jdk/src/solaris/classes/sun/awt/X11/XMenuBarPeer.java
author mchung
Tue, 29 Sep 2009 16:03:03 -0700
changeset 3938 ef327bd847c0
parent 2 90ce3da70b43
child 5506 202f599c92aa
permissions -rw-r--r--
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes Summary: Replace calls to Logger with sun.util.logging.PlatformLogger Reviewed-by: prr, art, alexp, dcherepanov, igor, dav, anthony
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 2002-2007 Sun Microsystems, Inc.  All Rights Reserved.
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
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
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.lang.reflect.Field;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.util.Vector;
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2
diff changeset
    33
import sun.util.logging.PlatformLogger;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import sun.awt.SunToolkit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
public class XMenuBarPeer extends XBaseMenuWindow implements MenuBarPeer {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
    /************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
     * Data members
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
     ************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2
diff changeset
    44
    private static PlatformLogger log = PlatformLogger.getLogger("sun.awt.X11.XMenuBarPeer");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
     * Primary members
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    private XFramePeer framePeer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    private MenuBar menuBarTarget;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
     * Index of help menu
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    private XMenuPeer helpMenu = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
     * dimension constants
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    private final static int BAR_SPACING_TOP = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    private final static int BAR_SPACING_BOTTOM = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    private final static int BAR_SPACING_LEFT = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    private final static int BAR_SPACING_RIGHT = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    private final static int BAR_ITEM_SPACING = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    private final static int BAR_ITEM_MARGIN_LEFT = 10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    private final static int BAR_ITEM_MARGIN_RIGHT = 10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    private final static int BAR_ITEM_MARGIN_TOP = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    private final static int BAR_ITEM_MARGIN_BOTTOM = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    //fields
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    private static Field f_helpMenu;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    private static Field f_menus;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        f_helpMenu = SunToolkit.getField(MenuBar.class, "helpMenu");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        f_menus = SunToolkit.getField(MenuBar.class, "menus");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    /************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * Mapping data
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     ************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * XBaseMenuWindow's mappingData is extended with
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * desired height of menu bar
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    static class MappingData extends XBaseMenuWindow.MappingData {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        int desiredHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        MappingData(XMenuItemPeer[] items, int desiredHeight) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
            super(items);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
            this.desiredHeight = desiredHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
         * Constructs MappingData without items
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
         * This constructor should be used in case of errors
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        MappingData() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
            this.desiredHeight = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        public int getDesiredHeight() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
            return this.desiredHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    /************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * Construction
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     ************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    XMenuBarPeer(MenuBar menuBarTarget) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        this.menuBarTarget = menuBarTarget;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    }
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
     * Implementaion of interface methods
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
     * From MenuComponentPeer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    public void setFont(Font f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        resetMapping();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        setItemsFont(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        postPaintEvent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * From MenuBarPeer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * Functions addMenu, delMenu, addHelpMenu
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * need to have somewhat strange behaivour
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * deduced from java.awt.MenuBar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * We can not get index of particular item in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * MenuBar.menus array, because MenuBar firstly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * performs array operations and then calls peer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * So we need to synchronize indicies in 'items'
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * array with MenuBar.menus. We have to follow
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * these rules:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * 1. Menus are always added to the end of array,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * even when helpMenu is present
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * 2. Removal of any menu item acts as casual
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     * remove from array
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * 3. MenuBar.setHelpMenu _firstly_ removes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * previous helpMenu by calling delMenu() if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * necessary, then it performs addMenu(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * and then - addHelpMenu().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * Note that these functions don't perform
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * type checks and checks for nulls or duplicates
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    public void addMenu(Menu m) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        addItem(m);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        postPaintEvent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    public void delMenu(int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        synchronized(getMenuTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
            XMenuItemPeer item = getItem(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
            if (item != null && item == helpMenu) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
                helpMenu = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            delItem(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        postPaintEvent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    public void addHelpMenu(Menu m) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        XMenuPeer mp = (XMenuPeer)m.getPeer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        synchronized(getMenuTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
            helpMenu = mp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        postPaintEvent();
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
     * Initialization
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     ************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * called from XFramePeer.setMenuBar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    public void init(Frame frame) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        this.target = frame;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        this.framePeer = (XFramePeer)frame.getPeer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        XCreateWindowParams params = getDelayedParams();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        params.remove(DELAYED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        params.add(PARENT_WINDOW, framePeer.getShell());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        params.add(TARGET, frame);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        init(params);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     * Overriden initialization
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    void postInit(XCreateWindowParams params) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        super.postInit(params);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        Vector targetMenuVector = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        Menu targetHelpMenu = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
            // Get menus from the target.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
            targetMenuVector = (Vector)f_menus.get(menuBarTarget);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
            targetHelpMenu = (Menu)f_helpMenu.get(menuBarTarget);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
            reloadItems(targetMenuVector);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        } catch (IllegalAccessException iae) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
            iae.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        if (targetHelpMenu != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
            addHelpMenu(targetHelpMenu);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        xSetVisible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        toFront();
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
     * Implementation of abstract methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     ************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * Menu bar is always root window in menu window's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * hierarchy
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    protected XBaseMenuWindow getParentMenuWindow() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        return null;
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
     * @see XBaseMenuWindow.map
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    protected MappingData map() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        XMenuItemPeer[] itemVector = copyItems();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        int itemCnt = itemVector.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        XMenuItemPeer helpMenu = this.helpMenu;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        int helpMenuPos = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        //find helpMenu and move it to the end of array
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        if (helpMenu != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
            //Fixed 6270847: PIT: HELP menu is not shown at the right place when normal menus added to MB are removed, XToolkit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
            for (int i = 0; i < itemCnt; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                if (itemVector[i] == helpMenu) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
                    helpMenuPos = i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
            if (helpMenuPos != -1 && helpMenuPos != itemCnt - 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
                System.arraycopy(itemVector, helpMenuPos + 1, itemVector, helpMenuPos, itemCnt - 1 - helpMenuPos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
                itemVector[itemCnt - 1] = helpMenu;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        //We need maximum height before calculating item's bounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        int maxHeight = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        XMenuItemPeer.TextMetrics[] itemMetrics = new XMenuItemPeer.TextMetrics[itemCnt];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        for (int i = 0; i < itemCnt; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
            itemMetrics[i] = itemVector[i].getTextMetrics();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
            Dimension dim = itemMetrics[i].getTextDimension();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
            if (dim != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
                maxHeight = Math.max(maxHeight, dim.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        //Calculate bounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        int nextOffset = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        int itemHeight = BAR_ITEM_MARGIN_TOP + maxHeight + BAR_ITEM_MARGIN_BOTTOM;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        int mappedCnt = itemCnt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        for (int i = 0; i < itemCnt; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
            XMenuItemPeer item = itemVector[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
            XMenuItemPeer.TextMetrics metrics = itemMetrics[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
            Dimension dim = metrics.getTextDimension();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
            if (dim != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
                int itemWidth = BAR_ITEM_MARGIN_LEFT + dim.width + BAR_ITEM_MARGIN_RIGHT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
                //Fix for 6270757: PIT: Menus and Sub-menus are shown outside the frame, XToolkit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
                //Cut-off items that don't fit in window
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
                //At least one item must remain in menu
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
                if ((nextOffset + itemWidth > this.width) && (i > 0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
                    mappedCnt = i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
                //If this item is help menu, move it to the right edge
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
                if ((i == itemCnt - 1) && helpMenuPos != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
                    nextOffset = Math.max(nextOffset, this.width - itemWidth - BAR_SPACING_RIGHT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
                Rectangle bounds = new Rectangle(nextOffset, BAR_SPACING_TOP, itemWidth, itemHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
                //text should be centered vertically in menu item's bounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
                int y = (maxHeight + dim.height) / 2  - metrics.getTextBaseline();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
                Point textOrigin = new Point(nextOffset + BAR_ITEM_MARGIN_LEFT, BAR_SPACING_TOP + BAR_ITEM_MARGIN_TOP + y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
                nextOffset += itemWidth + BAR_ITEM_SPACING;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
                item.map(bounds, textOrigin);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
                Rectangle bounds = new Rectangle(nextOffset, BAR_SPACING_TOP, 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
                Point textOrigin = new Point(nextOffset + BAR_ITEM_MARGIN_LEFT, BAR_SPACING_TOP + BAR_ITEM_MARGIN_TOP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        XMenuItemPeer mappedVector[] = new XMenuItemPeer[mappedCnt];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        System.arraycopy(itemVector, 0, mappedVector, 0, mappedCnt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        MappingData mappingData = new MappingData(mappedVector, BAR_SPACING_TOP + itemHeight + BAR_SPACING_BOTTOM);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        return mappingData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * @see XBaseMenuWindow.getSubmenuBounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    protected Rectangle getSubmenuBounds(Rectangle itemBounds, Dimension windowSize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        Rectangle globalBounds = toGlobal(itemBounds);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        Rectangle res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        res = fitWindowBelow(globalBounds, windowSize, screenSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        if (res != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
            return res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        res = fitWindowAbove(globalBounds, windowSize, screenSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        if (res != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
            return res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        res = fitWindowRight(globalBounds, windowSize, screenSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
        if (res != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
            return res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        res = fitWindowLeft(globalBounds, windowSize, screenSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        if (res != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
            return res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        return fitWindowToScreen(windowSize, screenSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     * This function is called when it's likely that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     * size of items has changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     * Invokes framePeer's updateChildrenSizes()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
    protected void updateSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        resetMapping();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        if (framePeer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
            framePeer.reshapeMenubarPeer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
    /************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
     * Utility functions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     ************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     * Returns desired height of menu bar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
    int getDesiredHeight() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        MappingData mappingData = (MappingData)getMappingData();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        return mappingData.getDesiredHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     * Returns true if framePeer is not null and is enabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     * Used to fix 6185057: Disabling a frame does not disable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     * the menus on the frame, on solaris/linux
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
    boolean isFramePeerEnabled() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
        if (framePeer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
            return framePeer.isEnabled();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
    /************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
     * Overriden XBaseMenuWindow functions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
     ************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
     * @see XBaseMenuWindow.doDispose()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
    protected void doDispose() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        super.doDispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
        XToolkit.targetDisposedPeer(menuBarTarget, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
    /************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
     * Overriden XWindow general-purpose functions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
     ************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     * For menu bars this function is called from framePeer's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
     * reshape(...) and updateChildrenSizes()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
    public void reshape(int x, int y, int width, int height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        if ((width != this.width) || (height != this.height)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
            resetMapping();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        super.reshape(x, y, width, height);
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
     * Performs ungrabbing of input
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     * @see XBaseWindow.ungrabInputImpl()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
    void ungrabInputImpl() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        selectItem(null, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
        super.ungrabInputImpl();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
        postPaintEvent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
    /************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     * Overriden XWindow painting & printing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
     ************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
    public void paint(Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
        resetColors();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
        /* Calculate menubar dimension. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
        int width = getWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
        int height = getHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
        flush();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
        //Fill background of rectangle
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
        g.setColor(getBackgroundColor());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
        g.fillRect(1, 1, width - 2, height - 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        draw3DRect(g, 0, 0, width, height, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
        //Paint menus
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        MappingData mappingData = (MappingData)getMappingData();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
        XMenuItemPeer[] itemVector = mappingData.getItems();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
        XMenuItemPeer selectedItem = getSelectedItem();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
        for (int i = 0; i < itemVector.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
            XMenuItemPeer item = itemVector[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
            //paint item
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
            g.setFont(item.getTargetFont());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
            Rectangle bounds = item.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
            Point textOrigin = item.getTextOrigin();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
            if (item == selectedItem) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
                g.setColor(getSelectedColor());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
                g.fillRect(bounds.x, bounds.y, bounds.width, bounds.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
                draw3DRect(g, bounds.x, bounds.y, bounds.width, bounds.height, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
            if (isFramePeerEnabled() && item.isTargetItemEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
                g.setColor(getForegroundColor());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
                g.setColor(getDisabledColor());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
            g.drawString(item.getTargetLabel(), textOrigin.x, textOrigin.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
        flush();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
    static final int W_DIFF = (XFramePeer.CROSSHAIR_INSET + 1) * 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
    static final int H_DIFF = XFramePeer.BUTTON_Y + XFramePeer.BUTTON_H;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
    void print(Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
        //TODO:Implement
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
    /************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
     * Overriden XBaseMenuWindow event handling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
     ************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
    protected void handleEvent(AWTEvent event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
        // explicitly block all events except PaintEvent.PAINT for menus,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
        // that are in the modal blocked window
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
        if ((framePeer != null) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
            (event.getID() != PaintEvent.PAINT))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
            if (framePeer.isModalBlocked()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
        switch(event.getID()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
        case MouseEvent.MOUSE_PRESSED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
        case MouseEvent.MOUSE_RELEASED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
        case MouseEvent.MOUSE_CLICKED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
        case MouseEvent.MOUSE_MOVED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
        case MouseEvent.MOUSE_ENTERED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
        case MouseEvent.MOUSE_EXITED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
        case MouseEvent.MOUSE_DRAGGED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
            //Fix for 6185057: Disabling a frame does not disable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
            //the menus on the frame, on solaris/linux
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
            if (isFramePeerEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
                doHandleJavaMouseEvent((MouseEvent)event);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
        case KeyEvent.KEY_PRESSED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
        case KeyEvent.KEY_RELEASED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
            //Fix for 6185057: Disabling a frame does not disable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
            //the menus on the frame, on solaris/linux
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
            if (isFramePeerEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
                doHandleJavaKeyEvent((KeyEvent)event);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
            super.handleEvent(event);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
    /************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
     * Overriden XWindow keyboard processing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
     ************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
     * This function is called from XWindow
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
     * @see XWindow.handleF10onEDT()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
    void handleF10KeyPress(KeyEvent event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
        int keyState = event.getModifiers();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
        if (((keyState & InputEvent.ALT_MASK) != 0) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
            ((keyState & InputEvent.SHIFT_MASK) != 0) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
            ((keyState & InputEvent.CTRL_MASK) != 0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
        grabInput();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
        selectItem(getFirstSelectableItem(), true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
     * In previous version keys were handled in handleKeyPress.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
     * Now we override this function do disable F10 explicit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
     * processing. All processing is done using KeyEvent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
    public void handleKeyPress(XEvent xev) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
        XKeyEvent xkey = xev.get_xkey();
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2
diff changeset
   536
        if (log.isLoggable(PlatformLogger.FINE)) log.fine(xkey.toString());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
        if (isEventDisabled(xev)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
        final Component currentSource = (Component)getEventSource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
        //This is the only difference from XWindow.handleKeyPress
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
        //Ancestor's function can invoke handleF10KeyPress here
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
        handleKeyPress(xkey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
} //class XMenuBarPeer