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