KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > util > browser > gui > lib > BooleanBox


1 /*===========================================================================
2
3 ObjectWeb Naming Context Framework
4 Copyright (C) 2002 USTL - LIFL - GOAL
5 Contact: architecture@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): Jerome Moroy.
23 Contributor(s): ______________________________________.
24
25 ===========================================================================*/

26
27 package org.objectweb.util.browser.gui.lib;
28
29 /** The Browser API's imports */
30 import org.objectweb.util.browser.gui.api.ValidateReport;
31
32 /** The java API's imports */
33 import javax.swing.JRadioButton JavaDoc;
34 import javax.swing.ButtonGroup JavaDoc;
35 import javax.swing.JLabel JavaDoc;
36 import javax.swing.Box JavaDoc;
37 import javax.swing.SwingConstants JavaDoc;
38 import java.awt.Component JavaDoc;
39 import java.awt.Dimension JavaDoc;
40
41 /**
42  * This class represents the panel which allow to specify a label
43  *
44  * @author <a HREF="mailto:Jerome.Moroy@lifl.fr">Jerome Moroy</a>
45  * @version 0.1
46  */

47 public class BooleanBox
48     extends AbstractElementBox{
49
50    //==================================================================
51
//
52
// Internal states.
53
//
54
//==================================================================
55

56     protected ButtonGroup JavaDoc group_ = null;
57
58     //==================================================================
59
//
60
// Constructors.
61
//
62
//==================================================================
63

64     /**
65      * Default constructor
66      */

67     public BooleanBox(String JavaDoc label) {
68         this(label, "True","False", true);
69     }
70         
71     /**
72      * Default constructor
73      */

74     public BooleanBox(String JavaDoc label, String JavaDoc trueLabel, String JavaDoc falseLabel, boolean defaultValue) {
75         JRadioButton JavaDoc trueButton, falseButton;
76         add(Box.createHorizontalGlue());
77         JLabel JavaDoc fieldLabel = new JLabel JavaDoc(label + ": ", SwingConstants.RIGHT);
78         fieldLabel.setAlignmentX(Component.RIGHT_ALIGNMENT);
79         fieldLabel.setAlignmentY(Component.CENTER_ALIGNMENT);
80         add(fieldLabel);
81         add(Box.createHorizontalStrut(5));
82         trueButton = new JRadioButton JavaDoc(trueLabel);
83         trueButton.setActionCommand("true");
84         if(defaultValue)
85             trueButton.setSelected(true);
86         trueButton.setPreferredSize(new Dimension JavaDoc(110, 20));
87         trueButton.setMaximumSize(new Dimension JavaDoc(110, 20));
88         add(trueButton);
89         add(Box.createHorizontalStrut(5));
90         falseButton = new JRadioButton JavaDoc(falseLabel);
91         falseButton.setActionCommand("false");
92         if(!defaultValue)
93             falseButton.setSelected(true);
94         falseButton.setPreferredSize(new Dimension JavaDoc(110, 20));
95         falseButton.setMaximumSize(new Dimension JavaDoc(110, 20));
96         add(falseButton);
97         
98         group_ = new ButtonGroup JavaDoc();
99         group_.add(trueButton);
100         group_.add(falseButton);
101         
102     }
103
104     // ==================================================================
105
//
106
// Public methods for ElementBox.
107
//
108
// ==================================================================
109

110     /**
111      * Validates the content of the ElementBox. Indicates if the different value are acceptables or not.
112      * @return The corresponding ValidateReport.
113      */

114     public ValidateReport validateBox(){
115         return new DefaultValidateReport();
116     }
117     
118     /**
119      * Returns the Box contains by the ElementBox.
120      * @return The Box contains by the ElementBox.
121      */

122     public Box JavaDoc getBox(){
123         return this;
124     }
125
126     // ==================================================================
127
//
128
// Public methods.
129
//
130
// ==================================================================
131

132     /** Returns the specify label */
133     public boolean getValue() {
134         return group_.getSelection().getActionCommand().equals("true");
135     }
136
137 }
138
Popular Tags