Revision 168

View differences:

org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.swing/org.gvsig.tools.swing.impl/src/test/java/org/gvsig/tools/AppTest.java
11 11
    extends TestCase
12 12
{
13 13
    /**
14
     * @return the suite of tests being tested
15
     */
16
    public static Test suite()
17
    {
18
        return new TestSuite( AppTest.class );
19
    }
20

  
21
    /**
14 22
     * Create the test case
15 23
     *
16 24
     * @param testName name of the test case
......
21 29
    }
22 30

  
23 31
    /**
24
     * @return the suite of tests being tested
25
     */
26
    public static Test suite()
27
    {
28
        return new TestSuite( AppTest.class );
29
    }
30

  
31
    /**
32 32
     * Rigourous Test :-)
33 33
     */
34 34
    public void testApp()
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/StringJDynObjectComponent.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 * 
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 * 
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 * 
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
 * MA  02110-1301, USA.
20
 * 
21
 */
22

  
23
/*
24
 * AUTHORS (In addition to CIT):
25
 * 2010 {}  {{Task}}
26
 */
27
package org.gvsig.tools.swing.impl.dynobject;
28

  
29
import java.awt.BorderLayout;
30

  
31
import javax.swing.JLabel;
32

  
33
import org.gvsig.tools.dynobject.DynObject;
34
import org.gvsig.tools.swing.api.dynobject.JDynObjectComponent;
35

  
36
/**
37
 * Simple {@link JDynObjectComponent} implementation which shows a
38
 * {@link DynObject} as a String.
39
 * <p>
40
 * <strong>NOTE:</strong> initial dummy implementation to be replaced with a
41
 * more complete one.
42
 * </p>
43
 * 
44
 * @author 2010- C?sar Ordi?ana - gvSIG team
45
 */
46
public class StringJDynObjectComponent extends JDynObjectComponent {
47

  
48
	private static final long serialVersionUID = 5716325904557339463L;
49

  
50
	/**
51
	 * @see JDynObjectView#JDynObjectView(DynObject).
52
	 */
53
	public StringJDynObjectComponent(DynObject dynObject) {
54
		super(dynObject);
55
		initUI();
56
	}
57

  
58
	private void initUI() {
59
		setLayout(new BorderLayout());
60
		JLabel label = new JLabel("<html><pre>".concat(
61
				getDynObject().toString()).concat("</pre></html>"));
62
		add(label, BorderLayout.CENTER);
63
	}
64

  
65
	@Override
66
	public void storeData() {
67
		// Nothing to do, as this component is not able to edit the DynObject
68
		// data.
69
	}
70
}
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/DefaultJDynObjectComponent.java
26 26
 */
27 27
package org.gvsig.tools.swing.impl.dynobject;
28 28

  
29
import java.awt.BorderLayout;
30 29
import java.awt.Color;
31 30
import java.awt.Component;
32 31
import java.awt.GridBagConstraints;
33 32
import java.awt.GridBagLayout;
34 33
import java.awt.Insets;
35
import java.util.ArrayList;
36
import java.util.Arrays;
37 34
import java.util.HashMap;
38
import java.util.Iterator;
39 35
import java.util.List;
40 36
import java.util.Map;
41
import java.util.Map.Entry;
42 37

  
43
import javax.swing.JComboBox;
44 38
import javax.swing.JLabel;
45 39
import javax.swing.JPanel;
46 40
import javax.swing.JScrollPane;
47
import javax.swing.JSpinner;
48
import javax.swing.JTextField;
49
import javax.swing.ScrollPaneConstants;
50
import javax.swing.SpinnerModel;
51
import javax.swing.SpinnerNumberModel;
41
import javax.swing.JTabbedPane;
52 42

  
53 43
import org.gvsig.tools.ToolsLocator;
54
import org.gvsig.tools.dataTypes.DataTypes;
55 44
import org.gvsig.tools.dynobject.DynField;
56 45
import org.gvsig.tools.dynobject.DynObject;
57
import org.gvsig.tools.dynobject.DynObjectValueItem;
58 46
import org.gvsig.tools.i18n.I18nManager;
59
import org.gvsig.tools.swing.api.ToolsSwingLocator;
60
import org.gvsig.tools.swing.api.dynobject.DynObjectSwingManager;
47
import org.gvsig.tools.service.ServiceException;
48
import org.gvsig.tools.swing.api.dynobject.DynFieldComponentModel;
49
import org.gvsig.tools.swing.api.dynobject.DynObjectModel;
61 50
import org.gvsig.tools.swing.api.dynobject.JDynObjectComponent;
51
import org.gvsig.tools.swing.api.dynobject.ValueChangedListener;
52
import org.gvsig.tools.swing.api.dynobject.dynfield.JDynFieldComponent;
53
import org.gvsig.tools.swing.api.dynobject.dynfield.ValueField;
54
import org.gvsig.tools.swing.spi.AbstractDynObjectComponent;
62 55
import org.slf4j.Logger;
63 56
import org.slf4j.LoggerFactory;
64 57

  
......
68 61
 * @author 2008-2009 Jos? Manuel Viv?
69 62
 * @author 2010- C?sar Ordi?ana - gvSIG team
70 63
 */
71
public class DefaultJDynObjectComponent extends JDynObjectComponent {
64
public class DefaultJDynObjectComponent extends AbstractDynObjectComponent implements JDynObjectComponent, ValueField, ValueChangedListener{
72 65
	// implements ActionListener {
73 66

  
74 67
	private static final long serialVersionUID = 2888673056424008867L;
......
77 70
			.getLogger(DefaultJDynObjectComponent.class);
78 71

  
79 72
	private final I18nManager i18nManager = ToolsLocator.getI18nManager();
80
	// private final UsabilitySwingManager usManager = ToolsSwingLocator
81
	// .getUsabilitySwingManager();
82
	private final DynObjectSwingManager dsManager = ToolsSwingLocator
83
			.getDynObjectSwingManager();
84 73

  
85
	public static final int SHOW_ALL = 0;
86
	public static final int SHOW_ONLY_THIS_PARAMS = 1;
87
	public static final int HIDDE_THIS_PARAMS = 2;
88

  
89
	// private String title;
90

  
91 74
	private DynObject parameters;
92
	private List<DynField> fields;
93
	// private JButton botAcept;
94
	// private JButton botCancel;
95
	// private JButton botRestoreDefaults;
96
	// private boolean showButtons;
97
	// private JPanel panButtons;
98
	private JPanel panParameters;
99
	private Map<DynField, Component> componentField;
100 75

  
101 76
	private Color mandatoryLabelColor = Color.red;
102
	// private boolean modal;
103
	private JScrollPane parametersScroll;
104

  
105 77
	protected Map<String, Object> tempValue = new HashMap<String, Object>();
106
	public boolean srsShowTransformPanel;
78
	private HashMap<DynField, JLabel> labelList;
107 79

  
108
	public DefaultJDynObjectComponent(DynObject parameters) {
109
		this(parameters, SHOW_ALL, null);
110
	}
80
	private JTabbedPane tabPanel;
111 81

  
112
	public DefaultJDynObjectComponent(DynObject parameters, int mode,
113
			List<String> paramsNames) {
114
		this(parameters, mode, paramsNames,
115
		// true,
116
				false);
117
	}
118

  
119
	public DefaultJDynObjectComponent(DynObject parameters, int mode,
120
			List<String> paramsNames,
121
			// boolean showButtons,
122
			boolean srsShowTransformPanel) {
123

  
124
		super(parameters);
82
	public DefaultJDynObjectComponent(DynObject parameters, DynObjectModel model) throws ServiceException {
83
		super(parameters,model);
84
		//added to handle labels correctly   
85
		this.labelList = new HashMap<DynField,JLabel>();
125 86
		this.parameters = parameters;
126
		this.fields = Arrays.asList(parameters.getDynClass().getDynFields());
127
		// this.showButtons = showButtons;
128
		this.srsShowTransformPanel = srsShowTransformPanel;
129
		if (mode == SHOW_ONLY_THIS_PARAMS || mode == HIDDE_THIS_PARAMS) {
130
			if (paramsNames == null) {
131
				throw new IllegalArgumentException("must expecify a name list");
132
			}
133
			ArrayList<DynField> toShow = new ArrayList<DynField>();
134
			List<DynField> fields = Arrays.asList(parameters.getDynClass()
135
					.getDynFields());
136
			Iterator<DynField> iter = fields.iterator();
137
			DynField field;
138
			while (iter.hasNext()) {
139
				field = iter.next();
87
		this.tabPanel = new JTabbedPane();
88
		//Uncomment the following line to use scrolling tabs.
89
		this.tabPanel.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
90
		addParametersFromModel();
140 91

  
141
				if (mode == SHOW_ONLY_THIS_PARAMS
142
						&& paramsNames.contains(field.getName())) {
143
					toShow.add(field);
144
				} else if (mode == HIDDE_THIS_PARAMS
145
						&& !(paramsNames.contains(field.getName()))) {
146
					toShow.add(field);
147
				}
148
			}
149
			this.fields = toShow;
150
		} else if (mode == SHOW_ALL) {
151

  
152
		} else {
153
			throw new IllegalArgumentException();
154
		}
155
		this.initialize();
156

  
157 92
	}
158

  
159
	private void initialize() {
160
		this.setLayout(new BorderLayout(6, 6));
161
		this.add(this.getParametersScroll(), BorderLayout.CENTER);
162

  
163
		// if (this.showButtons) {
164
		// this.add(this.getButtonsPanel(), BorderLayout.SOUTH);
165
		// }
166
		this.fromParamsToUI();
167
	}
168

  
169
	// private JPanel getButtonsPanel() {
170
	// if (this.panButtons == null) {
171
	// this.panButtons = new JPanel();
172
	// this.panButtons.setLayout(new GridBagLayout());
173
	// GridBagConstraints constr = new GridBagConstraints();
174
	// constr.anchor = GridBagConstraints.LAST_LINE_END;
175
	// constr.fill = GridBagConstraints.HORIZONTAL;
176
	// constr.weightx = 1;
177
	// constr.weighty = 0;
178
	// this.panButtons.add(new JLabel(), constr);
179
	//
180
	// constr = this.getDefaultParametersConstraints();
181
	// constr.fill = GridBagConstraints.NONE;
182
	// constr.weightx = 0;
183
	// constr.weighty = 0;
184
	//
185
	// this.panButtons.add(this.getAcceptButton(), constr);
186
	// this.panButtons.add(this.getCancelButton(), constr);
187
	// this.panButtons.add(this.getRestoreDefaults(), constr);
188
	// }
189
	// return this.panButtons;
190
	// }
191

  
192
	// private JButton getRestoreDefaults() {
193
	// if (this.botRestoreDefaults == null) {
194
	// this.botRestoreDefaults = usManager.createJButton(i18nManager
195
	// .getTranslation("restoreDefaults"));
196
	// this.botRestoreDefaults.addActionListener(this);
197
	// }
198
	// return this.botRestoreDefaults;
199
	// }
200
	//
201
	// private JButton getCancelButton() {
202
	// if (this.botCancel == null) {
203
	// this.botCancel = usManager.createJButton(i18nManager
204
	// .getTranslation("cancel"));
205
	// this.botCancel.addActionListener(this);
206
	// }
207
	// return this.botCancel;
208
	// }
209
	//
210
	// private JButton getAcceptButton() {
211
	// if (this.botAcept == null) {
212
	// this.botAcept = usManager.createJButton(i18nManager
213
	// .getTranslation("accept"));
214
	// this.botAcept.addActionListener(this);
215
	// }
216
	// return this.botAcept;
217
	// }
218

  
219
	private GridBagConstraints getDefaultParametersConstraints() {
93
	
94
	private void addGridBagComponent(JPanel panel, DynField field, int row) throws ServiceException {
95
	    
96
	    	JDynFieldComponent input =  getJDynFieldComponent(field, this);
97
		
98
		StatusLabel label = this.createFieldLabel(input);
99
		input.addValueChangedListener(label);
100
		
101
		Component component = (Component) input.getComponent();
102
		component.setName(field.getName());	
103
		addComponentToList(component,input);
104
			
105
		//Arranging label and component into panel
106
		
220 107
		GridBagConstraints constr = new GridBagConstraints();
221 108
		constr.insets = new Insets(2, 2, 2, 2);
109
		constr.weighty = row;
222 110
		constr.ipadx = 2;
223 111
		constr.ipady = 2;
224
		constr.anchor = GridBagConstraints.PAGE_START;
225
		return constr;
226

  
227
	}
228

  
229
	private Component getParametersScroll() {
230
		if (parametersScroll == null) {
231
			parametersScroll = new JScrollPane();
232
			parametersScroll.setViewportView(getParametersPanel());
233
			parametersScroll.setBorder(null);
234
			parametersScroll
235
					.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
236
			parametersScroll
237
					.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
238
		}
239
		return parametersScroll;
240
	}
241

  
242
	private JPanel getParametersPanel() {
243
		if (this.panParameters == null) {
244
			this.panParameters = new JPanel();
245
			this.panParameters.setLayout(new GridBagLayout());
246
			// this.panParameters.setBorder(BorderFactory
247
			// .createTitledBorder(this
248
			// .getLocalizedText("values")));
249

  
250
			Iterator<DynField> iter = this.fields.iterator();
251
			DynField field;
252
			while (iter.hasNext()) {
253
				field = iter.next();
254
				switch (field.getTheTypeOfAvailableValues()) {
255
				case DynField.ANY:
256
					this.addFieldSingle(this.panParameters, field);
257
					break;
258
				case DynField.CHOICE:
259
					this.addFieldChoice(this.panParameters, field);
260
					break;
261
				case DynField.RANGE:
262
					this.addFieldRange(this.panParameters, field);
263
					break;
264

  
265
				default:
266
					// FIXME lanzar un warning???
267
					this.addFieldSingle(this.panParameters, field);
268
					break;
269
				}
270

  
271
			}
272
			GridBagConstraints constr = new GridBagConstraints();
273
			constr.fill = GridBagConstraints.BOTH;
274
			constr.weightx = 1;
275
			constr.weighty = 1;
276
			constr.gridheight = GridBagConstraints.REMAINDER;
277
			constr.gridwidth = GridBagConstraints.REMAINDER;
278
			this.panParameters.add(new JLabel(), constr);
279
		}
280
		return this.panParameters;
281
	}
282

  
283
	private JLabel createFieldLabel(DynField field) {
284
		JLabel label = new JLabel();
285
		label.setText(i18nManager.getTranslation(field.getDescription()));
286

  
287
		if (field.isMandatory()) {
288
			label.setForeground(this.mandatoryLabelColor);
289
		}
290
		return label;
291
	}
292

  
293
	private void addFieldRange(JPanel panel, DynField field) {
294
		GridBagConstraints constr = this.getDefaultParametersConstraints();
295 112
		constr.fill = GridBagConstraints.HORIZONTAL;
296
		constr.weighty = 0;
297
		constr.weightx = 0;
113
		constr.anchor = GridBagConstraints.NORTHWEST;
298 114

  
299
		JLabel label = this.createFieldLabel(field);
300
		constr.gridwidth = GridBagConstraints.RELATIVE;
115
		constr.gridx = 0;
116
		constr.gridy = row;
301 117
		panel.add(label, constr);
302 118

  
303
		constr.gridwidth = GridBagConstraints.REMAINDER;
304
		constr.weightx = 1;
305 119

  
306
		Object max, min;
307
		double dmax, dmin, step;
308
		max = field.getMaxValue();
309
		min = field.getMinValue();
310
		boolean decimal;
120
		constr.fill = GridBagConstraints.HORIZONTAL;
121
		constr.gridx = 1;
122
		constr.weightx = 0.7;
123
		panel.add(component, constr);
124
		
125
		input.fireValueChangedEvent();
126
	}
311 127

  
312
		if (!(max instanceof Number)) {
313
			max = null;
314
		}
315
		if (!(min instanceof Number)) {
316
			min = null;
317
		}
318
		dmax = 0;
319
		dmin = 0;
320
		step = 1;
128
	private void addParametersFromModel() throws ServiceException {
129
	    DynField field;
130
	    JPanel pane;
131
	    String[] groups = this.getModel().getGroups();
321 132

  
322
		switch (field.getType()) {
323
		case DataTypes.INT:
324
			decimal = false;
325
			if (max == null) {
326
				max = Integer.MAX_VALUE;
327
			} else {
328
				dmax = ((Integer) max).doubleValue();
329
			}
330
			if (min == null) {
331
				dmin = Integer.MIN_VALUE;
332
			} else {
333
				dmin = ((Integer) min).doubleValue();
334
			}
335
			break;
133
	    for (String group: groups){
134
		List items = this.getModel().getGroupElements(group);
135
		
136
		pane = new JPanel(new GridBagLayout());
137
		
138
	    	for (int i=0;i<items.size();i++) {
139
		    field = ((DynFieldComponentModel)items.get(i))
140
		    		.getDynField();
141
		    addGridBagComponent(pane,field,i);
336 142

  
337
		case DataTypes.LONG:
338
			decimal = false;
339
			if (max == null) {
340
				dmax = Long.MAX_VALUE;
341
			} else {
342
				dmax = ((Long) max).doubleValue();
343
			}
344
			if (min == null) {
345
				dmin = Long.MIN_VALUE;
346
			} else {
347
				dmin = ((Long) min).doubleValue();
348
			}
349
			break;
350

  
351
		case DataTypes.BYTE:
352
			decimal = false;
353
			if (max == null) {
354
				dmax = Byte.MAX_VALUE;
355
			} else {
356
				dmax = ((Byte) max).doubleValue();
357
			}
358
			if (min == null) {
359
				dmin = Byte.MIN_VALUE;
360
			} else {
361
				dmin = ((Byte) min).doubleValue();
362
			}
363
			break;
364

  
365
		case DataTypes.FLOAT:
366
			decimal = true;
367
			if (max == null) {
368
				dmax = Float.MAX_VALUE;
369
			} else {
370
				dmax = ((Float) max).doubleValue();
371
			}
372
			if (min == null) {
373
				dmin = Float.MIN_VALUE;
374
			} else {
375
				dmin = ((Float) min).doubleValue();
376
			}
377
			break;
378

  
379
		case DataTypes.DOUBLE:
380
			decimal = true;
381
			if (max == null) {
382
				dmax = Double.MAX_VALUE;
383
			} else {
384
				dmax = ((Double) max).doubleValue();
385
			}
386
			if (min == null) {
387
				dmin = Double.MIN_VALUE;
388
			} else {
389
				dmin = ((Double) min).doubleValue();
390
			}
391
			break;
392

  
393
		default:
394
			JTextField text = new JTextField();
395
			text.setEnabled(false);
396
			panel.add(text, constr);
397
			this.getComponentField().put(field, text);
398
			return;
399 143
		}
400
		if ((dmax - dmin) != 0) {
401
			step = (dmax - dmin) / 20;
402
		}
144
		this.tabPanel.addTab(group,createScrollPane(pane));
145
	    }
146
	}
403 147

  
404
		SpinnerModel spinnerModel;
405
		if (decimal) {
406
			spinnerModel = new SpinnerNumberModel(dmin, dmin, dmax, step);
407
		} else {
408
			spinnerModel = new SpinnerNumberModel((int) dmin, (int) dmin,
409
					(int) dmax, (int) step);
410
		}
411
		JSpinner spinner = new JSpinner(spinnerModel);
412
		spinner.setName(field.getName());
413
		constr.gridwidth = GridBagConstraints.REMAINDER;
414
		constr.weightx = 1;
415
		panel.add(spinner, constr);
416
		this.getComponentField().put(field, spinner);
148
	/**
149
	 * @param label
150
	 * @param field
151
	 */
152
	private void checkValidation(JLabel label, JDynFieldComponent field) {
153
	    if (label==null) return;
154
	    if (!isValid(field)){
155
		label.setForeground(this.mandatoryLabelColor);
156
	    }else{
157
		label.setForeground(Color.BLACK);
158
	    }
417 159
	}
160
	
161
	protected void closeWindow() {
162
		LOG.debug("Result DynObject: {}", parameters);
418 163

  
419
	private void addFieldChoice(JPanel panel, DynField field) {
420
		GridBagConstraints constr = this.getDefaultParametersConstraints();
421
		constr.fill = GridBagConstraints.HORIZONTAL;
422
		constr.weighty = 0;
423
		constr.weightx = 0;
424

  
425
		JLabel label = this.createFieldLabel(field);
426
		constr.gridwidth = GridBagConstraints.RELATIVE;
427
		panel.add(label, constr);
428

  
429
		JComboBox combo = new JComboBox(field.getAvailableValues());
430
		combo.setName(field.getName());
431
		constr.gridwidth = GridBagConstraints.REMAINDER;
432
		constr.weightx = 1;
433
		panel.add(combo, constr);
434
		this.getComponentField().put(field, combo);
435

  
164
		// if (PluginServices.getMainFrame() == null) {
165
		// ((JFrame) (getParent().getParent().getParent().getParent()))
166
		// .dispose();
167
		// } else {
168
		// PluginServices.getMDIManager().closeWindow(this);
169
		// }
436 170
	}
171
	
172
	private StatusLabel createFieldLabel(JDynFieldComponent component) {
173
	    	DynField field = component.getDynField();
174
		String text = i18nManager.getTranslation(field.getDescription());
437 175

  
438
	private void addFieldSingle(JPanel panel, DynField field) {
439
		GridBagConstraints constr = this.getDefaultParametersConstraints();
440
		constr.fill = GridBagConstraints.HORIZONTAL;
441
		constr.weighty = 0;
442
		constr.weightx = 0;
443

  
444
		JLabel label = this.createFieldLabel(field);
445
		constr.gridwidth = GridBagConstraints.RELATIVE;
446
		panel.add(label, constr);
447

  
448
		// JTextField text = new JTextField();
449
		Component input = getComponentFor(field);
450
		input.setName(field.getName());
451
		constr.gridwidth = GridBagConstraints.REMAINDER;
452
		constr.weightx = 1;
453
		panel.add(input, constr);
454
		this.getComponentField().put(field, input);
455

  
176
		StatusLabel label = new StatusLabel(text, field.isMandatory());
177
	
178
		//adding label to a hashmap
179
		this.labelList.put (field,label);
180
		
181
		return label;
456 182
	}
457 183

  
458
	private Component getComponentFor(DynField field) {
459
		Component result = dsManager.createJDynFieldComponent(field,
460
				getDynObject());
461 184

  
462
		return (result == null) ? new JTextField() : result;
185
	private Component createScrollPane(JPanel panel) throws ServiceException {
186
	    JScrollPane scrollPane = new JScrollPane();
187
	    scrollPane.setAlignmentX(JScrollPane.LEFT_ALIGNMENT);	 
188
	    scrollPane.setAlignmentY(JScrollPane.TOP_ALIGNMENT);
189
	   
190
	    
191
	    scrollPane.setViewportView(panel);
192
	    scrollPane.setAutoscrolls(true);
193
////	    scrollPane.setBorder(null);
194
//	    scrollPane
195
//		.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
196
//	    scrollPane
197
//		.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
198
	    return scrollPane;
463 199
	}
464 200

  
465
	// class MyProjectionSelector extends JPanel {
466
	// /**
467
	// *
468
	// */
469
	// private static final long serialVersionUID = -6331922386501903468L;
201
/* (non-Javadoc)
202
 * @see org.gvsig.tools.swing.api.dynobject.JComponent#getComponent()
203
 */
204
public Object getComponent() {
205
    return this.tabPanel;
206
//	    return this.panel;
207
}
208

  
209
	/**
210
	 * 	OTRAS PRUEBAS DELAYOUT
211
	 */
212
		
213
	//	private GridBagConstraints getDefaultParametersConstraints() {
214
	//	GridBagConstraints constr = new GridBagConstraints();
215
	//	constr.insets = new Insets(2, 2, 2, 2);
216
	//	constr.ipadx = 2;
217
	//	constr.ipady = 2;
218
	//	return constr;
219
	//}
220
	
221
	//	private JPanel createNorthWestPane(JPanel pane){
222
	//	    //Make a panel
223
	//	    JPanel northWestPanel = new JPanel(new GridLayout(1,1));
224
	//	    GridBagConstraints c = new GridBagConstraints();
225
	//	    c.gridx = 0;
226
	//	    c.gridy = 0;
227
	//	    c.anchor = GridBagConstraints.NORTHWEST;
228
	//	    c.insets = new Insets(0,0,0,0);
229
	//	    northWestPanel.add(pane, c);
470 230
	//
471
	// private CRSSelectPanel crsSelector = null;
472
	// private IProjection srs = null;
231
	//	    northWestPanel.add(pane);
232
	//	    return northWestPanel;
233
	//	}
234
		
235
	//	/**
236
	//	 * @throws ServiceException 
237
	//	 * 
238
	//	 */
239
	//	private void addGridBagParametersFromModel() throws ServiceException {
473 240
	//
474
	// MyProjectionSelector(){
475
	// super();
476
	// init();
477
	// }
241
	//	    DynField field;
242
	//	    JPanel pane;
243
	//	    String[] groups = this.getModel().getGroups();
478 244
	//
479
	// private void init() {
480
	// this.setValue(null);
481
	// }
245
	//	    for (String group: groups){
246
	//		List items = this.getModel().getGroupElements(group);
247
	//		
248
	//		pane = new JPanel(new GridBagLayout());
249
	//	    	pane.setBorder(BorderFactory.createTitledBorder("Prueba"));
250
	//		
251
	//	    	for (int i=0;i<items.size();i++) {
252
	//		    field = ((DynFieldComponentModel)items.get(i))
253
	//		    		.getDynField();
254
	//		    addGridBagFieldSingle(pane,field,i);
255
	//		}
256
	////		this.tabPanel.addTab(group,createScrollPane(pane));
257
	//		this.tabPanel.addTab(group,pane);
258
	//	    }
259
	//	    
260
	//	    this.tabPanel.setSelectedIndex(0);
261
	//	}
262
		
263
	//	private void addFieldSingle(JPanel panel, DynField field, int row) throws ServiceException {
264
	//	    
265
	//	    	JDynFieldComponent input =  getJDynFieldComponent(field, this);
266
	//		
267
	//		StatusLabel label = this.createFieldLabel(input);
268
	//		input.addValueChangedListener(label);
269
	//		
270
	//		// JTextField text = new JTextField();
271
	//		//Component input = getComponentFor(field);
272
	//		Component component = (Component) input.getComponent();
273
	//		component.setName(field.getName());	
274
	//		addComponentToList(component,input);
275
	//		
276
	//		
277
	//		//Arranging label and component into panel
278
	//		
279
	//		GridBagConstraints constr = this.getDefaultParametersConstraints();
280
	//		
281
	//		constr.fill = GridBagConstraints.HORIZONTAL;
282
	//			    
283
	//		constr.gridx = 0;
284
	////		constr.gridy = row;
285
	//		constr.gridheight = GridBagConstraints.RELATIVE;
286
	//		constr.anchor = GridBagConstraints.PAGE_START;
287
	//		constr.weighty = 0;
288
	////		constr.w =  1;
289
	////		constr.weightx = 0;
290
	////		constr.gridheight = GridBagConstraints.RELATIVE;
291
	//		panel.add(label, BorderLayout.WEST);
482 292
	//
483
	// private void setCurrentProj(IProjection proj) {
484
	// if (proj == null){
485
	// srs = null;
486
	// } else {
487
	// srs = proj;
488
	// }
489
	// }
490 293
	//
491
	// public void setValue(IProjection proj) {
492
	// if (crsSelector != null) {
493
	// this.remove(crsSelector);
494
	// }
294
	//		
295
	//		panel.add(component, BorderLayout.CENTER);
296
	//		
297
	//		input.fireValueChangedEvent();
298
	//	}
299
	
300
	//	private void initialize() throws ServiceException {
301
	//		this.panel = new JPanel(new BorderLayout(6,6));
302
	//		this.panel.setPreferredSize(new Dimension(800, 560));
303
	//		
304
	////		this.panel.add(this.getParametersScroll(), BorderLayout.PAGE_START);
495 305
	//
496
	// crsSelector = CRSSelectPanel.getPanel(proj);
497
	// crsSelector
498
	// .setTransPanelActive(DynObjectEditor.this.srsShowTransformPanel);
499
	// crsSelector.addActionListener(new ActionListener() {
500
	// public void actionPerformed(ActionEvent e) {
501
	// setCurrentProj(crsSelector.getCurProj());
502
	// }
503
	// });
306
	//		this.panel.add(this.getParametersPanel(isMainPanel), BorderLayout.PAGE_START);
307
	////		this.panel =  this.getParametersScroll();
504 308
	//
505
	// this.add(crsSelector);
506
	// this.doLayout();
507
	// }
508
	//
509
	// public IProjection getValue() {
510
	// return srs;
511
	// }
512
	//
513
	//
514
	//
515
	// }
516

  
517
	private void fromParamsToUISingle(DynField field, Component component) {
518

  
519
		// Object value = parameters.getDynValue(field.getName());
520
		// JTextField text;
521
		// switch (field.getType()) {
522
		// case DataTypes.STRING:
523
		// text = (JTextField) component;
524
		// if (value == null) {
525
		// text.setText("");
526
		// return;
527
		// }
309
	//		//		this.panel.add(this.panParameters);
310
	//		// if (this.showButtons) {
311
	//		// this.add(this.getButtonsPanel(), BorderLayout.SOUTH);
312
	//		// }
313
	////		this.fromParamsToUI();
314
	//	}
315
	
316
		// private JPanel getButtonsPanel() {
317
		// if (this.panButtons == null) {
318
		// this.panButtons = new JPanel();
319
		// this.panButtons.setLayout(new GridBagLayout());
320
		// GridBagConstraints constr = new GridBagConstraints();
321
		// constr.anchor = GridBagConstraints.LAST_LINE_END;
322
		// constr.fill = GridBagConstraints.HORIZONTAL;
323
		// constr.weightx = 1;
324
		// constr.weighty = 0;
325
		// this.panButtons.add(new JLabel(), constr);
528 326
		//
529
		// text.setText((String) value);
530
		// break;
327
		// const3r = this.getDefaultParametersConstraints();
328
		// constr33.fill = GridBagConstraints.NONE;
329
		// constr.weightx = 0;
330
		// constr.weighty = 0;
531 331
		//
532
		// // case DataTypes.SRS:
533
		// // ((MyProjectionSelector) component).setValue((IProjection) value);
534
		// // break;
535
		//
536
		// default:
537
		// text = (JTextField) component;
538
		// if (value == null) {
539
		// text.setText("");
540
		// return;
332
		// this.panButtons.add(this.getAcceptButton(), constr);
333
		// this.panButtons.add(this.getCancelButton(), constr);
334
		// this.panButtons.add(this.getRestoreDefaults(), constr);
541 335
		// }
336
		// return this.panButtons;
337
		// }
338
	
339
		// private JButton getRestoreDefaults() {
340
		// if (this.botRestoreDefaults == null) {
341
		// this.botRestoreDefaults = usManager.createJButton(i18nManager
342
		// .getTranslation("restoreDefaults"));
343
		// this.botRestoreDefaults.addActionListener(this);
344
		// }
345
		// return this.botRestoreDefaults;
346
		// }
542 347
		//
543
		// text.setText(value.toString());
544
		// break;
348
		// private JButton getCancelButton() {
349
		// if (this.botCancel == null) {
350
		// this.botCancel = usManager.createJButton(i18nManager
351
		// .getTranslation("cancel"));
352
		// this.botCancel.addActionListener(this);
545 353
		// }
546

  
547
	}
548

  
549
	private void fromParamsToUIRange(DynField field, Component component) {
550
		JSpinner spinner = (JSpinner) component;
551

  
552
		Object value = parameters.getDynValue(field.getName());
553
		double dValue = 0;
554
		if (value == null) {
555
			value = field.getMinValue();
556
		}
557
		if (value instanceof Double) {
558
			dValue = ((Double) value).doubleValue();
559
		} else if (value instanceof String) {
560
			dValue = Double.parseDouble((String) value);
561
		} else {
562
			// FIXME ????
563
			dValue = 0;
564
		}
565
		spinner.setValue(dValue);
566

  
567
	}
568

  
569
	private void fromParamsToUIChoice(DynField field, Component component) {
570
		JComboBox combo = (JComboBox) component;
571
		Object value = parameters.getDynValue(field.getName());
572

  
573
		DynObjectValueItem item = null;
574
		for (int i = 0; i < field.getAvailableValues().length; i++) {
575
			if (value == null) {
576
				if (field.getAvailableValues()[i].getValue() == null) {
577
					item = field.getAvailableValues()[i];
578
					break;
579
				}
580
			} else {
581
				if (field.getAvailableValues()[i].getValue().equals(value)) {
582
					item = field.getAvailableValues()[i];
583
					break;
584
				}
585

  
586
			}
587
		}
588

  
589
		combo.getModel().setSelectedItem(item);
590

  
591
	}
592

  
593
	private void fromDefaultsToUISingle(DynField field, Component component) {
594
		JTextField text = (JTextField) component;
595

  
596
		if (field.getDefaultValue() == null) {
597
			text.setText("");
598
		} else if (field.getType() == DataTypes.STRING) {
599
			text.setText((String) field.getDefaultValue());
600
		} else {
601
			text.setText(field.getDefaultValue().toString());
602
		}
603

  
604
	}
605

  
606
	private void fromDefaultsToUIChoice(DynField field, Component component) {
607
		JComboBox combo = (JComboBox) component;
608
		Object value = field.getDefaultValue();
609

  
610
		DynObjectValueItem item = null;
611
		for (int i = 0; i < field.getAvailableValues().length; i++) {
612
			if (value == null) {
613
				if (field.getAvailableValues()[i].getValue() == null) {
614
					item = field.getAvailableValues()[i];
615
					break;
616
				}
617
			} else {
618
				if (field.getAvailableValues()[i].getValue().equals(value)) {
619
					item = field.getAvailableValues()[i];
620
					break;
621
				}
622

  
623
			}
624
		}
625

  
626
		combo.getModel().setSelectedItem(item);
627
	}
628

  
629
	private void fromDefaultsToUIRange(DynField field, Component component) {
630
		JSpinner spinner = (JSpinner) component;
631
		Object value = field.getDefaultValue();
632
		double dValue = 0;
633
		if (value == null) {
634
			value = field.getMinValue();
635
		}
636

  
637
		if (value instanceof Double) {
638
			dValue = ((Double) value).doubleValue();
639
		} else if (value instanceof String) {
640
			dValue = Double.parseDouble((String) value);
641
		} else {
642
			// FIXME ????
643
			dValue = 0;
644
		}
645

  
646
		spinner.setValue(dValue);
647
	}
648

  
649
	public void fromParamsToUI() {
650
		Iterator<Entry<DynField, Component>> iter = this.getComponentField()
651
				.entrySet().iterator();
652
		Entry<DynField, Component> entry;
653
		while (iter.hasNext()) {
654
			entry = iter.next();
655

  
656
			switch (entry.getKey().getTheTypeOfAvailableValues()) {
657
			case DynField.ANY:
658
				this.fromParamsToUISingle(entry.getKey(), entry.getValue());
659
				break;
660
			case DynField.CHOICE:
661
				this.fromParamsToUIChoice(entry.getKey(), entry.getValue());
662
				break;
663
			case DynField.RANGE:
664
				this.fromParamsToUIRange(entry.getKey(), entry.getValue());
665
				break;
666

  
667
			default:
668
				// FIXME warning??
669
				this.fromParamsToUISingle(entry.getKey(), entry.getValue());
670
				break;
671
			}
672

  
673
		}
674
	}
675

  
676
	public void fromDefaultsToUI() {
677
		Iterator<Entry<DynField, Component>> iter = this.getComponentField()
678
				.entrySet().iterator();
679
		Entry<DynField, Component> entry;
680
		while (iter.hasNext()) {
681
			entry = iter.next();
682

  
683
			switch (entry.getKey().getTheTypeOfAvailableValues()) {
684
			case DynField.ANY:
685
				this.fromDefaultsToUISingle(entry.getKey(), entry.getValue());
686
				break;
687
			case DynField.CHOICE:
688
				this.fromDefaultsToUIChoice(entry.getKey(), entry.getValue());
689
				break;
690
			case DynField.RANGE:
691
				this.fromDefaultsToUIRange(entry.getKey(), entry.getValue());
692
				break;
693

  
694
			default:
695
				// FIXME warning??
696
				this.fromParamsToUISingle(entry.getKey(), entry.getValue());
697
				break;
698
			}
699

  
700
		}
701
	}
702

  
703
	@Override
704
	public void storeData() {
705
		// TODO go through all JDynFieldComponents and call storeData() on them
706
	}
707

  
708
	private void fromUIToParams() {
709
		Iterator<Entry<DynField, Component>> iter = this.getComponentField()
710
				.entrySet().iterator();
711
		Entry<DynField, Component> entry;
712
		while (iter.hasNext()) {
713
			entry = iter.next();
714

  
715
			switch (entry.getKey().getTheTypeOfAvailableValues()) {
716
			case DynField.ANY:
717
				this.fromUIToParamsSingle(entry.getKey(), entry.getValue());
718
				break;
719
			case DynField.CHOICE:
720
				this.fromUIToParamsChoice(entry.getKey(), entry.getValue());
721
				break;
722
			case DynField.RANGE:
723
				this.fromUIToParamsRange(entry.getKey(), entry.getValue());
724
				break;
725

  
726
			default:
727
				// FIXME warning??
728
				this.fromUIToParamsSingle(entry.getKey(), entry.getValue());
729
				break;
730
			}
731

  
732
		}
733

  
734
	}
735

  
736
	private void fromUIToParamsSingle(DynField field, Component component) {
737
		JTextField text;
738

  
739
		switch (field.getType()) {
740
		case DataTypes.STRING:
741
			text = (JTextField) component;
742
			if (text.getText().length() == 0) {
743
				String curValue = (String) parameters.getDynValue(field
744
						.getName());
745
				if (curValue == null || curValue.length() == 0) {
746
					return;
747
				}
748
			}
749
			parameters.setDynValue(field.getName(), text.getText());
750
			break;
751

  
752
		case DataTypes.INT:
753
			text = (JTextField) component;
754
			if (text.getText().length() == 0) {
755
				Integer curValue = (Integer) parameters.getDynValue(field
756
						.getName());
757
				if (curValue == null) {
758
					return;
759
				}
760
			}
761

  
762
			// try{
763
			parameters.setDynValue(field.getName(), new Integer(Integer
764
					.parseInt(text.getText())));
765
			// } catch (NumberFormatException e) {
766
			// NotificationManager.addError(e);
767
			// }
768
			break;
769

  
770
		case DataTypes.BOOLEAN:
771
			text = (JTextField) component;
772

  
773
			if (text.getText().length() == 0) {
774
				Boolean curValue = (Boolean) parameters.getDynValue(field
775
						.getName());
776
				if (curValue == null) {
777
					return;
778
				}
779
			}
780

  
781
			parameters.setDynValue(field.getName(), new Boolean(Boolean
782
					.parseBoolean(text.getText())));
783

  
784
			break;
785

  
786
		// case DataTypes.SRS:
787
		// parameters.setDynValue(field.getName(),
788
		// ((MyProjectionSelector) component).getValue());
354
		// return this.botCancel;
355
		// }
789 356
		//
790
		// break;
791

  
792
		case DataTypes.OBJECT:
793
			// TODO
794

  
795
			break;
796
		default:
797
			// FIXME Warning !!!
798
			text = (JTextField) component;
799
			if (text.getText().length() == 0) {
800
				Object curValue = parameters.getDynValue(field.getName());
801
				if (curValue == null) {
802
					return;
803
				}
804
			}
805

  
806
			parameters.setDynValue(field.getName(), text.getText());
807
			break;
808
		}
809
	}
810

  
811
	private void fromUIToParamsChoice(DynField field, Component component) {
812
		JComboBox combo = (JComboBox) component;
813
		parameters.setDynValue(field.getName(), ((DynObjectValueItem) combo
814
				.getSelectedItem()).getValue());
815
	}
816

  
817
	private void fromUIToParamsRange(DynField field, Component component) {
818
		JSpinner spinner = (JSpinner) component;
819
		parameters.setDynValue(field.getName(), spinner.getValue());
820

  
821
	}
822

  
823
	private Map<DynField, Component> getComponentField() {
824
		if (this.componentField == null) {
825
			this.componentField = new HashMap<DynField, Component>();
826
		}
827
		return componentField;
828

  
829
	}
830

  
831
	// public void actionPerformed(ActionEvent e) {
832
	// Component source = (Component) e.getSource();
833
	// if (source == this.botAcept) {
834
	// this.fromUIToParams();
835
	// this.closeWindow();
357
		// private JButton getAcceptButton() {
358
		// if (this.botAcept == null) {
359
		// this.botAcept = usManager.createJButton(i18nManager
360
		// .getTranslation("accept"));
361
		// this.botAcept.addActionListener(this);
362
		// }
363
		// return this.botAcept;
364
		// }
365
	
366
	//	private void addGridLayoutComponent(JPanel panel, DynField field, int row) throws ServiceException {
367
	//	    
368
	//	    	JDynFieldComponent input =  getJDynFieldComponent(field, this);
369
	//		
370
	//		StatusLabel label = this.createFieldLabel(input);
371
	//		input.addValueChangedListener(label);
372
	//		
373
	//		// JTextField text = new JTextField();
374
	//		//Component input = getComponentFor(field);
375
	//		Component component = (Component) input.getComponent();
376
	//		component.setName(field.getName());	
377
	//		addComponentToList(component,input);
378
	//		
379
	//		
380
	//		//Arranging label and component into panel
381
	//		
382
	//		GridBagConstraints constr = this.getDefaultParametersConstraints();
383
	//		
384
	////		constr.fill = GridBagConstraints.HORIZONTAL;
385
	////			    
386
	////		constr.gridx = 0;
387
	//////		constr.gridy = row;
388
	////		constr.gridheight = GridBagConstraints.RELATIVE;
389
	////		if (row==0){
390
	////		    constr.anchor = GridBagConstraints.NORTHWEST;
391
	////		}else{
392
	////		    constr.anchor = GridBagConstraints.PAGE_START;
393
	////		}
394
	////		constr.weighty = 0;
395
	////		constr.w =  1;
396
	////		constr.weightx = 0;
397
	////		constr.gridheight = GridBagConstraints.RELATIVE;
398
	//		panel.add(label);
836 399
	//
837
	// } else if (source == this.botCancel) {
838
	// // TODO Close windows
839
	// this.closeWindow();
840
	// } else if (source == this.botRestoreDefaults) {
841
	// this.fromDefaultsToUI();
842 400
	//
843
	// }
844
	// if (!this.getComponentField().containsValue(e.getSource())) {
845
	// return;
846
	// }
847
	// System.out.println("Action perform:" + source);
848
	//
849
	// }
401
	////		constr.fill = GridBagConstraints.BOTH;
402
	////		if (row==0){
403
	////		    constr.anchor = GridBagConstraints.NORTHWEST;
404
	////		}else{
405
	////		    constr.anchor = GridBagConstraints.PAGE_START;
406
	////		}
407
	////		constr.gridx = 1;
408
	////		constr.gridwidth = GridBagConstraints.NONE;
409
	////		constr.weightx = 0.70;
410
	//		panel.add(component);
411
	//		
412
	//		input.fireValueChangedEvent();
413
	//	}
414
	
415
		
416
		private JLabel getFieldLabel (DynField field){
417
		    return this.labelList.get(field);
418
		}
850 419

  
851
	protected void closeWindow() {
852
		LOG.debug("Result DynObject: {}", parameters);
853

  
854
		// if (PluginServices.getMainFrame() == null) {
855
		// ((JFrame) (getParent().getParent().getParent().getParent()))
856
		// .dispose();
857
		// } else {
858
		// PluginServices.getMDIManager().closeWindow(this);
859
		// }
860
	}
861

  
862 420
	// /* (non-Javadoc)
863 421
	// * @see com.iver.andami.ui.mdiManager.IWindow#getWindowInfo()
864 422
	// */
......
877 435
	// }
878 436

  
879 437
	/**
880
	 * @param mandatoryLabelColor
881
	 *            the mandatoryLabelColor to set
438
	 * @return the mandatoryLabelColor
882 439
	 */
883
	public void setMandatoryLabelColor(Color mandatoryLabelColor) {
884
		this.mandatoryLabelColor = mandatoryLabelColor;
440
	public Color getMandatoryLabelColor() {
441
		return mandatoryLabelColor;
885 442
	}
886 443

  
444
	/* (non-Javadoc)
445
	 * @see org.gvsig.tools.swing.spi.AbstractDynObjectComponent#getValue()
446
	 */
447
	@Override
448
	public Object getValue() {
449
	    return this.getDynObject();
450
	}
451

  
452
	/* (non-Javadoc)
453
	 * @see org.gvsig.tools.swing.api.dynobject.ValueChangedListener#handleValueChanged(org.gvsig.tools.swing.api.dynobject.JDynObjectComponent, org.gvsig.tools.swing.api.dynobject.dynfield.JDynFieldComponent)
454
	 */
455
	public void handleValueChanged(JDynFieldComponent field) {
456
	    JLabel label = getFieldLabel(field.getDynField());
457
	    this.checkValidation(label, field);
458
	}
459

  
887 460
	/**
888
	 * @return the mandatoryLabelColor
461
	 * @param field
462
	 * @return
889 463
	 */
890
	public Color getMandatoryLabelColor() {
891
		return mandatoryLabelColor;
464
	protected boolean isValid(JDynFieldComponent field) {   
465
	    return field.isValid();
892 466
	}
893 467

  
894
	// public void editObject(boolean modal) {
895
	// // this.modal = modal;
896
	// // try {
897
	// // PluginServices.getMDIManager().addWindow(this);
898
	// // } catch (Exception e) {
899
	// // JFrame frame = new JFrame();
900
	// // frame.setLayout(new BorderLayout());
901
	// // frame.add(this);
902
	// // frame.setBounds(10, 10, 400, 400);
903
	// // frame.setVisible(true);
904
	// // }
905
	// }
906 468

  
907
	// public String getTitle() {
908
	// return title;
909
	// }
910
	//
911
	// public void setTitle(String title) {
912
	// this.title = title;
913
	// }
469
	/* (non-Javadoc)
470
	 * @see org.gvsig.tools.swing.api.dynobject.JDynObjectComponent#requestFocus()
471
	 */
472
	public void requestFocus() {
473
	}
914 474

  
915
	// public Object getWindowProfile() {
916
	// return WindowInfo.PROPERTIES_PROFILE;
917
	// }
475
	/**
476
	 * @param mandatoryLabelColor
477
	 *            the mandatoryLabelColor to set
478
	 */
479
	public void setMandatoryLabelColor(Color mandatoryLabelColor) {
480
		this.mandatoryLabelColor = mandatoryLabelColor;
481
	}
918 482

  
919
	// public boolean isSrsShowTransformPanel() {
920
	// return srsShowTransformPanel;
921
	// }
922
	//
923
	// public void setSrsShowTransformPanel(boolean srsShowTransformPanel) {
924
	// this.srsShowTransformPanel = srsShowTransformPanel;
925
	// }
483
	/* (non-Javadoc)
484
	 * @see org.gvsig.tools.swing.api.dynobject.dynfield.ValueField#setValue(java.lang.Object)
485
	 */
486
	public void setValue(Object value) {
487
	   
488
	}
926 489

  
927 490
}
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
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 * 
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 * 
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 * 
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
 * MA  02110-1301, USA.
20
 * 
21
 */
22
/*
23
 * AUTHORS (In addition to CIT):
24
 * 2010 Institute of New Imaging Technologies (INIT): 
25
 *   http://www.init.uji.es
26
 * Geographic Information research group: 
27
 *   http://www.geoinfo.uji.es
28
 * Universitat Jaume I, Spain
29
 */
30

  
31
/**
32
 * 
33
 */
34
package org.gvsig.tools.swing.impl.dynobject;
35

  
36
import java.awt.Color;
37

  
38
import javax.swing.Icon;
39
import javax.swing.ImageIcon;
40
import javax.swing.JLabel;
41

  
42
import org.gvsig.tools.swing.api.dynobject.ValueChangedListener;
43
import org.gvsig.tools.swing.api.dynobject.dynfield.JDynFieldComponent;
44

  
45
/**
46
 * @author <a href="mailto:reinhold@uji.es">cmartin</a>
47
 * 
48
 */
49
public class StatusLabel extends JLabel implements ValueChangedListener{
50

  
51
    private static final String NOT_VALIDATED = "unavailable.png";
52
    
53
    private static final Color COLOR_MANDATORY = Color.RED;
54
    
55

  
56
    public StatusLabel(String text, boolean isMandatory) {
57
	setOpaque(true);
58
	setHorizontalTextPosition(JLabel.LEFT);
59
	setHorizontalAlignment(LEFT);
60
	setVerticalAlignment(CENTER);
61
	setIconTextGap(10);
62
	if (isMandatory){
63
	    this.setForeground(COLOR_MANDATORY);
64
	    this.setText("<html><u>" + text + "</u><html>");
65
	}else
66
	    setText(text);
67
    }
68

  
69

  
70
    /**
71
     * @param notValidated
72
     * @return
73
     */
74
    private Icon getIcon(String notValidated, String description) {
75
	String path = this.getClass().getResource(NOT_VALIDATED).getPath();
76
	if ((path==null)||(path.equals("")))
77
	    return null;
78
	ImageIcon icon = new ImageIcon(path);
79
	icon.setDescription(description);
80
	icon.setImageObserver(this);
81
	return icon;
82
    }
83
//
84
//    // Set the font and text when no image was found.
85
//    protected void setText(String text, Font normalFont) {
86
//	if (uhOhFont == null) { // lazily create this font
87
//	    uhOhFont = normalFont.deriveFont(Font.ITALIC);
88
//	}
89
//	setFont(uhOhFont);
90
//	setText(uhOhText);
91
//    }
92

  
93
    /* (non-Javadoc)
94
     * @see org.gvsig.tools.swing.api.dynobject.ValueChangedListener#handleValueChanged(org.gvsig.tools.swing.api.dynobject.dynfield.JDynFieldComponent)
95
     */
96
    public void handleValueChanged(JDynFieldComponent field) {
97

  
98
	// Set the icon and text. If icon was null, say so.
99
	if (!field.isValid()){	    
100
	    this.setIcon(getIcon(NOT_VALIDATED, "Not Validated"));	    
101
	}else{
102
	    setIcon(null);	    
103
	}
104
    }
105
}
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/AbstractDynObjectModel.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
5
* 
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
10
* 
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
* GNU General Public License for more details.
15
* 
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
* MA  02110-1301, USA.
20
* 
21
*/
22
/*
23
 * AUTHORS (In addition to CIT):
24
 * 2010 Institute of New Imaging Technologies (INIT): 
25
 *   http://www.init.uji.es
26
 * Geographic Information research group: 
27
 *   http://www.geoinfo.uji.es
28
 * Universitat Jaume I, Spain
29
 */
30

  
31
/**
32
 * 
33
 */
34
package org.gvsig.tools.swing.impl.dynobject;
35

  
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff