1 /* |
|
2 * Copyright 1995-2005 Sun Microsystems, Inc. All Rights Reserved. |
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 * |
|
5 * This code is free software; you can redistribute it and/or modify it |
|
6 * under the terms of the GNU General Public License version 2 only, as |
|
7 * published by the Free Software Foundation. Sun designates this |
|
8 * particular file as subject to the "Classpath" exception as provided |
|
9 * 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 |
|
29 import java.awt.*; |
|
30 import java.awt.event.*; |
|
31 import java.awt.peer.*; |
|
32 |
|
33 class MCheckboxMenuItemPeer extends MMenuItemPeer |
|
34 implements CheckboxMenuItemPeer { |
|
35 private boolean inUpCall=false; |
|
36 private boolean inInit=false; |
|
37 |
|
38 native void pSetState(boolean t); |
|
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.targetToPeer(getParent_NoClientCode(target)); |
|
52 create(parent); |
|
53 } |
|
54 |
|
55 public void setState(boolean t) { |
|
56 if (!nativeCreated) { |
|
57 return; |
|
58 } |
|
59 if (!inUpCall && (t != getState())) { |
|
60 pSetState(t); |
|
61 if (!inInit) { |
|
62 // 4135725 : do not notify on programatic changes |
|
63 // notifyStateChanged(t); |
|
64 } |
|
65 } |
|
66 } |
|
67 |
|
68 void notifyStateChanged(boolean state) { |
|
69 CheckboxMenuItem cb = (CheckboxMenuItem)target; |
|
70 ItemEvent e = new ItemEvent(cb, |
|
71 ItemEvent.ITEM_STATE_CHANGED, |
|
72 cb.getLabel(), |
|
73 state ? ItemEvent.SELECTED : ItemEvent.DESELECTED); |
|
74 postEvent(e); |
|
75 } |
|
76 |
|
77 |
|
78 // NOTE: This method may be called by privileged threads. |
|
79 // DO NOT INVOKE CLIENT CODE ON THIS THREAD! |
|
80 public void action(long when, int modifiers, boolean state) { |
|
81 final CheckboxMenuItem cb = (CheckboxMenuItem)target; |
|
82 final boolean newState = state; |
|
83 |
|
84 MToolkit.executeOnEventHandlerThread(cb, new Runnable() { |
|
85 public void run() { |
|
86 cb.setState(newState); |
|
87 notifyStateChanged(newState); |
|
88 } |
|
89 }); |
|
90 //Fix for 5005195: MAWT: CheckboxMenuItem fires action events |
|
91 //super.action() is not invoked |
|
92 } // action() |
|
93 } // class MCheckboxMenuItemPeer |
|