author | ohair |
Tue, 25 May 2010 15:58:33 -0700 | |
changeset 5506 | 202f599c92aa |
parent 3084 | 67ca55732362 |
child 8816 | 29f983feda95 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
5506 | 2 |
* Copyright (c) 1995, 2006, Oracle and/or its affiliates. All rights reserved. |
2 | 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 |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 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 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
package java.awt; |
|
26 |
||
27 |
import java.awt.peer.MenuComponentPeer; |
|
28 |
import java.awt.event.ActionEvent; |
|
29 |
import java.io.IOException; |
|
30 |
import java.io.ObjectInputStream; |
|
31 |
import sun.awt.AppContext; |
|
32 |
import sun.awt.SunToolkit; |
|
3084
67ca55732362
6824169: Need to remove some AWT class dependencies
dcherepanov
parents:
2
diff
changeset
|
33 |
import sun.awt.AWTAccessor; |
2 | 34 |
import javax.accessibility.*; |
35 |
||
36 |
/** |
|
37 |
* The abstract class <code>MenuComponent</code> is the superclass |
|
38 |
* of all menu-related components. In this respect, the class |
|
39 |
* <code>MenuComponent</code> is analogous to the abstract superclass |
|
40 |
* <code>Component</code> for AWT components. |
|
41 |
* <p> |
|
42 |
* Menu components receive and process AWT events, just as components do, |
|
43 |
* through the method <code>processEvent</code>. |
|
44 |
* |
|
45 |
* @author Arthur van Hoff |
|
46 |
* @since JDK1.0 |
|
47 |
*/ |
|
48 |
public abstract class MenuComponent implements java.io.Serializable { |
|
49 |
||
50 |
static { |
|
51 |
/* ensure that the necessary native libraries are loaded */ |
|
52 |
Toolkit.loadLibraries(); |
|
53 |
if (!GraphicsEnvironment.isHeadless()) { |
|
54 |
initIDs(); |
|
55 |
} |
|
56 |
} |
|
57 |
||
58 |
transient MenuComponentPeer peer; |
|
59 |
transient MenuContainer parent; |
|
60 |
||
61 |
/** |
|
62 |
* The <code>AppContext</code> of the <code>MenuComponent</code>. |
|
63 |
* This is set in the constructor and never changes. |
|
64 |
*/ |
|
65 |
transient AppContext appContext; |
|
66 |
||
67 |
/** |
|
68 |
* The menu component's font. This value can be |
|
69 |
* <code>null</code> at which point a default will be used. |
|
70 |
* This defaults to <code>null</code>. |
|
71 |
* |
|
72 |
* @serial |
|
73 |
* @see #setFont(Font) |
|
74 |
* @see #getFont() |
|
75 |
*/ |
|
76 |
Font font; |
|
77 |
||
78 |
/** |
|
79 |
* The menu component's name, which defaults to <code>null</code>. |
|
80 |
* @serial |
|
81 |
* @see #getName() |
|
82 |
* @see #setName(String) |
|
83 |
*/ |
|
84 |
private String name; |
|
85 |
||
86 |
/** |
|
87 |
* A variable to indicate whether a name is explicitly set. |
|
88 |
* If <code>true</code> the name will be set explicitly. |
|
89 |
* This defaults to <code>false</code>. |
|
90 |
* @serial |
|
91 |
* @see #setName(String) |
|
92 |
*/ |
|
93 |
private boolean nameExplicitlySet = false; |
|
94 |
||
95 |
/** |
|
96 |
* Defaults to <code>false</code>. |
|
97 |
* @serial |
|
98 |
* @see #dispatchEvent(AWTEvent) |
|
99 |
*/ |
|
100 |
boolean newEventsOnly = false; |
|
101 |
||
102 |
/* |
|
103 |
* Internal constants for serialization. |
|
104 |
*/ |
|
105 |
final static String actionListenerK = Component.actionListenerK; |
|
106 |
final static String itemListenerK = Component.itemListenerK; |
|
107 |
||
108 |
/* |
|
109 |
* JDK 1.1 serialVersionUID |
|
110 |
*/ |
|
111 |
private static final long serialVersionUID = -4536902356223894379L; |
|
112 |
||
3084
67ca55732362
6824169: Need to remove some AWT class dependencies
dcherepanov
parents:
2
diff
changeset
|
113 |
static { |
67ca55732362
6824169: Need to remove some AWT class dependencies
dcherepanov
parents:
2
diff
changeset
|
114 |
AWTAccessor.setMenuComponentAccessor( |
67ca55732362
6824169: Need to remove some AWT class dependencies
dcherepanov
parents:
2
diff
changeset
|
115 |
new AWTAccessor.MenuComponentAccessor() { |
67ca55732362
6824169: Need to remove some AWT class dependencies
dcherepanov
parents:
2
diff
changeset
|
116 |
public AppContext getAppContext(MenuComponent menuComp) { |
67ca55732362
6824169: Need to remove some AWT class dependencies
dcherepanov
parents:
2
diff
changeset
|
117 |
return menuComp.appContext; |
67ca55732362
6824169: Need to remove some AWT class dependencies
dcherepanov
parents:
2
diff
changeset
|
118 |
} |
67ca55732362
6824169: Need to remove some AWT class dependencies
dcherepanov
parents:
2
diff
changeset
|
119 |
public void setAppContext(MenuComponent menuComp, |
67ca55732362
6824169: Need to remove some AWT class dependencies
dcherepanov
parents:
2
diff
changeset
|
120 |
AppContext appContext) { |
67ca55732362
6824169: Need to remove some AWT class dependencies
dcherepanov
parents:
2
diff
changeset
|
121 |
menuComp.appContext = appContext; |
67ca55732362
6824169: Need to remove some AWT class dependencies
dcherepanov
parents:
2
diff
changeset
|
122 |
} |
67ca55732362
6824169: Need to remove some AWT class dependencies
dcherepanov
parents:
2
diff
changeset
|
123 |
public MenuContainer getParent(MenuComponent menuComp) { |
67ca55732362
6824169: Need to remove some AWT class dependencies
dcherepanov
parents:
2
diff
changeset
|
124 |
return menuComp.parent; |
67ca55732362
6824169: Need to remove some AWT class dependencies
dcherepanov
parents:
2
diff
changeset
|
125 |
} |
67ca55732362
6824169: Need to remove some AWT class dependencies
dcherepanov
parents:
2
diff
changeset
|
126 |
}); |
67ca55732362
6824169: Need to remove some AWT class dependencies
dcherepanov
parents:
2
diff
changeset
|
127 |
} |
67ca55732362
6824169: Need to remove some AWT class dependencies
dcherepanov
parents:
2
diff
changeset
|
128 |
|
2 | 129 |
/** |
130 |
* Creates a <code>MenuComponent</code>. |
|
131 |
* @exception HeadlessException if |
|
132 |
* <code>GraphicsEnvironment.isHeadless</code> |
|
133 |
* returns <code>true</code> |
|
134 |
* @see java.awt.GraphicsEnvironment#isHeadless |
|
135 |
*/ |
|
136 |
public MenuComponent() throws HeadlessException { |
|
137 |
GraphicsEnvironment.checkHeadless(); |
|
138 |
appContext = AppContext.getAppContext(); |
|
139 |
} |
|
140 |
||
141 |
/** |
|
142 |
* Constructs a name for this <code>MenuComponent</code>. |
|
143 |
* Called by <code>getName</code> when the name is <code>null</code>. |
|
144 |
* @return a name for this <code>MenuComponent</code> |
|
145 |
*/ |
|
146 |
String constructComponentName() { |
|
147 |
return null; // For strict compliance with prior platform versions, a MenuComponent |
|
148 |
// that doesn't set its name should return null from |
|
149 |
// getName() |
|
150 |
} |
|
151 |
||
152 |
/** |
|
153 |
* Gets the name of the menu component. |
|
154 |
* @return the name of the menu component |
|
155 |
* @see java.awt.MenuComponent#setName(java.lang.String) |
|
156 |
* @since JDK1.1 |
|
157 |
*/ |
|
158 |
public String getName() { |
|
159 |
if (name == null && !nameExplicitlySet) { |
|
160 |
synchronized(this) { |
|
161 |
if (name == null && !nameExplicitlySet) |
|
162 |
name = constructComponentName(); |
|
163 |
} |
|
164 |
} |
|
165 |
return name; |
|
166 |
} |
|
167 |
||
168 |
/** |
|
169 |
* Sets the name of the component to the specified string. |
|
170 |
* @param name the name of the menu component |
|
171 |
* @see java.awt.MenuComponent#getName |
|
172 |
* @since JDK1.1 |
|
173 |
*/ |
|
174 |
public void setName(String name) { |
|
175 |
synchronized(this) { |
|
176 |
this.name = name; |
|
177 |
nameExplicitlySet = true; |
|
178 |
} |
|
179 |
} |
|
180 |
||
181 |
/** |
|
182 |
* Returns the parent container for this menu component. |
|
183 |
* @return the menu component containing this menu component, |
|
184 |
* or <code>null</code> if this menu component |
|
185 |
* is the outermost component, the menu bar itself |
|
186 |
*/ |
|
187 |
public MenuContainer getParent() { |
|
188 |
return getParent_NoClientCode(); |
|
189 |
} |
|
190 |
// NOTE: This method may be called by privileged threads. |
|
191 |
// This functionality is implemented in a package-private method |
|
192 |
// to insure that it cannot be overridden by client subclasses. |
|
193 |
// DO NOT INVOKE CLIENT CODE ON THIS THREAD! |
|
194 |
final MenuContainer getParent_NoClientCode() { |
|
195 |
return parent; |
|
196 |
} |
|
197 |
||
198 |
/** |
|
199 |
* @deprecated As of JDK version 1.1, |
|
200 |
* programs should not directly manipulate peers. |
|
201 |
*/ |
|
202 |
@Deprecated |
|
203 |
public MenuComponentPeer getPeer() { |
|
204 |
return peer; |
|
205 |
} |
|
206 |
||
207 |
/** |
|
208 |
* Gets the font used for this menu component. |
|
209 |
* @return the font used in this menu component, if there is one; |
|
210 |
* <code>null</code> otherwise |
|
211 |
* @see java.awt.MenuComponent#setFont |
|
212 |
*/ |
|
213 |
public Font getFont() { |
|
214 |
Font font = this.font; |
|
215 |
if (font != null) { |
|
216 |
return font; |
|
217 |
} |
|
218 |
MenuContainer parent = this.parent; |
|
219 |
if (parent != null) { |
|
220 |
return parent.getFont(); |
|
221 |
} |
|
222 |
return null; |
|
223 |
} |
|
224 |
||
225 |
// NOTE: This method may be called by privileged threads. |
|
226 |
// This functionality is implemented in a package-private method |
|
227 |
// to insure that it cannot be overridden by client subclasses. |
|
228 |
// DO NOT INVOKE CLIENT CODE ON THIS THREAD! |
|
229 |
final Font getFont_NoClientCode() { |
|
230 |
Font font = this.font; |
|
231 |
if (font != null) { |
|
232 |
return font; |
|
233 |
} |
|
234 |
||
235 |
// The MenuContainer interface does not have getFont_NoClientCode() |
|
236 |
// and it cannot, because it must be package-private. Because of |
|
237 |
// this, we must manually cast classes that implement |
|
238 |
// MenuContainer. |
|
239 |
Object parent = this.parent; |
|
240 |
if (parent != null) { |
|
241 |
if (parent instanceof Component) { |
|
242 |
font = ((Component)parent).getFont_NoClientCode(); |
|
243 |
} else if (parent instanceof MenuComponent) { |
|
244 |
font = ((MenuComponent)parent).getFont_NoClientCode(); |
|
245 |
} |
|
246 |
} |
|
247 |
return font; |
|
248 |
} // getFont_NoClientCode() |
|
249 |
||
250 |
||
251 |
/** |
|
252 |
* Sets the font to be used for this menu component to the specified |
|
253 |
* font. This font is also used by all subcomponents of this menu |
|
254 |
* component, unless those subcomponents specify a different font. |
|
255 |
* <p> |
|
256 |
* Some platforms may not support setting of all font attributes |
|
257 |
* of a menu component; in such cases, calling <code>setFont</code> |
|
258 |
* will have no effect on the unsupported font attributes of this |
|
259 |
* menu component. Unless subcomponents of this menu component |
|
260 |
* specify a different font, this font will be used by those |
|
261 |
* subcomponents if supported by the underlying platform. |
|
262 |
* |
|
263 |
* @param f the font to be set |
|
264 |
* @see #getFont |
|
265 |
* @see Font#getAttributes |
|
266 |
* @see java.awt.font.TextAttribute |
|
267 |
*/ |
|
268 |
public void setFont(Font f) { |
|
269 |
font = f; |
|
270 |
//Fixed 6312943: NullPointerException in method MenuComponent.setFont(Font) |
|
271 |
MenuComponentPeer peer = (MenuComponentPeer)this.peer; |
|
272 |
if (peer != null) { |
|
273 |
peer.setFont(f); |
|
274 |
} |
|
275 |
} |
|
276 |
||
277 |
/** |
|
278 |
* Removes the menu component's peer. The peer allows us to modify the |
|
279 |
* appearance of the menu component without changing the functionality of |
|
280 |
* the menu component. |
|
281 |
*/ |
|
282 |
public void removeNotify() { |
|
283 |
synchronized (getTreeLock()) { |
|
284 |
MenuComponentPeer p = (MenuComponentPeer)this.peer; |
|
285 |
if (p != null) { |
|
286 |
Toolkit.getEventQueue().removeSourceEvents(this, true); |
|
287 |
this.peer = null; |
|
288 |
p.dispose(); |
|
289 |
} |
|
290 |
} |
|
291 |
} |
|
292 |
||
293 |
/** |
|
294 |
* Posts the specified event to the menu. |
|
295 |
* This method is part of the Java 1.0 event system |
|
296 |
* and it is maintained only for backwards compatibility. |
|
297 |
* Its use is discouraged, and it may not be supported |
|
298 |
* in the future. |
|
299 |
* @param evt the event which is to take place |
|
300 |
* @deprecated As of JDK version 1.1, replaced by {@link |
|
301 |
* #dispatchEvent(AWTEvent) dispatchEvent}. |
|
302 |
*/ |
|
303 |
@Deprecated |
|
304 |
public boolean postEvent(Event evt) { |
|
305 |
MenuContainer parent = this.parent; |
|
306 |
if (parent != null) { |
|
307 |
parent.postEvent(evt); |
|
308 |
} |
|
309 |
return false; |
|
310 |
} |
|
311 |
||
312 |
/** |
|
313 |
* Delivers an event to this component or one of its sub components. |
|
314 |
* @param e the event |
|
315 |
*/ |
|
316 |
public final void dispatchEvent(AWTEvent e) { |
|
317 |
dispatchEventImpl(e); |
|
318 |
} |
|
319 |
||
320 |
void dispatchEventImpl(AWTEvent e) { |
|
321 |
EventQueue.setCurrentEventAndMostRecentTime(e); |
|
322 |
||
323 |
Toolkit.getDefaultToolkit().notifyAWTEventListeners(e); |
|
324 |
||
325 |
if (newEventsOnly || |
|
326 |
(parent != null && parent instanceof MenuComponent && |
|
327 |
((MenuComponent)parent).newEventsOnly)) { |
|
328 |
if (eventEnabled(e)) { |
|
329 |
processEvent(e); |
|
330 |
} else if (e instanceof ActionEvent && parent != null) { |
|
331 |
e.setSource(parent); |
|
332 |
((MenuComponent)parent).dispatchEvent(e); |
|
333 |
} |
|
334 |
||
335 |
} else { // backward compatibility |
|
336 |
Event olde = e.convertToOld(); |
|
337 |
if (olde != null) { |
|
338 |
postEvent(olde); |
|
339 |
} |
|
340 |
} |
|
341 |
} |
|
342 |
||
343 |
// REMIND: remove when filtering is done at lower level |
|
344 |
boolean eventEnabled(AWTEvent e) { |
|
345 |
return false; |
|
346 |
} |
|
347 |
/** |
|
348 |
* Processes events occurring on this menu component. |
|
349 |
* <p>Note that if the event parameter is <code>null</code> |
|
350 |
* the behavior is unspecified and may result in an |
|
351 |
* exception. |
|
352 |
* |
|
353 |
* @param e the event |
|
354 |
* @since JDK1.1 |
|
355 |
*/ |
|
356 |
protected void processEvent(AWTEvent e) { |
|
357 |
} |
|
358 |
||
359 |
/** |
|
360 |
* Returns a string representing the state of this |
|
361 |
* <code>MenuComponent</code>. This method is intended to be used |
|
362 |
* only for debugging purposes, and the content and format of the |
|
363 |
* returned string may vary between implementations. The returned |
|
364 |
* string may be empty but may not be <code>null</code>. |
|
365 |
* |
|
366 |
* @return the parameter string of this menu component |
|
367 |
*/ |
|
368 |
protected String paramString() { |
|
369 |
String thisName = getName(); |
|
370 |
return (thisName != null? thisName : ""); |
|
371 |
} |
|
372 |
||
373 |
/** |
|
374 |
* Returns a representation of this menu component as a string. |
|
375 |
* @return a string representation of this menu component |
|
376 |
*/ |
|
377 |
public String toString() { |
|
378 |
return getClass().getName() + "[" + paramString() + "]"; |
|
379 |
} |
|
380 |
||
381 |
/** |
|
382 |
* Gets this component's locking object (the object that owns the thread |
|
383 |
* sychronization monitor) for AWT component-tree and layout |
|
384 |
* operations. |
|
385 |
* @return this component's locking object |
|
386 |
*/ |
|
387 |
protected final Object getTreeLock() { |
|
388 |
return Component.LOCK; |
|
389 |
} |
|
390 |
||
391 |
/** |
|
392 |
* Reads the menu component from an object input stream. |
|
393 |
* |
|
394 |
* @param s the <code>ObjectInputStream</code> to read |
|
395 |
* @exception HeadlessException if |
|
396 |
* <code>GraphicsEnvironment.isHeadless</code> returns |
|
397 |
* <code>true</code> |
|
398 |
* @serial |
|
399 |
* @see java.awt.GraphicsEnvironment#isHeadless |
|
400 |
*/ |
|
401 |
private void readObject(ObjectInputStream s) |
|
402 |
throws ClassNotFoundException, IOException, HeadlessException |
|
403 |
{ |
|
404 |
GraphicsEnvironment.checkHeadless(); |
|
405 |
s.defaultReadObject(); |
|
406 |
||
407 |
appContext = AppContext.getAppContext(); |
|
408 |
} |
|
409 |
||
410 |
/** |
|
411 |
* Initialize JNI field and method IDs. |
|
412 |
*/ |
|
413 |
private static native void initIDs(); |
|
414 |
||
415 |
||
416 |
/* |
|
417 |
* --- Accessibility Support --- |
|
418 |
* |
|
419 |
* MenuComponent will contain all of the methods in interface Accessible, |
|
420 |
* though it won't actually implement the interface - that will be up |
|
421 |
* to the individual objects which extend MenuComponent. |
|
422 |
*/ |
|
423 |
||
424 |
AccessibleContext accessibleContext = null; |
|
425 |
||
426 |
/** |
|
427 |
* Gets the <code>AccessibleContext</code> associated with |
|
428 |
* this <code>MenuComponent</code>. |
|
429 |
* |
|
430 |
* The method implemented by this base class returns <code>null</code>. |
|
431 |
* Classes that extend <code>MenuComponent</code> |
|
432 |
* should implement this method to return the |
|
433 |
* <code>AccessibleContext</code> associated with the subclass. |
|
434 |
* |
|
435 |
* @return the <code>AccessibleContext</code> of this |
|
436 |
* <code>MenuComponent</code> |
|
437 |
* @since 1.3 |
|
438 |
*/ |
|
439 |
public AccessibleContext getAccessibleContext() { |
|
440 |
return accessibleContext; |
|
441 |
} |
|
442 |
||
443 |
/** |
|
444 |
* Inner class of <code>MenuComponent</code> used to provide |
|
445 |
* default support for accessibility. This class is not meant |
|
446 |
* to be used directly by application developers, but is instead |
|
447 |
* meant only to be subclassed by menu component developers. |
|
448 |
* <p> |
|
449 |
* The class used to obtain the accessible role for this object. |
|
450 |
* @since 1.3 |
|
451 |
*/ |
|
452 |
protected abstract class AccessibleAWTMenuComponent |
|
453 |
extends AccessibleContext |
|
454 |
implements java.io.Serializable, AccessibleComponent, |
|
455 |
AccessibleSelection |
|
456 |
{ |
|
457 |
/* |
|
458 |
* JDK 1.3 serialVersionUID |
|
459 |
*/ |
|
460 |
private static final long serialVersionUID = -4269533416223798698L; |
|
461 |
||
462 |
/** |
|
463 |
* Although the class is abstract, this should be called by |
|
464 |
* all sub-classes. |
|
465 |
*/ |
|
466 |
protected AccessibleAWTMenuComponent() { |
|
467 |
} |
|
468 |
||
469 |
// AccessibleContext methods |
|
470 |
// |
|
471 |
||
472 |
/** |
|
473 |
* Gets the <code>AccessibleSelection</code> associated with this |
|
474 |
* object which allows its <code>Accessible</code> children to be selected. |
|
475 |
* |
|
476 |
* @return <code>AccessibleSelection</code> if supported by object; |
|
477 |
* else return <code>null</code> |
|
478 |
* @see AccessibleSelection |
|
479 |
*/ |
|
480 |
public AccessibleSelection getAccessibleSelection() { |
|
481 |
return this; |
|
482 |
} |
|
483 |
||
484 |
/** |
|
485 |
* Gets the accessible name of this object. This should almost never |
|
486 |
* return <code>java.awt.MenuComponent.getName</code>, as that |
|
487 |
* generally isn't a localized name, and doesn't have meaning for the |
|
488 |
* user. If the object is fundamentally a text object (e.g. a menu item), the |
|
489 |
* accessible name should be the text of the object (e.g. "save"). |
|
490 |
* If the object has a tooltip, the tooltip text may also be an |
|
491 |
* appropriate String to return. |
|
492 |
* |
|
493 |
* @return the localized name of the object -- can be <code>null</code> |
|
494 |
* if this object does not have a name |
|
495 |
* @see AccessibleContext#setAccessibleName |
|
496 |
*/ |
|
497 |
public String getAccessibleName() { |
|
498 |
return accessibleName; |
|
499 |
} |
|
500 |
||
501 |
/** |
|
502 |
* Gets the accessible description of this object. This should be |
|
503 |
* a concise, localized description of what this object is - what |
|
504 |
* is its meaning to the user. If the object has a tooltip, the |
|
505 |
* tooltip text may be an appropriate string to return, assuming |
|
506 |
* it contains a concise description of the object (instead of just |
|
507 |
* the name of the object - e.g. a "Save" icon on a toolbar that |
|
508 |
* had "save" as the tooltip text shouldn't return the tooltip |
|
509 |
* text as the description, but something like "Saves the current |
|
510 |
* text document" instead). |
|
511 |
* |
|
512 |
* @return the localized description of the object -- can be |
|
513 |
* <code>null</code> if this object does not have a description |
|
514 |
* @see AccessibleContext#setAccessibleDescription |
|
515 |
*/ |
|
516 |
public String getAccessibleDescription() { |
|
517 |
return accessibleDescription; |
|
518 |
} |
|
519 |
||
520 |
/** |
|
521 |
* Gets the role of this object. |
|
522 |
* |
|
523 |
* @return an instance of <code>AccessibleRole</code> |
|
524 |
* describing the role of the object |
|
525 |
* @see AccessibleRole |
|
526 |
*/ |
|
527 |
public AccessibleRole getAccessibleRole() { |
|
528 |
return AccessibleRole.AWT_COMPONENT; // Non-specific -- overridden in subclasses |
|
529 |
} |
|
530 |
||
531 |
/** |
|
532 |
* Gets the state of this object. |
|
533 |
* |
|
534 |
* @return an instance of <code>AccessibleStateSet</code> |
|
535 |
* containing the current state set of the object |
|
536 |
* @see AccessibleState |
|
537 |
*/ |
|
538 |
public AccessibleStateSet getAccessibleStateSet() { |
|
539 |
return MenuComponent.this.getAccessibleStateSet(); |
|
540 |
} |
|
541 |
||
542 |
/** |
|
543 |
* Gets the <code>Accessible</code> parent of this object. |
|
544 |
* If the parent of this object implements <code>Accessible</code>, |
|
545 |
* this method should simply return <code>getParent</code>. |
|
546 |
* |
|
547 |
* @return the <code>Accessible</code> parent of this object -- can |
|
548 |
* be <code>null</code> if this object does not have an |
|
549 |
* <code>Accessible</code> parent |
|
550 |
*/ |
|
551 |
public Accessible getAccessibleParent() { |
|
552 |
if (accessibleParent != null) { |
|
553 |
return accessibleParent; |
|
554 |
} else { |
|
555 |
MenuContainer parent = MenuComponent.this.getParent(); |
|
556 |
if (parent instanceof Accessible) { |
|
557 |
return (Accessible) parent; |
|
558 |
} |
|
559 |
} |
|
560 |
return null; |
|
561 |
} |
|
562 |
||
563 |
/** |
|
564 |
* Gets the index of this object in its accessible parent. |
|
565 |
* |
|
566 |
* @return the index of this object in its parent; -1 if this |
|
567 |
* object does not have an accessible parent |
|
568 |
* @see #getAccessibleParent |
|
569 |
*/ |
|
570 |
public int getAccessibleIndexInParent() { |
|
571 |
return MenuComponent.this.getAccessibleIndexInParent(); |
|
572 |
} |
|
573 |
||
574 |
/** |
|
575 |
* Returns the number of accessible children in the object. If all |
|
576 |
* of the children of this object implement <code>Accessible</code>, |
|
577 |
* then this method should return the number of children of this object. |
|
578 |
* |
|
579 |
* @return the number of accessible children in the object |
|
580 |
*/ |
|
581 |
public int getAccessibleChildrenCount() { |
|
582 |
return 0; // MenuComponents don't have children |
|
583 |
} |
|
584 |
||
585 |
/** |
|
586 |
* Returns the nth <code>Accessible</code> child of the object. |
|
587 |
* |
|
588 |
* @param i zero-based index of child |
|
589 |
* @return the nth Accessible child of the object |
|
590 |
*/ |
|
591 |
public Accessible getAccessibleChild(int i) { |
|
592 |
return null; // MenuComponents don't have children |
|
593 |
} |
|
594 |
||
595 |
/** |
|
596 |
* Returns the locale of this object. |
|
597 |
* |
|
598 |
* @return the locale of this object |
|
599 |
*/ |
|
600 |
public java.util.Locale getLocale() { |
|
601 |
MenuContainer parent = MenuComponent.this.getParent(); |
|
602 |
if (parent instanceof Component) |
|
603 |
return ((Component)parent).getLocale(); |
|
604 |
else |
|
605 |
return java.util.Locale.getDefault(); |
|
606 |
} |
|
607 |
||
608 |
/** |
|
609 |
* Gets the <code>AccessibleComponent</code> associated with |
|
610 |
* this object if one exists. Otherwise return <code>null</code>. |
|
611 |
* |
|
612 |
* @return the component |
|
613 |
*/ |
|
614 |
public AccessibleComponent getAccessibleComponent() { |
|
615 |
return this; |
|
616 |
} |
|
617 |
||
618 |
||
619 |
// AccessibleComponent methods |
|
620 |
// |
|
621 |
/** |
|
622 |
* Gets the background color of this object. |
|
623 |
* |
|
624 |
* @return the background color, if supported, of the object; |
|
625 |
* otherwise, <code>null</code> |
|
626 |
*/ |
|
627 |
public Color getBackground() { |
|
628 |
return null; // Not supported for MenuComponents |
|
629 |
} |
|
630 |
||
631 |
/** |
|
632 |
* Sets the background color of this object. |
|
633 |
* (For transparency, see <code>isOpaque</code>.) |
|
634 |
* |
|
635 |
* @param c the new <code>Color</code> for the background |
|
636 |
* @see Component#isOpaque |
|
637 |
*/ |
|
638 |
public void setBackground(Color c) { |
|
639 |
// Not supported for MenuComponents |
|
640 |
} |
|
641 |
||
642 |
/** |
|
643 |
* Gets the foreground color of this object. |
|
644 |
* |
|
645 |
* @return the foreground color, if supported, of the object; |
|
646 |
* otherwise, <code>null</code> |
|
647 |
*/ |
|
648 |
public Color getForeground() { |
|
649 |
return null; // Not supported for MenuComponents |
|
650 |
} |
|
651 |
||
652 |
/** |
|
653 |
* Sets the foreground color of this object. |
|
654 |
* |
|
655 |
* @param c the new <code>Color</code> for the foreground |
|
656 |
*/ |
|
657 |
public void setForeground(Color c) { |
|
658 |
// Not supported for MenuComponents |
|
659 |
} |
|
660 |
||
661 |
/** |
|
662 |
* Gets the <code>Cursor</code> of this object. |
|
663 |
* |
|
664 |
* @return the <code>Curso</code>, if supported, of the object; |
|
665 |
* otherwise, <code>null</code> |
|
666 |
*/ |
|
667 |
public Cursor getCursor() { |
|
668 |
return null; // Not supported for MenuComponents |
|
669 |
} |
|
670 |
||
671 |
/** |
|
672 |
* Sets the <code>Cursor</code> of this object. |
|
673 |
* <p> |
|
674 |
* The method may have no visual effect if the Java platform |
|
675 |
* implementation and/or the native system do not support |
|
676 |
* changing the mouse cursor shape. |
|
677 |
* @param cursor the new <code>Cursor</code> for the object |
|
678 |
*/ |
|
679 |
public void setCursor(Cursor cursor) { |
|
680 |
// Not supported for MenuComponents |
|
681 |
} |
|
682 |
||
683 |
/** |
|
684 |
* Gets the <code>Font</code> of this object. |
|
685 |
* |
|
686 |
* @return the <code>Font</code>,if supported, for the object; |
|
687 |
* otherwise, <code>null</code> |
|
688 |
*/ |
|
689 |
public Font getFont() { |
|
690 |
return MenuComponent.this.getFont(); |
|
691 |
} |
|
692 |
||
693 |
/** |
|
694 |
* Sets the <code>Font</code> of this object. |
|
695 |
* |
|
696 |
* @param f the new <code>Font</code> for the object |
|
697 |
*/ |
|
698 |
public void setFont(Font f) { |
|
699 |
MenuComponent.this.setFont(f); |
|
700 |
} |
|
701 |
||
702 |
/** |
|
703 |
* Gets the <code>FontMetrics</code> of this object. |
|
704 |
* |
|
705 |
* @param f the <code>Font</code> |
|
706 |
* @return the FontMetrics, if supported, the object; |
|
707 |
* otherwise, <code>null</code> |
|
708 |
* @see #getFont |
|
709 |
*/ |
|
710 |
public FontMetrics getFontMetrics(Font f) { |
|
711 |
return null; // Not supported for MenuComponents |
|
712 |
} |
|
713 |
||
714 |
/** |
|
715 |
* Determines if the object is enabled. |
|
716 |
* |
|
717 |
* @return true if object is enabled; otherwise, false |
|
718 |
*/ |
|
719 |
public boolean isEnabled() { |
|
720 |
return true; // Not supported for MenuComponents |
|
721 |
} |
|
722 |
||
723 |
/** |
|
724 |
* Sets the enabled state of the object. |
|
725 |
* |
|
726 |
* @param b if true, enables this object; otherwise, disables it |
|
727 |
*/ |
|
728 |
public void setEnabled(boolean b) { |
|
729 |
// Not supported for MenuComponents |
|
730 |
} |
|
731 |
||
732 |
/** |
|
733 |
* Determines if the object is visible. Note: this means that the |
|
734 |
* object intends to be visible; however, it may not in fact be |
|
735 |
* showing on the screen because one of the objects that this object |
|
736 |
* is contained by is not visible. To determine if an object is |
|
737 |
* showing on the screen, use <code>isShowing</code>. |
|
738 |
* |
|
739 |
* @return true if object is visible; otherwise, false |
|
740 |
*/ |
|
741 |
public boolean isVisible() { |
|
742 |
return true; // Not supported for MenuComponents |
|
743 |
} |
|
744 |
||
745 |
/** |
|
746 |
* Sets the visible state of the object. |
|
747 |
* |
|
748 |
* @param b if true, shows this object; otherwise, hides it |
|
749 |
*/ |
|
750 |
public void setVisible(boolean b) { |
|
751 |
// Not supported for MenuComponents |
|
752 |
} |
|
753 |
||
754 |
/** |
|
755 |
* Determines if the object is showing. This is determined by checking |
|
756 |
* the visibility of the object and ancestors of the object. Note: |
|
757 |
* this will return true even if the object is obscured by another |
|
758 |
* (for example, it happens to be underneath a menu that was pulled |
|
759 |
* down). |
|
760 |
* |
|
761 |
* @return true if object is showing; otherwise, false |
|
762 |
*/ |
|
763 |
public boolean isShowing() { |
|
764 |
return true; // Not supported for MenuComponents |
|
765 |
} |
|
766 |
||
767 |
/** |
|
768 |
* Checks whether the specified point is within this object's bounds, |
|
769 |
* where the point's x and y coordinates are defined to be relative to |
|
770 |
* the coordinate system of the object. |
|
771 |
* |
|
772 |
* @param p the <code>Point</code> relative to the coordinate |
|
773 |
* system of the object |
|
774 |
* @return true if object contains <code>Point</code>; otherwise false |
|
775 |
*/ |
|
776 |
public boolean contains(Point p) { |
|
777 |
return false; // Not supported for MenuComponents |
|
778 |
} |
|
779 |
||
780 |
/** |
|
781 |
* Returns the location of the object on the screen. |
|
782 |
* |
|
783 |
* @return location of object on screen -- can be <code>null</code> |
|
784 |
* if this object is not on the screen |
|
785 |
*/ |
|
786 |
public Point getLocationOnScreen() { |
|
787 |
return null; // Not supported for MenuComponents |
|
788 |
} |
|
789 |
||
790 |
/** |
|
791 |
* Gets the location of the object relative to the parent in the form |
|
792 |
* of a point specifying the object's top-left corner in the screen's |
|
793 |
* coordinate space. |
|
794 |
* |
|
795 |
* @return an instance of <code>Point</code> representing the |
|
796 |
* top-left corner of the object's bounds in the coordinate |
|
797 |
* space of the screen; <code>null</code> if |
|
798 |
* this object or its parent are not on the screen |
|
799 |
*/ |
|
800 |
public Point getLocation() { |
|
801 |
return null; // Not supported for MenuComponents |
|
802 |
} |
|
803 |
||
804 |
/** |
|
805 |
* Sets the location of the object relative to the parent. |
|
806 |
*/ |
|
807 |
public void setLocation(Point p) { |
|
808 |
// Not supported for MenuComponents |
|
809 |
} |
|
810 |
||
811 |
/** |
|
812 |
* Gets the bounds of this object in the form of a |
|
813 |
* <code>Rectangle</code> object. |
|
814 |
* The bounds specify this object's width, height, and location |
|
815 |
* relative to its parent. |
|
816 |
* |
|
817 |
* @return a rectangle indicating this component's bounds; |
|
818 |
* <code>null</code> if this object is not on the screen |
|
819 |
*/ |
|
820 |
public Rectangle getBounds() { |
|
821 |
return null; // Not supported for MenuComponents |
|
822 |
} |
|
823 |
||
824 |
/** |
|
825 |
* Sets the bounds of this object in the form of a |
|
826 |
* <code>Rectangle</code> object. |
|
827 |
* The bounds specify this object's width, height, and location |
|
828 |
* relative to its parent. |
|
829 |
* |
|
830 |
* @param r a rectangle indicating this component's bounds |
|
831 |
*/ |
|
832 |
public void setBounds(Rectangle r) { |
|
833 |
// Not supported for MenuComponents |
|
834 |
} |
|
835 |
||
836 |
/** |
|
837 |
* Returns the size of this object in the form of a |
|
838 |
* <code>Dimension</code> object. The height field of |
|
839 |
* the <code>Dimension</code> object contains this object's |
|
840 |
* height, and the width field of the <code>Dimension</code> |
|
841 |
* object contains this object's width. |
|
842 |
* |
|
843 |
* @return a <code>Dimension</code> object that indicates the |
|
844 |
* size of this component; <code>null</code> |
|
845 |
* if this object is not on the screen |
|
846 |
*/ |
|
847 |
public Dimension getSize() { |
|
848 |
return null; // Not supported for MenuComponents |
|
849 |
} |
|
850 |
||
851 |
/** |
|
852 |
* Resizes this object. |
|
853 |
* |
|
854 |
* @param d - the <code>Dimension</code> specifying the |
|
855 |
* new size of the object |
|
856 |
*/ |
|
857 |
public void setSize(Dimension d) { |
|
858 |
// Not supported for MenuComponents |
|
859 |
} |
|
860 |
||
861 |
/** |
|
862 |
* Returns the <code>Accessible</code> child, if one exists, |
|
863 |
* contained at the local coordinate <code>Point</code>. |
|
864 |
* If there is no <code>Accessible</code> child, <code>null</code> |
|
865 |
* is returned. |
|
866 |
* |
|
867 |
* @param p the point defining the top-left corner of the |
|
868 |
* <code>Accessible</code>, given in the coordinate space |
|
869 |
* of the object's parent |
|
870 |
* @return the <code>Accessible</code>, if it exists, |
|
871 |
* at the specified location; else <code>null</code> |
|
872 |
*/ |
|
873 |
public Accessible getAccessibleAt(Point p) { |
|
874 |
return null; // MenuComponents don't have children |
|
875 |
} |
|
876 |
||
877 |
/** |
|
878 |
* Returns whether this object can accept focus or not. |
|
879 |
* |
|
880 |
* @return true if object can accept focus; otherwise false |
|
881 |
*/ |
|
882 |
public boolean isFocusTraversable() { |
|
883 |
return true; // Not supported for MenuComponents |
|
884 |
} |
|
885 |
||
886 |
/** |
|
887 |
* Requests focus for this object. |
|
888 |
*/ |
|
889 |
public void requestFocus() { |
|
890 |
// Not supported for MenuComponents |
|
891 |
} |
|
892 |
||
893 |
/** |
|
894 |
* Adds the specified focus listener to receive focus events from this |
|
895 |
* component. |
|
896 |
* |
|
897 |
* @param l the focus listener |
|
898 |
*/ |
|
899 |
public void addFocusListener(java.awt.event.FocusListener l) { |
|
900 |
// Not supported for MenuComponents |
|
901 |
} |
|
902 |
||
903 |
/** |
|
904 |
* Removes the specified focus listener so it no longer receives focus |
|
905 |
* events from this component. |
|
906 |
* |
|
907 |
* @param l the focus listener |
|
908 |
*/ |
|
909 |
public void removeFocusListener(java.awt.event.FocusListener l) { |
|
910 |
// Not supported for MenuComponents |
|
911 |
} |
|
912 |
||
913 |
// AccessibleSelection methods |
|
914 |
// |
|
915 |
||
916 |
/** |
|
917 |
* Returns the number of <code>Accessible</code> children currently selected. |
|
918 |
* If no children are selected, the return value will be 0. |
|
919 |
* |
|
920 |
* @return the number of items currently selected |
|
921 |
*/ |
|
922 |
public int getAccessibleSelectionCount() { |
|
923 |
return 0; // To be fully implemented in a future release |
|
924 |
} |
|
925 |
||
926 |
/** |
|
927 |
* Returns an <code>Accessible</code> representing the specified |
|
928 |
* selected child in the object. If there isn't a selection, or there are |
|
929 |
* fewer children selected than the integer passed in, the return |
|
930 |
* value will be <code>null</code>. |
|
931 |
* <p>Note that the index represents the i-th selected child, which |
|
932 |
* is different from the i-th child. |
|
933 |
* |
|
934 |
* @param i the zero-based index of selected children |
|
935 |
* @return the i-th selected child |
|
936 |
* @see #getAccessibleSelectionCount |
|
937 |
*/ |
|
938 |
public Accessible getAccessibleSelection(int i) { |
|
939 |
return null; // To be fully implemented in a future release |
|
940 |
} |
|
941 |
||
942 |
/** |
|
943 |
* Determines if the current child of this object is selected. |
|
944 |
* |
|
945 |
* @return true if the current child of this object is selected; |
|
946 |
* else false |
|
947 |
* @param i the zero-based index of the child in this |
|
948 |
* <code>Accessible</code> object |
|
949 |
* @see AccessibleContext#getAccessibleChild |
|
950 |
*/ |
|
951 |
public boolean isAccessibleChildSelected(int i) { |
|
952 |
return false; // To be fully implemented in a future release |
|
953 |
} |
|
954 |
||
955 |
/** |
|
956 |
* Adds the specified <code>Accessible</code> child of the object |
|
957 |
* to the object's selection. If the object supports multiple selections, |
|
958 |
* the specified child is added to any existing selection, otherwise |
|
959 |
* it replaces any existing selection in the object. If the |
|
960 |
* specified child is already selected, this method has no effect. |
|
961 |
* |
|
962 |
* @param i the zero-based index of the child |
|
963 |
* @see AccessibleContext#getAccessibleChild |
|
964 |
*/ |
|
965 |
public void addAccessibleSelection(int i) { |
|
966 |
// To be fully implemented in a future release |
|
967 |
} |
|
968 |
||
969 |
/** |
|
970 |
* Removes the specified child of the object from the object's |
|
971 |
* selection. If the specified item isn't currently selected, this |
|
972 |
* method has no effect. |
|
973 |
* |
|
974 |
* @param i the zero-based index of the child |
|
975 |
* @see AccessibleContext#getAccessibleChild |
|
976 |
*/ |
|
977 |
public void removeAccessibleSelection(int i) { |
|
978 |
// To be fully implemented in a future release |
|
979 |
} |
|
980 |
||
981 |
/** |
|
982 |
* Clears the selection in the object, so that no children in the |
|
983 |
* object are selected. |
|
984 |
*/ |
|
985 |
public void clearAccessibleSelection() { |
|
986 |
// To be fully implemented in a future release |
|
987 |
} |
|
988 |
||
989 |
/** |
|
990 |
* Causes every child of the object to be selected |
|
991 |
* if the object supports multiple selections. |
|
992 |
*/ |
|
993 |
public void selectAllAccessibleSelection() { |
|
994 |
// To be fully implemented in a future release |
|
995 |
} |
|
996 |
||
997 |
} // inner class AccessibleAWTComponent |
|
998 |
||
999 |
/** |
|
1000 |
* Gets the index of this object in its accessible parent. |
|
1001 |
* |
|
1002 |
* @return -1 if this object does not have an accessible parent; |
|
1003 |
* otherwise, the index of the child in its accessible parent. |
|
1004 |
*/ |
|
1005 |
int getAccessibleIndexInParent() { |
|
1006 |
MenuContainer localParent = parent; |
|
1007 |
if (!(localParent instanceof MenuComponent)) { |
|
1008 |
// MenuComponents only have accessible index when inside MenuComponents |
|
1009 |
return -1; |
|
1010 |
} |
|
1011 |
MenuComponent localParentMenu = (MenuComponent)localParent; |
|
1012 |
return localParentMenu.getAccessibleChildIndex(this); |
|
1013 |
} |
|
1014 |
||
1015 |
/** |
|
1016 |
* Gets the index of the child within this MenuComponent. |
|
1017 |
* |
|
1018 |
* @param child MenuComponent whose index we are interested in. |
|
1019 |
* @return -1 if this object doesn't contain the child, |
|
1020 |
* otherwise, index of the child. |
|
1021 |
*/ |
|
1022 |
int getAccessibleChildIndex(MenuComponent child) { |
|
1023 |
return -1; // Overridden in subclasses. |
|
1024 |
} |
|
1025 |
||
1026 |
/** |
|
1027 |
* Gets the state of this object. |
|
1028 |
* |
|
1029 |
* @return an instance of <code>AccessibleStateSet</code> |
|
1030 |
* containing the current state set of the object |
|
1031 |
* @see AccessibleState |
|
1032 |
*/ |
|
1033 |
AccessibleStateSet getAccessibleStateSet() { |
|
1034 |
AccessibleStateSet states = new AccessibleStateSet(); |
|
1035 |
return states; |
|
1036 |
} |
|
1037 |
||
1038 |
} |