jdk/src/java.desktop/share/classes/javax/swing/MenuSelectionManager.java
author aghaisas
Mon, 10 Jul 2017 14:55:29 +0530
changeset 47151 362dcbee0613
parent 43722 25ba19c20260
permissions -rw-r--r--
6919529: NPE from MultiUIDefaults.getUIError Reviewed-by: aghaisas, psadhukhan, serb Contributed-by: shashidhara.veerabhadraiah@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
22584
eed64ee05369 8032733: Fix cast lint warnings in client libraries
darcy
parents: 11268
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: 1301
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: 1301
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: 1301
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1301
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1301
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
package javax.swing;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import javax.swing.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import sun.awt.AppContext;
23298
1c729daf92a0 7094099: DropDown List of JComboBox detached
anashaty
parents: 22584
diff changeset
    33
import sun.swing.SwingUtilities2;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * A MenuSelectionManager owns the selection in menu hierarchy.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * @author Arnaud Weber
25201
4adc75e0c4e5 8046485: Add missing @since tag under javax.swing.*
henryjen
parents: 23298
diff changeset
    39
 * @since 1.2
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
public class MenuSelectionManager {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
    42
    private Vector<MenuElement> selection = new Vector<MenuElement>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    /* diagnostic aids -- should be false for production builds. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    private static final boolean TRACE =   false; // trace creates and disposes
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    private static final boolean VERBOSE = false; // show reuse hits/misses
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    private static final boolean DEBUG =   false;  // show bad params, misc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    private static final StringBuilder MENU_SELECTION_MANAGER_KEY =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
                       new StringBuilder("javax.swing.MenuSelectionManager");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
     * Returns the default menu selection manager.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
     * @return a MenuSelectionManager object
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    public static MenuSelectionManager defaultManager() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        synchronized (MENU_SELECTION_MANAGER_KEY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
            AppContext context = AppContext.getAppContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
            MenuSelectionManager msm = (MenuSelectionManager)context.get(
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
                                                 MENU_SELECTION_MANAGER_KEY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
            if (msm == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
                msm = new MenuSelectionManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
                context.put(MENU_SELECTION_MANAGER_KEY, msm);
23298
1c729daf92a0 7094099: DropDown List of JComboBox detached
anashaty
parents: 22584
diff changeset
    65
1c729daf92a0 7094099: DropDown List of JComboBox detached
anashaty
parents: 22584
diff changeset
    66
                // installing additional listener if found in the AppContext
1c729daf92a0 7094099: DropDown List of JComboBox detached
anashaty
parents: 22584
diff changeset
    67
                Object o = context.get(SwingUtilities2.MENU_SELECTION_MANAGER_LISTENER_KEY);
1c729daf92a0 7094099: DropDown List of JComboBox detached
anashaty
parents: 22584
diff changeset
    68
                if (o != null && o instanceof ChangeListener) {
1c729daf92a0 7094099: DropDown List of JComboBox detached
anashaty
parents: 22584
diff changeset
    69
                    msm.addChangeListener((ChangeListener) o);
1c729daf92a0 7094099: DropDown List of JComboBox detached
anashaty
parents: 22584
diff changeset
    70
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
            return msm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * Only one ChangeEvent is needed per button model instance since the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * event's only state is the source property.  The source of events
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     * generated is always "this".
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    protected transient ChangeEvent changeEvent = null;
25386
9ef80c24fd74 8046590: fix doclint issues in swing classes, part 1 of 4
yan
parents: 25201
diff changeset
    83
    /** The collection of registered listeners */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    protected EventListenerList listenerList = new EventListenerList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * Changes the selection in the menu hierarchy.  The elements
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * in the array are sorted in order from the root menu
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * element to the currently selected menu element.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * Note that this method is public but is used by the look and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * feel engine and should not be called by client applications.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * @param path  an array of <code>MenuElement</code> objects specifying
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     *        the selected path
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    public void setSelectedPath(MenuElement[] path) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        int i,c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        int currentSelectionCount = selection.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        int firstDifference = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        if(path == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
            path = new MenuElement[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        if (DEBUG) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
            System.out.print("Previous:  "); printMenuElementArray(getSelectedPath());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
            System.out.print("New:  "); printMenuElementArray(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        for(i=0,c=path.length;i<c;i++) {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
   112
            if (i < currentSelectionCount && selection.elementAt(i) == path[i])
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
                firstDifference++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        for(i=currentSelectionCount - 1 ; i >= firstDifference ; i--) {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
   119
            MenuElement me = selection.elementAt(i);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
            selection.removeElementAt(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
            me.menuSelectionChanged(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        for(i = firstDifference, c = path.length ; i < c ; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
            if (path[i] != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
                selection.addElement(path[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
                path[i].menuSelectionChanged(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        fireStateChanged();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * Returns the path to the currently selected menu item
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * @return an array of MenuElement objects representing the selected path
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    public MenuElement[] getSelectedPath() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        MenuElement res[] = new MenuElement[selection.size()];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        int i,c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        for(i=0,c=selection.size();i<c;i++)
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
   143
            res[i] = selection.elementAt(i);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        return res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * Tell the menu selection to close and unselect all the menu components. Call this method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * when a choice has been made
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    public void clearSelectedPath() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        if (selection.size() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
            setSelectedPath(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * Adds a ChangeListener to the button.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * @param l the listener to add
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    public void addChangeListener(ChangeListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        listenerList.add(ChangeListener.class, l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     * Removes a ChangeListener from the button.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * @param l the listener to remove
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    public void removeChangeListener(ChangeListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        listenerList.remove(ChangeListener.class, l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * Returns an array of all the <code>ChangeListener</code>s added
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * to this MenuSelectionManager with addChangeListener().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * @return all of the <code>ChangeListener</code>s added or an empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     *         array if no listeners have been added
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    public ChangeListener[] getChangeListeners() {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
   184
        return listenerList.getListeners(ChangeListener.class);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * Notifies all listeners that have registered interest for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * notification on this event type.  The event instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * is created lazily.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * @see EventListenerList
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    protected void fireStateChanged() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        // Guaranteed to return a non-null array
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        Object[] listeners = listenerList.getListenerList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        // Process the listeners last to first, notifying
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        // those that are interested in this event
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        for (int i = listeners.length-2; i>=0; i-=2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
            if (listeners[i]==ChangeListener.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                // Lazily create the event:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
                if (changeEvent == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
                    changeEvent = new ChangeEvent(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
                ((ChangeListener)listeners[i+1]).stateChanged(changeEvent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * When a MenuElement receives an event from a MouseListener, it should never process the event
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * directly. Instead all MenuElements should call this method with the event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * @param event  a MouseEvent object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     */
43722
25ba19c20260 8143077: Deprecate InputEvent._MASK in favor of InputEvent._DOWN_MASK
serb
parents: 25859
diff changeset
   215
    @SuppressWarnings("deprecation")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    public void processMouseEvent(MouseEvent event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        int screenX,screenY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        Point p;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        int i,c,j,d;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        Component mc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        Rectangle r2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        int cWidth,cHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        MenuElement menuElement;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        MenuElement subElements[];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        MenuElement path[];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        int selectionSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        p = event.getPoint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
459
d555ba8bbec1 6690791: Even more ClassCasetException with TrayIcon
mlapshin
parents: 2
diff changeset
   229
        Component source = event.getComponent();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
459
d555ba8bbec1 6690791: Even more ClassCasetException with TrayIcon
mlapshin
parents: 2
diff changeset
   231
        if ((source != null) && !source.isShowing()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
            // This can happen if a mouseReleased removes the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            // containing component -- bug 4146684
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        int type = event.getID();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        int modifiers = event.getModifiers();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        // 4188027: drag enter/exit added in JDK 1.1.7A, JDK1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        if ((type==MouseEvent.MOUSE_ENTERED||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
             type==MouseEvent.MOUSE_EXITED)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
            && ((modifiers & (InputEvent.BUTTON1_MASK |
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
                              InputEvent.BUTTON2_MASK | InputEvent.BUTTON3_MASK)) !=0 )) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
459
d555ba8bbec1 6690791: Even more ClassCasetException with TrayIcon
mlapshin
parents: 2
diff changeset
   247
        if (source != null) {
d555ba8bbec1 6690791: Even more ClassCasetException with TrayIcon
mlapshin
parents: 2
diff changeset
   248
            SwingUtilities.convertPointToScreen(p, source);
d555ba8bbec1 6690791: Even more ClassCasetException with TrayIcon
mlapshin
parents: 2
diff changeset
   249
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        screenX = p.x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        screenY = p.y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
25568
b906a74c6882 8043550: Fix raw and unchecked lint warnings in javax.swing.*
darcy
parents: 25201
diff changeset
   254
        @SuppressWarnings("unchecked")
b906a74c6882 8043550: Fix raw and unchecked lint warnings in javax.swing.*
darcy
parents: 25201
diff changeset
   255
        Vector<MenuElement> tmp = (Vector<MenuElement>)selection.clone();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        selectionSize = tmp.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        boolean success = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        for (i=selectionSize - 1;i >= 0 && success == false; i--) {
22584
eed64ee05369 8032733: Fix cast lint warnings in client libraries
darcy
parents: 11268
diff changeset
   259
            menuElement = tmp.elementAt(i);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
            subElements = menuElement.getSubElements();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
            path = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
            for (j = 0, d = subElements.length;j < d && success == false; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
                if (subElements[j] == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
                mc = subElements[j].getComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
                if(!mc.isShowing())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
                if(mc instanceof JComponent) {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
   270
                    cWidth  = mc.getWidth();
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
   271
                    cHeight = mc.getHeight();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
                    r2 = mc.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
                    cWidth  = r2.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
                    cHeight = r2.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
                p.x = screenX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
                p.y = screenY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
                SwingUtilities.convertPointFromScreen(p,mc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
                /** Send the event to visible menu element if menu element currently in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
                 *  the selected path or contains the event location
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
                if(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
                   (p.x >= 0 && p.x < cWidth && p.y >= 0 && p.y < cHeight)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
                    int k;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
                    if(path == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
                        path = new MenuElement[i+2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
                        for(k=0;k<=i;k++)
22584
eed64ee05369 8032733: Fix cast lint warnings in client libraries
darcy
parents: 11268
diff changeset
   290
                            path[k] = tmp.elementAt(k);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
                    path[i+1] = subElements[j];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
                    MenuElement currentSelection[] = getSelectedPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
                    // Enter/exit detection -- needs tuning...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
                    if (currentSelection[currentSelection.length-1] !=
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
                        path[i+1] &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
                        (currentSelection.length < 2 ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
                         currentSelection[currentSelection.length-2] !=
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
                         path[i+1])) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
                        Component oldMC = currentSelection[currentSelection.length-1].getComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
                        MouseEvent exitEvent = new MouseEvent(oldMC, MouseEvent.MOUSE_EXITED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
                                                              event.getWhen(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
                                                              event.getModifiers(), p.x, p.y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
                                                              event.getXOnScreen(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
                                                              event.getYOnScreen(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
                                                              event.getClickCount(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
                                                              event.isPopupTrigger(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
                                                              MouseEvent.NOBUTTON);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
                        currentSelection[currentSelection.length-1].
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
                            processMouseEvent(exitEvent, path, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
                        MouseEvent enterEvent = new MouseEvent(mc,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
                                                               MouseEvent.MOUSE_ENTERED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
                                                               event.getWhen(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
                                                               event.getModifiers(), p.x, p.y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
                                                               event.getXOnScreen(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
                                                               event.getYOnScreen(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
                                                               event.getClickCount(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
                                                               event.isPopupTrigger(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
                                                               MouseEvent.NOBUTTON);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
                        subElements[j].processMouseEvent(enterEvent, path, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
                    MouseEvent mouseEvent = new MouseEvent(mc, event.getID(),event. getWhen(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
                                                           event.getModifiers(), p.x, p.y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
                                                           event.getXOnScreen(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
                                                           event.getYOnScreen(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
                                                           event.getClickCount(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
                                                           event.isPopupTrigger(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
                                                           MouseEvent.NOBUTTON);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
                    subElements[j].processMouseEvent(mouseEvent, path, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
                    success = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
                    event.consume();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
    private void printMenuElementArray(MenuElement path[]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        printMenuElementArray(path, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
    private void printMenuElementArray(MenuElement path[], boolean dumpStack) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        System.out.println("Path is(");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        int i, j;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
        for(i=0,j=path.length; i<j ;i++){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
            for (int k=0; k<=i; k++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
                System.out.print("  ");
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
   350
            MenuElement me = path[i];
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
            if(me instanceof JMenuItem) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
                System.out.println(((JMenuItem)me).getText() + ", ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
            } else if (me instanceof JMenuBar) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
                System.out.println("JMenuBar, ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
            } else if(me instanceof JPopupMenu) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
                System.out.println("JPopupMenu, ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
            } else if (me == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
                System.out.println("NULL , ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
                System.out.println("" + me + ", ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        System.out.println(")");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
        if (dumpStack == true)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
            Thread.dumpStack();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     * Returns the component in the currently selected path
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     * which contains sourcePoint.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     * @param source The component in whose coordinate space sourcePoint
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
     *        is given
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
     * @param sourcePoint The point which is being tested
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
     * @return The component in the currently selected path which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
     *         contains sourcePoint (relative to the source component's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
     *         coordinate space.  If sourcePoint is not inside a component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
     *         on the currently selected path, null is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
    public Component componentForPoint(Component source, Point sourcePoint) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        int screenX,screenY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
        Point p = sourcePoint;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        int i,c,j,d;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
        Component mc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        Rectangle r2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        int cWidth,cHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
        MenuElement menuElement;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        MenuElement subElements[];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
        int selectionSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
        SwingUtilities.convertPointToScreen(p,source);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        screenX = p.x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
        screenY = p.y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
25568
b906a74c6882 8043550: Fix raw and unchecked lint warnings in javax.swing.*
darcy
parents: 25201
diff changeset
   397
        @SuppressWarnings("unchecked")
b906a74c6882 8043550: Fix raw and unchecked lint warnings in javax.swing.*
darcy
parents: 25201
diff changeset
   398
        Vector<MenuElement> tmp = (Vector<MenuElement>)selection.clone();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        selectionSize = tmp.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        for(i=selectionSize - 1 ; i >= 0 ; i--) {
22584
eed64ee05369 8032733: Fix cast lint warnings in client libraries
darcy
parents: 11268
diff changeset
   401
            menuElement = tmp.elementAt(i);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
            subElements = menuElement.getSubElements();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
            for(j = 0, d = subElements.length ; j < d ; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
                if (subElements[j] == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
                mc = subElements[j].getComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
                if(!mc.isShowing())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
                if(mc instanceof JComponent) {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
   411
                    cWidth  = mc.getWidth();
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
   412
                    cHeight = mc.getHeight();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
                    r2 = mc.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
                    cWidth  = r2.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
                    cHeight = r2.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
                p.x = screenX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
                p.y = screenY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
                SwingUtilities.convertPointFromScreen(p,mc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
                /** Return the deepest component on the selection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
                 *  path in whose bounds the event's point occurs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
                if (p.x >= 0 && p.x < cWidth && p.y >= 0 && p.y < cHeight) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
                    return mc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
     * When a MenuElement receives an event from a KeyListener, it should never process the event
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
     * directly. Instead all MenuElements should call this method with the event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
     * @param e  a KeyEvent object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
    public void processKeyEvent(KeyEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
        MenuElement[] sel2 = new MenuElement[0];
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
   441
        sel2 = selection.toArray(sel2);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
        int selSize = sel2.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
        MenuElement[] path;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
        if (selSize < 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
        for (int i=selSize-1; i>=0; i--) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
            MenuElement elem = sel2[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
            MenuElement[] subs = elem.getSubElements();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
            path = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
            for (int j=0; j<subs.length; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
                if (subs[j] == null || !subs[j].getComponent().isShowing()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
                    || !subs[j].getComponent().isEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
                if(path == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
                    path = new MenuElement[i+2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
                    System.arraycopy(sel2, 0, path, 0, i+1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
                path[i+1] = subs[j];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
                subs[j].processKeyEvent(e, path, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
                if (e.isConsumed()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
                    return;
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
        // finally dispatch event to the first component in path
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
        path = new MenuElement[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
        path[0] = sel2[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
        path[0].processKeyEvent(e, path, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
        if (e.isConsumed()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
    /**
25386
9ef80c24fd74 8046590: fix doclint issues in swing classes, part 1 of 4
yan
parents: 25201
diff changeset
   482
     * Return true if {@code c} is part of the currently used menu
9ef80c24fd74 8046590: fix doclint issues in swing classes, part 1 of 4
yan
parents: 25201
diff changeset
   483
     *
9ef80c24fd74 8046590: fix doclint issues in swing classes, part 1 of 4
yan
parents: 25201
diff changeset
   484
     * @param c a {@code Component}
9ef80c24fd74 8046590: fix doclint issues in swing classes, part 1 of 4
yan
parents: 25201
diff changeset
   485
     * @return true if {@code c} is part of the currently used menu,
9ef80c24fd74 8046590: fix doclint issues in swing classes, part 1 of 4
yan
parents: 25201
diff changeset
   486
     *         false otherwise
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
    public boolean isComponentPartOfCurrentMenu(Component c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
        if(selection.size() > 0) {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
   490
            MenuElement me = selection.elementAt(0);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
            return isComponentPartOfCurrentMenu(me,c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
        } else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
    private boolean isComponentPartOfCurrentMenu(MenuElement root,Component c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
        MenuElement children[];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
        int i,d;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
        if (root == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
        if(root.getComponent() == c)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
            children = root.getSubElements();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
            for(i=0,d=children.length;i<d;i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
                if(isComponentPartOfCurrentMenu(children[i],c))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
                    return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
}