jdk/src/solaris/classes/sun/awt/X11/XMenuWindow.java
author yan
Mon, 06 Oct 2008 16:45:00 +0400
changeset 1966 12a51fb0db0d
parent 2 90ce3da70b43
child 3938 ef327bd847c0
permissions -rw-r--r--
5100701: Toolkit.getLockingKeyState() does not work on XToolkit, but works on Motif Summary: Does not work on Motif but works on XToolkit now; implemented using XQueryPointer. Reviewed-by: anthony
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 2002-2006 Sun Microsystems, Inc.  All Rights Reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
package sun.awt.X11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.peer.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.awt.image.BufferedImage;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.awt.geom.Point2D;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.util.Vector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.util.logging.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
public class XMenuWindow extends XBaseMenuWindow {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
    /************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
     * Data members
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
     ************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    private static Logger log = Logger.getLogger("sun.awt.X11.XMenuWindow");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
     * Primary members
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    private XMenuPeer menuPeer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
     * dimension constants
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    private final static int WINDOW_SPACING_LEFT = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    private final static int WINDOW_SPACING_RIGHT = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    private final static int WINDOW_SPACING_TOP = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    private final static int WINDOW_SPACING_BOTTOM = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    private final static int WINDOW_ITEM_INDENT = 15;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    private final static int WINDOW_ITEM_MARGIN_LEFT = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    private final static int WINDOW_ITEM_MARGIN_RIGHT = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    private final static int WINDOW_ITEM_MARGIN_TOP = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    private final static int WINDOW_ITEM_MARGIN_BOTTOM = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    private final static int WINDOW_SHORTCUT_SPACING = 10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     * Checkmark
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    private static final int CHECKMARK_SIZE = 128;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    private static final int[] CHECKMARK_X = new int[] {1, 25,56,124,124,85, 64};  // X-coords
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    private static final int[] CHECKMARK_Y = new int[] {59,35,67,  0, 12,66,123};  // Y-coords
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
     * Mapping data
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     ************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    static class MappingData extends XBaseMenuWindow.MappingData {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
         * Rectangle for the caption
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
         * Necessary to fix 6267144: PIT: Popup menu label is not shown, XToolkit
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        private Rectangle captionRect;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
         * Desired size of menu window
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        private Dimension desiredSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
         * Width of largest checkmark
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
         * At the same time the left origin
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
         * of all item's text
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        private int leftMarkWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
         * Left origin of all shortcut labels
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        private int shortcutOrigin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
         * The origin of right mark
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
         * (submenu's arrow)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        private int rightMarkOrigin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        MappingData(XMenuItemPeer[] items, Rectangle captionRect, Dimension desiredSize, int leftMarkWidth, int shortcutOrigin, int rightMarkOrigin) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
            super(items);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
            this.captionRect = captionRect;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
            this.desiredSize = desiredSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
            this.leftMarkWidth = leftMarkWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
            this.shortcutOrigin = shortcutOrigin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
            this.rightMarkOrigin = rightMarkOrigin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
         * Constructs MappingData without items
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
         * This constructor should be used in case of errors
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        MappingData() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
            this.desiredSize = new Dimension(0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
            this.leftMarkWidth = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
            this.shortcutOrigin = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
            this.rightMarkOrigin = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        public Rectangle getCaptionRect() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
            return this.captionRect;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        public Dimension getDesiredSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
            return this.desiredSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        public int getShortcutOrigin() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
            return this.shortcutOrigin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        public int getLeftMarkWidth() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
            return this.leftMarkWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        public int getRightMarkOrigin() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
            return this.rightMarkOrigin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        }
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    /************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * Construction
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
     * Constructs XMenuWindow for specified XMenuPeer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * null for XPopupMenuWindow
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    XMenuWindow(XMenuPeer menuPeer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        if (menuPeer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
            this.menuPeer = menuPeer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
            this.target = menuPeer.getContainer().target;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
            // Get menus from the target.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
            Vector targetItemVector = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
            targetItemVector = getMenuTargetItems();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
            reloadItems(targetItemVector);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    /************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * Initialization
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     ************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * Overriden initialization
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    void postInit(XCreateWindowParams params) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        super.postInit(params);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        //Fixed 6267182: PIT: Menu is not visible after
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        //showing and disposing a file dialog, XToolkit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        //toFront() is called on every show
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
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * Implementation of abstract methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     ************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * @see XBaseMenuWindow.getParentMenuWindow()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    protected XBaseMenuWindow getParentMenuWindow() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        return (menuPeer != null) ? menuPeer.getContainer() : null;
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
     * @see XBaseMenuWindow.map()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    protected MappingData map() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        //TODO:Implement popup-menu caption mapping and painting and tear-off
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        int itemCnt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        if (!isCreated()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
            MappingData mappingData = new MappingData(new XMenuItemPeer[0], new Rectangle(0, 0, 0, 0), new Dimension(0, 0), 0, 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
            return mappingData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        XMenuItemPeer[] itemVector = copyItems();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        itemCnt = itemVector.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        //We need maximum width of components before calculating item's bounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        Dimension captionSize = getCaptionSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        int maxWidth = (captionSize != null) ? captionSize.width : 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        int maxLeftIndent = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        int maxRightIndent = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        int maxShortcutWidth = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        XMenuItemPeer.TextMetrics[] itemMetrics = new XMenuItemPeer.TextMetrics[itemCnt];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        for (int i = 0; i < itemCnt; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
            XMenuItemPeer item = itemVector[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
            itemMetrics[i] = itemVector[i].getTextMetrics();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
            Dimension dim = itemMetrics[i].getTextDimension();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
            if (dim != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
                if (itemVector[i] instanceof XCheckboxMenuItemPeer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                    maxLeftIndent = Math.max(maxLeftIndent, dim.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
                } else if (itemVector[i] instanceof XMenuPeer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
                    maxRightIndent = Math.max(maxRightIndent, dim.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
                maxWidth = Math.max(maxWidth, dim.width);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
                maxShortcutWidth = Math.max(maxShortcutWidth, itemMetrics[i].getShortcutWidth());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        //Calculate bounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        int nextOffset = WINDOW_SPACING_TOP;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        int shortcutOrigin = WINDOW_SPACING_LEFT + WINDOW_ITEM_MARGIN_LEFT + maxLeftIndent + maxWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        if (maxShortcutWidth > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
            shortcutOrigin = shortcutOrigin + WINDOW_SHORTCUT_SPACING;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        int rightMarkOrigin = shortcutOrigin + maxShortcutWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        int itemWidth = rightMarkOrigin + maxRightIndent + WINDOW_ITEM_MARGIN_RIGHT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        int width = WINDOW_SPACING_LEFT + itemWidth + WINDOW_SPACING_RIGHT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        //Caption rectangle
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        Rectangle captionRect = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        if (captionSize != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
            captionRect = new Rectangle(WINDOW_SPACING_LEFT, nextOffset, itemWidth, captionSize.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            nextOffset += captionSize.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
            captionRect = new Rectangle(WINDOW_SPACING_LEFT, nextOffset, maxWidth, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        //Item rectangles
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        for (int i = 0; i < itemCnt; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
            XMenuItemPeer item = (XMenuItemPeer)itemVector[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
            XMenuItemPeer.TextMetrics metrics = itemMetrics[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
            Dimension dim = metrics.getTextDimension();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
            if (dim != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
                int itemHeight = WINDOW_ITEM_MARGIN_TOP + dim.height + WINDOW_ITEM_MARGIN_BOTTOM;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
                Rectangle bounds = new Rectangle(WINDOW_SPACING_LEFT, nextOffset, itemWidth, itemHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
                int y = (itemHeight + dim.height) / 2  - metrics.getTextBaseline();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
                Point textOrigin = new Point(WINDOW_SPACING_LEFT + WINDOW_ITEM_MARGIN_LEFT + maxLeftIndent, nextOffset + y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
                nextOffset += itemHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
                item.map(bounds, textOrigin);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
                //Text metrics could not be determined because of errors
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
                //Map item with empty rectangle
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
                Rectangle bounds = new Rectangle(WINDOW_SPACING_LEFT, nextOffset, 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
                Point textOrigin = new Point(WINDOW_SPACING_LEFT + WINDOW_ITEM_MARGIN_LEFT + maxLeftIndent, nextOffset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
                item.map(bounds, textOrigin);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        int height = nextOffset + WINDOW_SPACING_BOTTOM;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        MappingData mappingData = new MappingData(itemVector, captionRect, new Dimension(width, height), maxLeftIndent, shortcutOrigin, rightMarkOrigin);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        return mappingData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * @see XBaseMenuWindow.getSubmenuBounds()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    protected Rectangle getSubmenuBounds(Rectangle itemBounds, Dimension windowSize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        Rectangle globalBounds = toGlobal(itemBounds);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        Rectangle res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        res = fitWindowRight(globalBounds, windowSize, screenSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        if (res != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
            return res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        res = fitWindowBelow(globalBounds, windowSize, screenSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        if (res != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
            return res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        res = fitWindowAbove(globalBounds, windowSize, screenSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        if (res != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
            return res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        res = fitWindowLeft(globalBounds, windowSize, screenSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        if (res != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
            return res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        return fitWindowToScreen(windowSize, screenSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     * It's likely that size of items was changed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     * invoke resizing of window on eventHandlerThread
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
    protected void updateSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        resetMapping();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        if (isShowing()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
            XToolkit.executeOnEventHandlerThread(target, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
                    public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
                        Dimension dim = getDesiredSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
                        reshape(x, y, dim.width, dim.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
                });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        }
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
     * Overridable caption-painting functions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     * Necessary to fix 6267144: PIT: Popup menu label is not shown, XToolkit
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
     * Returns size of menu window's caption or null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     * if window has no caption.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     * Can be overriden for popup menus and tear-off menus
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
    protected Dimension getCaptionSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        return null;
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
     * Paints menu window's caption.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     * Can be overriden for popup menus and tear-off menus.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     * Default implementation does nothing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
    protected void paintCaption(Graphics g, Rectangle rect) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
    /************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     * General-purpose utility functions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     ************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
     * Returns corresponding menu peer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
    XMenuPeer getMenuPeer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        return menuPeer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
     * Reads vector of items from target
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
     * This function is overriden in XPopupMenuPeer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
    Vector getMenuTargetItems() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        return menuPeer.getTargetItems();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     * Returns desired size calculated while mapping
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
    Dimension getDesiredSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
        MappingData mappingData = (MappingData)getMappingData();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        return mappingData.getDesiredSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     * Checks if menu window is created
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
    boolean isCreated() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
        return getWindow() != 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
     * Performs delayed creation of menu window if necessary
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
    boolean ensureCreated() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        if (!isCreated()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
            XCreateWindowParams params = getDelayedParams();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
            params.remove(DELAYED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
            params.add(OVERRIDE_REDIRECT, Boolean.TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
            params.add(XWindow.TARGET, target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
            init(params);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     * Init window if it's not inited yet
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
     * and show it at specified coordinates
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     * @param bounds bounding rectangle of window
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
     * in global coordinates
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
    void show(Rectangle bounds) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        if (!isCreated()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
        if (log.isLoggable(Level.FINER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
            log.finer("showing menu window + " + getWindow() + " at " + bounds);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
            reshape(bounds.x, bounds.y, bounds.width, bounds.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
            xSetVisible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
            //Fixed 6267182: PIT: Menu is not visible after
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
            //showing and disposing a file dialog, XToolkit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
            toFront();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
            selectItem(getFirstSelectableItem(), false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
     * Hides menu window
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
    void hide() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
        selectItem(null, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
        xSetVisible(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
    /************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
     * Painting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
     ************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
     * Paints menu window
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
    public void paint(Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
        resetColors();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
        int width = getWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
        int height = getHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
        flush();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
        //Fill background of rectangle
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
        g.setColor(getBackgroundColor());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
        g.fillRect(1, 1, width - 2, height - 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
        draw3DRect(g, 0, 0, width, height, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
        //Mapping data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
        MappingData mappingData = (MappingData)getMappingData();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
        //Paint caption
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        paintCaption(g, mappingData.getCaptionRect());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
        //Paint menus
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
        XMenuItemPeer[] itemVector = mappingData.getItems();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
        Dimension windowSize =  mappingData.getDesiredSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
        XMenuItemPeer selectedItem = getSelectedItem();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
        for (int i = 0; i < itemVector.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
            XMenuItemPeer item = itemVector[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
            XMenuItemPeer.TextMetrics metrics = item.getTextMetrics();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
            Rectangle bounds = item.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
            if (item.isSeparator()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
                draw3DRect(g, bounds.x, bounds.y + bounds.height / 2,  bounds.width, 2, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
                //paint item
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
                g.setFont(item.getTargetFont());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
                Point textOrigin = item.getTextOrigin();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
                Dimension textDim = metrics.getTextDimension();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
                if (item == selectedItem) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
                    g.setColor(getSelectedColor());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
                    g.fillRect(bounds.x, bounds.y, bounds.width, bounds.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
                    draw3DRect(g, bounds.x, bounds.y, bounds.width, bounds.height, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
                g.setColor(item.isTargetItemEnabled() ? getForegroundColor() : getDisabledColor());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
                g.drawString(item.getTargetLabel(), textOrigin.x, textOrigin.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
                String shortcutText = item.getShortcutText();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
                if (shortcutText != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
                    g.drawString(shortcutText, mappingData.getShortcutOrigin(), textOrigin.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
                if (item instanceof XMenuPeer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
                    //calculate arrow coordinates
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
                    int markWidth = textDim.height * 4 / 5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
                    int markHeight = textDim.height * 4 / 5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
                    int markX = bounds.x + bounds.width - markWidth - WINDOW_SPACING_RIGHT - WINDOW_ITEM_MARGIN_RIGHT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
                    int markY = bounds.y + (bounds.height - markHeight) / 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
                    //draw arrow
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
                    g.setColor(item.isTargetItemEnabled() ? getDarkShadowColor() : getDisabledColor());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
                    g.drawLine(markX, markY + markHeight, markX + markWidth, markY + markHeight / 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
                    g.setColor(item.isTargetItemEnabled() ? getLightShadowColor() : getDisabledColor());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
                    g.drawLine(markX, markY, markX + markWidth, markY + markHeight / 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
                    g.drawLine(markX, markY, markX, markY + markHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
                } else if (item instanceof XCheckboxMenuItemPeer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
                    //calculate checkmark coordinates
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
                    int markWidth = textDim.height * 4 / 5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
                    int markHeight = textDim.height * 4 / 5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
                    int markX = WINDOW_SPACING_LEFT + WINDOW_ITEM_MARGIN_LEFT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
                    int markY = bounds.y + (bounds.height - markHeight) / 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
                    boolean checkState = ((XCheckboxMenuItemPeer)item).getTargetState();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
                    //draw checkmark
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
                    if (checkState) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
                        g.setColor(getSelectedColor());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
                        g.fillRect(markX, markY, markWidth, markHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
                        draw3DRect(g, markX, markY, markWidth, markHeight, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
                        int[] px = new int[CHECKMARK_X.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
                        int[] py = new int[CHECKMARK_X.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
                        for (int j = 0; j < CHECKMARK_X.length; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
                            px[j] = markX + CHECKMARK_X[j] * markWidth / CHECKMARK_SIZE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
                            py[j] = markY + CHECKMARK_Y[j] * markHeight / CHECKMARK_SIZE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
                        g.setColor(item.isTargetItemEnabled() ? getForegroundColor() : getDisabledColor());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
                        g.fillPolygon(px, py, CHECKMARK_X.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
                        g.setColor(getBackgroundColor());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
                        g.fillRect(markX, markY, markWidth, markHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
                        draw3DRect(g, markX, markY, markWidth, markHeight, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
        flush();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
}