KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > nqadmin > swingSet > SSComboBox


1 /* $Id: SSComboBox.java,v 1.34 2005/02/21 16:31:29 prasanth Exp $
2  *
3  * Tab Spacing = 4
4  *
5  * Copyright (c) 2003-2005, The Pangburn Company and Prasanth R. Pasala.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions are met:
10  *
11  * Redistributions of source code must retain the above copyright notice, this
12  * list of conditions and the following disclaimer. Redistributions in binary
13  * form must reproduce the above copyright notice, this list of conditions and
14  * the following disclaimer in the documentation and/or other materials
15  * provided with the distribution. The names of its contributors may not be
16  * used to endorse or promote products derived from this software without
17  * specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  *
31  */

32
33 package com.nqadmin.swingSet;
34
35 import java.io.*;
36 import java.sql.*;
37 import java.awt.*;
38 import java.awt.event.*;
39 import javax.swing.*;
40 import javax.swing.border.*;
41 import javax.swing.text.*;
42 import javax.swing.event.*;
43 import java.beans.*;
44 import javax.sql.*;
45 import com.nqadmin.swingSet.datasources.SSRowSet;
46
47 /**
48  * SSComboBox.java
49  *<p>
50  * SwingSet - Open Toolkit For Making Swing Controls Database-Aware
51  *<p><pre>
52  * Provides a way of displaying text corresponding to codes that are stored in
53  * the database. By default the codes start from zero. If you want to provide a
54  * different mapping for the items in the combobox then a string of integers
55  * containing the corresponding numeric values for each choice must be provided.
56  *
57  * Note that if you DO NOT want to use the default mappings, the custom
58  * mappings must be set before calling the bind() method to bind the
59  * combobox to a database column.
60  *
61  * Also, if changing both a sSRowSet and column name consider using the bind()
62  * method rather than individual setSSRowSet() and setColumName() calls.
63  *
64  * e.g.
65  * SSComboBox combo = new SSComboBox();
66  * String[] options = {"111", "2222", "33333"};
67  * combo.setOptions(options);
68  *
69  * For the above items the combobox assumes that the values start from zero:
70  * "111" -> 0, "2222" -> 1, "33333" -> 2
71  *
72  * To give your own mappings you can set the mappings separately or pass
73  * them along with the options:
74  *
75  * SSComboBox combo = new SSComboBox();
76  * String[] options = {"111", "2222", "33333"};
77  * int[] mappings = { 1,5,7 };
78  * combo.setOptions(options, mappings);
79  *
80  * // next line is assuming mysSRowSet has been initialized and my_column is a
81  * // column in mysSRowSet
82  * combo.bind(mysSRowSet,"my_column");
83  *</pre><p>
84  * @author $Author: prasanth $
85  * @version $Revision: 1.34 $
86  */

87 //public class SSComboBox extends JComponent {
88
public class SSComboBox extends JComboBox {
89     
90 /* NOTE: It would probably be best to retool mappings such that they are stored
91          as strings, similar to SSDBComboBox. */

92
93     /**
94      * Value to represent that no item has been selected in the combo box.
95      */

96     public static final int NON_SELECTED = (int)((Math.pow(2, 32) -1)/(-2));
97
98     /**
99      * Text field bound to the SSRowSet.
100      */

101     protected JTextField textField = new JTextField();
102
103     /**
104      * Component listener.
105      */

106     private final MyComboListener cmbListener = new MyComboListener();
107
108     /**
109      * Bound text field document listener.
110      */

111     private final MyTextFieldDocumentListener textFieldDocumentListener = new MyTextFieldDocumentListener();
112
113     /**
114      * Underlying values for each combo box choice if different from defaults
115      * of 0, 1, 2, 3, etc.
116      */

117     protected int[] mappings = null;
118
119     /**
120      * SSRowSet from which component will get/set values.
121      */

122     protected SSRowSet sSRowSet;
123
124     /**
125      * SSRowSet column to which the component will be bound.
126      */

127     protected String JavaDoc columnName = "";
128     
129     /**
130      * Options to be displayed in combo box.
131      */

132     protected String JavaDoc[] options;
133     
134     /**
135      * Code representing of predefined options to be displayed in the combo box
136      * (e.g. yes/no, exclude/include, etc.
137      */

138     protected int predefinedOptions = -1;
139
140     /**
141      * Constant indicating that combo box should display predefined yes/no
142      * options.
143      */

144     public static final int YES_NO_OPTION = 0;
145     
146     /**
147      * Predefined "yes" option.
148      */

149     public static final int YES = 1;
150     
151     /**
152      * Predefined "no" option.
153      */

154     public static final int NO = 0;
155     
156     /**
157      * Constant indicating that combo box should display predefined gender
158      * options.
159      */

160     public static final int GENDER_OPTION = 1;
161     
162    /**
163      * Predefined "male" option.
164      */

165     public static final int MALE = 0;
166     
167     /**
168      * Predefined "female" option.
169      */

170     public static final int FEMALE = 1;
171     
172     /**
173      * Predefined "unisex" option.
174      */

175     public static final int UNISEX = 2;
176
177     /**
178      * Constant indicating that combo box should display predefined
179      * include/exclude options.
180      */

181     public static final int INCLUDE_EXCLUDE_OPTION = 2;
182     
183     /**
184      * Predefined "exclude" option.
185      */

186     public static final int EXCLUDE = 0;
187     
188     /**
189      * Predefined "include" option.
190      */

191     public static final int INCLUDE = 1;
192     
193     /**
194      * Creates an object of SSComboBox.
195      */

196     public SSComboBox() {
197         init();
198     }
199
200     /**
201      * Sets the value stored in the component.
202      *
203      * Currently not a bean property since there is no associated variable.
204      *
205      * @param _value value to assign to combo box
206      */

207     public void setSelectedValue(int _value) {
208         textField.setText(String.valueOf(_value));
209     }
210
211     /**
212      * Returns the combo box value associated with the currently selected item.
213      *
214      * Currently not a bean property since there is no associated variable.
215      *
216      * @return returns the value associated with the selected item OR -1 if
217      * nothing is selected.
218      */

219     public int getSelectedValue() {
220         //if (cmbDisplayed.getSelectedIndex() == -1) {
221
if (getSelectedIndex() == -1) {
222             return NON_SELECTED;
223         }
224
225         if (mappings != null) {
226             //return mappings[cmbDisplayed.getSelectedIndex()];
227
return mappings[getSelectedIndex()];
228         }
229         //return cmbDisplayed.getSelectedIndex();
230
return getSelectedIndex();
231
232     }
233     
234     /**
235      * Sets the SSRowSet column name to which the component is bound.
236      *
237      * @param _columnName column name in the SSRowSet to which the component
238      * is bound
239      */

240     public void setColumnName(String JavaDoc _columnName) {
241         String JavaDoc oldValue = columnName;
242         columnName = _columnName;
243         firePropertyChange("columnName", oldValue, columnName);
244         bind();
245     }
246
247     /**
248      * Returns the column name to which the combo is bound.
249      *
250      * @return returns the column name to which to combo box is bound.
251      */

252     public String JavaDoc getColumnName() {
253         return columnName;
254     }
255     
256     /**
257      * Sets the SSRowSet to which the component is bound.
258      *
259      * @param _sSRowSet SSRowSet to which the component is bound
260      */

261     public void setSSRowSet(SSRowSet _sSRowSet) {
262         SSRowSet oldValue = sSRowSet;
263         sSRowSet = _sSRowSet;
264         firePropertyChange("sSRowSet", oldValue, sSRowSet);
265         bind();
266     }
267
268     /**
269      * Returns the SSRowSet being used to get the values.
270      *
271      * @return returns the SSRowSet being used.
272      */

273     public SSRowSet getSSRowSet() {
274         return sSRowSet;
275     }
276     
277     /**
278      * Sets the underlying values for each of the items in the combo box
279      * (e.g. the values that map to the items displayed in the combo box)
280      *
281      * @param _mappings an array of values that correspond to those in the combo box.
282      */

283     public void setMappings(int[] _mappings) {
284         int[] oldValue = (int[])_mappings.clone();
285         mappings = (int[])_mappings.clone();
286         firePropertyChange("mappings", oldValue, mappings);
287         // INITIALIZE THE ARRAY AND COPY THE MAPPING VALUES
288
//mappings = new int[_mappings.length];
289
//for (int i=0;i<_mappings.length;i++) {
290
// mappings[i] = _mappings[i];
291
//}
292
}
293     
294     /**
295      * Returns the underlying values for each of the items in the combo box
296      * (e.g. the values that map to the items displayed in the combo box)
297      *
298      * @return returns the underlying values for each of the items in the combo box
299      */

300     public int[] getMappings() {
301         return mappings;
302     }
303     
304     /**
305      * Adds an array of strings as combo box items.
306      *
307      * @param _options the list of options that you want to appear in the combo box.
308      */

309     public void setOptions(String JavaDoc[] _options) {
310         String JavaDoc[] oldValue = (String JavaDoc[])_options.clone();
311         options = (String JavaDoc[])_options.clone();
312         firePropertyChange("options", oldValue, options);
313             
314         // ADD THE SPECIFIED ITEMS TO THE COMBO BOX
315
// REMOVE ANY OLD ITEMS SO THAT MULTIPLE CALLS TO THIS FUNCTION DOES NOT AFFECT
316
// THE DISPLAYED ITEMS
317
if (getItemCount() != 0) {
318                 removeAllItems();
319             }
320             for (int i=0;i<_options.length;i++) {
321                 addItem(_options[i]);
322             }
323     }
324
325     /**
326      * Returns the items displayed in the combo box.
327      *
328      * @return returns the items displayed in the combo box
329      */

330     public String JavaDoc[] getOptions() {
331         return options;
332 // if developer is adding items with addItem() then options won't have the data
333
// may be better to loop through all items and return that way...
334
}
335
336     /**
337      * Sets the options to be displayed in the combo box and their corresponding values.
338      *
339      * @param _options options to be displayed in the combo box.
340      * @param _mappings integer values that correspond to the options in the combo box.
341      *
342      * @return returns true if the options and mappings are set successfully -
343      * returns false if the size of arrays do not match or if the values could
344      * not be set
345      */

346     public boolean setOptions(String JavaDoc[] _options, int[]_mappings) {
347         if (_options.length != _mappings.length) {
348             return false;
349         }
350         
351         setOptions(_options);
352         
353         setMappings(_mappings);
354         
355         return true;
356         
357         //options = _options;
358
//options = (int[])_options.clone();
359

360         // REMOVE ANY OLD ITEMS SO THAT MULTIPLE CALLS TO THIS FUNCTION DOES NOT AFFECT
361
// THE DISPLAYED ITEMS
362
//if (getItemCount() != 0) {
363
// removeAllItems();
364
//}
365
// ADD THE ITEMS TO THE COMBOBOX
366
//for (int i=0;i<_options.length;i++) {
367
// addItem(_options[i]);
368
//}
369
// COPY THE MAPPING VALUES
370
//mappings = new int[_mappings.length];
371
//for (int i=0;i<_mappings.length;i++) {
372
// mappings[i] = _mappings[i];
373
//}
374
//mappings = (int[])_mappings.clone();
375

376         //return true;
377
}
378
379     /**
380      * Sets the options to be displayed in the combo box based on common
381      * predefined options.
382      *
383      * @param _predefinedOptions predefined options to be displayed in the combo box.
384      */

385     public boolean setPredefinedOptions(int _predefinedOptions) {
386         int oldValue = predefinedOptions;
387         
388         if (_predefinedOptions == YES_NO_OPTION) {
389             setOptions(new String JavaDoc[]{"No", "Yes"});
390         } else if (_predefinedOptions == SEX_OPTION || _predefinedOptions == GENDER_OPTION) {
391             setOptions(new String JavaDoc[]{"Male", "Female", "Unisex"});
392         } else if (_predefinedOptions == INCLUDE_EXCLUDE_OPTION) {
393             setOptions(new String JavaDoc[]{"Include", "Exclude"});
394         } else {
395             return false;
396         }
397         
398         predefinedOptions = _predefinedOptions;
399         firePropertyChange("predefinedOptions", oldValue, predefinedOptions);
400         
401         return true;
402     
403     
404 /*
405         
406         if (getItemCount() != 0) {
407             removeAllItems();
408         }
409         if (_predefinedOptions == YES_NO_OPTION) {
410             addItem(new String("No"));
411             addItem(new String("Yes"));
412             options = new String[]{"No", "Yes"};
413         } else if (_predefinedOptions == SEX_OPTION || _predefinedOptions == GENDER_OPTION) {
414             addItem(new String("Male"));
415             addItem(new String("Female"));
416             addItem(new String("Unisex"));
417             options = new String[]{"Male", "Female", "Unisex"};
418         } else if (_predefinedOptions == INCLUDE_EXCLUDE_OPTION) {
419             addItem(new String("Include"));
420             addItem(new String("Exclude"));
421             options = new String[]{"Include", "Exclude"};
422         } else {
423             return false;
424         }
425         
426         predefinedOptions = _predefinedOptions;
427
428         return true;
429 */

430     }
431     
432     /**
433      * Returns the option code used to display predefined options in the
434      * combo box.
435      *
436      * @return returns the predefined option code
437      */

438     public int getPredefinedOptions() {
439         return predefinedOptions;
440     }
441
442     /**
443      * Sets the SSRowSet and column name to which the component is to be bound.
444      *
445      * @param _sSRowSet datasource to be used.
446      * @param _columnName Name of the column to which this check box should be bound
447      */

448     public void bind(SSRowSet _sSRowSet, String JavaDoc _columnName) {
449         SSRowSet oldValue = sSRowSet;
450         sSRowSet = _sSRowSet;
451         firePropertyChange("sSRowSet", oldValue, sSRowSet);
452         
453         String JavaDoc oldValue2 = columnName;
454         columnName = _columnName;
455         firePropertyChange("columnName", oldValue2, columnName);
456         
457         bind();
458     }
459     
460     /**
461      * Initialization code.
462      */

463     protected void init() {
464         // ADD KEY LISTENER TO TRANSFER FOCUS TO NEXT ELEMENT WHEN ENTER
465
// KEY IS PRESSED.
466
addKeyListener(new KeyAdapter() {
467                 public void keyReleased(KeyEvent ke) {
468                     if (ke.getKeyCode() == KeyEvent.VK_ENTER) {
469                         ((Component)ke.getSource()).transferFocus();
470                     }
471                 }
472             });
473             
474         // SET PREFERRED DIMENSIONS
475
setPreferredSize(new Dimension(200,20));
476     }
477
478     /**
479      * Method for handling binding of component to a SSRowSet column.
480      */

481     protected void bind() {
482         
483         // CHECK FOR NULL COLUMN/ROWSET
484
if (columnName==null || columnName.trim().equals("") || sSRowSet==null) {
485                 return;
486             }
487             
488         // REMOVE LISTENERS TO PREVENT DUPLICATION
489
removeListeners();
490
491         // BIND THE TEXT FIELD TO THE SPECIFIED COLUMN
492
textField.setDocument(new SSTextDocument(sSRowSet, columnName));
493
494         // SET THE COMBO BOX ITEM DISPLAYED
495
updateDisplay();
496
497         // ADD BACK LISTENERS
498
addListeners();
499                
500     }
501
502     /**
503      * Updates the value displayed in the component based on the SSRowSet column
504      * binding.
505      */

506     protected void updateDisplay() {
507         try {
508             String JavaDoc text = textField.getText().trim();
509             // GET THE INTEGER EQUIVALENT OF THE TEXT IN THE TEXT FIELD
510
int intValue = 0;
511             if ( !(text.trim().equals("")) ) {
512                 intValue = Integer.parseInt(text);
513             }
514             // CHECK IF THE VALUE DISPLAYED IS THE SAME AS THAT IN TEXT FIELD
515
// TWO CASES 1. THE MAPPINGS FOR THE STRINGS DISPLAYED ARE GIVEN BY USER
516
// 2. VALUES FOR THE ITEMS IN COMBO START FROM ZERO
517
// IN CASE ONE: YOU CAN JUST CHECK FOR EQUALITY OF THE SELECTEDINDEX AND VALUE IN TEXT FIELD
518
// IN CASE TWO: YOU HAVE TO CHECK IF THE VALUE IN THE MAPPINGVALUES ARRAY AT INDEX EQUAL
519
// TO THE SELECTED INDEX OF THE COMBO BOX EQUALS THE VALUE IN TEXT FIELD
520
// IF THESE CONDITIONS ARE MET YOU NEED NOT CHANGE COMBO BOX SELECTED ITEM
521
if ( (mappings==null && intValue != getSelectedIndex()) ||
522                  (mappings!=null && getSelectedIndex() == -1) ||
523                  (mappings!=null && mappings[getSelectedIndex()] != intValue) ) {
524
525                 if (mappings==null && (intValue <0 || intValue >= getItemCount() )) {
526                 // IF EXPLICIT VALUES FOR THE ITEMS IN COMBO ARE NOT SPECIFIED THEN CODES START
527
// FROM ZERO. IN SUCH A CASE CHECK IF THE NUMBER EXCEEDS THE NUMBER OF ITEMS
528
// IN COMBO BOX (THIS IS ERROR CONDITION SO NOTIFY USER)
529
System.out.println("Error: value from DB:" + intValue + " items in combo box: " + getItemCount());
530                     setSelectedIndex(-1);
531                 } else {
532                 // IF MAPPINGS ARE SPECIFIED THEN GET THE INDEX AT WHICH THE VALUE IN TEXT FIELD
533
// APPEARS IN THE MAPPINGVALUES ARRAY. SET THE SELECTED ITEM OF COMBO SO THAT INDEX
534
if (mappings!=null) {
535                         int i=0;
536                         for (;i<mappings.length;i++) {
537                             if (mappings[i] == intValue) {
538                                 setSelectedIndex(i);
539                                 break;
540                             }
541                         }
542                         // IF THAT VALUE IS NOT FOUND IN THE GIVEN MAPPING VALUES PRINT AN ERROR MESSAGE
543
if (i==mappings.length) {
544                             System.out.println("change ERROR: could not find a corresponding item in combo for value " + intValue);
545                             setSelectedIndex(-1);
546                         }
547                     } else {
548                     // IF MAPPINGS ARE NOT SPECIFIED SET THE SELECTED ITEM AS THE ITEM AT INDEX
549
// EQUAL TO THE VALUE IN TEXT FIELD
550
setSelectedIndex(intValue);
551                     }
552                 }
553             }
554
555         } catch(NumberFormatException JavaDoc nfe) {
556             nfe.printStackTrace();
557         }
558
559     }
560     
561     /**
562      * Adds listeners for component and bound text field (where applicable).
563      */

564     private void addListeners() {
565         textField.getDocument().addDocumentListener(textFieldDocumentListener);
566         addActionListener(cmbListener);
567     }
568
569     /**
570      * Removes listeners for component and bound text field (where applicable).
571      */

572     private void removeListeners() {
573         textField.getDocument().removeDocumentListener(textFieldDocumentListener);
574         removeActionListener(cmbListener);
575     }
576
577     /**
578      * Listener(s) for the bound text field used to propigate values back to the
579      * component's value.
580      */

581     private class MyTextFieldDocumentListener implements DocumentListener, Serializable {
582
583         public void changedUpdate(DocumentEvent de) {
584             removeActionListener(cmbListener);
585             updateDisplay();
586             addActionListener(cmbListener);
587         } // end public void changedUpdate(DocumentEvent de)
588

589         public void insertUpdate(DocumentEvent de) {
590             removeActionListener(cmbListener);
591             updateDisplay();
592             addActionListener(cmbListener);
593         } // end public void insertUpdate(DocumentEvent de)
594

595         public void removeUpdate(DocumentEvent de) {
596
597         /* Nothing to do here....*/
598
599         }
600     }
601
602     /**
603      * Listener(s) for the component's value used to propigate changes back to
604      * bound text field.
605      */

606     private class MyComboListener implements ActionListener, Serializable {
607
608         public void actionPerformed(ActionEvent ae) {
609             textField.getDocument().removeDocumentListener(textFieldDocumentListener);
610             int index = getSelectedIndex();
611             try {
612                 if (index == -1) {
613                     textField.setText("");
614                 } else {
615                     String JavaDoc strValueInText = textField.getText();
616                     int valueOfText = -1;
617                     strValueInText = strValueInText.trim();
618                     if ( !strValueInText.equals("") ) {
619                         valueOfText = Integer.parseInt(strValueInText);
620                     }
621
622                     if ( mappings == null && valueOfText != index ) {
623                         textField.setText( String.valueOf(index) );
624                     }
625                     else if(mappings != null && mappings.length > index && valueOfText != mappings[index]){
626                         textField.setText(String.valueOf(mappings[index]));
627                     }
628                 }
629             } catch(NullPointerException JavaDoc npe) {
630                 npe.printStackTrace();
631             } catch(NumberFormatException JavaDoc nfe) {
632                 nfe.printStackTrace();
633             }
634             textField.getDocument().addDocumentListener(textFieldDocumentListener);
635         }
636     }
637
638
639
640 // DEPRECATED STUFF....................
641
/**
642      * Constant indicating that combo box should display predefined gender
643      * options.
644      *
645      * @deprecated
646      * @see #GENDER_OPTION
647      */

648     public static final int SEX_OPTION = 1;
649     
650     /**
651      * Predefined "unisex" option.
652      *
653      * @deprecated
654      * @see #UNISEX
655      */

656     public static final int UNI_SEX = 2;
657
658     /**
659      * Creates an instance of SSComboBox and sets the text field with which the combo
660      * box will be synchronized with.
661      *
662      * @deprecated
663      */

664     public SSComboBox(SSTextDocument document) {
665
666         //super();
667
init();
668         //addComponent();
669

670         this.setDocument(document);
671     }
672
673     /**
674      * Sets the document to which the combo box will be bound to. Changes to this
675      * will immediately reflect in the combo box.
676      *
677      * @param _document text document to which the combo box has to be bound
678      *
679      * @deprecated
680      * @see #bind
681      */

682     public void setDocument(SSTextDocument _document) {
683             textField.setDocument(_document);
684             updateDisplay();
685         // NEEDED, IF THIS FUNCTION IS CALLED MORE THAN ONCE.
686
// SO THAT WE DON'T STACK UP LISTENERS AS THE NUMBER OF CALLS TO THIS
687
// FUNCTION INCREASES
688
removeListeners();
689             addListeners();
690     }
691
692     /**
693      * returns the combo box that has to be displayed on screen.
694      *
695      * @return returns the combo box that displays the items.
696      *
697      * @deprecated
698      */

699     public JComboBox getComboBox() {
700         return this;
701     }
702
703     /**
704      * Returns the combo box to be displayed on the screen.
705      *
706      * @return returns the combo box that displays the items.
707      *
708      * @deprecated
709      */

710     public Component getComponent() {
711         return this;
712     }
713     
714     /**
715      * Adds an array of strings as combo box items.
716      *
717      * @param _options the list of options that you want to appear in the combo box.
718      *
719      * @return returns true if the options and mappings are set successfully -
720      * returns false if the size of arrays do not match or if the values could
721      * not be set
722      *
723      * @deprecated
724      * @see #setOptions
725      */

726     public boolean setOption(String JavaDoc[] _options) {
727         setOptions(_options);
728         return true;
729     }
730     
731     /**
732      * Sets the options to be displayed in the combo box and their corresponding values.
733      *
734      * @param _options options to be displayed in the combo box.
735      * @param _mappings integer values that correspond to the options in the combo box.
736      *
737      * @return returns true if the options and mappings are set successfully -
738      * returns false if the size of arrays do not match or if the values could
739      * not be set
740      *
741      * @deprecated
742      * @see #setOptions
743      */

744     public boolean setOption(String JavaDoc[] _options, int[]_mappings) {
745         return setOptions(_options, _mappings);
746     }
747
748     /**
749      * Sets the options to be displayed in the combo box and their corresponding values.
750      *
751      * @param _options predefined options to be displayed in the combo box.
752      * @param _mappings integer values that correspond to the options in the combo box.
753      *
754      * @deprecated
755      * @see #setPredefinedOptions
756      * @see #setMappings
757      */

758     public void setOption(int _options, int[]_mappings) throws PropertyVetoException {
759         setPredefinedOptions(_options);
760         setMappings(_mappings);
761     }
762
763     /**
764      * Sets the options to be displayed in the combo box based on common
765      * predefined options.
766      *
767      * @param _option predefined options to be displayed in the combo box.
768      *
769      * @deprecated
770      * @see #setPredefinedOptions
771      */

772     public boolean setOption(int _option) {
773         return setPredefinedOptions(_option);
774     }
775     
776     /**
777      * Sets the underlying values for each of the items in the combo box
778      * (e.g. the values that map to the items displayed in the combo box)
779      *
780      * @param _mappings an array of values that correspond to those in the combo box.
781      *
782      * @deprecated
783      * @see #setMappings
784      */

785     public void setMappingValues(int[] _mappings) {
786         setMappings(_mappings);
787     }
788
789 } // end public class SSComboBox extends JComboBox {
790

791
792
793 /*
794  * $Log: SSComboBox.java,v $
795  * Revision 1.34 2005/02/21 16:31:29 prasanth
796  * In bind checking for empty columnName before binding the component.
797  *
798  * Revision 1.33 2005/02/13 15:38:20 yoda2
799  * Removed redundant PropertyChangeListener and VetoableChangeListener class variables and methods from components with JComponent as an ancestor.
800  *
801  * Revision 1.32 2005/02/11 22:59:25 yoda2
802  * Imported PropertyVetoException and added some bound properties.
803  *
804  * Revision 1.31 2005/02/11 20:15:58 yoda2
805  * Added infrastructure to support property & vetoable change listeners (for beans).
806  *
807  * Revision 1.30 2005/02/10 20:12:54 yoda2
808  * Setter/getter cleanup & method reordering for consistency.
809  *
810  * Revision 1.29 2005/02/10 03:46:47 yoda2
811  * Replaced all setDisplay() methods & calls with updateDisplay() methods & calls to prevent any setter/getter confusion.
812  *
813  * Revision 1.28 2005/02/07 20:36:35 yoda2
814  * Made private listener data members final.
815  *
816  * Revision 1.27 2005/02/07 04:20:13 yoda2
817  * JavaDoc cleanup.
818  *
819  * Revision 1.26 2005/02/04 22:48:52 yoda2
820  * API cleanup & updated Copyright info.
821  *
822  * Revision 1.25 2005/02/03 23:50:56 prasanth
823  * 1. Removed commented out code.
824  * 2. Modified setDisplay function to change value only when underlying value
825  * does not match with that displayed.
826  * 3. Using setDisplay in document listener.
827  *
828  * Revision 1.24 2005/02/02 23:36:58 yoda2
829  * Removed setMaximiumSize() calls.
830  *
831  * Revision 1.23 2005/01/19 20:54:43 yoda2
832  * API cleanup.
833  *
834  * Revision 1.22 2005/01/19 03:15:44 yoda2
835  * Got rid of setBinding and retooled public/private bind() methods and how they are called.
836  *
837  * Revision 1.21 2005/01/18 22:27:24 yoda2
838  * Changed to extend JComboBox rather than JComponent. Deprecated bind(), setSSRowSet(), & setColumnName().
839  *
840  * Revision 1.20 2004/11/11 14:45:48 yoda2
841  * Using TextPad, converted all tabs to "soft" tabs comprised of four actual spaces.
842  *
843  * Revision 1.19 2004/11/01 15:53:30 yoda2
844  * Fixed various JavaDoc errors.
845  *
846  * Revision 1.18 2004/10/25 23:09:01 prasanth
847  * In setOption using the class variable rather than function argument.
848  *
849  * Revision 1.17 2004/10/25 22:03:18 yoda2
850  * Updated JavaDoc for new datasource abstraction layer in 0.9.0 release.
851  *
852  * Revision 1.16 2004/10/25 19:51:02 prasanth
853  * Modified to use the new SSRowSet instead of RowSet.
854  *
855  * Revision 1.15 2004/09/21 18:57:47 prasanth
856  * Added Unisex as an option.
857  *
858  * Revision 1.14 2004/09/21 14:14:14 prasanth
859  * Swapped the codes for FEMALE & MALE.
860  *
861  * Revision 1.13 2004/09/13 15:41:25 prasanth
862  * Added a constant to indicate that there is no selection in combobox.
863  * This value will be returned when the selected index in combo box is -1.
864  *
865  * Revision 1.12 2004/09/02 16:20:17 prasanth
866  * Added support for mapping values in setDisplay function.
867  * Combo Listener was not handling mapping values so added that.
868  *
869  * Revision 1.11 2004/08/12 23:51:16 prasanth
870  * Updating the value to null if the selected index is -1.
871  *
872  * Revision 1.10 2004/08/10 22:06:59 yoda2
873  * Added/edited JavaDoc, made code layout more uniform across classes, made various small coding improvements suggested by PMD.
874  *
875  * Revision 1.9 2004/08/09 21:31:13 prasanth
876  * Corrected wrong function call. removeAll() --> removeAllItems()
877  *
878  * Revision 1.8 2004/08/09 15:37:36 prasanth
879  * 1. Removing elements in the combo before adding any new one.
880  * 2. Added key listener to transfer focus on enter key.
881  *
882  * Revision 1.7 2004/08/02 14:41:10 prasanth
883  * 1. Added set methods for sSRowSet, columnname, selectedvalue.
884  * 2. Added get methods for sSRowSet, columname.
885  * 3. Added addComponent and removeListener functions (private).
886  *
887  * Revision 1.6 2004/03/08 16:43:37 prasanth
888  * Updated copy right year.
889  *
890  * Revision 1.5 2004/02/23 16:39:35 prasanth
891  * Added GENDER_OPTION.
892  *
893  * Revision 1.4 2003/12/16 18:01:40 prasanth
894  * Documented versions for release 0.6.0
895  *
896  * Revision 1.3 2003/10/31 16:04:44 prasanth
897  * Added method getSelectedIndex() and getSelectedValue().
898  *
899  * Revision 1.2 2003/09/25 14:27:45 yoda2
900  * Removed unused Import statements and added preformatting tags to JavaDoc descriptions.
901  *
902  * Revision 1.1.1.1 2003/09/25 13:56:43 yoda2
903  * Initial CVS import for SwingSet.
904  *
905  */
Popular Tags