jdk/src/share/classes/javax/swing/Box.java
author malenkov
Wed, 07 May 2008 23:20:32 +0400
changeset 466 6acd5ec503a8
parent 2 90ce3da70b43
child 5506 202f599c92aa
permissions -rw-r--r--
4935607: RFE: LTP: Should be possible to set the TRANSIENT attribute of propertiies to FALSE Summary: Add the Transient annotation and support it (JSR-273) Reviewed-by: peterz, loneid
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 1997-2007 Sun Microsystems, Inc.  All Rights Reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
package javax.swing;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.awt.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.beans.ConstructorProperties;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.util.Locale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.io.Serializable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import javax.accessibility.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * A lightweight container
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * that uses a BoxLayout object as its layout manager.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * Box provides several class methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * that are useful for containers using BoxLayout --
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * even non-Box containers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * The <code>Box</code> class can create several kinds
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * of invisible components
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * that affect layout:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * glue, struts, and rigid areas.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * If all the components your <code>Box</code> contains
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * have a fixed size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * you might want to use a glue component
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * (returned by <code>createGlue</code>)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * to control the components' positions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * If you need a fixed amount of space between two components,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * try using a strut
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * (<code>createHorizontalStrut</code> or <code>createVerticalStrut</code>).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * If you need an invisible component
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * that always takes up the same amount of space,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * get it by invoking <code>createRigidArea</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * If you are implementing a <code>BoxLayout</code> you
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * can find further information and examples in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * <a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 href="http://java.sun.com/docs/books/tutorial/uiswing/layout/box.html">How to Use BoxLayout</a>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * a section in <em>The Java Tutorial.</em>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * <strong>Warning:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * Serialized objects of this class will not be compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * future Swing releases. The current serialization support is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * appropriate for short term storage or RMI between applications running
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * the same version of Swing.  As of 1.4, support for long term storage
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * of all JavaBeans<sup><font size="-2">TM</font></sup>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * has been added to the <code>java.beans</code> package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * Please see {@link java.beans.XMLEncoder}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * @see BoxLayout
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * @author  Timothy Prinzing
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
public class Box extends JComponent implements Accessible {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * Creates a <code>Box</code> that displays its components
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * along the the specified axis.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     * @param axis  can be {@link BoxLayout#X_AXIS},
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     *              {@link BoxLayout#Y_AXIS},
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     *              {@link BoxLayout#LINE_AXIS} or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     *              {@link BoxLayout#PAGE_AXIS}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * @throws AWTError if the <code>axis</code> is invalid
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * @see #createHorizontalBox
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * @see #createVerticalBox
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    public Box(int axis) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        super.setLayout(new BoxLayout(this, axis));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     * Creates a <code>Box</code> that displays its components
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * from left to right. If you want a <code>Box</code> that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * respects the component orientation you should create the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * <code>Box</code> using the constructor and pass in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * <code>BoxLayout.LINE_AXIS</code>, eg:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     *   Box lineBox = new Box(BoxLayout.LINE_AXIS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * @return the box
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    public static Box createHorizontalBox() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        return new Box(BoxLayout.X_AXIS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * Creates a <code>Box</code> that displays its components
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * from top to bottom. If you want a <code>Box</code> that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * respects the component orientation you should create the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * <code>Box</code> using the constructor and pass in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * <code>BoxLayout.PAGE_AXIS</code>, eg:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     *   Box lineBox = new Box(BoxLayout.PAGE_AXIS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * @return the box
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    public static Box createVerticalBox() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        return new Box(BoxLayout.Y_AXIS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * Creates an invisible component that's always the specified size.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * <!-- WHEN WOULD YOU USE THIS AS OPPOSED TO A STRUT? -->
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * @param d the dimensions of the invisible component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * @return the component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * @see #createGlue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * @see #createHorizontalStrut
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * @see #createVerticalStrut
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    public static Component createRigidArea(Dimension d) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        return new Filler(d, d, d);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * Creates an invisible, fixed-width component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * In a horizontal box,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * you typically use this method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * to force a certain amount of space between two components.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * In a vertical box,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * you might use this method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     * to force the box to be at least the specified width.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * The invisible component has no height
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * unless excess space is available,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * in which case it takes its share of available space,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * just like any other component that has no maximum height.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * @param width the width of the invisible component, in pixels >= 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * @return the component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * @see #createVerticalStrut
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * @see #createGlue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * @see #createRigidArea
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    public static Component createHorizontalStrut(int width) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        return new Filler(new Dimension(width,0), new Dimension(width,0),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
                          new Dimension(width, Short.MAX_VALUE));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * Creates an invisible, fixed-height component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * In a vertical box,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * you typically use this method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * to force a certain amount of space between two components.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * In a horizontal box,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * you might use this method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * to force the box to be at least the specified height.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * The invisible component has no width
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * unless excess space is available,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * in which case it takes its share of available space,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * just like any other component that has no maximum width.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * @param height the height of the invisible component, in pixels >= 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * @return the component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * @see #createHorizontalStrut
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     * @see #createGlue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * @see #createRigidArea
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    public static Component createVerticalStrut(int height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        return new Filler(new Dimension(0,height), new Dimension(0,height),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                          new Dimension(Short.MAX_VALUE, height));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * Creates an invisible "glue" component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * that can be useful in a Box
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * whose visible components have a maximum width
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * (for a horizontal box)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * or height (for a vertical box).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * You can think of the glue component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * as being a gooey substance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * that expands as much as necessary
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * to fill the space between its neighboring components.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * For example, suppose you have
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * a horizontal box that contains two fixed-size components.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * If the box gets extra space,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * the fixed-size components won't become larger,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    * so where does the extra space go?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * Without glue,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * the extra space goes to the right of the second component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * If you put glue between the fixed-size components,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * then the extra space goes there.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * If you put glue before the first fixed-size component,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * the extra space goes there,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * and the fixed-size components are shoved against the right
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * edge of the box.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * If you put glue before the first fixed-size component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * and after the second fixed-size component,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * the fixed-size components are centered in the box.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     * To use glue,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * call <code>Box.createGlue</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * and add the returned component to a container.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * The glue component has no minimum or preferred size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     * so it takes no space unless excess space is available.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * If excess space is available,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * then the glue component takes its share of available
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * horizontal or vertical space,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * just like any other component that has no maximum width or height.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * @return the component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    public static Component createGlue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        return new Filler(new Dimension(0,0), new Dimension(0,0),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
                          new Dimension(Short.MAX_VALUE, Short.MAX_VALUE));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * Creates a horizontal glue component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     * @return the component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    public static Component createHorizontalGlue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        return new Filler(new Dimension(0,0), new Dimension(0,0),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
                          new Dimension(Short.MAX_VALUE, 0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     * Creates a vertical glue component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * @return the component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    public static Component createVerticalGlue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        return new Filler(new Dimension(0,0), new Dimension(0,0),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
                          new Dimension(0, Short.MAX_VALUE));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     * Throws an AWTError, since a Box can use only a BoxLayout.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     * @param l the layout manager to use
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    public void setLayout(LayoutManager l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        throw new AWTError("Illegal request");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     * Paints this <code>Box</code>.  If this <code>Box</code> has a UI this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * method invokes super's implementation, otherwise if this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * <code>Box</code> is opaque the <code>Graphics</code> is filled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * using the background.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * @param g the <code>Graphics</code> to paint to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * @throws NullPointerException if <code>g</code> is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    protected void paintComponent(Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        if (ui != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
            // On the off chance some one created a UI, honor it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
            super.paintComponent(g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        } else if (isOpaque()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
            g.setColor(getBackground());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
            g.fillRect(0, 0, getWidth(), getHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     * An implementation of a lightweight component that participates in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     * layout but has no view.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     * <strong>Warning:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     * Serialized objects of this class will not be compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     * future Swing releases. The current serialization support is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     * appropriate for short term storage or RMI between applications running
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     * the same version of Swing.  As of 1.4, support for long term storage
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     * of all JavaBeans<sup><font size="-2">TM</font></sup>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     * has been added to the <code>java.beans</code> package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     * Please see {@link java.beans.XMLEncoder}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
    public static class Filler extends JComponent implements Accessible {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
         * Constructor to create shape with the given size ranges.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
         * @param min   Minimum size
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
         * @param pref  Preferred size
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
         * @param max   Maximum size
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        @ConstructorProperties({"minimumSize", "preferredSize", "maximumSize"})
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        public Filler(Dimension min, Dimension pref, Dimension max) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
            setMinimumSize(min);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
            setPreferredSize(pref);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
            setMaximumSize(max);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
         * Change the size requests for this shape.  An invalidate() is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
         * propagated upward as a result so that layout will eventually
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
         * happen with using the new sizes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
         * @param min   Value to return for getMinimumSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
         * @param pref  Value to return for getPreferredSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
         * @param max   Value to return for getMaximumSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        public void changeShape(Dimension min, Dimension pref, Dimension max) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
            setMinimumSize(min);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
            setPreferredSize(pref);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
            setMaximumSize(max);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
            revalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        // ---- Component methods ------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
         * Paints this <code>Filler</code>.  If this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
         * <code>Filler</code> has a UI this method invokes super's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
         * implementation, otherwise if this <code>Filler</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
         * opaque the <code>Graphics</code> is filled using the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
         * background.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
         * @param g the <code>Graphics</code> to paint to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
         * @throws NullPointerException if <code>g</code> is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
         * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        protected void paintComponent(Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
            if (ui != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
                // On the off chance some one created a UI, honor it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
                super.paintComponent(g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
            } else if (isOpaque()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
                g.setColor(getBackground());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
                g.fillRect(0, 0, getWidth(), getHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
/////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
// Accessibility support for Box$Filler
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
         * Gets the AccessibleContext associated with this Box.Filler.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
         * For box fillers, the AccessibleContext takes the form of an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
         * AccessibleBoxFiller.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
         * A new AccessibleAWTBoxFiller instance is created if necessary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
         * @return an AccessibleBoxFiller that serves as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
         *         AccessibleContext of this Box.Filler.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
        public AccessibleContext getAccessibleContext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
            if (accessibleContext == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
                accessibleContext = new AccessibleBoxFiller();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
            return accessibleContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
         * This class implements accessibility support for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
         * <code>Box.Filler</code> class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
        protected class AccessibleBoxFiller extends AccessibleAWTComponent {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
            // AccessibleContext methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
             * Gets the role of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
             * @return an instance of AccessibleRole describing the role of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
             *   the object (AccessibleRole.FILLER)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
             * @see AccessibleRole
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
            public AccessibleRole getAccessibleRole() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
                return AccessibleRole.FILLER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
/////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
// Accessibility support for Box
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
     * Gets the AccessibleContext associated with this Box.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     * For boxes, the AccessibleContext takes the form of an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
     * AccessibleBox.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
     * A new AccessibleAWTBox instance is created if necessary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
     * @return an AccessibleBox that serves as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     *         AccessibleContext of this Box
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
    public AccessibleContext getAccessibleContext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
        if (accessibleContext == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
            accessibleContext = new AccessibleBox();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
        return accessibleContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
     * This class implements accessibility support for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
     * <code>Box</code> class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
    protected class AccessibleBox extends AccessibleAWTContainer {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
        // AccessibleContext methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
         * Gets the role of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
         * @return an instance of AccessibleRole describing the role of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
         *   object (AccessibleRole.FILLER)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
         * @see AccessibleRole
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
        public AccessibleRole getAccessibleRole() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
            return AccessibleRole.FILLER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
    } // inner class AccessibleBox
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
}