src/java.desktop/unix/classes/sun/awt/X11/XPopupMenuPeer.java
author serb
Wed, 18 Apr 2018 14:07:41 -0700
changeset 49998 9070717a16a1
parent 47216 71c04702a3d5
child 54871 c2e4aef5edf2
permissions -rw-r--r--
8187392: Deprecated methods in the peers can be removed Reviewed-by: prr, kaddepalli
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
49998
9070717a16a1 8187392: Deprecated methods in the peers can be removed
serb
parents: 47216
diff changeset
     2
 * Copyright (c) 2002, 2018, 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
     */
32865
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 25859
diff changeset
    61
    private static final int CAPTION_MARGIN_TOP = 4;
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 25859
diff changeset
    62
    private static final int CAPTION_SEPARATOR_HEIGHT = 6;
2
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
     * From MenuPeer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * addSeparator routines are not used
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * in peers. Shared code invokes addItem("-")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * for adding separators
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    public void addSeparator() {
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16839
diff changeset
   110
        if (log.isLoggable(PlatformLogger.Level.FINER)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 13604
diff changeset
   111
            log.finer("addSeparator is not implemented");
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 13604
diff changeset
   112
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * From PopupMenuPeer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     */
43722
25ba19c20260 8143077: Deprecate InputEvent._MASK in favor of InputEvent._DOWN_MASK
serb
parents: 34395
diff changeset
   118
    @SuppressWarnings("deprecation")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    public void show(Event e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        target = (Component)e.target;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        // Get menus from the target.
24538
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 22584
diff changeset
   122
        Vector<MenuItem> targetItemVector = getMenuTargetItems();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        if (targetItemVector != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
            reloadItems(targetItemVector);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
            //Fix for 6287092: JCK15a: api/java_awt/interactive/event/EventTests.html#EventTest0015 fails, mustang
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
            Point tl = target.getLocationOnScreen();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
            Point pt = new Point(tl.x + e.x, tl.y + e.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
            //Fixed 6266513: Incorrect key handling in XAWT popup menu
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
            //No item should be selected when showing popup menu
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
            if (!ensureCreated()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
            Dimension dim = getDesiredSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
            //Fix for 6267162: PIT: Popup Menu gets hidden below the screen when opened
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
            //near the periphery of the screen, XToolkit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
            Rectangle bounds = getWindowBounds(pt, dim);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
            reshape(bounds);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
            xSetVisible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
            toFront();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
            selectItem(null, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
            grabInput();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    /************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * Access to target's fields
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     ************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    //Fix for 6267144: PIT: Popup menu label is not shown, XToolkit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    Font getTargetFont() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        if (popupMenuTarget == null) {
116
9c43d9eb1029 6645856: static field XWindowPeer.defaultFont hides XWindow.defaultFont
son
parents: 2
diff changeset
   154
            return XWindow.getDefaultFont();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        }
13604
31089af1a447 7163201: Simplify toolkit internals references
bagiras
parents: 5506
diff changeset
   156
        return AWTAccessor.getMenuComponentAccessor()
31089af1a447 7163201: Simplify toolkit internals references
bagiras
parents: 5506
diff changeset
   157
                   .getFont_NoClientCode(popupMenuTarget);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
13604
31089af1a447 7163201: Simplify toolkit internals references
bagiras
parents: 5506
diff changeset
   160
    //Fix for 6267144: PIT: Popup menu label is not shown, XToolkit
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    String getTargetLabel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        if (target == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
            return "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        }
13604
31089af1a447 7163201: Simplify toolkit internals references
bagiras
parents: 5506
diff changeset
   165
        return AWTAccessor.getMenuItemAccessor().getLabel(popupMenuTarget);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    //Fix for 6184485: Popup menu is not disabled on XToolkit even when calling setEnabled (false)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    boolean isTargetEnabled() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        if (popupMenuTarget == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        }
13604
31089af1a447 7163201: Simplify toolkit internals references
bagiras
parents: 5506
diff changeset
   173
        return AWTAccessor.getMenuItemAccessor().isEnabled(popupMenuTarget);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
24538
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 22584
diff changeset
   176
    Vector<MenuItem> getMenuTargetItems() {
13604
31089af1a447 7163201: Simplify toolkit internals references
bagiras
parents: 5506
diff changeset
   177
        if (popupMenuTarget == null) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        }
13604
31089af1a447 7163201: Simplify toolkit internals references
bagiras
parents: 5506
diff changeset
   180
        return AWTAccessor.getMenuAccessor().getItems(popupMenuTarget);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    /************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * Utility functions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     ************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    //Fix for 6267162: PIT: Popup Menu gets hidden below the screen when opened
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    //near the periphery of the screen, XToolkit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * Calculates placement of popup menu window
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * given origin in global coordinates and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * size of menu window. Returns suggested
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * rectangle for menu window in global coordinates
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * @param origin the origin point specified in show()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * function converted to global coordinates
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * @param windowSize the desired size of menu's window
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    protected Rectangle getWindowBounds(Point origin, Dimension windowSize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        Rectangle globalBounds = new Rectangle(origin.x, origin.y, 0, 0);
44354
a99429b721a9 8160270: dual-screen issue with java.awt.Choice
serb
parents: 43722
diff changeset
   203
        Rectangle screenBounds = getCurrentGraphicsConfiguration().getBounds();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        Rectangle res;
44354
a99429b721a9 8160270: dual-screen issue with java.awt.Choice
serb
parents: 43722
diff changeset
   205
        res = fitWindowRight(globalBounds, windowSize, screenBounds);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        if (res != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
            return res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        }
44354
a99429b721a9 8160270: dual-screen issue with java.awt.Choice
serb
parents: 43722
diff changeset
   209
        res = fitWindowLeft(globalBounds, windowSize, screenBounds);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        if (res != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
            return res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        }
44354
a99429b721a9 8160270: dual-screen issue with java.awt.Choice
serb
parents: 43722
diff changeset
   213
        res = fitWindowBelow(globalBounds, windowSize, screenBounds);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        if (res != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
            return res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        }
44354
a99429b721a9 8160270: dual-screen issue with java.awt.Choice
serb
parents: 43722
diff changeset
   217
        res = fitWindowAbove(globalBounds, windowSize, screenBounds);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        if (res != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            return res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        }
44354
a99429b721a9 8160270: dual-screen issue with java.awt.Choice
serb
parents: 43722
diff changeset
   221
        return fitWindowToScreen(windowSize, screenBounds);
2
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
     * Overriden XMenuWindow caption-painting functions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * Necessary to fix 6267144: PIT: Popup menu label is not shown, XToolkit
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
     * Returns height of menu window's caption.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * Can be overriden for popup menus and tear-off menus
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    protected Dimension getCaptionSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        String s = getTargetLabel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        if (s.equals("")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        Graphics g = getGraphics();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        if (g == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
            g.setFont(getTargetFont());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
            FontMetrics fm = g.getFontMetrics();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
            String str = getTargetLabel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            int width = fm.stringWidth(str);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
            int height = CAPTION_MARGIN_TOP + fm.getHeight() + CAPTION_SEPARATOR_HEIGHT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
            Dimension textDimension = new Dimension(width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
            return textDimension;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
            g.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * Paints menu window's caption.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * Can be overriden for popup menus and tear-off menus.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     * Default implementation does nothing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    protected void paintCaption(Graphics g, Rectangle rect) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        String s = getTargetLabel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        if (s.equals("")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        g.setFont(getTargetFont());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        FontMetrics fm = g.getFontMetrics();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        String str = getTargetLabel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        int width = fm.stringWidth(str);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        int textx = rect.x + (rect.width - width) / 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        int texty = rect.y + CAPTION_MARGIN_TOP + fm.getAscent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        int sepy = rect.y + rect.height - CAPTION_SEPARATOR_HEIGHT / 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        g.setColor(isTargetEnabled() ? getForegroundColor() : getDisabledColor());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        g.drawString(s, textx, texty);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        draw3DRect(g, rect.x, sepy,  rect.width, 2, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    /************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     * Overriden XBaseMenuWindow functions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     ************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    protected void doDispose() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        super.doDispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        XToolkit.targetDisposedPeer(popupMenuTarget, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    protected void handleEvent(AWTEvent event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        switch(event.getID()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        case MouseEvent.MOUSE_PRESSED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        case MouseEvent.MOUSE_RELEASED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        case MouseEvent.MOUSE_CLICKED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        case MouseEvent.MOUSE_MOVED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        case MouseEvent.MOUSE_ENTERED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        case MouseEvent.MOUSE_EXITED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        case MouseEvent.MOUSE_DRAGGED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
            doHandleJavaMouseEvent((MouseEvent)event);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        case KeyEvent.KEY_PRESSED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        case KeyEvent.KEY_RELEASED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
            doHandleJavaKeyEvent((KeyEvent)event);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
            super.handleEvent(event);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
            break;
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
    /************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     * Overriden XWindow general-purpose functions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     ************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    void ungrabInputImpl() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        hide();
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
     * Overriden XWindow keyboard processing
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
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     * In previous version keys were handled in handleKeyPress.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     * Now we override this function do disable F10 explicit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     * processing. All processing is done using KeyEvent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
    public void handleKeyPress(XEvent xev) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        XKeyEvent xkey = xev.get_xkey();
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16839
diff changeset
   331
        if (log.isLoggable(PlatformLogger.Level.FINE)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
            log.fine(xkey.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        if (isEventDisabled(xev)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        }
22584
eed64ee05369 8032733: Fix cast lint warnings in client libraries
darcy
parents: 18178
diff changeset
   337
        final Component currentSource = getEventSource();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        handleKeyPress(xkey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
}