KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectstyle > cayenne > dataview > dvmodeler > CustomBorderFactory


1 /* ====================================================================
2  *
3  * The ObjectStyle Group Software License, version 1.1
4  * ObjectStyle Group - http://objectstyle.org/
5  *
6  * Copyright (c) 2002-2005, Andrei (Andrus) Adamchik and individual authors
7  * of the software. All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  *
13  * 1. Redistributions of source code must retain the above copyright
14  * notice, this list of conditions and the following disclaimer.
15  *
16  * 2. Redistributions in binary form must reproduce the above copyright
17  * notice, this list of conditions and the following disclaimer in
18  * the documentation and/or other materials provided with the
19  * distribution.
20  *
21  * 3. The end-user documentation included with the redistribution, if any,
22  * must include the following acknowlegement:
23  * "This product includes software developed by independent contributors
24  * and hosted on ObjectStyle Group web site (http://objectstyle.org/)."
25  * Alternately, this acknowlegement may appear in the software itself,
26  * if and wherever such third-party acknowlegements normally appear.
27  *
28  * 4. The names "ObjectStyle Group" and "Cayenne" must not be used to endorse
29  * or promote products derived from this software without prior written
30  * permission. For written permission, email
31  * "andrus at objectstyle dot org".
32  *
33  * 5. Products derived from this software may not be called "ObjectStyle"
34  * or "Cayenne", nor may "ObjectStyle" or "Cayenne" appear in their
35  * names without prior written permission.
36  *
37  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
38  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
39  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
40  * DISCLAIMED. IN NO EVENT SHALL THE OBJECTSTYLE GROUP OR
41  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
42  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
43  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
44  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
45  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
46  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
47  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
48  * SUCH DAMAGE.
49  * ====================================================================
50  *
51  * This software consists of voluntary contributions made by many
52  * individuals and hosted on ObjectStyle Group web site. For more
53  * information on the ObjectStyle Group, please see
54  * <http://objectstyle.org/>.
55  */

56
57 package org.objectstyle.cayenne.dataview.dvmodeler;
58
59 import java.awt.*;
60 import javax.swing.border.*;
61 import javax.swing.plaf.UIResource JavaDoc;
62 import javax.swing.UIManager JavaDoc;
63
64 /**
65  *
66  * @author Andriy Shapochka
67  * @version 1.0
68  */

69
70 public class CustomBorderFactory {
71   public static final Border THIN_RAISED_BORDER = new ThinRaisedBorder();
72   public static final Border THIN_LOWERED_BORDER = new ThinLoweredBorder();
73   public static final Border TILE_BORDER = new TileBorder();
74
75   public static class ThinRaisedBorder extends AbstractBorder {
76     private static final Insets INSETS = new Insets(2, 2, 2, 2);
77
78     public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) {
79       g.translate(x, y);
80       g.setColor(c.getBackground().brighter());
81       g.drawLine(0, 0, w - 2, 0);
82       g.drawLine(0, 0, 0, h - 2);
83       g.setColor(c.getBackground().darker());
84       g.drawLine(w - 1, 0, w - 1, h - 1);
85       g.drawLine(0, h - 1, w - 1, h - 1);
86       g.translate(-x, -y);
87     }
88
89     public Insets getBorderInsets(Component c) { return INSETS; }
90   }
91
92
93   public static class ThinLoweredBorder extends AbstractBorder {
94     private static final Insets INSETS = new Insets(2, 2, 2, 2);
95
96     public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) {
97       g.translate(x, y);
98       g.setColor(c.getBackground().darker());
99       g.drawLine(0, 0, w - 2, 0);
100       g.drawLine(0, 0, 0, h - 2);
101       g.setColor(c.getBackground().brighter());
102       g.drawLine(w - 1, 0, w - 1, h - 1);
103       g.drawLine(0, h - 1, w - 1, h - 1);
104       g.translate(-x, -y);
105     }
106
107     public Insets getBorderInsets(Component c) { return INSETS; }
108   }
109
110   public static class TileBorder extends AbstractBorder implements UIResource JavaDoc {
111
112     public static final Insets INSETS = new Insets(1, 1, 3, 3);
113
114     static final int ALPHA1 = 173;
115     static final int ALPHA2 = 66;
116
117
118     public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) {
119       paintShadowedBorder(c, g, x, y, w, h);
120     }
121
122     private void paintShadowedBorder(Component c, Graphics g, int x, int y, int w, int h) {
123       Color background = c.getParent().getBackground();
124       Color shadow = UIManager.getColor("controlShadow");
125       Color lightShadow = new Color(shadow.getRed(),
126                                       shadow.getGreen(),
127                                       shadow.getBlue(),
128                                       ALPHA1);
129       Color lighterShadow = new Color(shadow.getRed(),
130                                       shadow.getGreen(),
131                                       shadow.getBlue(),
132                                       ALPHA2);
133       g.translate(x, y);
134       // Dark border
135
g.setColor(shadow);
136       g.drawRect(0, 0, w-3, h-3);
137       // Paint background before painting the shadow
138
g.setColor(background);
139       g.fillRect(w - 2, 0, 2, h);
140       g.fillRect(0, h-2, w, 2);
141       // Shadow line 1
142
g.setColor(lightShadow);
143       g.drawLine(w - 2, 1, w - 2, h - 2);
144       g.drawLine(1, h - 2, w - 3, h - 2);
145       // Shadow line2
146
g.setColor(lighterShadow);
147       g.drawLine(w - 1, 2, w - 1, h - 2);
148       g.drawLine(2, h - 1, w - 2, h - 1);
149       g.translate(-x, -y);
150     }
151
152     public Insets getBorderInsets(Component c) {
153       return INSETS;
154     }
155   }
156 }
Popular Tags