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