Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

EtchedLineBorder.java 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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;
  18. import java.awt.Component;
  19. import java.awt.Graphics;
  20. import javax.swing.border.EtchedBorder;
  21. /**
  22. * An etched line border.
  23. */
  24. public class EtchedLineBorder extends EtchedBorder {
  25. /** A version number for this class. */
  26. private static final long serialVersionUID = 1;
  27. /** Border side. */
  28. private final BorderSide side;
  29. /** Border side. */
  30. public enum BorderSide {
  31. /** Creates a border at the top. */
  32. TOP,
  33. /** Creates a border at the bottom. */
  34. BOTTOM,
  35. }
  36. /**
  37. * Creates a new etched line border.
  38. *
  39. * @param type Etch type
  40. * @param side Border side
  41. */
  42. public EtchedLineBorder(final int type, final BorderSide side) {
  43. super(type);
  44. this.side = side;
  45. }
  46. @Override
  47. public void paintBorder(final Component c, final Graphics g, final int x,
  48. final int y, final int width, final int height) {
  49. g.translate(x, y);
  50. g.setColor(etchType == LOWERED
  51. ? getShadowColor(c) : getHighlightColor(c));
  52. switch (side) {
  53. case TOP:
  54. g.drawLine(0, 0, width - 2, 0);
  55. g.setColor(etchType == LOWERED
  56. ? getHighlightColor(c) : getShadowColor(c));
  57. g.drawLine(0, 1, width - 2, 1);
  58. break;
  59. case BOTTOM:
  60. g.drawLine(0, height - 1, width - 2, height - 1);
  61. g.setColor(etchType == LOWERED
  62. ? getHighlightColor(c) : getShadowColor(c));
  63. g.drawLine(0, height, width - 2, height);
  64. break;
  65. default:
  66. break;
  67. }
  68. g.translate(-x, -y);
  69. }
  70. }