jdk/src/share/classes/javax/swing/plaf/basic/BasicToolBarUI.java
author xdono
Wed, 02 Jul 2008 12:55:45 -0700
changeset 715 f16baef3a20e
parent 438 2ae294e4518c
child 1299 027d966d5658
permissions -rw-r--r--
6719955: Update copyright year Summary: Update copyright year for files that have been modified in 2008 Reviewed-by: ohair, tbell
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
715
f16baef3a20e 6719955: Update copyright year
xdono
parents: 438
diff changeset
     2
 * Copyright 1997-2008 Sun Microsystems, Inc.  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
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
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
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
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.plaf.basic;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import javax.swing.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import javax.swing.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.awt.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.beans.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.util.Hashtable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.util.HashMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import javax.swing.border.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import javax.swing.plaf.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import sun.swing.DefaultLookup;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import sun.swing.UIAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * A Basic L&F implementation of ToolBarUI.  This implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * is a "combined" view/controller.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * @author Georges Saab
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * @author Jeff Shapiro
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
public class BasicToolBarUI extends ToolBarUI implements SwingConstants
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    protected JToolBar toolBar;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    private boolean floating;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    private int floatingX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    private int floatingY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    private JFrame floatingFrame;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    private RootPaneContainer floatingToolBar;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    protected DragWindow dragWindow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    private Container dockingSource;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    private int dockingSensitivity = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    protected int focusedCompIndex = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    protected Color dockingColor = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    protected Color floatingColor = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    protected Color dockingBorderColor = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    protected Color floatingBorderColor = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    protected MouseInputListener dockingListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    protected PropertyChangeListener propertyListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    protected ContainerListener toolBarContListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    protected FocusListener toolBarFocusListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    private Handler handler;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    protected String constraintBeforeFloating = BorderLayout.NORTH;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    // Rollover button implementation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    private static String IS_ROLLOVER = "JToolBar.isRollover";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    private static Border rolloverBorder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    private static Border nonRolloverBorder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    private static Border nonRolloverToggleBorder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    private boolean rolloverBorders = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    private HashMap borderTable = new HashMap();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    private Hashtable rolloverTable = new Hashtable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * As of Java 2 platform v1.3 this previously undocumented field is no
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * longer used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * Key bindings are now defined by the LookAndFeel, please refer to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * the key bindings specification for further details.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * @deprecated As of Java 2 platform v1.3.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    protected KeyStroke upKey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * As of Java 2 platform v1.3 this previously undocumented field is no
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * longer used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * Key bindings are now defined by the LookAndFeel, please refer to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * the key bindings specification for further details.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * @deprecated As of Java 2 platform v1.3.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    protected KeyStroke downKey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * As of Java 2 platform v1.3 this previously undocumented field is no
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * longer used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * Key bindings are now defined by the LookAndFeel, please refer to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * the key bindings specification for further details.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * @deprecated As of Java 2 platform v1.3.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    protected KeyStroke leftKey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * As of Java 2 platform v1.3 this previously undocumented field is no
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * longer used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * Key bindings are now defined by the LookAndFeel, please refer to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * the key bindings specification for further details.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * @deprecated As of Java 2 platform v1.3.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    protected KeyStroke rightKey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    private static String FOCUSED_COMP_INDEX = "JToolBar.focusedCompIndex";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    public static ComponentUI createUI( JComponent c )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        return new BasicToolBarUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    public void installUI( JComponent c )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        toolBar = (JToolBar) c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        // Set defaults
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        installDefaults();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        installComponents();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        installListeners();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        installKeyboardActions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        // Initialize instance vars
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        dockingSensitivity = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        floating = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        floatingX = floatingY = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        floatingToolBar = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        setOrientation( toolBar.getOrientation() );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        LookAndFeel.installProperty(c, "opaque", Boolean.TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        if ( c.getClientProperty( FOCUSED_COMP_INDEX ) != null )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
            focusedCompIndex = ( (Integer) ( c.getClientProperty( FOCUSED_COMP_INDEX ) ) ).intValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    public void uninstallUI( JComponent c )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        // Clear defaults
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        uninstallDefaults();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        uninstallComponents();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        uninstallListeners();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        uninstallKeyboardActions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        // Clear instance vars
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        if (isFloating() == true)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
            setFloating(false, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        floatingToolBar = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        dragWindow = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        dockingSource = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
438
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
   181
        c.putClientProperty( FOCUSED_COMP_INDEX, Integer.valueOf( focusedCompIndex ) );
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    protected void installDefaults( )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        LookAndFeel.installBorder(toolBar,"ToolBar.border");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        LookAndFeel.installColorsAndFont(toolBar,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
                                              "ToolBar.background",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                                              "ToolBar.foreground",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                                              "ToolBar.font");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        // Toolbar specific defaults
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        if ( dockingColor == null || dockingColor instanceof UIResource )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            dockingColor = UIManager.getColor("ToolBar.dockingBackground");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        if ( floatingColor == null || floatingColor instanceof UIResource )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
            floatingColor = UIManager.getColor("ToolBar.floatingBackground");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        if ( dockingBorderColor == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
             dockingBorderColor instanceof UIResource )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
            dockingBorderColor = UIManager.getColor("ToolBar.dockingForeground");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        if ( floatingBorderColor == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
             floatingBorderColor instanceof UIResource )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
            floatingBorderColor = UIManager.getColor("ToolBar.floatingForeground");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        // ToolBar rollover button borders
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        Object rolloverProp = toolBar.getClientProperty( IS_ROLLOVER );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        if (rolloverProp == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            rolloverProp = UIManager.get("ToolBar.isRollover");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        if ( rolloverProp != null ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
            rolloverBorders = ((Boolean)rolloverProp).booleanValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        if (rolloverBorder == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
            rolloverBorder = createRolloverBorder();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        if (nonRolloverBorder == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
            nonRolloverBorder = createNonRolloverBorder();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        if (nonRolloverToggleBorder == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            nonRolloverToggleBorder = createNonRolloverToggleBorder();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        setRolloverBorders( isRolloverBorders() );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    protected void uninstallDefaults( )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        LookAndFeel.uninstallBorder(toolBar);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        dockingColor = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        floatingColor = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        dockingBorderColor = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        floatingBorderColor = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        installNormalBorders(toolBar);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        rolloverBorder = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        nonRolloverBorder = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        nonRolloverToggleBorder = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    protected void installComponents( )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    protected void uninstallComponents( )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    protected void installListeners( )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        dockingListener = createDockingListener( );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        if ( dockingListener != null )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
            toolBar.addMouseMotionListener( dockingListener );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
            toolBar.addMouseListener( dockingListener );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        propertyListener = createPropertyListener();  // added in setFloating
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        if (propertyListener != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
            toolBar.addPropertyChangeListener(propertyListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        toolBarContListener = createToolBarContListener();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        if ( toolBarContListener != null ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
            toolBar.addContainerListener( toolBarContListener );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        toolBarFocusListener = createToolBarFocusListener();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        if ( toolBarFocusListener != null )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
            // Put focus listener on all components in toolbar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
            Component[] components = toolBar.getComponents();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
            for ( int i = 0; i < components.length; ++i )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
                components[ i ].addFocusListener( toolBarFocusListener );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    protected void uninstallListeners( )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        if ( dockingListener != null )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
            toolBar.removeMouseMotionListener(dockingListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
            toolBar.removeMouseListener(dockingListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
            dockingListener = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        if ( propertyListener != null )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
            toolBar.removePropertyChangeListener(propertyListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
            propertyListener = null;  // removed in setFloating
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        if ( toolBarContListener != null )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
            toolBar.removeContainerListener( toolBarContListener );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
            toolBarContListener = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        if ( toolBarFocusListener != null )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
            // Remove focus listener from all components in toolbar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
            Component[] components = toolBar.getComponents();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
            for ( int i = 0; i < components.length; ++i )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
                components[ i ].removeFocusListener( toolBarFocusListener );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
            toolBarFocusListener = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        handler = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
    protected void installKeyboardActions( )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        InputMap km = getInputMap(JComponent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
                                  WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        SwingUtilities.replaceUIInputMap(toolBar, JComponent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
                                         WHEN_ANCESTOR_OF_FOCUSED_COMPONENT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
                                         km);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
    LazyActionMap.installLazyActionMap(toolBar, BasicToolBarUI.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
            "ToolBar.actionMap");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
    InputMap getInputMap(int condition) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        if (condition == JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
            return (InputMap)DefaultLookup.get(toolBar, this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
                    "ToolBar.ancestorInputMap");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
    static void loadActionMap(LazyActionMap map) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        map.put(new Actions(Actions.NAVIGATE_RIGHT));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        map.put(new Actions(Actions.NAVIGATE_LEFT));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        map.put(new Actions(Actions.NAVIGATE_UP));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        map.put(new Actions(Actions.NAVIGATE_DOWN));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
    protected void uninstallKeyboardActions( )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        SwingUtilities.replaceUIActionMap(toolBar, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        SwingUtilities.replaceUIInputMap(toolBar, JComponent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
                                         WHEN_ANCESTOR_OF_FOCUSED_COMPONENT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
                                         null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
    protected void navigateFocusedComp( int direction )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        int nComp = toolBar.getComponentCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        int j;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        switch ( direction )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
            case EAST:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
            case SOUTH:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
                if ( focusedCompIndex < 0 || focusedCompIndex >= nComp ) break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
                j = focusedCompIndex + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
                while ( j != focusedCompIndex )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
                {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
                    if ( j >= nComp ) j = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
                    Component comp = toolBar.getComponentAtIndex( j++ );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
                    if ( comp != null && comp.isFocusTraversable() && comp.isEnabled() )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
                    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
                        comp.requestFocus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
            case WEST:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
            case NORTH:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
                if ( focusedCompIndex < 0 || focusedCompIndex >= nComp ) break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
                j = focusedCompIndex - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
                while ( j != focusedCompIndex )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
                {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
                    if ( j < 0 ) j = nComp - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
                    Component comp = toolBar.getComponentAtIndex( j-- );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
                    if ( comp != null && comp.isFocusTraversable() && comp.isEnabled() )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
                    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
                        comp.requestFocus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
            default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     * Creates a rollover border for toolbar components. The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     * rollover border will be installed if rollover borders are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     * enabled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     * Override this method to provide an alternate rollover border.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
    protected Border createRolloverBorder() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
        Object border = UIManager.get("ToolBar.rolloverBorder");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
        if (border != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
            return (Border)border;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
        UIDefaults table = UIManager.getLookAndFeelDefaults();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
        return new CompoundBorder(new BasicBorders.RolloverButtonBorder(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
                                           table.getColor("controlShadow"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
                                           table.getColor("controlDkShadow"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
                                           table.getColor("controlHighlight"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
                                           table.getColor("controlLtHighlight")),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
                                  new BasicBorders.RolloverMarginBorder());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
     * Creates the non rollover border for toolbar components. This
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
     * border will be installed as the border for components added
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     * to the toolbar if rollover borders are not enabled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
     * Override this method to provide an alternate rollover border.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
    protected Border createNonRolloverBorder() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
        Object border = UIManager.get("ToolBar.nonrolloverBorder");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
        if (border != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
            return (Border)border;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
        UIDefaults table = UIManager.getLookAndFeelDefaults();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
        return new CompoundBorder(new BasicBorders.ButtonBorder(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
                                           table.getColor("Button.shadow"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
                                           table.getColor("Button.darkShadow"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
                                           table.getColor("Button.light"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
                                           table.getColor("Button.highlight")),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
                                  new BasicBorders.RolloverMarginBorder());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
     * Creates a non rollover border for Toggle buttons in the toolbar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
    private Border createNonRolloverToggleBorder() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
        UIDefaults table = UIManager.getLookAndFeelDefaults();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
        return new CompoundBorder(new BasicBorders.RadioButtonBorder(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
                                           table.getColor("ToggleButton.shadow"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
                                           table.getColor("ToggleButton.darkShadow"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
                                           table.getColor("ToggleButton.light"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
                                           table.getColor("ToggleButton.highlight")),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
                                  new BasicBorders.RolloverMarginBorder());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
     * No longer used, use BasicToolBarUI.createFloatingWindow(JToolBar)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
     * @see #createFloatingWindow
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
    protected JFrame createFloatingFrame(JToolBar toolbar) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
        Window window = SwingUtilities.getWindowAncestor(toolbar);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
        JFrame frame = new JFrame(toolbar.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
                                  (window != null) ? window.getGraphicsConfiguration() : null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
            // Override createRootPane() to automatically resize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
            // the frame when contents change
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
            protected JRootPane createRootPane() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
                JRootPane rootPane = new JRootPane() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
                    private boolean packing = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
                    public void validate() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
                        super.validate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
                        if (!packing) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
                            packing = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
                            pack();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
                            packing = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
                };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
                rootPane.setOpaque(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
                return rootPane;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
        frame.getRootPane().setName("ToolBar.FloatingFrame");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
        frame.setResizable(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
        WindowListener wl = createFrameListener();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
        frame.addWindowListener(wl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
        return frame;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
     * Creates a window which contains the toolbar after it has been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
     * dragged out from its container
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
     * @return a <code>RootPaneContainer</code> object, containing the toolbar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
    protected RootPaneContainer createFloatingWindow(JToolBar toolbar) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
        class ToolBarDialog extends JDialog {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
            public ToolBarDialog(Frame owner, String title, boolean modal) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
                super(owner, title, modal);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
            public ToolBarDialog(Dialog owner, String title, boolean modal) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
                super(owner, title, modal);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
            // Override createRootPane() to automatically resize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
            // the frame when contents change
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
            protected JRootPane createRootPane() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
                JRootPane rootPane = new JRootPane() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
                    private boolean packing = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
                    public void validate() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
                        super.validate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
                        if (!packing) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
                            packing = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
                            pack();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
                            packing = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
                };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
                rootPane.setOpaque(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
                return rootPane;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
        JDialog dialog;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
        Window window = SwingUtilities.getWindowAncestor(toolbar);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
        if (window instanceof Frame) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
            dialog = new ToolBarDialog((Frame)window, toolbar.getName(), false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
        } else if (window instanceof Dialog) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
            dialog = new ToolBarDialog((Dialog)window, toolbar.getName(), false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
            dialog = new ToolBarDialog((Frame)null, toolbar.getName(), false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
        dialog.getRootPane().setName("ToolBar.FloatingWindow");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
        dialog.setTitle(toolbar.getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
        dialog.setResizable(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
        WindowListener wl = createFrameListener();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
        dialog.addWindowListener(wl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
        return dialog;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
    protected DragWindow createDragWindow(JToolBar toolbar) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
        Window frame = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
        if(toolBar != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
            Container p;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
            for(p = toolBar.getParent() ; p != null && !(p instanceof Window) ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
                p = p.getParent());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
            if(p != null && p instanceof Window)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
                frame = (Window) p;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
        if(floatingToolBar == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
            floatingToolBar = createFloatingWindow(toolBar);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
        if (floatingToolBar instanceof Window) frame = (Window) floatingToolBar;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
        DragWindow dragWindow = new DragWindow(frame);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
        return dragWindow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
     * Returns a flag to determine whether rollover button borders
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
     * are enabled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
     * @return true if rollover borders are enabled; false otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
     * @see #setRolloverBorders
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
    public boolean isRolloverBorders() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
        return rolloverBorders;
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
     * Sets the flag for enabling rollover borders on the toolbar and it will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
     * also install the apropriate border depending on the state of the flag.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
     * @param rollover if true, rollover borders are installed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
     *        Otherwise non-rollover borders are installed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
     * @see #isRolloverBorders
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
    public void setRolloverBorders( boolean rollover ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
        rolloverBorders = rollover;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
        if ( rolloverBorders )  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
            installRolloverBorders( toolBar );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
        } else  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
            installNonRolloverBorders( toolBar );
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
     * Installs rollover borders on all the child components of the JComponent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
     * This is a convenience method to call <code>setBorderToRollover</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
     * for each child component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
     * @param c container which holds the child components (usally a JToolBar)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
     * @see #setBorderToRollover
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
    protected void installRolloverBorders ( JComponent c )  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
        // Put rollover borders on buttons
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
        Component[] components = c.getComponents();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
        for ( int i = 0; i < components.length; ++i ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
            if ( components[ i ] instanceof JComponent ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
                ( (JComponent)components[ i ] ).updateUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
                setBorderToRollover( components[ i ] );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
        }
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
     * Installs non-rollover borders on all the child components of the JComponent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
     * A non-rollover border is the border that is installed on the child component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
     * while it is in the toolbar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
     * This is a convenience method to call <code>setBorderToNonRollover</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
     * for each child component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
     * @param c container which holds the child components (usally a JToolBar)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
     * @see #setBorderToNonRollover
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
    protected void installNonRolloverBorders ( JComponent c )  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
        // Put non-rollover borders on buttons. These borders reduce the margin.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
        Component[] components = c.getComponents();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
        for ( int i = 0; i < components.length; ++i ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
            if ( components[ i ] instanceof JComponent ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
                ( (JComponent)components[ i ] ).updateUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
                setBorderToNonRollover( components[ i ] );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
     * Installs normal borders on all the child components of the JComponent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
     * A normal border is the original border that was installed on the child
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
     * component before it was added to the toolbar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
     * This is a convenience method to call <code>setBorderNormal</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
     * for each child component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
     * @param c container which holds the child components (usally a JToolBar)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
     * @see #setBorderToNonRollover
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
    protected void installNormalBorders ( JComponent c )  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
        // Put back the normal borders on buttons
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
        Component[] components = c.getComponents();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
        for ( int i = 0; i < components.length; ++i ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
            setBorderToNormal( components[ i ] );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
     * Sets the border of the component to have a rollover border which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
     * was created by <code>createRolloverBorder</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
     * @param c component which will have a rollover border installed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
     * @see #createRolloverBorder
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
    protected void setBorderToRollover(Component c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
        if (c instanceof AbstractButton) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
            AbstractButton b = (AbstractButton)c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
            Border border = (Border)borderTable.get(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
            if (border == null || border instanceof UIResource) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
                borderTable.put(b, b.getBorder());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
            // Only set the border if its the default border
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
            if (b.getBorder() instanceof UIResource) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
                b.setBorder(getRolloverBorder(b));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
            rolloverTable.put(b, b.isRolloverEnabled()?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
                              Boolean.TRUE: Boolean.FALSE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
            b.setRolloverEnabled(true);
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
     * Returns a rollover border for the button.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
     * @param b the button to calculate the rollover border for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
     * @return the rollover border
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
     * @see #setBorderToRollover
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
    protected Border getRolloverBorder(AbstractButton b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
        return rolloverBorder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
     * Sets the border of the component to have a non-rollover border which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
     * was created by <code>createNonRolloverBorder</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
     * @param c component which will have a non-rollover border installed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
     * @see #createNonRolloverBorder
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
    protected void setBorderToNonRollover(Component c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
        if (c instanceof AbstractButton) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
            AbstractButton b = (AbstractButton)c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
            Border border = (Border)borderTable.get(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
            if (border == null || border instanceof UIResource) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
                borderTable.put(b, b.getBorder());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
            // Only set the border if its the default border
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
            if (b.getBorder() instanceof UIResource) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
                b.setBorder(getNonRolloverBorder(b));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
            rolloverTable.put(b, b.isRolloverEnabled()?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
                              Boolean.TRUE: Boolean.FALSE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
            b.setRolloverEnabled(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
     * Returns a non-rollover border for the button.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
     * @param b the button to calculate the non-rollover border for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
     * @return the non-rollover border
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
     * @see #setBorderToNonRollover
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
    protected Border getNonRolloverBorder(AbstractButton b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
        if (b instanceof JToggleButton) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
            return nonRolloverToggleBorder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
            return nonRolloverBorder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
     * Sets the border of the component to have a normal border.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
     * A normal border is the original border that was installed on the child
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
     * component before it was added to the toolbar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
     * @param c component which will have a normal border re-installed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
     * @see #createNonRolloverBorder
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
    protected void setBorderToNormal(Component c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
        if (c instanceof AbstractButton) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
            AbstractButton b = (AbstractButton)c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
            Border border = (Border)borderTable.remove(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
            b.setBorder(border);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
            Boolean value = (Boolean)rolloverTable.remove(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
            if (value != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
                b.setRolloverEnabled(value.booleanValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
        }
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 void setFloatingLocation(int x, int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
        floatingX = x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
        floatingY = y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
    public boolean isFloating() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
        return floating;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
    public void setFloating(boolean b, Point p) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
        if (toolBar.isFloatable() == true) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
            boolean visible = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
            Window ancestor = SwingUtilities.getWindowAncestor(toolBar);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
            if (ancestor != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
                visible = ancestor.isVisible();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
            if (dragWindow != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
                dragWindow.setVisible(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
            this.floating = b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
            if (floatingToolBar == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
                floatingToolBar = createFloatingWindow(toolBar);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
            if (b == true)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
                if (dockingSource == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
                {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
                    dockingSource = toolBar.getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
                    dockingSource.remove(toolBar);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
                constraintBeforeFloating = calculateConstraint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
                if ( propertyListener != null )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
                    UIManager.addPropertyChangeListener( propertyListener );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
                floatingToolBar.getContentPane().add(toolBar,BorderLayout.CENTER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
                if (floatingToolBar instanceof Window) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
                    ((Window)floatingToolBar).pack();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
                    ((Window)floatingToolBar).setLocation(floatingX, floatingY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
                    if (visible) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
                        ((Window)floatingToolBar).show();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
                        ancestor.addWindowListener(new WindowAdapter() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
                            public void windowOpened(WindowEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
                                ((Window)floatingToolBar).show();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
                        });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
                if (floatingToolBar == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
                    floatingToolBar = createFloatingWindow(toolBar);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
                if (floatingToolBar instanceof Window) ((Window)floatingToolBar).setVisible(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
                floatingToolBar.getContentPane().remove(toolBar);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
                String constraint = getDockingConstraint(dockingSource,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
                                                         p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
                if (constraint == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
                    constraint = BorderLayout.NORTH;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
                int orientation = mapConstraintToOrientation(constraint);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
                setOrientation(orientation);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
                if (dockingSource== null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
                    dockingSource = toolBar.getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
                if ( propertyListener != null )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
                    UIManager.removePropertyChangeListener( propertyListener );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
                dockingSource.add(constraint, toolBar);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
            dockingSource.invalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
            Container dockingSourceParent = dockingSource.getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
            if (dockingSourceParent != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
                dockingSourceParent.validate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
            dockingSource.repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
    private int mapConstraintToOrientation(String constraint)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
        int orientation = toolBar.getOrientation();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
        if ( constraint != null )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
            if ( constraint.equals(BorderLayout.EAST) || constraint.equals(BorderLayout.WEST) )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
                orientation = JToolBar.VERTICAL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
            else if ( constraint.equals(BorderLayout.NORTH) || constraint.equals(BorderLayout.SOUTH) )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
                orientation = JToolBar.HORIZONTAL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
        return orientation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
    public void setOrientation(int orientation)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
        toolBar.setOrientation( orientation );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
        if (dragWindow !=null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
            dragWindow.setOrientation(orientation);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
     * Gets the color displayed when over a docking area
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
    public Color getDockingColor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
        return dockingColor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
     * Sets the color displayed when over a docking area
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
   public void setDockingColor(Color c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
        this.dockingColor = c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
     * Gets the color displayed when over a floating area
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
    public Color getFloatingColor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
        return floatingColor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
     * Sets the color displayed when over a floating area
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
    public void setFloatingColor(Color c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
        this.floatingColor = c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
    private boolean isBlocked(Component comp, Object constraint) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
        if (comp instanceof Container) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
            Container cont = (Container)comp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
            LayoutManager lm = cont.getLayout();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
            if (lm instanceof BorderLayout) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
                BorderLayout blm = (BorderLayout)lm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
                Component c = blm.getLayoutComponent(cont, constraint);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
                return (c != null && c != toolBar);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
    public boolean canDock(Component c, Point p) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
        return (p != null && getDockingConstraint(c, p) != null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
    private String calculateConstraint() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
        String constraint = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
        LayoutManager lm = dockingSource.getLayout();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
        if (lm instanceof BorderLayout) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
            constraint = (String)((BorderLayout)lm).getConstraints(toolBar);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
        return (constraint != null) ? constraint : constraintBeforeFloating;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
    private String getDockingConstraint(Component c, Point p) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
        if (p == null) return constraintBeforeFloating;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
        if (c.contains(p)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
            dockingSensitivity = (toolBar.getOrientation() == JToolBar.HORIZONTAL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
                                                ? toolBar.getSize().height
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
                                                : toolBar.getSize().width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
            // North  (Base distance on height for now!)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
            if (p.y < dockingSensitivity && !isBlocked(c, BorderLayout.NORTH)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
                return BorderLayout.NORTH;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
            // East  (Base distance on height for now!)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
            if (p.x >= c.getWidth() - dockingSensitivity && !isBlocked(c, BorderLayout.EAST)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
                return BorderLayout.EAST;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
            // West  (Base distance on height for now!)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
            if (p.x < dockingSensitivity && !isBlocked(c, BorderLayout.WEST)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
                return BorderLayout.WEST;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
            if (p.y >= c.getHeight() - dockingSensitivity && !isBlocked(c, BorderLayout.SOUTH)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
                return BorderLayout.SOUTH;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
    protected void dragTo(Point position, Point origin)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
        if (toolBar.isFloatable() == true)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
          try
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
          {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
            if (dragWindow == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
                dragWindow = createDragWindow(toolBar);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
            Point offset = dragWindow.getOffset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
            if (offset == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
                Dimension size = toolBar.getPreferredSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
                offset = new Point(size.width/2, size.height/2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
                dragWindow.setOffset(offset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
            Point global = new Point(origin.x+ position.x,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
                                     origin.y+position.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
            Point dragPoint = new Point(global.x- offset.x,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
                                        global.y- offset.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
            if (dockingSource == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
                dockingSource = toolBar.getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
                constraintBeforeFloating = calculateConstraint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
            Point dockingPosition = dockingSource.getLocationOnScreen();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
            Point comparisonPoint = new Point(global.x-dockingPosition.x,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
                                              global.y-dockingPosition.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
            if (canDock(dockingSource, comparisonPoint)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
                dragWindow.setBackground(getDockingColor());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
                String constraint = getDockingConstraint(dockingSource,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
                                                         comparisonPoint);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
                int orientation = mapConstraintToOrientation(constraint);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
                dragWindow.setOrientation(orientation);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
                dragWindow.setBorderColor(dockingBorderColor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
                dragWindow.setBackground(getFloatingColor());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
                dragWindow.setBorderColor(floatingBorderColor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
                dragWindow.setOrientation(toolBar.getOrientation());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
            dragWindow.setLocation(dragPoint.x, dragPoint.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
            if (dragWindow.isVisible() == false) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
                Dimension size = toolBar.getPreferredSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
                dragWindow.setSize(size.width, size.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
                dragWindow.show();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
          catch ( IllegalComponentStateException e )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
          {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
    protected void floatAt(Point position, Point origin)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
        if(toolBar.isFloatable() == true)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
          try
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
          {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
            Point offset = dragWindow.getOffset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
            if (offset == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
                offset = position;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
                dragWindow.setOffset(offset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
            Point global = new Point(origin.x+ position.x,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
                                     origin.y+position.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
            setFloatingLocation(global.x-offset.x,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
                                global.y-offset.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
            if (dockingSource != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
                Point dockingPosition = dockingSource.getLocationOnScreen();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
                Point comparisonPoint = new Point(global.x-dockingPosition.x,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
                                                  global.y-dockingPosition.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
                if (canDock(dockingSource, comparisonPoint)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
                    setFloating(false, comparisonPoint);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
                    setFloating(true, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
                setFloating(true, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
            dragWindow.setOffset(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
          catch ( IllegalComponentStateException e )
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
          {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
    private Handler getHandler() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
        if (handler == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
            handler = new Handler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
        return handler;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
    protected ContainerListener createToolBarContListener( )
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
        return getHandler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
    protected FocusListener createToolBarFocusListener( )
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
        return getHandler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
    protected PropertyChangeListener createPropertyListener()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
        return getHandler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
    protected MouseInputListener createDockingListener( ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
        getHandler().tb = toolBar;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
        return getHandler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
    protected WindowListener createFrameListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
        return new FrameListener();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
     * Paints the contents of the window used for dragging.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
     * @param g Graphics to paint to.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
     * @throws NullPointerException is <code>g</code> is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
    protected void paintDragWindow(Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
        g.setColor(dragWindow.getBackground());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
        int w = dragWindow.getWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
        int h = dragWindow.getHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
        g.fillRect(0, 0, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
        g.setColor(dragWindow.getBorderColor());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
        g.drawRect(0, 0, w - 1, h - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
    private static class Actions extends UIAction {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
        private static final String NAVIGATE_RIGHT = "navigateRight";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
        private static final String NAVIGATE_LEFT = "navigateLeft";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
        private static final String NAVIGATE_UP = "navigateUp";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
        private static final String NAVIGATE_DOWN = "navigateDown";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
        public Actions(String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
            super(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
        public void actionPerformed(ActionEvent evt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
            String key = getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
            JToolBar toolBar = (JToolBar)evt.getSource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
            BasicToolBarUI ui = (BasicToolBarUI)BasicLookAndFeel.getUIOfType(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
                     toolBar.getUI(), BasicToolBarUI.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
            if (NAVIGATE_RIGHT == key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
                ui.navigateFocusedComp(EAST);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
            } else if (NAVIGATE_LEFT == key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
                ui.navigateFocusedComp(WEST);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
            } else if (NAVIGATE_UP == key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
                ui.navigateFocusedComp(NORTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
            } else if (NAVIGATE_DOWN == key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
                ui.navigateFocusedComp(SOUTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
    private class Handler implements ContainerListener,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
            FocusListener, MouseInputListener, PropertyChangeListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
        // ContainerListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
        public void componentAdded(ContainerEvent evt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
            Component c = evt.getChild();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
            if (toolBarFocusListener != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
                c.addFocusListener(toolBarFocusListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
            if (isRolloverBorders()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
                setBorderToRollover(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
                setBorderToNonRollover(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
        public void componentRemoved(ContainerEvent evt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
            Component c = evt.getChild();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
            if (toolBarFocusListener != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
                c.removeFocusListener(toolBarFocusListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
            // Revert the button border
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
            setBorderToNormal(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
        // FocusListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
        public void focusGained(FocusEvent evt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
            Component c = evt.getComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
            focusedCompIndex = toolBar.getComponentIndex(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
        public void focusLost(FocusEvent evt) { }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
        // MouseInputListener (DockingListener)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
        JToolBar tb;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
        boolean isDragging = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
        Point origin = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
        public void mousePressed(MouseEvent evt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
            if (!tb.isEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
            isDragging = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
        public void mouseReleased(MouseEvent evt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
            if (!tb.isEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
            if (isDragging == true) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
                Point position = evt.getPoint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
                if (origin == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
                    origin = evt.getComponent().getLocationOnScreen();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
                floatAt(position, origin);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
            origin = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
            isDragging = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
        public void mouseDragged(MouseEvent evt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
            if (!tb.isEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
            isDragging = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
            Point position = evt.getPoint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
            if (origin == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
                origin = evt.getComponent().getLocationOnScreen();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
            dragTo(position, origin);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
        public void mouseClicked(MouseEvent evt) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
        public void mouseEntered(MouseEvent evt) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
        public void mouseExited(MouseEvent evt) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
        public void mouseMoved(MouseEvent evt) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
        // PropertyChangeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
        public void propertyChange(PropertyChangeEvent evt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
            String propertyName = evt.getPropertyName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
            if (propertyName == "lookAndFeel") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
                toolBar.updateUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
            } else if (propertyName == "orientation") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
                // Search for JSeparator components and change it's orientation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
                // to match the toolbar and flip it's orientation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
                Component[] components = toolBar.getComponents();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
                int orientation = ((Integer)evt.getNewValue()).intValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
                JToolBar.Separator separator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
                for (int i = 0; i < components.length; ++i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
                    if (components[i] instanceof JToolBar.Separator) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
                        separator = (JToolBar.Separator)components[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
                        if ((orientation == JToolBar.HORIZONTAL)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
                            separator.setOrientation(JSeparator.VERTICAL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
                        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
                            separator.setOrientation(JSeparator.HORIZONTAL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
                        Dimension size = separator.getSeparatorSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
                        if (size != null && size.width != size.height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
                            // Flip the orientation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
                            Dimension newSize =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
                                new Dimension(size.height, size.width);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
                            separator.setSeparatorSize(newSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
            } else if (propertyName == IS_ROLLOVER) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
                installNormalBorders(toolBar);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
                setRolloverBorders(((Boolean)evt.getNewValue()).booleanValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
    protected class FrameListener extends WindowAdapter {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
        public void windowClosing(WindowEvent w) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
            if (toolBar.isFloatable() == true) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
                if (dragWindow != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
                    dragWindow.setVisible(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
                floating = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
                if (floatingToolBar == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
                    floatingToolBar = createFloatingWindow(toolBar);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
                if (floatingToolBar instanceof Window) ((Window)floatingToolBar).setVisible(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
                floatingToolBar.getContentPane().remove(toolBar);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
                String constraint = constraintBeforeFloating;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
                if (toolBar.getOrientation() == JToolBar.HORIZONTAL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
                    if (constraint == "West" || constraint == "East") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
                        constraint = "North";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
                    if (constraint == "North" || constraint == "South") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
                        constraint = "West";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
                if (dockingSource == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
                    dockingSource = toolBar.getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
                if (propertyListener != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
                    UIManager.removePropertyChangeListener(propertyListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
                dockingSource.add(toolBar, constraint);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
                dockingSource.invalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
                Container dockingSourceParent = dockingSource.getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
                if (dockingSourceParent != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
                        dockingSourceParent.validate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
                dockingSource.repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
    protected class ToolBarContListener implements ContainerListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
        // NOTE: This class exists only for backward compatability. All
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
        // its functionality has been moved into Handler. If you need to add
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
        // new functionality add it to the Handler, but make sure this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
        // class calls into the Handler.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
        public void componentAdded( ContainerEvent e )  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
            getHandler().componentAdded(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
        public void componentRemoved( ContainerEvent e ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
            getHandler().componentRemoved(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
    protected class ToolBarFocusListener implements FocusListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
        // NOTE: This class exists only for backward compatability. All
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
        // its functionality has been moved into Handler. If you need to add
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
        // new functionality add it to the Handler, but make sure this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
        // class calls into the Handler.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
        public void focusGained( FocusEvent e ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
            getHandler().focusGained(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
        public void focusLost( FocusEvent e ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
            getHandler().focusLost(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
    protected class PropertyListener implements PropertyChangeListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
        // NOTE: This class exists only for backward compatability. All
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
        // its functionality has been moved into Handler. If you need to add
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
        // new functionality add it to the Handler, but make sure this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
        // class calls into the Handler.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
        public void propertyChange( PropertyChangeEvent e ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
            getHandler().propertyChange(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1316
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1317
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
     * This class should be treated as a &quot;protected&quot; inner class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
     * Instantiate it only within subclasses of BasicToolBarUI.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
    public class DockingListener implements MouseInputListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
        // NOTE: This class exists only for backward compatability. All
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
        // its functionality has been moved into Handler. If you need to add
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
        // new functionality add it to the Handler, but make sure this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
        // class calls into the Handler.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1326
        protected JToolBar toolBar;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
        protected boolean isDragging = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
        protected Point origin = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1329
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
        public DockingListener(JToolBar t) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
            this.toolBar = t;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
            getHandler().tb = t;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1333
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1335
        public void mouseClicked(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1336
        getHandler().mouseClicked(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1337
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1338
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1339
        public void mousePressed(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1340
        getHandler().tb = toolBar;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1341
        getHandler().mousePressed(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1342
        isDragging = getHandler().isDragging;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1343
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1344
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1345
        public void mouseReleased(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1346
        getHandler().tb = toolBar;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1347
        getHandler().isDragging = isDragging;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1348
        getHandler().origin = origin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1349
        getHandler().mouseReleased(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1350
        isDragging = getHandler().isDragging;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1351
        origin = getHandler().origin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1352
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1353
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1354
        public void mouseEntered(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1355
        getHandler().mouseEntered(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1356
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1357
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1358
        public void mouseExited(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1359
        getHandler().mouseExited(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1360
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1361
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1362
        public void mouseDragged(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1363
        getHandler().tb = toolBar;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1364
        getHandler().origin = origin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1365
        getHandler().mouseDragged(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1366
        isDragging = getHandler().isDragging;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1367
        origin = getHandler().origin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1368
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1369
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1370
        public void mouseMoved(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1371
        getHandler().mouseMoved(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1372
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1373
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1374
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1375
    protected class DragWindow extends Window
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1376
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1377
        Color borderColor = Color.gray;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1378
        int orientation = toolBar.getOrientation();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1379
        Point offset; // offset of the mouse cursor inside the DragWindow
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1380
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1381
        DragWindow(Window w) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1382
            super(w);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1383
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1384
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1385
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1386
     * Returns the orientation of the toolbar window when the toolbar is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1387
     * floating. The orientation is either one of <code>JToolBar.HORIZONTAL</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1388
     * or <code>JToolBar.VERTICAL</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1389
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1390
     * @return the orientation of the toolbar window
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1391
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1392
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1393
    public int getOrientation() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1394
        return orientation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1395
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1396
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1397
        public void setOrientation(int o) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1398
            if(isShowing()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1399
                if (o == this.orientation)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1400
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1401
                this.orientation = o;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1402
                Dimension size = getSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1403
                setSize(new Dimension(size.height, size.width));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1404
                if (offset!=null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1405
                    if( BasicGraphicsUtils.isLeftToRight(toolBar) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1406
                        setOffset(new Point(offset.y, offset.x));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1407
                    } else if( o == JToolBar.HORIZONTAL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1408
                        setOffset(new Point( size.height-offset.y, offset.x));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1409
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1410
                        setOffset(new Point(offset.y, size.width-offset.x));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1411
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1412
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1413
                repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1414
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1415
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1416
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1417
        public Point getOffset() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1418
            return offset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1419
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1420
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1421
        public void setOffset(Point p) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1422
            this.offset = p;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1423
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1424
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1425
        public void setBorderColor(Color c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1426
            if (this.borderColor == c)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1427
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1428
            this.borderColor = c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1429
            repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1430
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1431
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1432
        public Color getBorderColor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1433
            return this.borderColor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1434
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1435
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1436
        public void paint(Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1437
            paintDragWindow(g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1438
            // Paint the children
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1439
            super.paint(g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1440
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1441
        public Insets getInsets() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1442
            return new Insets(1,1,1,1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1443
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1444
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1445
}