KickJava   Java API By Example, From Geeks To Geeks.

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


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.JLabel JavaDoc;
32 import javax.swing.Box JavaDoc;
33 import javax.swing.BoxLayout JavaDoc;
34 import javax.swing.SwingConstants JavaDoc;
35
36 import java.awt.Component JavaDoc;
37 import java.awt.Dimension JavaDoc;
38
39 /** The OMG Trading Service imports. */
40 import org.omg.CosTrading.FollowOption;
41
42 /**
43  * A Box to display a CosTrading FollowOption in a combo box. This
44  * class also provides a way to register a listener in order to be
45  * notified of any change in the combo box.
46  *
47  * @author <a HREF="mailto:Sylvain.Leblanc@lifl.fr">Sylvain Leblanc</a>
48  * @version 0.1
49  */

50 public class FollowOptionBox extends Box JavaDoc {
51
52     // ==================================================================
53
//
54
// Internal state.
55
//
56
// ==================================================================
57

58     /** The combo box. */
59     protected JComboBox JavaDoc options_;
60
61     /** The label of the entry */
62     protected JLabel JavaDoc fieldLabel_;
63
64     // ==================================================================
65
//
66
// Constructors.
67
//
68
// ==================================================================
69

70     /**
71      * Default constructor.
72      *
73      * @param label The label placed behind the combo box.
74      */

75     public FollowOptionBox(String JavaDoc label) {
76         super(BoxLayout.X_AXIS);
77         add(Box.createHorizontalGlue());
78         fieldLabel_ = new JLabel JavaDoc(label, SwingConstants.RIGHT);
79         fieldLabel_.setAlignmentX(Component.RIGHT_ALIGNMENT);
80         fieldLabel_.setAlignmentY(Component.CENTER_ALIGNMENT);
81         add(fieldLabel_);
82         add(Box.createHorizontalStrut(5));
83         options_ = new JComboBox JavaDoc(new String JavaDoc[] {"local_only", "if_no_local", "always"});
84         options_.setPreferredSize(new Dimension JavaDoc(225, 20));
85         options_.setMaximumSize(new Dimension JavaDoc(225, 20));
86         add(options_);
87     }
88
89     /**
90      * Default constructor.
91      *
92      * @param label The label placed behind the combo box.
93      * @param init The initial value of the combo box.
94      */

95     public FollowOptionBox(String JavaDoc label, FollowOption init) {
96         this(label);
97         options_.setSelectedIndex(optionToIndex(init));
98     }
99
100     // ==================================================================
101
//
102
// Internal methods.
103
//
104
// ==================================================================
105

106     /**
107      * Returns the index of the follow option in the combo box.
108      *
109      * @param o The follow option.
110      *
111      * @return The index of the given option.
112      */

113     protected int optionToIndex(FollowOption o) {
114         if (o.value() == FollowOption._local_only) return 0;
115         if (o.value() == FollowOption._if_no_local) return 1;
116         return 2;
117     }
118
119     // ==================================================================
120
//
121
// Public methods.
122
//
123
// ==================================================================
124

125     /**
126      * Returns the specified option.
127      *
128      * @return The option selected in the combo box.
129      */

130     public FollowOption getOption() {
131         String JavaDoc option = (String JavaDoc)options_.getSelectedItem();
132         if (option.equals("local_only")) return FollowOption.local_only;
133         if (option.equals("if_no_local")) return FollowOption.if_no_local;
134         return FollowOption.always;
135     }
136
137     /**
138      * Adds a listener on the combo box.
139      *
140      * @param listener The listener to add in the combo box.
141      */

142     public void addItemListener(java.awt.event.ItemListener JavaDoc listener) {
143         options_.addItemListener(listener);
144     }
145
146     // ==================================================================
147
//
148
// Public methods of Box (since j2sdk-1.4.1 only).
149
//
150
// ==================================================================
151

152     /**
153      * Sets the tool tip text on each JComponent of the box.
154      *
155      * @param text The tool tip text to set.
156      */

157     public void setToolTipText(String JavaDoc text) {
158         options_.setToolTipText(text);
159         fieldLabel_.setToolTipText(text);
160     }
161
162     /**
163      * Gets the tool tip text set on each JComponent of the box.
164      *
165      * @return The tool tip text used.
166      */

167     public String JavaDoc getToolTipText() {
168         return options_.getToolTipText();
169     }
170 }
171
Popular Tags