1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.xnap.commons.gui;
21
22 import java.awt.Component;
23 import java.awt.Graphics;
24 import java.awt.Insets;
25 import javax.swing.border.AbstractBorder;
26
27 /***
28 * Provides a simple 2 line bevel border. If the Border is raised it will look
29 * like a tiny wall around the component it is used with. If it is lowered it
30 * will look like a thin trench.
31 */
32 public class ThinEtchedBorder extends AbstractBorder {
33
34 public static final int RAISED = 0;
35
36 public static final int LOWERED = 1;
37
38 protected int etchType;
39
40 /***
41 * Constructs a border with the given <code>etchType</code>.
42 *
43 * @see javax.swing.border.BevelBorder#BevelBorder(int)
44 * @param etchType either <code>BevelBoder.RAISED</code> or <code>BevelBorder.LOWERED</code>
45 */
46 public ThinEtchedBorder(int etchType)
47 {
48 this.etchType = etchType;
49 }
50
51 /***
52 * Constructs a lowered border.
53 *
54 * @see javax.swing.border.BevelBorder#BevelBorder(int)
55 */
56 public ThinEtchedBorder()
57 {
58 this(LOWERED);
59 }
60
61 public void paintBorder(Component c, Graphics g, int x, int y, int w,
62 int h)
63 {
64 g.translate(x, y);
65
66 g.setColor((etchType == LOWERED)
67 ? c.getBackground().darker()
68 : c.getBackground().brighter());
69 g.drawLine(0, h - 2, w - 1, h - 2);
70
71 g.setColor((etchType == LOWERED)
72 ? c.getBackground().brighter()
73 : c.getBackground().darker());
74 g.drawLine(0, h - 1, w - 1, h - 1);
75
76 g.translate(-x, -y);
77 }
78
79 public Insets getBorderInsets(Component c)
80 {
81 return new Insets(2, 2, 2, 2);
82 }
83
84 public Insets getBorderInsets(Component c, Insets insets)
85 {
86 insets.left = insets.top = insets.right = insets.bottom = 2;
87 return insets;
88 }
89
90 /***
91 * Returns true.
92 */
93 public boolean isBorderOpaque()
94 {
95 return true;
96 }
97
98 /***
99 * Returns the etch type.
100 */
101 public int getEtchType()
102 {
103 return etchType;
104 }
105
106 }