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