0N/A/*
2362N/A * Copyright (c) 1997, 2006, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage javax.swing;
0N/A
0N/Aimport java.awt.Color;
0N/Aimport java.awt.Component;
0N/Aimport java.awt.ComponentOrientation;
0N/Aimport java.awt.Container;
0N/Aimport java.awt.Dimension;
0N/Aimport java.awt.Graphics;
0N/Aimport java.awt.Insets;
0N/Aimport java.awt.LayoutManager;
0N/Aimport java.awt.LayoutManager2;
0N/Aimport java.awt.event.*;
0N/Aimport java.beans.*;
0N/A
0N/Aimport javax.swing.border.Border;
0N/Aimport javax.swing.plaf.*;
0N/Aimport javax.accessibility.*;
0N/A
0N/Aimport java.io.Serializable;
0N/Aimport java.io.ObjectOutputStream;
0N/Aimport java.io.ObjectInputStream;
0N/Aimport java.io.IOException;
0N/Aimport java.util.Hashtable;
0N/A
0N/A
0N/A/**
0N/A * <code>JToolBar</code> provides a component that is useful for
0N/A * displaying commonly used <code>Action</code>s or controls.
0N/A * For examples and information on using tool bars see
0N/A * <a href="http://java.sun.com/docs/books/tutorial/uiswing/components/toolbar.html">How to Use Tool Bars</a>,
0N/A * a section in <em>The Java Tutorial</em>.
0N/A *
0N/A * <p>
0N/A * With most look and feels,
0N/A * the user can drag out a tool bar into a separate window
0N/A * (unless the <code>floatable</code> property is set to <code>false</code>).
0N/A * For drag-out to work correctly, it is recommended that you add
0N/A * <code>JToolBar</code> instances to one of the four "sides" of a
0N/A * container whose layout manager is a <code>BorderLayout</code>,
0N/A * and do not add children to any of the other four "sides".
0N/A * <p>
0N/A * <strong>Warning:</strong> Swing is not thread safe. For more
0N/A * information see <a
0N/A * href="package-summary.html#threading">Swing's Threading
0N/A * Policy</a>.
0N/A * <p>
0N/A * <strong>Warning:</strong>
0N/A * Serialized objects of this class will not be compatible with
0N/A * future Swing releases. The current serialization support is
0N/A * appropriate for short term storage or RMI between applications running
0N/A * the same version of Swing. As of 1.4, support for long term storage
0N/A * of all JavaBeans<sup><font size="-2">TM</font></sup>
0N/A * has been added to the <code>java.beans</code> package.
0N/A * Please see {@link java.beans.XMLEncoder}.
0N/A *
0N/A * @beaninfo
0N/A * attribute: isContainer true
0N/A * description: A component which displays commonly used controls or Actions.
0N/A *
0N/A * @author Georges Saab
0N/A * @author Jeff Shapiro
0N/A * @see Action
0N/A */
0N/Apublic class JToolBar extends JComponent implements SwingConstants, Accessible
0N/A{
0N/A /**
0N/A * @see #getUIClassID
0N/A * @see #readObject
0N/A */
0N/A private static final String uiClassID = "ToolBarUI";
0N/A
0N/A private boolean paintBorder = true;
0N/A private Insets margin = null;
0N/A private boolean floatable = true;
0N/A private int orientation = HORIZONTAL;
0N/A
0N/A /**
0N/A * Creates a new tool bar; orientation defaults to <code>HORIZONTAL</code>.
0N/A */
0N/A public JToolBar()
0N/A {
0N/A this( HORIZONTAL );
0N/A }
0N/A
0N/A /**
0N/A * Creates a new tool bar with the specified <code>orientation</code>.
0N/A * The <code>orientation</code> must be either <code>HORIZONTAL</code>
0N/A * or <code>VERTICAL</code>.
0N/A *
0N/A * @param orientation the orientation desired
0N/A */
0N/A public JToolBar( int orientation )
0N/A {
0N/A this(null, orientation);
0N/A }
0N/A
0N/A /**
0N/A * Creates a new tool bar with the specified <code>name</code>. The
0N/A * name is used as the title of the undocked tool bar. The default
0N/A * orientation is <code>HORIZONTAL</code>.
0N/A *
0N/A * @param name the name of the tool bar
0N/A * @since 1.3
0N/A */
0N/A public JToolBar( String name ) {
0N/A this(name, HORIZONTAL);
0N/A }
0N/A
0N/A /**
0N/A * Creates a new tool bar with a specified <code>name</code> and
0N/A * <code>orientation</code>.
0N/A * All other constructors call this constructor.
0N/A * If <code>orientation</code> is an invalid value, an exception will
0N/A * be thrown.
0N/A *
0N/A * @param name the name of the tool bar
0N/A * @param orientation the initial orientation -- it must be
0N/A * either <code>HORIZONTAL</code> or <code>VERTICAL</code>
0N/A * @exception IllegalArgumentException if orientation is neither
0N/A * <code>HORIZONTAL</code> nor <code>VERTICAL</code>
0N/A * @since 1.3
0N/A */
0N/A public JToolBar( String name , int orientation) {
0N/A setName(name);
0N/A checkOrientation( orientation );
0N/A
0N/A this.orientation = orientation;
0N/A DefaultToolBarLayout layout = new DefaultToolBarLayout( orientation );
0N/A setLayout( layout );
0N/A
0N/A addPropertyChangeListener( layout );
0N/A
0N/A updateUI();
0N/A }
0N/A
0N/A /**
0N/A * Returns the tool bar's current UI.
0N/A * @see #setUI
0N/A */
0N/A public ToolBarUI getUI() {
0N/A return (ToolBarUI)ui;
0N/A }
0N/A
0N/A /**
0N/A * Sets the L&F object that renders this component.
0N/A *
0N/A * @param ui the <code>ToolBarUI</code> L&F object
0N/A * @see UIDefaults#getUI
0N/A * @beaninfo
0N/A * bound: true
0N/A * hidden: true
0N/A * attribute: visualUpdate true
0N/A * description: The UI object that implements the Component's LookAndFeel.
0N/A */
0N/A public void setUI(ToolBarUI ui) {
0N/A super.setUI(ui);
0N/A }
0N/A
0N/A /**
0N/A * Notification from the <code>UIFactory</code> that the L&F has changed.
0N/A * Called to replace the UI with the latest version from the
0N/A * <code>UIFactory</code>.
0N/A *
0N/A * @see JComponent#updateUI
0N/A */
0N/A public void updateUI() {
0N/A setUI((ToolBarUI)UIManager.getUI(this));
0N/A // GTKLookAndFeel installs a different LayoutManager, and sets it
0N/A // to null after changing the look and feel, so, install the default
0N/A // if the LayoutManager is null.
0N/A if (getLayout() == null) {
0N/A setLayout(new DefaultToolBarLayout(getOrientation()));
0N/A }
0N/A invalidate();
0N/A }
0N/A
0N/A
0N/A
0N/A /**
0N/A * Returns the name of the L&F class that renders this component.
0N/A *
0N/A * @return the string "ToolBarUI"
0N/A * @see JComponent#getUIClassID
0N/A * @see UIDefaults#getUI
0N/A */
0N/A public String getUIClassID() {
0N/A return uiClassID;
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Returns the index of the specified component.
0N/A * (Note: Separators occupy index positions.)
0N/A *
0N/A * @param c the <code>Component</code> to find
0N/A * @return an integer indicating the component's position,
0N/A * where 0 is first
0N/A */
0N/A public int getComponentIndex(Component c) {
0N/A int ncomponents = this.getComponentCount();
0N/A Component[] component = this.getComponents();
0N/A for (int i = 0 ; i < ncomponents ; i++) {
0N/A Component comp = component[i];
0N/A if (comp == c)
0N/A return i;
0N/A }
0N/A return -1;
0N/A }
0N/A
0N/A /**
0N/A * Returns the component at the specified index.
0N/A *
0N/A * @param i the component's position, where 0 is first
0N/A * @return the <code>Component</code> at that position,
0N/A * or <code>null</code> for an invalid index
0N/A *
0N/A */
0N/A public Component getComponentAtIndex(int i) {
0N/A int ncomponents = this.getComponentCount();
0N/A if ( i >= 0 && i < ncomponents) {
0N/A Component[] component = this.getComponents();
0N/A return component[i];
0N/A }
0N/A return null;
0N/A }
0N/A
0N/A /**
0N/A * Sets the margin between the tool bar's border and
0N/A * its buttons. Setting to <code>null</code> causes the tool bar to
0N/A * use the default margins. The tool bar's default <code>Border</code>
0N/A * object uses this value to create the proper margin.
0N/A * However, if a non-default border is set on the tool bar,
0N/A * it is that <code>Border</code> object's responsibility to create the
0N/A * appropriate margin space (otherwise this property will
0N/A * effectively be ignored).
0N/A *
0N/A * @param m an <code>Insets</code> object that defines the space
0N/A * between the border and the buttons
0N/A * @see Insets
0N/A * @beaninfo
0N/A * description: The margin between the tool bar's border and contents
0N/A * bound: true
0N/A * expert: true
0N/A */
0N/A public void setMargin(Insets m)
0N/A {
0N/A Insets old = margin;
0N/A margin = m;
0N/A firePropertyChange("margin", old, m);
0N/A revalidate();
0N/A repaint();
0N/A }
0N/A
0N/A /**
0N/A * Returns the margin between the tool bar's border and
0N/A * its buttons.
0N/A *
0N/A * @return an <code>Insets</code> object containing the margin values
0N/A * @see Insets
0N/A */
0N/A public Insets getMargin()
0N/A {
0N/A if(margin == null) {
0N/A return new Insets(0,0,0,0);
0N/A } else {
0N/A return margin;
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Gets the <code>borderPainted</code> property.
0N/A *
0N/A * @return the value of the <code>borderPainted</code> property
0N/A * @see #setBorderPainted
0N/A */
0N/A public boolean isBorderPainted()
0N/A {
0N/A return paintBorder;
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Sets the <code>borderPainted</code> property, which is
0N/A * <code>true</code> if the border should be painted.
0N/A * The default value for this property is <code>true</code>.
0N/A * Some look and feels might not implement painted borders;
0N/A * they will ignore this property.
0N/A *
0N/A * @param b if true, the border is painted
0N/A * @see #isBorderPainted
0N/A * @beaninfo
0N/A * description: Does the tool bar paint its borders?
0N/A * bound: true
0N/A * expert: true
0N/A */
0N/A public void setBorderPainted(boolean b)
0N/A {
0N/A if ( paintBorder != b )
0N/A {
0N/A boolean old = paintBorder;
0N/A paintBorder = b;
0N/A firePropertyChange("borderPainted", old, b);
0N/A revalidate();
0N/A repaint();
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Paints the tool bar's border if the <code>borderPainted</code> property
0N/A * is <code>true</code>.
0N/A *
0N/A * @param g the <code>Graphics</code> context in which the painting
0N/A * is done
0N/A * @see JComponent#paint
0N/A * @see JComponent#setBorder
0N/A */
0N/A protected void paintBorder(Graphics g)
0N/A {
0N/A if (isBorderPainted())
0N/A {
0N/A super.paintBorder(g);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Gets the <code>floatable</code> property.
0N/A *
0N/A * @return the value of the <code>floatable</code> property
0N/A *
0N/A * @see #setFloatable
0N/A */
0N/A public boolean isFloatable()
0N/A {
0N/A return floatable;
0N/A }
0N/A
0N/A /**
0N/A * Sets the <code>floatable</code> property,
0N/A * which must be <code>true</code> for the user to move the tool bar.
0N/A * Typically, a floatable tool bar can be
0N/A * dragged into a different position within the same container
0N/A * or out into its own window.
0N/A * The default value of this property is <code>true</code>.
0N/A * Some look and feels might not implement floatable tool bars;
0N/A * they will ignore this property.
0N/A *
0N/A * @param b if <code>true</code>, the tool bar can be moved;
0N/A * <code>false</code> otherwise
0N/A * @see #isFloatable
0N/A * @beaninfo
0N/A * description: Can the tool bar be made to float by the user?
0N/A * bound: true
0N/A * preferred: true
0N/A */
0N/A public void setFloatable( boolean b )
0N/A {
0N/A if ( floatable != b )
0N/A {
0N/A boolean old = floatable;
0N/A floatable = b;
0N/A
0N/A firePropertyChange("floatable", old, b);
0N/A revalidate();
0N/A repaint();
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Returns the current orientation of the tool bar. The value is either
0N/A * <code>HORIZONTAL</code> or <code>VERTICAL</code>.
0N/A *
0N/A * @return an integer representing the current orientation -- either
0N/A * <code>HORIZONTAL</code> or <code>VERTICAL</code>
0N/A * @see #setOrientation
0N/A */
0N/A public int getOrientation()
0N/A {
0N/A return this.orientation;
0N/A }
0N/A
0N/A /**
0N/A * Sets the orientation of the tool bar. The orientation must have
0N/A * either the value <code>HORIZONTAL</code> or <code>VERTICAL</code>.
0N/A * If <code>orientation</code> is
0N/A * an invalid value, an exception will be thrown.
0N/A *
0N/A * @param o the new orientation -- either <code>HORIZONTAL</code> or
0N/A * <code>VERTICAL</code>
0N/A * @exception IllegalArgumentException if orientation is neither
0N/A * <code>HORIZONTAL</code> nor <code>VERTICAL</code>
0N/A * @see #getOrientation
0N/A * @beaninfo
0N/A * description: The current orientation of the tool bar
0N/A * bound: true
0N/A * preferred: true
0N/A * enum: HORIZONTAL SwingConstants.HORIZONTAL
0N/A * VERTICAL SwingConstants.VERTICAL
0N/A */
0N/A public void setOrientation( int o )
0N/A {
0N/A checkOrientation( o );
0N/A
0N/A if ( orientation != o )
0N/A {
0N/A int old = orientation;
0N/A orientation = o;
0N/A
0N/A firePropertyChange("orientation", old, o);
0N/A revalidate();
0N/A repaint();
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Sets the rollover state of this toolbar. If the rollover state is true
0N/A * then the border of the toolbar buttons will be drawn only when the
0N/A * mouse pointer hovers over them. The default value of this property
0N/A * is false.
0N/A * <p>
0N/A * The implementation of a look and feel may choose to ignore this
0N/A * property.
0N/A *
0N/A * @param rollover true for rollover toolbar buttons; otherwise false
0N/A * @since 1.4
0N/A * @beaninfo
0N/A * bound: true
0N/A * preferred: true
0N/A * attribute: visualUpdate true
0N/A * description: Will draw rollover button borders in the toolbar.
0N/A */
0N/A public void setRollover(boolean rollover) {
0N/A putClientProperty("JToolBar.isRollover",
0N/A rollover ? Boolean.TRUE : Boolean.FALSE);
0N/A }
0N/A
0N/A /**
0N/A * Returns the rollover state.
0N/A *
0N/A * @return true if rollover toolbar buttons are to be drawn; otherwise false
0N/A * @see #setRollover(boolean)
0N/A * @since 1.4
0N/A */
0N/A public boolean isRollover() {
0N/A Boolean rollover = (Boolean)getClientProperty("JToolBar.isRollover");
0N/A if (rollover != null) {
0N/A return rollover.booleanValue();
0N/A }
0N/A return false;
0N/A }
0N/A
0N/A private void checkOrientation( int orientation )
0N/A {
0N/A switch ( orientation )
0N/A {
0N/A case VERTICAL:
0N/A case HORIZONTAL:
0N/A break;
0N/A default:
0N/A throw new IllegalArgumentException( "orientation must be one of: VERTICAL, HORIZONTAL" );
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Appends a separator of default size to the end of the tool bar.
0N/A * The default size is determined by the current look and feel.
0N/A */
0N/A public void addSeparator()
0N/A {
0N/A addSeparator(null);
0N/A }
0N/A
0N/A /**
0N/A * Appends a separator of a specified size to the end
0N/A * of the tool bar.
0N/A *
0N/A * @param size the <code>Dimension</code> of the separator
0N/A */
0N/A public void addSeparator( Dimension size )
0N/A {
0N/A JToolBar.Separator s = new JToolBar.Separator( size );
0N/A add(s);
0N/A }
0N/A
0N/A /**
0N/A * Adds a new <code>JButton</code> which dispatches the action.
0N/A *
0N/A * @param a the <code>Action</code> object to add as a new menu item
0N/A * @return the new button which dispatches the action
0N/A */
0N/A public JButton add(Action a) {
0N/A JButton b = createActionComponent(a);
0N/A b.setAction(a);
0N/A add(b);
0N/A return b;
0N/A }
0N/A
0N/A /**
0N/A * Factory method which creates the <code>JButton</code> for
0N/A * <code>Action</code>s added to the <code>JToolBar</code>.
0N/A * The default name is empty if a <code>null</code> action is passed.
0N/A *
0N/A * @param a the <code>Action</code> for the button to be added
0N/A * @return the newly created button
0N/A * @see Action
0N/A * @since 1.3
0N/A */
0N/A protected JButton createActionComponent(Action a) {
0N/A JButton b = new JButton() {
0N/A protected PropertyChangeListener createActionPropertyChangeListener(Action a) {
0N/A PropertyChangeListener pcl = createActionChangeListener(this);
0N/A if (pcl==null) {
0N/A pcl = super.createActionPropertyChangeListener(a);
0N/A }
0N/A return pcl;
0N/A }
0N/A };
0N/A if (a != null && (a.getValue(Action.SMALL_ICON) != null ||
0N/A a.getValue(Action.LARGE_ICON_KEY) != null)) {
0N/A b.setHideActionText(true);
0N/A }
0N/A b.setHorizontalTextPosition(JButton.CENTER);
0N/A b.setVerticalTextPosition(JButton.BOTTOM);
0N/A return b;
0N/A }
0N/A
0N/A /**
0N/A * Returns a properly configured <code>PropertyChangeListener</code>
0N/A * which updates the control as changes to the <code>Action</code> occur,
0N/A * or <code>null</code> if the default
0N/A * property change listener for the control is desired.
0N/A *
0N/A * @return <code>null</code>
0N/A */
0N/A protected PropertyChangeListener createActionChangeListener(JButton b) {
0N/A return null;
0N/A }
0N/A
0N/A /**
0N/A * If a <code>JButton</code> is being added, it is initially
0N/A * set to be disabled.
0N/A *
0N/A * @param comp the component to be enhanced
0N/A * @param constraints the constraints to be enforced on the component
0N/A * @param index the index of the component
0N/A *
0N/A */
0N/A protected void addImpl(Component comp, Object constraints, int index) {
0N/A if (comp instanceof Separator) {
0N/A if (getOrientation() == VERTICAL) {
0N/A ( (Separator)comp ).setOrientation(JSeparator.HORIZONTAL);
0N/A } else {
0N/A ( (Separator)comp ).setOrientation(JSeparator.VERTICAL);
0N/A }
0N/A }
0N/A super.addImpl(comp, constraints, index);
0N/A if (comp instanceof JButton) {
0N/A ((JButton)comp).setDefaultCapable(false);
0N/A }
0N/A }
0N/A
0N/A
0N/A /**
0N/A * A toolbar-specific separator. An object with dimension but
0N/A * no contents used to divide buttons on a tool bar into groups.
0N/A */
0N/A static public class Separator extends JSeparator
0N/A {
0N/A private Dimension separatorSize;
0N/A
0N/A /**
0N/A * Creates a new toolbar separator with the default size
0N/A * as defined by the current look and feel.
0N/A */
0N/A public Separator()
0N/A {
0N/A this( null ); // let the UI define the default size
0N/A }
0N/A
0N/A /**
0N/A * Creates a new toolbar separator with the specified size.
0N/A *
0N/A * @param size the <code>Dimension</code> of the separator
0N/A */
0N/A public Separator( Dimension size )
0N/A {
0N/A super( JSeparator.HORIZONTAL );
0N/A setSeparatorSize(size);
0N/A }
0N/A
0N/A /**
0N/A * Returns the name of the L&F class that renders this component.
0N/A *
0N/A * @return the string "ToolBarSeparatorUI"
0N/A * @see JComponent#getUIClassID
0N/A * @see UIDefaults#getUI
0N/A */
0N/A public String getUIClassID()
0N/A {
0N/A return "ToolBarSeparatorUI";
0N/A }
0N/A
0N/A /**
0N/A * Sets the size of the separator.
0N/A *
0N/A * @param size the new <code>Dimension</code> of the separator
0N/A */
0N/A public void setSeparatorSize( Dimension size )
0N/A {
0N/A if (size != null) {
0N/A separatorSize = size;
0N/A } else {
0N/A super.updateUI();
0N/A }
0N/A this.invalidate();
0N/A }
0N/A
0N/A /**
0N/A * Returns the size of the separator
0N/A *
0N/A * @return the <code>Dimension</code> object containing the separator's
0N/A * size (This is a reference, NOT a copy!)
0N/A */
0N/A public Dimension getSeparatorSize()
0N/A {
0N/A return separatorSize;
0N/A }
0N/A
0N/A /**
0N/A * Returns the minimum size for the separator.
0N/A *
0N/A * @return the <code>Dimension</code> object containing the separator's
0N/A * minimum size
0N/A */
0N/A public Dimension getMinimumSize()
0N/A {
0N/A if (separatorSize != null) {
0N/A return separatorSize.getSize();
0N/A } else {
0N/A return super.getMinimumSize();
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Returns the maximum size for the separator.
0N/A *
0N/A * @return the <code>Dimension</code> object containing the separator's
0N/A * maximum size
0N/A */
0N/A public Dimension getMaximumSize()
0N/A {
0N/A if (separatorSize != null) {
0N/A return separatorSize.getSize();
0N/A } else {
0N/A return super.getMaximumSize();
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Returns the preferred size for the separator.
0N/A *
0N/A * @return the <code>Dimension</code> object containing the separator's
0N/A * preferred size
0N/A */
0N/A public Dimension getPreferredSize()
0N/A {
0N/A if (separatorSize != null) {
0N/A return separatorSize.getSize();
0N/A } else {
0N/A return super.getPreferredSize();
0N/A }
0N/A }
0N/A }
0N/A
0N/A
0N/A /**
0N/A * See <code>readObject</code> and <code>writeObject</code> in
0N/A * <code>JComponent</code> for more
0N/A * information about serialization in Swing.
0N/A */
0N/A private void writeObject(ObjectOutputStream s) throws IOException {
0N/A s.defaultWriteObject();
0N/A if (getUIClassID().equals(uiClassID)) {
0N/A byte count = JComponent.getWriteObjCounter(this);
0N/A JComponent.setWriteObjCounter(this, --count);
0N/A if (count == 0 && ui != null) {
0N/A ui.installUI(this);
0N/A }
0N/A }
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Returns a string representation of this <code>JToolBar</code>.
0N/A * This method
0N/A * is intended to be used only for debugging purposes, and the
0N/A * content and format of the returned string may vary between
0N/A * implementations. The returned string may be empty but may not
0N/A * be <code>null</code>.
0N/A *
0N/A * @return a string representation of this <code>JToolBar</code>.
0N/A */
0N/A protected String paramString() {
0N/A String paintBorderString = (paintBorder ?
0N/A "true" : "false");
0N/A String marginString = (margin != null ?
0N/A margin.toString() : "");
0N/A String floatableString = (floatable ?
0N/A "true" : "false");
0N/A String orientationString = (orientation == HORIZONTAL ?
0N/A "HORIZONTAL" : "VERTICAL");
0N/A
0N/A return super.paramString() +
0N/A ",floatable=" + floatableString +
0N/A ",margin=" + marginString +
0N/A ",orientation=" + orientationString +
0N/A ",paintBorder=" + paintBorderString;
0N/A }
0N/A
0N/A
0N/A private class DefaultToolBarLayout
0N/A implements LayoutManager2, Serializable, PropertyChangeListener, UIResource {
0N/A
0N/A BoxLayout lm;
0N/A
0N/A DefaultToolBarLayout(int orientation) {
0N/A if (orientation == JToolBar.VERTICAL) {
0N/A lm = new BoxLayout(JToolBar.this, BoxLayout.PAGE_AXIS);
0N/A } else {
0N/A lm = new BoxLayout(JToolBar.this, BoxLayout.LINE_AXIS);
0N/A }
0N/A }
0N/A
0N/A public void addLayoutComponent(String name, Component comp) {
0N/A lm.addLayoutComponent(name, comp);
0N/A }
0N/A
0N/A public void addLayoutComponent(Component comp, Object constraints) {
0N/A lm.addLayoutComponent(comp, constraints);
0N/A }
0N/A
0N/A public void removeLayoutComponent(Component comp) {
0N/A lm.removeLayoutComponent(comp);
0N/A }
0N/A
0N/A public Dimension preferredLayoutSize(Container target) {
0N/A return lm.preferredLayoutSize(target);
0N/A }
0N/A
0N/A public Dimension minimumLayoutSize(Container target) {
0N/A return lm.minimumLayoutSize(target);
0N/A }
0N/A
0N/A public Dimension maximumLayoutSize(Container target) {
0N/A return lm.maximumLayoutSize(target);
0N/A }
0N/A
0N/A public void layoutContainer(Container target) {
0N/A lm.layoutContainer(target);
0N/A }
0N/A
0N/A public float getLayoutAlignmentX(Container target) {
0N/A return lm.getLayoutAlignmentX(target);
0N/A }
0N/A
0N/A public float getLayoutAlignmentY(Container target) {
0N/A return lm.getLayoutAlignmentY(target);
0N/A }
0N/A
0N/A public void invalidateLayout(Container target) {
0N/A lm.invalidateLayout(target);
0N/A }
0N/A
0N/A public void propertyChange(PropertyChangeEvent e) {
0N/A String name = e.getPropertyName();
0N/A if( name.equals("orientation") ) {
0N/A int o = ((Integer)e.getNewValue()).intValue();
0N/A
0N/A if (o == JToolBar.VERTICAL)
0N/A lm = new BoxLayout(JToolBar.this, BoxLayout.PAGE_AXIS);
0N/A else {
0N/A lm = new BoxLayout(JToolBar.this, BoxLayout.LINE_AXIS);
0N/A }
0N/A }
0N/A }
0N/A }
0N/A
0N/A
0N/A public void setLayout(LayoutManager mgr) {
0N/A LayoutManager oldMgr = getLayout();
0N/A if (oldMgr instanceof PropertyChangeListener) {
0N/A removePropertyChangeListener((PropertyChangeListener)oldMgr);
0N/A }
0N/A super.setLayout(mgr);
0N/A }
0N/A
0N/A/////////////////
0N/A// Accessibility support
0N/A////////////////
0N/A
0N/A /**
0N/A * Gets the AccessibleContext associated with this JToolBar.
0N/A * For tool bars, the AccessibleContext takes the form of an
0N/A * AccessibleJToolBar.
0N/A * A new AccessibleJToolBar instance is created if necessary.
0N/A *
0N/A * @return an AccessibleJToolBar that serves as the
0N/A * AccessibleContext of this JToolBar
0N/A */
0N/A public AccessibleContext getAccessibleContext() {
0N/A if (accessibleContext == null) {
0N/A accessibleContext = new AccessibleJToolBar();
0N/A }
0N/A return accessibleContext;
0N/A }
0N/A
0N/A /**
0N/A * This class implements accessibility support for the
0N/A * <code>JToolBar</code> class. It provides an implementation of the
0N/A * Java Accessibility API appropriate to toolbar user-interface elements.
0N/A */
0N/A protected class AccessibleJToolBar extends AccessibleJComponent {
0N/A
0N/A /**
0N/A * Get the state of this object.
0N/A *
0N/A * @return an instance of AccessibleStateSet containing the current
0N/A * state set of the object
0N/A * @see AccessibleState
0N/A */
0N/A public AccessibleStateSet getAccessibleStateSet() {
0N/A AccessibleStateSet states = super.getAccessibleStateSet();
0N/A // FIXME: [[[WDW - need to add orientation from BoxLayout]]]
0N/A // FIXME: [[[WDW - need to do SELECTABLE if SelectionModel is added]]]
0N/A return states;
0N/A }
0N/A
0N/A /**
0N/A * Get the role of this object.
0N/A *
0N/A * @return an instance of AccessibleRole describing the role of the object
0N/A */
0N/A public AccessibleRole getAccessibleRole() {
0N/A return AccessibleRole.TOOL_BAR;
0N/A }
0N/A } // inner class AccessibleJToolBar
0N/A}