0N/A/*
2362N/A * Copyright (c) 1996, 2007, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/Apackage sun.awt.windows;
0N/A
0N/Aimport java.util.ResourceBundle;
0N/Aimport java.util.MissingResourceException;
0N/Aimport java.awt.*;
0N/Aimport java.awt.peer.*;
0N/Aimport java.awt.event.ActionEvent;
0N/Aimport java.security.AccessController;
0N/Aimport java.security.PrivilegedAction;
1696N/Aimport sun.util.logging.PlatformLogger;
0N/A
0N/Aclass WMenuItemPeer extends WObjectPeer implements MenuItemPeer {
1696N/A private static final PlatformLogger log = PlatformLogger.getLogger("sun.awt.WMenuItemPeer");
0N/A
0N/A static {
0N/A initIDs();
0N/A }
0N/A
0N/A String shortcutLabel;
0N/A //WMenuBarPeer extends WMenuPeer
0N/A //so parent is always instanceof WMenuPeer
0N/A protected WMenuPeer parent;
0N/A
0N/A // MenuItemPeer implementation
0N/A
0N/A private synchronized native void _dispose();
0N/A protected void disposeImpl() {
0N/A WToolkit.targetDisposedPeer(target, this);
0N/A _dispose();
0N/A }
0N/A
0N/A public void setEnabled(boolean b) {
0N/A enable(b);
0N/A }
0N/A
0N/A /**
0N/A * DEPRECATED: Replaced by setEnabled(boolean).
0N/A */
0N/A public void enable() {
0N/A enable(true);
0N/A }
0N/A
0N/A /**
0N/A * DEPRECATED: Replaced by setEnabled(boolean).
0N/A */
0N/A public void disable() {
0N/A enable(false);
0N/A }
0N/A
0N/A public void readShortcutLabel() {
0N/A //Fix for 6288578: PIT. Windows: Shortcuts displayed for the menuitems in a popup menu
0N/A WMenuPeer ancestor = parent;
0N/A while (ancestor != null && !(ancestor instanceof WMenuBarPeer)) {
0N/A ancestor = ancestor.parent;
0N/A }
0N/A if (ancestor instanceof WMenuBarPeer) {
0N/A MenuShortcut sc = ((MenuItem)target).getShortcut();
0N/A shortcutLabel = (sc != null) ? sc.toString() : null;
0N/A } else {
0N/A shortcutLabel = null;
0N/A }
0N/A }
0N/A
0N/A public void setLabel(String label) {
0N/A //Fix for 6288578: PIT. Windows: Shortcuts displayed for the menuitems in a popup menu
0N/A readShortcutLabel();
0N/A _setLabel(label);
0N/A }
0N/A public native void _setLabel(String label);
0N/A
0N/A // Toolkit & peer internals
0N/A
0N/A private final boolean isCheckbox;
0N/A
0N/A protected WMenuItemPeer() {
0N/A isCheckbox = false;
0N/A }
0N/A WMenuItemPeer(MenuItem target) {
0N/A this(target, false);
0N/A }
0N/A
0N/A WMenuItemPeer(MenuItem target, boolean isCheckbox) {
0N/A this.target = target;
0N/A this.parent = (WMenuPeer) WToolkit.targetToPeer(target.getParent());
0N/A this.isCheckbox = isCheckbox;
0N/A create(parent);
0N/A // fix for 5088782: check if menu object is created successfully
0N/A checkMenuCreation();
0N/A //Fix for 6288578: PIT. Windows: Shortcuts displayed for the menuitems in a popup menu
0N/A readShortcutLabel();
0N/A }
0N/A
0N/A protected void checkMenuCreation()
0N/A {
0N/A // fix for 5088782: check if menu peer is created successfully
0N/A if (pData == 0)
0N/A {
0N/A if (createError != null)
0N/A {
0N/A throw createError;
0N/A }
0N/A else
0N/A {
0N/A throw new InternalError("couldn't create menu peer");
0N/A }
0N/A }
0N/A
0N/A }
0N/A
0N/A /*
0N/A * Post an event. Queue it for execution by the callback thread.
0N/A */
0N/A void postEvent(AWTEvent event) {
0N/A WToolkit.postEvent(WToolkit.targetToAppContext(target), event);
0N/A }
0N/A
0N/A native void create(WMenuPeer parent);
0N/A
0N/A native void enable(boolean e);
0N/A
0N/A // native callbacks
0N/A
0N/A void handleAction(final long when, final int modifiers) {
0N/A WToolkit.executeOnEventHandlerThread(target, new Runnable() {
0N/A public void run() {
0N/A postEvent(new ActionEvent(target, ActionEvent.ACTION_PERFORMED,
0N/A ((MenuItem)target).
0N/A getActionCommand(), when,
0N/A modifiers));
0N/A }
0N/A });
0N/A }
0N/A
0N/A private static Font defaultMenuFont;
0N/A
0N/A static {
0N/A defaultMenuFont = (Font) AccessController.doPrivileged(
0N/A new PrivilegedAction() {
0N/A public Object run() {
0N/A try {
0N/A ResourceBundle rb = ResourceBundle.getBundle("sun.awt.windows.awtLocalization");
0N/A return Font.decode(rb.getString("menuFont"));
0N/A } catch (MissingResourceException e) {
1696N/A if (log.isLoggable(PlatformLogger.FINE)) {
1696N/A log.fine("WMenuItemPeer: " + e.getMessage()+". Using default MenuItem font.", e);
0N/A }
0N/A return new Font("SanSerif", Font.PLAIN, 11);
0N/A }
0N/A }
0N/A });
0N/A }
0N/A
0N/A static Font getDefaultFont() {
0N/A return defaultMenuFont;
0N/A }
0N/A
0N/A /**
0N/A * Initialize JNI field and method IDs
0N/A */
0N/A private static native void initIDs();
0N/A
0N/A // Needed for MenuComponentPeer.
0N/A public void setFont(Font f) {
0N/A }
0N/A}