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