1 /* CompoundBorder.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)
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., 59 Temple Place, Suite 330, Boston, MA
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
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. */
39 package javax
.swing
.border
;
41 import java
.awt
.Component
;
42 import java
.awt
.Graphics
;
43 import java
.awt
.Insets
;
46 * A Border that is composed of an interior and an exterior border,
47 * where the interior border is tightly nested into the exterior.
49 * @author Sascha Brawer (brawer@dandelis.ch)
51 public class CompoundBorder
52 extends AbstractBorder
55 * Determined using the <code>serialver</code> tool
56 * of Apple/Sun JDK 1.3.1 on MacOS X 10.1.5.
58 static final long serialVersionUID
= 9054540377030555103L;
62 * The inside border, which is painted between the bordered
63 * Component and the outside border. It is valid for
64 * <code>insideBorder</code> to be <code>null</code>.
66 protected Border insideBorder
;
70 * The outside border, which is painted outside both the
71 * bordered Component and the inside border. It is valid for
72 * <code>outsideBorder</code> to be <code>null</code>.
74 protected Border outsideBorder
;
78 * Constructs a CompoundBorder whose inside and outside borders
79 * are both <code>null</code>. While this does not really make
80 * any sense (there exists a class EmptyBorder as well, and not
81 * every Component needs to have a border at all), the API
82 * specification requires the existence of this constructor.
86 public CompoundBorder ()
93 * Constructs a CompoundBorder with the specified inside and
96 * @param outsideBorder the outside border, which is painted to the
97 * outside of both <code>insideBorder</code> and the enclosed
98 * component. It is acceptable to pass <code>null</code>, in
99 * which case no outside border is painted.
101 * @param insideBorder the inside border, which is painted to
102 * between <code>outsideBorder</code> and the enclosed
103 * component. It is acceptable to pass <code>null</code>, in
104 * which case no inside border is painted.
106 public CompoundBorder (Border outsideBorder
, Border insideBorder
)
108 this.outsideBorder
= outsideBorder
;
109 this.insideBorder
= insideBorder
;
114 * Determines whether or not this border is opaque. An opaque
115 * border fills every pixel in its area when painting. Partially
116 * translucent borders must return <code>false</code>, or ugly
117 * artifacts can appear on screen.
119 * @return <code>true</code> if both the inside and outside borders
120 * are opaque, or <code>false</code> otherwise.
122 public boolean isBorderOpaque ()
124 /* While it would be safe to assume true for the opacity of
125 * a null border, this behavior would not be according to
126 * the API specification. Also, it is pathological to have
127 * null borders anyway.
129 if ((insideBorder
== null) || (outsideBorder
== null))
132 return insideBorder
.isBorderOpaque()
133 && outsideBorder
.isBorderOpaque();
138 * Paints the compound border by first painting the outside border,
139 * then painting the inside border tightly nested into the outside.
141 * @param c the component whose border is to be painted.
142 * @param g the graphics for painting.
143 * @param x the horizontal position for painting the border.
144 * @param y the vertical position for painting the border.
145 * @param width the width of the available area for painting the border.
146 * @param height the height of the available area for painting the border.
148 public void paintBorder(Component c
, Graphics g
,
149 int x
, int y
, int width
, int height
)
151 /* If there is an outside border, paint it and reduce the
152 * bounding box by its insets.
154 if (outsideBorder
!= null)
156 Insets outsideInsets
;
158 outsideBorder
.paintBorder(c
, g
, x
, y
, width
, height
);
159 outsideInsets
= outsideBorder
.getBorderInsets(c
);
161 x
+= outsideInsets
.left
;
162 y
+= outsideInsets
.top
;
164 /* Reduce width and height by the respective extent of the
167 width
-= outsideInsets
.left
+ outsideInsets
.right
;
168 height
-= outsideInsets
.top
+ outsideInsets
.bottom
;
171 if (insideBorder
!= null)
172 insideBorder
.paintBorder(c
, g
, x
, y
, width
, height
);
177 * Changes the specified insets to the insets of this border,
178 * which is the sum of the insets of the inside and the outside
181 * @param c the component in the center of this border.
182 * @param insets an Insets object for holding the added insets.
184 * @return the <code>insets</code> object.
186 public Insets
getBorderInsets(Component c
, Insets insets
)
191 insets
= new Insets (0,0,0,0);
193 insets
.left
= insets
.right
= insets
.top
= insets
.bottom
= 0;
195 /* If there is an outside border, add it to insets. */
196 if (outsideBorder
!= null)
198 borderInsets
= outsideBorder
.getBorderInsets(c
);
199 insets
.left
+= borderInsets
.left
;
200 insets
.right
+= borderInsets
.right
;
201 insets
.top
+= borderInsets
.top
;
202 insets
.bottom
+= borderInsets
.bottom
;
205 /* If there is an inside border, add it to insets. */
206 if (insideBorder
!= null)
208 borderInsets
= insideBorder
.getBorderInsets(c
);
209 insets
.left
+= borderInsets
.left
;
210 insets
.right
+= borderInsets
.right
;
211 insets
.top
+= borderInsets
.top
;
212 insets
.bottom
+= borderInsets
.bottom
;
220 * Determines the insets of this border, which is the sum of the
221 * insets of the inside and the outside border.
223 * @param c the component in the center of this border.
225 public Insets
getBorderInsets (Component c
)
227 /* It is not clear why CompoundBorder does not simply inherit
228 * the implementation from AbstractBorder. However, we want
229 * to be compatible with the API specification, which overrides
230 * the getBorderInsets(Component) method.
232 return getBorderInsets (c
, null);
237 * Returns the outside border, which is painted outside both the
238 * bordered Component and the inside border. It is valid for the
239 * result to be <code>null</code>.
241 public Border
getOutsideBorder ()
243 return outsideBorder
;
248 * Returns the inside border, which is painted between the bordered
249 * Component and the outside border. It is valid for the result to
250 * be <code>null</code>.
252 public Border
getInsideBorder ()