jdk/src/share/classes/javax/swing/JToolBar.java
author dmarkov
Wed, 16 Apr 2014 12:51:25 +0400
changeset 24184 4da2f6ec4dab
parent 22574 7f8ce0c8c20a
child 24982 37fe99dfd9e9
permissions -rw-r--r--
8032874: ArrayIndexOutOfBoundsException in JTable while clearing data in JTable Reviewed-by: alexp, alexsch
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
22574
7f8ce0c8c20a 8032627: Add @SuppressWarnings("serial") to appropriate javax.swing classes
darcy
parents: 20458
diff changeset
     2
 * Copyright (c) 1997, 2014, 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
package javax.swing;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.Color;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.Component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.awt.ComponentOrientation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.awt.Container;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.awt.Dimension;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.awt.Graphics;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.awt.Insets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.awt.LayoutManager;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.awt.LayoutManager2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.awt.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.beans.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import javax.swing.border.Border;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import javax.swing.plaf.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import javax.accessibility.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import java.io.Serializable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import java.io.ObjectOutputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import java.io.ObjectInputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
import java.util.Hashtable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * <code>JToolBar</code> provides a component that is useful for
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * displaying commonly used <code>Action</code>s or controls.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * For examples and information on using tool bars see
20455
f6f9a0c2796b 8020688: Broken links in documentation at http://docs.oracle.com/javase/6/docs/api/index.
mcherkas
parents: 20157
diff changeset
    55
 * <a href="http://docs.oracle.com/javase/tutorial/uiswing/components/toolbar.html">How to Use Tool Bars</a>,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * a section in <em>The Java Tutorial</em>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * With most look and feels,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * the user can drag out a tool bar into a separate window
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * (unless the <code>floatable</code> property is set to <code>false</code>).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * For drag-out to work correctly, it is recommended that you add
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * <code>JToolBar</code> instances to one of the four "sides" of a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * container whose layout manager is a <code>BorderLayout</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * and do not add children to any of the other four "sides".
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * <strong>Warning:</strong> Swing is not thread safe. For more
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * information see <a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * href="package-summary.html#threading">Swing's Threading
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * Policy</a>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * <strong>Warning:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * Serialized objects of this class will not be compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * future Swing releases. The current serialization support is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * appropriate for short term storage or RMI between applications running
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * the same version of Swing.  As of 1.4, support for long term storage
20458
f2423fb3fd19 8025840: Fix all the doclint warnings about trademark
cl
parents: 20455
diff changeset
    77
 * of all JavaBeans&trade;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * has been added to the <code>java.beans</code> package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * Please see {@link java.beans.XMLEncoder}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 *   attribute: isContainer true
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 * description: A component which displays commonly used controls or Actions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 * @author Georges Saab
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 * @author Jeff Shapiro
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 * @see Action
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 */
22574
7f8ce0c8c20a 8032627: Add @SuppressWarnings("serial") to appropriate javax.swing classes
darcy
parents: 20458
diff changeset
    89
@SuppressWarnings("serial") // Same-version serialization only
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
public class JToolBar extends JComponent implements SwingConstants, Accessible
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * @see #getUIClassID
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * @see #readObject
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    private static final String uiClassID = "ToolBarUI";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    private    boolean   paintBorder              = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    private    Insets    margin                   = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    private    boolean   floatable                = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    private    int       orientation              = HORIZONTAL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * Creates a new tool bar; orientation defaults to <code>HORIZONTAL</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    public JToolBar()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        this( HORIZONTAL );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * Creates a new tool bar with the specified <code>orientation</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * The <code>orientation</code> must be either <code>HORIZONTAL</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * or <code>VERTICAL</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * @param orientation  the orientation desired
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    public JToolBar( int orientation )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        this(null, orientation);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * Creates a new tool bar with the specified <code>name</code>.  The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * name is used as the title of the undocked tool bar.  The default
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * orientation is <code>HORIZONTAL</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * @param name the name of the tool bar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    public JToolBar( String name ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        this(name, HORIZONTAL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * Creates a new tool bar with a specified <code>name</code> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * <code>orientation</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * All other constructors call this constructor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * If <code>orientation</code> is an invalid value, an exception will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * be thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * @param name  the name of the tool bar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * @param orientation  the initial orientation -- it must be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     *          either <code>HORIZONTAL</code> or <code>VERTICAL</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * @exception IllegalArgumentException if orientation is neither
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     *          <code>HORIZONTAL</code> nor <code>VERTICAL</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    public JToolBar( String name , int orientation) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        setName(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        checkOrientation( orientation );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        this.orientation = orientation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        DefaultToolBarLayout layout =  new DefaultToolBarLayout( orientation );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        setLayout( layout );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        addPropertyChangeListener( layout );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        updateUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * Returns the tool bar's current UI.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * @see #setUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    public ToolBarUI getUI() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        return (ToolBarUI)ui;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    /**
20157
cafca01a8e28 8025230: [cleanup] some more javadoc formatting fixes for swing
yan
parents: 5506
diff changeset
   171
     * Sets the L&amp;F object that renders this component.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     *
20157
cafca01a8e28 8025230: [cleanup] some more javadoc formatting fixes for swing
yan
parents: 5506
diff changeset
   173
     * @param ui  the <code>ToolBarUI</code> L&amp;F object
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * @see UIDefaults#getUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     *        bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     *       hidden: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     *    attribute: visualUpdate true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     *  description: The UI object that implements the Component's LookAndFeel.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    public void setUI(ToolBarUI ui) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        super.setUI(ui);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    /**
20157
cafca01a8e28 8025230: [cleanup] some more javadoc formatting fixes for swing
yan
parents: 5506
diff changeset
   186
     * Notification from the <code>UIFactory</code> that the L&amp;F has changed.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * Called to replace the UI with the latest version from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * <code>UIFactory</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * @see JComponent#updateUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    public void updateUI() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        setUI((ToolBarUI)UIManager.getUI(this));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        // GTKLookAndFeel installs a different LayoutManager, and sets it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        // to null after changing the look and feel, so, install the default
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        // if the LayoutManager is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        if (getLayout() == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
            setLayout(new DefaultToolBarLayout(getOrientation()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        invalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    /**
20157
cafca01a8e28 8025230: [cleanup] some more javadoc formatting fixes for swing
yan
parents: 5506
diff changeset
   206
     * Returns the name of the L&amp;F class that renders this component.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * @return the string "ToolBarUI"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * @see JComponent#getUIClassID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * @see UIDefaults#getUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    public String getUIClassID() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        return uiClassID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * Returns the index of the specified component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * (Note: Separators occupy index positions.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * @param c  the <code>Component</code> to find
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * @return an integer indicating the component's position,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     *          where 0 is first
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    public int getComponentIndex(Component c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        int ncomponents = this.getComponentCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        Component[] component = this.getComponents();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        for (int i = 0 ; i < ncomponents ; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
            Component comp = component[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
            if (comp == c)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
                return i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * Returns the component at the specified index.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * @param i  the component's position, where 0 is first
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * @return   the <code>Component</code> at that position,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     *          or <code>null</code> for an invalid index
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    public Component getComponentAtIndex(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        int ncomponents = this.getComponentCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        if ( i >= 0 && i < ncomponents) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            Component[] component = this.getComponents();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
            return component[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
      * Sets the margin between the tool bar's border and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
      * its buttons. Setting to <code>null</code> causes the tool bar to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
      * use the default margins. The tool bar's default <code>Border</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
      * object uses this value to create the proper margin.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
      * However, if a non-default border is set on the tool bar,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
      * it is that <code>Border</code> object's responsibility to create the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
      * appropriate margin space (otherwise this property will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
      * effectively be ignored).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
      * @param m an <code>Insets</code> object that defines the space
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
      *         between the border and the buttons
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
      * @see Insets
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
      * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
      * description: The margin between the tool bar's border and contents
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
      *       bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
      *      expert: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     public void setMargin(Insets m)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
         Insets old = margin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
         margin = m;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
         firePropertyChange("margin", old, m);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
         revalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
         repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
      * Returns the margin between the tool bar's border and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
      * its buttons.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
      * @return an <code>Insets</code> object containing the margin values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
      * @see Insets
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     public Insets getMargin()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
         if(margin == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
             return new Insets(0,0,0,0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
         } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
             return margin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
      * Gets the <code>borderPainted</code> property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
      * @return the value of the <code>borderPainted</code> property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
      * @see #setBorderPainted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     public boolean isBorderPainted()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
         return paintBorder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
      * Sets the <code>borderPainted</code> property, which is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
      * <code>true</code> if the border should be painted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
      * The default value for this property is <code>true</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
      * Some look and feels might not implement painted borders;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
      * they will ignore this property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
      * @param b if true, the border is painted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
      * @see #isBorderPainted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
      * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
      * description: Does the tool bar paint its borders?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
      *       bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
      *      expert: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     public void setBorderPainted(boolean b)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
         if ( paintBorder != b )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
         {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
             boolean old = paintBorder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
             paintBorder = b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
             firePropertyChange("borderPainted", old, b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
             revalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
             repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
      * Paints the tool bar's border if the <code>borderPainted</code> property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
      * is <code>true</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
      * @param g  the <code>Graphics</code> context in which the painting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
      *         is done
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
      * @see JComponent#paint
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
      * @see JComponent#setBorder
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     protected void paintBorder(Graphics g)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
         if (isBorderPainted())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
         {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
             super.paintBorder(g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     * Gets the <code>floatable</code> property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     * @return the value of the <code>floatable</code> property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
     * @see #setFloatable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
    public boolean isFloatable()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        return floatable;
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
      * Sets the <code>floatable</code> property,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
      * which must be <code>true</code> for the user to move the tool bar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
      * Typically, a floatable tool bar can be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
      * dragged into a different position within the same container
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
      * or out into its own window.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
      * The default value of this property is <code>true</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
      * Some look and feels might not implement floatable tool bars;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
      * they will ignore this property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
      * @param b if <code>true</code>, the tool bar can be moved;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
      *          <code>false</code> otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
      * @see #isFloatable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
      * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
      * description: Can the tool bar be made to float by the user?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
      *       bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
      *   preferred: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
    public void setFloatable( boolean b )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
        if ( floatable != b )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
            boolean old = floatable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
            floatable = b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
            firePropertyChange("floatable", old, b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
            revalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
            repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     * Returns the current orientation of the tool bar.  The value is either
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
     * <code>HORIZONTAL</code> or <code>VERTICAL</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
     * @return an integer representing the current orientation -- either
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
     *          <code>HORIZONTAL</code> or <code>VERTICAL</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
     * @see #setOrientation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
    public int getOrientation()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
        return this.orientation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
     * Sets the orientation of the tool bar.  The orientation must have
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
     * either the value <code>HORIZONTAL</code> or <code>VERTICAL</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     * If <code>orientation</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     * an invalid value, an exception will be thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     * @param o  the new orientation -- either <code>HORIZONTAL</code> or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     *                  <code>VERTICAL</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     * @exception IllegalArgumentException if orientation is neither
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
     *          <code>HORIZONTAL</code> nor <code>VERTICAL</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
     * @see #getOrientation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
     * description: The current orientation of the tool bar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
     *       bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
     *   preferred: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
     *        enum: HORIZONTAL SwingConstants.HORIZONTAL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
     *              VERTICAL   SwingConstants.VERTICAL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
    public void setOrientation( int o )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
        checkOrientation( o );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        if ( orientation != o )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
            int old = orientation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
            orientation = o;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
            firePropertyChange("orientation", old, o);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
            revalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
            repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
     * Sets the rollover state of this toolbar. If the rollover state is true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
     * then the border of the toolbar buttons will be drawn only when the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
     * mouse pointer hovers over them. The default value of this property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
     * is false.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
     * The implementation of a look and feel may choose to ignore this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
     * property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
     * @param rollover true for rollover toolbar buttons; otherwise false
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
     *        bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
     *    preferred: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
     *    attribute: visualUpdate true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
     *  description: Will draw rollover button borders in the toolbar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
    public void setRollover(boolean rollover) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
        putClientProperty("JToolBar.isRollover",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
                          rollover ? Boolean.TRUE : Boolean.FALSE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
     * Returns the rollover state.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
     * @return true if rollover toolbar buttons are to be drawn; otherwise false
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
     * @see #setRollover(boolean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
    public boolean isRollover() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
        Boolean rollover = (Boolean)getClientProperty("JToolBar.isRollover");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
        if (rollover != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
            return rollover.booleanValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
    private void checkOrientation( int orientation )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
        switch ( orientation )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
            case VERTICAL:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
            case HORIZONTAL:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
            default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
                throw new IllegalArgumentException( "orientation must be one of: VERTICAL, HORIZONTAL" );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
     * Appends a separator of default size to the end of the tool bar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
     * The default size is determined by the current look and feel.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
    public void addSeparator()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
        addSeparator(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
     * Appends a separator of a specified size to the end
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
     * of the tool bar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
     * @param size the <code>Dimension</code> of the separator
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
    public void addSeparator( Dimension size )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
        JToolBar.Separator s = new JToolBar.Separator( size );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
        add(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
     * Adds a new <code>JButton</code> which dispatches the action.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
     * @param a the <code>Action</code> object to add as a new menu item
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
     * @return the new button which dispatches the action
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
    public JButton add(Action a) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
        JButton b = createActionComponent(a);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
        b.setAction(a);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
        add(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
        return b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
     * Factory method which creates the <code>JButton</code> for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
     * <code>Action</code>s added to the <code>JToolBar</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
     * The default name is empty if a <code>null</code> action is passed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
     * @param a the <code>Action</code> for the button to be added
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
     * @return the newly created button
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
     * @see Action
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
    protected JButton createActionComponent(Action a) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
        JButton b = new JButton() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
            protected PropertyChangeListener createActionPropertyChangeListener(Action a) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
                PropertyChangeListener pcl = createActionChangeListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
                if (pcl==null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
                    pcl = super.createActionPropertyChangeListener(a);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
                return pcl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
        if (a != null && (a.getValue(Action.SMALL_ICON) != null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
                          a.getValue(Action.LARGE_ICON_KEY) != null)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
            b.setHideActionText(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
        b.setHorizontalTextPosition(JButton.CENTER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
        b.setVerticalTextPosition(JButton.BOTTOM);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
        return b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
     * Returns a properly configured <code>PropertyChangeListener</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
     * which updates the control as changes to the <code>Action</code> occur,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
     * or <code>null</code> if the default
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
     * property change listener for the control is desired.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
     * @return <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
    protected PropertyChangeListener createActionChangeListener(JButton b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
     * If a <code>JButton</code> is being added, it is initially
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
     * set to be disabled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
     * @param comp  the component to be enhanced
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
     * @param constraints  the constraints to be enforced on the component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
     * @param index the index of the component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
    protected void addImpl(Component comp, Object constraints, int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
        if (comp instanceof Separator) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
            if (getOrientation() == VERTICAL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
                ( (Separator)comp ).setOrientation(JSeparator.HORIZONTAL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
                ( (Separator)comp ).setOrientation(JSeparator.VERTICAL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
        super.addImpl(comp, constraints, index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
        if (comp instanceof JButton) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
            ((JButton)comp).setDefaultCapable(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
     * A toolbar-specific separator. An object with dimension but
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
     * no contents used to divide buttons on a tool bar into groups.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
    static public class Separator extends JSeparator
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
        private Dimension separatorSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
         * Creates a new toolbar separator with the default size
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
         * as defined by the current look and feel.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
        public Separator()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
            this( null );  // let the UI define the default size
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
         * Creates a new toolbar separator with the specified size.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
         * @param size the <code>Dimension</code> of the separator
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
        public Separator( Dimension size )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
            super( JSeparator.HORIZONTAL );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
            setSeparatorSize(size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
        /**
20157
cafca01a8e28 8025230: [cleanup] some more javadoc formatting fixes for swing
yan
parents: 5506
diff changeset
   617
         * Returns the name of the L&amp;F class that renders this component.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
         * @return the string "ToolBarSeparatorUI"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
         * @see JComponent#getUIClassID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
         * @see UIDefaults#getUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
        public String getUIClassID()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
            return "ToolBarSeparatorUI";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
         * Sets the size of the separator.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
         * @param size the new <code>Dimension</code> of the separator
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
        public void setSeparatorSize( Dimension size )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
            if (size != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
                separatorSize = size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
                super.updateUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
            this.invalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
         * Returns the size of the separator
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
         * @return the <code>Dimension</code> object containing the separator's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
         *         size (This is a reference, NOT a copy!)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
        public Dimension getSeparatorSize()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
            return separatorSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
         * Returns the minimum size for the separator.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
         * @return the <code>Dimension</code> object containing the separator's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
         *         minimum size
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
        public Dimension getMinimumSize()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
            if (separatorSize != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
                return separatorSize.getSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
                return super.getMinimumSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
         * Returns the maximum size for the separator.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
         * @return the <code>Dimension</code> object containing the separator's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
         *         maximum size
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
        public Dimension getMaximumSize()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
            if (separatorSize != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
                return separatorSize.getSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
                return super.getMaximumSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
         * Returns the preferred size for the separator.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
         * @return the <code>Dimension</code> object containing the separator's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
         *         preferred size
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
        public Dimension getPreferredSize()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
            if (separatorSize != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
                return separatorSize.getSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
                return super.getPreferredSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
     * See <code>readObject</code> and <code>writeObject</code> in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
     * <code>JComponent</code> for more
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
     * information about serialization in Swing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
    private void writeObject(ObjectOutputStream s) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
        s.defaultWriteObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
        if (getUIClassID().equals(uiClassID)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
            byte count = JComponent.getWriteObjCounter(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
            JComponent.setWriteObjCounter(this, --count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
            if (count == 0 && ui != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
                ui.installUI(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
     * Returns a string representation of this <code>JToolBar</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
     * This method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
     * is intended to be used only for debugging purposes, and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
     * content and format of the returned string may vary between
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
     * implementations. The returned string may be empty but may not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
     * be <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
     * @return  a string representation of this <code>JToolBar</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
    protected String paramString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
        String paintBorderString = (paintBorder ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
                                    "true" : "false");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
        String marginString = (margin != null ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
                               margin.toString() : "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
        String floatableString = (floatable ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
                                  "true" : "false");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
        String orientationString = (orientation == HORIZONTAL ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
                                    "HORIZONTAL" : "VERTICAL");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
        return super.paramString() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
        ",floatable=" + floatableString +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
        ",margin=" + marginString +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
        ",orientation=" + orientationString +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
        ",paintBorder=" + paintBorderString;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
    private class DefaultToolBarLayout
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
        implements LayoutManager2, Serializable, PropertyChangeListener, UIResource {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
        BoxLayout lm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
        DefaultToolBarLayout(int orientation) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
            if (orientation == JToolBar.VERTICAL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
                lm = new BoxLayout(JToolBar.this, BoxLayout.PAGE_AXIS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
                lm = new BoxLayout(JToolBar.this, BoxLayout.LINE_AXIS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
        public void addLayoutComponent(String name, Component comp) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
            lm.addLayoutComponent(name, comp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
        public void addLayoutComponent(Component comp, Object constraints) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
            lm.addLayoutComponent(comp, constraints);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
        public void removeLayoutComponent(Component comp) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
            lm.removeLayoutComponent(comp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
        public Dimension preferredLayoutSize(Container target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
            return lm.preferredLayoutSize(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
        public Dimension minimumLayoutSize(Container target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
            return lm.minimumLayoutSize(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
        public Dimension maximumLayoutSize(Container target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
            return lm.maximumLayoutSize(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
        public void layoutContainer(Container target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
            lm.layoutContainer(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
        public float getLayoutAlignmentX(Container target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
            return lm.getLayoutAlignmentX(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
        public float getLayoutAlignmentY(Container target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
            return lm.getLayoutAlignmentY(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
        public void invalidateLayout(Container target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
            lm.invalidateLayout(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
        public void propertyChange(PropertyChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
            String name = e.getPropertyName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
            if( name.equals("orientation") ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
                int o = ((Integer)e.getNewValue()).intValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
                if (o == JToolBar.VERTICAL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
                    lm = new BoxLayout(JToolBar.this, BoxLayout.PAGE_AXIS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
                    lm = new BoxLayout(JToolBar.this, BoxLayout.LINE_AXIS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
    public void setLayout(LayoutManager mgr) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
        LayoutManager oldMgr = getLayout();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
        if (oldMgr instanceof PropertyChangeListener) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
            removePropertyChangeListener((PropertyChangeListener)oldMgr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
        super.setLayout(mgr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
/////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
// Accessibility support
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
     * Gets the AccessibleContext associated with this JToolBar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
     * For tool bars, the AccessibleContext takes the form of an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
     * AccessibleJToolBar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
     * A new AccessibleJToolBar instance is created if necessary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
     * @return an AccessibleJToolBar that serves as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
     *         AccessibleContext of this JToolBar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
    public AccessibleContext getAccessibleContext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
        if (accessibleContext == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
            accessibleContext = new AccessibleJToolBar();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
        return accessibleContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
     * This class implements accessibility support for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
     * <code>JToolBar</code> class.  It provides an implementation of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
     * Java Accessibility API appropriate to toolbar user-interface elements.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
    protected class AccessibleJToolBar extends AccessibleJComponent {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
         * Get the state of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
         * @return an instance of AccessibleStateSet containing the current
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
         * state set of the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
         * @see AccessibleState
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
        public AccessibleStateSet getAccessibleStateSet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
            AccessibleStateSet states = super.getAccessibleStateSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
            // FIXME:  [[[WDW - need to add orientation from BoxLayout]]]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
            // FIXME:  [[[WDW - need to do SELECTABLE if SelectionModel is added]]]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
            return states;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
         * Get the role of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
         * @return an instance of AccessibleRole describing the role of the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
        public AccessibleRole getAccessibleRole() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
            return AccessibleRole.TOOL_BAR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
    } // inner class AccessibleJToolBar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
}