Dead
[official-gcc.git] / gomp-20050608-branch / libjava / classpath / javax / swing / Box.java
blob57519f6fcbdb6b3365b8641cac1c85897a77666e
1 /* Box.java --
2 Copyright (C) 2002, 2004 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. */
39 package javax.swing;
41 import java.awt.AWTError;
42 import java.awt.Component;
43 import java.awt.Container;
44 import java.awt.Dimension;
45 import java.awt.LayoutManager;
47 import javax.accessibility.Accessible;
48 import javax.accessibility.AccessibleContext;
49 import javax.accessibility.AccessibleRole;
51 /**
52 * A component that uses a {@link BoxLayout} as Layout Manager.
54 * In addition to that, this class provides a set of static methods for
55 * creating some filler components ('struts' and 'glue') for use in
56 * containers that are laid out using BoxLayout.
58 * @author Ronald Veldema (rveldema@cs.vu.nl)
60 public class Box extends JComponent implements Accessible
62 private static final long serialVersionUID = 1525417495883046342L;
64 /**
65 * Provides accessibility support for <code>Box</code>es.
67 protected class AccessibleBox extends Container.AccessibleAWTContainer
69 private static final long serialVersionUID = -7775079816389931944L;
71 protected AccessibleBox()
73 // Nothing to do here.
76 public AccessibleRole getAccessibleRole()
78 return null;
82 /**
83 * A component that servers as a filler in BoxLayout controlled containers.
85 public static class Filler extends JComponent implements Accessible
87 private static final long serialVersionUID = -1204263191910183998L;
89 /**
90 * Provides accessibility support for <code>Box.Filler</code>.
92 protected class AccessibleBoxFiller
93 extends Component.AccessibleAWTComponent
95 private static final long serialVersionUID = 164963348357479321L;
97 protected AccessibleBoxFiller()
99 // Nothing to do here.
102 public AccessibleRole getAccessibleRole()
104 return null;
108 private transient Dimension min, pref, max;
111 * Creates a new instance of Filler.
113 * @param min the minimum size of the filler.
114 * @param pref the preferred size of the filler.
115 * @param max the maximum size of the filler.
117 public Filler(Dimension min, Dimension pref, Dimension max)
119 changeShape(min, pref, max);
123 * Changes the dimensions of this Filler.
125 * @param min the new minimum size of the filler.
126 * @param pref the new preferred size of the filler.
127 * @param max the new maximum size of the filler.
129 public void changeShape(Dimension min, Dimension pref, Dimension max)
131 this.min = min;
132 this.pref = pref;
133 this.max = max;
136 public AccessibleContext getAccessibleContext()
138 if (accessibleContext == null)
139 accessibleContext = new AccessibleBoxFiller();
140 return accessibleContext;
144 * Returns the maximum size of this Filler.
146 * @return the maximum size of this Filler.
148 public Dimension getMaximumSize()
150 return max;
154 * Returns the minimum size of this Filler.
156 * @return the minimum size of this Filler.
158 public Dimension getMinimumSize()
160 return min;
164 * Returns the preferred size of this Filler.
166 * @return the preferred size of this Filler.
168 public Dimension getPreferredSize()
170 return pref;
175 * Creates a new Box component, that lays out its children according
176 * to the <code>axis</code> parameter.
178 * @param axis the orientation of the BoxLayout.
180 * @see BoxLayout#X_AXIS
181 * @see BoxLayout#Y_AXIS
182 * @see BoxLayout#LINE_AXIS
183 * @see BoxLayout#PAGE_AXIS
185 public Box(int axis)
187 super.setLayout(new BoxLayout(this, axis));
191 * Creates a filler component which acts as glue between components.
192 * It does not take space unless some extra space is available. If extra
193 * space is available, this component can expand in both X and Y directions.
195 * @return a glue-like filler component.
197 public static Component createGlue()
199 Filler glue = new Filler(new Dimension(0,0), new Dimension(0,0),
200 new Dimension(Short.MAX_VALUE,Short.MAX_VALUE)
202 return glue;
205 public static Box createHorizontalBox()
207 return new Box(BoxLayout.X_AXIS);
211 * Creates a filler component which acts as glue between components.
212 * It does not take space unless some extra space is available. If extra
213 * space is available, this component can expand in the X direction.
215 * @return a glue-like filler component.
217 public static Component createHorizontalGlue()
219 Filler glue = new Filler(new Dimension(0,0), new Dimension(0,0),
220 new Dimension(Short.MAX_VALUE, 0)
222 return glue;
226 * Creates a filler component which acts as strut between components.
227 * It will fill exactly the specified horizontal size.
229 * @param width the width of this strut in pixels.
231 * @return a strut-like filler component.
233 public static Component createHorizontalStrut(int width)
235 Filler strut = new Filler(new Dimension(width, 0),
236 new Dimension(width, 0),
237 new Dimension(width, Integer.MAX_VALUE));
238 return strut;
241 public static Component createRigidArea(Dimension d)
243 return new Filler(d, d, d);
246 public static Box createVerticalBox()
248 return new Box(BoxLayout.Y_AXIS);
252 * Creates a filler component which acts as glue between components.
253 * It does not take space unless some extra space is available. If extra
254 * space is available, this component can expand in the Y direction.
256 * @return a glue-like filler component.
258 public static Component createVerticalGlue()
260 return createGlue();
264 * Creates a filler component which acts as strut between components.
265 * It will fill exactly the specified vertical size.
267 * @param height the height of this strut in pixels.
269 * @return a strut-like filler component.
271 public static Component createVerticalStrut(int height)
273 Filler strut = new Filler(new Dimension(0, height),
274 new Dimension(0, height),
275 new Dimension(Integer.MAX_VALUE, height));
276 return strut;
279 public void setLayout(LayoutManager l)
281 throw new AWTError("Not allowed to set layout managers for boxes.");
284 public AccessibleContext getAccessibleContext()
286 if (accessibleContext == null)
287 accessibleContext = new AccessibleBox();
288 return accessibleContext;