jdk/src/solaris/classes/sun/awt/X11/XBaseMenuWindow.java
author leonidr
Wed, 02 Oct 2013 17:06:09 +0400
changeset 20449 20326f6cd2aa
parent 18525 2d5db9a68add
child 21278 ef8a3a2a72f2
permissions -rw-r--r--
8023994: Right click on the icon added to the system tray for the first time, java.lang.IllegalArgumentException thrown. Reviewed-by: anthony, serb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
18520
7fad3f87d731 8014264: The applet pathguy_TimeDead throws java.lang.NullPointerException in java console once click drop-down check box.
leonidr
parents: 16839
diff changeset
     2
 * Copyright (c) 2005, 2013, 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: 3938
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: 3938
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: 3938
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3938
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3938
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
package sun.awt.X11;
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.awt.peer.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.awt.image.ColorModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import sun.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.util.ArrayList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.util.Vector;
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 439
diff changeset
    36
import sun.util.logging.PlatformLogger;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import sun.java2d.SurfaceData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import sun.java2d.SunGraphics2D;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * The abstract class XBaseMenuWindow is the superclass
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * of all menu windows.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
abstract public class XBaseMenuWindow extends XWindow {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    /************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
     * Data members
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
     ************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 439
diff changeset
    52
    private static PlatformLogger log = PlatformLogger.getLogger("sun.awt.X11.XBaseMenuWindow");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
     * Colors are calculated using MotifColorUtilities class
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
     * from backgroundColor and are contained in these vars.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    private Color backgroundColor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    private Color foregroundColor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    private Color lightShadowColor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    private Color darkShadowColor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    private Color selectedColor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    private Color disabledColor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     * Array of items.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    private ArrayList<XMenuItemPeer> items;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     * Index of selected item in array of items
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    private int selectedIndex = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * Specifies currently showing submenu.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    private XMenuPeer showingSubmenu = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * Static synchronizational object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * Following operations should be synchronized
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * using this object:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * 1. Access to items vector
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     * 2. Access to selection
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * 3. Access to showing menu window member
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * This is lowest level lock,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * no other locks should be taken when
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * thread own this lock.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    static private Object menuTreeLock = new Object();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    /************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * Event processing
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     ************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * If mouse button is clicked on item showing submenu
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * we have to hide its submenu.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * And if mouse button is pressed on such item and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * dragged to another, getShowingSubmenu() is changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * So this member saves the item that the user
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * presses mouse button on _only_ if it's showing submenu.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    private XMenuPeer showingMousePressedSubmenu = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * If the PopupMenu is invoked as a result of right button click
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * first mouse event after grabInput would be MouseReleased.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * We need to check if the user has moved mouse after input grab.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * If yes - hide the PopupMenu. If no - do nothing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    protected Point grabInputPoint = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    protected boolean hasPointerMoved = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
20449
20326f6cd2aa 8023994: Right click on the icon added to the system tray for the first time, java.lang.IllegalArgumentException thrown.
leonidr
parents: 18525
diff changeset
   119
    private AppContext disposeAppContext;
20326f6cd2aa 8023994: Right click on the icon added to the system tray for the first time, java.lang.IllegalArgumentException thrown.
leonidr
parents: 18525
diff changeset
   120
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    /************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * Mapping data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     ************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * Mapping data that is filled in getMappedItems function
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * and reset in resetSize function. It contains array of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * items in order that they appear on screen and may contain
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * additional data defined by descendants.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    private MappingData mappingData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    static class MappingData implements Cloneable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
         * Array of item in order that they appear on screen
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        private XMenuItemPeer[] items;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
         * Constructs MappingData object with list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
         * of menu items
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        MappingData(XMenuItemPeer[] items) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            this.items = items;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
         * Constructs MappingData without items
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
         * This constructor should be used in case of errors
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        MappingData() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
            this.items = new XMenuItemPeer[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        public Object clone() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
                return super.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            } catch (CloneNotSupportedException ex) {
10419
12c063b39232 7084245: Update usages of InternalError to use exception chaining
sherman
parents: 5506
diff changeset
   162
                throw new InternalError(ex);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        public XMenuItemPeer[] getItems() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
            return this.items;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    /************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * Construction
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     ************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    XBaseMenuWindow() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        super(new XCreateWindowParams(new Object[] {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
            DELAYED, Boolean.TRUE}));
20449
20326f6cd2aa 8023994: Right click on the icon added to the system tray for the first time, java.lang.IllegalArgumentException thrown.
leonidr
parents: 18525
diff changeset
   179
20326f6cd2aa 8023994: Right click on the icon added to the system tray for the first time, java.lang.IllegalArgumentException thrown.
leonidr
parents: 18525
diff changeset
   180
        disposeAppContext = AppContext.getAppContext();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    /************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * Abstract methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     ************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * Returns parent menu window (not the X-heirarchy parent window)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    protected abstract XBaseMenuWindow getParentMenuWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * Performs mapping of items in window.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * This function creates and fills specific
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * descendant of MappingData
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * and sets mapping coordinates of items
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * This function should return default menu data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * if errors occur
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    protected abstract MappingData map();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * Calculates placement of submenu window
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * given bounds of item with submenu and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * size of submenu window. Returns suggested
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * rectangle for submenu window in global coordinates
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * @param itemBounds the bounding rectangle of item
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * in local coordinates
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * @param windowSize the desired size of submenu's window
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    protected abstract Rectangle getSubmenuBounds(Rectangle itemBounds, Dimension windowSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * This function is to be called if it's likely that size
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * of items was changed. It can be called from any thread
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * in any locked state, so it should not take locks
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    protected abstract void updateSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    /************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * Initialization
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     ************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * Overrides XBaseWindow.instantPreInit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    void instantPreInit(XCreateWindowParams params) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        super.instantPreInit(params);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        items = new ArrayList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    /************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * General-purpose functions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     ************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     * Returns static lock used for menus
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    static Object getMenuTreeLock() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        return menuTreeLock;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * This function is called to clear all saved
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     * size data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    protected void resetMapping() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        mappingData = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     * Invokes repaint procedure on eventHandlerThread
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    void postPaintEvent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        if (isShowing()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
            PaintEvent pe = new PaintEvent(target, PaintEvent.PAINT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
                                           new Rectangle(0, 0, width, height));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
            postEvent(pe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    /************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     * Utility functions for manipulating items
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     ************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * Thread-safely returns item at specified index
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * @param index the position of the item to be returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    XMenuItemPeer getItem(int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        if (index >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
            synchronized(getMenuTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
                if (items.size() > index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
                    return items.get(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     * Thread-safely creates a copy of the items vector
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    XMenuItemPeer[] copyItems() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        synchronized(getMenuTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
            return (XMenuItemPeer[])items.toArray(new XMenuItemPeer[] {});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     * Thread-safely returns selected item
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    XMenuItemPeer getSelectedItem() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        synchronized(getMenuTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
            if (selectedIndex >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
                if (items.size() > selectedIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
                    return items.get(selectedIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     * Returns showing submenu, if any
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    XMenuPeer getShowingSubmenu() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        synchronized(getMenuTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
            return showingSubmenu;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     * Adds item to end of items vector.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     * Note that this function does not perform
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     * check for adding duplicate items
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     * @param item item to add
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
    public void addItem(MenuItem item) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        XMenuItemPeer mp = (XMenuItemPeer)item.getPeer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        if (mp != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
            mp.setContainer(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
            synchronized(getMenuTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
                items.add(mp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        } else {
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16839
diff changeset
   337
            if (log.isLoggable(PlatformLogger.Level.FINE)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
                log.fine("WARNING: Attempt to add menu item without a peer");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        updateSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     * Removes item at the specified index from items vector.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     * @param index the position of the item to be removed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
    public void delItem(int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        synchronized(getMenuTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
            if (selectedIndex == index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
                selectItem(null, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
            } else if (selectedIndex > index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
                selectedIndex--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
            if (index < items.size()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
                items.remove(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
            } else {
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16839
diff changeset
   358
                if (log.isLoggable(PlatformLogger.Level.FINE)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
                    log.fine("WARNING: Attempt to remove non-existing menu item, index : " + index + ", item count : " + items.size());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        updateSize();
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
     * Clears items vector and loads specified vector
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
     * @param items vector to be loaded
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
    public void reloadItems(Vector items) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
        synchronized(getMenuTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
            this.items.clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
            MenuItem[] itemArray = (MenuItem[])items.toArray(new MenuItem[] {});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
            int itemCnt = itemArray.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
            for(int i = 0; i < itemCnt; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
                addItem(itemArray[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
     * Select specified item and shows/hides submenus if necessary
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
     * We can not select by index, so we need to select by ref.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
     * @param item the item to be selected, null to clear selection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
     * @param showWindowIfMenu if the item is XMenuPeer then its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
     * window is shown/hidden according to this param.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
    void selectItem(XMenuItemPeer item, boolean showWindowIfMenu) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        synchronized(getMenuTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
            XMenuPeer showingSubmenu = getShowingSubmenu();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
            int newSelectedIndex = (item != null) ? items.indexOf(item) : -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
            if (this.selectedIndex != newSelectedIndex) {
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16839
diff changeset
   393
                if (log.isLoggable(PlatformLogger.Level.FINEST)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
                    log.finest("Selected index changed, was : " + this.selectedIndex + ", new : " + newSelectedIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
                this.selectedIndex = newSelectedIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
                postPaintEvent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
            final XMenuPeer submenuToShow = (showWindowIfMenu && (item instanceof XMenuPeer)) ? (XMenuPeer)item : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
            if (submenuToShow != showingSubmenu) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
                XToolkit.executeOnEventHandlerThread(target, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
                        public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
                            doShowSubmenu(submenuToShow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
                    });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     * Performs hiding of currently showing submenu
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     * and showing of submenuToShow.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     * This function should be executed on eventHandlerThread
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     * @param submenuToShow submenu to be shown or null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     * to hide currently showing submenu
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
    private void doShowSubmenu(XMenuPeer submenuToShow) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
        XMenuWindow menuWindowToShow = (submenuToShow != null) ? submenuToShow.getMenuWindow() : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
        Dimension dim = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
        Rectangle bounds = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
        //ensureCreated can invoke XWindowPeer.init() ->
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
        //XWindowPeer.initGraphicsConfiguration() ->
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
        //Window.getGraphicsConfiguration()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
        //that tries to obtain Component.AWTTreeLock.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
        //So it should be called outside awtLock()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
        if (menuWindowToShow != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
            menuWindowToShow.ensureCreated();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
            synchronized(getMenuTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
                if (showingSubmenu != submenuToShow) {
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16839
diff changeset
   433
                    if (log.isLoggable(PlatformLogger.Level.FINEST)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
                        log.finest("Changing showing submenu");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
                    if (showingSubmenu != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
                        XMenuWindow showingSubmenuWindow = showingSubmenu.getMenuWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
                        if (showingSubmenuWindow != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
                            showingSubmenuWindow.hide();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
                    if (submenuToShow != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
                        dim = menuWindowToShow.getDesiredSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
                        bounds = menuWindowToShow.getParentMenuWindow().getSubmenuBounds(submenuToShow.getBounds(), dim);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
                        menuWindowToShow.show(bounds);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
                    showingSubmenu = submenuToShow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
    final void setItemsFont( Font font ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
        XMenuItemPeer[] items = copyItems();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
        int itemCnt = items.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
        for (int i = 0; i < itemCnt; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
            items[i].setFont(font);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
    /************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
     * Utility functions for manipulating mapped items
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
     * Returns array of mapped items, null if error
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
     * This function has to be not synchronized
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
     * and we have to guarantee that we return
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
     * some MappingData to user. It's OK if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
     * this.mappingData is replaced meanwhile
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
    MappingData getMappingData() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
        MappingData mappingData = this.mappingData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
        if (mappingData == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
            mappingData = map();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
            this.mappingData = mappingData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
        return (MappingData)mappingData.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
     * returns item thats mapped coordinates contain
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
     * specified point, null of none.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
     * @param pt the point in this window's coordinate system
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
    XMenuItemPeer getItemFromPoint(Point pt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
        XMenuItemPeer[] items = getMappingData().getItems();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
        int cnt = items.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
        for (int i = 0; i < cnt; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
            if (items[i].getBounds().contains(pt)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
                return items[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
     * Returns first item after currently selected
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
     * item that can be selected according to mapping array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
     * (no separators and no disabled items).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
     * Currently selected item if it's only selectable,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
     * null if no item can be selected
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
    XMenuItemPeer getNextSelectableItem() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
        XMenuItemPeer[] mappedItems = getMappingData().getItems();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
        XMenuItemPeer selectedItem = getSelectedItem();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
        int cnt = mappedItems.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
        //Find index of selected item
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
        int selIdx = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
        for (int i = 0; i < cnt; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
            if (mappedItems[i] == selectedItem) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
                selIdx = i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
        int idx = (selIdx == cnt - 1) ? 0 : selIdx + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
        //cycle through mappedItems to find selectable item
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
        //beginning from the next item and moving to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
        //beginning of array when end is reached.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
        //Cycle is finished on selected item itself
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
        for (int i = 0; i < cnt; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
            XMenuItemPeer item = mappedItems[idx];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
            if (!item.isSeparator() && item.isTargetItemEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
                return item;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
            idx++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
            if (idx >= cnt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
                idx = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
        //return null if no selectable item was found
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
     * Returns first item before currently selected
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
     * see getNextSelectableItem() for comments
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
    XMenuItemPeer getPrevSelectableItem() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
        XMenuItemPeer[] mappedItems = getMappingData().getItems();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
        XMenuItemPeer selectedItem = getSelectedItem();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
        int cnt = mappedItems.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
        //Find index of selected item
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
        int selIdx = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
        for (int i = 0; i < cnt; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
            if (mappedItems[i] == selectedItem) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
                selIdx = i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
        int idx = (selIdx <= 0) ? cnt - 1 : selIdx - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
        //cycle through mappedItems to find selectable item
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
        for (int i = 0; i < cnt; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
            XMenuItemPeer item = mappedItems[idx];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
            if (!item.isSeparator() && item.isTargetItemEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
                return item;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
            idx--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
            if (idx < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
                idx = cnt - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
        //return null if no selectable item was found
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
     * Returns first selectable item
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
     * This function is intended for clearing selection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
    XMenuItemPeer getFirstSelectableItem() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
        XMenuItemPeer[] mappedItems = getMappingData().getItems();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
        int cnt = mappedItems.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
        for (int i = 0; i < cnt; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
            XMenuItemPeer item = mappedItems[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
            if (!item.isSeparator() && item.isTargetItemEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
                return item;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
    /************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
     * Utility functions for manipulating
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
     * hierarchy of windows
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
     ************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
     * returns leaf menu window or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
     * this if no children are showing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
    XBaseMenuWindow getShowingLeaf() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
        synchronized(getMenuTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
            XBaseMenuWindow leaf = this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
            XMenuPeer leafchild = leaf.getShowingSubmenu();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
            while (leafchild != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
                leaf = leafchild.getMenuWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
                leafchild = leaf.getShowingSubmenu();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
            return leaf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
     * returns root menu window
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
     * or this if this window is topmost
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
    XBaseMenuWindow getRootMenuWindow() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
        synchronized(getMenuTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
            XBaseMenuWindow t = this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
            XBaseMenuWindow tparent = t.getParentMenuWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
            while (tparent != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
                t = tparent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
                tparent = t.getParentMenuWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
            return t;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
     * Returns window that contains pt.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
     * search is started from leaf window
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
     * to return first window in Z-order
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
     * @param pt point in global coordinates
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
    XBaseMenuWindow getMenuWindowFromPoint(Point pt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
        synchronized(getMenuTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
            XBaseMenuWindow t = getShowingLeaf();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
            while (t != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
                Rectangle r = new Rectangle(t.toGlobal(new Point(0, 0)), t.getSize());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
                if (r.contains(pt)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
                    return t;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
                t = t.getParentMenuWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
    /************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
     * Primitives for getSubmenuBounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
     * These functions are invoked from getSubmenuBounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
     * implementations in different order. They check if window
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
     * of size windowSize fits to the specified edge of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
     * rectangle itemBounds on the screen of screenSize.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
     * Return rectangle that occupies the window if it fits or null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
     ************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
     * Checks if window fits below specified item
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
     * returns rectangle that the window fits to or null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
     * @param itemBounds rectangle of item in global coordinates
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
     * @param windowSize size of submenu window to fit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
     * @param screenSize size of screen
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
    Rectangle fitWindowBelow(Rectangle itemBounds, Dimension windowSize, Dimension screenSize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
        int width = windowSize.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
        int height = windowSize.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
        //Fix for 6267162: PIT: Popup Menu gets hidden below the screen when opened
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
        //near the periphery of the screen, XToolkit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
        //Window should be moved if it's outside top-left screen bounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
        int x = (itemBounds.x > 0) ? itemBounds.x : 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
        int y = (itemBounds.y + itemBounds.height > 0) ? itemBounds.y + itemBounds.height : 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
        if (y + height <= screenSize.height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
            //move it to the left if needed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
            if (width > screenSize.width) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
                width = screenSize.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
            if (x + width > screenSize.width) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
                x = screenSize.width - width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
            return new Rectangle(x, y, width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
     * Checks if window fits above specified item
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
     * returns rectangle that the window fits to or null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
     * @param itemBounds rectangle of item in global coordinates
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
     * @param windowSize size of submenu window to fit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
     * @param screenSize size of screen
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
    Rectangle fitWindowAbove(Rectangle itemBounds, Dimension windowSize, Dimension screenSize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
        int width = windowSize.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
        int height = windowSize.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
        //Fix for 6267162: PIT: Popup Menu gets hidden below the screen when opened
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
        //near the periphery of the screen, XToolkit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
        //Window should be moved if it's outside bottom-left screen bounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
        int x = (itemBounds.x > 0) ? itemBounds.x : 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
        int y = (itemBounds.y > screenSize.height) ? screenSize.height - height : itemBounds.y - height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
        if (y >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
            //move it to the left if needed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
            if (width > screenSize.width) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
                width = screenSize.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
            if (x + width > screenSize.width) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
                x = screenSize.width - width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
            return new Rectangle(x, y, width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
     * Checks if window fits to the right specified item
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
     * returns rectangle that the window fits to or null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
     * @param itemBounds rectangle of item in global coordinates
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
     * @param windowSize size of submenu window to fit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
     * @param screenSize size of screen
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
    Rectangle fitWindowRight(Rectangle itemBounds, Dimension windowSize, Dimension screenSize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
        int width = windowSize.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
        int height = windowSize.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
        //Fix for 6267162: PIT: Popup Menu gets hidden below the screen when opened
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
        //near the periphery of the screen, XToolkit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
        //Window should be moved if it's outside top-left screen bounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
        int x = (itemBounds.x + itemBounds.width > 0) ? itemBounds.x + itemBounds.width : 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
        int y = (itemBounds.y > 0) ? itemBounds.y : 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
        if (x + width <= screenSize.width) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
            //move it to the top if needed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
            if (height > screenSize.height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
                height = screenSize.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
            if (y + height > screenSize.height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
                y = screenSize.height - height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
            return new Rectangle(x, y, width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
     * Checks if window fits to the left specified item
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
     * returns rectangle that the window fits to or null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
     * @param itemBounds rectangle of item in global coordinates
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
     * @param windowSize size of submenu window to fit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
     * @param screenSize size of screen
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
    Rectangle fitWindowLeft(Rectangle itemBounds, Dimension windowSize, Dimension screenSize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
        int width = windowSize.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
        int height = windowSize.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
        //Fix for 6267162: PIT: Popup Menu gets hidden below the screen when opened
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
        //near the periphery of the screen, XToolkit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
        //Window should be moved if it's outside top-right screen bounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
        int x = (itemBounds.x < screenSize.width) ? itemBounds.x - width : screenSize.width - width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
        int y = (itemBounds.y > 0) ? itemBounds.y : 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
        if (x >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
            //move it to the top if needed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
            if (height > screenSize.height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
                height = screenSize.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
            if (y + height > screenSize.height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
                y = screenSize.height - height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
            return new Rectangle(x, y, width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
     * The last thing we can do with the window
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
     * to fit it on screen - move it to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
     * top-left edge and cut by screen dimensions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
     * @param windowSize size of submenu window to fit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
     * @param screenSize size of screen
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
    Rectangle fitWindowToScreen(Dimension windowSize, Dimension screenSize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
        int width = (windowSize.width < screenSize.width) ? windowSize.width : screenSize.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
        int height = (windowSize.height < screenSize.height) ? windowSize.height : screenSize.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
        return new Rectangle(0, 0, width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
    /************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
     * Utility functions for manipulating colors
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
     ************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
     * This function is called before every painting.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
     * TODO:It would be better to add PropertyChangeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
     * to target component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
     * TODO:It would be better to access background color
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
     * not invoking user-overridable function
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
    void resetColors() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
        replaceColors((target == null) ? SystemColor.window : target.getBackground());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
     * Calculates colors of various elements given
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
     * background color. Uses MotifColorUtilities
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
     * @param backgroundColor the color of menu window's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
     * background.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
    void replaceColors(Color backgroundColor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
        if (backgroundColor != this.backgroundColor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
            this.backgroundColor = backgroundColor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
            int red = backgroundColor.getRed();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
            int green = backgroundColor.getGreen();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
            int blue = backgroundColor.getBlue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
            foregroundColor = new Color(MotifColorUtilities.calculateForegroundFromBackground(red,green,blue));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
            lightShadowColor = new Color(MotifColorUtilities.calculateTopShadowFromBackground(red,green,blue));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
            darkShadowColor = new Color(MotifColorUtilities.calculateBottomShadowFromBackground(red,green,blue));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
            selectedColor = new Color(MotifColorUtilities.calculateSelectFromBackground(red,green,blue));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
            disabledColor = (backgroundColor.equals(Color.BLACK)) ? foregroundColor.darker() : backgroundColor.darker();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
    Color getBackgroundColor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
        return backgroundColor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
    Color getForegroundColor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
        return foregroundColor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
    Color getLightShadowColor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
        return lightShadowColor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
    Color getDarkShadowColor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
        return darkShadowColor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
    Color getSelectedColor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
        return selectedColor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
    Color getDisabledColor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
        return disabledColor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
    /************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
     * Painting utility functions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
     ************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
     * Draws raised or sunken rectangle on specified graphics
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
     * @param g the graphics on which to draw
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
     * @param x the coordinate of left edge in coordinates of graphics
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
     * @param y the coordinate of top edge in coordinates of graphics
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
     * @param width the width of rectangle
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
     * @param height the height of rectangle
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
     * @param raised true to draw raised rectangle, false to draw sunken
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
    void draw3DRect(Graphics g, int x, int y, int width, int height, boolean raised) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
        if ((width <= 0) || (height <= 0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
        Color c = g.getColor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
        g.setColor(raised ? getLightShadowColor() : getDarkShadowColor());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
        g.drawLine(x, y, x, y + height - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
        g.drawLine(x + 1, y, x + width - 1, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
        g.setColor(raised ? getDarkShadowColor() : getLightShadowColor());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
        g.drawLine(x + 1, y + height - 1, x + width - 1, y + height - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
        g.drawLine(x + width - 1, y + 1, x + width - 1, y + height - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
        g.setColor(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
    /************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
     * Overriden utility functions of XWindow
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
     ************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
     * Filters X events
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
     protected boolean isEventDisabled(XEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
        switch (e.get_type()) {
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
   892
          case XConstants.Expose :
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
   893
          case XConstants.GraphicsExpose :
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
   894
          case XConstants.ButtonPress:
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
   895
          case XConstants.ButtonRelease:
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
   896
          case XConstants.MotionNotify:
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
   897
          case XConstants.KeyPress:
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
   898
          case XConstants.KeyRelease:
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
   899
          case XConstants.DestroyNotify:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
              return super.isEventDisabled(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
          default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
              return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
     * Invokes disposal procedure on eventHandlerThread
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
    public void dispose() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
        setDisposed(true);
20449
20326f6cd2aa 8023994: Right click on the icon added to the system tray for the first time, java.lang.IllegalArgumentException thrown.
leonidr
parents: 18525
diff changeset
   911
20326f6cd2aa 8023994: Right click on the icon added to the system tray for the first time, java.lang.IllegalArgumentException thrown.
leonidr
parents: 18525
diff changeset
   912
        SunToolkit.invokeLaterOnAppContext(disposeAppContext, new Runnable()  {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
            public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
                doDispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
        });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
     * Performs disposal of menu window.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
     * Should be called only on eventHandlerThread
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
    protected void doDispose() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
        xSetVisible(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
        SurfaceData oldData = surfaceData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
        surfaceData = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
        if (oldData != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
            oldData.invalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
        destroy();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
     * Invokes event processing on eventHandlerThread
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
     * This function needs to be overriden since
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
     * XBaseMenuWindow has no corresponding component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
     * so events can not be processed using standart means
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
    void postEvent(final AWTEvent event) {
18520
7fad3f87d731 8014264: The applet pathguy_TimeDead throws java.lang.NullPointerException in java console once click drop-down check box.
leonidr
parents: 16839
diff changeset
   940
        InvocationEvent ev = new InvocationEvent(event.getSource(), new Runnable() {
7fad3f87d731 8014264: The applet pathguy_TimeDead throws java.lang.NullPointerException in java console once click drop-down check box.
leonidr
parents: 16839
diff changeset
   941
            public void run() {
7fad3f87d731 8014264: The applet pathguy_TimeDead throws java.lang.NullPointerException in java console once click drop-down check box.
leonidr
parents: 16839
diff changeset
   942
                handleEvent(event);
7fad3f87d731 8014264: The applet pathguy_TimeDead throws java.lang.NullPointerException in java console once click drop-down check box.
leonidr
parents: 16839
diff changeset
   943
            }
7fad3f87d731 8014264: The applet pathguy_TimeDead throws java.lang.NullPointerException in java console once click drop-down check box.
leonidr
parents: 16839
diff changeset
   944
        });
7fad3f87d731 8014264: The applet pathguy_TimeDead throws java.lang.NullPointerException in java console once click drop-down check box.
leonidr
parents: 16839
diff changeset
   945
        super.postEvent(ev);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
     * The implementation of base window performs processing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
     * of paint events only. This behaviour is changed in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
     * descendants.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
    protected void handleEvent(AWTEvent event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
        switch(event.getID()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
        case PaintEvent.PAINT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
            doHandleJavaPaintEvent((PaintEvent)event);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
     * Save location of pointer for further use
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
     * then invoke superclass
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
    public boolean grabInput() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
        int rootX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
        int rootY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
        boolean res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
            long root = XlibWrapper.RootWindow(XToolkit.getDisplay(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
                    getScreenNumber());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
            res = XlibWrapper.XQueryPointer(XToolkit.getDisplay(), root,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
                                            XlibWrapper.larg1, //root
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
                                            XlibWrapper.larg2, //child
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
                                            XlibWrapper.larg3, //root_x
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
                                            XlibWrapper.larg4, //root_y
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
                                            XlibWrapper.larg5, //child_x
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
                                            XlibWrapper.larg6, //child_y
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
                                            XlibWrapper.larg7);//mask
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
            rootX = Native.getInt(XlibWrapper.larg3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
            rootY = Native.getInt(XlibWrapper.larg4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
            res &= super.grabInput();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
        if (res) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
            //Mouse pointer is on the same display
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
            this.grabInputPoint = new Point(rootX, rootY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
            this.hasPointerMoved = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
            this.grabInputPoint = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
            this.hasPointerMoved = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
        return res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
    /************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
     * Overridable event processing functions
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
     ************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
     * Performs repainting
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
    void doHandleJavaPaintEvent(PaintEvent event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
        Rectangle rect = event.getUpdateRect();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
        repaint(rect.x, rect.y, rect.width, rect.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
    /************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
     * User input handling utility functions
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
     ************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
     * Performs handling of java mouse event
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
     * Note that this function should be invoked
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
     * only from root of menu window's hierarchy
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
     * that grabs input focus
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
    void doHandleJavaMouseEvent( MouseEvent mouseEvent ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
        if (!XToolkit.isLeftMouseButton(mouseEvent) && !XToolkit.isRightMouseButton(mouseEvent)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
        //Window that owns input
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
        XBaseWindow grabWindow = XAwtState.getGrabWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
        //Point of mouse event in global coordinates
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
        Point ptGlobal = mouseEvent.getLocationOnScreen();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
        if (!hasPointerMoved) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
            //Fix for 6301307: NullPointerException while dispatching mouse events, XToolkit
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
            if (grabInputPoint == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
                (Math.abs(ptGlobal.x - grabInputPoint.x) > getMouseMovementSmudge()) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
                (Math.abs(ptGlobal.y - grabInputPoint.y) > getMouseMovementSmudge())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
                hasPointerMoved = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
        //Z-order first descendant of current menu window
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
        //hierarchy that contain mouse point
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
        XBaseMenuWindow wnd = getMenuWindowFromPoint(ptGlobal);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
        //Item in wnd that contains mouse point, if any
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
        XMenuItemPeer item = (wnd != null) ? wnd.getItemFromPoint(wnd.toLocal(ptGlobal)) : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
        //Currently showing leaf window
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
        XBaseMenuWindow cwnd = getShowingLeaf();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
        switch (mouseEvent.getID()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
          case MouseEvent.MOUSE_PRESSED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
              //This line is to get rid of possible problems
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
              //That may occur if mouse events are lost
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
              showingMousePressedSubmenu = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
              if ((grabWindow == this) && (wnd == null)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
                  //Menus grab input and the user
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
                  //presses mouse button outside
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
                  ungrabInput();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
              } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
                  //Menus grab input OR mouse is pressed on menu window
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
                  grabInput();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
                  if (item != null && !item.isSeparator() && item.isTargetItemEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
                      //Button is pressed on enabled item
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
                      if (wnd.getShowingSubmenu() == item) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
                          //Button is pressed on item that shows
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
                          //submenu. We have to hide its submenu
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
                          //if user clicks on it
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
                          showingMousePressedSubmenu = (XMenuPeer)item;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
                      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
                      wnd.selectItem(item, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
                  } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
                      //Button is pressed on disabled item or empty space
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
                      if (wnd != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
                          wnd.selectItem(null, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
                      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
                  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
          case MouseEvent.MOUSE_RELEASED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
              //Note that if item is not null, wnd has to be not null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
              if (item != null && !item.isSeparator() && item.isTargetItemEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
                  if  (item instanceof XMenuPeer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
                      if (showingMousePressedSubmenu == item) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
                          //User clicks on item that shows submenu.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
                          //Hide the submenu
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
                          if (wnd instanceof XMenuBarPeer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
                              ungrabInput();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
                          } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
                              wnd.selectItem(item, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
                          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
                      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
                  } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
                      //Invoke action event
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
                      item.action(mouseEvent.getWhen());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
                      ungrabInput();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
                  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
              } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
                  //Mouse is released outside menu items
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
                  if (hasPointerMoved || (wnd instanceof XMenuBarPeer)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
                      ungrabInput();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
                  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
              showingMousePressedSubmenu = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
          case MouseEvent.MOUSE_DRAGGED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
              if (wnd != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
                  //Mouse is dragged over menu window
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
                  //Move selection to item under cursor
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
                  if (item != null && !item.isSeparator() && item.isTargetItemEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
                      if (grabWindow == this){
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
                          wnd.selectItem(item, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
                      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
                  } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
                      wnd.selectItem(null, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
                  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
              } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
                  //Mouse is dragged outside menu windows
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
                  //clear selection in leaf to reflect it
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
                  if (cwnd != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
                      cwnd.selectItem(null, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
                  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
     * Performs handling of java keyboard event
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
     * Note that this function should be invoked
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
     * only from root of menu window's hierarchy
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
     * that grabs input focus
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
    void doHandleJavaKeyEvent(KeyEvent event) {
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16839
diff changeset
  1130
        if (log.isLoggable(PlatformLogger.Level.FINER)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 10419
diff changeset
  1131
            log.finer(event.toString());
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 10419
diff changeset
  1132
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
        if (event.getID() != KeyEvent.KEY_PRESSED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
        final int keyCode = event.getKeyCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
        XBaseMenuWindow cwnd = getShowingLeaf();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
        XMenuItemPeer citem = cwnd.getSelectedItem();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
        switch(keyCode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
          case KeyEvent.VK_UP:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
          case KeyEvent.VK_KP_UP:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
              if (!(cwnd instanceof XMenuBarPeer)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
                  //If active window is not menu bar,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
                  //move selection up
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
                  cwnd.selectItem(cwnd.getPrevSelectableItem(), false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
          case KeyEvent.VK_DOWN:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
          case KeyEvent.VK_KP_DOWN:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
              if (cwnd instanceof XMenuBarPeer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
                  //If active window is menu bar show current submenu
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
                  selectItem(getSelectedItem(), true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
              } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
                  //move selection down
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
                  cwnd.selectItem(cwnd.getNextSelectableItem(), false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
          case KeyEvent.VK_LEFT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
          case KeyEvent.VK_KP_LEFT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
              if (cwnd instanceof XMenuBarPeer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
                  //leaf window is menu bar
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
                  //select previous item
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
                  selectItem(getPrevSelectableItem(), false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
              } else if (cwnd.getParentMenuWindow() instanceof XMenuBarPeer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
                  //leaf window is direct child of menu bar
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
                  //select previous item of menu bar
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
                  //and show its submenu
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
                  selectItem(getPrevSelectableItem(), true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
              } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
                  //hide leaf moving focus to its parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
                  //(equvivalent of pressing ESC)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
                  XBaseMenuWindow pwnd = cwnd.getParentMenuWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
                  //Fix for 6272952: PIT: Pressing LEFT ARROW on a popup menu throws NullPointerException, XToolkit
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
                  if (pwnd != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
                      pwnd.selectItem(pwnd.getSelectedItem(), false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
                  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
          case KeyEvent.VK_RIGHT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
          case KeyEvent.VK_KP_RIGHT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
              if (cwnd instanceof XMenuBarPeer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
                  //leaf window is menu bar
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
                  //select next item
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
                  selectItem(getNextSelectableItem(), false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
              } else if (citem instanceof XMenuPeer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
                  //current item is menu, show its window
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
                  //(equivalent of ENTER)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
                  cwnd.selectItem(citem, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
              } else if (this instanceof XMenuBarPeer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
                  //if this is menu bar (not popup menu)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
                  //and the user presses RIGHT on item (not submenu)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
                  //select next top-level menu
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
                  selectItem(getNextSelectableItem(), true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
          case KeyEvent.VK_SPACE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
          case KeyEvent.VK_ENTER:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
              //If the current item has submenu show it
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
              //Perform action otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
              if (citem instanceof XMenuPeer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
                  cwnd.selectItem(citem, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
              } else if (citem != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
                  citem.action(event.getWhen());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
                  ungrabInput();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
          case KeyEvent.VK_ESCAPE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
              //If current window is menu bar or its child - close it
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
              //If current window is popup menu - close it
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
              //go one level up otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
              //Fixed 6266513: Incorrect key handling in XAWT popup menu
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
              //Popup menu should be closed on 'ESC'
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
              if ((cwnd instanceof XMenuBarPeer) || (cwnd.getParentMenuWindow() instanceof XMenuBarPeer)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
                  ungrabInput();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
              } else if (cwnd instanceof XPopupMenuPeer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
                  ungrabInput();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
              } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
                  XBaseMenuWindow pwnd = cwnd.getParentMenuWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
                  pwnd.selectItem(pwnd.getSelectedItem(), false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
          case KeyEvent.VK_F10:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
              //Fixed 6266513: Incorrect key handling in XAWT popup menu
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
              //All menus should be closed on 'F10'
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
              ungrabInput();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
          default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
} //class XBaseMenuWindow