KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > java > awt > MenuComponent


1 /*
2  * @(#)MenuComponent.java 1.77 04/05/18
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7 package java.awt;
8
9 import java.awt.peer.MenuComponentPeer;
10 import java.awt.event.ActionEvent JavaDoc;
11 import java.io.IOException JavaDoc;
12 import java.io.ObjectInputStream JavaDoc;
13 import sun.awt.AppContext;
14 import sun.awt.SunToolkit;
15 import javax.accessibility.*;
16
17 /**
18  * The abstract class <code>MenuComponent</code> is the superclass
19  * of all menu-related components. In this respect, the class
20  * <code>MenuComponent</code> is analogous to the abstract superclass
21  * <code>Component</code> for AWT components.
22  * <p>
23  * Menu components receive and process AWT events, just as components do,
24  * through the method <code>processEvent</code>.
25  *
26  * @version 1.77, 05/18/04
27  * @author Arthur van Hoff
28  * @since JDK1.0
29  */

30 public abstract class MenuComponent implements java.io.Serializable JavaDoc {
31
32     static {
33         /* ensure that the necessary native libraries are loaded */
34     Toolkit.loadLibraries();
35         if (!GraphicsEnvironment.isHeadless()) {
36             initIDs();
37         }
38     }
39
40     transient MenuComponentPeer peer;
41     transient MenuContainer JavaDoc parent;
42
43     /**
44      * The <code>AppContext</code> of the <code>MenuComponent</code>.
45      * This is set in the constructor and never changes.
46      */

47     transient AppContext appContext;
48
49     /**
50      * The menu component's font. This value can be
51      * <code>null</code> at which point a default will be used.
52      * This defaults to <code>null</code>.
53      *
54      * @serial
55      * @see #setFont(Font)
56      * @see #getFont()
57      */

58     Font JavaDoc font;
59
60     /**
61      * The menu component's name, which defaults to <code>null</code>.
62      * @serial
63      * @see #getName()
64      * @see #setName(String)
65      */

66     private String JavaDoc name;
67
68     /**
69      * A variable to indicate whether a name is explicitly set.
70      * If <code>true</code> the name will be set explicitly.
71      * This defaults to <code>false</code>.
72      * @serial
73      * @see #setName(String)
74      */

75     private boolean nameExplicitlySet = false;
76
77     /**
78      * Defaults to <code>false</code>.
79      * @serial
80      * @see #dispatchEvent(AWTEvent)
81      */

82     boolean newEventsOnly = false;
83  
84     /*
85      * Internal constants for serialization.
86      */

87     final static String JavaDoc actionListenerK = Component.actionListenerK;
88     final static String JavaDoc itemListenerK = Component.itemListenerK;
89
90     /*
91      * JDK 1.1 serialVersionUID
92      */

93     private static final long serialVersionUID = -4536902356223894379L;
94
95     /**
96      * This object is used as a key for internal hashtables.
97      */

98     transient private Object JavaDoc privateKey = new Object JavaDoc();
99
100     /**
101      * Creates a <code>MenuComponent</code>.
102      * @exception HeadlessException if
103      * <code>GraphicsEnvironment.isHeadless</code>
104      * returns <code>true</code>
105      * @see java.awt.GraphicsEnvironment#isHeadless
106      */

107     public MenuComponent() throws HeadlessException JavaDoc {
108         GraphicsEnvironment.checkHeadless();
109     appContext = AppContext.getAppContext();
110     }
111
112     /**
113      * Constructs a name for this <code>MenuComponent</code>.
114      * Called by <code>getName</code> when the name is <code>null</code>.
115      * @return a name for this <code>MenuComponent</code>
116      */

117     String JavaDoc constructComponentName() {
118         return null; // For strict compliance with prior platform versions, a MenuComponent
119
// that doesn't set its name should return null from
120
// getName()
121
}
122
123     /**
124      * Gets the name of the menu component.
125      * @return the name of the menu component
126      * @see java.awt.MenuComponent#setName(java.lang.String)
127      * @since JDK1.1
128      */

129     public String JavaDoc getName() {
130         if (name == null && !nameExplicitlySet) {
131             synchronized(this) {
132                 if (name == null && !nameExplicitlySet)
133                     name = constructComponentName();
134             }
135         }
136         return name;
137     }
138
139     /**
140      * Sets the name of the component to the specified string.
141      * @param name the name of the menu component
142      * @see java.awt.MenuComponent#getName
143      * @since JDK1.1
144      */

145     public void setName(String JavaDoc name) {
146         synchronized(this) {
147             this.name = name;
148             nameExplicitlySet = true;
149         }
150     }
151
152     /**
153      * Returns the parent container for this menu component.
154      * @return the menu component containing this menu component,
155      * or <code>null</code> if this menu component
156      * is the outermost component, the menu bar itself
157      */

158     public MenuContainer JavaDoc getParent() {
159     return getParent_NoClientCode();
160     }
161     // NOTE: This method may be called by privileged threads.
162
// This functionality is implemented in a package-private method
163
// to insure that it cannot be overridden by client subclasses.
164
// DO NOT INVOKE CLIENT CODE ON THIS THREAD!
165
final MenuContainer JavaDoc getParent_NoClientCode() {
166     return parent;
167     }
168
169     /**
170      * @deprecated As of JDK version 1.1,
171      * programs should not directly manipulate peers.
172      */

173     @Deprecated JavaDoc
174     public MenuComponentPeer getPeer() {
175     return peer;
176     }
177
178     /**
179      * Gets the font used for this menu component.
180      * @return the font used in this menu component, if there is one;
181      * <code>null</code> otherwise
182      * @see java.awt.MenuComponent#setFont
183      */

184     public Font JavaDoc getFont() {
185     Font JavaDoc font = this.font;
186     if (font != null) {
187         return font;
188     }
189     MenuContainer JavaDoc parent = this.parent;
190     if (parent != null) {
191         return parent.getFont();
192     }
193     return null;
194     }
195
196     // NOTE: This method may be called by privileged threads.
197
// This functionality is implemented in a package-private method
198
// to insure that it cannot be overridden by client subclasses.
199
// DO NOT INVOKE CLIENT CODE ON THIS THREAD!
200
final Font JavaDoc getFont_NoClientCode() {
201     Font JavaDoc font = this.font;
202     if (font != null) {
203         return font;
204     }
205
206     // The MenuContainer interface does not have getFont_NoClientCode()
207
// and it cannot, because it must be package-private. Because of
208
// this, we must manually cast classes that implement
209
// MenuContainer.
210
Object JavaDoc parent = this.parent;
211     if (parent != null) {
212         if (parent instanceof Component JavaDoc) {
213         font = ((Component JavaDoc)parent).getFont_NoClientCode();
214         } else if (parent instanceof MenuComponent JavaDoc) {
215         font = ((MenuComponent JavaDoc)parent).getFont_NoClientCode();
216         }
217     }
218     return font;
219     } // getFont_NoClientCode()
220

221
222     /**
223      * Sets the font to be used for this menu component to the specified
224      * font. This font is also used by all subcomponents of this menu
225      * component, unless those subcomponents specify a different font.
226      * <p>
227      * Some platforms may not support setting of all font attributes
228      * of a menu component; in such cases, calling <code>setFont</code>
229      * will have no effect on the unsupported font attributes of this
230      * menu component. Unless subcomponents of this menu component
231      * specify a different font, this font will be used by those
232      * subcomponents if supported by the underlying platform.
233      *
234      * @param f the font to be set
235      * @see #getFont
236      * @see Font#getAttributes
237      * @see java.awt.font.TextAttribute
238      */

239     public void setFont(Font JavaDoc f) {
240     font = f;
241         if (peer != null) {
242             peer.setFont(f);
243         }
244     }
245
246     /**
247      * Removes the menu component's peer. The peer allows us to modify the
248      * appearance of the menu component without changing the functionality of
249      * the menu component.
250      */

251     public void removeNotify() {
252         synchronized (getTreeLock()) {
253         MenuComponentPeer p = (MenuComponentPeer)this.peer;
254         if (p != null) {
255             Toolkit.getEventQueue().removeSourceEvents(this, true);
256         this.peer = null;
257         p.dispose();
258         }
259     }
260     }
261
262     /**
263      * Posts the specified event to the menu.
264      * This method is part of the Java&nbsp;1.0 event system
265      * and it is maintained only for backwards compatibility.
266      * Its use is discouraged, and it may not be supported
267      * in the future.
268      * @param evt the event which is to take place
269      * @deprecated As of JDK version 1.1, replaced by {@link
270      * #dispatchEvent(AWTEvent) dispatchEvent}.
271      */

272     @Deprecated JavaDoc
273     public boolean postEvent(Event JavaDoc evt) {
274     MenuContainer JavaDoc parent = this.parent;
275     if (parent != null) {
276         parent.postEvent(evt);
277     }
278     return false;
279     }
280
281     /*
282      * Delivers an event to this component or one of its sub components.
283      * @param e the event
284      */

285     public final void dispatchEvent(AWTEvent JavaDoc e) {
286         dispatchEventImpl(e);
287     }
288
289     void dispatchEventImpl(AWTEvent JavaDoc e) {
290         EventQueue.setCurrentEventAndMostRecentTime(e);
291
292         Toolkit.getDefaultToolkit().notifyAWTEventListeners(e);
293
294         if (newEventsOnly ||
295             (parent != null && parent instanceof MenuComponent JavaDoc &&
296              ((MenuComponent JavaDoc)parent).newEventsOnly)) {
297             if (eventEnabled(e)) {
298                 processEvent(e);
299             } else if (e instanceof ActionEvent JavaDoc && parent != null) {
300                 e.setSource(parent);
301                 ((MenuComponent JavaDoc)parent).dispatchEvent(e);
302             }
303                 
304         } else { // backward compatibility
305
Event JavaDoc olde = e.convertToOld();
306             if (olde != null) {
307                 postEvent(olde);
308             }
309         }
310     }
311
312     // REMIND: remove when filtering is done at lower level
313
boolean eventEnabled(AWTEvent JavaDoc e) {
314         return false;
315     }
316     /**
317      * Processes events occurring on this menu component.
318      * <p>Note that if the event parameter is <code>null</code>
319      * the behavior is unspecified and may result in an
320      * exception.
321      *
322      * @param e the event
323      * @since JDK1.1
324      */

325     protected void processEvent(AWTEvent JavaDoc e) {
326     }
327
328     /**
329      * Returns a string representing the state of this
330      * <code>MenuComponent</code>. This method is intended to be used
331      * only for debugging purposes, and the content and format of the
332      * returned string may vary between implementations. The returned
333      * string may be empty but may not be <code>null</code>.
334      *
335      * @return the parameter string of this menu component
336      */

337     protected String JavaDoc paramString() {
338         String JavaDoc thisName = getName();
339         return (thisName != null? thisName : "");
340     }
341
342     /**
343      * Returns a representation of this menu component as a string.
344      * @return a string representation of this menu component
345      */

346     public String JavaDoc toString() {
347     return getClass().getName() + "[" + paramString() + "]";
348     }
349
350     /**
351      * Gets this component's locking object (the object that owns the thread
352      * sychronization monitor) for AWT component-tree and layout
353      * operations.
354      * @return this component's locking object
355      */

356     protected final Object JavaDoc getTreeLock() {
357         return Component.LOCK;
358     }
359
360     /**
361      * Reads the menu component from an object input stream.
362      *
363      * @param s the <code>ObjectInputStream</code> to read
364      * @exception HeadlessException if
365      * <code>GraphicsEnvironment.isHeadless</code> returns
366      * <code>true</code>
367      * @serial
368      * @see java.awt.GraphicsEnvironment#isHeadless
369      */

370     private void readObject(ObjectInputStream JavaDoc s)
371         throws ClassNotFoundException JavaDoc, IOException JavaDoc, HeadlessException JavaDoc
372     {
373         GraphicsEnvironment.checkHeadless();
374         s.defaultReadObject();
375
376         privateKey = new Object JavaDoc();
377     appContext = AppContext.getAppContext();
378     }
379
380     /**
381      * Initialize JNI field and method IDs.
382      */

383     private static native void initIDs();
384
385
386     /*
387      * --- Accessibility Support ---
388      *
389      * MenuComponent will contain all of the methods in interface Accessible,
390      * though it won't actually implement the interface - that will be up
391      * to the individual objects which extend MenuComponent.
392      */

393
394     AccessibleContext accessibleContext = null;
395
396     /**
397      * Gets the <code>AccessibleContext</code> associated with
398      * this <code>MenuComponent</code>.
399      *
400      * The method implemented by this base class returns <code>null</code>.
401      * Classes that extend <code>MenuComponent</code>
402      * should implement this method to return the
403      * <code>AccessibleContext</code> associated with the subclass.
404      *
405      * @return the <code>AccessibleContext</code> of this
406      * <code>MenuComponent</code>
407      */

408     public AccessibleContext getAccessibleContext() {
409         return accessibleContext;
410     }
411
412     /**
413      * Inner class of <code>MenuComponent</code> used to provide
414      * default support for accessibility. This class is not meant
415      * to be used directly by application developers, but is instead
416      * meant only to be subclassed by menu component developers.
417      * <p>
418      * The class used to obtain the accessible role for this object.
419      */

420     protected abstract class AccessibleAWTMenuComponent
421     extends AccessibleContext
422         implements java.io.Serializable JavaDoc, AccessibleComponent,
423                    AccessibleSelection
424     {
425         /*
426          * JDK 1.3 serialVersionUID
427          */

428         private static final long serialVersionUID = -4269533416223798698L;
429
430     /**
431      * Although the class is abstract, this should be called by
432      * all sub-classes.
433      */

434     protected AccessibleAWTMenuComponent() {
435         }
436
437         // AccessibleContext methods
438
//
439

440     /**
441      * Gets the <code>AccessibleSelection</code> associated with this
442          * object which allows its <code>Accessible</code> children to be selected.
443      *
444      * @return <code>AccessibleSelection</code> if supported by object;
445          * else return <code>null</code>
446      * @see AccessibleSelection
447      */

448     public AccessibleSelection getAccessibleSelection() {
449         return this;
450     }
451
452         /**
453          * Gets the accessible name of this object. This should almost never
454          * return <code>java.awt.MenuComponent.getName</code>, as that
455          * generally isn't a localized name, and doesn't have meaning for the
456          * user. If the object is fundamentally a text object (e.g. a menu item), the
457          * accessible name should be the text of the object (e.g. "save").
458          * If the object has a tooltip, the tooltip text may also be an
459          * appropriate String to return.
460          *
461          * @return the localized name of the object -- can be <code>null</code>
462          * if this object does not have a name
463          * @see AccessibleContext#setAccessibleName
464          */

465         public String JavaDoc getAccessibleName() {
466         return accessibleName;
467         }
468
469         /**
470          * Gets the accessible description of this object. This should be
471          * a concise, localized description of what this object is - what
472          * is its meaning to the user. If the object has a tooltip, the
473          * tooltip text may be an appropriate string to return, assuming
474          * it contains a concise description of the object (instead of just
475          * the name of the object - e.g. a "Save" icon on a toolbar that
476          * had "save" as the tooltip text shouldn't return the tooltip
477          * text as the description, but something like "Saves the current
478          * text document" instead).
479          *
480          * @return the localized description of the object -- can be
481          * <code>null</code> if this object does not have a description
482          * @see AccessibleContext#setAccessibleDescription
483          */

484         public String JavaDoc getAccessibleDescription() {
485         return accessibleDescription;
486         }
487
488         /**
489          * Gets the role of this object.
490          *
491          * @return an instance of <code>AccessibleRole</code>
492          * describing the role of the object
493          * @see AccessibleRole
494          */

495         public AccessibleRole getAccessibleRole() {
496             return AccessibleRole.AWT_COMPONENT; // Non-specific -- overridden in subclasses
497
}
498
499         /**
500          * Gets the state of this object.
501          *
502          * @return an instance of <code>AccessibleStateSet</code>
503          * containing the current state set of the object
504          * @see AccessibleState
505          */

506         public AccessibleStateSet getAccessibleStateSet() {
507             return MenuComponent.this.getAccessibleStateSet();
508         }
509
510         /**
511          * Gets the <code>Accessible</code> parent of this object.
512          * If the parent of this object implements <code>Accessible</code>,
513          * this method should simply return <code>getParent</code>.
514          *
515          * @return the <code>Accessible</code> parent of this object -- can
516          * be <code>null</code> if this object does not have an
517          * <code>Accessible</code> parent
518          */

519         public Accessible getAccessibleParent() {
520             if (accessibleParent != null) {
521                 return accessibleParent;
522             } else {
523                 MenuContainer JavaDoc parent = MenuComponent.this.getParent();
524                 if (parent instanceof Accessible) {
525                     return (Accessible) parent;
526                 }
527             }
528             return null;
529         }
530
531         /**
532          * Gets the index of this object in its accessible parent.
533          *
534          * @return the index of this object in its parent; -1 if this
535          * object does not have an accessible parent
536          * @see #getAccessibleParent
537          */

538         public int getAccessibleIndexInParent() {
539             return MenuComponent.this.getAccessibleIndexInParent();
540         }
541
542         /**
543          * Returns the number of accessible children in the object. If all
544          * of the children of this object implement <code>Accessible</code>,
545          * then this method should return the number of children of this object.
546          *
547          * @return the number of accessible children in the object
548          */

549         public int getAccessibleChildrenCount() {
550             return 0; // MenuComponents don't have children
551
}
552
553         /**
554          * Returns the nth <code>Accessible</code> child of the object.
555          *
556          * @param i zero-based index of child
557          * @return the nth Accessible child of the object
558          */

559         public Accessible getAccessibleChild(int i) {
560             return null; // MenuComponents don't have children
561
}
562
563         /**
564          * Returns the locale of this object.
565          *
566          * @return the locale of this object
567          */

568         public java.util.Locale JavaDoc getLocale() {
569             MenuContainer JavaDoc parent = MenuComponent.this.getParent();
570             if (parent instanceof Component JavaDoc)
571                 return ((Component JavaDoc)parent).getLocale();
572             else
573                 return java.util.Locale.getDefault();
574         }
575
576         /**
577          * Gets the <code>AccessibleComponent</code> associated with
578          * this object if one exists. Otherwise return <code>null</code>.
579      *
580      * @return the component
581          */

582         public AccessibleComponent getAccessibleComponent() {
583             return this;
584         }
585
586
587         // AccessibleComponent methods
588
//
589
/**
590          * Gets the background color of this object.
591          *
592          * @return the background color, if supported, of the object;
593          * otherwise, <code>null</code>
594          */

595         public Color JavaDoc getBackground() {
596             return null; // Not supported for MenuComponents
597
}
598
599         /**
600          * Sets the background color of this object.
601          * (For transparency, see <code>isOpaque</code>.)
602          *
603          * @param c the new <code>Color</code> for the background
604          * @see Component#isOpaque
605          */

606         public void setBackground(Color JavaDoc c) {
607             // Not supported for MenuComponents
608
}
609
610         /**
611          * Gets the foreground color of this object.
612          *
613          * @return the foreground color, if supported, of the object;
614          * otherwise, <code>null</code>
615          */

616         public Color JavaDoc getForeground() {
617             return null; // Not supported for MenuComponents
618
}
619
620         /**
621          * Sets the foreground color of this object.
622          *
623          * @param c the new <code>Color</code> for the foreground
624          */

625         public void setForeground(Color JavaDoc c) {
626             // Not supported for MenuComponents
627
}
628
629         /**
630          * Gets the <code>Cursor</code> of this object.
631          *
632          * @return the <code>Curso</code>, if supported, of the object;
633          * otherwise, <code>null</code>
634          */

635         public Cursor JavaDoc getCursor() {
636             return null; // Not supported for MenuComponents
637
}
638
639         /**
640          * Sets the <code>Cursor</code> of this object.
641          *
642          * @param cursor the new <code>Cursor</code> for the object
643          */

644         public void setCursor(Cursor JavaDoc cursor) {
645             // Not supported for MenuComponents
646
}
647
648         /**
649          * Gets the <code>Font</code> of this object.
650          *
651          * @return the <code>Font</code>,if supported, for the object;
652          * otherwise, <code>null</code>
653          */

654         public Font JavaDoc getFont() {
655             return MenuComponent.this.getFont();
656         }
657
658         /**
659          * Sets the <code>Font</code> of this object.
660          *
661          * @param f the new <code>Font</code> for the object
662          */

663         public void setFont(Font JavaDoc f) {
664             MenuComponent.this.setFont(f);
665         }
666
667         /**
668          * Gets the <code>FontMetrics</code> of this object.
669          *
670          * @param f the <code>Font</code>
671          * @return the FontMetrics, if supported, the object;
672          * otherwise, <code>null</code>
673          * @see #getFont
674          */

675         public FontMetrics JavaDoc getFontMetrics(Font JavaDoc f) {
676             return null; // Not supported for MenuComponents
677
}
678
679         /**
680          * Determines if the object is enabled.
681          *
682          * @return true if object is enabled; otherwise, false
683          */

684         public boolean isEnabled() {
685             return true; // Not supported for MenuComponents
686
}
687
688         /**
689          * Sets the enabled state of the object.
690          *
691          * @param b if true, enables this object; otherwise, disables it
692          */

693         public void setEnabled(boolean b) {
694             // Not supported for MenuComponents
695
}
696
697         /**
698          * Determines if the object is visible. Note: this means that the
699          * object intends to be visible; however, it may not in fact be
700          * showing on the screen because one of the objects that this object
701          * is contained by is not visible. To determine if an object is
702          * showing on the screen, use <code>isShowing</code>.
703          *
704          * @return true if object is visible; otherwise, false
705          */

706         public boolean isVisible() {
707             return true; // Not supported for MenuComponents
708
}
709
710         /**
711          * Sets the visible state of the object.
712          *
713          * @param b if true, shows this object; otherwise, hides it
714          */

715         public void setVisible(boolean b) {
716             // Not supported for MenuComponents
717
}
718
719         /**
720          * Determines if the object is showing. This is determined by checking
721          * the visibility of the object and ancestors of the object. Note:
722          * this will return true even if the object is obscured by another
723          * (for example, it happens to be underneath a menu that was pulled
724          * down).
725          *
726          * @return true if object is showing; otherwise, false
727          */

728         public boolean isShowing() {
729             return true; // Not supported for MenuComponents
730
}
731
732         /**
733          * Checks whether the specified point is within this object's bounds,
734          * where the point's x and y coordinates are defined to be relative to
735          * the coordinate system of the object.
736          *
737          * @param p the <code>Point</code> relative to the coordinate
738          * system of the object
739          * @return true if object contains <code>Point</code>; otherwise false
740          */

741         public boolean contains(Point JavaDoc p) {
742             return false; // Not supported for MenuComponents
743
}
744
745         /**
746          * Returns the location of the object on the screen.
747          *
748          * @return location of object on screen -- can be <code>null</code>
749          * if this object is not on the screen
750          */

751         public Point JavaDoc getLocationOnScreen() {
752             return null; // Not supported for MenuComponents
753
}
754
755         /**
756          * Gets the location of the object relative to the parent in the form
757          * of a point specifying the object's top-left corner in the screen's
758          * coordinate space.
759          *
760          * @return an instance of <code>Point</code> representing the
761          * top-left corner of the object's bounds in the coordinate
762          * space of the screen; <code>null</code> if
763          * this object or its parent are not on the screen
764          */

765         public Point JavaDoc getLocation() {
766             return null; // Not supported for MenuComponents
767
}
768
769         /**
770          * Sets the location of the object relative to the parent.
771          */

772         public void setLocation(Point JavaDoc p) {
773             // Not supported for MenuComponents
774
}
775
776         /**
777          * Gets the bounds of this object in the form of a
778          * <code>Rectangle</code> object.
779          * The bounds specify this object's width, height, and location
780          * relative to its parent.
781          *
782          * @return a rectangle indicating this component's bounds;
783          * <code>null</code> if this object is not on the screen
784          */

785         public Rectangle JavaDoc getBounds() {
786             return null; // Not supported for MenuComponents
787
}
788
789         /**
790          * Sets the bounds of this object in the form of a
791          * <code>Rectangle</code> object.
792          * The bounds specify this object's width, height, and location
793          * relative to its parent.
794          *
795          * @param r a rectangle indicating this component's bounds
796          */

797         public void setBounds(Rectangle JavaDoc r) {
798             // Not supported for MenuComponents
799
}
800
801         /**
802          * Returns the size of this object in the form of a
803          * <code>Dimension</code> object. The height field of
804          * the <code>Dimension</code> object contains this object's
805          * height, and the width field of the <code>Dimension</code>
806          * object contains this object's width.
807          *
808          * @return a <code>Dimension</code> object that indicates the
809          * size of this component; <code>null</code>
810          * if this object is not on the screen
811          */

812         public Dimension JavaDoc getSize() {
813             return null; // Not supported for MenuComponents
814
}
815
816         /**
817          * Resizes this object.
818          *
819          * @param d - the <code>Dimension</code> specifying the
820          * new size of the object
821          */

822         public void setSize(Dimension JavaDoc d) {
823             // Not supported for MenuComponents
824
}
825
826         /**
827          * Returns the <code>Accessible</code> child, if one exists,
828          * contained at the local coordinate <code>Point</code>.
829          * If there is no <code>Accessible</code> child, <code>null</code>
830          * is returned.
831          *
832          * @param p the point defining the top-left corner of the
833          * <code>Accessible</code>, given in the coordinate space
834          * of the object's parent
835          * @return the <code>Accessible</code>, if it exists,
836          * at the specified location; else <code>null</code>
837          */

838         public Accessible getAccessibleAt(Point JavaDoc p) {
839             return null; // MenuComponents don't have children
840
}
841
842         /**
843          * Returns whether this object can accept focus or not.
844          *
845          * @return true if object can accept focus; otherwise false
846          */

847         public boolean isFocusTraversable() {
848             return true; // Not supported for MenuComponents
849
}
850
851         /**
852          * Requests focus for this object.
853          */

854         public void requestFocus() {
855             // Not supported for MenuComponents
856
}
857
858         /**
859          * Adds the specified focus listener to receive focus events from this
860          * component.
861          *
862          * @param l the focus listener
863          */

864         public void addFocusListener(java.awt.event.FocusListener JavaDoc l) {
865             // Not supported for MenuComponents
866
}
867
868         /**
869          * Removes the specified focus listener so it no longer receives focus
870          * events from this component.
871          *
872          * @param l the focus listener
873          */

874         public void removeFocusListener(java.awt.event.FocusListener JavaDoc l) {
875             // Not supported for MenuComponents
876
}
877
878     // AccessibleSelection methods
879
//
880

881     /**
882      * Returns the number of <code>Accessible</code> children currently selected.
883      * If no children are selected, the return value will be 0.
884      *
885      * @return the number of items currently selected
886      */

887      public int getAccessibleSelectionCount() {
888          return 0; // To be fully implemented in a future release
889
}
890
891     /**
892      * Returns an <code>Accessible</code> representing the specified
893      * selected child in the object. If there isn't a selection, or there are
894      * fewer children selected than the integer passed in, the return
895      * value will be <code>null</code>.
896      * <p>Note that the index represents the i-th selected child, which
897      * is different from the i-th child.
898      *
899      * @param i the zero-based index of selected children
900      * @return the i-th selected child
901      * @see #getAccessibleSelectionCount
902      */

903      public Accessible getAccessibleSelection(int i) {
904          return null; // To be fully implemented in a future release
905
}
906
907     /**
908      * Determines if the current child of this object is selected.
909      *
910      * @return true if the current child of this object is selected;
911      * else false
912      * @param i the zero-based index of the child in this
913          * <code>Accessible</code> object
914      * @see AccessibleContext#getAccessibleChild
915      */

916      public boolean isAccessibleChildSelected(int i) {
917          return false; // To be fully implemented in a future release
918
}
919
920     /**
921      * Adds the specified <code>Accessible</code> child of the object
922          * to the object's selection. If the object supports multiple selections,
923      * the specified child is added to any existing selection, otherwise
924      * it replaces any existing selection in the object. If the
925      * specified child is already selected, this method has no effect.
926      *
927      * @param i the zero-based index of the child
928      * @see AccessibleContext#getAccessibleChild
929      */

930      public void addAccessibleSelection(int i) {
931            // To be fully implemented in a future release
932
}
933
934     /**
935      * Removes the specified child of the object from the object's
936      * selection. If the specified item isn't currently selected, this
937      * method has no effect.
938      *
939      * @param i the zero-based index of the child
940      * @see AccessibleContext#getAccessibleChild
941      */

942      public void removeAccessibleSelection(int i) {
943            // To be fully implemented in a future release
944
}
945
946     /**
947      * Clears the selection in the object, so that no children in the
948      * object are selected.
949      */

950      public void clearAccessibleSelection() {
951            // To be fully implemented in a future release
952
}
953
954     /**
955      * Causes every child of the object to be selected
956      * if the object supports multiple selections.
957      */

958      public void selectAllAccessibleSelection() {
959            // To be fully implemented in a future release
960
}
961
962     } // inner class AccessibleAWTComponent
963

964     /**
965      * Gets the index of this object in its accessible parent.
966      *
967      * @return -1 if this object does not have an accessible parent;
968      * otherwise, the index of the child in its accessible parent.
969      */

970     int getAccessibleIndexInParent() {
971         MenuContainer JavaDoc localParent = parent;
972         if (!(localParent instanceof MenuComponent JavaDoc)) {
973             // MenuComponents only have accessible index when inside MenuComponents
974
return -1;
975         }
976         MenuComponent JavaDoc localParentMenu = (MenuComponent JavaDoc)localParent;
977         return localParentMenu.getAccessibleChildIndex(this);
978     }
979
980     /**
981      * Gets the index of the child within this MenuComponent.
982      *
983      * @param child MenuComponent whose index we are interested in.
984      * @return -1 if this object doesn't contain the child,
985      * otherwise, index of the child.
986      */

987     int getAccessibleChildIndex(MenuComponent JavaDoc child) {
988         return -1; // Overridden in subclasses.
989
}
990
991     /**
992      * Gets the state of this object.
993      *
994      * @return an instance of <code>AccessibleStateSet</code>
995      * containing the current state set of the object
996      * @see AccessibleState
997      */

998     AccessibleStateSet getAccessibleStateSet() {
999         AccessibleStateSet states = new AccessibleStateSet();
1000        return states;
1001    }
1002
1003}
1004
Popular Tags