jdk/src/share/classes/javax/swing/plaf/basic/BasicRootPaneUI.java
author prr
Mon, 14 Jul 2014 09:48:26 -0700
changeset 25777 bb88947b6766
parent 25761 c408b10ef757
permissions -rw-r--r--
8049893: Replace uses of 'new Integer()' with appropriate alternative across client classes Reviewed-by: prr, pchelko Contributed-by: 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: 5506
diff changeset
     2
 * Copyright (c) 1999, 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: 2
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: 2
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: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
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 java.awt.event.ActionEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.KeyboardFocusManager;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.awt.Component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.awt.Point;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.awt.Rectangle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.beans.PropertyChangeEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.beans.PropertyChangeListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import javax.swing.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import javax.swing.plaf.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import sun.swing.DefaultLookup;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import sun.swing.UIAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * Basic implementation of RootPaneUI, there is one shared between all
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * JRootPane instances.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * @author Scott Violet
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
public class BasicRootPaneUI extends RootPaneUI implements
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
                  PropertyChangeListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    private static RootPaneUI rootPaneUI = new BasicRootPaneUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
25761
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 23697
diff changeset
    51
    /**
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 23697
diff changeset
    52
     * Returns a new instance of {@code BasicRootPaneUI}.
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 23697
diff changeset
    53
     *
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 23697
diff changeset
    54
     * @param c a component
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 23697
diff changeset
    55
     * @return a new instance of {@code BasicRootPaneUI}
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 23697
diff changeset
    56
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    public static ComponentUI createUI(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        return rootPaneUI;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    public void installUI(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        installDefaults((JRootPane)c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        installComponents((JRootPane)c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        installListeners((JRootPane)c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        installKeyboardActions((JRootPane)c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    public void uninstallUI(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        uninstallDefaults((JRootPane)c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        uninstallComponents((JRootPane)c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        uninstallListeners((JRootPane)c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        uninstallKeyboardActions((JRootPane)c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
25761
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 23697
diff changeset
    76
    /**
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 23697
diff changeset
    77
     * Installs default properties.
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 23697
diff changeset
    78
     *
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 23697
diff changeset
    79
     * @param c an instance of {@code JRootPane}
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 23697
diff changeset
    80
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    protected void installDefaults(JRootPane c){
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        LookAndFeel.installProperty(c, "opaque", Boolean.FALSE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
25761
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 23697
diff changeset
    85
    /**
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 23697
diff changeset
    86
     * Installs components.
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 23697
diff changeset
    87
     *
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 23697
diff changeset
    88
     * @param root an instance of {@code JRootPane}
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 23697
diff changeset
    89
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    protected void installComponents(JRootPane root) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
25761
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 23697
diff changeset
    93
    /**
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 23697
diff changeset
    94
     * Registers listeners.
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 23697
diff changeset
    95
     *
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 23697
diff changeset
    96
     * @param root an instance of {@code JRootPane}
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 23697
diff changeset
    97
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    protected void installListeners(JRootPane root) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        root.addPropertyChangeListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
25761
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 23697
diff changeset
   102
    /**
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 23697
diff changeset
   103
     * Registers keyboard actions.
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 23697
diff changeset
   104
     *
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 23697
diff changeset
   105
     * @param root an instance of {@code JRootPane}
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 23697
diff changeset
   106
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    protected void installKeyboardActions(JRootPane root) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        InputMap km = getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW, root);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        SwingUtilities.replaceUIInputMap(root,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
                JComponent.WHEN_IN_FOCUSED_WINDOW, km);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        km = getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
                root);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        SwingUtilities.replaceUIInputMap(root,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
                JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, km);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        LazyActionMap.installLazyActionMap(root, BasicRootPaneUI.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
                "RootPane.actionMap");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        updateDefaultButtonBindings(root);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
25761
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 23697
diff changeset
   121
    /**
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 23697
diff changeset
   122
     * Uninstalls default properties.
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 23697
diff changeset
   123
     *
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 23697
diff changeset
   124
     * @param root an instance of {@code JRootPane}
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 23697
diff changeset
   125
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    protected void uninstallDefaults(JRootPane root) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
25761
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 23697
diff changeset
   129
    /**
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 23697
diff changeset
   130
     * Unregisters components.
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 23697
diff changeset
   131
     *
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 23697
diff changeset
   132
     * @param root an instance of {@code JRootPane}
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 23697
diff changeset
   133
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    protected void uninstallComponents(JRootPane root) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
25761
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 23697
diff changeset
   137
    /**
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 23697
diff changeset
   138
     * Unregisters listeners.
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 23697
diff changeset
   139
     *
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 23697
diff changeset
   140
     * @param root an instance of {@code JRootPane}
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 23697
diff changeset
   141
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    protected void uninstallListeners(JRootPane root) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        root.removePropertyChangeListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
25761
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 23697
diff changeset
   146
    /**
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 23697
diff changeset
   147
     * Unregisters keyboard actions.
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 23697
diff changeset
   148
     *
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 23697
diff changeset
   149
     * @param root an instance of {@code JRootPane}
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 23697
diff changeset
   150
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    protected void uninstallKeyboardActions(JRootPane root) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        SwingUtilities.replaceUIInputMap(root, JComponent.
25761
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 23697
diff changeset
   153
                WHEN_IN_FOCUSED_WINDOW, null);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        SwingUtilities.replaceUIActionMap(root, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    InputMap getInputMap(int condition, JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        if (condition == JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
            return (InputMap)DefaultLookup.get(c, this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
                                       "RootPane.ancestorInputMap");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        if (condition == JComponent.WHEN_IN_FOCUSED_WINDOW) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
            return createInputMap(condition, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    ComponentInputMap createInputMap(int condition, JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        return new RootPaneInputMap(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    static void loadActionMap(LazyActionMap map) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        map.put(new Actions(Actions.PRESS));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        map.put(new Actions(Actions.RELEASE));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        map.put(new Actions(Actions.POST_POPUP));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * Invoked when the default button property has changed. This reloads
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * the bindings from the defaults table with name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * <code>RootPane.defaultButtonWindowKeyBindings</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    void updateDefaultButtonBindings(JRootPane root) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        InputMap km = SwingUtilities.getUIInputMap(root, JComponent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
                                               WHEN_IN_FOCUSED_WINDOW);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        while (km != null && !(km instanceof RootPaneInputMap)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
            km = km.getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        if (km != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
            km.clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
            if (root.getDefaultButton() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
                Object[] bindings = (Object[])DefaultLookup.get(root, this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
                           "RootPane.defaultButtonWindowKeyBindings");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
                if (bindings != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
                    LookAndFeel.loadKeyBindings(km, bindings);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     * Invoked when a property changes on the root pane. If the event
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * indicates the <code>defaultButton</code> has changed, this will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * reinstall the keyboard actions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    public void propertyChange(PropertyChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        if(e.getPropertyName().equals("defaultButton")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
            JRootPane rootpane = (JRootPane)e.getSource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
            updateDefaultButtonBindings(rootpane);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
            if (rootpane.getClientProperty("temporaryDefaultButton") == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
                rootpane.putClientProperty("initialDefaultButton", e.getNewValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    static class Actions extends UIAction {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        public static final String PRESS = "press";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        public static final String RELEASE = "release";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        public static final String POST_POPUP = "postPopup";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        Actions(String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
            super(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        public void actionPerformed(ActionEvent evt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
            JRootPane root = (JRootPane)evt.getSource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
            JButton owner = root.getDefaultButton();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
            String key = getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
            if (key == POST_POPUP) { // Action to post popup
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
                Component c = KeyboardFocusManager
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
                        .getCurrentKeyboardFocusManager()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
                         .getFocusOwner();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                if(c instanceof JComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
                    JComponent src = (JComponent) c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
                    JPopupMenu jpm = src.getComponentPopupMenu();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                    if(jpm != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                        Point pt = src.getPopupLocation(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                        if(pt == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
                            Rectangle vis = src.getVisibleRect();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                            pt = new Point(vis.x+vis.width/2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                                           vis.y+vis.height/2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
                        jpm.show(c, pt.x, pt.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
            else if (owner != null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
                     && SwingUtilities.getRootPane(owner) == root) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
                if (key == PRESS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
                    owner.doClick(20);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        public boolean isEnabled(Object sender) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
            String key = getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
            if(key == POST_POPUP) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
                MenuElement[] elems = MenuSelectionManager
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
                        .defaultManager()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
                        .getSelectedPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
                if(elems != null && elems.length != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
                    return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
                    // We shall not interfere with already opened menu
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
                Component c = KeyboardFocusManager
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
                       .getCurrentKeyboardFocusManager()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
                        .getFocusOwner();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
                if(c instanceof JComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
                    JComponent src = (JComponent) c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
                    return src.getComponentPopupMenu() != null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
            if (sender != null && sender instanceof JRootPane) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
                JButton owner = ((JRootPane)sender).getDefaultButton();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
                return (owner != null && owner.getModel().isEnabled());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 5506
diff changeset
   289
    @SuppressWarnings("serial") // JDK-implementation class
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    private static class RootPaneInputMap extends ComponentInputMapUIResource {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        public RootPaneInputMap(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
            super(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
}