jdk/src/share/classes/javax/swing/plaf/basic/BasicToolBarUI.java
author malenkov
Tue, 29 Oct 2013 17:01:06 +0400
changeset 21278 ef8a3a2a72f2
parent 20169 d7fa6d7586c9
child 23010 6dadb192ad81
permissions -rw-r--r--
8022746: List of spelling errors in API doc Reviewed-by: alexsch, smarks
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4394
diff changeset
     2
 * Copyright (c) 1997, 2008, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4394
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4394
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4394
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4394
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4394
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package javax.swing.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
/**
20169
d7fa6d7586c9 8025085: [javadoc] some errors in javax/swing
yan
parents: 5506
diff changeset
    45
 * A Basic L&F implementation of ToolBarUI.  This implementation
2
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
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 438
diff changeset
    86
    private HashMap<AbstractButton, Border> borderTable = new HashMap<AbstractButton, Border>();
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 438
diff changeset
    87
    private Hashtable<AbstractButton, Boolean> rolloverTable = new Hashtable<AbstractButton, Boolean>();
2
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
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 438
diff changeset
   174
        if (isFloating())
2
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
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 438
diff changeset
   276
            for (Component component : components) {
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 438
diff changeset
   277
                component.addFocusListener(toolBarFocusListener);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    protected void uninstallListeners( )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        if ( dockingListener != null )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
            toolBar.removeMouseMotionListener(dockingListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
            toolBar.removeMouseListener(dockingListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
            dockingListener = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        if ( propertyListener != null )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
            toolBar.removePropertyChangeListener(propertyListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
            propertyListener = null;  // removed in setFloating
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        if ( toolBarContListener != null )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
            toolBar.removeContainerListener( toolBarContListener );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
            toolBarContListener = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        if ( toolBarFocusListener != null )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
            // Remove focus listener from all components in toolbar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
            Component[] components = toolBar.getComponents();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 438
diff changeset
   309
            for (Component component : components) {
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 438
diff changeset
   310
                component.removeFocusListener(toolBarFocusListener);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
            toolBarFocusListener = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        handler = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
    protected void installKeyboardActions( )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        InputMap km = getInputMap(JComponent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
                                  WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        SwingUtilities.replaceUIInputMap(toolBar, JComponent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
                                         WHEN_ANCESTOR_OF_FOCUSED_COMPONENT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
                                         km);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
    LazyActionMap.installLazyActionMap(toolBar, BasicToolBarUI.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
            "ToolBar.actionMap");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
    InputMap getInputMap(int condition) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        if (condition == JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
            return (InputMap)DefaultLookup.get(toolBar, this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
                    "ToolBar.ancestorInputMap");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
    static void loadActionMap(LazyActionMap map) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        map.put(new Actions(Actions.NAVIGATE_RIGHT));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        map.put(new Actions(Actions.NAVIGATE_LEFT));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        map.put(new Actions(Actions.NAVIGATE_UP));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        map.put(new Actions(Actions.NAVIGATE_DOWN));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
    protected void uninstallKeyboardActions( )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
        SwingUtilities.replaceUIActionMap(toolBar, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        SwingUtilities.replaceUIInputMap(toolBar, JComponent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
                                         WHEN_ANCESTOR_OF_FOCUSED_COMPONENT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
                                         null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
    protected void navigateFocusedComp( int direction )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        int nComp = toolBar.getComponentCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        int j;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        switch ( direction )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
            case EAST:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
            case SOUTH:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
                if ( focusedCompIndex < 0 || focusedCompIndex >= nComp ) break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
                j = focusedCompIndex + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
                while ( j != focusedCompIndex )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
                {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
                    if ( j >= nComp ) j = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
                    Component comp = toolBar.getComponentAtIndex( j++ );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
                    if ( comp != null && comp.isFocusTraversable() && comp.isEnabled() )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
                    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
                        comp.requestFocus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
            case WEST:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
            case NORTH:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
                if ( focusedCompIndex < 0 || focusedCompIndex >= nComp ) break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
                j = focusedCompIndex - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
                while ( j != focusedCompIndex )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
                {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
                    if ( j < 0 ) j = nComp - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
                    Component comp = toolBar.getComponentAtIndex( j-- );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
                    if ( comp != null && comp.isFocusTraversable() && comp.isEnabled() )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
                    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
                        comp.requestFocus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
            default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
     * Creates a rollover border for toolbar components. The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     * rollover border will be installed if rollover borders are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     * enabled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     * Override this method to provide an alternate rollover border.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
    protected Border createRolloverBorder() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
        Object border = UIManager.get("ToolBar.rolloverBorder");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
        if (border != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
            return (Border)border;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
        UIDefaults table = UIManager.getLookAndFeelDefaults();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
        return new CompoundBorder(new BasicBorders.RolloverButtonBorder(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
                                           table.getColor("controlShadow"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
                                           table.getColor("controlDkShadow"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
                                           table.getColor("controlHighlight"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
                                           table.getColor("controlLtHighlight")),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
                                  new BasicBorders.RolloverMarginBorder());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
     * Creates the non rollover border for toolbar components. This
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
     * border will be installed as the border for components added
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
     * to the toolbar if rollover borders are not enabled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     * Override this method to provide an alternate rollover border.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
    protected Border createNonRolloverBorder() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
        Object border = UIManager.get("ToolBar.nonrolloverBorder");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
        if (border != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
            return (Border)border;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
        UIDefaults table = UIManager.getLookAndFeelDefaults();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
        return new CompoundBorder(new BasicBorders.ButtonBorder(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
                                           table.getColor("Button.shadow"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
                                           table.getColor("Button.darkShadow"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
                                           table.getColor("Button.light"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
                                           table.getColor("Button.highlight")),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
                                  new BasicBorders.RolloverMarginBorder());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
     * Creates a non rollover border for Toggle buttons in the toolbar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
    private Border createNonRolloverToggleBorder() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
        UIDefaults table = UIManager.getLookAndFeelDefaults();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
        return new CompoundBorder(new BasicBorders.RadioButtonBorder(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
                                           table.getColor("ToggleButton.shadow"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
                                           table.getColor("ToggleButton.darkShadow"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
                                           table.getColor("ToggleButton.light"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
                                           table.getColor("ToggleButton.highlight")),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
                                  new BasicBorders.RolloverMarginBorder());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
     * No longer used, use BasicToolBarUI.createFloatingWindow(JToolBar)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
     * @see #createFloatingWindow
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
    protected JFrame createFloatingFrame(JToolBar toolbar) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
        Window window = SwingUtilities.getWindowAncestor(toolbar);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
        JFrame frame = new JFrame(toolbar.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
                                  (window != null) ? window.getGraphicsConfiguration() : null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
            // Override createRootPane() to automatically resize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
            // the frame when contents change
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
            protected JRootPane createRootPane() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
                JRootPane rootPane = new JRootPane() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
                    private boolean packing = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
                    public void validate() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
                        super.validate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
                        if (!packing) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
                            packing = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
                            pack();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
                            packing = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
                };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
                rootPane.setOpaque(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
                return rootPane;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
        frame.getRootPane().setName("ToolBar.FloatingFrame");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
        frame.setResizable(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
        WindowListener wl = createFrameListener();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
        frame.addWindowListener(wl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
        return frame;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
     * Creates a window which contains the toolbar after it has been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
     * dragged out from its container
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
     * @return a <code>RootPaneContainer</code> object, containing the toolbar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
    protected RootPaneContainer createFloatingWindow(JToolBar toolbar) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
        class ToolBarDialog extends JDialog {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
            public ToolBarDialog(Frame owner, String title, boolean modal) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
                super(owner, title, modal);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
            public ToolBarDialog(Dialog owner, String title, boolean modal) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
                super(owner, title, modal);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
            // Override createRootPane() to automatically resize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
            // the frame when contents change
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
            protected JRootPane createRootPane() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
                JRootPane rootPane = new JRootPane() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
                    private boolean packing = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
                    public void validate() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
                        super.validate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
                        if (!packing) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
                            packing = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
                            pack();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
                            packing = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
                };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
                rootPane.setOpaque(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
                return rootPane;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
        JDialog dialog;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
        Window window = SwingUtilities.getWindowAncestor(toolbar);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
        if (window instanceof Frame) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
            dialog = new ToolBarDialog((Frame)window, toolbar.getName(), false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
        } else if (window instanceof Dialog) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
            dialog = new ToolBarDialog((Dialog)window, toolbar.getName(), false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
            dialog = new ToolBarDialog((Frame)null, toolbar.getName(), false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
        dialog.getRootPane().setName("ToolBar.FloatingWindow");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
        dialog.setTitle(toolbar.getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
        dialog.setResizable(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
        WindowListener wl = createFrameListener();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
        dialog.addWindowListener(wl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
        return dialog;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
    protected DragWindow createDragWindow(JToolBar toolbar) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
        Window frame = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
        if(toolBar != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
            Container p;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
            for(p = toolBar.getParent() ; p != null && !(p instanceof Window) ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
                p = p.getParent());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
            if(p != null && p instanceof Window)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
                frame = (Window) p;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
        if(floatingToolBar == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
            floatingToolBar = createFloatingWindow(toolBar);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
        if (floatingToolBar instanceof Window) frame = (Window) floatingToolBar;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
        DragWindow dragWindow = new DragWindow(frame);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
        return dragWindow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
     * Returns a flag to determine whether rollover button borders
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
     * are enabled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
     * @return true if rollover borders are enabled; false otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
     * @see #setRolloverBorders
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
    public boolean isRolloverBorders() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
        return rolloverBorders;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
     * Sets the flag for enabling rollover borders on the toolbar and it will
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 20169
diff changeset
   586
     * also install the appropriate border depending on the state of the flag.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
     * @param rollover if true, rollover borders are installed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
     *        Otherwise non-rollover borders are installed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
     * @see #isRolloverBorders
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
    public void setRolloverBorders( boolean rollover ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
        rolloverBorders = rollover;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
        if ( rolloverBorders )  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
            installRolloverBorders( toolBar );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
        } else  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
            installNonRolloverBorders( toolBar );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
     * Installs rollover borders on all the child components of the JComponent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
     * This is a convenience method to call <code>setBorderToRollover</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
     * for each child component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
     *
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 20169
diff changeset
   609
     * @param c container which holds the child components (usually a JToolBar)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
     * @see #setBorderToRollover
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
    protected void installRolloverBorders ( JComponent c )  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
        // Put rollover borders on buttons
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
        Component[] components = c.getComponents();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 438
diff changeset
   617
        for (Component component : components) {
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 438
diff changeset
   618
            if (component instanceof JComponent) {
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 438
diff changeset
   619
                ((JComponent) component).updateUI();
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 438
diff changeset
   620
                setBorderToRollover(component);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
        }
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
     * Installs non-rollover borders on all the child components of the JComponent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
     * A non-rollover border is the border that is installed on the child component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
     * while it is in the toolbar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
     * This is a convenience method to call <code>setBorderToNonRollover</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
     * for each child component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
     *
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 20169
diff changeset
   633
     * @param c container which holds the child components (usually a JToolBar)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
     * @see #setBorderToNonRollover
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
    protected void installNonRolloverBorders ( JComponent c )  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
        // Put non-rollover borders on buttons. These borders reduce the margin.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
        Component[] components = c.getComponents();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 438
diff changeset
   641
        for (Component component : components) {
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 438
diff changeset
   642
            if (component instanceof JComponent) {
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 438
diff changeset
   643
                ((JComponent) component).updateUI();
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 438
diff changeset
   644
                setBorderToNonRollover(component);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
        }
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
     * Installs normal borders on all the child components of the JComponent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
     * A normal border is the original border that was installed on the child
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
     * component before it was added to the toolbar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
     * This is a convenience method to call <code>setBorderNormal</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
     * for each child component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
     *
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 20169
diff changeset
   657
     * @param c container which holds the child components (usually a JToolBar)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
     * @see #setBorderToNonRollover
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
    protected void installNormalBorders ( JComponent c )  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
        // Put back the normal borders on buttons
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
        Component[] components = c.getComponents();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 438
diff changeset
   665
        for (Component component : components) {
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 438
diff changeset
   666
            setBorderToNormal(component);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
     * Sets the border of the component to have a rollover border which
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1299
diff changeset
   672
     * was created by the {@link #createRolloverBorder} method.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
     * @param c component which will have a rollover border installed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
     * @see #createRolloverBorder
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
    protected void setBorderToRollover(Component c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
        if (c instanceof AbstractButton) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
            AbstractButton b = (AbstractButton)c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 438
diff changeset
   682
            Border border = borderTable.get(b);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
            if (border == null || border instanceof UIResource) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
                borderTable.put(b, b.getBorder());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
            // Only set the border if its the default border
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
            if (b.getBorder() instanceof UIResource) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
                b.setBorder(getRolloverBorder(b));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
            rolloverTable.put(b, b.isRolloverEnabled()?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
                              Boolean.TRUE: Boolean.FALSE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
            b.setRolloverEnabled(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
     * Returns a rollover border for the button.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
     * @param b the button to calculate the rollover border for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
     * @return the rollover border
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
     * @see #setBorderToRollover
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
    protected Border getRolloverBorder(AbstractButton b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
        return rolloverBorder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
     * Sets the border of the component to have a non-rollover border which
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1299
diff changeset
   712
     * was created by the {@link #createNonRolloverBorder} method.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
     * @param c component which will have a non-rollover border installed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
     * @see #createNonRolloverBorder
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
    protected void setBorderToNonRollover(Component c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
        if (c instanceof AbstractButton) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
            AbstractButton b = (AbstractButton)c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 438
diff changeset
   722
            Border border = borderTable.get(b);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
            if (border == null || border instanceof UIResource) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
                borderTable.put(b, b.getBorder());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
            // Only set the border if its the default border
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
            if (b.getBorder() instanceof UIResource) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
                b.setBorder(getNonRolloverBorder(b));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
            rolloverTable.put(b, b.isRolloverEnabled()?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
                              Boolean.TRUE: Boolean.FALSE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
            b.setRolloverEnabled(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
     * Returns a non-rollover border for the button.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
     * @param b the button to calculate the non-rollover border for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
     * @return the non-rollover border
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
     * @see #setBorderToNonRollover
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
    protected Border getNonRolloverBorder(AbstractButton b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
        if (b instanceof JToggleButton) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
            return nonRolloverToggleBorder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
            return nonRolloverBorder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
     * Sets the border of the component to have a normal border.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
     * A normal border is the original border that was installed on the child
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
     * component before it was added to the toolbar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
     * @param c component which will have a normal border re-installed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
     * @see #createNonRolloverBorder
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
    protected void setBorderToNormal(Component c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
        if (c instanceof AbstractButton) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
            AbstractButton b = (AbstractButton)c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 438
diff changeset
   766
            Border border = borderTable.remove(b);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
            b.setBorder(border);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 438
diff changeset
   769
            Boolean value = rolloverTable.remove(b);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
            if (value != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
                b.setRolloverEnabled(value.booleanValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
    public void setFloatingLocation(int x, int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
        floatingX = x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
        floatingY = y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
    public boolean isFloating() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
        return floating;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
    public void setFloating(boolean b, Point p) {
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 438
diff changeset
   786
        if (toolBar.isFloatable()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
            boolean visible = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
            Window ancestor = SwingUtilities.getWindowAncestor(toolBar);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
            if (ancestor != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
                visible = ancestor.isVisible();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
            if (dragWindow != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
                dragWindow.setVisible(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
            this.floating = b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
            if (floatingToolBar == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
                floatingToolBar = createFloatingWindow(toolBar);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
            if (b == true)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
                if (dockingSource == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
                {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
                    dockingSource = toolBar.getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
                    dockingSource.remove(toolBar);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
                constraintBeforeFloating = calculateConstraint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
                if ( propertyListener != null )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
                    UIManager.addPropertyChangeListener( propertyListener );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
                floatingToolBar.getContentPane().add(toolBar,BorderLayout.CENTER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
                if (floatingToolBar instanceof Window) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
                    ((Window)floatingToolBar).pack();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
                    ((Window)floatingToolBar).setLocation(floatingX, floatingY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
                    if (visible) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
                        ((Window)floatingToolBar).show();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
                        ancestor.addWindowListener(new WindowAdapter() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
                            public void windowOpened(WindowEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
                                ((Window)floatingToolBar).show();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
                        });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
                if (floatingToolBar == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
                    floatingToolBar = createFloatingWindow(toolBar);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
                if (floatingToolBar instanceof Window) ((Window)floatingToolBar).setVisible(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
                floatingToolBar.getContentPane().remove(toolBar);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
                String constraint = getDockingConstraint(dockingSource,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
                                                         p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
                if (constraint == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
                    constraint = BorderLayout.NORTH;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
                int orientation = mapConstraintToOrientation(constraint);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
                setOrientation(orientation);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
                if (dockingSource== null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
                    dockingSource = toolBar.getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
                if ( propertyListener != null )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
                    UIManager.removePropertyChangeListener( propertyListener );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
                dockingSource.add(constraint, toolBar);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
            dockingSource.invalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
            Container dockingSourceParent = dockingSource.getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
            if (dockingSourceParent != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
                dockingSourceParent.validate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
            dockingSource.repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
    private int mapConstraintToOrientation(String constraint)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
        int orientation = toolBar.getOrientation();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
        if ( constraint != null )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
            if ( constraint.equals(BorderLayout.EAST) || constraint.equals(BorderLayout.WEST) )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
                orientation = JToolBar.VERTICAL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
            else if ( constraint.equals(BorderLayout.NORTH) || constraint.equals(BorderLayout.SOUTH) )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
                orientation = JToolBar.HORIZONTAL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
        return orientation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
    public void setOrientation(int orientation)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
        toolBar.setOrientation( orientation );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
        if (dragWindow !=null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
            dragWindow.setOrientation(orientation);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
     * Gets the color displayed when over a docking area
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
    public Color getDockingColor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
        return dockingColor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
     * Sets the color displayed when over a docking area
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
   public void setDockingColor(Color c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
        this.dockingColor = c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
     * Gets the color displayed when over a floating area
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
    public Color getFloatingColor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
        return floatingColor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
     * Sets the color displayed when over a floating area
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
    public void setFloatingColor(Color c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
        this.floatingColor = c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
    private boolean isBlocked(Component comp, Object constraint) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
        if (comp instanceof Container) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
            Container cont = (Container)comp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
            LayoutManager lm = cont.getLayout();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
            if (lm instanceof BorderLayout) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
                BorderLayout blm = (BorderLayout)lm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
                Component c = blm.getLayoutComponent(cont, constraint);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
                return (c != null && c != toolBar);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
    public boolean canDock(Component c, Point p) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
        return (p != null && getDockingConstraint(c, p) != null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
    private String calculateConstraint() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
        String constraint = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
        LayoutManager lm = dockingSource.getLayout();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
        if (lm instanceof BorderLayout) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
            constraint = (String)((BorderLayout)lm).getConstraints(toolBar);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
        return (constraint != null) ? constraint : constraintBeforeFloating;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
    private String getDockingConstraint(Component c, Point p) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
        if (p == null) return constraintBeforeFloating;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
        if (c.contains(p)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
            dockingSensitivity = (toolBar.getOrientation() == JToolBar.HORIZONTAL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
                                                ? toolBar.getSize().height
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
                                                : toolBar.getSize().width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
            // North  (Base distance on height for now!)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
            if (p.y < dockingSensitivity && !isBlocked(c, BorderLayout.NORTH)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
                return BorderLayout.NORTH;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
            // East  (Base distance on height for now!)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
            if (p.x >= c.getWidth() - dockingSensitivity && !isBlocked(c, BorderLayout.EAST)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
                return BorderLayout.EAST;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
            // West  (Base distance on height for now!)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
            if (p.x < dockingSensitivity && !isBlocked(c, BorderLayout.WEST)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
                return BorderLayout.WEST;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
            if (p.y >= c.getHeight() - dockingSensitivity && !isBlocked(c, BorderLayout.SOUTH)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
                return BorderLayout.SOUTH;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
    protected void dragTo(Point position, Point origin)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
    {
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 438
diff changeset
   954
        if (toolBar.isFloatable())
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
          try
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
          {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
            if (dragWindow == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
                dragWindow = createDragWindow(toolBar);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
            Point offset = dragWindow.getOffset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
            if (offset == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
                Dimension size = toolBar.getPreferredSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
                offset = new Point(size.width/2, size.height/2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
                dragWindow.setOffset(offset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
            Point global = new Point(origin.x+ position.x,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
                                     origin.y+position.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
            Point dragPoint = new Point(global.x- offset.x,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
                                        global.y- offset.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
            if (dockingSource == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
                dockingSource = toolBar.getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
                constraintBeforeFloating = calculateConstraint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
            Point dockingPosition = dockingSource.getLocationOnScreen();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
            Point comparisonPoint = new Point(global.x-dockingPosition.x,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
                                              global.y-dockingPosition.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
            if (canDock(dockingSource, comparisonPoint)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
                dragWindow.setBackground(getDockingColor());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
                String constraint = getDockingConstraint(dockingSource,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
                                                         comparisonPoint);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
                int orientation = mapConstraintToOrientation(constraint);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
                dragWindow.setOrientation(orientation);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
                dragWindow.setBorderColor(dockingBorderColor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
                dragWindow.setBackground(getFloatingColor());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
                dragWindow.setBorderColor(floatingBorderColor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
                dragWindow.setOrientation(toolBar.getOrientation());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
            dragWindow.setLocation(dragPoint.x, dragPoint.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
            if (dragWindow.isVisible() == false) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
                Dimension size = toolBar.getPreferredSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
                dragWindow.setSize(size.width, size.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
                dragWindow.show();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
          catch ( IllegalComponentStateException e )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
          {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
          }
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
    protected void floatAt(Point position, Point origin)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
    {
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 438
diff changeset
  1004
        if(toolBar.isFloatable())
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
          try
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
          {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
            Point offset = dragWindow.getOffset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
            if (offset == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
                offset = position;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
                dragWindow.setOffset(offset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
            Point global = new Point(origin.x+ position.x,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
                                     origin.y+position.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
            setFloatingLocation(global.x-offset.x,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
                                global.y-offset.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
            if (dockingSource != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
                Point dockingPosition = dockingSource.getLocationOnScreen();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
                Point comparisonPoint = new Point(global.x-dockingPosition.x,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
                                                  global.y-dockingPosition.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
                if (canDock(dockingSource, comparisonPoint)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
                    setFloating(false, comparisonPoint);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
                    setFloating(true, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
                setFloating(true, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
            dragWindow.setOffset(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
          catch ( IllegalComponentStateException e )
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
          {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
          }
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
    private Handler getHandler() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
        if (handler == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
            handler = new Handler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
        return handler;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
    protected ContainerListener createToolBarContListener( )
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
        return getHandler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
    protected FocusListener createToolBarFocusListener( )
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
        return getHandler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
    protected PropertyChangeListener createPropertyListener()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
        return getHandler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
    protected MouseInputListener createDockingListener( ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
        getHandler().tb = toolBar;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
        return getHandler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
    protected WindowListener createFrameListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
        return new FrameListener();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
     * Paints the contents of the window used for dragging.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
     * @param g Graphics to paint to.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
     * @throws NullPointerException is <code>g</code> is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
    protected void paintDragWindow(Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
        g.setColor(dragWindow.getBackground());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
        int w = dragWindow.getWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
        int h = dragWindow.getHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
        g.fillRect(0, 0, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
        g.setColor(dragWindow.getBorderColor());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
        g.drawRect(0, 0, w - 1, h - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
    private static class Actions extends UIAction {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
        private static final String NAVIGATE_RIGHT = "navigateRight";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
        private static final String NAVIGATE_LEFT = "navigateLeft";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
        private static final String NAVIGATE_UP = "navigateUp";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
        private static final String NAVIGATE_DOWN = "navigateDown";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
        public Actions(String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
            super(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
        public void actionPerformed(ActionEvent evt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
            String key = getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
            JToolBar toolBar = (JToolBar)evt.getSource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
            BasicToolBarUI ui = (BasicToolBarUI)BasicLookAndFeel.getUIOfType(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
                     toolBar.getUI(), BasicToolBarUI.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
            if (NAVIGATE_RIGHT == key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
                ui.navigateFocusedComp(EAST);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
            } else if (NAVIGATE_LEFT == key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
                ui.navigateFocusedComp(WEST);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
            } else if (NAVIGATE_UP == key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
                ui.navigateFocusedComp(NORTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
            } else if (NAVIGATE_DOWN == key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
                ui.navigateFocusedComp(SOUTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
        }
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
    private class Handler implements ContainerListener,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
            FocusListener, MouseInputListener, PropertyChangeListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
        // ContainerListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
        public void componentAdded(ContainerEvent evt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
            Component c = evt.getChild();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
            if (toolBarFocusListener != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
                c.addFocusListener(toolBarFocusListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
            if (isRolloverBorders()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
                setBorderToRollover(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
                setBorderToNonRollover(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
        public void componentRemoved(ContainerEvent evt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
            Component c = evt.getChild();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
            if (toolBarFocusListener != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
                c.removeFocusListener(toolBarFocusListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
            // Revert the button border
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
            setBorderToNormal(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
        // FocusListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
        public void focusGained(FocusEvent evt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
            Component c = evt.getComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
            focusedCompIndex = toolBar.getComponentIndex(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
        public void focusLost(FocusEvent evt) { }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
        // MouseInputListener (DockingListener)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
        JToolBar tb;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
        boolean isDragging = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
        Point origin = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
        public void mousePressed(MouseEvent evt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
            if (!tb.isEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
            isDragging = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
        public void mouseReleased(MouseEvent evt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
            if (!tb.isEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
            }
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 438
diff changeset
  1175
            if (isDragging) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
                Point position = evt.getPoint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
                if (origin == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
                    origin = evt.getComponent().getLocationOnScreen();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
                floatAt(position, origin);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
            origin = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
            isDragging = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
        public void mouseDragged(MouseEvent evt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
            if (!tb.isEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
            isDragging = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
            Point position = evt.getPoint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
            if (origin == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
                origin = evt.getComponent().getLocationOnScreen();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
            dragTo(position, origin);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
        public void mouseClicked(MouseEvent evt) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
        public void mouseEntered(MouseEvent evt) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
        public void mouseExited(MouseEvent evt) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
        public void mouseMoved(MouseEvent evt) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
        // PropertyChangeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
        public void propertyChange(PropertyChangeEvent evt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
            String propertyName = evt.getPropertyName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
            if (propertyName == "lookAndFeel") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
                toolBar.updateUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
            } else if (propertyName == "orientation") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
                // Search for JSeparator components and change it's orientation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
                // to match the toolbar and flip it's orientation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
                Component[] components = toolBar.getComponents();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
                int orientation = ((Integer)evt.getNewValue()).intValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
                JToolBar.Separator separator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
                for (int i = 0; i < components.length; ++i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
                    if (components[i] instanceof JToolBar.Separator) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
                        separator = (JToolBar.Separator)components[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
                        if ((orientation == JToolBar.HORIZONTAL)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
                            separator.setOrientation(JSeparator.VERTICAL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
                        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
                            separator.setOrientation(JSeparator.HORIZONTAL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
                        Dimension size = separator.getSeparatorSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
                        if (size != null && size.width != size.height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
                            // Flip the orientation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
                            Dimension newSize =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
                                new Dimension(size.height, size.width);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
                            separator.setSeparatorSize(newSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
            } else if (propertyName == IS_ROLLOVER) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
                installNormalBorders(toolBar);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
                setRolloverBorders(((Boolean)evt.getNewValue()).booleanValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
    protected class FrameListener extends WindowAdapter {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
        public void windowClosing(WindowEvent w) {
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 438
diff changeset
  1243
            if (toolBar.isFloatable()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
                if (dragWindow != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
                    dragWindow.setVisible(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
                floating = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
                if (floatingToolBar == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
                    floatingToolBar = createFloatingWindow(toolBar);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
                if (floatingToolBar instanceof Window) ((Window)floatingToolBar).setVisible(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
                floatingToolBar.getContentPane().remove(toolBar);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
                String constraint = constraintBeforeFloating;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
                if (toolBar.getOrientation() == JToolBar.HORIZONTAL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
                    if (constraint == "West" || constraint == "East") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
                        constraint = "North";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
                    if (constraint == "North" || constraint == "South") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
                        constraint = "West";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
                if (dockingSource == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
                    dockingSource = toolBar.getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
                if (propertyListener != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
                    UIManager.removePropertyChangeListener(propertyListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
                dockingSource.add(toolBar, constraint);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
                dockingSource.invalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
                Container dockingSourceParent = dockingSource.getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
                if (dockingSourceParent != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
                        dockingSourceParent.validate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
                dockingSource.repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
        }
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
    protected class ToolBarContListener implements ContainerListener {
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 20169
diff changeset
  1277
        // NOTE: This class exists only for backward compatibility. All
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
        // its functionality has been moved into Handler. If you need to add
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
        // new functionality add it to the Handler, but make sure this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
        // class calls into the Handler.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
        public void componentAdded( ContainerEvent e )  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
            getHandler().componentAdded(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
        public void componentRemoved( ContainerEvent e ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
            getHandler().componentRemoved(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
    protected class ToolBarFocusListener implements FocusListener {
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 20169
diff changeset
  1292
        // NOTE: This class exists only for backward compatibility. All
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
        // its functionality has been moved into Handler. If you need to add
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
        // new functionality add it to the Handler, but make sure this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
        // class calls into the Handler.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
        public void focusGained( FocusEvent e ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
            getHandler().focusGained(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
        public void focusLost( FocusEvent e ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
            getHandler().focusLost(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
    protected class PropertyListener implements PropertyChangeListener {
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 20169
diff changeset
  1306
        // NOTE: This class exists only for backward compatibility. All
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
        // its functionality has been moved into Handler. If you need to add
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
        // new functionality add it to the Handler, but make sure this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
        // class calls into the Handler.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
        public void propertyChange( PropertyChangeEvent e ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
            getHandler().propertyChange(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1316
     * This class should be treated as a &quot;protected&quot; inner class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1317
     * Instantiate it only within subclasses of BasicToolBarUI.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
    public class DockingListener implements MouseInputListener {
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 20169
diff changeset
  1320
        // NOTE: This class exists only for backward compatibility. All
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
        // its functionality has been moved into Handler. If you need to add
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
        // new functionality add it to the Handler, but make sure this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
        // class calls into the Handler.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
        protected JToolBar toolBar;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
        protected boolean isDragging = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1326
        protected Point origin = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
        public DockingListener(JToolBar t) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1329
            this.toolBar = t;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
            getHandler().tb = t;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1333
        public void mouseClicked(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
        getHandler().mouseClicked(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1335
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1336
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1337
        public void mousePressed(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1338
        getHandler().tb = toolBar;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1339
        getHandler().mousePressed(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1340
        isDragging = getHandler().isDragging;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1341
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1342
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1343
        public void mouseReleased(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1344
        getHandler().tb = toolBar;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1345
        getHandler().isDragging = isDragging;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1346
        getHandler().origin = origin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1347
        getHandler().mouseReleased(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1348
        isDragging = getHandler().isDragging;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1349
        origin = getHandler().origin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1350
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1351
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1352
        public void mouseEntered(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1353
        getHandler().mouseEntered(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1354
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1355
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1356
        public void mouseExited(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1357
        getHandler().mouseExited(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1358
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1359
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1360
        public void mouseDragged(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1361
        getHandler().tb = toolBar;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1362
        getHandler().origin = origin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1363
        getHandler().mouseDragged(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1364
        isDragging = getHandler().isDragging;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1365
        origin = getHandler().origin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1366
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1367
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1368
        public void mouseMoved(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1369
        getHandler().mouseMoved(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1370
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1371
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1372
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1373
    protected class DragWindow extends Window
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1374
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1375
        Color borderColor = Color.gray;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1376
        int orientation = toolBar.getOrientation();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1377
        Point offset; // offset of the mouse cursor inside the DragWindow
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1378
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1379
        DragWindow(Window w) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1380
            super(w);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1381
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1382
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1383
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1384
     * Returns the orientation of the toolbar window when the toolbar is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1385
     * floating. The orientation is either one of <code>JToolBar.HORIZONTAL</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1386
     * or <code>JToolBar.VERTICAL</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1387
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1388
     * @return the orientation of the toolbar window
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1389
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1390
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1391
    public int getOrientation() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1392
        return orientation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1393
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1394
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1395
        public void setOrientation(int o) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1396
            if(isShowing()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1397
                if (o == this.orientation)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1398
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1399
                this.orientation = o;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1400
                Dimension size = getSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1401
                setSize(new Dimension(size.height, size.width));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1402
                if (offset!=null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1403
                    if( BasicGraphicsUtils.isLeftToRight(toolBar) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1404
                        setOffset(new Point(offset.y, offset.x));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1405
                    } else if( o == JToolBar.HORIZONTAL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1406
                        setOffset(new Point( size.height-offset.y, offset.x));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1407
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1408
                        setOffset(new Point(offset.y, size.width-offset.x));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1409
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1410
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1411
                repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1412
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1413
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1414
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1415
        public Point getOffset() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1416
            return offset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1417
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1418
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1419
        public void setOffset(Point p) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1420
            this.offset = p;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1421
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1422
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1423
        public void setBorderColor(Color c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1424
            if (this.borderColor == c)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1425
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1426
            this.borderColor = c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1427
            repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1428
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1429
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1430
        public Color getBorderColor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1431
            return this.borderColor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1432
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1433
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1434
        public void paint(Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1435
            paintDragWindow(g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1436
            // Paint the children
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1437
            super.paint(g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1438
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1439
        public Insets getInsets() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1440
            return new Insets(1,1,1,1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1441
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1442
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1443
}