You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

SidelessEtchedBorder.java 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*
  2. * Copyright (c) 2006-2017 DMDirc Developers
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
  5. * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
  6. * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
  7. * permit persons to whom the Software is furnished to do so, subject to the following conditions:
  8. *
  9. * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
  10. * Software.
  11. *
  12. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  13. * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
  14. * OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  15. * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  16. */
  17. package com.dmdirc.addons.ui_swing.components.statusbar;
  18. import java.awt.Color;
  19. import java.awt.Component;
  20. import java.awt.Graphics;
  21. import javax.swing.border.EtchedBorder;
  22. /**
  23. * An {@link EtchedBorder} with one of it's sides missing.
  24. */
  25. class SidelessEtchedBorder extends EtchedBorder {
  26. /** A version number for this class. */
  27. private static final long serialVersionUID = 1;
  28. /** Side to not paint. */
  29. private final Side side;
  30. /**
  31. * Specifies which side to not include.
  32. */
  33. public enum Side {
  34. /** Top border. */
  35. TOP,
  36. /** Right hand border. */
  37. RIGHT,
  38. /** Bottom border. */
  39. BOTTOM,
  40. /** Left hand border. */
  41. LEFT,
  42. /* Draw all borders. */
  43. NONE,
  44. }
  45. /**
  46. * Creates a new sideless etched border.
  47. *
  48. * @param side Which side do you wish to leave out
  49. */
  50. public SidelessEtchedBorder(final Side side) {
  51. this.side = side;
  52. }
  53. /**
  54. * Creates a new sideless etched border.
  55. *
  56. * @param etchType What etch type to use
  57. * @param side Which side do you wish to leave out
  58. */
  59. public SidelessEtchedBorder(final int etchType, final Side side) {
  60. super(etchType);
  61. this.side = side;
  62. }
  63. /**
  64. * Creates a new sideless etched border.
  65. *
  66. * @param highlight Highlight colour to use
  67. * @param shadow Shadow colour to use
  68. * @param side Which side do you wish to leave out
  69. */
  70. public SidelessEtchedBorder(final Color highlight, final Color shadow,
  71. final Side side) {
  72. super(highlight, shadow);
  73. this.side = side;
  74. }
  75. /**
  76. * Creates a new sideless etched border.
  77. *
  78. * @param etchType What etch type to use
  79. * @param highlight Highlight colour to use
  80. * @param shadow Shadow colour to use
  81. * @param side Which side do you wish to leave out
  82. */
  83. public SidelessEtchedBorder(final int etchType, final Color highlight,
  84. final Color shadow, final Side side) {
  85. super(etchType, highlight, shadow);
  86. this.side = side;
  87. }
  88. @Override
  89. public void paintBorder(final Component c, final Graphics g, final int x,
  90. final int y, final int width, final int height) {
  91. g.translate(x, y);
  92. g.setColor(etchType == LOWERED ? getShadowColor(c) : getHighlightColor(c));
  93. if (!side.equals(Side.TOP)) {
  94. g.drawLine(0, 0, width - 1, 0);
  95. }
  96. if (!side.equals(Side.BOTTOM)) {
  97. g.drawLine(0, height - 2, width, height - 2);
  98. }
  99. if (!side.equals(Side.LEFT)) {
  100. g.drawLine(0, 0, 0, height - 2);
  101. }
  102. if (!side.equals(Side.RIGHT)) {
  103. g.drawLine(width - 2, 0, width - 2, height - 1);
  104. }
  105. g.setColor(Color.WHITE);
  106. if (!side.equals(Side.BOTTOM)) {
  107. g.drawLine(0, height - 1, width, height - 1);
  108. }
  109. if (!side.equals(Side.RIGHT)) {
  110. g.drawLine(width - 1, 0, width - 1, height - 1);
  111. }
  112. g.translate(-x, -y);
  113. }
  114. }