001: /*
002: * @(#)PPCMenuItemPeer.java 1.9 06/10/10
003: *
004: * Copyright 1990-2006 Sun Microsystems, Inc. All Rights Reserved.
005: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License version
009: * 2 only, as published by the Free Software Foundation.
010: *
011: * This program is distributed in the hope that it will be useful, but
012: * WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * General Public License version 2 for more details (a copy is
015: * included at /legal/license.txt).
016: *
017: * You should have received a copy of the GNU General Public License
018: * version 2 along with this work; if not, write to the Free Software
019: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA
021: *
022: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
023: * Clara, CA 95054 or visit www.sun.com if you need additional
024: * information or have any questions.
025: */
026:
027: package sun.awt.pocketpc;
028:
029: import java.util.ResourceBundle;
030: import java.util.MissingResourceException;
031: import java.awt.*;
032: import sun.awt.peer.*;
033: import java.awt.event.ActionEvent;
034:
035: /**
036: *
037: *
038: * @author Nicholas Allen
039: */
040:
041: class PPCMenuItemPeer extends PPCObjectPeer implements MenuItemPeer {
042:
043: private static native void initIDs();
044:
045: static {
046: initIDs();
047: }
048:
049: private boolean disposed = false;
050:
051: String shortcutLabel;
052:
053: // MenuItemPeer implementation
054:
055: /*
056: * Subclasses should override disposeImpl() instead of dispose(). Client
057: * code should always invoke dispose(), never disposeImpl().
058: */
059: private native void disposeNative();
060:
061: protected void disposeImpl() {
062: // PPCToolkit.targetDisposedPeer(target, this);
063: disposeNative();
064: }
065:
066: public final void dispose() {
067: boolean call_disposeImpl = false;
068:
069: if (!disposed) {
070: synchronized (this ) {
071: if (!disposed) {
072: disposed = call_disposeImpl = true;
073: }
074: }
075: }
076:
077: if (call_disposeImpl) {
078: disposeImpl();
079: }
080: }
081:
082: public void setEnabled(boolean b) {
083: enable(b);
084: }
085:
086: /**
087: * DEPRECATED: Replaced by setEnabled(boolean).
088: */
089: public void enable() {
090: enable(true);
091: }
092:
093: /**
094: * DEPRECATED: Replaced by setEnabled(boolean).
095: */
096: public void disable() {
097: enable(false);
098: }
099:
100: public void setLabel(String label) {
101: //Netscape : Windows popup menus dont have labels, so trying to do a
102: //setLabel on one will cause a segFault. Ideally, we'd just
103: //override setLabel in PPCPopupMenuPeer, but due to a JIT bug we cant.
104: if (this instanceof PPCPopupMenuPeer)
105: return;
106:
107: MenuShortcut sc = ((MenuItem) target).getShortcut();
108: shortcutLabel = (sc != null) ? sc.toString() : null;
109: _setLabel(label);
110: }
111:
112: public native void _setLabel(String label);
113:
114: // Toolkit & peer internals
115:
116: boolean isCheckbox = false;
117:
118: protected PPCMenuItemPeer() {
119: }
120:
121: PPCMenuItemPeer(MenuItem target) {
122: this .target = target;
123: PPCMenuPeer parent = (PPCMenuPeer) PPCToolkit
124: .getMenuComponentPeer((MenuComponent) target
125: .getParent());
126: create(parent);
127: MenuShortcut sc = ((MenuItem) target).getShortcut();
128: if (sc != null) {
129: shortcutLabel = sc.toString();
130: }
131: }
132:
133: native void create(PPCMenuPeer parent);
134:
135: native void enable(boolean e);
136:
137: protected void finalize() throws Throwable {
138: // Calling dispose() here is essentially a NOP since the current
139: // implementation prohibts gc before an explicit call to dispose().
140: dispose();
141: super .finalize();
142: }
143:
144: // native callbacks
145:
146: void handleAction(int modifiers) {
147: PPCToolkit.postEvent(new ActionEvent(target,
148: ActionEvent.ACTION_PERFORMED, ((MenuItem) target)
149: .getActionCommand(), modifiers));
150:
151: }
152:
153: private static Font defaultMenuFont;
154:
155: static {
156: try {
157: ResourceBundle rb = ResourceBundle
158: .getBundle("sun.awt.windows.awtLocalization");
159: defaultMenuFont = Font.decode(rb.getString("menuFont"));
160: } catch (MissingResourceException e) {
161: //System.out.println(e.getMessage());
162: // System.out.println("Using default MenuItem font\n");
163: defaultMenuFont = new Font("SanSerif", Font.PLAIN, 11);
164: }
165:
166: }
167:
168: Font getDefaultFont() {
169: return defaultMenuFont;
170: }
171: }
|