45 |
|
|
46 |
|
|
47 |
/** |
/** |
48 |
* DOCUMENT ME! |
* This class represents JCheckBoxMenuItem. Its behaviour is very similar |
49 |
|
* to JCheckBoxButton. Just like the JCheckBoxButton, user can check and |
50 |
|
* uncheck this menu item by clicking on it. Also setSelected()/setState() |
51 |
|
* can be use used for the same purpose. JCheckBoxMenuItem uses |
52 |
|
* ToggleButtonModel to keep track of its selection. |
53 |
*/ |
*/ |
54 |
public class JCheckBoxMenuItem extends JMenuItem implements SwingConstants, |
public class JCheckBoxMenuItem extends JMenuItem implements SwingConstants, |
55 |
Accessible |
Accessible |
56 |
{ |
{ |
57 |
private static final long serialVersionUID = -6676402307973384715L; |
private static final long serialVersionUID = -6676402307973384715L; |
58 |
|
|
59 |
|
/** name for the UI delegate for this menuItem. */ |
60 |
private static final String uiClassID = "CheckBoxMenuItemUI"; |
private static final String uiClassID = "CheckBoxMenuItemUI"; |
61 |
|
|
62 |
|
/** Indicates whether this menu item is checked. */ |
63 |
private boolean state; |
private boolean state; |
64 |
private Object[] selectedObjects; |
|
65 |
|
/** |
66 |
|
* This array contains text of this menu item if this menu item is in |
67 |
|
* checked state and null it is not. |
68 |
|
*/ |
69 |
|
private Object[] selectedObjects = new Object[1]; |
70 |
|
|
71 |
/** |
/** |
72 |
* Creates a new JCheckBoxMenuItem object. |
* Creates a new JCheckBoxMenuItem object. |
77 |
} |
} |
78 |
|
|
79 |
/** |
/** |
80 |
* Creates a new JCheckBoxMenuItem object. |
* Creates a new JCheckBoxMenuItem with given icon |
81 |
* |
* |
82 |
* @param icon DOCUMENT ME! |
* @param icon Icon for this menu item |
83 |
*/ |
*/ |
84 |
public JCheckBoxMenuItem(Icon icon) |
public JCheckBoxMenuItem(Icon icon) |
85 |
{ |
{ |
87 |
} |
} |
88 |
|
|
89 |
/** |
/** |
90 |
* Creates a new JCheckBoxMenuItem object. |
* Creates a new JCheckBoxMenuItem with given label |
91 |
* |
* |
92 |
* @param text DOCUMENT ME! |
* @param text Label for this menu item |
93 |
*/ |
*/ |
94 |
public JCheckBoxMenuItem(String text) |
public JCheckBoxMenuItem(String text) |
95 |
{ |
{ |
97 |
} |
} |
98 |
|
|
99 |
/** |
/** |
100 |
* Creates a new JCheckBoxMenuItem object. |
* Creates a new JCheckBoxMenuItem using given action |
101 |
* |
* |
102 |
* @param action DOCUMENT ME! |
* @param action Action for this menu item. |
103 |
*/ |
*/ |
104 |
public JCheckBoxMenuItem(Action action) |
public JCheckBoxMenuItem(Action action) |
105 |
{ |
{ |
108 |
} |
} |
109 |
|
|
110 |
/** |
/** |
111 |
* Creates a new JCheckBoxMenuItem object. |
* Creates a new JCheckBoxMenuItem object with given label and icon |
112 |
* |
* |
113 |
* @param text DOCUMENT ME! |
* @param text Label for this menu item |
114 |
* @param icon DOCUMENT ME! |
* @param icon Icon for this menu item |
115 |
*/ |
*/ |
116 |
public JCheckBoxMenuItem(String text, Icon icon) |
public JCheckBoxMenuItem(String text, Icon icon) |
117 |
{ |
{ |
119 |
} |
} |
120 |
|
|
121 |
/** |
/** |
122 |
* Creates a new JCheckBoxMenuItem object. |
* Creates a new JCheckBoxMenuItem object using specified label and |
123 |
|
* marked as checked if given 'state' is true |
124 |
* |
* |
125 |
* @param text DOCUMENT ME! |
* @param text Label for this menu item |
126 |
* @param state DOCUMENT ME! |
* @param state True if this item should be in checked state and false otherwise |
127 |
*/ |
*/ |
128 |
public JCheckBoxMenuItem(String text, boolean state) |
public JCheckBoxMenuItem(String text, boolean state) |
129 |
{ |
{ |
131 |
} |
} |
132 |
|
|
133 |
/** |
/** |
134 |
* Creates a new JCheckBoxMenuItem object. |
* Creates a new JCheckBoxMenuItem object with given label, icon, |
135 |
|
* and marked as checked if given 'state' is true |
136 |
* |
* |
137 |
* @param text DOCUMENT ME! |
* @param text Label for this menu item |
138 |
* @param icon DOCUMENT ME! |
* @param icon icon for this menu item |
139 |
* @param state DOCUMENT ME! |
* @param state True if this item should be in checked state and false otherwise |
140 |
*/ |
*/ |
141 |
public JCheckBoxMenuItem(String text, Icon icon, boolean state) |
public JCheckBoxMenuItem(String text, Icon icon, boolean state) |
142 |
{ |
{ |
145 |
this.state = state; |
this.state = state; |
146 |
} |
} |
147 |
|
|
|
/** |
|
|
* DOCUMENT ME! |
|
|
* |
|
|
* @param stream DOCUMENT ME! |
|
|
* |
|
|
* @throws IOException DOCUMENT ME! |
|
|
*/ |
|
148 |
private void writeObject(ObjectOutputStream stream) throws IOException |
private void writeObject(ObjectOutputStream stream) throws IOException |
149 |
{ |
{ |
|
// TODO |
|
150 |
} |
} |
151 |
|
|
152 |
/** |
/** |
153 |
* DOCUMENT ME! |
* This method returns a name to identify which look and feel class will be |
154 |
|
* the UI delegate for the menuItem. |
155 |
* |
* |
156 |
* @return $returnType$ DOCUMENT ME! |
* @return The Look and Feel classID. "JCheckBoxMenuItemUI" |
157 |
*/ |
*/ |
158 |
public String getUIClassID() |
public String getUIClassID() |
159 |
{ |
{ |
161 |
} |
} |
162 |
|
|
163 |
/** |
/** |
164 |
* DOCUMENT ME! |
* Returns checked state for this check box menu item. |
165 |
* |
* |
166 |
* @return $returnType$ DOCUMENT ME! |
* @return Returns true if this menu item is in checked state |
167 |
|
* and false otherwise. |
168 |
*/ |
*/ |
169 |
public boolean getState() |
public boolean getState() |
170 |
{ |
{ |
172 |
} |
} |
173 |
|
|
174 |
/** |
/** |
175 |
* DOCUMENT ME! |
* Sets state for this check box menu item. If |
176 |
|
* given 'state' is true, then mark menu item as checked, |
177 |
|
* and uncheck this menu item otherwise. |
178 |
|
* |
179 |
|
* @param state new state for this menu item |
180 |
* |
* |
|
* @param state DOCUMENT ME! |
|
181 |
*/ |
*/ |
182 |
public synchronized void setState(boolean state) |
public synchronized void setState(boolean state) |
183 |
{ |
{ |
185 |
} |
} |
186 |
|
|
187 |
/** |
/** |
188 |
* DOCUMENT ME! |
* This method returns array containing label of this |
189 |
|
* menu item if it is selected and null otherwise. |
190 |
* |
* |
191 |
* @return $returnType$ DOCUMENT ME! |
* @return Array containing label of this |
192 |
|
* menu item if this menu item is selected or null otherwise. |
193 |
*/ |
*/ |
194 |
public Object[] getSelectedObjects() |
public Object[] getSelectedObjects() |
195 |
{ |
{ |
196 |
|
if (state == true) |
197 |
|
selectedObjects[0] = this.getText(); |
198 |
|
else |
199 |
|
selectedObjects[0] = null; |
200 |
|
|
201 |
return selectedObjects; |
return selectedObjects; |
202 |
} |
} |
203 |
|
|
204 |
/** |
/** |
205 |
* DOCUMENT ME! |
* This method overrides JComponent.requestFocus with an empty |
206 |
|
* implementation, since JCheckBoxMenuItems should not |
207 |
|
* receve focus in general. |
208 |
*/ |
*/ |
209 |
public void requestFocus() |
public void requestFocus() |
210 |
{ |
{ |
211 |
// TODO |
// Should do nothing here |
212 |
} |
} |
213 |
|
|
214 |
/** |
/** |
215 |
* DOCUMENT ME! |
* A string that describes this JCheckBoxMenuItem. Normally only used |
216 |
|
* for debugging. |
217 |
* |
* |
218 |
* @return $returnType$ DOCUMENT ME! |
* @return A string describing this JCheckBoxMenuItem |
219 |
*/ |
*/ |
220 |
protected String paramString() |
protected String paramString() |
221 |
{ |
{ |
222 |
return "JCheckBoxMenuItem"; |
return "JCheckBoxMenuItem"; |
223 |
} |
} |
224 |
|
|
|
/** |
|
|
* DOCUMENT ME! |
|
|
* |
|
|
* @return $returnType$ DOCUMENT ME! |
|
|
*/ |
|
225 |
public AccessibleContext getAccessibleContext() |
public AccessibleContext getAccessibleContext() |
226 |
{ |
{ |
227 |
if (accessibleContext == null) |
if (accessibleContext == null) |
230 |
return accessibleContext; |
return accessibleContext; |
231 |
} |
} |
232 |
|
|
|
/** |
|
|
* DOCUMENT ME! |
|
|
*/ |
|
233 |
protected class AccessibleJCheckBoxMenuItem extends AccessibleJMenuItem |
protected class AccessibleJCheckBoxMenuItem extends AccessibleJMenuItem |
234 |
{ |
{ |
235 |
private static final long serialVersionUID = 1079958073579370777L; |
private static final long serialVersionUID = 1079958073579370777L; |
241 |
{ |
{ |
242 |
} |
} |
243 |
|
|
|
/** |
|
|
* DOCUMENT ME! |
|
|
* |
|
|
* @return $returnType$ DOCUMENT ME! |
|
|
*/ |
|
244 |
public AccessibleRole getAccessibleRole() |
public AccessibleRole getAccessibleRole() |
245 |
{ |
{ |
246 |
return AccessibleRole.CHECK_BOX; |
return AccessibleRole.CHECK_BOX; |