KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*===========================================================================
2
3 ObjectWeb Naming Context Framework
4 Copyright (C) 2002 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.
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.JTextField JavaDoc;
34 import javax.swing.JLabel JavaDoc;
35 import javax.swing.Box JavaDoc;
36 import javax.swing.SwingConstants JavaDoc;
37
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 LabelBox
48     extends AbstractElementBox{
49
50     /** The value of the label */
51     protected String JavaDoc label_;
52
53     /** The name of the entry */
54     protected JTextField JavaDoc name_;
55     
56     /**
57      * Default constructor
58      * @param label The label of the box, it is use to display information and to display error message.
59      */

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

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

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

99     public LabelBox(String JavaDoc label, String JavaDoc defaultValue, boolean isMandatory){
100         this(label, isMandatory);
101         name_.setText(defaultValue);
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         if(isMandatory_){
116             if(name_.getText()==null||name_.getText().equals(""))
117                 return new DefaultValidateReport(false,"The \"" + label_ + "\" value is mandatory");
118         }
119         return new DefaultValidateReport();
120     }
121     
122     /**
123      * Returns the Box contains by the ElementBox.
124      * @return The Box contains by the ElementBox.
125      */

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

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