01: /*
02: * $Id: JGraphpadShadowBorder.java,v 1.1.1.1 2005/08/04 11:21:58 gaudenz Exp $
03: * Copyright (c) 2001-2005, Gaudenz Alder
04: *
05: * All rights reserved.
06: *
07: * This file is licensed under the JGraph software license, a copy of which
08: * will have been provided to you in the file LICENSE at the root of your
09: * installation directory. If you are unable to locate this file please
10: * contact JGraph sales for another copy.
11: */
12: package com.jgraph.pad.util;
13:
14: import java.awt.Color;
15: import java.awt.Component;
16: import java.awt.Graphics;
17: import java.awt.Insets;
18: import java.io.Serializable;
19:
20: import javax.swing.border.Border;
21:
22: /**
23: * Border with a drop shadow.
24: */
25: public class JGraphpadShadowBorder implements Border, Serializable {
26: private Insets insets;
27:
28: public static JGraphpadShadowBorder sharedInstance = new JGraphpadShadowBorder();
29:
30: private JGraphpadShadowBorder() {
31: insets = new Insets(1, 1, 3, 3);
32: }
33:
34: public Insets getBorderInsets(Component c) {
35: return insets;
36: }
37:
38: public boolean isBorderOpaque() {
39: // we'll be filling in our own background.
40: return true;
41: }
42:
43: public void paintBorder(Component c, Graphics g, int x, int y,
44: int w, int h) {
45: // choose which colors we want to use
46: Color bg = c.getBackground();
47: if (c.getParent() != null)
48: bg = c.getParent().getBackground();
49: Color mid = bg.darker();
50: Color rect = mid.darker();
51: Color edge = average(mid, bg);
52:
53: // fill in the corners with the parent-background
54: // so it looks see-through
55: g.setColor(bg);
56: g.fillRect(0, h - 3, 3, 3);
57: g.fillRect(w - 3, 0, 3, 3);
58: g.fillRect(w - 3, h - 3, 3, 3);
59:
60: // draw the outline
61: g.setColor(rect);
62: g.drawRect(0, 0, w - 3, h - 3);
63:
64: // draw the drop-shadow
65: g.setColor(mid);
66: g.drawLine(1, h - 2, w - 2, h - 2);
67: g.drawLine(w - 2, 1, w - 2, h - 2);
68:
69: g.setColor(edge);
70: g.drawLine(2, h - 1, w - 2, h - 1);
71: g.drawLine(w - 1, 2, w - 1, h - 2);
72: }
73:
74: private static Color average(Color c1, Color c2) {
75: int red = c1.getRed() + (c2.getRed() - c1.getRed()) / 2;
76: int green = c1.getGreen() + (c2.getGreen() - c1.getGreen()) / 2;
77: int blue = c1.getBlue() + (c2.getBlue() - c1.getBlue()) / 2;
78: return new Color(red, green, blue);
79: }
80:
81: public static JGraphpadShadowBorder getSharedInstance() {
82: return sharedInstance;
83: }
84: }
|