jdk/src/solaris/classes/sun/awt/X11/XPopupMenuPeer.java
author chegar
Mon, 17 Jun 2013 14:09:25 +0100
changeset 18178 ee71c923891d
parent 16839 d0f2e97b7359
child 22584 eed64ee05369
permissions -rw-r--r--
8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level) Reviewed-by: darcy
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() {
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16839
diff changeset
   126
        if (log.isLoggable(PlatformLogger.Level.FINER)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 13604
diff changeset
   127
            log.finer("addSeparator is not implemented");
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 13604
diff changeset
   128
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * From PopupMenuPeer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    public void show(Event e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        target = (Component)e.target;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        // Get menus from the target.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        Vector targetItemVector = getMenuTargetItems();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        if (targetItemVector != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
            reloadItems(targetItemVector);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
            //Fix for 6287092: JCK15a: api/java_awt/interactive/event/EventTests.html#EventTest0015 fails, mustang
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
            Point tl = target.getLocationOnScreen();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
            Point pt = new Point(tl.x + e.x, tl.y + e.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
            //Fixed 6266513: Incorrect key handling in XAWT popup menu
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
            //No item should be selected when showing popup menu
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
            if (!ensureCreated()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
            Dimension dim = getDesiredSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
            //Fix for 6267162: PIT: Popup Menu gets hidden below the screen when opened
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
            //near the periphery of the screen, XToolkit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
            Rectangle bounds = getWindowBounds(pt, dim);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
            reshape(bounds);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
            xSetVisible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
            toFront();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
            selectItem(null, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
            grabInput();
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
    /************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * Access to target's fields
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     ************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    //Fix for 6267144: PIT: Popup menu label is not shown, XToolkit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    Font getTargetFont() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        if (popupMenuTarget == null) {
116
9c43d9eb1029 6645856: static field XWindowPeer.defaultFont hides XWindow.defaultFont
son
parents: 2
diff changeset
   169
            return XWindow.getDefaultFont();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        }
13604
31089af1a447 7163201: Simplify toolkit internals references
bagiras
parents: 5506
diff changeset
   171
        return AWTAccessor.getMenuComponentAccessor()
31089af1a447 7163201: Simplify toolkit internals references
bagiras
parents: 5506
diff changeset
   172
                   .getFont_NoClientCode(popupMenuTarget);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
13604
31089af1a447 7163201: Simplify toolkit internals references
bagiras
parents: 5506
diff changeset
   175
    //Fix for 6267144: PIT: Popup menu label is not shown, XToolkit
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    String getTargetLabel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        if (target == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
            return "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        }
13604
31089af1a447 7163201: Simplify toolkit internals references
bagiras
parents: 5506
diff changeset
   180
        return AWTAccessor.getMenuItemAccessor().getLabel(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
    //Fix for 6184485: Popup menu is not disabled on XToolkit even when calling setEnabled (false)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    boolean isTargetEnabled() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        if (popupMenuTarget == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        }
13604
31089af1a447 7163201: Simplify toolkit internals references
bagiras
parents: 5506
diff changeset
   188
        return AWTAccessor.getMenuItemAccessor().isEnabled(popupMenuTarget);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    Vector getMenuTargetItems() {
13604
31089af1a447 7163201: Simplify toolkit internals references
bagiras
parents: 5506
diff changeset
   192
        if (popupMenuTarget == null) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        }
13604
31089af1a447 7163201: Simplify toolkit internals references
bagiras
parents: 5506
diff changeset
   195
        return AWTAccessor.getMenuAccessor().getItems(popupMenuTarget);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    /************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * Utility functions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     ************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    //Fix for 6267162: PIT: Popup Menu gets hidden below the screen when opened
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    //near the periphery of the screen, XToolkit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * Calculates placement of popup menu window
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * given origin in global coordinates and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * size of menu window. Returns suggested
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * rectangle for menu window in global coordinates
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * @param origin the origin point specified in show()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * function converted to global coordinates
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * @param windowSize the desired size of menu's window
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    protected Rectangle getWindowBounds(Point origin, Dimension windowSize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        Rectangle globalBounds = new Rectangle(origin.x, origin.y, 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        Rectangle res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        res = fitWindowRight(globalBounds, windowSize, screenSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        if (res != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
            return res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        res = fitWindowLeft(globalBounds, windowSize, screenSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        if (res != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            return res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        res = fitWindowBelow(globalBounds, windowSize, screenSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        if (res != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
            return res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        res = fitWindowAbove(globalBounds, windowSize, screenSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        if (res != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
            return res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        return fitWindowToScreen(windowSize, screenSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    /************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * Overriden XMenuWindow caption-painting functions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * Necessary to fix 6267144: PIT: Popup menu label is not shown, XToolkit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     ************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     * Returns height of menu window's caption.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     * Can be overriden for popup menus and tear-off menus
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    protected Dimension getCaptionSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        String s = getTargetLabel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        if (s.equals("")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        Graphics g = getGraphics();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        if (g == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
            g.setFont(getTargetFont());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
            FontMetrics fm = g.getFontMetrics();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
            String str = getTargetLabel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
            int width = fm.stringWidth(str);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
            int height = CAPTION_MARGIN_TOP + fm.getHeight() + CAPTION_SEPARATOR_HEIGHT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
            Dimension textDimension = new Dimension(width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
            return textDimension;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
            g.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * Paints menu window's caption.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * Can be overriden for popup menus and tear-off menus.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * Default implementation does nothing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    protected void paintCaption(Graphics g, Rectangle rect) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        String s = getTargetLabel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        if (s.equals("")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        g.setFont(getTargetFont());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        FontMetrics fm = g.getFontMetrics();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        String str = getTargetLabel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        int width = fm.stringWidth(str);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        int textx = rect.x + (rect.width - width) / 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        int texty = rect.y + CAPTION_MARGIN_TOP + fm.getAscent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        int sepy = rect.y + rect.height - CAPTION_SEPARATOR_HEIGHT / 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        g.setColor(isTargetEnabled() ? getForegroundColor() : getDisabledColor());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        g.drawString(s, textx, texty);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        draw3DRect(g, rect.x, sepy,  rect.width, 2, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    /************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     * Overriden XBaseMenuWindow functions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     ************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    protected void doDispose() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        super.doDispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        XToolkit.targetDisposedPeer(popupMenuTarget, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    protected void handleEvent(AWTEvent event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        switch(event.getID()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        case MouseEvent.MOUSE_PRESSED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        case MouseEvent.MOUSE_RELEASED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        case MouseEvent.MOUSE_CLICKED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        case MouseEvent.MOUSE_MOVED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        case MouseEvent.MOUSE_ENTERED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        case MouseEvent.MOUSE_EXITED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        case MouseEvent.MOUSE_DRAGGED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
            doHandleJavaMouseEvent((MouseEvent)event);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        case KeyEvent.KEY_PRESSED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        case KeyEvent.KEY_RELEASED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
            doHandleJavaKeyEvent((KeyEvent)event);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
            super.handleEvent(event);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
            break;
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
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     * Overriden XWindow general-purpose functions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     ************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
    void ungrabInputImpl() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        hide();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
    }
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
     * Overriden XWindow keyboard processing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     ************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     * In previous version keys were handled in handleKeyPress.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     * Now we override this function do disable F10 explicit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     * processing. All processing is done using KeyEvent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
    public void handleKeyPress(XEvent xev) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        XKeyEvent xkey = xev.get_xkey();
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16839
diff changeset
   346
        if (log.isLoggable(PlatformLogger.Level.FINE)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
            log.fine(xkey.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        if (isEventDisabled(xev)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        final Component currentSource = (Component)getEventSource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        handleKeyPress(xkey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
}