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.Color;
23 import java.awt.Component;
24 import java.awt.Graphics;
25 import java.awt.Insets;
26 import javax.swing.border.BevelBorder;
27
28 /***
29 * Provides a simple 1 line bevel border. If the Border is raised it will look
30 * like the component it is used with is raised a little bit. If it is lowered it
31 * will look like the component is lowered a bit.
32 *
33 * <p>Very similiar to Swing's {@link javax.swing.border.BevelBorder} except
34 * it looks a bit prettier.
35 */
36 public class ThinBevelBorder extends BevelBorder {
37
38 /***
39 * Constructs a border with the given <code>etchType</code>.
40 *
41 * @see BevelBorder#BevelBorder(int)
42 * @param bevelType either <code>BevelBoder.RAISED</code> or <code>BevelBorder.LOWERED</code>
43 */
44 public ThinBevelBorder(int bevelType)
45 {
46 super(bevelType);
47 }
48
49 public Insets getBorderInsets(Component c)
50 {
51 return new Insets(1, 1, 1, 1);
52 }
53
54 public Insets getBorderInsets(Component c, Insets insets)
55 {
56 insets.left = insets.top = insets.right = insets.bottom = 1;
57 return insets;
58 }
59
60 protected void paintLoweredBevel(Component c, Graphics g, int x, int y,
61 int width, int height)
62 {
63 Color oldColor = g.getColor();
64 int h = height;
65 int w = width;
66
67 g.translate(x, y);
68
69 g.setColor(getShadowOuterColor(c));
70 g.drawLine(0, 0, 0, h - 2);
71 g.drawLine(1, 0, w - 1, 0);
72
73 g.setColor(getHighlightOuterColor(c));
74 g.drawLine(0, h - 1, w - 1, h - 1);
75 g.drawLine(w - 1, 1, w - 1, h - 2);
76
77 g.translate(-x, -y);
78 g.setColor(oldColor);
79
80 }
81
82 protected void paintRaisedBevel(Component c, Graphics g, int x, int y,
83 int width, int height)
84 {
85 Color oldColor = g.getColor();
86 int h = height;
87 int w = width;
88
89 g.translate(x, y);
90
91 g.setColor(getHighlightOuterColor(c));
92 g.drawLine(0, 0, 0, h - 2);
93 g.drawLine(1, 0, w - 1, 0);
94
95 g.setColor(getShadowOuterColor(c));
96 g.drawLine(0, h - 1, w - 1, h - 1);
97 g.drawLine(w - 1, 1, w - 1, h - 2);
98
99 g.translate(-x, -y);
100 g.setColor(oldColor);
101 }
102
103 }