View Javadoc

1   package org.devaki.nextobjects.ui.components;
2   /*
3   
4   nextobjects Copyright (C) 2001-2005 Emmanuel Florent
5   
6   This program is free software; you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by the
8   Free Software Foundation; either version 2 of the License, or (at your
9   option) any later version.
10  
11  This program is distributed in the hope that it will
12  be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
13  of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14  PURPOSE. See the GNU General Public License for more details.
15  
16  You should have received a copy of the GNU General Public License along
17  with this program; if not, write to the Free Software Foundation, Inc., 59
18  Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19  
20  */
21  import java.util.Vector;
22  import javax.swing.JComboBox;
23  /***
24   * This class overwrite of the 'JComboBox' component
25    * @author     <a href="mailto:eflorent@devaki.org">Emmanuel Florent</a>
26   */
27  public class CustomComboBox extends JComboBox
28  {
29      /***
30       * Create a 'CustomComboBox' object
31       * @param tooltipText Text that appears as a Tool Tip
32       * @param data Vector to fill in the component
33       * @param isEnabled Is the button enabled or not
34       * @param selectedIndex Indicate the initial selected index
35       */
36      public CustomComboBox(
37          final Vector data,
38          final int selectedIndex,
39          final String tooltipText,
40          final boolean isEnabled)
41      {
42          super(data);
43          // Initial selected index
44          this.setSelectedIndex(selectedIndex);
45          // If the parameter 'tooltipText' is not empty, set it as tooltip
46          if (tooltipText.length() != 0)
47          {
48              this.setToolTipText(tooltipText);
49          }
50          // Enable/Disable
51          this.setEnabled(isEnabled);
52      }
53      /***
54       * Create a 'CustomComboBox' object
55       * @param tooltipText Text that appears as a Tool Tip
56       * @param data Array of String objects to fill in the component
57       * @param isEnabled Is the button enabled or not
58       * @param selectedIndex Indicate the initial selected index
59       */
60      public CustomComboBox(
61          final String[] data,
62          final int selectedIndex,
63          final String tooltipText,
64          final boolean isEnabled)
65      {
66          super(data);
67          // Initial selected index
68          this.setSelectedIndex(selectedIndex);
69          // If the parameter 'tooltipText' is not empty, set it as tooltip
70          if (tooltipText.length() != 0)
71          {
72              this.setToolTipText(tooltipText);
73          }
74          // Enable/Disable
75          this.setEnabled(isEnabled);
76      }
77      /***
78       * Create a 'CustomComboBox' object
79       * @param tooltipText Text that appears as a Tool Tip
80       * @param isEnabled Is the button enabled or not
81       */
82      public CustomComboBox(final String tooltipText, final boolean isEnabled)
83      {
84          // If the parameter 'tooltipText' is not empty, set it as tooltip
85          if (tooltipText.length() != 0)
86          {
87              this.setToolTipText(tooltipText);
88          }
89          // Enable/Disable
90          this.setEnabled(isEnabled);
91      }
92      /***
93       * Fill in a 'CustomComboBox' component
94       * @param data Vector that initializes the component
95       */
96      public final void setData(final Vector data)
97      {
98          this.removeAllItems();
99          for (int i = 0; i < data.size(); i++)
100         {
101             this.addItem(data.elementAt(i));
102         }
103     }
104 }