KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > core > gui > base > ShadowBorder


1 package org.columba.core.gui.base;
2
3 import java.awt.Color JavaDoc;
4 import java.awt.Component JavaDoc;
5 import java.awt.Graphics JavaDoc;
6 import java.awt.Insets JavaDoc;
7
8 import javax.swing.UIManager JavaDoc;
9 import javax.swing.border.Border JavaDoc;
10
11 public class ShadowBorder implements Border JavaDoc {
12     private Insets JavaDoc insets;
13
14     public ShadowBorder() {
15         insets = new Insets JavaDoc(2, 2, 4, 4);
16     }
17
18     public Insets JavaDoc getBorderInsets(Component JavaDoc c) {
19         return insets;
20     }
21
22     public boolean isBorderOpaque() {
23         return true;
24     }
25
26     public void paintBorder(Component JavaDoc c, Graphics JavaDoc g, int x, int y, int w, int h) {
27         Color JavaDoc bg = c.getBackground();
28         if (c.getParent() != null)
29             bg = c.getParent().getBackground();
30         Color JavaDoc mid = bg.darker();
31         Color JavaDoc rect = UIManager.getColor("control").darker();
32         Color JavaDoc edge = average(mid, bg);
33
34         // g.setColor(bg);
35
// g.fillRect(0, h - 3, 3, 3);
36
// g.fillRect(w - 3, 0, 3, 3);
37
// g.fillRect(w - 3, h - 3, 3, 3);
38

39         w-=3;
40         h-=3;
41         g.setColor(rect);
42         // g.drawRect(0, 0, w - 3, h - 3);
43
int ovalHeight = 3;
44         int ovalWidth = 3;
45         // left
46
g.drawLine(x, y + ovalHeight, x, y +h);
47         g.drawArc(x, y, 2 * ovalWidth, 2 * ovalHeight, 180, -90);
48         // top
49
g.drawLine(x + ovalWidth, y, x + w - ovalWidth, y);
50         g.drawArc(x + w - 2 * ovalWidth, y, 2 * ovalWidth, 2 * ovalHeight, 90,
51                 -90);
52         // right
53
g.drawLine(x + w, y + ovalHeight, x + w, y + h);
54         // bottom
55
g.drawLine(x, y + h, x + w, y + h);
56
57         w+=1;
58         h+=1;
59         //
60
g.setColor(edge);
61          // bottom
62
g.drawLine(x+1, h, x+w, h );
63          // right
64
g.drawLine(x+w, y+ovalHeight+1, x+w , y+h);
65 //
66
// w+=1;
67
// h+=1;
68
// g.setColor(edge);
69
// // bottom
70
// g.drawLine(x+2, h, x+w, h );
71
// // right
72
// g.drawLine(x+w, y+ovalHeight+2, x+w , y+h);
73

74     }
75
76     private static Color JavaDoc average(Color JavaDoc c1, Color JavaDoc c2) {
77         int red = c1.getRed() + (c2.getRed() - c1.getRed()) / 2;
78         int green = c1.getGreen() + (c2.getGreen() - c1.getGreen()) / 2;
79         int blue = c1.getBlue() + (c2.getBlue() - c1.getBlue()) / 2;
80         return new Color JavaDoc(red, green, blue);
81     }
82 }
Popular Tags