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