Remove old autovect-branch by moving to "dead" directory.
[official-gcc.git] / old-autovect-branch / libjava / classpath / javax / swing / border / SoftBevelBorder.java
blob028fd00e0214c760c83da0e75f6c2a6235693c56
1 /* SoftBevelBorder.java --
2 Copyright (C) 2003 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 02110-1301 USA.
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
24 combination.
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
38 package javax.swing.border;
40 import java.awt.Color;
41 import java.awt.Component;
42 import java.awt.Graphics;
43 import java.awt.Insets;
46 /**
47 * A rectangular, three pixel thick border that looks like a BevelBorder
48 * with slightly softened corners.
50 * <p>Like BevelBorder, SoftBevelBorder has a highlight and a shadow
51 * color. In the raised variant, the highlight color is used for the
52 * top and left edges, and the shadow color is used for the bottom and
53 * right edge. In the lowered variant, color usage is reversed. For
54 * an image, see the documentation of the individual constructors.
56 * @author Sascha Brawer (brawer@dandelis.ch)
58 public class SoftBevelBorder extends BevelBorder
60 /**
61 * Determined using the <code>serialver</code> tool
62 * of Sun JDK 1.4.1_01 on GNU/Linux 2.4.20. Interestingly,
63 * the Apple/Sun JDK 1.3.1 on MacOS X 10.1.5 gives a different
64 * value, namely -6658357140774549493L.
66 static final long serialVersionUID = 5248789787305979975L;
69 /**
70 * Constructs a SoftBevelBorder whose colors will be derived from the
71 * background of the enclosed component. The background color is
72 * retrieved each time the border is painted, so a SoftBevelBorder
73 * constructed by this method will automatically reflect a change
74 * to the component&#x2019;s background color.
76 * <p><img src="doc-files/SoftBevelBorder-1.png" width="500" height="200"
77 * alt="[An illustration showing raised and lowered SoftBevelBorders]" />
79 * @param bevelType the desired appearance of the border. The value
80 * must be either {@link BevelBorder#RAISED}
81 * or {@link BevelBorder#LOWERED}.
83 * @throws IllegalArgumentException if <code>bevelType</code> has
84 * an unsupported value.
86 public SoftBevelBorder(int bevelType)
88 super(bevelType);
92 /**
93 * Constructs a SoftBevelBorder given its appearance type and two
94 * colors for its highlight and shadow.
96 * <p><img src="doc-files/SoftBevelBorder-2.png" width="500" height="150"
97 * alt="[An illustration showing SoftBevelBorders that were
98 * constructed with this method]" />
100 * @param bevelType the desired appearance of the border. The value
101 * must be either {@link BevelBorder#RAISED} or {@link
102 * BevelBorder#LOWERED}.
104 * @param highlight the color that will be used for the inner side
105 * of the highlighted edges (top and left if if
106 * <code>bevelType</code> is {@link BevelBorder#RAISED};
107 * bottom and right otherwise). The color for the outer side
108 * is a brightened version of this color.
110 * @param shadow the color that will be used for the outer side of
111 * the shadowed edges (bottom and right if
112 * <code>bevelType</code> is {@link BevelBorder#RAISED}; top
113 * and left otherwise). The color for the inner side is a
114 * brightened version of this color.
116 * @throws IllegalArgumentException if <code>bevelType</code> has an
117 * unsupported value.
119 * @throws NullPointerException if <code>highlight</code> or
120 * <code>shadow</code> is <code>null</code>.
122 * @see java.awt.Color#brighter()
124 public SoftBevelBorder(int bevelType, Color highlight, Color shadow)
126 this(bevelType,
127 /* highlightOuter */ highlight.brighter(),
128 /* highlightInner */ highlight,
129 /* shadowOuter */ shadow,
130 /* shadowInner */ shadow.brighter());
135 * Constructs a SoftBevelBorder given its appearance type and all
136 * colors.
138 * <p><img src="doc-files/SoftBevelBorder-3.png" width="500" height="150"
139 * alt="[An illustration showing SoftBevelBorders that were
140 * constructed with this method]" />
142 * @param bevelType the desired appearance of the border. The value
143 * must be either {@link BevelBorder#RAISED} or {@link
144 * BevelBorder#LOWERED}.
146 * @param highlightOuter the color that will be used for the outer
147 * side of the highlighted edges (top and left if
148 * <code>bevelType</code> is {@link BevelBorder#RAISED};
149 * bottom and right otherwise).
151 * @param highlightInner the color that will be used for the inner
152 * side of the highlighted edges.
154 * @param shadowOuter the color that will be used for the outer side
155 * of the shadowed edges (bottom and right if
156 * <code>bevelType</code> is {@link BevelBorder#RAISED}; top
157 * and left otherwise).
159 * @param shadowInner the color that will be used for the inner
160 * side of the shadowed edges.
162 * @throws IllegalArgumentException if <code>bevelType</code> has
163 * an unsupported value.
165 * @throws NullPointerException if one of the passed colors
166 * is <code>null</code>.
168 public SoftBevelBorder(int bevelType,
169 Color highlightOuter, Color highlightInner,
170 Color shadowOuter, Color shadowInner)
172 super(bevelType,
173 highlightOuter, highlightInner,
174 shadowOuter, shadowInner);
179 * Paints the border for a given component.
181 * @param c the component whose border is to be painted.
182 * @param g the graphics for painting.
183 * @param x the horizontal position for painting the border.
184 * @param y the vertical position for painting the border.
185 * @param width the width of the available area for painting the border.
186 * @param height the height of the available area for painting the border.
188 public void paintBorder(Component c, Graphics g,
189 int x, int y, int width, int height)
191 switch (bevelType)
193 case RAISED:
194 paintSoftBevel(g, x, y, width, height,
195 getHighlightOuterColor(c), getHighlightInnerColor(c),
196 getShadowInnerColor(c), getShadowOuterColor(c));
197 break;
199 case LOWERED:
200 paintSoftBevel(g, x, y, width, height,
201 getShadowOuterColor(c), getShadowInnerColor(c),
202 getHighlightInnerColor(c), getHighlightOuterColor(c));
203 break;
209 * Measures the width of this border.
211 * @param c the component whose border is to be measured.
213 * @return an Insets object whose <code>left</code>, <code>right</code>,
214 * <code>top</code> and <code>bottom</code> fields indicate the
215 * width of the border at the respective edge.
217 * @see #getBorderInsets(java.awt.Component, java.awt.Insets)
219 public Insets getBorderInsets(Component c)
221 return new Insets(3, 3, 3, 3);
226 * Measures the width of this border, storing the results into a
227 * pre-existing Insets object.
229 * @param insets an Insets object for holding the result values.
230 * After invoking this method, the <code>left</code>,
231 * <code>right</code>, <code>top</code> and
232 * <code>bottom</code> fields indicate the width of the
233 * border at the respective edge.
235 * @return the same object that was passed for <code>insets</code>.
237 * @see #getBorderInsets(Component)
239 public Insets getBorderInsets(Component c, Insets insets)
241 insets.left = insets.right = insets.top = insets.bottom = 3;
242 return insets;
247 * Determines whether this border fills every pixel in its area
248 * when painting.
250 * <p>The enlarged view (see documentation for constructors) shows
251 * that a SoftBevelBorder does not paint all pixels. Therefore,
252 * this method always returns <code>false</code>.
254 * @return <code>false</code>.
256 public boolean isBorderOpaque()
258 return false;
263 * Paints a soft bevel in four colors.
265 * <pre>
266 * +++++++++++.
267 * ++.........# + = color a
268 * +.. # . = color b
269 * +. # X = color c
270 * .. X# # = color d
271 * . ##########</pre>
273 * @param g the graphics for painting.
274 * @param x the horizontal position for painting the border.
275 * @param y the vertical position for painting the border.
276 * @param width the width of the available area for painting the border.
277 * @param height the height of the available area for painting the border.
278 * @param a the color for the outer side of the top and left edges.
279 * @param b the color for the inner side of the top and left edges.
280 * @param c the color for the inner side of the bottom and right edges.
281 * @param d the color for the outer side of the bottom and right edges.
283 private static void paintSoftBevel(Graphics g,
284 int x, int y, int width, int height,
285 Color a, Color b, Color c, Color d)
287 Color oldColor;
289 oldColor = g.getColor();
290 g.translate(x, y);
291 width = width - 1;
292 height = height - 1;
296 /* To understand this code, it might be helpful to look at the
297 * images that are included with the JavaDoc, especially
298 * SoftBevelBorder-3.png. They are located in the "doc-files"
299 * subdirectory.
301 g.setColor(a);
302 g.drawLine(0, 0, width - 1, 0); // a, horizontal
303 g.drawLine(0, 1, 2, 1); // a, horizontal
304 g.drawLine(0, 2, 0, height - 1); // a, vertical
306 g.setColor(b);
307 g.drawLine(width, 0, width, 0); // b, horizontal
308 g.drawLine(2, 1, width - 1, 1); // b, horizontal
309 g.drawLine(1, 2, 2, 2); // b, horizontal
310 g.drawLine(1, 3, 1, height - 1); // b, vertical
311 g.drawLine(0, height - 1, 0, height); // b, vertical
313 g.setColor(c);
314 g.drawLine(width - 1, height - 1, // c, one pixel
315 width - 1, height - 1);
317 g.setColor(d);
318 g.drawLine(2, height, width, height); // d, horizontal
319 g.drawLine(width, 2, width, height - 1); // d, vertical
321 finally
323 g.translate(-x, -y);
324 g.setColor(oldColor);