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.

EtchedLineBorder.java 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. * Copyright (c) 2006-2011 Chris Smith, Shane Mc Cormack, Gregory Holmes
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a copy
  5. * of this software and associated documentation files (the "Software"), to deal
  6. * in the Software without restriction, including without limitation the rights
  7. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. * copies of the Software, and to permit persons to whom the Software is
  9. * furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  20. * SOFTWARE.
  21. */
  22. package com.dmdirc.installer.ui;
  23. import java.awt.Component;
  24. import java.awt.Graphics;
  25. import javax.swing.border.EtchedBorder;
  26. import static com.dmdirc.installer.ui.InstallerDialog.SMALL_GAP;
  27. /**
  28. * An etched line border.
  29. */
  30. class EtchedLineBorder extends EtchedBorder {
  31. /**
  32. * A version number for this class. It should be changed whenever the class
  33. * structure is changed (or anything else that would prevent serialized
  34. * objects being unserialized with the new class).
  35. */
  36. private static final long serialVersionUID = 1;
  37. /** Border side. */
  38. private final BorderSide side;
  39. /** Border side. */
  40. public enum BorderSide {
  41. /** Creates a border at the top. */
  42. TOP,
  43. /** Creates a border at the bottom. */
  44. BOTTOM,
  45. };
  46. /**
  47. * Creates a new etched line border.
  48. *
  49. * @param type Etch type
  50. * @param side Border side
  51. */
  52. public EtchedLineBorder(final int type, final BorderSide side) {
  53. super(type);
  54. this.side = side;
  55. }
  56. /** {@inheritDoc} */
  57. @Override
  58. public void paintBorder(final Component c, final Graphics g, final int x,
  59. final int y, final int width, final int height) {
  60. g.translate(x, y);
  61. g.setColor(
  62. etchType == LOWERED ? getShadowColor(c) : getHighlightColor(c));
  63. switch (side) {
  64. case TOP:
  65. g.drawLine(-SMALL_GAP, -SMALL_GAP, width + SMALL_GAP, -SMALL_GAP);
  66. break;
  67. case BOTTOM:
  68. g.drawLine(-SMALL_GAP, height + SMALL_GAP, width + SMALL_GAP, height + SMALL_GAP);
  69. break;
  70. default:
  71. break;
  72. }
  73. g.setColor(
  74. etchType == LOWERED ? getHighlightColor(c) : getShadowColor(c));
  75. switch (side) {
  76. case TOP:
  77. g.drawLine(-SMALL_GAP, -SMALL_GAP - 1, width + SMALL_GAP, -SMALL_GAP - 1);
  78. break;
  79. case BOTTOM:
  80. g.drawLine(-SMALL_GAP, height + SMALL_GAP - 1, width + SMALL_GAP, height + SMALL_GAP - 1);
  81. break;
  82. default:
  83. break;
  84. }
  85. g.translate(-x, -y);
  86. }
  87. }