jdk/src/solaris/classes/sun/awt/X11/XPopupMenuPeer.java
author ant
Fri, 22 Feb 2013 15:13:13 +0400
changeset 15983 26a673dec5b2
parent 13604 31089af1a447
child 16839 d0f2e97b7359
permissions -rw-r--r--
8006406: lightweight embedding in other Java UI toolkits Reviewed-by: serb, anthony, art
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) 2002, 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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.util.Vector;
13604
31089af1a447 7163201: Simplify toolkit internals references
bagiras
parents: 5506
diff changeset
    32
import sun.awt.AWTAccessor;
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 116
diff changeset
    33
import sun.util.logging.PlatformLogger;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
public class XPopupMenuPeer extends XMenuWindow implements PopupMenuPeer {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
    /************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
     * Data members
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
     ************************************************/
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 116
diff changeset
    42
    private static PlatformLogger log = PlatformLogger.getLogger("sun.awt.X11.XBaseMenuWindow");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
     * Primary members
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    private XComponentPeer componentPeer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    private PopupMenu popupMenuTarget;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
     * If mouse button is clicked on item showing submenu
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
     * we have to hide its submenu.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
     * This member saves the submenu under cursor
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
     * Only if it's showing
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    private XMenuPeer showingMousePressedSubmenu = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
     * Painting constants
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    private final static int CAPTION_MARGIN_TOP = 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    private final static int CAPTION_SEPARATOR_HEIGHT = 6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    /************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     * Construction
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     ************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    XPopupMenuPeer(PopupMenu target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        super(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        this.popupMenuTarget = target;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    /************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     *
13604
31089af1a447 7163201: Simplify toolkit internals references
bagiras
parents: 5506
diff changeset
    76
     * Implementation of interface methods
2
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
     * From MenuComponentPeer
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    public void setFont(Font f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        resetMapping();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        setItemsFont(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        postPaintEvent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * From MenuItemPeer
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    public void setLabel(String label) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        resetMapping();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        postPaintEvent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    public void setEnabled(boolean enabled) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        postPaintEvent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * DEPRECATED:  Replaced by setEnabled(boolean).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * @see java.awt.peer.MenuItemPeer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    public void enable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        setEnabled( true );
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
     * DEPRECATED:  Replaced by setEnabled(boolean).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * @see java.awt.peer.MenuItemPeer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    public void disable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        setEnabled( false );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * From MenuPeer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * addSeparator routines are not used
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * in peers. Shared code invokes addItem("-")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * for adding separators
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    public void addSeparator() {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 116
diff changeset
   126
        if (log.isLoggable(PlatformLogger.FINER)) log.finer("addSeparator is not implemented");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * From PopupMenuPeer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    public void show(Event e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        target = (Component)e.target;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        // Get menus from the target.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        Vector targetItemVector = getMenuTargetItems();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        if (targetItemVector != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
            reloadItems(targetItemVector);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
            //Fix for 6287092: JCK15a: api/java_awt/interactive/event/EventTests.html#EventTest0015 fails, mustang
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
            Point tl = target.getLocationOnScreen();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
            Point pt = new Point(tl.x + e.x, tl.y + e.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
            //Fixed 6266513: Incorrect key handling in XAWT popup menu
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
            //No item should be selected when showing popup menu
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
            if (!ensureCreated()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
            Dimension dim = getDesiredSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            //Fix for 6267162: PIT: Popup Menu gets hidden below the screen when opened
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
            //near the periphery of the screen, XToolkit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
            Rectangle bounds = getWindowBounds(pt, dim);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
            reshape(bounds);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
            xSetVisible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
            toFront();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
            selectItem(null, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
            grabInput();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    /************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * Access to target's fields
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
    //Fix for 6267144: PIT: Popup menu label is not shown, XToolkit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    Font getTargetFont() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        if (popupMenuTarget == null) {
116
9c43d9eb1029 6645856: static field XWindowPeer.defaultFont hides XWindow.defaultFont
son
parents: 2
diff changeset
   167
            return XWindow.getDefaultFont();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        }
13604
31089af1a447 7163201: Simplify toolkit internals references
bagiras
parents: 5506
diff changeset
   169
        return AWTAccessor.getMenuComponentAccessor()
31089af1a447 7163201: Simplify toolkit internals references
bagiras
parents: 5506
diff changeset
   170
                   .getFont_NoClientCode(popupMenuTarget);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
13604
31089af1a447 7163201: Simplify toolkit internals references
bagiras
parents: 5506
diff changeset
   173
    //Fix for 6267144: PIT: Popup menu label is not shown, XToolkit
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    String getTargetLabel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        if (target == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
            return "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        }
13604
31089af1a447 7163201: Simplify toolkit internals references
bagiras
parents: 5506
diff changeset
   178
        return AWTAccessor.getMenuItemAccessor().getLabel(popupMenuTarget);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    //Fix for 6184485: Popup menu is not disabled on XToolkit even when calling setEnabled (false)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    boolean isTargetEnabled() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        if (popupMenuTarget == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        }
13604
31089af1a447 7163201: Simplify toolkit internals references
bagiras
parents: 5506
diff changeset
   186
        return AWTAccessor.getMenuItemAccessor().isEnabled(popupMenuTarget);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    Vector getMenuTargetItems() {
13604
31089af1a447 7163201: Simplify toolkit internals references
bagiras
parents: 5506
diff changeset
   190
        if (popupMenuTarget == null) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        }
13604
31089af1a447 7163201: Simplify toolkit internals references
bagiras
parents: 5506
diff changeset
   193
        return AWTAccessor.getMenuAccessor().getItems(popupMenuTarget);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    /************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * Utility functions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     ************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    //Fix for 6267162: PIT: Popup Menu gets hidden below the screen when opened
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    //near the periphery of the screen, XToolkit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * Calculates placement of popup menu window
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * given origin in global coordinates and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * size of menu window. Returns suggested
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * rectangle for menu window in global coordinates
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * @param origin the origin point specified in show()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * function converted to global coordinates
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * @param windowSize the desired size of menu's window
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    protected Rectangle getWindowBounds(Point origin, Dimension windowSize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        Rectangle globalBounds = new Rectangle(origin.x, origin.y, 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        Rectangle res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        res = fitWindowRight(globalBounds, windowSize, screenSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        if (res != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
            return res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        res = fitWindowLeft(globalBounds, windowSize, screenSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        if (res != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
            return res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        res = fitWindowBelow(globalBounds, windowSize, screenSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        if (res != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
            return res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        res = fitWindowAbove(globalBounds, windowSize, screenSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        if (res != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
            return res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        return fitWindowToScreen(windowSize, screenSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    /************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * Overriden XMenuWindow caption-painting functions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * Necessary to fix 6267144: PIT: Popup menu label is not shown, XToolkit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     ************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     * Returns height of menu window's caption.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     * Can be overriden for popup menus and tear-off menus
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    protected Dimension getCaptionSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        String s = getTargetLabel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        if (s.equals("")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        Graphics g = getGraphics();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        if (g == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
            g.setFont(getTargetFont());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
            FontMetrics fm = g.getFontMetrics();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
            String str = getTargetLabel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
            int width = fm.stringWidth(str);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
            int height = CAPTION_MARGIN_TOP + fm.getHeight() + CAPTION_SEPARATOR_HEIGHT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
            Dimension textDimension = new Dimension(width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
            return textDimension;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
            g.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     * Paints menu window's caption.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     * Can be overriden for popup menus and tear-off menus.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * Default implementation does nothing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    protected void paintCaption(Graphics g, Rectangle rect) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        String s = getTargetLabel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        if (s.equals("")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        g.setFont(getTargetFont());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        FontMetrics fm = g.getFontMetrics();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        String str = getTargetLabel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        int width = fm.stringWidth(str);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        int textx = rect.x + (rect.width - width) / 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        int texty = rect.y + CAPTION_MARGIN_TOP + fm.getAscent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        int sepy = rect.y + rect.height - CAPTION_SEPARATOR_HEIGHT / 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        g.setColor(isTargetEnabled() ? getForegroundColor() : getDisabledColor());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        g.drawString(s, textx, texty);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        draw3DRect(g, rect.x, sepy,  rect.width, 2, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    /************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     * Overriden XBaseMenuWindow functions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     ************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    protected void doDispose() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        super.doDispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        XToolkit.targetDisposedPeer(popupMenuTarget, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    protected void handleEvent(AWTEvent event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        switch(event.getID()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        case MouseEvent.MOUSE_PRESSED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        case MouseEvent.MOUSE_RELEASED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        case MouseEvent.MOUSE_CLICKED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        case MouseEvent.MOUSE_MOVED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        case MouseEvent.MOUSE_ENTERED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        case MouseEvent.MOUSE_EXITED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        case MouseEvent.MOUSE_DRAGGED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
            doHandleJavaMouseEvent((MouseEvent)event);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        case KeyEvent.KEY_PRESSED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        case KeyEvent.KEY_RELEASED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
            doHandleJavaKeyEvent((KeyEvent)event);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
            super.handleEvent(event);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
    /************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     * Overriden XWindow general-purpose functions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     ************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
    void ungrabInputImpl() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        hide();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
    /************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     * Overriden XWindow keyboard processing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     ************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     * In previous version keys were handled in handleKeyPress.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     * Now we override this function do disable F10 explicit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     * processing. All processing is done using KeyEvent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
    public void handleKeyPress(XEvent xev) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        XKeyEvent xkey = xev.get_xkey();
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 116
diff changeset
   344
        if (log.isLoggable(PlatformLogger.FINE)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
            log.fine(xkey.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
        if (isEventDisabled(xev)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        final Component currentSource = (Component)getEventSource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        handleKeyPress(xkey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
}