2
|
1 |
/*
|
|
2 |
* Copyright 2003-2007 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.X11;
|
|
27 |
|
|
28 |
import java.awt.*;
|
|
29 |
import java.awt.peer.*;
|
|
30 |
import java.awt.event.*;
|
|
31 |
|
|
32 |
import java.util.logging.*;
|
|
33 |
|
|
34 |
import java.lang.reflect.Field;
|
|
35 |
import sun.awt.SunToolkit;
|
|
36 |
|
|
37 |
class XCheckboxMenuItemPeer extends XMenuItemPeer implements CheckboxMenuItemPeer {
|
|
38 |
|
|
39 |
/************************************************
|
|
40 |
*
|
|
41 |
* Data members
|
|
42 |
*
|
|
43 |
************************************************/
|
|
44 |
|
|
45 |
private static Logger log = Logger.getLogger("sun.awt.X11.XCheckboxMenuItemPeer");
|
|
46 |
|
|
47 |
/*
|
|
48 |
* CheckboxMenuItem's fields
|
|
49 |
*/
|
|
50 |
private final static Field f_state;
|
|
51 |
static {
|
|
52 |
f_state = SunToolkit.getField(CheckboxMenuItem.class, "state");
|
|
53 |
}
|
|
54 |
|
|
55 |
/************************************************
|
|
56 |
*
|
|
57 |
* Construction
|
|
58 |
*
|
|
59 |
************************************************/
|
|
60 |
XCheckboxMenuItemPeer(CheckboxMenuItem target) {
|
|
61 |
super(target);
|
|
62 |
}
|
|
63 |
|
|
64 |
/************************************************
|
|
65 |
*
|
|
66 |
* Implementaion of interface methods
|
|
67 |
*
|
|
68 |
************************************************/
|
|
69 |
|
|
70 |
//Prom CheckboxMenuItemtPeer
|
|
71 |
public void setState(boolean t) {
|
|
72 |
repaintIfShowing();
|
|
73 |
}
|
|
74 |
|
|
75 |
/************************************************
|
|
76 |
*
|
|
77 |
* Access to target's fields
|
|
78 |
*
|
|
79 |
************************************************/
|
|
80 |
boolean getTargetState() {
|
|
81 |
MenuItem target = getTarget();
|
|
82 |
if (target == null) {
|
|
83 |
return false;
|
|
84 |
}
|
|
85 |
try {
|
|
86 |
return f_state.getBoolean(target);
|
|
87 |
} catch (IllegalAccessException e) {
|
|
88 |
e.printStackTrace();
|
|
89 |
}
|
|
90 |
return false;
|
|
91 |
}
|
|
92 |
|
|
93 |
/************************************************
|
|
94 |
*
|
|
95 |
* Utility functions
|
|
96 |
*
|
|
97 |
************************************************/
|
|
98 |
|
|
99 |
/**
|
|
100 |
* Toggles state and generates ItemEvent
|
|
101 |
*/
|
|
102 |
void action(final long when) {
|
|
103 |
XToolkit.executeOnEventHandlerThread((CheckboxMenuItem)getTarget(), new Runnable() {
|
|
104 |
public void run() {
|
|
105 |
doToggleState(when);
|
|
106 |
}
|
|
107 |
});
|
|
108 |
}
|
|
109 |
|
|
110 |
|
|
111 |
/************************************************
|
|
112 |
*
|
|
113 |
* Private
|
|
114 |
*
|
|
115 |
************************************************/
|
|
116 |
private void doToggleState(long when) {
|
|
117 |
CheckboxMenuItem cb = (CheckboxMenuItem)getTarget();
|
|
118 |
boolean newState = !getTargetState();
|
|
119 |
cb.setState(newState);
|
|
120 |
ItemEvent e = new ItemEvent(cb,
|
|
121 |
ItemEvent.ITEM_STATE_CHANGED,
|
|
122 |
getTargetLabel(),
|
|
123 |
getTargetState() ? ItemEvent.SELECTED : ItemEvent.DESELECTED);
|
|
124 |
XWindow.postEventStatic(e);
|
|
125 |
//WToolkit does not post ActionEvent when clicking on menu item
|
|
126 |
//MToolkit _does_ post.
|
|
127 |
//Fix for 5005195 MAWT: CheckboxMenuItem fires action events
|
|
128 |
//Events should not be fired
|
|
129 |
//XWindow.postEventStatic(new ActionEvent(cb, ActionEvent.ACTION_PERFORMED,
|
|
130 |
// getTargetActionCommand(), when,
|
|
131 |
// 0));
|
|
132 |
}
|
|
133 |
|
|
134 |
} // class XCheckboxMenuItemPeer
|