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