KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > util > explorer > swing > gui > lib > BooleanBox


1 /*====================================================================
2
3 Objectweb Explorer Framework
4 Copyright (C) 2000-2004 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): Jerome Moroy, Philippe Merle.
23 Contributor(s): ______________________________________.
24
25 ====================================================================*/

26
27 package org.objectweb.util.explorer.swing.gui.lib;
28
29 import java.awt.Component JavaDoc;
30 import java.awt.Dimension JavaDoc;
31
32 import javax.swing.Box JavaDoc;
33 import javax.swing.ButtonGroup JavaDoc;
34 import javax.swing.JLabel JavaDoc;
35 import javax.swing.JRadioButton JavaDoc;
36 import javax.swing.SwingConstants JavaDoc;
37
38 import org.objectweb.util.explorer.swing.gui.api.ValidateReport;
39
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      * @param label The label of the property
67      */

68     public BooleanBox(String JavaDoc label) {
69         this(label, "True","False", true);
70     }
71         
72     /**
73      * Default constructor
74      * @param label The label of the property
75      * @param trueLabel The label of the "true" property
76      * @param falseLabel The label of the "false" property
77      * @param defaultValue The checked value
78      */

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

115     /**
116      * Validates the content of the ElementBox. Indicates if the different value are acceptables or not.
117      * @return The corresponding ValidateReport.
118      */

119     public ValidateReport validateBox(){
120         return new DefaultValidateReport();
121     }
122     
123     /**
124      * Returns the Box contains by the ElementBox.
125      * @return The Box contains by the ElementBox.
126      */

127     public Box JavaDoc getBox(){
128         return this;
129     }
130
131     // ==================================================================
132
//
133
// Public methods.
134
//
135
// ==================================================================
136

137     /**
138      * Returns the specify label
139      * @return The value of the boolean box.
140      */

141     public boolean getValue() {
142         return group_.getSelection().getActionCommand().equals("true");
143     }
144
145 }
146
Popular Tags