jdk/src/solaris/classes/sun/awt/X11/XMenuPeer.java
author ant
Fri, 22 Feb 2013 15:13:13 +0400
changeset 15983 26a673dec5b2
parent 13604 31089af1a447
child 16839 d0f2e97b7359
permissions -rw-r--r--
8006406: lightweight embedding in other Java UI toolkits Reviewed-by: serb, anthony, art
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3938
diff changeset
     2
 * Copyright (c) 2002, 2007, 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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.util.Vector;
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2
diff changeset
    31
import sun.util.logging.PlatformLogger;
13604
31089af1a447 7163201: Simplify toolkit internals references
bagiras
parents: 5506
diff changeset
    32
import sun.awt.AWTAccessor;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
public class XMenuPeer extends XMenuItemPeer implements MenuPeer {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
    /************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
     * Data members
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
     ************************************************/
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2
diff changeset
    41
    private static PlatformLogger log = PlatformLogger.getLogger("sun.awt.X11.XMenuPeer");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
     * Window that correspond to this menu
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    XMenuWindow menuWindow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    /************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
     * Construction
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
     ************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    XMenuPeer(Menu target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
        super(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
     * This function is called when menu is bound
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
     * to its container window. Creates submenu window
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
     * that fills its items vector while construction
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    void setContainer(XBaseMenuWindow container) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        super.setContainer(container);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        menuWindow = new XMenuWindow(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    /************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     * Implementaion of interface methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     *
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
     * From MenuComponentPeer
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
     * Disposes menu window if needed
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    public void dispose() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        if (menuWindow != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
            menuWindow.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        super.dispose();
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
     * Resets text metrics for this item, for its menu window
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * and for all descendant menu windows
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    public void setFont(Font font) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        //TODO:We can decrease count of repaints here
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        //and get rid of recursion
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        resetTextMetrics();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        XMenuWindow menuWindow = getMenuWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        if (menuWindow != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
            menuWindow.setItemsFont(font);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        repaintIfShowing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * From MenuPeer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * addSeparator routines are not used
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * in peers. Shared code invokes addItem("-")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * for adding separators
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    public void addSeparator() {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2
diff changeset
   114
        if (log.isLoggable(PlatformLogger.FINER)) log.finer("addSeparator is not implemented");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    public void addItem(MenuItem item) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        XMenuWindow menuWindow = getMenuWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        if (menuWindow != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
            menuWindow.addItem(item);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        } else {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2
diff changeset
   122
            if (log.isLoggable(PlatformLogger.FINE)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
                log.fine("Attempt to use XMenuWindowPeer without window");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    public void delItem(int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        XMenuWindow menuWindow = getMenuWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        if (menuWindow != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
            menuWindow.delItem(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        } else {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2
diff changeset
   133
            if (log.isLoggable(PlatformLogger.FINE)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
                log.fine("Attempt to use XMenuWindowPeer without window");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    /************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * Access to target's fields
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     ************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    Vector getTargetItems() {
13604
31089af1a447 7163201: Simplify toolkit internals references
bagiras
parents: 5506
diff changeset
   145
        return AWTAccessor.getMenuAccessor().getItems((Menu)getTarget());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    }
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
     * Overriden behaviour
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     ************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    boolean isSeparator() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    //Fix for 6180416: Shortcut keys are displayed against Menus on XToolkit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    //Menu should always return null as shortcutText
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    String getShortcutText() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    /************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * Utility functions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     ************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * Returns menu window of this menu or null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * it this menu has no container and so its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * window can't be created.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    XMenuWindow getMenuWindow() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        return menuWindow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
}