KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > swing > border > SoftBevelBorder


1 /*
2  * @(#)SoftBevelBorder.java 1.16 03/12/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7 package javax.swing.border;
8
9 import java.awt.Graphics JavaDoc;
10 import java.awt.Insets JavaDoc;
11 import java.awt.Rectangle JavaDoc;
12 import java.awt.Color JavaDoc;
13 import java.awt.Component JavaDoc;
14
15
16 /**
17  * A class which implements a raised or lowered bevel with
18  * softened corners.
19  * <p>
20  * <strong>Warning:</strong>
21  * Serialized objects of this class will not be compatible with
22  * future Swing releases. The current serialization support is
23  * appropriate for short term storage or RMI between applications running
24  * the same version of Swing. As of 1.4, support for long term storage
25  * of all JavaBeans<sup><font size="-2">TM</font></sup>
26  * has been added to the <code>java.beans</code> package.
27  * Please see {@link java.beans.XMLEncoder}.
28  *
29  * @version 1.16 12/19/03
30  * @author Amy Fowler
31  * @author Chester Rose
32  */

33 public class SoftBevelBorder extends BevelBorder JavaDoc
34 {
35
36     /**
37      * Creates a bevel border with the specified type and whose
38      * colors will be derived from the background color of the
39      * component passed into the paintBorder method.
40      * @param bevelType the type of bevel for the border
41      */

42     public SoftBevelBorder(int bevelType) {
43         super(bevelType);
44     }
45
46     /**
47      * Creates a bevel border with the specified type, highlight and
48      * shadow colors.
49      * @param bevelType the type of bevel for the border
50      * @param highlight the color to use for the bevel highlight
51      * @param shadow the color to use for the bevel shadow
52      */

53     public SoftBevelBorder(int bevelType, Color JavaDoc highlight, Color JavaDoc shadow) {
54         super(bevelType, highlight, shadow);
55     }
56
57     /**
58      * Creates a bevel border with the specified type, highlight
59      * shadow colors.
60      * @param bevelType the type of bevel for the border
61      * @param highlightOuterColor the color to use for the bevel outer highlight
62      * @param highlightInnerColor the color to use for the bevel inner highlight
63      * @param shadowOuterColor the color to use for the bevel outer shadow
64      * @param shadowInnerColor the color to use for the bevel inner shadow
65      */

66     public SoftBevelBorder(int bevelType, Color JavaDoc highlightOuterColor,
67                         Color JavaDoc highlightInnerColor, Color JavaDoc shadowOuterColor,
68                         Color JavaDoc shadowInnerColor) {
69         super(bevelType, highlightOuterColor, highlightInnerColor,
70               shadowOuterColor, shadowInnerColor);
71     }
72
73     /**
74      * Paints the border for the specified component with the specified
75      * position and size.
76      * @param c the component for which this border is being painted
77      * @param g the paint graphics
78      * @param x the x position of the painted border
79      * @param y the y position of the painted border
80      * @param width the width of the painted border
81      * @param height the height of the painted border
82      */

83     public void paintBorder(Component JavaDoc c, Graphics JavaDoc g, int x, int y, int width, int height) {
84         Color JavaDoc oldColor = g.getColor();
85         g.translate(x, y);
86
87         if (bevelType == RAISED) {
88         g.setColor(getHighlightOuterColor(c));
89         g.drawLine(0, 0, width-2, 0);
90         g.drawLine(0, 0, 0, height-2);
91         g.drawLine(1, 1, 1, 1);
92         
93         g.setColor(getHighlightInnerColor(c));
94         g.drawLine(2, 1, width-2, 1);
95         g.drawLine(1, 2, 1, height-2);
96         g.drawLine(2, 2, 2, 2);
97         g.drawLine(0, height-1, 0, height-2);
98         g.drawLine(width-1, 0, width-1, 0);
99         
100         g.setColor(getShadowOuterColor(c));
101         g.drawLine(2, height-1, width-1, height-1);
102         g.drawLine(width-1, 2, width-1, height-1);
103         
104         g.setColor(getShadowInnerColor(c));
105         g.drawLine(width-2, height-2, width-2, height-2);
106
107
108         } else if (bevelType == LOWERED) {
109         g.setColor(getShadowOuterColor(c));
110         g.drawLine(0, 0, width-2, 0);
111         g.drawLine(0, 0, 0, height-2);
112         g.drawLine(1, 1, 1, 1);
113         
114         g.setColor(getShadowInnerColor(c));
115         g.drawLine(2, 1, width-2, 1);
116         g.drawLine(1, 2, 1, height-2);
117         g.drawLine(2, 2, 2, 2);
118         g.drawLine(0, height-1, 0, height-2);
119         g.drawLine(width-1, 0, width-1, 0);
120         
121         g.setColor(getHighlightOuterColor(c));
122         g.drawLine(2, height-1, width-1, height-1);
123         g.drawLine(width-1, 2, width-1, height-1);
124         
125         g.setColor(getHighlightInnerColor(c));
126         g.drawLine(width-2, height-2, width-2, height-2);
127         }
128         g.translate(-x, -y);
129         g.setColor(oldColor);
130     }
131
132     /**
133      * Returns the insets of the border.
134      * @param c the component for which this border insets value applies
135      */

136     public Insets JavaDoc getBorderInsets(Component JavaDoc c) {
137     return getBorderInsets(c, new Insets JavaDoc(0,0,0,0));
138     }
139
140     /**
141      * Reinitialize the insets parameter with this Border's current Insets.
142      * @param c the component for which this border insets value applies
143      * @param insets the object to be reinitialized
144      */

145     public Insets JavaDoc getBorderInsets(Component JavaDoc c, Insets JavaDoc insets) {
146         insets.top = insets.left = insets.bottom = insets.right = 3;
147     return insets;
148     }
149
150     /**
151      * Returns whether or not the border is opaque.
152      */

153     public boolean isBorderOpaque() { return false; }
154
155 }
156
Popular Tags