2004-10-22 Michael Koch <konqueror@gmx.de>
[official-gcc.git] / libjava / javax / swing / Box.java
blob7532d3087124f55134cb43467c0b322440f4fd26
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., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 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.Dimension;
44 import java.awt.LayoutManager;
46 import javax.accessibility.Accessible;
47 import javax.accessibility.AccessibleContext;
48 import javax.accessibility.AccessibleRole;
50 /**
51 * A component that uses a {@link BoxLayout} as Layout Manager.
53 * In addition to that, this class provides a set of static methods for
54 * creating some filler components ('struts' and 'glue') for use in
55 * containers that are laid out using BoxLayout.
57 * @author Ronald Veldema (rveldema@cs.vu.nl)
59 public class Box extends JComponent implements Accessible
61 private static final long serialVersionUID = 1525417495883046342L;
63 // FIXME: disable to make libjava compile; visibility rules are broken
64 protected class AccessibleBox // extends Container.AccessibleAWTContainer
66 private static final long serialVersionUID = -7775079816389931944L;
68 protected AccessibleBox()
72 public AccessibleRole getAccessibleRole()
74 return null;
78 /**
79 * A component that servers as a filler in BoxLayout controlled containers.
81 public static class Filler extends JComponent implements Accessible
83 private static final long serialVersionUID = -1204263191910183998L;
85 // FIXME: disable to make libjava compile; visibility rules are broken
86 protected class AccessibleBoxFiller // extends Component.AccessibleAWTComponent
88 private static final long serialVersionUID = 164963348357479321L;
90 protected AccessibleBoxFiller()
94 public AccessibleRole getAccessibleRole()
96 return null;
100 protected AccessibleContext accessibleContext;
102 private transient Dimension min, pref, max;
105 * Creates a new instance of Filler.
107 * @param min the minimum size of the filler.
108 * @param pref the preferred size of the filler.
109 * @param max the maximum size of the filler.
111 public Filler(Dimension min, Dimension pref, Dimension max)
113 changeShape(min, pref, max);
117 * Changes the dimensions of this Filler.
119 * @param min the new minimum size of the filler.
120 * @param pref the new preferred size of the filler.
121 * @param max the new maximum size of the filler.
123 public void changeShape(Dimension min, Dimension pref, Dimension max)
125 this.min = min;
126 this.pref = pref;
127 this.max = max;
130 public AccessibleContext getAccessibleContext()
132 // FIXME: disable to make libjava compile; visibility rules are broken
133 // if (accessibleContext == null)
134 // accessibleContext = new AccessibleBoxFiller();
135 return accessibleContext;
139 * Returns the maximum size of this Filler.
141 * @return the maximum size of this Filler.
143 public Dimension getMaximumSize()
145 return max;
149 * Returns the minimum size of this Filler.
151 * @return the minimum size of this Filler.
153 public Dimension getMinimumSize()
155 return min;
159 * Returns the preferred size of this Filler.
161 * @return the preferred size of this Filler.
163 public Dimension getPreferredSize()
165 return pref;
170 * Creates a new Box component, that lays out its children according
171 * to the <code>axis</code> parameter.
173 * @param axis the orientation of the BoxLayout.
175 * @see BoxLayout#X_AXIS
176 * @see BoxLayout#Y_AXIS
177 * @see BoxLayout#LINE_AXIS
178 * @see BoxLayout#PAGE_AXIS
180 public Box(int axis)
182 super.setLayout(new BoxLayout(this, axis));
186 * Creates a filler component which acts as glue between components.
187 * It does not take space unless some extra space is available. If extra
188 * space is available, this component can expand in both X and Y directions.
190 * @return a glue-like filler component.
192 public static Component createGlue()
194 Filler glue = new Filler(new Dimension(0,0), new Dimension(0,0),
195 new Dimension(Integer.MAX_VALUE,Integer.MAX_VALUE)
197 return glue;
200 public static Box createHorizontalBox()
202 return new Box(BoxLayout.X_AXIS);
206 * Creates a filler component which acts as glue between components.
207 * It does not take space unless some extra space is available. If extra
208 * space is available, this component can expand in the X direction.
210 * @return a glue-like filler component.
212 public static Component createHorizontalGlue()
214 return createGlue();
218 * Creates a filler component which acts as strut between components.
219 * It will fill exactly the specified horizontal size.
221 * @param width the width of this strut in pixels.
223 * @return a strut-like filler component.
225 public static Component createHorizontalStrut(int width)
227 Filler strut = new Filler(new Dimension(width, 0),
228 new Dimension(width, 0),
229 new Dimension(width, Integer.MAX_VALUE));
230 return strut;
233 public static Component createRigidArea(Dimension d)
235 return new Filler(d, d, d);
238 public static Box createVerticalBox()
240 return new Box(BoxLayout.Y_AXIS);
244 * Creates a filler component which acts as glue between components.
245 * It does not take space unless some extra space is available. If extra
246 * space is available, this component can expand in the Y direction.
248 * @return a glue-like filler component.
250 public static Component createVerticalGlue()
252 return createGlue();
256 * Creates a filler component which acts as strut between components.
257 * It will fill exactly the specified vertical size.
259 * @param height the height of this strut in pixels.
261 * @return a strut-like filler component.
263 public static Component createVerticalStrut(int height)
265 Filler strut = new Filler(new Dimension(0, height),
266 new Dimension(0, height),
267 new Dimension(Integer.MAX_VALUE, height));
268 return strut;
271 public void setLayout(LayoutManager l)
273 throw new AWTError("Not allowed to set layout managers for boxes.");
276 public AccessibleContext getAccessibleContext()
278 // if (accessibleContext == null)
279 // accessibleContext = new AccessibleBox();
280 return accessibleContext;