01: package org.gui4j.core.swing;
02:
03: import java.awt.Color;
04: import java.awt.Component;
05: import java.awt.Graphics;
06: import java.awt.Insets;
07:
08: import javax.swing.UIManager;
09: import javax.swing.border.AbstractBorder;
10:
11: public class ShadowBorder extends AbstractBorder {
12: private static final Insets INSETS = new Insets(1, 1, 3, 3);
13:
14: public Insets getBorderInsets(Component c) {
15: return INSETS;
16: }
17:
18: public void paintBorder(Component c, Graphics g, int x, int y,
19: int w, int h) {
20:
21: Color shadow = UIManager.getColor("controlShadow");
22: if (shadow == null) {
23: shadow = Color.GRAY;
24: }
25: Color lightShadow = new Color(shadow.getRed(), shadow
26: .getGreen(), shadow.getBlue(), 170);
27: Color lighterShadow = new Color(shadow.getRed(), shadow
28: .getGreen(), shadow.getBlue(), 70);
29: g.translate(x, y);
30:
31: g.setColor(shadow);
32: g.fillRect(0, 0, w - 3, 1);
33: g.fillRect(0, 0, 1, h - 3);
34: g.fillRect(w - 3, 1, 1, h - 3);
35: g.fillRect(1, h - 3, w - 3, 1);
36: // Shadow line 1
37: g.setColor(lightShadow);
38: g.fillRect(w - 3, 0, 1, 1);
39: g.fillRect(0, h - 3, 1, 1);
40: g.fillRect(w - 2, 1, 1, h - 3);
41: g.fillRect(1, h - 2, w - 3, 1);
42: // Shadow line2
43: g.setColor(lighterShadow);
44: g.fillRect(w - 2, 0, 1, 1);
45: g.fillRect(0, h - 2, 1, 1);
46: g.fillRect(w - 2, h - 2, 1, 1);
47: g.fillRect(w - 1, 1, 1, h - 2);
48: g.fillRect(1, h - 1, w - 2, 1);
49: g.translate(-x, -y);
50: }
51:
52: }
|