0N/A/*
2362N/A * Copyright (c) 1997, 2008, 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.plaf.basic;
0N/A
0N/Aimport javax.swing.*;
0N/Aimport javax.swing.event.*;
0N/Aimport java.awt.*;
0N/Aimport java.awt.event.*;
0N/A
0N/Aimport java.beans.*;
0N/A
0N/Aimport java.util.Hashtable;
0N/Aimport java.util.HashMap;
0N/A
0N/Aimport javax.swing.border.*;
0N/Aimport javax.swing.plaf.*;
0N/Aimport sun.swing.DefaultLookup;
0N/Aimport sun.swing.UIAction;
0N/A
0N/A
0N/A/**
0N/A * A Basic L&F implementation of ToolBarUI. This implementation
0N/A * is a "combined" view/controller.
0N/A * <p>
0N/A *
0N/A * @author Georges Saab
0N/A * @author Jeff Shapiro
0N/A */
0N/Apublic class BasicToolBarUI extends ToolBarUI implements SwingConstants
0N/A{
0N/A protected JToolBar toolBar;
0N/A private boolean floating;
0N/A private int floatingX;
0N/A private int floatingY;
0N/A private JFrame floatingFrame;
0N/A private RootPaneContainer floatingToolBar;
0N/A protected DragWindow dragWindow;
0N/A private Container dockingSource;
0N/A private int dockingSensitivity = 0;
0N/A protected int focusedCompIndex = -1;
0N/A
0N/A protected Color dockingColor = null;
0N/A protected Color floatingColor = null;
0N/A protected Color dockingBorderColor = null;
0N/A protected Color floatingBorderColor = null;
0N/A
0N/A protected MouseInputListener dockingListener;
0N/A protected PropertyChangeListener propertyListener;
0N/A
0N/A protected ContainerListener toolBarContListener;
0N/A protected FocusListener toolBarFocusListener;
0N/A private Handler handler;
0N/A
0N/A protected String constraintBeforeFloating = BorderLayout.NORTH;
0N/A
0N/A // Rollover button implementation.
0N/A private static String IS_ROLLOVER = "JToolBar.isRollover";
0N/A private static Border rolloverBorder;
0N/A private static Border nonRolloverBorder;
0N/A private static Border nonRolloverToggleBorder;
0N/A private boolean rolloverBorders = false;
0N/A
614N/A private HashMap<AbstractButton, Border> borderTable = new HashMap<AbstractButton, Border>();
614N/A private Hashtable<AbstractButton, Boolean> rolloverTable = new Hashtable<AbstractButton, Boolean>();
0N/A
0N/A
0N/A /**
0N/A * As of Java 2 platform v1.3 this previously undocumented field is no
0N/A * longer used.
0N/A * Key bindings are now defined by the LookAndFeel, please refer to
0N/A * the key bindings specification for further details.
0N/A *
0N/A * @deprecated As of Java 2 platform v1.3.
0N/A */
0N/A @Deprecated
0N/A protected KeyStroke upKey;
0N/A /**
0N/A * As of Java 2 platform v1.3 this previously undocumented field is no
0N/A * longer used.
0N/A * Key bindings are now defined by the LookAndFeel, please refer to
0N/A * the key bindings specification for further details.
0N/A *
0N/A * @deprecated As of Java 2 platform v1.3.
0N/A */
0N/A @Deprecated
0N/A protected KeyStroke downKey;
0N/A /**
0N/A * As of Java 2 platform v1.3 this previously undocumented field is no
0N/A * longer used.
0N/A * Key bindings are now defined by the LookAndFeel, please refer to
0N/A * the key bindings specification for further details.
0N/A *
0N/A * @deprecated As of Java 2 platform v1.3.
0N/A */
0N/A @Deprecated
0N/A protected KeyStroke leftKey;
0N/A /**
0N/A * As of Java 2 platform v1.3 this previously undocumented field is no
0N/A * longer used.
0N/A * Key bindings are now defined by the LookAndFeel, please refer to
0N/A * the key bindings specification for further details.
0N/A *
0N/A * @deprecated As of Java 2 platform v1.3.
0N/A */
0N/A @Deprecated
0N/A protected KeyStroke rightKey;
0N/A
0N/A
0N/A private static String FOCUSED_COMP_INDEX = "JToolBar.focusedCompIndex";
0N/A
0N/A public static ComponentUI createUI( JComponent c )
0N/A {
0N/A return new BasicToolBarUI();
0N/A }
0N/A
0N/A public void installUI( JComponent c )
0N/A {
0N/A toolBar = (JToolBar) c;
0N/A
0N/A // Set defaults
0N/A installDefaults();
0N/A installComponents();
0N/A installListeners();
0N/A installKeyboardActions();
0N/A
0N/A // Initialize instance vars
0N/A dockingSensitivity = 0;
0N/A floating = false;
0N/A floatingX = floatingY = 0;
0N/A floatingToolBar = null;
0N/A
0N/A setOrientation( toolBar.getOrientation() );
0N/A LookAndFeel.installProperty(c, "opaque", Boolean.TRUE);
0N/A
0N/A if ( c.getClientProperty( FOCUSED_COMP_INDEX ) != null )
0N/A {
0N/A focusedCompIndex = ( (Integer) ( c.getClientProperty( FOCUSED_COMP_INDEX ) ) ).intValue();
0N/A }
0N/A }
0N/A
0N/A public void uninstallUI( JComponent c )
0N/A {
0N/A
0N/A // Clear defaults
0N/A uninstallDefaults();
0N/A uninstallComponents();
0N/A uninstallListeners();
0N/A uninstallKeyboardActions();
0N/A
0N/A // Clear instance vars
614N/A if (isFloating())
0N/A setFloating(false, null);
0N/A
0N/A floatingToolBar = null;
0N/A dragWindow = null;
0N/A dockingSource = null;
0N/A
215N/A c.putClientProperty( FOCUSED_COMP_INDEX, Integer.valueOf( focusedCompIndex ) );
0N/A }
0N/A
0N/A protected void installDefaults( )
0N/A {
0N/A LookAndFeel.installBorder(toolBar,"ToolBar.border");
0N/A LookAndFeel.installColorsAndFont(toolBar,
0N/A "ToolBar.background",
0N/A "ToolBar.foreground",
0N/A "ToolBar.font");
0N/A // Toolbar specific defaults
0N/A if ( dockingColor == null || dockingColor instanceof UIResource )
0N/A dockingColor = UIManager.getColor("ToolBar.dockingBackground");
0N/A if ( floatingColor == null || floatingColor instanceof UIResource )
0N/A floatingColor = UIManager.getColor("ToolBar.floatingBackground");
0N/A if ( dockingBorderColor == null ||
0N/A dockingBorderColor instanceof UIResource )
0N/A dockingBorderColor = UIManager.getColor("ToolBar.dockingForeground");
0N/A if ( floatingBorderColor == null ||
0N/A floatingBorderColor instanceof UIResource )
0N/A floatingBorderColor = UIManager.getColor("ToolBar.floatingForeground");
0N/A
0N/A // ToolBar rollover button borders
0N/A Object rolloverProp = toolBar.getClientProperty( IS_ROLLOVER );
0N/A if (rolloverProp == null) {
0N/A rolloverProp = UIManager.get("ToolBar.isRollover");
0N/A }
0N/A if ( rolloverProp != null ) {
0N/A rolloverBorders = ((Boolean)rolloverProp).booleanValue();
0N/A }
0N/A
0N/A if (rolloverBorder == null) {
0N/A rolloverBorder = createRolloverBorder();
0N/A }
0N/A if (nonRolloverBorder == null) {
0N/A nonRolloverBorder = createNonRolloverBorder();
0N/A }
0N/A if (nonRolloverToggleBorder == null) {
0N/A nonRolloverToggleBorder = createNonRolloverToggleBorder();
0N/A }
0N/A
0N/A
0N/A setRolloverBorders( isRolloverBorders() );
0N/A }
0N/A
0N/A protected void uninstallDefaults( )
0N/A {
0N/A LookAndFeel.uninstallBorder(toolBar);
0N/A dockingColor = null;
0N/A floatingColor = null;
0N/A dockingBorderColor = null;
0N/A floatingBorderColor = null;
0N/A
0N/A installNormalBorders(toolBar);
0N/A
0N/A rolloverBorder = null;
0N/A nonRolloverBorder = null;
0N/A nonRolloverToggleBorder = null;
0N/A }
0N/A
0N/A protected void installComponents( )
0N/A {
0N/A }
0N/A
0N/A protected void uninstallComponents( )
0N/A {
0N/A }
0N/A
0N/A protected void installListeners( )
0N/A {
0N/A dockingListener = createDockingListener( );
0N/A
0N/A if ( dockingListener != null )
0N/A {
0N/A toolBar.addMouseMotionListener( dockingListener );
0N/A toolBar.addMouseListener( dockingListener );
0N/A }
0N/A
0N/A propertyListener = createPropertyListener(); // added in setFloating
0N/A if (propertyListener != null) {
0N/A toolBar.addPropertyChangeListener(propertyListener);
0N/A }
0N/A
0N/A toolBarContListener = createToolBarContListener();
0N/A if ( toolBarContListener != null ) {
0N/A toolBar.addContainerListener( toolBarContListener );
0N/A }
0N/A
0N/A toolBarFocusListener = createToolBarFocusListener();
0N/A
0N/A if ( toolBarFocusListener != null )
0N/A {
0N/A // Put focus listener on all components in toolbar
0N/A Component[] components = toolBar.getComponents();
0N/A
614N/A for (Component component : components) {
614N/A component.addFocusListener(toolBarFocusListener);
0N/A }
0N/A }
0N/A }
0N/A
0N/A protected void uninstallListeners( )
0N/A {
0N/A if ( dockingListener != null )
0N/A {
0N/A toolBar.removeMouseMotionListener(dockingListener);
0N/A toolBar.removeMouseListener(dockingListener);
0N/A
0N/A dockingListener = null;
0N/A }
0N/A
0N/A if ( propertyListener != null )
0N/A {
0N/A toolBar.removePropertyChangeListener(propertyListener);
0N/A propertyListener = null; // removed in setFloating
0N/A }
0N/A
0N/A if ( toolBarContListener != null )
0N/A {
0N/A toolBar.removeContainerListener( toolBarContListener );
0N/A toolBarContListener = null;
0N/A }
0N/A
0N/A if ( toolBarFocusListener != null )
0N/A {
0N/A // Remove focus listener from all components in toolbar
0N/A Component[] components = toolBar.getComponents();
0N/A
614N/A for (Component component : components) {
614N/A component.removeFocusListener(toolBarFocusListener);
0N/A }
0N/A
0N/A toolBarFocusListener = null;
0N/A }
0N/A handler = null;
0N/A }
0N/A
0N/A protected void installKeyboardActions( )
0N/A {
0N/A InputMap km = getInputMap(JComponent.
0N/A WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
0N/A
0N/A SwingUtilities.replaceUIInputMap(toolBar, JComponent.
0N/A WHEN_ANCESTOR_OF_FOCUSED_COMPONENT,
0N/A km);
0N/A
0N/A LazyActionMap.installLazyActionMap(toolBar, BasicToolBarUI.class,
0N/A "ToolBar.actionMap");
0N/A }
0N/A
0N/A InputMap getInputMap(int condition) {
0N/A if (condition == JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT) {
0N/A return (InputMap)DefaultLookup.get(toolBar, this,
0N/A "ToolBar.ancestorInputMap");
0N/A }
0N/A return null;
0N/A }
0N/A
0N/A static void loadActionMap(LazyActionMap map) {
0N/A map.put(new Actions(Actions.NAVIGATE_RIGHT));
0N/A map.put(new Actions(Actions.NAVIGATE_LEFT));
0N/A map.put(new Actions(Actions.NAVIGATE_UP));
0N/A map.put(new Actions(Actions.NAVIGATE_DOWN));
0N/A }
0N/A
0N/A protected void uninstallKeyboardActions( )
0N/A {
0N/A SwingUtilities.replaceUIActionMap(toolBar, null);
0N/A SwingUtilities.replaceUIInputMap(toolBar, JComponent.
0N/A WHEN_ANCESTOR_OF_FOCUSED_COMPONENT,
0N/A null);
0N/A }
0N/A
0N/A protected void navigateFocusedComp( int direction )
0N/A {
0N/A int nComp = toolBar.getComponentCount();
0N/A int j;
0N/A
0N/A switch ( direction )
0N/A {
0N/A case EAST:
0N/A case SOUTH:
0N/A
0N/A if ( focusedCompIndex < 0 || focusedCompIndex >= nComp ) break;
0N/A
0N/A j = focusedCompIndex + 1;
0N/A
0N/A while ( j != focusedCompIndex )
0N/A {
0N/A if ( j >= nComp ) j = 0;
0N/A Component comp = toolBar.getComponentAtIndex( j++ );
0N/A
0N/A if ( comp != null && comp.isFocusTraversable() && comp.isEnabled() )
0N/A {
0N/A comp.requestFocus();
0N/A break;
0N/A }
0N/A }
0N/A
0N/A break;
0N/A
0N/A case WEST:
0N/A case NORTH:
0N/A
0N/A if ( focusedCompIndex < 0 || focusedCompIndex >= nComp ) break;
0N/A
0N/A j = focusedCompIndex - 1;
0N/A
0N/A while ( j != focusedCompIndex )
0N/A {
0N/A if ( j < 0 ) j = nComp - 1;
0N/A Component comp = toolBar.getComponentAtIndex( j-- );
0N/A
0N/A if ( comp != null && comp.isFocusTraversable() && comp.isEnabled() )
0N/A {
0N/A comp.requestFocus();
0N/A break;
0N/A }
0N/A }
0N/A
0N/A break;
0N/A
0N/A default:
0N/A break;
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Creates a rollover border for toolbar components. The
0N/A * rollover border will be installed if rollover borders are
0N/A * enabled.
0N/A * <p>
0N/A * Override this method to provide an alternate rollover border.
0N/A *
0N/A * @since 1.4
0N/A */
0N/A protected Border createRolloverBorder() {
0N/A Object border = UIManager.get("ToolBar.rolloverBorder");
0N/A if (border != null) {
0N/A return (Border)border;
0N/A }
0N/A UIDefaults table = UIManager.getLookAndFeelDefaults();
0N/A return new CompoundBorder(new BasicBorders.RolloverButtonBorder(
0N/A table.getColor("controlShadow"),
0N/A table.getColor("controlDkShadow"),
0N/A table.getColor("controlHighlight"),
0N/A table.getColor("controlLtHighlight")),
0N/A new BasicBorders.RolloverMarginBorder());
0N/A }
0N/A
0N/A /**
0N/A * Creates the non rollover border for toolbar components. This
0N/A * border will be installed as the border for components added
0N/A * to the toolbar if rollover borders are not enabled.
0N/A * <p>
0N/A * Override this method to provide an alternate rollover border.
0N/A *
0N/A * @since 1.4
0N/A */
0N/A protected Border createNonRolloverBorder() {
0N/A Object border = UIManager.get("ToolBar.nonrolloverBorder");
0N/A if (border != null) {
0N/A return (Border)border;
0N/A }
0N/A UIDefaults table = UIManager.getLookAndFeelDefaults();
0N/A return new CompoundBorder(new BasicBorders.ButtonBorder(
0N/A table.getColor("Button.shadow"),
0N/A table.getColor("Button.darkShadow"),
0N/A table.getColor("Button.light"),
0N/A table.getColor("Button.highlight")),
0N/A new BasicBorders.RolloverMarginBorder());
0N/A }
0N/A
0N/A /**
0N/A * Creates a non rollover border for Toggle buttons in the toolbar.
0N/A */
0N/A private Border createNonRolloverToggleBorder() {
0N/A UIDefaults table = UIManager.getLookAndFeelDefaults();
0N/A return new CompoundBorder(new BasicBorders.RadioButtonBorder(
0N/A table.getColor("ToggleButton.shadow"),
0N/A table.getColor("ToggleButton.darkShadow"),
0N/A table.getColor("ToggleButton.light"),
0N/A table.getColor("ToggleButton.highlight")),
0N/A new BasicBorders.RolloverMarginBorder());
0N/A }
0N/A
0N/A /**
0N/A * No longer used, use BasicToolBarUI.createFloatingWindow(JToolBar)
0N/A * @see #createFloatingWindow
0N/A */
0N/A protected JFrame createFloatingFrame(JToolBar toolbar) {
0N/A Window window = SwingUtilities.getWindowAncestor(toolbar);
0N/A JFrame frame = new JFrame(toolbar.getName(),
0N/A (window != null) ? window.getGraphicsConfiguration() : null) {
0N/A // Override createRootPane() to automatically resize
0N/A // the frame when contents change
0N/A protected JRootPane createRootPane() {
0N/A JRootPane rootPane = new JRootPane() {
0N/A private boolean packing = false;
0N/A
0N/A public void validate() {
0N/A super.validate();
0N/A if (!packing) {
0N/A packing = true;
0N/A pack();
0N/A packing = false;
0N/A }
0N/A }
0N/A };
0N/A rootPane.setOpaque(true);
0N/A return rootPane;
0N/A }
0N/A };
0N/A frame.getRootPane().setName("ToolBar.FloatingFrame");
0N/A frame.setResizable(false);
0N/A WindowListener wl = createFrameListener();
0N/A frame.addWindowListener(wl);
0N/A return frame;
0N/A }
0N/A
0N/A /**
0N/A * Creates a window which contains the toolbar after it has been
0N/A * dragged out from its container
0N/A * @return a <code>RootPaneContainer</code> object, containing the toolbar.
0N/A * @since 1.4
0N/A */
0N/A protected RootPaneContainer createFloatingWindow(JToolBar toolbar) {
0N/A class ToolBarDialog extends JDialog {
0N/A public ToolBarDialog(Frame owner, String title, boolean modal) {
0N/A super(owner, title, modal);
0N/A }
0N/A
0N/A public ToolBarDialog(Dialog owner, String title, boolean modal) {
0N/A super(owner, title, modal);
0N/A }
0N/A
0N/A // Override createRootPane() to automatically resize
0N/A // the frame when contents change
0N/A protected JRootPane createRootPane() {
0N/A JRootPane rootPane = new JRootPane() {
0N/A private boolean packing = false;
0N/A
0N/A public void validate() {
0N/A super.validate();
0N/A if (!packing) {
0N/A packing = true;
0N/A pack();
0N/A packing = false;
0N/A }
0N/A }
0N/A };
0N/A rootPane.setOpaque(true);
0N/A return rootPane;
0N/A }
0N/A }
0N/A
0N/A JDialog dialog;
0N/A Window window = SwingUtilities.getWindowAncestor(toolbar);
0N/A if (window instanceof Frame) {
0N/A dialog = new ToolBarDialog((Frame)window, toolbar.getName(), false);
0N/A } else if (window instanceof Dialog) {
0N/A dialog = new ToolBarDialog((Dialog)window, toolbar.getName(), false);
0N/A } else {
0N/A dialog = new ToolBarDialog((Frame)null, toolbar.getName(), false);
0N/A }
0N/A
0N/A dialog.getRootPane().setName("ToolBar.FloatingWindow");
0N/A dialog.setTitle(toolbar.getName());
0N/A dialog.setResizable(false);
0N/A WindowListener wl = createFrameListener();
0N/A dialog.addWindowListener(wl);
0N/A return dialog;
0N/A }
0N/A
0N/A protected DragWindow createDragWindow(JToolBar toolbar) {
0N/A Window frame = null;
0N/A if(toolBar != null) {
0N/A Container p;
0N/A for(p = toolBar.getParent() ; p != null && !(p instanceof Window) ;
0N/A p = p.getParent());
0N/A if(p != null && p instanceof Window)
0N/A frame = (Window) p;
0N/A }
0N/A if(floatingToolBar == null) {
0N/A floatingToolBar = createFloatingWindow(toolBar);
0N/A }
0N/A if (floatingToolBar instanceof Window) frame = (Window) floatingToolBar;
0N/A DragWindow dragWindow = new DragWindow(frame);
0N/A return dragWindow;
0N/A }
0N/A
0N/A /**
0N/A * Returns a flag to determine whether rollover button borders
0N/A * are enabled.
0N/A *
0N/A * @return true if rollover borders are enabled; false otherwise
0N/A * @see #setRolloverBorders
0N/A * @since 1.4
0N/A */
0N/A public boolean isRolloverBorders() {
0N/A return rolloverBorders;
0N/A }
0N/A
0N/A /**
0N/A * Sets the flag for enabling rollover borders on the toolbar and it will
0N/A * also install the apropriate border depending on the state of the flag.
0N/A *
0N/A * @param rollover if true, rollover borders are installed.
0N/A * Otherwise non-rollover borders are installed
0N/A * @see #isRolloverBorders
0N/A * @since 1.4
0N/A */
0N/A public void setRolloverBorders( boolean rollover ) {
0N/A rolloverBorders = rollover;
0N/A
0N/A if ( rolloverBorders ) {
0N/A installRolloverBorders( toolBar );
0N/A } else {
0N/A installNonRolloverBorders( toolBar );
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Installs rollover borders on all the child components of the JComponent.
0N/A * <p>
0N/A * This is a convenience method to call <code>setBorderToRollover</code>
0N/A * for each child component.
0N/A *
0N/A * @param c container which holds the child components (usally a JToolBar)
0N/A * @see #setBorderToRollover
0N/A * @since 1.4
0N/A */
0N/A protected void installRolloverBorders ( JComponent c ) {
0N/A // Put rollover borders on buttons
0N/A Component[] components = c.getComponents();
0N/A
614N/A for (Component component : components) {
614N/A if (component instanceof JComponent) {
614N/A ((JComponent) component).updateUI();
614N/A setBorderToRollover(component);
0N/A }
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Installs non-rollover borders on all the child components of the JComponent.
0N/A * A non-rollover border is the border that is installed on the child component
0N/A * while it is in the toolbar.
0N/A * <p>
0N/A * This is a convenience method to call <code>setBorderToNonRollover</code>
0N/A * for each child component.
0N/A *
0N/A * @param c container which holds the child components (usally a JToolBar)
0N/A * @see #setBorderToNonRollover
0N/A * @since 1.4
0N/A */
0N/A protected void installNonRolloverBorders ( JComponent c ) {
0N/A // Put non-rollover borders on buttons. These borders reduce the margin.
0N/A Component[] components = c.getComponents();
0N/A
614N/A for (Component component : components) {
614N/A if (component instanceof JComponent) {
614N/A ((JComponent) component).updateUI();
614N/A setBorderToNonRollover(component);
0N/A }
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Installs normal borders on all the child components of the JComponent.
0N/A * A normal border is the original border that was installed on the child
0N/A * component before it was added to the toolbar.
0N/A * <p>
0N/A * This is a convenience method to call <code>setBorderNormal</code>
0N/A * for each child component.
0N/A *
0N/A * @param c container which holds the child components (usally a JToolBar)
0N/A * @see #setBorderToNonRollover
0N/A * @since 1.4
0N/A */
0N/A protected void installNormalBorders ( JComponent c ) {
0N/A // Put back the normal borders on buttons
0N/A Component[] components = c.getComponents();
0N/A
614N/A for (Component component : components) {
614N/A setBorderToNormal(component);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Sets the border of the component to have a rollover border which
1999N/A * was created by the {@link #createRolloverBorder} method.
0N/A *
0N/A * @param c component which will have a rollover border installed
0N/A * @see #createRolloverBorder
0N/A * @since 1.4
0N/A */
0N/A protected void setBorderToRollover(Component c) {
0N/A if (c instanceof AbstractButton) {
0N/A AbstractButton b = (AbstractButton)c;
0N/A
614N/A Border border = borderTable.get(b);
0N/A if (border == null || border instanceof UIResource) {
0N/A borderTable.put(b, b.getBorder());
0N/A }
0N/A
0N/A // Only set the border if its the default border
0N/A if (b.getBorder() instanceof UIResource) {
0N/A b.setBorder(getRolloverBorder(b));
0N/A }
0N/A
0N/A rolloverTable.put(b, b.isRolloverEnabled()?
0N/A Boolean.TRUE: Boolean.FALSE);
0N/A b.setRolloverEnabled(true);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Returns a rollover border for the button.
0N/A *
0N/A * @param b the button to calculate the rollover border for
0N/A * @return the rollover border
0N/A * @see #setBorderToRollover
0N/A * @since 1.6
0N/A */
0N/A protected Border getRolloverBorder(AbstractButton b) {
0N/A return rolloverBorder;
0N/A }
0N/A
0N/A /**
0N/A * Sets the border of the component to have a non-rollover border which
1999N/A * was created by the {@link #createNonRolloverBorder} method.
0N/A *
0N/A * @param c component which will have a non-rollover border installed
0N/A * @see #createNonRolloverBorder
0N/A * @since 1.4
0N/A */
0N/A protected void setBorderToNonRollover(Component c) {
0N/A if (c instanceof AbstractButton) {
0N/A AbstractButton b = (AbstractButton)c;
0N/A
614N/A Border border = borderTable.get(b);
0N/A if (border == null || border instanceof UIResource) {
0N/A borderTable.put(b, b.getBorder());
0N/A }
0N/A
0N/A // Only set the border if its the default border
0N/A if (b.getBorder() instanceof UIResource) {
0N/A b.setBorder(getNonRolloverBorder(b));
0N/A }
0N/A rolloverTable.put(b, b.isRolloverEnabled()?
0N/A Boolean.TRUE: Boolean.FALSE);
0N/A b.setRolloverEnabled(false);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Returns a non-rollover border for the button.
0N/A *
0N/A * @param b the button to calculate the non-rollover border for
0N/A * @return the non-rollover border
0N/A * @see #setBorderToNonRollover
0N/A * @since 1.6
0N/A */
0N/A protected Border getNonRolloverBorder(AbstractButton b) {
0N/A if (b instanceof JToggleButton) {
0N/A return nonRolloverToggleBorder;
0N/A } else {
0N/A return nonRolloverBorder;
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Sets the border of the component to have a normal border.
0N/A * A normal border is the original border that was installed on the child
0N/A * component before it was added to the toolbar.
0N/A *
0N/A * @param c component which will have a normal border re-installed
0N/A * @see #createNonRolloverBorder
0N/A * @since 1.4
0N/A */
0N/A protected void setBorderToNormal(Component c) {
0N/A if (c instanceof AbstractButton) {
0N/A AbstractButton b = (AbstractButton)c;
0N/A
614N/A Border border = borderTable.remove(b);
0N/A b.setBorder(border);
0N/A
614N/A Boolean value = rolloverTable.remove(b);
0N/A if (value != null) {
0N/A b.setRolloverEnabled(value.booleanValue());
0N/A }
0N/A }
0N/A }
0N/A
0N/A public void setFloatingLocation(int x, int y) {
0N/A floatingX = x;
0N/A floatingY = y;
0N/A }
0N/A
0N/A public boolean isFloating() {
0N/A return floating;
0N/A }
0N/A
0N/A public void setFloating(boolean b, Point p) {
614N/A if (toolBar.isFloatable()) {
0N/A boolean visible = false;
0N/A Window ancestor = SwingUtilities.getWindowAncestor(toolBar);
0N/A if (ancestor != null) {
0N/A visible = ancestor.isVisible();
0N/A }
0N/A if (dragWindow != null)
0N/A dragWindow.setVisible(false);
0N/A this.floating = b;
0N/A if (floatingToolBar == null) {
0N/A floatingToolBar = createFloatingWindow(toolBar);
0N/A }
0N/A if (b == true)
0N/A {
0N/A if (dockingSource == null)
0N/A {
0N/A dockingSource = toolBar.getParent();
0N/A dockingSource.remove(toolBar);
0N/A }
0N/A constraintBeforeFloating = calculateConstraint();
0N/A if ( propertyListener != null )
0N/A UIManager.addPropertyChangeListener( propertyListener );
0N/A floatingToolBar.getContentPane().add(toolBar,BorderLayout.CENTER);
0N/A if (floatingToolBar instanceof Window) {
0N/A ((Window)floatingToolBar).pack();
0N/A ((Window)floatingToolBar).setLocation(floatingX, floatingY);
0N/A if (visible) {
0N/A ((Window)floatingToolBar).show();
0N/A } else {
0N/A ancestor.addWindowListener(new WindowAdapter() {
0N/A public void windowOpened(WindowEvent e) {
0N/A ((Window)floatingToolBar).show();
0N/A }
0N/A });
0N/A }
0N/A }
0N/A } else {
0N/A if (floatingToolBar == null)
0N/A floatingToolBar = createFloatingWindow(toolBar);
0N/A if (floatingToolBar instanceof Window) ((Window)floatingToolBar).setVisible(false);
0N/A floatingToolBar.getContentPane().remove(toolBar);
0N/A String constraint = getDockingConstraint(dockingSource,
0N/A p);
0N/A if (constraint == null) {
0N/A constraint = BorderLayout.NORTH;
0N/A }
0N/A int orientation = mapConstraintToOrientation(constraint);
0N/A setOrientation(orientation);
0N/A if (dockingSource== null)
0N/A dockingSource = toolBar.getParent();
0N/A if ( propertyListener != null )
0N/A UIManager.removePropertyChangeListener( propertyListener );
0N/A dockingSource.add(constraint, toolBar);
0N/A }
0N/A dockingSource.invalidate();
0N/A Container dockingSourceParent = dockingSource.getParent();
0N/A if (dockingSourceParent != null)
0N/A dockingSourceParent.validate();
0N/A dockingSource.repaint();
0N/A }
0N/A }
0N/A
0N/A private int mapConstraintToOrientation(String constraint)
0N/A {
0N/A int orientation = toolBar.getOrientation();
0N/A
0N/A if ( constraint != null )
0N/A {
0N/A if ( constraint.equals(BorderLayout.EAST) || constraint.equals(BorderLayout.WEST) )
0N/A orientation = JToolBar.VERTICAL;
0N/A else if ( constraint.equals(BorderLayout.NORTH) || constraint.equals(BorderLayout.SOUTH) )
0N/A orientation = JToolBar.HORIZONTAL;
0N/A }
0N/A
0N/A return orientation;
0N/A }
0N/A
0N/A public void setOrientation(int orientation)
0N/A {
0N/A toolBar.setOrientation( orientation );
0N/A
0N/A if (dragWindow !=null)
0N/A dragWindow.setOrientation(orientation);
0N/A }
0N/A
0N/A /**
0N/A * Gets the color displayed when over a docking area
0N/A */
0N/A public Color getDockingColor() {
0N/A return dockingColor;
0N/A }
0N/A
0N/A /**
0N/A * Sets the color displayed when over a docking area
0N/A */
0N/A public void setDockingColor(Color c) {
0N/A this.dockingColor = c;
0N/A }
0N/A
0N/A /**
0N/A * Gets the color displayed when over a floating area
0N/A */
0N/A public Color getFloatingColor() {
0N/A return floatingColor;
0N/A }
0N/A
0N/A /**
0N/A * Sets the color displayed when over a floating area
0N/A */
0N/A public void setFloatingColor(Color c) {
0N/A this.floatingColor = c;
0N/A }
0N/A
0N/A private boolean isBlocked(Component comp, Object constraint) {
0N/A if (comp instanceof Container) {
0N/A Container cont = (Container)comp;
0N/A LayoutManager lm = cont.getLayout();
0N/A if (lm instanceof BorderLayout) {
0N/A BorderLayout blm = (BorderLayout)lm;
0N/A Component c = blm.getLayoutComponent(cont, constraint);
0N/A return (c != null && c != toolBar);
0N/A }
0N/A }
0N/A return false;
0N/A }
0N/A
0N/A public boolean canDock(Component c, Point p) {
0N/A return (p != null && getDockingConstraint(c, p) != null);
0N/A }
0N/A
0N/A private String calculateConstraint() {
0N/A String constraint = null;
0N/A LayoutManager lm = dockingSource.getLayout();
0N/A if (lm instanceof BorderLayout) {
0N/A constraint = (String)((BorderLayout)lm).getConstraints(toolBar);
0N/A }
0N/A return (constraint != null) ? constraint : constraintBeforeFloating;
0N/A }
0N/A
0N/A
0N/A
0N/A private String getDockingConstraint(Component c, Point p) {
0N/A if (p == null) return constraintBeforeFloating;
0N/A if (c.contains(p)) {
0N/A dockingSensitivity = (toolBar.getOrientation() == JToolBar.HORIZONTAL)
0N/A ? toolBar.getSize().height
0N/A : toolBar.getSize().width;
0N/A // North (Base distance on height for now!)
0N/A if (p.y < dockingSensitivity && !isBlocked(c, BorderLayout.NORTH)) {
0N/A return BorderLayout.NORTH;
0N/A }
0N/A // East (Base distance on height for now!)
0N/A if (p.x >= c.getWidth() - dockingSensitivity && !isBlocked(c, BorderLayout.EAST)) {
0N/A return BorderLayout.EAST;
0N/A }
0N/A // West (Base distance on height for now!)
0N/A if (p.x < dockingSensitivity && !isBlocked(c, BorderLayout.WEST)) {
0N/A return BorderLayout.WEST;
0N/A }
0N/A if (p.y >= c.getHeight() - dockingSensitivity && !isBlocked(c, BorderLayout.SOUTH)) {
0N/A return BorderLayout.SOUTH;
0N/A }
0N/A }
0N/A return null;
0N/A }
0N/A
0N/A protected void dragTo(Point position, Point origin)
0N/A {
614N/A if (toolBar.isFloatable())
0N/A {
0N/A try
0N/A {
0N/A if (dragWindow == null)
0N/A dragWindow = createDragWindow(toolBar);
0N/A Point offset = dragWindow.getOffset();
0N/A if (offset == null) {
0N/A Dimension size = toolBar.getPreferredSize();
0N/A offset = new Point(size.width/2, size.height/2);
0N/A dragWindow.setOffset(offset);
0N/A }
0N/A Point global = new Point(origin.x+ position.x,
0N/A origin.y+position.y);
0N/A Point dragPoint = new Point(global.x- offset.x,
0N/A global.y- offset.y);
0N/A if (dockingSource == null)
0N/A dockingSource = toolBar.getParent();
0N/A constraintBeforeFloating = calculateConstraint();
0N/A Point dockingPosition = dockingSource.getLocationOnScreen();
0N/A Point comparisonPoint = new Point(global.x-dockingPosition.x,
0N/A global.y-dockingPosition.y);
0N/A if (canDock(dockingSource, comparisonPoint)) {
0N/A dragWindow.setBackground(getDockingColor());
0N/A String constraint = getDockingConstraint(dockingSource,
0N/A comparisonPoint);
0N/A int orientation = mapConstraintToOrientation(constraint);
0N/A dragWindow.setOrientation(orientation);
0N/A dragWindow.setBorderColor(dockingBorderColor);
0N/A } else {
0N/A dragWindow.setBackground(getFloatingColor());
0N/A dragWindow.setBorderColor(floatingBorderColor);
0N/A dragWindow.setOrientation(toolBar.getOrientation());
0N/A }
0N/A
0N/A dragWindow.setLocation(dragPoint.x, dragPoint.y);
0N/A if (dragWindow.isVisible() == false) {
0N/A Dimension size = toolBar.getPreferredSize();
0N/A dragWindow.setSize(size.width, size.height);
0N/A dragWindow.show();
0N/A }
0N/A }
0N/A catch ( IllegalComponentStateException e )
0N/A {
0N/A }
0N/A }
0N/A }
0N/A
0N/A protected void floatAt(Point position, Point origin)
0N/A {
614N/A if(toolBar.isFloatable())
0N/A {
0N/A try
0N/A {
0N/A Point offset = dragWindow.getOffset();
0N/A if (offset == null) {
0N/A offset = position;
0N/A dragWindow.setOffset(offset);
0N/A }
0N/A Point global = new Point(origin.x+ position.x,
0N/A origin.y+position.y);
0N/A setFloatingLocation(global.x-offset.x,
0N/A global.y-offset.y);
0N/A if (dockingSource != null) {
0N/A Point dockingPosition = dockingSource.getLocationOnScreen();
0N/A Point comparisonPoint = new Point(global.x-dockingPosition.x,
0N/A global.y-dockingPosition.y);
0N/A if (canDock(dockingSource, comparisonPoint)) {
0N/A setFloating(false, comparisonPoint);
0N/A } else {
0N/A setFloating(true, null);
0N/A }
0N/A } else {
0N/A setFloating(true, null);
0N/A }
0N/A dragWindow.setOffset(null);
0N/A }
0N/A catch ( IllegalComponentStateException e )
0N/A {
0N/A }
0N/A }
0N/A }
0N/A
0N/A private Handler getHandler() {
0N/A if (handler == null) {
0N/A handler = new Handler();
0N/A }
0N/A return handler;
0N/A }
0N/A
0N/A protected ContainerListener createToolBarContListener( )
0N/A {
0N/A return getHandler();
0N/A }
0N/A
0N/A protected FocusListener createToolBarFocusListener( )
0N/A {
0N/A return getHandler();
0N/A }
0N/A
0N/A protected PropertyChangeListener createPropertyListener()
0N/A {
0N/A return getHandler();
0N/A }
0N/A
0N/A protected MouseInputListener createDockingListener( ) {
0N/A getHandler().tb = toolBar;
0N/A return getHandler();
0N/A }
0N/A
0N/A protected WindowListener createFrameListener() {
0N/A return new FrameListener();
0N/A }
0N/A
0N/A /**
0N/A * Paints the contents of the window used for dragging.
0N/A *
0N/A * @param g Graphics to paint to.
0N/A * @throws NullPointerException is <code>g</code> is null
0N/A * @since 1.5
0N/A */
0N/A protected void paintDragWindow(Graphics g) {
0N/A g.setColor(dragWindow.getBackground());
0N/A int w = dragWindow.getWidth();
0N/A int h = dragWindow.getHeight();
0N/A g.fillRect(0, 0, w, h);
0N/A g.setColor(dragWindow.getBorderColor());
0N/A g.drawRect(0, 0, w - 1, h - 1);
0N/A }
0N/A
0N/A
0N/A private static class Actions extends UIAction {
0N/A private static final String NAVIGATE_RIGHT = "navigateRight";
0N/A private static final String NAVIGATE_LEFT = "navigateLeft";
0N/A private static final String NAVIGATE_UP = "navigateUp";
0N/A private static final String NAVIGATE_DOWN = "navigateDown";
0N/A
0N/A public Actions(String name) {
0N/A super(name);
0N/A }
0N/A
0N/A public void actionPerformed(ActionEvent evt) {
0N/A String key = getName();
0N/A JToolBar toolBar = (JToolBar)evt.getSource();
0N/A BasicToolBarUI ui = (BasicToolBarUI)BasicLookAndFeel.getUIOfType(
0N/A toolBar.getUI(), BasicToolBarUI.class);
0N/A
0N/A if (NAVIGATE_RIGHT == key) {
0N/A ui.navigateFocusedComp(EAST);
0N/A } else if (NAVIGATE_LEFT == key) {
0N/A ui.navigateFocusedComp(WEST);
0N/A } else if (NAVIGATE_UP == key) {
0N/A ui.navigateFocusedComp(NORTH);
0N/A } else if (NAVIGATE_DOWN == key) {
0N/A ui.navigateFocusedComp(SOUTH);
0N/A }
0N/A }
0N/A }
0N/A
0N/A
0N/A private class Handler implements ContainerListener,
0N/A FocusListener, MouseInputListener, PropertyChangeListener {
0N/A
0N/A //
0N/A // ContainerListener
0N/A //
0N/A public void componentAdded(ContainerEvent evt) {
0N/A Component c = evt.getChild();
0N/A
0N/A if (toolBarFocusListener != null) {
0N/A c.addFocusListener(toolBarFocusListener);
0N/A }
0N/A
0N/A if (isRolloverBorders()) {
0N/A setBorderToRollover(c);
0N/A } else {
0N/A setBorderToNonRollover(c);
0N/A }
0N/A }
0N/A
0N/A public void componentRemoved(ContainerEvent evt) {
0N/A Component c = evt.getChild();
0N/A
0N/A if (toolBarFocusListener != null) {
0N/A c.removeFocusListener(toolBarFocusListener);
0N/A }
0N/A
0N/A // Revert the button border
0N/A setBorderToNormal(c);
0N/A }
0N/A
0N/A
0N/A //
0N/A // FocusListener
0N/A //
0N/A public void focusGained(FocusEvent evt) {
0N/A Component c = evt.getComponent();
0N/A focusedCompIndex = toolBar.getComponentIndex(c);
0N/A }
0N/A
0N/A public void focusLost(FocusEvent evt) { }
0N/A
0N/A
0N/A //
0N/A // MouseInputListener (DockingListener)
0N/A //
0N/A JToolBar tb;
0N/A boolean isDragging = false;
0N/A Point origin = null;
0N/A
0N/A public void mousePressed(MouseEvent evt) {
0N/A if (!tb.isEnabled()) {
0N/A return;
0N/A }
0N/A isDragging = false;
0N/A }
0N/A
0N/A public void mouseReleased(MouseEvent evt) {
0N/A if (!tb.isEnabled()) {
0N/A return;
0N/A }
614N/A if (isDragging) {
0N/A Point position = evt.getPoint();
0N/A if (origin == null)
0N/A origin = evt.getComponent().getLocationOnScreen();
0N/A floatAt(position, origin);
0N/A }
0N/A origin = null;
0N/A isDragging = false;
0N/A }
0N/A
0N/A public void mouseDragged(MouseEvent evt) {
0N/A if (!tb.isEnabled()) {
0N/A return;
0N/A }
0N/A isDragging = true;
0N/A Point position = evt.getPoint();
0N/A if (origin == null) {
0N/A origin = evt.getComponent().getLocationOnScreen();
0N/A }
0N/A dragTo(position, origin);
0N/A }
0N/A
0N/A public void mouseClicked(MouseEvent evt) {}
0N/A public void mouseEntered(MouseEvent evt) {}
0N/A public void mouseExited(MouseEvent evt) {}
0N/A public void mouseMoved(MouseEvent evt) {}
0N/A
0N/A
0N/A //
0N/A // PropertyChangeListener
0N/A //
0N/A public void propertyChange(PropertyChangeEvent evt) {
0N/A String propertyName = evt.getPropertyName();
0N/A if (propertyName == "lookAndFeel") {
0N/A toolBar.updateUI();
0N/A } else if (propertyName == "orientation") {
0N/A // Search for JSeparator components and change it's orientation
0N/A // to match the toolbar and flip it's orientation.
0N/A Component[] components = toolBar.getComponents();
0N/A int orientation = ((Integer)evt.getNewValue()).intValue();
0N/A JToolBar.Separator separator;
0N/A
0N/A for (int i = 0; i < components.length; ++i) {
0N/A if (components[i] instanceof JToolBar.Separator) {
0N/A separator = (JToolBar.Separator)components[i];
0N/A if ((orientation == JToolBar.HORIZONTAL)) {
0N/A separator.setOrientation(JSeparator.VERTICAL);
0N/A } else {
0N/A separator.setOrientation(JSeparator.HORIZONTAL);
0N/A }
0N/A Dimension size = separator.getSeparatorSize();
0N/A if (size != null && size.width != size.height) {
0N/A // Flip the orientation.
0N/A Dimension newSize =
0N/A new Dimension(size.height, size.width);
0N/A separator.setSeparatorSize(newSize);
0N/A }
0N/A }
0N/A }
0N/A } else if (propertyName == IS_ROLLOVER) {
0N/A installNormalBorders(toolBar);
0N/A setRolloverBorders(((Boolean)evt.getNewValue()).booleanValue());
0N/A }
0N/A }
0N/A }
0N/A
0N/A protected class FrameListener extends WindowAdapter {
0N/A public void windowClosing(WindowEvent w) {
614N/A if (toolBar.isFloatable()) {
0N/A if (dragWindow != null)
0N/A dragWindow.setVisible(false);
0N/A floating = false;
0N/A if (floatingToolBar == null)
0N/A floatingToolBar = createFloatingWindow(toolBar);
0N/A if (floatingToolBar instanceof Window) ((Window)floatingToolBar).setVisible(false);
0N/A floatingToolBar.getContentPane().remove(toolBar);
0N/A String constraint = constraintBeforeFloating;
0N/A if (toolBar.getOrientation() == JToolBar.HORIZONTAL) {
0N/A if (constraint == "West" || constraint == "East") {
0N/A constraint = "North";
0N/A }
0N/A } else {
0N/A if (constraint == "North" || constraint == "South") {
0N/A constraint = "West";
0N/A }
0N/A }
0N/A if (dockingSource == null)
0N/A dockingSource = toolBar.getParent();
0N/A if (propertyListener != null)
0N/A UIManager.removePropertyChangeListener(propertyListener);
0N/A dockingSource.add(toolBar, constraint);
0N/A dockingSource.invalidate();
0N/A Container dockingSourceParent = dockingSource.getParent();
0N/A if (dockingSourceParent != null)
0N/A dockingSourceParent.validate();
0N/A dockingSource.repaint();
0N/A }
0N/A }
0N/A
0N/A }
0N/A
0N/A protected class ToolBarContListener implements ContainerListener {
0N/A // NOTE: This class exists only for backward compatability. All
0N/A // its functionality has been moved into Handler. If you need to add
0N/A // new functionality add it to the Handler, but make sure this
0N/A // class calls into the Handler.
0N/A public void componentAdded( ContainerEvent e ) {
0N/A getHandler().componentAdded(e);
0N/A }
0N/A
0N/A public void componentRemoved( ContainerEvent e ) {
0N/A getHandler().componentRemoved(e);
0N/A }
0N/A
0N/A }
0N/A
0N/A protected class ToolBarFocusListener implements FocusListener {
0N/A // NOTE: This class exists only for backward compatability. All
0N/A // its functionality has been moved into Handler. If you need to add
0N/A // new functionality add it to the Handler, but make sure this
0N/A // class calls into the Handler.
0N/A public void focusGained( FocusEvent e ) {
0N/A getHandler().focusGained(e);
0N/A }
0N/A
0N/A public void focusLost( FocusEvent e ) {
0N/A getHandler().focusLost(e);
0N/A }
0N/A }
0N/A
0N/A protected class PropertyListener implements PropertyChangeListener {
0N/A // NOTE: This class exists only for backward compatability. All
0N/A // its functionality has been moved into Handler. If you need to add
0N/A // new functionality add it to the Handler, but make sure this
0N/A // class calls into the Handler.
0N/A public void propertyChange( PropertyChangeEvent e ) {
0N/A getHandler().propertyChange(e);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * This class should be treated as a &quot;protected&quot; inner class.
0N/A * Instantiate it only within subclasses of BasicToolBarUI.
0N/A */
0N/A public class DockingListener implements MouseInputListener {
0N/A // NOTE: This class exists only for backward compatability. All
0N/A // its functionality has been moved into Handler. If you need to add
0N/A // new functionality add it to the Handler, but make sure this
0N/A // class calls into the Handler.
0N/A protected JToolBar toolBar;
0N/A protected boolean isDragging = false;
0N/A protected Point origin = null;
0N/A
0N/A public DockingListener(JToolBar t) {
0N/A this.toolBar = t;
0N/A getHandler().tb = t;
0N/A }
0N/A
0N/A public void mouseClicked(MouseEvent e) {
0N/A getHandler().mouseClicked(e);
0N/A }
0N/A
0N/A public void mousePressed(MouseEvent e) {
0N/A getHandler().tb = toolBar;
0N/A getHandler().mousePressed(e);
0N/A isDragging = getHandler().isDragging;
0N/A }
0N/A
0N/A public void mouseReleased(MouseEvent e) {
0N/A getHandler().tb = toolBar;
0N/A getHandler().isDragging = isDragging;
0N/A getHandler().origin = origin;
0N/A getHandler().mouseReleased(e);
0N/A isDragging = getHandler().isDragging;
0N/A origin = getHandler().origin;
0N/A }
0N/A
0N/A public void mouseEntered(MouseEvent e) {
0N/A getHandler().mouseEntered(e);
0N/A }
0N/A
0N/A public void mouseExited(MouseEvent e) {
0N/A getHandler().mouseExited(e);
0N/A }
0N/A
0N/A public void mouseDragged(MouseEvent e) {
0N/A getHandler().tb = toolBar;
0N/A getHandler().origin = origin;
0N/A getHandler().mouseDragged(e);
0N/A isDragging = getHandler().isDragging;
0N/A origin = getHandler().origin;
0N/A }
0N/A
0N/A public void mouseMoved(MouseEvent e) {
0N/A getHandler().mouseMoved(e);
0N/A }
0N/A }
0N/A
0N/A protected class DragWindow extends Window
0N/A {
0N/A Color borderColor = Color.gray;
0N/A int orientation = toolBar.getOrientation();
0N/A Point offset; // offset of the mouse cursor inside the DragWindow
0N/A
0N/A DragWindow(Window w) {
0N/A super(w);
0N/A }
0N/A
0N/A /**
0N/A * Returns the orientation of the toolbar window when the toolbar is
0N/A * floating. The orientation is either one of <code>JToolBar.HORIZONTAL</code>
0N/A * or <code>JToolBar.VERTICAL</code>.
0N/A *
0N/A * @return the orientation of the toolbar window
0N/A * @since 1.6
0N/A */
0N/A public int getOrientation() {
0N/A return orientation;
0N/A }
0N/A
0N/A public void setOrientation(int o) {
0N/A if(isShowing()) {
0N/A if (o == this.orientation)
0N/A return;
0N/A this.orientation = o;
0N/A Dimension size = getSize();
0N/A setSize(new Dimension(size.height, size.width));
0N/A if (offset!=null) {
0N/A if( BasicGraphicsUtils.isLeftToRight(toolBar) ) {
0N/A setOffset(new Point(offset.y, offset.x));
0N/A } else if( o == JToolBar.HORIZONTAL ) {
0N/A setOffset(new Point( size.height-offset.y, offset.x));
0N/A } else {
0N/A setOffset(new Point(offset.y, size.width-offset.x));
0N/A }
0N/A }
0N/A repaint();
0N/A }
0N/A }
0N/A
0N/A public Point getOffset() {
0N/A return offset;
0N/A }
0N/A
0N/A public void setOffset(Point p) {
0N/A this.offset = p;
0N/A }
0N/A
0N/A public void setBorderColor(Color c) {
0N/A if (this.borderColor == c)
0N/A return;
0N/A this.borderColor = c;
0N/A repaint();
0N/A }
0N/A
0N/A public Color getBorderColor() {
0N/A return this.borderColor;
0N/A }
0N/A
0N/A public void paint(Graphics g) {
0N/A paintDragWindow(g);
0N/A // Paint the children
0N/A super.paint(g);
0N/A }
0N/A public Insets getInsets() {
0N/A return new Insets(1,1,1,1);
0N/A }
0N/A }
0N/A}