KickJava   Java API By Example, From Geeks To Geeks.

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


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 javax.swing.JTextField JavaDoc;
30 import javax.swing.JLabel JavaDoc;
31 import javax.swing.Box JavaDoc;
32 import javax.swing.SwingConstants JavaDoc;
33
34 import org.objectweb.util.explorer.swing.gui.api.ValidateReport;
35
36 import java.awt.Component JavaDoc;
37 import java.awt.Dimension JavaDoc;
38
39 /**
40  * This class represents the panel which allow to specify a label
41  *
42  * @author <a HREF="mailto:Jerome.Moroy@lifl.fr">Jerome Moroy</a>
43  * @version 0.1
44  */

45 public class LabelBox
46     extends AbstractElementBox{
47
48     /** The value of the label */
49     protected String JavaDoc label_;
50
51     /** The name of the entry */
52     protected JTextField JavaDoc name_;
53     
54     /**
55      * Default constructor
56      * @param label The label of the box, it is use to display information and to display error message.
57      */

58     public LabelBox(String JavaDoc label) {
59         this(label,true);
60     }
61
62     /**
63      * Constructor with params
64      * @param label The label
65      * @param isMandatory If the value is mandatory : TRUE, else : FALSE
66      */

67     public LabelBox(String JavaDoc label, boolean isMandatory) {
68         super(isMandatory);
69         label_ = label;
70         add(Box.createHorizontalGlue());
71         JLabel JavaDoc fieldLabel = new JLabel JavaDoc(label_ + ": ", SwingConstants.RIGHT);
72         fieldLabel.setAlignmentX(Component.RIGHT_ALIGNMENT);
73         fieldLabel.setAlignmentY(Component.CENTER_ALIGNMENT);
74         add(fieldLabel);
75         add(Box.createHorizontalStrut(5));
76         name_ = new JTextField JavaDoc();
77         name_.setPreferredSize(new Dimension JavaDoc(225, 20));
78         name_.setMaximumSize(new Dimension JavaDoc(225, 20));
79         add(name_);
80     }
81
82     /**
83      * Constructor with params
84      * @param label
85      * @param defaultValue
86      */

87     public LabelBox(String JavaDoc label, String JavaDoc defaultValue){
88         this(label, defaultValue, true);
89     }
90
91     /**
92      * Constructor with params
93      * @param label
94      * @param defaultValue
95      * @param isMandatory
96      */

97     public LabelBox(String JavaDoc label, String JavaDoc defaultValue, boolean isMandatory){
98         this(label, isMandatory);
99         name_.setText(defaultValue);
100     }
101
102     // ==================================================================
103
//
104
// Public methods for ElementBox.
105
//
106
// ==================================================================
107

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

112     public ValidateReport validateBox(){
113         if(isMandatory_){
114             if(name_.getText()==null||name_.getText().equals(""))
115                 return new DefaultValidateReport(false,"The \"" + label_ + "\" value is mandatory");
116         }
117         return new DefaultValidateReport();
118     }
119     
120     /**
121      * Returns the Box contains by the ElementBox.
122      * @return The Box contains by the ElementBox.
123      */

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

134     /** Returns the specify label */
135     public String JavaDoc getLabel() {
136         return name_.getText();
137     }
138
139 }
140
Popular Tags