Revision 539 org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.swing/org.gvsig.tools.swing.impl/src/main/java/org/gvsig/tools/swing/impl/dynobject/StatusLabel.java
StatusLabel.java | ||
---|---|---|
33 | 33 |
*/ |
34 | 34 |
package org.gvsig.tools.swing.impl.dynobject; |
35 | 35 |
|
36 |
import java.awt.BorderLayout; |
|
36 | 37 |
import java.awt.Color; |
37 | 38 |
import java.awt.Component; |
38 | 39 |
import java.awt.Font; |
... | ... | |
47 | 48 |
import javax.swing.JLabel; |
48 | 49 |
import javax.swing.JPanel; |
49 | 50 |
import javax.swing.JScrollPane; |
51 |
import javax.swing.JTabbedPane; |
|
50 | 52 |
import javax.swing.SwingConstants; |
51 | 53 |
|
52 | 54 |
import org.gvsig.tools.ToolsLocator; |
... | ... | |
61 | 63 |
* whenever the listener is triggered. |
62 | 64 |
* |
63 | 65 |
* @author 2010 - <a href="cordinyana@gvsig.org">C?sar Ordi?ana</a> - gvSIG Team |
64 |
* @author 2010 - <a href="mailto:reinhold@uji.es">Cristian Mart?n Reinhold</a> - |
|
66 |
* @author 2010 - <a href="mailto:reinhold@uji.es">Cristian Mart?n Reinhold</a> |
|
67 |
* - |
|
65 | 68 |
* gvSIG Team |
66 | 69 |
* @version $Id$ |
67 | 70 |
* |
... | ... | |
88 | 91 |
|
89 | 92 |
private DynField dynField; |
90 | 93 |
|
91 |
public StatusLabel(JDynFieldComponent input, JLabel fieldLabel, DynField dynField) { |
|
94 |
public StatusLabel(JDynFieldComponent input, JLabel fieldLabel, |
|
95 |
DynField dynField) { |
|
92 | 96 |
this.fieldComponent = input; |
93 | 97 |
this.fieldLabel = fieldLabel; |
94 | 98 |
this.dynField = dynField; |
95 |
|
|
96 |
initUI(); |
|
99 |
if (dynField == null){ |
|
100 |
this.dynField = input.getDynField(); |
|
101 |
} |
|
102 |
|
|
103 |
initUI(); |
|
97 | 104 |
} |
98 | 105 |
|
99 | 106 |
private void initUI() { |
... | ... | |
103 | 110 |
validationLabel.setIconTextGap(1); |
104 | 111 |
validationLabel.setText(" "); |
105 | 112 |
validationLabel.setVerticalAlignment(SwingConstants.TOP); |
106 |
|
|
107 |
|
|
113 |
|
|
108 | 114 |
validationMessage = new JLabel(); |
109 | 115 |
validationLabel.setOpaque(true); |
110 | 116 |
validationLabel.setText(""); |
111 | 117 |
validationLabel.setVerticalAlignment(SwingConstants.CENTER); |
112 |
|
|
118 |
|
|
113 | 119 |
fieldLabel.setOpaque(true); |
114 | 120 |
fieldLabel.setHorizontalTextPosition(SwingConstants.LEFT); |
115 | 121 |
fieldLabel.setHorizontalAlignment(SwingConstants.LEFT); |
... | ... | |
125 | 131 |
* @return |
126 | 132 |
*/ |
127 | 133 |
private Icon getIcon(String iconName, String description) { |
128 |
URL res = this.getClass().getResource(iconName);
|
|
129 |
if (res == null){ |
|
134 |
URL res = org.gvsig.tools.swing.impl.dynobject.StatusLabel.class.getResource(iconName);
|
|
135 |
if (res == null) {
|
|
130 | 136 |
return null; |
131 | 137 |
} |
132 | 138 |
String path = res.getPath(); |
... | ... | |
152 | 158 |
public Component getValidationLabel() { |
153 | 159 |
return this.fieldLabel; |
154 | 160 |
} |
155 |
|
|
156 |
public Component getFieldComponent(){ |
|
161 |
|
|
162 |
public Component getFieldComponent() {
|
|
157 | 163 |
JComponent component = this.fieldComponent.asJComponent(); |
158 | 164 |
component.setName(dynField.getName()); |
159 | 165 |
return component; |
160 | 166 |
} |
161 |
|
|
162 |
public Component getValidationPanel() { |
|
167 |
|
|
168 |
public Component getValidationPanel(boolean addScrollPane) {
|
|
163 | 169 |
if (validationPanel == null) { |
164 | 170 |
validationPanel = new JPanel(new GridBagLayout()); |
171 |
validationPanel.setOpaque(true); |
|
165 | 172 |
|
166 |
GridBagConstraints constr = getValidationPanelConstraints(); |
|
167 |
validationPanel.setOpaque(true); |
|
173 |
GridBagConstraints constr = getValidationPanelConstraints(); |
|
174 |
constr.weightx = 0.0; |
|
175 |
constr.weighty = 0.0; |
|
168 | 176 |
|
169 |
constr.weightx = 0.0; |
|
170 |
constr.weighty = 0.0; |
|
171 |
constr.gridx = 0; |
|
172 |
constr.gridy = 1; |
|
173 |
constr.fill = GridBagConstraints.NONE; |
|
174 |
validationPanel.add(validationLabel, constr); |
|
177 |
constr.gridx = 0; |
|
178 |
constr.gridy = 1; |
|
179 |
constr.fill = GridBagConstraints.NONE; |
|
180 |
|
|
181 |
validationPanel.add(validationLabel, constr); |
|
175 | 182 |
|
183 |
constr.weightx = 1.0; |
|
184 |
constr.weighty = 0.0; |
|
185 |
constr.gridx = 0; |
|
186 |
constr.gridy = 0; |
|
187 |
if (this.dynField.getType() == DataTypes.LIST) { |
|
188 |
constr.gridwidth = 3; |
|
176 | 189 |
|
177 |
constr.weightx = 1.0; |
|
178 |
constr.weighty = 0.0; |
|
179 |
constr.gridx = 0; |
|
180 |
constr.gridy = 0; |
|
181 |
if(this.dynField.getType()== DataTypes.LIST){ |
|
182 |
constr.gridwidth=3; |
|
183 |
|
|
184 |
}else{ |
|
185 |
constr.gridwidth=2; |
|
186 |
} |
|
187 |
// constr.fill = GridBagConstraints.RELATIVE; |
|
188 |
constr.fill = GridBagConstraints.BOTH; |
|
189 |
constr.anchor = GridBagConstraints.NORTHWEST; |
|
190 |
validationPanel.add(getFieldComponent(), constr); |
|
190 |
} else { |
|
191 |
constr.gridwidth = 2; |
|
192 |
} |
|
191 | 193 |
|
192 |
constr = new GridBagConstraints(); |
|
193 |
constr.insets = new Insets(1, 2, 2, 2); |
|
194 |
constr.gridx = 1; |
|
195 |
constr.gridy = 1; |
|
196 |
constr.ipadx = 5; |
|
197 |
constr.ipady = 1; |
|
198 |
constr.fill = GridBagConstraints.HORIZONTAL; |
|
199 |
constr.anchor = GridBagConstraints.NORTHWEST; |
|
194 |
constr.gridwidth = 2; |
|
195 |
// constr.fill = GridBagConstraints.RELATIVE; |
|
196 |
constr.fill = GridBagConstraints.BOTH; |
|
197 |
constr.anchor = GridBagConstraints.NORTHWEST; |
|
198 |
|
|
199 |
validationPanel.add(getFieldComponent(), constr); |
|
200 | 200 |
|
201 |
validationPanel.add(validationMessage, constr); |
|
201 |
constr = new GridBagConstraints(); |
|
202 |
constr.insets = new Insets(1, 2, 2, 2); |
|
203 |
constr.gridx = 1; |
|
204 |
constr.gridy = 1; |
|
205 |
constr.ipadx = 5; |
|
206 |
constr.ipady = 1; |
|
207 |
constr.fill = GridBagConstraints.BOTH; |
|
208 |
constr.anchor = GridBagConstraints.NORTHWEST; |
|
209 |
|
|
210 |
validationPanel.add(validationMessage, constr); |
|
202 | 211 |
} |
203 |
|
|
204 |
JScrollPane jScrollPane = new javax.swing.JScrollPane(); |
|
205 |
JPanel newPanel = new JPanel(new GridBagLayout()); |
|
212 |
|
|
213 |
if (!addScrollPane){ |
|
214 |
return validationPanel; |
|
215 |
} |
|
216 |
|
|
217 |
JScrollPane jScrollPane = new javax.swing.JScrollPane(); |
|
218 |
JPanel newPanel = new JPanel(new BorderLayout()); |
|
206 | 219 |
jScrollPane.setViewportView(validationPanel); |
207 |
|
|
208 |
newPanel.add(jScrollPane, getValidationPanelConstraints());
|
|
220 |
|
|
221 |
newPanel.add(jScrollPane, BorderLayout.WEST);
|
|
209 | 222 |
return newPanel; |
210 | 223 |
} |
211 | 224 |
|
212 | 225 |
private GridBagConstraints getValidationPanelConstraints() { |
213 | 226 |
GridBagConstraints constr = new GridBagConstraints(); |
214 | 227 |
constr.insets = new Insets(2, 2, 2, 2); |
215 |
constr.weightx = 1.0; |
|
216 |
constr.weighty = 1.0; |
|
217 | 228 |
constr.ipadx = 2; |
218 | 229 |
constr.ipady = 2; |
219 |
constr.fill = GridBagConstraints.BOTH;
|
|
230 |
constr.fill = GridBagConstraints.BOTH; |
|
220 | 231 |
constr.anchor = GridBagConstraints.NORTHWEST; |
221 |
return constr; } |
|
232 |
return constr; |
|
233 |
} |
|
222 | 234 |
|
223 | 235 |
/* |
224 | 236 |
* (non-Javadoc) |
... | ... | |
243 | 255 |
|
244 | 256 |
private String getErrorMessage(JDynFieldComponent field) { |
245 | 257 |
String msg = field.getValidationMessage(); |
246 |
if ((field.isMandatory())&&(field.getValue()==null)){
|
|
258 |
if ((field.isMandatory()) && (field.getValue() == null)) {
|
|
247 | 259 |
return translate("Mandatory field. Please insert value."); |
248 | 260 |
} |
249 |
if ((msg == null) ||(msg.equals(""))){
|
|
261 |
if ((msg == null) || (msg.equals(""))) {
|
|
250 | 262 |
return translate("Incompatible type. Not Validated"); |
251 | 263 |
} |
252 |
return msg;
|
|
264 |
return msg; |
|
253 | 265 |
} |
254 | 266 |
|
255 | 267 |
private String translate(String message) { |
... | ... | |
257 | 269 |
} |
258 | 270 |
|
259 | 271 |
private void updateValidationMessageStatus() { |
260 |
if (validationMessage.getText().equals("")){ |
|
272 |
if (validationMessage.getText().equals("")) {
|
|
261 | 273 |
validationMessage.setVisible(false); |
262 |
}else{
|
|
263 |
validationMessage.setVisible(true);
|
|
264 |
|
|
274 |
} else {
|
|
275 |
validationMessage.setVisible(true); |
|
276 |
|
|
265 | 277 |
} |
266 | 278 |
} |
267 | 279 |
} |
Also available in: Unified diff