001 /* EmptyBorder.java --
002 Copyright (C) 2003 Free Software Foundation, Inc.
003
004 This file is part of GNU Classpath.
005
006 GNU Classpath is free software; you can redistribute it and/or modify
007 it under the terms of the GNU General Public License as published by
008 the Free Software Foundation; either version 2, or (at your option)
009 any later version.
010
011 GNU Classpath is distributed in the hope that it will be useful, but
012 WITHOUT ANY WARRANTY; without even the implied warranty of
013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014 General Public License for more details.
015
016 You should have received a copy of the GNU General Public License
017 along with GNU Classpath; see the file COPYING. If not, write to the
018 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
019 02110-1301 USA.
020
021 Linking this library statically or dynamically with other modules is
022 making a combined work based on this library. Thus, the terms and
023 conditions of the GNU General Public License cover the whole
024 combination.
025
026 As a special exception, the copyright holders of this library give you
027 permission to link this library with independent modules to produce an
028 executable, regardless of the license terms of these independent
029 modules, and to copy and distribute the resulting executable under
030 terms of your choice, provided that you also meet, for each linked
031 independent module, the terms and conditions of the license of that
032 module. An independent module is a module which is not derived from
033 or based on this library. If you modify this library, you may extend
034 this exception to your version of the library, but you are not
035 obligated to do so. If you do not wish to do so, delete this
036 exception statement from your version. */
037
038
039 package javax.swing.border;
040
041 import java.awt.Component;
042 import java.awt.Graphics;
043 import java.awt.Insets;
044
045
046 /**
047 * A border for leaving a specifiable number of pixels empty around
048 * the enclosed component. An EmptyBorder requires some space on each
049 * edge, but does not perform any drawing.
050 *
051 * <p><img src="EmptyBorder-1.png" width="290" height="200"
052 * alt="[An illustration of EmptyBorder]" />
053 *
054 * @author Sascha Brawer (brawer@dandelis.ch)
055 */
056 public class EmptyBorder extends AbstractBorder
057 {
058 /**
059 * Determined using the <code>serialver</code> tool
060 * of Apple/Sun JDK 1.3.1 on MacOS X 10.1.5.
061 */
062 static final long serialVersionUID = -8116076291731988694L;
063
064
065 /**
066 * The number of pixels required at the left edge.
067 */
068 protected int left;
069
070
071 /**
072 * The number of pixels required at the right edge.
073 */
074 protected int right;
075
076
077 /**
078 * The number of pixels required at the top edge.
079 */
080 protected int top;
081
082
083 /**
084 * The number of pixels required at the bottom edge.
085 */
086 protected int bottom;
087
088
089 /**
090 * Constructs an empty border given the number of pixels required
091 * on each side.
092 *
093 * @param top the number of pixels that the border will need
094 * for its top edge.
095 *
096 * @param left the number of pixels that the border will need
097 * for its left edge.
098 *
099 * @param bottom the number of pixels that the border will need
100 * for its bottom edge.
101 *
102 * @param right the number of pixels that the border will need
103 * for its right edge.
104 */
105 public EmptyBorder(int top, int left, int bottom, int right)
106 {
107 this.top = top;
108 this.left = left;
109 this.bottom = bottom;
110 this.right = right;
111 }
112
113
114 /**
115 * Constructs an empty border given the number of pixels required
116 * on each side, passed in an Insets object.
117 *
118 * @param borderInsets the Insets for the new border.
119 */
120 public EmptyBorder(Insets borderInsets)
121 {
122 this(borderInsets.top, borderInsets.left,
123 borderInsets.bottom, borderInsets.right);
124 }
125
126
127 /**
128 * Performs nothing because an EmptyBorder does not paint any
129 * pixels. While the inherited implementation provided by
130 * {@link AbstractBorder#paintBorder} is a no-op as well,
131 * it is overwritten in order to match the API of the Sun
132 * reference implementation.
133 *
134 * @param c the component whose border is to be painted.
135 * @param g the graphics for painting.
136 * @param x the horizontal position for painting the border.
137 * @param y the vertical position for painting the border.
138 * @param width the width of the available area for painting the border.
139 * @param height the height of the available area for painting the border.
140 */
141 public void paintBorder(Component c, Graphics g,
142 int x, int y, int width, int height)
143 {
144 // Nothing to do here.
145 }
146
147
148 /**
149 * Measures the width of this border.
150 *
151 * @param c the component whose border is to be measured.
152 *
153 * @return an Insets object whose <code>left</code>, <code>right</code>,
154 * <code>top</code> and <code>bottom</code> fields indicate the
155 * width of the border at the respective edge.
156 *
157 * @see #getBorderInsets(java.awt.Component, java.awt.Insets)
158 */
159 public Insets getBorderInsets(Component c)
160 {
161 return getBorderInsets(c, null);
162 }
163
164
165 /**
166 * Measures the width of this border, storing the results into a
167 * pre-existing Insets object.
168 *
169 * @param insets an Insets object for holding the result values.
170 * After invoking this method, the <code>left</code>,
171 * <code>right</code>, <code>top</code> and
172 * <code>bottom</code> fields indicate the width of the
173 * border at the respective edge.
174 *
175 * @return the same object that was passed for <code>insets</code>.
176 *
177 * @see #getBorderInsets()
178 */
179 public Insets getBorderInsets(Component c, Insets insets)
180 {
181 if (insets == null)
182 insets = new Insets(0, 0, 0, 0);
183
184 insets.left = left;
185 insets.right = right;
186 insets.top = top;
187 insets.bottom = bottom;
188 return insets;
189 }
190
191
192 /**
193 * Measures the width of this border.
194 *
195 * @return an Insets object whose <code>left</code>, <code>right</code>,
196 * <code>top</code> and <code>bottom</code> fields indicate the
197 * width of the border at the respective edge.
198 *
199 * @see #getBorderInsets(java.awt.Component, java.awt.Insets)
200 */
201 public Insets getBorderInsets()
202 {
203 return getBorderInsets(null, null);
204 }
205
206
207 /**
208 * Determines whether this border fills every pixel in its area
209 * when painting. Since an empty border does not paint any pixels
210 * whatsoever, the result is <code>false</code>.
211 *
212 * @return <code>false</code>.
213 */
214 public boolean isBorderOpaque()
215 {
216 /* The inherited implementation of AbstractBorder.isBorderOpaque()
217 * would also return false. It is not clear why this is overriden
218 * in the Sun implementation, at least not from just reading the
219 * JavaDoc.
220 */
221 return false;
222 }
223 }