KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > openccm > explorer > CosTrading > gui > BooleanBox


1 /*===========================================================================
2
3 OpenCCM: The Open CORBA Component Model Platform
4 Copyright (C) 2000-2003 INRIA - USTL - LIFL - GOAL
5 Contact: openccm@objectweb.org
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 USA
21
22 Initial developer(s):Sylvain Leblanc.
23 Contributor(s): ______________________________________.
24
25 ===========================================================================*/

26
27 package org.objectweb.openccm.explorer.CosTrading.gui;
28
29 /** The Java API's imports */
30 import javax.swing.JComboBox JavaDoc;
31 import javax.swing.SwingConstants JavaDoc;
32 import javax.swing.BoxLayout JavaDoc;
33 import javax.swing.Box JavaDoc;
34 import javax.swing.JLabel JavaDoc;
35
36 import java.awt.Component JavaDoc;
37 import java.awt.Dimension JavaDoc;
38
39 /**
40  * A Box to display a boolean value in a combo box. This class also
41  * provides a way to register a listener in order to be notified of
42  * any change in the combo box.
43  *
44  * @author <a HREF="mailto:Sylvain.Leblanc@lifl.fr">Sylvain Leblanc</a>
45  * @version 0.1
46  */

47 public class BooleanBox extends Box JavaDoc {
48
49     // ==================================================================
50
//
51
// Internal state.
52
//
53
// ==================================================================
54

55     /** The combo box */
56     protected JComboBox JavaDoc bool_combo_;
57
58     /** The label of the entry */
59     protected JLabel JavaDoc fieldLabel_;
60
61     // ==================================================================
62
//
63
// Constructors.
64
//
65
// ==================================================================
66

67     /**
68      * Default constructor.
69      *
70      * @param label The label puts behind the combo box.
71      * @param init The initial value.
72      */

73     public BooleanBox(String JavaDoc label, boolean init) {
74         super(BoxLayout.X_AXIS);
75         add(Box.createHorizontalGlue());
76         fieldLabel_ = new JLabel JavaDoc(label, SwingConstants.RIGHT);
77         fieldLabel_.setAlignmentX(Component.RIGHT_ALIGNMENT);
78         fieldLabel_.setAlignmentY(Component.CENTER_ALIGNMENT);
79         add(fieldLabel_);
80         add(Box.createHorizontalStrut(5));
81         bool_combo_ = new JComboBox JavaDoc(new String JavaDoc[] {"true", "false"});
82         bool_combo_.setSelectedIndex(init?0:1);
83         bool_combo_.setPreferredSize(new Dimension JavaDoc(225, 20));
84         bool_combo_.setMaximumSize(new Dimension JavaDoc(225, 20));
85         add(bool_combo_);
86     }
87
88     /**
89      * Default constructor with initial value at <code>true</code>.
90      *
91      * @param label The label puts behind the combo box.
92      */

93     public BooleanBox(String JavaDoc label) {
94         this(label, true);
95     }
96
97     // ==================================================================
98
//
99
// Internal methods.
100
//
101
// ==================================================================
102

103     // ==================================================================
104
//
105
// Public methods.
106
//
107
// ==================================================================
108

109     /**
110      * Adds a listener on the combo box.
111      *
112      * @param listener The listener to add in the combo box.
113      */

114     public void addItemListener(java.awt.event.ItemListener JavaDoc listener) {
115         bool_combo_.addItemListener(listener);
116     }
117
118     /**
119      * Returns the specified boolean value.
120      *
121      * @return The boolean value selected in the combo box.
122      */

123     public boolean getBoolean() {
124         String JavaDoc bool = (String JavaDoc)bool_combo_.getSelectedItem();
125         if (bool.equals("true")) return true;
126         return false;
127     }
128
129     // ==================================================================
130
//
131
// Public methods of Box (since j2sdk-1.4.1 only).
132
//
133
// ==================================================================
134

135     /**
136      * Sets the tool tip text on each JComponent of the box.
137      *
138      * @param text The tool tip text to set.
139      */

140     public void setToolTipText(String JavaDoc text) {
141         bool_combo_.setToolTipText(text);
142         fieldLabel_.setToolTipText(text);
143     }
144
145     /**
146      * Gets the tool tip text set on each JComponent of the box.
147      *
148      * @return The tool tip text used.
149      */

150     public String JavaDoc getToolTipText() {
151         return bool_combo_.getToolTipText();
152     }
153 }
154
155
Popular Tags