KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > swing > JComboBox


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

7 package javax.swing;
8
9 import java.beans.*;
10 import java.util.*;
11
12 import java.awt.*;
13 import java.awt.event.*;
14
15 import java.io.Serializable JavaDoc;
16 import java.io.ObjectOutputStream JavaDoc;
17 import java.io.ObjectInputStream JavaDoc;
18 import java.io.IOException JavaDoc;
19
20 import javax.swing.event.*;
21 import javax.swing.plaf.*;
22 import javax.swing.border.*;
23
24 import javax.accessibility.*;
25
26 /**
27  * A component that combines a button or editable field and a drop-down list.
28  * The user can select a value from the drop-down list, which appears at the
29  * user's request. If you make the combo box editable, then the combo box
30  * includes an editable field into which the user can type a value.
31  *
32  * <p>
33  * For the keyboard keys used by this component in the standard Look and
34  * Feel (L&F) renditions, see the
35  * <a HREF="doc-files/Key-Index.html#JComboBox"><code>JComboBox</code> key assignments</a>.
36  * <p>
37  * <strong>Warning:</strong>
38  * Serialized objects of this class will not be compatible with
39  * future Swing releases. The current serialization support is
40  * appropriate for short term storage or RMI between applications running
41  * the same version of Swing. As of 1.4, support for long term storage
42  * of all JavaBeans<sup><font size="-2">TM</font></sup>
43  * has been added to the <code>java.beans</code> package.
44  * Please see {@link java.beans.XMLEncoder}.
45  *
46  * <p>
47  * See <a HREF="http://java.sun.com/docs/books/tutorial/uiswing/components/combobox.html">How to Use Combo Boxes</a>
48  * in <a HREF="http://java.sun.com/Series/Tutorial/index.html"><em>The Java Tutorial</em></a>
49  * for further information.
50  * <p>
51  * @see ComboBoxModel
52  * @see DefaultComboBoxModel
53  *
54  * @beaninfo
55  * attribute: isContainer false
56  * description: A combination of a text field and a drop-down list.
57  *
58  * @version 1.126 05/05/04
59  * @author Arnaud Weber
60  * @author Mark Davidson
61  */

62 public class JComboBox extends JComponent JavaDoc
63 implements ItemSelectable,ListDataListener,ActionListener, Accessible {
64     /**
65      * @see #getUIClassID
66      * @see #readObject
67      */

68     private static final String JavaDoc uiClassID = "ComboBoxUI";
69
70     /**
71      * This protected field is implementation specific. Do not access directly
72      * or override. Use the accessor methods instead.
73      *
74      * @see #getModel
75      * @see #setModel
76      */

77     protected ComboBoxModel JavaDoc dataModel;
78     /**
79      * This protected field is implementation specific. Do not access directly
80      * or override. Use the accessor methods instead.
81      *
82      * @see #getRenderer
83      * @see #setRenderer
84      */

85     protected ListCellRenderer JavaDoc renderer;
86     /**
87      * This protected field is implementation specific. Do not access directly
88      * or override. Use the accessor methods instead.
89      *
90      * @see #getEditor
91      * @see #setEditor
92      */

93     protected ComboBoxEditor JavaDoc editor;
94     /**
95      * This protected field is implementation specific. Do not access directly
96      * or override. Use the accessor methods instead.
97      *
98      * @see #getMaximumRowCount
99      * @see #setMaximumRowCount
100      */

101     protected int maximumRowCount = 8;
102
103     /**
104      * This protected field is implementation specific. Do not access directly
105      * or override. Use the accessor methods instead.
106      *
107      * @see #isEditable
108      * @see #setEditable
109      */

110     protected boolean isEditable = false;
111     /**
112      * This protected field is implementation specific. Do not access directly
113      * or override. Use the accessor methods instead.
114      *
115      * @see #setKeySelectionManager
116      * @see #getKeySelectionManager
117      */

118     protected KeySelectionManager keySelectionManager = null;
119     /**
120      * This protected field is implementation specific. Do not access directly
121      * or override. Use the accessor methods instead.
122      *
123      * @see #setActionCommand
124      * @see #getActionCommand
125      */

126     protected String JavaDoc actionCommand = "comboBoxChanged";
127     /**
128      * This protected field is implementation specific. Do not access directly
129      * or override. Use the accessor methods instead.
130      *
131      * @see #setLightWeightPopupEnabled
132      * @see #isLightWeightPopupEnabled
133      */

134     protected boolean lightWeightPopupEnabled = JPopupMenu.getDefaultLightWeightPopupEnabled();
135
136     /**
137      * This protected field is implementation specific. Do not access directly
138      * or override.
139      */

140     protected Object JavaDoc selectedItemReminder = null;
141
142     private Object JavaDoc prototypeDisplayValue;
143
144     // Flag to ensure that infinite loops do not occur with ActionEvents.
145
private boolean firingActionEvent = false;
146
147     // Flag to ensure the we don't get multiple ActionEvents on item selection.
148
private boolean selectingItem = false;
149
150     /**
151      * Creates a <code>JComboBox</code> that takes it's items from an
152      * existing <code>ComboBoxModel</code>. Since the
153      * <code>ComboBoxModel</code> is provided, a combo box created using
154      * this constructor does not create a default combo box model and
155      * may impact how the insert, remove and add methods behave.
156      *
157      * @param aModel the <code>ComboBoxModel</code> that provides the
158      * displayed list of items
159      * @see DefaultComboBoxModel
160      */

161     public JComboBox(ComboBoxModel JavaDoc aModel) {
162         super();
163         setModel(aModel);
164         init();
165     }
166
167     /**
168      * Creates a <code>JComboBox</code> that contains the elements
169      * in the specified array. By default the first item in the array
170      * (and therefore the data model) becomes selected.
171      *
172      * @param items an array of objects to insert into the combo box
173      * @see DefaultComboBoxModel
174      */

175     public JComboBox(final Object JavaDoc items[]) {
176         super();
177         setModel(new DefaultComboBoxModel JavaDoc(items));
178         init();
179     }
180
181     /**
182      * Creates a <code>JComboBox</code> that contains the elements
183      * in the specified Vector. By default the first item in the vector
184      * and therefore the data model) becomes selected.
185      *
186      * @param items an array of vectors to insert into the combo box
187      * @see DefaultComboBoxModel
188      */

189     public JComboBox(Vector<?> items) {
190         super();
191         setModel(new DefaultComboBoxModel JavaDoc(items));
192         init();
193     }
194
195     /**
196      * Creates a <code>JComboBox</code> with a default data model.
197      * The default data model is an empty list of objects.
198      * Use <code>addItem</code> to add items. By default the first item
199      * in the data model becomes selected.
200      *
201      * @see DefaultComboBoxModel
202      */

203     public JComboBox() {
204         super();
205         setModel(new DefaultComboBoxModel JavaDoc());
206         init();
207     }
208
209     private void init() {
210         installAncestorListener();
211         setOpaque(true);
212         updateUI();
213     }
214
215     protected void installAncestorListener() {
216         addAncestorListener(new AncestorListener(){
217                                 public void ancestorAdded(AncestorEvent event){ hidePopup();}
218                                 public void ancestorRemoved(AncestorEvent event){ hidePopup();}
219                                 public void ancestorMoved(AncestorEvent event){
220                                     if (event.getSource() != JComboBox.this)
221                                         hidePopup();
222                                 }});
223     }
224
225     /**
226      * Sets the L&F object that renders this component.
227      *
228      * @param ui the <code>ComboBoxUI</code> L&F object
229      * @see UIDefaults#getUI
230      *
231      * @beaninfo
232      * bound: true
233      * hidden: true
234      * attribute: visualUpdate true
235      * description: The UI object that implements the Component's LookAndFeel.
236      */

237     public void setUI(ComboBoxUI ui) {
238         super.setUI(ui);
239     }
240
241     /**
242      * Resets the UI property to a value from the current look and feel.
243      *
244      * @see JComponent#updateUI
245      */

246     public void updateUI() {
247         setUI((ComboBoxUI)UIManager.getUI(this));
248     }
249
250
251     /**
252      * Returns the name of the L&F class that renders this component.
253      *
254      * @return the string "ComboBoxUI"
255      * @see JComponent#getUIClassID
256      * @see UIDefaults#getUI
257      */

258     public String JavaDoc getUIClassID() {
259         return uiClassID;
260     }
261
262
263     /**
264      * Returns the L&F object that renders this component.
265      *
266      * @return the ComboBoxUI object that renders this component
267      */

268     public ComboBoxUI getUI() {
269         return(ComboBoxUI)ui;
270     }
271
272     /**
273      * Sets the data model that the <code>JComboBox</code> uses to obtain
274      * the list of items.
275      *
276      * @param aModel the <code>ComboBoxModel</code> that provides the
277      * displayed list of items
278      *
279      * @beaninfo
280      * bound: true
281      * description: Model that the combo box uses to get data to display.
282      */

283     public void setModel(ComboBoxModel JavaDoc aModel) {
284         ComboBoxModel JavaDoc oldModel = dataModel;
285     if (oldModel != null) {
286         oldModel.removeListDataListener(this);
287     }
288         dataModel = aModel;
289     dataModel.addListDataListener(this);
290     
291     // set the current selected item.
292
selectedItemReminder = dataModel.getSelectedItem();
293
294         firePropertyChange( "model", oldModel, dataModel);
295     }
296
297     /**
298      * Returns the data model currently used by the <code>JComboBox</code>.
299      *
300      * @return the <code>ComboBoxModel</code> that provides the displayed
301      * list of items
302      */

303     public ComboBoxModel JavaDoc getModel() {
304         return dataModel;
305     }
306
307     /*
308      * Properties
309      */

310
311     /**
312      * Sets the <code>lightWeightPopupEnabled</code> property, which
313      * provides a hint as to whether or not a lightweight
314      * <code>Component</code> should be used to contain the
315      * <code>JComboBox</code>, versus a heavyweight
316      * <code>Component</code> such as a <code>Panel</code>
317      * or a <code>Window</code>. The decision of lightweight
318      * versus heavyweight is ultimately up to the
319      * <code>JComboBox</code>. Lightweight windows are more
320      * efficient than heavyweight windows, but lightweight
321      * and heavyweight components do not mix well in a GUI.
322      * If your application mixes lightweight and heavyweight
323      * components, you should disable lightweight popups.
324      * The default value for the <code>lightWeightPopupEnabled</code>
325      * property is <code>true</code>, unless otherwise specified
326      * by the look and feel. Some look and feels always use
327      * heavyweight popups, no matter what the value of this property.
328      * <p>
329      * See the article <a HREF="http://java.sun.com/products/jfc/tsc/articles/mixing/index.html">Mixing Heavy and Light Components</a>
330      * on <a HREF="http://java.sun.com/products/jfc/tsc">
331      * <em>The Swing Connection</em></a>
332      * This method fires a property changed event.
333      *
334      * @param aFlag if <code>true</code>, lightweight popups are desired
335      *
336      * @beaninfo
337      * bound: true
338      * expert: true
339      * description: Set to <code>false</code> to require heavyweight popups.
340      */

341     public void setLightWeightPopupEnabled(boolean aFlag) {
342     boolean oldFlag = lightWeightPopupEnabled;
343         lightWeightPopupEnabled = aFlag;
344     firePropertyChange("lightWeightPopupEnabled", oldFlag, lightWeightPopupEnabled);
345     }
346
347     /**
348      * Gets the value of the <code>lightWeightPopupEnabled</code>
349      * property.
350      *
351      * @return the value of the <code>lightWeightPopupEnabled</code>
352      * property
353      * @see #setLightWeightPopupEnabled
354      */

355     public boolean isLightWeightPopupEnabled() {
356         return lightWeightPopupEnabled;
357     }
358
359     /**
360      * Determines whether the <code>JComboBox</code> field is editable.
361      * An editable <code>JComboBox</code> allows the user to type into the
362      * field or selected an item from the list to initialize the field,
363      * after which it can be edited. (The editing affects only the field,
364      * the list item remains intact.) A non editable <code>JComboBox</code>
365      * displays the selected item in the field,
366      * but the selection cannot be modified.
367      *
368      * @param aFlag a boolean value, where true indicates that the
369      * field is editable
370      *
371      * @beaninfo
372      * bound: true
373      * preferred: true
374      * description: If true, the user can type a new value in the combo box.
375      */

376     public void setEditable(boolean aFlag) {
377         boolean oldFlag = isEditable;
378         isEditable = aFlag;
379         firePropertyChange( "editable", oldFlag, isEditable );
380     }
381
382     /**
383      * Returns true if the <code>JComboBox</code> is editable.
384      * By default, a combo box is not editable.
385      *
386      * @return true if the <code>JComboBox</code> is editable, else false
387      */

388     public boolean isEditable() {
389         return isEditable;
390     }
391
392     /**
393      * Sets the maximum number of rows the <code>JComboBox</code> displays.
394      * If the number of objects in the model is greater than count,
395      * the combo box uses a scrollbar.
396      *
397      * @param count an integer specifying the maximum number of items to
398      * display in the list before using a scrollbar
399      * @beaninfo
400      * bound: true
401      * preferred: true
402      * description: The maximum number of rows the popup should have
403      */

404     public void setMaximumRowCount(int count) {
405         int oldCount = maximumRowCount;
406         maximumRowCount = count;
407         firePropertyChange( "maximumRowCount", oldCount, maximumRowCount );
408     }
409
410     /**
411      * Returns the maximum number of items the combo box can display
412      * without a scrollbar
413      *
414      * @return an integer specifying the maximum number of items that are
415      * displayed in the list before using a scrollbar
416      */

417     public int getMaximumRowCount() {
418         return maximumRowCount;
419     }
420
421     /**
422      * Sets the renderer that paints the list items and the item selected from the list in
423      * the JComboBox field. The renderer is used if the JComboBox is not
424      * editable. If it is editable, the editor is used to render and edit
425      * the selected item.
426      * <p>
427      * The default renderer displays a string or an icon.
428      * Other renderers can handle graphic images and composite items.
429      * <p>
430      * To display the selected item,
431      * <code>aRenderer.getListCellRendererComponent</code>
432      * is called, passing the list object and an index of -1.
433      *
434      * @param aRenderer the <code>ListCellRenderer</code> that
435      * displays the selected item
436      * @see #setEditor
437      * @beaninfo
438      * bound: true
439      * expert: true
440      * description: The renderer that paints the item selected in the list.
441      */

442     public void setRenderer(ListCellRenderer JavaDoc aRenderer) {
443         ListCellRenderer JavaDoc oldRenderer = renderer;
444         renderer = aRenderer;
445         firePropertyChange( "renderer", oldRenderer, renderer );
446         invalidate();
447     }
448
449     /**
450      * Returns the renderer used to display the selected item in the
451      * <code>JComboBox</code> field.
452      *
453      * @return the <code>ListCellRenderer</code> that displays
454      * the selected item.
455      */

456     public ListCellRenderer JavaDoc getRenderer() {
457         return renderer;
458     }
459
460     /**
461      * Sets the editor used to paint and edit the selected item in the
462      * <code>JComboBox</code> field. The editor is used only if the
463      * receiving <code>JComboBox</code> is editable. If not editable,
464      * the combo box uses the renderer to paint the selected item.
465      *
466      * @param anEditor the <code>ComboBoxEditor</code> that
467      * displays the selected item
468      * @see #setRenderer
469      * @beaninfo
470      * bound: true
471      * expert: true
472      * description: The editor that combo box uses to edit the current value
473      */

474     public void setEditor(ComboBoxEditor JavaDoc anEditor) {
475         ComboBoxEditor JavaDoc oldEditor = editor;
476
477         if ( editor != null ) {
478             editor.removeActionListener(this);
479     }
480         editor = anEditor;
481         if ( editor != null ) {
482             editor.addActionListener(this);
483         }
484         firePropertyChange( "editor", oldEditor, editor );
485     }
486
487     /**
488      * Returns the editor used to paint and edit the selected item in the
489      * <code>JComboBox</code> field.
490      *
491      * @return the <code>ComboBoxEditor</code> that displays the selected item
492      */

493     public ComboBoxEditor JavaDoc getEditor() {
494         return editor;
495     }
496
497     //
498
// Selection
499
//
500

501     /**
502      * Sets the selected item in the combo box display area to the object in
503      * the argument.
504      * If <code>anObject</code> is in the list, the display area shows
505      * <code>anObject</code> selected.
506      * <p>
507      * If <code>anObject</code> is <i>not</i> in the list and the combo box is
508      * uneditable, it will not change the current selection. For editable
509      * combo boxes, the selection will change to <code>anObject</code>.
510      * <p>
511      * If this constitutes a change in the selected item,
512      * <code>ItemListener</code>s added to the combo box will be notified with
513      * one or two <code>ItemEvent</code>s.
514      * If there is a current selected item, an <code>ItemEvent</code> will be
515      * fired and the state change will be <code>ItemEvent.DESELECTED</code>.
516      * If <code>anObject</code> is in the list and is not currently selected
517      * then an <code>ItemEvent</code> will be fired and the state change will
518      * be <code>ItemEvent.SELECTED</code>.
519      * <p>
520      * <code>ActionListener</code>s added to the combo box will be notified
521      * with an <code>ActionEvent</code> when this method is called.
522      *
523      * @param anObject the list object to select; use <code>null</code> to
524                         clear the selection
525      * @beaninfo
526      * preferred: true
527      * description: Sets the selected item in the JComboBox.
528      */

529     public void setSelectedItem(Object JavaDoc anObject) {
530     Object JavaDoc oldSelection = selectedItemReminder;
531     if (oldSelection == null || !oldSelection.equals(anObject)) {
532
533         if (anObject != null && !isEditable()) {
534         // For non editable combo boxes, an invalid selection
535
// will be rejected.
536
boolean found = false;
537         for (int i = 0; i < dataModel.getSize(); i++) {
538             if (anObject.equals(dataModel.getElementAt(i))) {
539             found = true;
540             break;
541             }
542         }
543         if (!found) {
544             return;
545         }
546         }
547         
548         // Must toggle the state of this flag since this method
549
// call may result in ListDataEvents being fired.
550
selectingItem = true;
551         dataModel.setSelectedItem(anObject);
552         selectingItem = false;
553
554         if (selectedItemReminder != dataModel.getSelectedItem()) {
555         // in case a users implementation of ComboBoxModel
556
// doesn't fire a ListDataEvent when the selection
557
// changes.
558
selectedItemChanged();
559         }
560     }
561     fireActionEvent();
562     }
563
564     /**
565      * Returns the current selected item.
566      * <p>
567      * If the combo box is editable, then this value may not have been added
568      * to the combo box with <code>addItem</code>, <code>insertItemAt</code>
569      * or the data constructors.
570      *
571      * @return the current selected Object
572      * @see #setSelectedItem
573      */

574     public Object JavaDoc getSelectedItem() {
575         return dataModel.getSelectedItem();
576     }
577
578     /**
579      * Selects the item at index <code>anIndex</code>.
580      *
581      * @param anIndex an integer specifying the list item to select,
582      * where 0 specifies the first item in the list and -1 indicates no selection
583      * @exception IllegalArgumentException if <code>anIndex</code> < -1 or
584      * <code>anIndex</code> is greater than or equal to size
585      * @beaninfo
586      * preferred: true
587      * description: The item at index is selected.
588      */

589     public void setSelectedIndex(int anIndex) {
590         int size = dataModel.getSize();
591
592         if ( anIndex == -1 ) {
593             setSelectedItem( null );
594         } else if ( anIndex < -1 || anIndex >= size ) {
595             throw new IllegalArgumentException JavaDoc("setSelectedIndex: " + anIndex + " out of bounds");
596         } else {
597             setSelectedItem(dataModel.getElementAt(anIndex));
598         }
599     }
600
601     /**
602      * Returns the first item in the list that matches the given item.
603      * The result is not always defined if the <code>JComboBox</code>
604      * allows selected items that are not in the list.
605      * Returns -1 if there is no selected item or if the user specified
606      * an item which is not in the list.
607      
608      * @return an integer specifying the currently selected list item,
609      * where 0 specifies
610      * the first item in the list;
611      * or -1 if no item is selected or if
612      * the currently selected item is not in the list
613      */

614     public int getSelectedIndex() {
615         Object JavaDoc sObject = dataModel.getSelectedItem();
616         int i,c;
617         Object JavaDoc obj;
618
619         for ( i=0,c=dataModel.getSize();i<c;i++ ) {
620             obj = dataModel.getElementAt(i);
621             if ( obj != null && obj.equals(sObject) )
622                 return i;
623         }
624         return -1;
625     }
626
627     /**
628      * Returns the "prototypical display" value - an Object used
629      * for the calculation of the display height and width.
630      *
631      * @return the value of the <code>prototypeDisplayValue</code> property
632      * @see #setPrototypeDisplayValue
633      * @since 1.4
634      */

635     public Object JavaDoc getPrototypeDisplayValue() {
636         return prototypeDisplayValue;
637     }
638
639     /**
640      * Sets the prototype display value used to calculate the size of the display
641      * for the UI portion.
642      * <p>
643      * If a prototype display value is specified, the preferred size of
644      * the combo box is calculated by configuring the renderer with the
645      * prototype display value and obtaining its preferred size. Specifying
646      * the preferred display value is often useful when the combo box will be
647      * displaying large amounts of data. If no prototype display value has
648      * been specified, the renderer must be configured for each value from
649      * the model and its preferred size obtained, which can be
650      * relatively expensive.
651      *
652      * @param prototypeDisplayValue
653      * @see #getPrototypeDisplayValue
654      * @since 1.4
655      * @beaninfo
656      * bound: true
657      * attribute: visualUpdate true
658      * description: The display prototype value, used to compute display width and height.
659      */

660     public void setPrototypeDisplayValue(Object JavaDoc prototypeDisplayValue) {
661         Object JavaDoc oldValue = this.prototypeDisplayValue;
662         this.prototypeDisplayValue = prototypeDisplayValue;
663         firePropertyChange("prototypeDisplayValue", oldValue, prototypeDisplayValue);
664     }
665
666     /**
667      * Adds an item to the item list.
668      * This method works only if the <code>JComboBox</code> uses a
669      * mutable data model.
670      * <p>
671      * <strong>Warning:</strong>
672      * Focus and keyboard navigation problems may arise if you add duplicate
673      * String objects. A workaround is to add new objects instead of String
674      * objects and make sure that the toString() method is defined.
675      * For example:
676      * <pre>
677      * comboBox.addItem(makeObj("Item 1"));
678      * comboBox.addItem(makeObj("Item 1"));
679      * ...
680      * private Object makeObj(final String item) {
681      * return new Object() { public String toString() { return item; } };
682      * }
683      * </pre>
684      *
685      * @param anObject the Object to add to the list
686      * @see MutableComboBoxModel
687      */

688     public void addItem(Object JavaDoc anObject) {
689         checkMutableComboBoxModel();
690         ((MutableComboBoxModel JavaDoc)dataModel).addElement(anObject);
691     }
692
693     /**
694      * Inserts an item into the item list at a given index.
695      * This method works only if the <code>JComboBox</code> uses a
696      * mutable data model.
697      *
698      * @param anObject the <code>Object</code> to add to the list
699      * @param index an integer specifying the position at which
700      * to add the item
701      * @see MutableComboBoxModel
702      */

703     public void insertItemAt(Object JavaDoc anObject, int index) {
704         checkMutableComboBoxModel();
705         ((MutableComboBoxModel JavaDoc)dataModel).insertElementAt(anObject,index);
706     }
707
708     /**
709      * Removes an item from the item list.
710      * This method works only if the <code>JComboBox</code> uses a
711      * mutable data model.
712      *
713      * @param anObject the object to remove from the item list
714      * @see MutableComboBoxModel
715      */

716     public void removeItem(Object JavaDoc anObject) {
717         checkMutableComboBoxModel();
718         ((MutableComboBoxModel JavaDoc)dataModel).removeElement(anObject);
719     }
720
721     /**
722      * Removes the item at <code>anIndex</code>
723      * This method works only if the <code>JComboBox</code> uses a
724      * mutable data model.
725      *
726      * @param anIndex an int specifying the index of the item to remove,
727      * where 0
728      * indicates the first item in the list
729      * @see MutableComboBoxModel
730      */

731     public void removeItemAt(int anIndex) {
732         checkMutableComboBoxModel();
733         ((MutableComboBoxModel JavaDoc)dataModel).removeElementAt( anIndex );
734     }
735
736     /**
737      * Removes all items from the item list.
738      */

739     public void removeAllItems() {
740         checkMutableComboBoxModel();
741         MutableComboBoxModel JavaDoc model = (MutableComboBoxModel JavaDoc)dataModel;
742         int size = model.getSize();
743
744         if ( model instanceof DefaultComboBoxModel JavaDoc ) {
745             ((DefaultComboBoxModel JavaDoc)model).removeAllElements();
746         }
747         else {
748             for ( int i = 0; i < size; ++i ) {
749                 Object JavaDoc element = model.getElementAt( 0 );
750                 model.removeElement( element );
751             }
752         }
753     selectedItemReminder = null;
754     if (isEditable()) {
755         editor.setItem(null);
756     }
757     }
758
759     /**
760      * Checks that the <code>dataModel</code> is an instance of
761      * <code>MutableComboBoxModel</code>. If not, it throws an exception.
762      * @exception RuntimeException if <code>dataModel</code> is not an
763      * instance of <code>MutableComboBoxModel</code>.
764      */

765     void checkMutableComboBoxModel() {
766         if ( !(dataModel instanceof MutableComboBoxModel JavaDoc) )
767             throw new RuntimeException JavaDoc("Cannot use this method with a non-Mutable data model.");
768     }
769
770     /**
771      * Causes the combo box to display its popup window.
772      * @see #setPopupVisible
773      */

774     public void showPopup() {
775         setPopupVisible(true);
776     }
777
778     /**
779      * Causes the combo box to close its popup window.
780      * @see #setPopupVisible
781      */

782     public void hidePopup() {
783         setPopupVisible(false);
784     }
785
786     /**
787      * Sets the visibility of the popup.
788      */

789     public void setPopupVisible(boolean v) {
790         getUI().setPopupVisible(this, v);
791     }
792
793     /**
794      * Determines the visibility of the popup.
795      *
796      * @return true if the popup is visible, otherwise returns false
797      */

798     public boolean isPopupVisible() {
799         return getUI().isPopupVisible(this);
800     }
801
802     /** Selection **/
803
804     /**
805      * Adds an <code>ItemListener</code>.
806      * <p>
807      * <code>aListener</code> will receive one or two <code>ItemEvent</code>s when
808      * the selected item changes.
809      *
810      * @param aListener the <code>ItemListener</code> that is to be notified
811      * @see #setSelectedItem
812      */

813     public void addItemListener(ItemListener aListener) {
814         listenerList.add(ItemListener.class,aListener);
815     }
816
817     /** Removes an <code>ItemListener</code>.
818      *
819      * @param aListener the <code>ItemListener</code> to remove
820      */

821     public void removeItemListener(ItemListener aListener) {
822         listenerList.remove(ItemListener.class,aListener);
823     }
824
825     /**
826      * Returns an array of all the <code>ItemListener</code>s added
827      * to this JComboBox with addItemListener().
828      *
829      * @return all of the <code>ItemListener</code>s added or an empty
830      * array if no listeners have been added
831      * @since 1.4
832      */

833     public ItemListener[] getItemListeners() {
834         return (ItemListener[])listenerList.getListeners(ItemListener.class);
835     }
836
837     /**
838      * Adds an <code>ActionListener</code>.
839      * <p>
840      * The <code>ActionListener</code> will receive an <code>ActionEvent</code>
841      * when a selection has been made. If the combo box is editable, then
842      * an <code>ActionEvent</code> will be fired when editing has stopped.
843      *
844      * @param l the <code>ActionListener</code> that is to be notified
845      * @see #setSelectedItem
846      */

847     public void addActionListener(ActionListener l) {
848         listenerList.add(ActionListener.class,l);
849     }
850
851     /** Removes an <code>ActionListener</code>.
852      *
853      * @param l the <code>ActionListener</code> to remove
854      */

855     public void removeActionListener(ActionListener l) {
856     if ((l != null) && (getAction() == l)) {
857         setAction(null);
858     } else {
859         listenerList.remove(ActionListener.class, l);
860     }
861     }
862
863     /**
864      * Returns an array of all the <code>ActionListener</code>s added
865      * to this JComboBox with addActionListener().
866      *
867      * @return all of the <code>ActionListener</code>s added or an empty
868      * array if no listeners have been added
869      * @since 1.4
870      */

871     public ActionListener[] getActionListeners() {
872         return (ActionListener[])listenerList.getListeners(
873                 ActionListener.class);
874     }
875
876     /**
877      * Adds a <code>PopupMenu</code> listener which will listen to notification
878      * messages from the popup portion of the combo box.
879      * <p>
880      * For all standard look and feels shipped with Java 2, the popup list
881      * portion of combo box is implemented as a <code>JPopupMenu</code>.
882      * A custom look and feel may not implement it this way and will
883      * therefore not receive the notification.
884      *
885      * @param l the <code>PopupMenuListener</code> to add
886      * @since 1.4
887      */

888     public void addPopupMenuListener(PopupMenuListener l) {
889         listenerList.add(PopupMenuListener.class,l);
890     }
891
892     /**
893      * Removes a <code>PopupMenuListener</code>.
894      *
895      * @param l the <code>PopupMenuListener</code> to remove
896      * @see #addPopupMenuListener
897      * @since 1.4
898      */

899     public void removePopupMenuListener(PopupMenuListener l) {
900         listenerList.remove(PopupMenuListener.class,l);
901     }
902
903     /**
904      * Returns an array of all the <code>PopupMenuListener</code>s added
905      * to this JComboBox with addPopupMenuListener().
906      *
907      * @return all of the <code>PopupMenuListener</code>s added or an empty
908      * array if no listeners have been added
909      * @since 1.4
910      */

911     public PopupMenuListener[] getPopupMenuListeners() {
912         return (PopupMenuListener[])listenerList.getListeners(
913                 PopupMenuListener.class);
914     }
915
916     /**
917      * Notifies <code>PopupMenuListener</code>s that the popup portion of the
918      * combo box will become visible.
919      * <p>
920      * This method is public but should not be called by anything other than
921      * the UI delegate.
922      * @see #addPopupMenuListener
923      * @since 1.4
924      */

925     public void firePopupMenuWillBecomeVisible() {
926         Object JavaDoc[] listeners = listenerList.getListenerList();
927         PopupMenuEvent e=null;
928         for (int i = listeners.length-2; i>=0; i-=2) {
929             if (listeners[i]==PopupMenuListener.class) {
930                 if (e == null)
931                     e = new PopupMenuEvent(this);
932                 ((PopupMenuListener)listeners[i+1]).popupMenuWillBecomeVisible(e);
933             }
934         }
935     }
936     
937     /**
938      * Notifies <code>PopupMenuListener</code>s that the popup portion of the
939      * combo box has become invisible.
940      * <p>
941      * This method is public but should not be called by anything other than
942      * the UI delegate.
943      * @see #addPopupMenuListener
944      * @since 1.4
945      */

946     public void firePopupMenuWillBecomeInvisible() {
947         Object JavaDoc[] listeners = listenerList.getListenerList();
948         PopupMenuEvent e=null;
949         for (int i = listeners.length-2; i>=0; i-=2) {
950             if (listeners[i]==PopupMenuListener.class) {
951                 if (e == null)
952                     e = new PopupMenuEvent(this);
953                 ((PopupMenuListener)listeners[i+1]).popupMenuWillBecomeInvisible(e);
954             }
955         }
956     }
957     
958     /**
959      * Notifies <code>PopupMenuListener</code>s that the popup portion of the
960      * combo box has been canceled.
961      * <p>
962      * This method is public but should not be called by anything other than
963      * the UI delegate.
964      * @see #addPopupMenuListener
965      * @since 1.4
966      */

967     public void firePopupMenuCanceled() {
968         Object JavaDoc[] listeners = listenerList.getListenerList();
969         PopupMenuEvent e=null;
970         for (int i = listeners.length-2; i>=0; i-=2) {
971             if (listeners[i]==PopupMenuListener.class) {
972                 if (e == null)
973                     e = new PopupMenuEvent(this);
974                 ((PopupMenuListener)listeners[i+1]).popupMenuCanceled(e);
975             }
976         }
977     }
978
979     /**
980      * Sets the action command that should be included in the event
981      * sent to action listeners.
982      *
983      * @param aCommand a string containing the "command" that is sent
984      * to action listeners; the same listener can then
985      * do different things depending on the command it
986      * receives
987      */

988     public void setActionCommand(String JavaDoc aCommand) {
989         actionCommand = aCommand;
990     }
991
992     /**
993      * Returns the action command that is included in the event sent to
994      * action listeners.
995      *
996      * @return the string containing the "command" that is sent
997      * to action listeners.
998      */

999     public String JavaDoc getActionCommand() {
1000        return actionCommand;
1001    }
1002
1003    private Action JavaDoc action;
1004    private PropertyChangeListener actionPropertyChangeListener;
1005
1006    /**
1007     * Sets the <code>Action</code> for the <code>ActionEvent</code> source.
1008     * The new <code>Action</code> replaces any previously set
1009     * <code>Action</code> but does not affect <code>ActionListeners</code>
1010     * independently added with <code>addActionListener</code>.
1011     * If the <code>Action</code> is already a registered
1012     * <code>ActionListener</code> for the <code>ActionEvent</code> source,
1013     * it is not re-registered.
1014     *
1015     * <p>
1016     * A side-effect of setting the <code>Action</code> is that the
1017     * <code>ActionEvent</code> source's properties are immedately set
1018     * from the values in the <code>Action</code> (performed by the method
1019     * <code>configurePropertiesFromAction</code>) and subsequently
1020     * updated as the <code>Action</code>'s properties change (via a
1021     * <code>PropertyChangeListener</code> created by the method
1022     * <code>createActionPropertyChangeListener</code>.
1023     *
1024     * @param a the <code>Action</code> for the <code>JComboBox</code>,
1025     * or <code>null</code>.
1026     * @since 1.3
1027     * @see Action
1028     * @see #getAction
1029     * @see #configurePropertiesFromAction
1030     * @see #createActionPropertyChangeListener
1031     * @beaninfo
1032     * bound: true
1033     * attribute: visualUpdate true
1034     * description: the Action instance connected with this ActionEvent source
1035     */

1036    public void setAction(Action JavaDoc a) {
1037    Action JavaDoc oldValue = getAction();
1038    if (action==null || !action.equals(a)) {
1039        action = a;
1040        if (oldValue!=null) {
1041        removeActionListener(oldValue);
1042        oldValue.removePropertyChangeListener(actionPropertyChangeListener);
1043        actionPropertyChangeListener = null;
1044        }
1045        configurePropertiesFromAction(action);
1046        if (action!=null) {
1047        // Don't add if it is already a listener
1048
if (!isListener(ActionListener.class, action)) {
1049            addActionListener(action);
1050        }
1051        // Reverse linkage:
1052
actionPropertyChangeListener = createActionPropertyChangeListener(action);
1053        action.addPropertyChangeListener(actionPropertyChangeListener);
1054        }
1055        firePropertyChange("action", oldValue, action);
1056        revalidate();
1057        repaint();
1058    }
1059    }
1060
1061    private boolean isListener(Class JavaDoc c, ActionListener a) {
1062    boolean isListener = false;
1063    Object JavaDoc[] listeners = listenerList.getListenerList();
1064        for (int i = listeners.length-2; i>=0; i-=2) {
1065            if (listeners[i]==c && listeners[i+1]==a) {
1066            isListener=true;
1067        }
1068    }
1069    return isListener;
1070    }
1071
1072    /**
1073     * Returns the currently set <code>Action</code> for this
1074     * <code>ActionEvent</code> source, or <code>null</code> if no
1075     * <code>Action</code> is set.
1076     *
1077     * @return the <code>Action</code> for this <code>ActionEvent</code>
1078     * source; or <code>null</code>
1079     * @since 1.3
1080     * @see Action
1081     * @see #setAction
1082     */

1083    public Action JavaDoc getAction() {
1084    return action;
1085    }
1086
1087    /**
1088     * Factory method which sets the <code>ActionEvent</code> source's
1089     * properties according to values from the <code>Action</code> instance.
1090     * The properties which are set may differ for subclasses.
1091     * By default, the properties which get set are
1092     * <code>Enabled</code> and <code>ToolTipText</code>.
1093     *
1094     * @param a the <code>Action</code> from which to get the properties,
1095     * or <code>null</code>
1096     * @since 1.3
1097     * @see Action
1098     * @see #setAction
1099     */

1100    protected void configurePropertiesFromAction(Action JavaDoc a) {
1101    setEnabled((a!=null?a.isEnabled():true));
1102    setToolTipText((a!=null?(String JavaDoc)a.getValue(Action.SHORT_DESCRIPTION):null));
1103    }
1104
1105    /**
1106     * Factory method which creates the <code>PropertyChangeListener</code>
1107     * used to update the <code>ActionEvent</code> source as properties change
1108     * on its <code>Action</code> instance.
1109     * Subclasses may override this in order to provide their own
1110     * <code>PropertyChangeListener</code> if the set of
1111     * properties which should be kept up to date differs from the
1112     * default properties (Text, Icon, Enabled, ToolTipText).
1113     *
1114     * Note that <code>PropertyChangeListeners</code> should avoid holding
1115     * strong references to the <code>ActionEvent</code> source,
1116     * as this may hinder garbage collection of the <code>ActionEvent</code>
1117     * source and all components in its containment hierarchy.
1118     *
1119     * @since 1.3
1120     * @see Action
1121     * @see #setAction
1122     */

1123    protected PropertyChangeListener createActionPropertyChangeListener(Action JavaDoc a) {
1124        return new AbstractActionPropertyChangeListener JavaDoc(this, a) {
1125        public void propertyChange(PropertyChangeEvent e) {
1126        String JavaDoc propertyName = e.getPropertyName();
1127        JComboBox JavaDoc comboBox = (JComboBox JavaDoc)getTarget();
1128        if (comboBox == null) { //WeakRef GC'ed in 1.2
1129
Action JavaDoc action = (Action JavaDoc)e.getSource();
1130            action.removePropertyChangeListener(this);
1131        } else {
1132            if (e.getPropertyName().equals(Action.SHORT_DESCRIPTION)) {
1133            String JavaDoc text = (String JavaDoc) e.getNewValue();
1134            comboBox.setToolTipText(text);
1135            } else if (propertyName.equals("enabled")) {
1136            Boolean JavaDoc enabledState = (Boolean JavaDoc) e.getNewValue();
1137            comboBox.setEnabled(enabledState.booleanValue());
1138            comboBox.repaint();
1139            }
1140        }
1141        }
1142    };
1143    }
1144
1145    /**
1146     * Notifies all listeners that have registered interest for
1147     * notification on this event type.
1148     * @param e the event of interest
1149     *
1150     * @see EventListenerList
1151     */

1152    protected void fireItemStateChanged(ItemEvent e) {
1153        // Guaranteed to return a non-null array
1154
Object JavaDoc[] listeners = listenerList.getListenerList();
1155        // Process the listeners last to first, notifying
1156
// those that are interested in this event
1157
for ( int i = listeners.length-2; i>=0; i-=2 ) {
1158            if ( listeners[i]==ItemListener.class ) {
1159                // Lazily create the event:
1160
// if (changeEvent == null)
1161
// changeEvent = new ChangeEvent(this);
1162
((ItemListener)listeners[i+1]).itemStateChanged(e);
1163            }
1164        }
1165    }
1166
1167    /**
1168     * Notifies all listeners that have registered interest for
1169     * notification on this event type.
1170     *
1171     * @see EventListenerList
1172     */

1173    protected void fireActionEvent() {
1174    if (!firingActionEvent) {
1175        // Set flag to ensure that an infinite loop is not created
1176
firingActionEvent = true;
1177        ActionEvent e = null;
1178        // Guaranteed to return a non-null array
1179
Object JavaDoc[] listeners = listenerList.getListenerList();
1180            long mostRecentEventTime = EventQueue.getMostRecentEventTime();
1181            int modifiers = 0;
1182            AWTEvent currentEvent = EventQueue.getCurrentEvent();
1183            if (currentEvent instanceof InputEvent) {
1184                modifiers = ((InputEvent)currentEvent).getModifiers();
1185            } else if (currentEvent instanceof ActionEvent) {
1186                modifiers = ((ActionEvent)currentEvent).getModifiers();
1187            }
1188        // Process the listeners last to first, notifying
1189
// those that are interested in this event
1190
for ( int i = listeners.length-2; i>=0; i-=2 ) {
1191        if ( listeners[i]==ActionListener.class ) {
1192            // Lazily create the event:
1193
if ( e == null )
1194            e = new ActionEvent(this,ActionEvent.ACTION_PERFORMED,
1195                                            getActionCommand(),
1196                                            mostRecentEventTime, modifiers);
1197            ((ActionListener)listeners[i+1]).actionPerformed(e);
1198        }
1199        }
1200        firingActionEvent = false;
1201    }
1202    }
1203
1204    /**
1205     * This protected method is implementation specific. Do not access directly
1206     * or override.
1207     */

1208    protected void selectedItemChanged() {
1209    if (selectedItemReminder != null ) {
1210        fireItemStateChanged(new ItemEvent(this,ItemEvent.ITEM_STATE_CHANGED,
1211                           selectedItemReminder,
1212                           ItemEvent.DESELECTED));
1213    }
1214    
1215    // set the new selected item.
1216
selectedItemReminder = dataModel.getSelectedItem();
1217
1218    if (selectedItemReminder != null ) {
1219        fireItemStateChanged(new ItemEvent(this,ItemEvent.ITEM_STATE_CHANGED,
1220                           selectedItemReminder,
1221                           ItemEvent.SELECTED));
1222    }
1223    }
1224
1225    /**
1226     * Returns an array containing the selected item.
1227     * This method is implemented for compatibility with
1228     * <code>ItemSelectable</code>.
1229     *
1230     * @return an array of <code>Objects</code> containing one
1231     * element -- the selected item
1232     */

1233    public Object JavaDoc[] getSelectedObjects() {
1234        Object JavaDoc selectedObject = getSelectedItem();
1235        if ( selectedObject == null )
1236            return new Object JavaDoc[0];
1237        else {
1238            Object JavaDoc result[] = new Object JavaDoc[1];
1239            result[0] = selectedObject;
1240            return result;
1241        }
1242    }
1243
1244    /**
1245     * This method is public as an implementation side effect.
1246     * do not call or override.
1247     */

1248    public void actionPerformed(ActionEvent e) {
1249        Object JavaDoc newItem = getEditor().getItem();
1250        setPopupVisible(false);
1251        getModel().setSelectedItem(newItem);
1252    String JavaDoc oldCommand = getActionCommand();
1253    setActionCommand("comboBoxEdited");
1254    fireActionEvent();
1255    setActionCommand(oldCommand);
1256    }
1257
1258    /**
1259     * This method is public as an implementation side effect.
1260     * do not call or override.
1261     */

1262    public void contentsChanged(ListDataEvent e) {
1263    Object JavaDoc oldSelection = selectedItemReminder;
1264    Object JavaDoc newSelection = dataModel.getSelectedItem();
1265    if (oldSelection == null || !oldSelection.equals(newSelection)) {
1266        selectedItemChanged();
1267        if (!selectingItem) {
1268        fireActionEvent();
1269        }
1270    }
1271    }
1272
1273    /**
1274     * This method is public as an implementation side effect.
1275     * do not call or override.
1276     */

1277    public void intervalAdded(ListDataEvent e) {
1278    if (selectedItemReminder != dataModel.getSelectedItem()) {
1279        selectedItemChanged();
1280    }
1281    }
1282
1283    /**
1284     * This method is public as an implementation side effect.
1285     * do not call or override.
1286     */

1287    public void intervalRemoved(ListDataEvent e) {
1288    contentsChanged(e);
1289    }
1290
1291    /**
1292     * Selects the list item that corresponds to the specified keyboard
1293     * character and returns true, if there is an item corresponding
1294     * to that character. Otherwise, returns false.
1295     *
1296     * @param keyChar a char, typically this is a keyboard key
1297     * typed by the user
1298     */

1299    public boolean selectWithKeyChar(char keyChar) {
1300        int index;
1301
1302        if ( keySelectionManager == null )
1303            keySelectionManager = createDefaultKeySelectionManager();
1304
1305        index = keySelectionManager.selectionForKey(keyChar,getModel());
1306        if ( index != -1 ) {
1307            setSelectedIndex(index);
1308            return true;
1309        }
1310        else
1311            return false;
1312    }
1313
1314    /**
1315     * Enables the combo box so that items can be selected. When the
1316     * combo box is disabled, items cannot be selected and values
1317     * cannot be typed into its field (if it is editable).
1318     *
1319     * @param b a boolean value, where true enables the component and
1320     * false disables it
1321     * @beaninfo
1322     * bound: true
1323     * preferred: true
1324     * description: Whether the combo box is enabled.
1325     */

1326    public void setEnabled(boolean b) {
1327        super.setEnabled(b);
1328        firePropertyChange( "enabled", !isEnabled(), isEnabled() );
1329    }
1330
1331    /**
1332     * Initializes the editor with the specified item.
1333     *
1334     * @param anEditor the <code>ComboBoxEditor</code> that displays
1335     * the list item in the
1336     * combo box field and allows it to be edited
1337     * @param anItem the object to display and edit in the field
1338     */

1339    public void configureEditor(ComboBoxEditor JavaDoc anEditor, Object JavaDoc anItem) {
1340        anEditor.setItem(anItem);
1341    }
1342
1343    /**
1344     * Handles <code>KeyEvent</code>s, looking for the Tab key.
1345     * If the Tab key is found, the popup window is closed.
1346     *
1347     * @param e the <code>KeyEvent</code> containing the keyboard
1348     * key that was pressed
1349     */

1350    public void processKeyEvent(KeyEvent e) {
1351        if ( e.getKeyCode() == KeyEvent.VK_TAB ) {
1352            hidePopup();
1353        }
1354        super.processKeyEvent(e);
1355    }
1356
1357    /**
1358     * Sets the object that translates a keyboard character into a list
1359     * selection. Typically, the first selection with a matching first
1360     * character becomes the selected item.
1361     *
1362     * @beaninfo
1363     * expert: true
1364     * description: The objects that changes the selection when a key is pressed.
1365     */

1366    public void setKeySelectionManager(KeySelectionManager aManager) {
1367        keySelectionManager = aManager;
1368    }
1369
1370    /**
1371     * Returns the list's key-selection manager.
1372     *
1373     * @return the <code>KeySelectionManager</code> currently in use
1374     */

1375    public KeySelectionManager getKeySelectionManager() {
1376        return keySelectionManager;
1377    }
1378
1379    /* Accessing the model */
1380    /**
1381     * Returns the number of items in the list.
1382     *
1383     * @return an integer equal to the number of items in the list
1384     */

1385    public int getItemCount() {
1386        return dataModel.getSize();
1387    }
1388
1389    /**
1390     * Returns the list item at the specified index. If <code>index</code>
1391     * is out of range (less than zero or greater than or equal to size)
1392     * it will return <code>null</code>.
1393     *
1394     * @param index an integer indicating the list position, where the first
1395     * item starts at zero
1396     * @return the <code>Object</code> at that list position; or
1397     * <code>null</code> if out of range
1398     */

1399    public Object JavaDoc getItemAt(int index) {
1400        return dataModel.getElementAt(index);
1401    }
1402
1403    /**
1404     * Returns an instance of the default key-selection manager.
1405     *
1406     * @return the <code>KeySelectionManager</code> currently used by the list
1407     * @see #setKeySelectionManager
1408     */

1409    protected KeySelectionManager createDefaultKeySelectionManager() {
1410        return new DefaultKeySelectionManager();
1411    }
1412
1413
1414    /**
1415     * The interface that defines a <code>KeySelectionManager</code>.
1416     * To qualify as a <code>KeySelectionManager</code>,
1417     * the class needs to implement the method
1418     * that identifies the list index given a character and the
1419     * combo box data model.
1420     */

1421    public interface KeySelectionManager {
1422        /** Given <code>aKey</code> and the model, returns the row
1423         * that should become selected. Return -1 if no match was
1424         * found.
1425         *
1426         * @param aKey a char value, usually indicating a keyboard key that
1427         * was pressed
1428         * @param aModel a ComboBoxModel -- the component's data model, containing
1429         * the list of selectable items
1430         * @return an int equal to the selected row, where 0 is the
1431         * first item and -1 is none.
1432         */

1433        int selectionForKey(char aKey,ComboBoxModel JavaDoc aModel);
1434    }
1435
1436    class DefaultKeySelectionManager implements KeySelectionManager, Serializable JavaDoc {
1437        public int selectionForKey(char aKey,ComboBoxModel JavaDoc aModel) {
1438            int i,c;
1439            int currentSelection = -1;
1440            Object JavaDoc selectedItem = aModel.getSelectedItem();
1441            String JavaDoc v;
1442            String JavaDoc pattern;
1443
1444            if ( selectedItem != null ) {
1445                for ( i=0,c=aModel.getSize();i<c;i++ ) {
1446                    if ( selectedItem == aModel.getElementAt(i) ) {
1447                        currentSelection = i;
1448                        break;
1449                    }
1450                }
1451            }
1452
1453            pattern = ("" + aKey).toLowerCase();
1454            aKey = pattern.charAt(0);
1455
1456            for ( i = ++currentSelection, c = aModel.getSize() ; i < c ; i++ ) {
1457                Object JavaDoc elem = aModel.getElementAt(i);
1458        if (elem != null && elem.toString() != null) {
1459            v = elem.toString().toLowerCase();
1460            if ( v.length() > 0 && v.charAt(0) == aKey )
1461            return i;
1462        }
1463            }
1464
1465            for ( i = 0 ; i < currentSelection ; i ++ ) {
1466                Object JavaDoc elem = aModel.getElementAt(i);
1467        if (elem != null && elem.toString() != null) {
1468            v = elem.toString().toLowerCase();
1469            if ( v.length() > 0 && v.charAt(0) == aKey )
1470            return i;
1471        }
1472            }
1473            return -1;
1474        }
1475    }
1476
1477
1478    /**
1479     * See <code>readObject</code> and <code>writeObject</code> in
1480     * </code>JComponent</code> for more
1481     * information about serialization in Swing.
1482     */

1483    private void writeObject(ObjectOutputStream JavaDoc s) throws IOException JavaDoc {
1484        s.defaultWriteObject();
1485        if (getUIClassID().equals(uiClassID)) {
1486            byte count = JComponent.getWriteObjCounter(this);
1487            JComponent.setWriteObjCounter(this, --count);
1488            if (count == 0 && ui != null) {
1489                ui.installUI(this);
1490            }
1491        }
1492    }
1493
1494
1495    /**
1496     * Returns a string representation of this <code>JComboBox</code>.
1497     * This method is intended to be used only for debugging purposes,
1498     * and the content and format of the returned string may vary between
1499     * implementations. The returned string may be empty but may not
1500     * be <code>null</code>.
1501     *
1502     * @return a string representation of this <code>JComboBox</code>
1503     */

1504    protected String JavaDoc paramString() {
1505        String JavaDoc selectedItemReminderString = (selectedItemReminder != null ?
1506                                             selectedItemReminder.toString() :
1507                                             "");
1508        String JavaDoc isEditableString = (isEditable ? "true" : "false");
1509        String JavaDoc lightWeightPopupEnabledString = (lightWeightPopupEnabled ?
1510                                                "true" : "false");
1511
1512        return super.paramString() +
1513        ",isEditable=" + isEditableString +
1514        ",lightWeightPopupEnabled=" + lightWeightPopupEnabledString +
1515        ",maximumRowCount=" + maximumRowCount +
1516        ",selectedItemReminder=" + selectedItemReminderString;
1517    }
1518
1519
1520///////////////////
1521
// Accessibility support
1522
///////////////////
1523

1524    /**
1525     * Gets the AccessibleContext associated with this JComboBox.
1526     * For combo boxes, the AccessibleContext takes the form of an
1527     * AccessibleJComboBox.
1528     * A new AccessibleJComboBox instance is created if necessary.
1529     *
1530     * @return an AccessibleJComboBox that serves as the
1531     * AccessibleContext of this JComboBox
1532     */

1533    public AccessibleContext getAccessibleContext() {
1534        if ( accessibleContext == null ) {
1535            accessibleContext = new AccessibleJComboBox();
1536        }
1537        return accessibleContext;
1538    }
1539
1540    /**
1541     * This class implements accessibility support for the
1542     * <code>JComboBox</code> class. It provides an implementation of the
1543     * Java Accessibility API appropriate to Combo Box user-interface elements.
1544     * <p>
1545     * <strong>Warning:</strong>
1546     * Serialized objects of this class will not be compatible with
1547     * future Swing releases. The current serialization support is
1548     * appropriate for short term storage or RMI between applications running
1549     * the same version of Swing. As of 1.4, support for long term storage
1550     * of all JavaBeans<sup><font size="-2">TM</font></sup>
1551     * has been added to the <code>java.beans</code> package.
1552     * Please see {@link java.beans.XMLEncoder}.
1553     */

1554    protected class AccessibleJComboBox extends AccessibleJComponent
1555    implements AccessibleAction, AccessibleSelection {
1556
1557
1558    private JList JavaDoc popupList; // combo box popup list
1559
private Accessible previousSelectedAccessible = null;
1560
1561    /**
1562     * Returns an AccessibleJComboBox instance
1563     */

1564    public AccessibleJComboBox() {
1565        // TIGER - 4894944 4894434
1566
// Get the popup list
1567
Accessible a = getUI().getAccessibleChild(JComboBox.this, 0);
1568            if (a instanceof javax.swing.plaf.basic.ComboPopup JavaDoc) {
1569                // Listen for changes to the popup menu selection.
1570
popupList = ((javax.swing.plaf.basic.ComboPopup JavaDoc)a).getList();
1571        popupList.addListSelectionListener(
1572            new AccessibleJComboBoxListSelectionListener());
1573            }
1574        // Listen for popup menu show/hide events
1575
JComboBox.this.addPopupMenuListener(
1576          new AccessibleJComboBoxPopupMenuListener());
1577    }
1578
1579    /*
1580     * Listener for combo box popup menu
1581         * TIGER - 4669379 4894434
1582     */

1583    private class AccessibleJComboBoxPopupMenuListener
1584            implements PopupMenuListener {
1585        
1586        /**
1587         * This method is called before the popup menu becomes visible
1588         */

1589        public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
1590        // save the initial selection
1591
if (popupList == null) {
1592            return;
1593        }
1594        int selectedIndex = popupList.getSelectedIndex();
1595        if (selectedIndex < 0) {
1596            return;
1597        }
1598        previousSelectedAccessible =
1599            popupList.getAccessibleContext().getAccessibleChild(selectedIndex);
1600        }
1601        
1602        /**
1603         * This method is called before the popup menu becomes invisible
1604         * Note that a JPopupMenu can become invisible any time
1605         */

1606        public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
1607        // ignore
1608
}
1609        
1610        /**
1611         * This method is called when the popup menu is canceled
1612         */

1613        public void popupMenuCanceled(PopupMenuEvent e) {
1614        // ignore
1615
}
1616    }
1617
1618    /*
1619     * Handles changes to the popup list selection.
1620         * TIGER - 4669379 4894434 4933143
1621     */

1622    private class AccessibleJComboBoxListSelectionListener
1623        implements ListSelectionListener {
1624
1625        public void valueChanged(ListSelectionEvent e) {
1626        if (popupList == null) {
1627            return;
1628        }
1629
1630        // Get the selected popup list item.
1631
int selectedIndex = popupList.getSelectedIndex();
1632        if (selectedIndex < 0) {
1633            return;
1634        }
1635        Accessible selectedAccessible =
1636            popupList.getAccessibleContext().getAccessibleChild(selectedIndex);
1637        if (selectedAccessible == null) {
1638            return;
1639        }
1640
1641        // Fire a FOCUSED lost PropertyChangeEvent for the
1642
// previously selected list item.
1643
PropertyChangeEvent pce = null;
1644
1645        if (previousSelectedAccessible != null) {
1646            pce = new PropertyChangeEvent(previousSelectedAccessible,
1647                AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
1648                AccessibleState.FOCUSED, null);
1649            firePropertyChange(AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
1650                       null, pce);
1651        }
1652        // Fire a FOCUSED gained PropertyChangeEvent for the
1653
// currently selected list item.
1654
pce = new PropertyChangeEvent(selectedAccessible,
1655                    AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
1656            null, AccessibleState.FOCUSED);
1657        firePropertyChange(AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
1658                   null, pce);
1659
1660        // Fire the ACCESSIBLE_ACTIVE_DESCENDANT_PROPERTY event
1661
// for the combo box.
1662
firePropertyChange(AccessibleContext.ACCESSIBLE_ACTIVE_DESCENDANT_PROPERTY,
1663                   previousSelectedAccessible, selectedAccessible);
1664
1665        // Save the previous selection.
1666
previousSelectedAccessible = selectedAccessible;
1667        }
1668    }
1669
1670
1671        /**
1672         * Returns the number of accessible children in the object. If all
1673         * of the children of this object implement Accessible, than this
1674         * method should return the number of children of this object.
1675         *
1676         * @return the number of accessible children in the object.
1677         */

1678        public int getAccessibleChildrenCount() {
1679            // Always delegate to the UI if it exists
1680
if (ui != null) {
1681                return ui.getAccessibleChildrenCount(JComboBox.this);
1682            } else {
1683                return super.getAccessibleChildrenCount();
1684            }
1685        }
1686
1687        /**
1688         * Returns the nth Accessible child of the object.
1689         * The child at index zero represents the popup.
1690         * If the combo box is editable, the child at index one
1691         * represents the editor.
1692         *
1693         * @param i zero-based index of child
1694         * @return the nth Accessible child of the object
1695         */

1696        public Accessible getAccessibleChild(int i) {
1697            // Always delegate to the UI if it exists
1698
if (ui != null) {
1699                return ui.getAccessibleChild(JComboBox.this, i);
1700            } else {
1701               return super.getAccessibleChild(i);
1702            }
1703        }
1704
1705        /**
1706         * Get the role of this object.
1707         *
1708         * @return an instance of AccessibleRole describing the role of the
1709         * object
1710         * @see AccessibleRole
1711         */

1712        public AccessibleRole getAccessibleRole() {
1713            return AccessibleRole.COMBO_BOX;
1714        }
1715
1716    /**
1717     * Gets the state set of this object. The AccessibleStateSet of
1718     * an object is composed of a set of unique AccessibleStates.
1719     * A change in the AccessibleStateSet of an object will cause a
1720     * PropertyChangeEvent to be fired for the ACCESSIBLE_STATE_PROPERTY
1721     * property.
1722     *
1723     * @return an instance of AccessibleStateSet containing the
1724     * current state set of the object
1725     * @see AccessibleStateSet
1726     * @see AccessibleState
1727     * @see #addPropertyChangeListener
1728     *
1729     */

1730    public AccessibleStateSet getAccessibleStateSet() {
1731        // TIGER - 4489748
1732
AccessibleStateSet ass = super.getAccessibleStateSet();
1733        if (ass == null) {
1734        ass = new AccessibleStateSet();
1735        }
1736        if (JComboBox.this.isPopupVisible()) {
1737        ass.add(AccessibleState.EXPANDED);
1738        } else {
1739        ass.add(AccessibleState.COLLAPSED);
1740        }
1741        return ass;
1742    }
1743
1744        /**
1745         * Get the AccessibleAction associated with this object. In the
1746         * implementation of the Java Accessibility API for this class,
1747     * return this object, which is responsible for implementing the
1748         * AccessibleAction interface on behalf of itself.
1749     *
1750     * @return this object
1751         */

1752        public AccessibleAction getAccessibleAction() {
1753            return this;
1754        }
1755
1756        /**
1757         * Return a description of the specified action of the object.
1758         *
1759         * @param i zero-based index of the actions
1760         */

1761        public String JavaDoc getAccessibleActionDescription(int i) {
1762            if (i == 0) {
1763                return UIManager.getString("ComboBox.togglePopupText");
1764            }
1765            else {
1766                return null;
1767            }
1768        }
1769
1770        /**
1771         * Returns the number of Actions available in this object. The
1772         * default behavior of a combo box is to have one action.
1773         *
1774         * @return 1, the number of Actions in this object
1775         */

1776        public int getAccessibleActionCount() {
1777            return 1;
1778        }
1779
1780        /**
1781         * Perform the specified Action on the object
1782         *
1783         * @param i zero-based index of actions
1784         * @return true if the the action was performed; else false.
1785         */

1786        public boolean doAccessibleAction(int i) {
1787            if (i == 0) {
1788                setPopupVisible(!isPopupVisible());
1789                return true;
1790            }
1791            else {
1792                return false;
1793            }
1794        }
1795
1796
1797        /**
1798         * Get the AccessibleSelection associated with this object. In the
1799         * implementation of the Java Accessibility API for this class,
1800     * return this object, which is responsible for implementing the
1801         * AccessibleSelection interface on behalf of itself.
1802     *
1803     * @return this object
1804         */

1805        public AccessibleSelection getAccessibleSelection() {
1806        return this;
1807        }
1808
1809    /**
1810     * Returns the number of Accessible children currently selected.
1811     * If no children are selected, the return value will be 0.
1812     *
1813     * @return the number of items currently selected.
1814     */

1815    public int getAccessibleSelectionCount() {
1816        Object JavaDoc o = JComboBox.this.getSelectedItem();
1817        if (o != null) {
1818        return 1;
1819        } else {
1820        return 0;
1821        }
1822    }
1823    
1824    /**
1825     * Returns an Accessible representing the specified selected child
1826     * in the popup. If there isn't a selection, or there are
1827     * fewer children selected than the integer passed in, the return
1828     * value will be null.
1829     * <p>Note that the index represents the i-th selected child, which
1830     * is different from the i-th child.
1831     *
1832     * @param i the zero-based index of selected children
1833     * @return the i-th selected child
1834     * @see #getAccessibleSelectionCount
1835     */

1836    public Accessible getAccessibleSelection(int i) {
1837            // Get the popup
1838
Accessible a =
1839                JComboBox.this.getUI().getAccessibleChild(JComboBox.this, 0);
1840            if (a != null &&
1841                a instanceof javax.swing.plaf.basic.ComboPopup JavaDoc) {
1842
1843                // get the popup list
1844
JList JavaDoc list = ((javax.swing.plaf.basic.ComboPopup JavaDoc)a).getList();
1845
1846                // return the i-th selection in the popup list
1847
AccessibleContext ac = list.getAccessibleContext();
1848                if (ac != null) {
1849                    AccessibleSelection as = ac.getAccessibleSelection();
1850                    if (as != null) {
1851                        return as.getAccessibleSelection(i);
1852                    }
1853                }
1854            }
1855            return null;
1856    }
1857    
1858    /**
1859     * Determines if the current child of this object is selected.
1860     *
1861     * @return true if the current child of this object is selected;
1862     * else false
1863     * @param i the zero-based index of the child in this Accessible
1864     * object.
1865     * @see AccessibleContext#getAccessibleChild
1866     */

1867    public boolean isAccessibleChildSelected(int i) {
1868        return JComboBox.this.getSelectedIndex() == i;
1869    }
1870    
1871    /**
1872     * Adds the specified Accessible child of the object to the object's
1873     * selection. If the object supports multiple selections,
1874     * the specified child is added to any existing selection, otherwise
1875     * it replaces any existing selection in the object. If the
1876     * specified child is already selected, this method has no effect.
1877     *
1878     * @param i the zero-based index of the child
1879     * @see AccessibleContext#getAccessibleChild
1880     */

1881    public void addAccessibleSelection(int i) {
1882            // TIGER - 4856195
1883
clearAccessibleSelection();
1884        JComboBox.this.setSelectedIndex(i);
1885    }
1886    
1887    /**
1888     * Removes the specified child of the object from the object's
1889     * selection. If the specified item isn't currently selected, this
1890     * method has no effect.
1891     *
1892     * @param i the zero-based index of the child
1893     * @see AccessibleContext#getAccessibleChild
1894     */

1895    public void removeAccessibleSelection(int i) {
1896        if (JComboBox.this.getSelectedIndex() == i) {
1897        clearAccessibleSelection();
1898        }
1899    }
1900
1901    /**
1902     * Clears the selection in the object, so that no children in the
1903     * object are selected.
1904     */

1905    public void clearAccessibleSelection() {
1906        JComboBox.this.setSelectedIndex(-1);
1907    }
1908    
1909    /**
1910     * Causes every child of the object to be selected
1911     * if the object supports multiple selections.
1912     */

1913    public void selectAllAccessibleSelection() {
1914        // do nothing since multiple selection is not supported
1915
}
1916
1917// public Accessible getAccessibleAt(Point p) {
1918
// Accessible a = getAccessibleChild(1);
1919
// if ( a != null ) {
1920
// return a; // the editor
1921
// }
1922
// else {
1923
// return getAccessibleChild(0); // the list
1924
// }
1925
// }
1926
private EditorAccessibleContext editorAccessibleContext = null;
1927
1928    private class AccessibleEditor implements Accessible {
1929        public AccessibleContext getAccessibleContext() {
1930        if (editorAccessibleContext == null) {
1931            Component c = JComboBox.this.getEditor().getEditorComponent();
1932            if (c instanceof Accessible) {
1933            editorAccessibleContext =
1934                new EditorAccessibleContext((Accessible)c);
1935            }
1936        }
1937        return editorAccessibleContext;
1938        }
1939    }
1940
1941    /*
1942     * Wrapper class for the AccessibleContext implemented by the
1943     * combo box editor. Delegates all method calls except
1944     * getAccessibleIndexInParent to the editor. The
1945     * getAccessibleIndexInParent method returns the selected
1946     * index in the combo box.
1947     */

1948    private class EditorAccessibleContext extends AccessibleContext {
1949
1950        private AccessibleContext ac;
1951
1952        private EditorAccessibleContext() {
1953        }
1954
1955        /*
1956         * @param a the AccessibleContext implemented by the
1957         * combo box editor
1958         */

1959        EditorAccessibleContext(Accessible a) {
1960        this.ac = a.getAccessibleContext();
1961        }
1962
1963        /**
1964         * Gets the accessibleName property of this object. The accessibleName
1965         * property of an object is a localized String that designates the purpose
1966         * of the object. For example, the accessibleName property of a label
1967         * or button might be the text of the label or button itself. In the
1968         * case of an object that doesn't display its name, the accessibleName
1969         * should still be set. For example, in the case of a text field used
1970         * to enter the name of a city, the accessibleName for the en_US locale
1971         * could be 'city.'
1972         *
1973         * @return the localized name of the object; null if this
1974         * object does not have a name
1975         *
1976         * @see #setAccessibleName
1977         */

1978        public String JavaDoc getAccessibleName() {
1979        return ac.getAccessibleName();
1980        }
1981    
1982        /**
1983         * Sets the localized accessible name of this object. Changing the
1984         * name will cause a PropertyChangeEvent to be fired for the
1985         * ACCESSIBLE_NAME_PROPERTY property.
1986         *
1987         * @param s the new localized name of the object.
1988         *
1989         * @see #getAccessibleName
1990         * @see #addPropertyChangeListener
1991         *
1992         * @beaninfo
1993         * preferred: true
1994         * description: Sets the accessible name for the component.
1995         */

1996        public void setAccessibleName(String JavaDoc s) {
1997        ac.setAccessibleName(s);
1998        }
1999        
2000        /**
2001         * Gets the accessibleDescription property of this object. The
2002         * accessibleDescription property of this object is a short localized
2003         * phrase describing the purpose of the object. For example, in the
2004         * case of a 'Cancel' button, the accessibleDescription could be
2005         * 'Ignore changes and close dialog box.'
2006         *
2007         * @return the localized description of the object; null if
2008         * this object does not have a description
2009         *
2010         * @see #setAccessibleDescription
2011         */

2012        public String JavaDoc getAccessibleDescription() {
2013        return ac.getAccessibleDescription();
2014        }
2015        
2016        /**
2017         * Sets the accessible description of this object. Changing the
2018         * name will cause a PropertyChangeEvent to be fired for the
2019         * ACCESSIBLE_DESCRIPTION_PROPERTY property.
2020         *
2021         * @param s the new localized description of the object
2022         *
2023         * @see #setAccessibleName
2024         * @see #addPropertyChangeListener
2025         *
2026         * @beaninfo
2027         * preferred: true
2028         * description: Sets the accessible description for the component.
2029         */

2030        public void setAccessibleDescription(String JavaDoc s) {
2031        ac.setAccessibleDescription(s);
2032        }
2033        
2034        /**
2035         * Gets the role of this object. The role of the object is the generic
2036         * purpose or use of the class of this object. For example, the role
2037         * of a push button is AccessibleRole.PUSH_BUTTON. The roles in
2038         * AccessibleRole are provided so component developers can pick from
2039         * a set of predefined roles. This enables assistive technologies to
2040         * provide a consistent interface to various tweaked subclasses of
2041         * components (e.g., use AccessibleRole.PUSH_BUTTON for all components
2042         * that act like a push button) as well as distinguish between sublasses
2043         * that behave differently (e.g., AccessibleRole.CHECK_BOX for check boxes
2044         * and AccessibleRole.RADIO_BUTTON for radio buttons).
2045         * <p>Note that the AccessibleRole class is also extensible, so
2046         * custom component developers can define their own AccessibleRole's
2047         * if the set of predefined roles is inadequate.
2048         *
2049         * @return an instance of AccessibleRole describing the role of the object
2050         * @see AccessibleRole
2051         */

2052        public AccessibleRole getAccessibleRole() {
2053        return ac.getAccessibleRole();
2054        }
2055        
2056        /**
2057         * Gets the state set of this object. The AccessibleStateSet of an object
2058         * is composed of a set of unique AccessibleStates. A change in the
2059         * AccessibleStateSet of an object will cause a PropertyChangeEvent to
2060         * be fired for the ACCESSIBLE_STATE_PROPERTY property.
2061         *
2062         * @return an instance of AccessibleStateSet containing the
2063         * current state set of the object
2064         * @see AccessibleStateSet
2065         * @see AccessibleState
2066         * @see #addPropertyChangeListener
2067         */

2068        public AccessibleStateSet getAccessibleStateSet() {
2069        return ac.getAccessibleStateSet();
2070        }
2071        
2072        /**
2073         * Gets the Accessible parent of this object.
2074         *
2075         * @return the Accessible parent of this object; null if this
2076         * object does not have an Accessible parent
2077         */

2078        public Accessible getAccessibleParent() {
2079        return ac.getAccessibleParent();
2080        }
2081        
2082        /**
2083         * Sets the Accessible parent of this object. This is meant to be used
2084         * only in the situations where the actual component's parent should
2085         * not be treated as the component's accessible parent and is a method
2086         * that should only be called by the parent of the accessible child.
2087         *
2088         * @param a - Accessible to be set as the parent
2089         */

2090        public void setAccessibleParent(Accessible a) {
2091        ac.setAccessibleParent(a);
2092        }
2093        
2094        /**
2095         * Gets the 0-based index of this object in its accessible parent.
2096         *
2097         * @return the 0-based index of this object in its parent; -1 if this
2098         * object does not have an accessible parent.
2099         *
2100         * @see #getAccessibleParent
2101         * @see #getAccessibleChildrenCount
2102         * @see #getAccessibleChild
2103         */

2104        public int getAccessibleIndexInParent() {
2105        return JComboBox.this.getSelectedIndex();
2106        }
2107        
2108        /**
2109         * Returns the number of accessible children of the object.
2110         *
2111         * @return the number of accessible children of the object.
2112         */

2113        public int getAccessibleChildrenCount() {
2114        return ac.getAccessibleChildrenCount();
2115        }
2116        
2117        /**
2118         * Returns the specified Accessible child of the object. The Accessible
2119         * children of an Accessible object are zero-based, so the first child
2120         * of an Accessible child is at index 0, the second child is at index 1,
2121         * and so on.
2122         *
2123         * @param i zero-based index of child
2124         * @return the Accessible child of the object
2125         * @see #getAccessibleChildrenCount
2126         */

2127        public Accessible getAccessibleChild(int i) {
2128        return ac.getAccessibleChild(i);
2129        }
2130        
2131        /**
2132         * Gets the locale of the component. If the component does not have a
2133         * locale, then the locale of its parent is returned.
2134         *
2135         * @return this component's locale. If this component does not have
2136         * a locale, the locale of its parent is returned.
2137         *
2138         * @exception IllegalComponentStateException
2139         * If the Component does not have its own locale and has not yet been
2140         * added to a containment hierarchy such that the locale can be
2141         * determined from the containing parent.
2142         */

2143        public Locale getLocale() throws IllegalComponentStateException {
2144        return ac.getLocale();
2145        }
2146        
2147        /**
2148         * Adds a PropertyChangeListener to the listener list.
2149         * The listener is registered for all Accessible properties and will
2150         * be called when those properties change.
2151         *
2152         * @see #ACCESSIBLE_NAME_PROPERTY
2153         * @see #ACCESSIBLE_DESCRIPTION_PROPERTY
2154         * @see #ACCESSIBLE_STATE_PROPERTY
2155         * @see #ACCESSIBLE_VALUE_PROPERTY
2156         * @see #ACCESSIBLE_SELECTION_PROPERTY
2157         * @see #ACCESSIBLE_TEXT_PROPERTY
2158         * @see #ACCESSIBLE_VISIBLE_DATA_PROPERTY
2159         *
2160         * @param listener The PropertyChangeListener to be added
2161         */

2162        public void addPropertyChangeListener(PropertyChangeListener listener) {
2163        ac.addPropertyChangeListener(listener);
2164        }
2165        
2166        /**
2167         * Removes a PropertyChangeListener from the listener list.
2168         * This removes a PropertyChangeListener that was registered
2169         * for all properties.
2170         *
2171         * @param listener The PropertyChangeListener to be removed
2172         */

2173        public void removePropertyChangeListener(PropertyChangeListener listener) {
2174        ac.removePropertyChangeListener(listener);
2175        }
2176        
2177        /**
2178         * Gets the AccessibleAction associated with this object that supports
2179         * one or more actions.
2180         *
2181         * @return AccessibleAction if supported by object; else return null
2182         * @see AccessibleAction
2183         */

2184        public AccessibleAction getAccessibleAction() {
2185        return ac.getAccessibleAction();
2186        }
2187        
2188        /**
2189         * Gets the AccessibleComponent associated with this object that has a
2190         * graphical representation.
2191         *
2192         * @return AccessibleComponent if supported by object; else return null
2193         * @see AccessibleComponent
2194         */

2195        public AccessibleComponent getAccessibleComponent() {
2196        return ac.getAccessibleComponent();
2197        }
2198        
2199        /**
2200         * Gets the AccessibleSelection associated with this object which allows its
2201         * Accessible children to be selected.
2202         *
2203         * @return AccessibleSelection if supported by object; else return null
2204         * @see AccessibleSelection
2205         */

2206        public AccessibleSelection getAccessibleSelection() {
2207        return ac.getAccessibleSelection();
2208        }
2209        
2210        /**
2211         * Gets the AccessibleText associated with this object presenting
2212         * text on the display.
2213         *
2214         * @return AccessibleText if supported by object; else return null
2215         * @see AccessibleText
2216         */

2217        public AccessibleText getAccessibleText() {
2218        return ac.getAccessibleText();
2219        }
2220        
2221        /**
2222         * Gets the AccessibleEditableText associated with this object
2223         * presenting editable text on the display.
2224         *
2225         * @return AccessibleEditableText if supported by object; else return null
2226         * @see AccessibleEditableText
2227         */

2228        public AccessibleEditableText getAccessibleEditableText() {
2229        return ac.getAccessibleEditableText();
2230        }
2231        
2232        /**
2233         * Gets the AccessibleValue associated with this object that supports a
2234         * Numerical value.
2235         *
2236         * @return AccessibleValue if supported by object; else return null
2237         * @see AccessibleValue
2238         */

2239        public AccessibleValue getAccessibleValue() {
2240        return ac.getAccessibleValue();
2241        }
2242        
2243        /**
2244         * Gets the AccessibleIcons associated with an object that has
2245         * one or more associated icons
2246         *
2247         * @return an array of AccessibleIcon if supported by object;
2248         * otherwise return null
2249         * @see AccessibleIcon
2250         */

2251        public AccessibleIcon [] getAccessibleIcon() {
2252        return ac.getAccessibleIcon();
2253        }
2254        
2255        /**
2256         * Gets the AccessibleRelationSet associated with an object
2257         *
2258         * @return an AccessibleRelationSet if supported by object;
2259         * otherwise return null
2260         * @see AccessibleRelationSet
2261         */

2262        public AccessibleRelationSet getAccessibleRelationSet() {
2263        return ac.getAccessibleRelationSet();
2264        }
2265        
2266        /**
2267         * Gets the AccessibleTable associated with an object
2268         *
2269         * @return an AccessibleTable if supported by object;
2270         * otherwise return null
2271         * @see AccessibleTable
2272         */

2273        public AccessibleTable getAccessibleTable() {
2274        return ac.getAccessibleTable();
2275        }
2276        
2277        /**
2278         * Support for reporting bound property changes. If oldValue and
2279         * newValue are not equal and the PropertyChangeEvent listener list
2280         * is not empty, then fire a PropertyChange event to each listener.
2281         * In general, this is for use by the Accessible objects themselves
2282         * and should not be called by an application program.
2283         * @param propertyName The programmatic name of the property that
2284         * was changed.
2285         * @param oldValue The old value of the property.
2286         * @param newValue The new value of the property.
2287         * @see java.beans.PropertyChangeSupport
2288         * @see #addPropertyChangeListener
2289         * @see #removePropertyChangeListener
2290         * @see #ACCESSIBLE_NAME_PROPERTY
2291         * @see #ACCESSIBLE_DESCRIPTION_PROPERTY
2292         * @see #ACCESSIBLE_STATE_PROPERTY
2293         * @see #ACCESSIBLE_VALUE_PROPERTY
2294         * @see #ACCESSIBLE_SELECTION_PROPERTY
2295         * @see #ACCESSIBLE_TEXT_PROPERTY
2296         * @see #ACCESSIBLE_VISIBLE_DATA_PROPERTY
2297         */

2298        public void firePropertyChange(String JavaDoc propertyName,
2299                       Object JavaDoc oldValue,
2300                       Object JavaDoc newValue) {
2301        ac.firePropertyChange(propertyName, oldValue, newValue);
2302        }
2303    }
2304
2305    } // innerclass AccessibleJComboBox
2306
}
2307
Popular Tags