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