svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.dal / org.gvsig.fmap.dal.swing / org.gvsig.fmap.dal.swing.impl / src / main / java / org / gvsig / fmap / dal / swing / impl / visualdbmodeler / ShadowBorder.java @ 47784
History | View | Annotate | Download (2.05 KB)
1 | 46986 | jjdelcerro | /*
|
---|---|---|---|
2 | * Copyright (c) 2001-2005, Gaudenz Alder
|
||
3 | *
|
||
4 | * All rights reserved.
|
||
5 | *
|
||
6 | * This file is licensed under the JGraph software license, a copy of which
|
||
7 | * will have been provided to you in the file LICENSE at the root of your
|
||
8 | * installation directory. If you are unable to locate this file please
|
||
9 | * contact JGraph sales for another copy.
|
||
10 | */
|
||
11 | package org.gvsig.fmap.dal.swing.impl.visualdbmodeler; |
||
12 | |||
13 | import java.awt.Color; |
||
14 | import java.awt.Component; |
||
15 | import java.awt.Graphics; |
||
16 | import java.awt.Insets; |
||
17 | import java.io.Serializable; |
||
18 | |||
19 | import javax.swing.border.Border; |
||
20 | |||
21 | /**
|
||
22 | * Border with a drop shadow.
|
||
23 | */
|
||
24 | public class ShadowBorder implements Border, Serializable |
||
25 | { |
||
26 | /**
|
||
27 | *
|
||
28 | */
|
||
29 | private static final long serialVersionUID = 6854989457150641240L; |
||
30 | |||
31 | private Insets insets; |
||
32 | |||
33 | public static ShadowBorder sharedInstance = new ShadowBorder(); |
||
34 | |||
35 | private ShadowBorder()
|
||
36 | { |
||
37 | insets = new Insets(0, 0, 2, 2); |
||
38 | } |
||
39 | |||
40 | public Insets getBorderInsets(Component c) |
||
41 | { |
||
42 | return insets;
|
||
43 | } |
||
44 | |||
45 | public boolean isBorderOpaque() |
||
46 | { |
||
47 | return false; |
||
48 | } |
||
49 | |||
50 | public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) |
||
51 | { |
||
52 | // choose which colors we want to use
|
||
53 | Color bg = c.getBackground();
|
||
54 | |||
55 | if (c.getParent() != null) |
||
56 | { |
||
57 | bg = c.getParent().getBackground(); |
||
58 | } |
||
59 | |||
60 | if (bg != null) |
||
61 | { |
||
62 | Color mid = bg.darker();
|
||
63 | Color edge = average(mid, bg);
|
||
64 | |||
65 | g.setColor(bg); |
||
66 | g.drawLine(0, h - 2, w, h - 2); |
||
67 | g.drawLine(0, h - 1, w, h - 1); |
||
68 | g.drawLine(w - 2, 0, w - 2, h); |
||
69 | g.drawLine(w - 1, 0, w - 1, h); |
||
70 | |||
71 | // draw the drop-shadow
|
||
72 | g.setColor(mid); |
||
73 | g.drawLine(1, h - 2, w - 2, h - 2); |
||
74 | g.drawLine(w - 2, 1, w - 2, h - 2); |
||
75 | |||
76 | g.setColor(edge); |
||
77 | g.drawLine(2, h - 1, w - 2, h - 1); |
||
78 | g.drawLine(w - 1, 2, w - 1, h - 2); |
||
79 | } |
||
80 | } |
||
81 | |||
82 | private static Color average(Color c1, Color c2) |
||
83 | { |
||
84 | int red = c1.getRed() + (c2.getRed() - c1.getRed()) / 2; |
||
85 | int green = c1.getGreen() + (c2.getGreen() - c1.getGreen()) / 2; |
||
86 | int blue = c1.getBlue() + (c2.getBlue() - c1.getBlue()) / 2; |
||
87 | return new Color(red, green, blue); |
||
88 | } |
||
89 | |||
90 | public static ShadowBorder getSharedInstance() |
||
91 | { |
||
92 | return sharedInstance;
|
||
93 | } |
||
94 | } |