001: /*
002: * @(#)GMenuItemPeer.java 1.13 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:
028: package sun.awt.gtk;
029:
030: import sun.awt.peer.*;
031: import java.awt.*;
032: import java.awt.event.*;
033:
034: /**
035: *
036: *
037: * @author Nicholas Allen
038: */
039:
040: class GMenuItemPeer implements MenuItemPeer {
041: private static native void initIDs();
042:
043: static {
044: initIDs();
045: }
046:
047: /** Creates a new GMenuItemPeer. */
048:
049: GMenuItemPeer(MenuItem target) {
050: this .target = target;
051: create();
052: try {
053: GMenuContainer container = (GMenuContainer) GToolkit
054: .getMenuComponentPeer((MenuComponent) target
055: .getParent());
056: menuBar = container.getMenuBar();
057: /* Add the item to its container. */
058:
059: container.add(this );
060: } catch (ClassCastException e) {
061: }
062: setLabel(target.getLabel());
063: setEnabled(target.isEnabled());
064: setFont(target.getFont());
065: }
066:
067: protected void create() {
068: boolean isSeparator = target.getLabel().equals("-");
069: create(isSeparator);
070: if (!isSeparator) {
071: setLabel(target.getLabel());
072: setFont(target.getFont());
073: }
074: }
075:
076: protected native void create(boolean isSeparator);
077:
078: public native void dispose();
079:
080: public void setLabel(String label) {
081: if (label != null) {
082: byte[] encString = label.getBytes();
083: byte[] encStringNul = new byte[encString.length + 1];
084: System.arraycopy(encString, 0, encStringNul, 0,
085: encString.length);
086: setLabelNative(encStringNul);
087: }
088: }
089:
090: protected native void setLabelNative(byte[] label);
091:
092: public native void setEnabled(boolean b);
093:
094: public native void setFont(Font f);
095:
096: public GMenuBarPeer getMenuBar() {
097: return menuBar;
098: }
099:
100: private void postActionEvent() {
101: GToolkit
102: .postEvent(new ActionEvent(target,
103: ActionEvent.ACTION_PERFORMED, target
104: .getActionCommand()));
105: }
106:
107: private int data;
108: protected MenuItem target;
109: /** The menu bar that this menu item is attatched to if it is attatcyed to a menu bar.
110: This is needed for the accelerator group that is used to implement shortcuts in Gtk.
111: The menu bar holds the accelerator group. */
112:
113: private GMenuBarPeer menuBar;
114: }
|