jdk/src/share/classes/javax/swing/Box.java
author mcherkas
Fri, 04 Oct 2013 20:13:32 +0400
changeset 20455 f6f9a0c2796b
parent 11268 f0e59c4852de
child 20458 f2423fb3fd19
permissions -rw-r--r--
8020688: Broken links in documentation at http://docs.oracle.com/javase/6/docs/api/index. Reviewed-by: anthony, alexsch
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 1997, 2007, Oracle and/or its affiliates. All rights reserved.
2
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
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
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
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
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
20455
f6f9a0c2796b 8020688: Broken links in documentation at http://docs.oracle.com/javase/6/docs/api/index.
mcherkas
parents: 11268
diff changeset
    63
 href="http://docs.oracle.com/javase/tutorial/uiswing/layout/box.html">How to Use BoxLayout</a>,
2
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
 */
11268
f0e59c4852de 7116950: Reduce number of warnings in swing
alexsch
parents: 5506
diff changeset
    79
@SuppressWarnings("serial")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
public class Box extends JComponent implements Accessible {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * Creates a <code>Box</code> that displays its components
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * along the the specified axis.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * @param axis  can be {@link BoxLayout#X_AXIS},
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     *              {@link BoxLayout#Y_AXIS},
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     *              {@link BoxLayout#LINE_AXIS} or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     *              {@link BoxLayout#PAGE_AXIS}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * @throws AWTError if the <code>axis</code> is invalid
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * @see #createHorizontalBox
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * @see #createVerticalBox
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    public Box(int axis) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        super.setLayout(new BoxLayout(this, axis));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * Creates a <code>Box</code> that displays its components
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * from left to right. If you want a <code>Box</code> that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * respects the component orientation you should create the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * <code>Box</code> using the constructor and pass in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * <code>BoxLayout.LINE_AXIS</code>, eg:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     *   Box lineBox = new Box(BoxLayout.LINE_AXIS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * @return the box
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    public static Box createHorizontalBox() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        return new Box(BoxLayout.X_AXIS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * Creates a <code>Box</code> that displays its components
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * from top to bottom. If you want a <code>Box</code> that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * respects the component orientation you should create the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * <code>Box</code> using the constructor and pass in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * <code>BoxLayout.PAGE_AXIS</code>, eg:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     *   Box lineBox = new Box(BoxLayout.PAGE_AXIS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * @return the box
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    public static Box createVerticalBox() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        return new Box(BoxLayout.Y_AXIS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * Creates an invisible component that's always the specified size.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * <!-- WHEN WOULD YOU USE THIS AS OPPOSED TO A STRUT? -->
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * @param d the dimensions of the invisible component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * @return the component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * @see #createGlue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * @see #createHorizontalStrut
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * @see #createVerticalStrut
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    public static Component createRigidArea(Dimension d) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        return new Filler(d, d, d);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * Creates an invisible, fixed-width component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * In a horizontal box,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * you typically use this method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * to force a certain amount of space between two components.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * In a vertical box,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     * you might use this method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * to force the box to be at least the specified width.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * The invisible component has no height
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * unless excess space is available,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * in which case it takes its share of available space,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * just like any other component that has no maximum height.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * @param width the width of the invisible component, in pixels >= 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * @return the component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * @see #createVerticalStrut
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * @see #createGlue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * @see #createRigidArea
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    public static Component createHorizontalStrut(int width) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        return new Filler(new Dimension(width,0), new Dimension(width,0),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
                          new Dimension(width, Short.MAX_VALUE));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * Creates an invisible, fixed-height component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * In a vertical box,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * you typically use this method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * to force a certain amount of space between two components.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * In a horizontal box,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * you might use this method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * to force the box to be at least the specified height.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * The invisible component has no width
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * unless excess space is available,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * in which case it takes its share of available space,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * just like any other component that has no maximum width.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * @param height the height of the invisible component, in pixels >= 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * @return the component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     * @see #createHorizontalStrut
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * @see #createGlue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * @see #createRigidArea
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    public static Component createVerticalStrut(int height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        return new Filler(new Dimension(0,height), new Dimension(0,height),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                          new Dimension(Short.MAX_VALUE, height));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * Creates an invisible "glue" component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * that can be useful in a Box
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * whose visible components have a maximum width
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * (for a horizontal box)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * or height (for a vertical box).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * You can think of the glue component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * as being a gooey substance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * that expands as much as necessary
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * to fill the space between its neighboring components.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * For example, suppose you have
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * a horizontal box that contains two fixed-size components.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * If the box gets extra space,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * the fixed-size components won't become larger,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    * so where does the extra space go?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * Without glue,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * the extra space goes to the right of the second component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * If you put glue between the fixed-size components,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * then the extra space goes there.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * If you put glue before the first fixed-size component,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * the extra space goes there,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * and the fixed-size components are shoved against the right
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * edge of the box.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * If you put glue before the first fixed-size component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * and after the second fixed-size component,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * the fixed-size components are centered in the box.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * To use glue,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * call <code>Box.createGlue</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * and add the returned component to a container.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     * The glue component has no minimum or preferred size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * so it takes no space unless excess space is available.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * If excess space is available,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * then the glue component takes its share of available
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * horizontal or vertical space,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * just like any other component that has no maximum width or height.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * @return the component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    public static Component createGlue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        return new Filler(new Dimension(0,0), new Dimension(0,0),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
                          new Dimension(Short.MAX_VALUE, Short.MAX_VALUE));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * Creates a horizontal glue component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     * @return the component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    public static Component createHorizontalGlue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        return new Filler(new Dimension(0,0), new Dimension(0,0),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
                          new Dimension(Short.MAX_VALUE, 0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     * Creates a vertical glue component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * @return the component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    public static Component createVerticalGlue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        return new Filler(new Dimension(0,0), new Dimension(0,0),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
                          new Dimension(0, Short.MAX_VALUE));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * Throws an AWTError, since a Box can use only a BoxLayout.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * @param l the layout manager to use
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    public void setLayout(LayoutManager l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        throw new AWTError("Illegal request");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * Paints this <code>Box</code>.  If this <code>Box</code> has a UI this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * method invokes super's implementation, otherwise if this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * <code>Box</code> is opaque the <code>Graphics</code> is filled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     * using the background.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * @param g the <code>Graphics</code> to paint to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     * @throws NullPointerException if <code>g</code> is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    protected void paintComponent(Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        if (ui != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
            // On the off chance some one created a UI, honor it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
            super.paintComponent(g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        } else if (isOpaque()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
            g.setColor(getBackground());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
            g.fillRect(0, 0, getWidth(), getHeight());
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     * An implementation of a lightweight component that participates in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     * layout but has no view.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     * <strong>Warning:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     * Serialized objects of this class will not be compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     * future Swing releases. The current serialization support is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     * appropriate for short term storage or RMI between applications running
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     * the same version of Swing.  As of 1.4, support for long term storage
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     * of all JavaBeans<sup><font size="-2">TM</font></sup>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     * has been added to the <code>java.beans</code> package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     * Please see {@link java.beans.XMLEncoder}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     */
11268
f0e59c4852de 7116950: Reduce number of warnings in swing
alexsch
parents: 5506
diff changeset
   305
    @SuppressWarnings("serial")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
    public static class Filler extends JComponent implements Accessible {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
         * Constructor to create shape with the given size ranges.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
         * @param min   Minimum size
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
         * @param pref  Preferred size
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
         * @param max   Maximum size
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        @ConstructorProperties({"minimumSize", "preferredSize", "maximumSize"})
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        public Filler(Dimension min, Dimension pref, Dimension max) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
            setMinimumSize(min);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
            setPreferredSize(pref);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
            setMaximumSize(max);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
         * Change the size requests for this shape.  An invalidate() is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
         * propagated upward as a result so that layout will eventually
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
         * happen with using the new sizes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
         * @param min   Value to return for getMinimumSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
         * @param pref  Value to return for getPreferredSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
         * @param max   Value to return for getMaximumSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        public void changeShape(Dimension min, Dimension pref, Dimension max) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
            setMinimumSize(min);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
            setPreferredSize(pref);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
            setMaximumSize(max);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
            revalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        // ---- Component methods ------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
         * Paints this <code>Filler</code>.  If this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
         * <code>Filler</code> has a UI this method invokes super's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
         * implementation, otherwise if this <code>Filler</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
         * opaque the <code>Graphics</code> is filled using the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
         * background.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
         * @param g the <code>Graphics</code> to paint to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
         * @throws NullPointerException if <code>g</code> is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
         * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        protected void paintComponent(Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
            if (ui != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
                // On the off chance some one created a UI, honor it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
                super.paintComponent(g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
            } else if (isOpaque()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
                g.setColor(getBackground());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
                g.fillRect(0, 0, getWidth(), getHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
/////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
// Accessibility support for Box$Filler
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
         * Gets the AccessibleContext associated with this Box.Filler.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
         * For box fillers, the AccessibleContext takes the form of an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
         * AccessibleBoxFiller.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
         * A new AccessibleAWTBoxFiller instance is created if necessary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
         * @return an AccessibleBoxFiller that serves as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
         *         AccessibleContext of this Box.Filler.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
        public AccessibleContext getAccessibleContext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
            if (accessibleContext == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
                accessibleContext = new AccessibleBoxFiller();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
            return accessibleContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
         * This class implements accessibility support for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
         * <code>Box.Filler</code> class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
         */
11268
f0e59c4852de 7116950: Reduce number of warnings in swing
alexsch
parents: 5506
diff changeset
   385
        @SuppressWarnings("serial")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        protected class AccessibleBoxFiller extends AccessibleAWTComponent {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
            // AccessibleContext methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
             * Gets the role of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
             * @return an instance of AccessibleRole describing the role of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
             *   the object (AccessibleRole.FILLER)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
             * @see AccessibleRole
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
            public AccessibleRole getAccessibleRole() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
                return AccessibleRole.FILLER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
/////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
// Accessibility support for Box
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
     * Gets the AccessibleContext associated with this Box.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
     * For boxes, the AccessibleContext takes the form of an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
     * AccessibleBox.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     * A new AccessibleAWTBox instance is created if necessary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     * @return an AccessibleBox that serves as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     *         AccessibleContext of this Box
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
    public AccessibleContext getAccessibleContext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
        if (accessibleContext == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
            accessibleContext = new AccessibleBox();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
        return accessibleContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
     * This class implements accessibility support for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
     * <code>Box</code> class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
     */
11268
f0e59c4852de 7116950: Reduce number of warnings in swing
alexsch
parents: 5506
diff changeset
   426
    @SuppressWarnings("serial")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
    protected class AccessibleBox extends AccessibleAWTContainer {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
        // AccessibleContext methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
         * Gets the role of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
         * @return an instance of AccessibleRole describing the role of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
         *   object (AccessibleRole.FILLER)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
         * @see AccessibleRole
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
        public AccessibleRole getAccessibleRole() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
            return AccessibleRole.FILLER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
    } // inner class AccessibleBox
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
}