01: /*
02: * Copyright 1995-2005 Sun Microsystems, Inc. All Rights Reserved.
03: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
04: *
05: * This code is free software; you can redistribute it and/or modify it
06: * under the terms of the GNU General Public License version 2 only, as
07: * published by the Free Software Foundation. Sun designates this
08: * particular file as subject to the "Classpath" exception as provided
09: * by Sun in the LICENSE file that accompanied this code.
10: *
11: * This code is distributed in the hope that it will be useful, but WITHOUT
12: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14: * version 2 for more details (a copy is included in the LICENSE file that
15: * accompanied this code).
16: *
17: * You should have received a copy of the GNU General Public License version
18: * 2 along with this work; if not, write to the Free Software Foundation,
19: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20: *
21: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22: * CA 95054 USA or visit www.sun.com if you need additional information or
23: * have any questions.
24: */
25:
26: package sun.awt.motif;
27:
28: import java.awt.*;
29: import java.awt.event.*;
30: import java.awt.peer.*;
31:
32: class MCheckboxMenuItemPeer extends MMenuItemPeer implements
33: CheckboxMenuItemPeer {
34: private boolean inUpCall = false;
35: private boolean inInit = false;
36:
37: native void pSetState(boolean t);
38:
39: native boolean getState();
40:
41: void create(MMenuPeer parent) {
42: super .create(parent);
43: inInit = true;
44: setState(((CheckboxMenuItem) target).getState());
45: inInit = false;
46: }
47:
48: MCheckboxMenuItemPeer(CheckboxMenuItem target) {
49: this .target = target;
50: isCheckbox = true;
51: MMenuPeer parent = (MMenuPeer) MToolkit
52: .targetToPeer(getParent_NoClientCode(target));
53: create(parent);
54: }
55:
56: public void setState(boolean t) {
57: if (!nativeCreated) {
58: return;
59: }
60: if (!inUpCall && (t != getState())) {
61: pSetState(t);
62: if (!inInit) {
63: // 4135725 : do not notify on programatic changes
64: // notifyStateChanged(t);
65: }
66: }
67: }
68:
69: void notifyStateChanged(boolean state) {
70: CheckboxMenuItem cb = (CheckboxMenuItem) target;
71: ItemEvent e = new ItemEvent(cb, ItemEvent.ITEM_STATE_CHANGED,
72: cb.getLabel(), state ? ItemEvent.SELECTED
73: : ItemEvent.DESELECTED);
74: postEvent(e);
75: }
76:
77: // NOTE: This method may be called by privileged threads.
78: // DO NOT INVOKE CLIENT CODE ON THIS THREAD!
79: public void action(long when, int modifiers, boolean state) {
80: final CheckboxMenuItem cb = (CheckboxMenuItem) target;
81: final boolean newState = state;
82:
83: MToolkit.executeOnEventHandlerThread(cb, new Runnable() {
84: public void run() {
85: cb.setState(newState);
86: notifyStateChanged(newState);
87: }
88: });
89: //Fix for 5005195: MAWT: CheckboxMenuItem fires action events
90: //super.action() is not invoked
91: } // action()
92: } // class MCheckboxMenuItemPeer
|