Revision 25935

View differences:

branches/v2_0_0_prep/applications/appgvSIG/src/org/gvsig/fmap/dal/serverexplorer/filesystem/swing/DynObjectEditor.java
50 50
import javax.swing.JFrame;
51 51
import javax.swing.JLabel;
52 52
import javax.swing.JPanel;
53
import javax.swing.JSpinner;
53 54
import javax.swing.JTextField;
55
import javax.swing.SpinnerModel;
56
import javax.swing.SpinnerNumberModel;
54 57

  
55
import org.gvsig.fmap.dal.DataParameters;
56 58
import org.gvsig.fmap.dal.DataTypes;
57 59
import org.gvsig.gui.beans.swing.JButton;
58
import org.gvsig.gui.beans.swing.JIncrementalNumberField;
59
import org.gvsig.gui.beans.swing.ValidatingTextField;
60 60
import org.gvsig.tools.ToolsLibrary;
61 61
import org.gvsig.tools.ToolsLocator;
62 62
import org.gvsig.tools.dynobject.DynClass;
......
80 80
	 *
81 81
	 */
82 82
	private static final long serialVersionUID = 23898787077741411L;
83
	public static final int SHOW_ONLY_THIS_PARAMS = 0;
84
	public static final int HIDDE_THIS_PARAMS = 1;
83
	public static final int SHOW_ALL = 0;
84
	public static final int SHOW_ONLY_THIS_PARAMS = 1;
85
	public static final int HIDDE_THIS_PARAMS = 2;
85 86

  
86 87
	private static boolean debug_mode = false;
87 88

  
......
92 93
	private JButton botAcept;
93 94
	private JButton botCancel;
94 95
	private JButton botRestoreDefaults;
96
	private boolean showButtons;
95 97
	private JPanel panButtons;
96 98
	private JPanel panParameters;
97 99
	private Map<DynField, Component> componentField;
......
101 103

  
102 104

  
103 105
	public DynObjectEditor(DynObject parameters) {
104
		super();
105
		this.parameters = parameters;
106
		this.fields = Arrays.asList(parameters.getDynClass()
107
				.getDynFields());;
108
		this.initialize();
106
		this(parameters, SHOW_ALL, null);
109 107
	}
110 108

  
111
	public DynObjectEditor(DataParameters parameters, int mode,
109
	public DynObjectEditor(DynObject parameters, int mode,
112 110
			List<String> paramsNames) {
111
		this(parameters, SHOW_ALL, null, true);
112

  
113
	}
114

  
115
	public DynObjectEditor(DynObject parameters, int mode,
116
			List<String> paramsNames, boolean showButtons) {
117

  
113 118
		super();
114 119
		this.parameters = parameters;
115 120
		this.fields = Arrays.asList(parameters.getDynClass().getDynFields());
116
		;
121
		this.showButtons = showButtons;
117 122
		if (mode == SHOW_ONLY_THIS_PARAMS || mode == HIDDE_THIS_PARAMS) {
118 123
			ArrayList<DynField> toShow = new ArrayList<DynField>();
119 124
			List<DynField> fields = Arrays.asList(parameters.getDynClass()
......
132 137
				}
133 138
			}
134 139
			this.fields = toShow;
140
		} else if (mode == SHOW_ALL) {
135 141

  
136 142
		} else{
137 143
			throw new IllegalArgumentException();
......
144 150
	private void initialize() {
145 151
		this.setLayout(new BorderLayout(6, 6));
146 152
		this.add(this.getParametersPanel(),BorderLayout.CENTER);
147
		this.add(this.getButtonsPanel(), BorderLayout.SOUTH);
153

  
154
		if (this.showButtons) {
155
			this.add(this.getButtonsPanel(), BorderLayout.SOUTH);
156
		}
148 157
		this.fromParamsToUI();
149 158
	}
150 159

  
......
280 289
		constr.weightx = 1;
281 290

  
282 291
		Object max, min;
283
		double dmax, dmin;
292
		double dmax, dmin,step;
284 293
		max = field.getMaxValue();
285 294
		min = field.getMinValue();
286 295
		boolean decimal;
......
293 302
		}
294 303
		dmax = 0;
295 304
		dmin = 0;
305
		step = 1;
296 306

  
297 307
		switch (field.getType()) {
298 308
		case DataTypes.INT:
......
372 382
			this.getComponentField().put(field, text);
373 383
			return;
374 384
		}
385
		if ((dmax -dmin) != 0){
386
			step = (dmax - dmin) / 20;
387
		}
375 388

  
376 389

  
377
		JIncrementalNumberField inc;
390
		SpinnerModel spinnerModel;
378 391
		if (decimal){
379
			inc = new JIncrementalNumberField("", 15,
380
					ValidatingTextField.DOUBLE_VALIDATOR,
381
					ValidatingTextField.NUMBER_CLEANER, dmin, dmax, 1);
392
			spinnerModel = new SpinnerNumberModel(dmin, dmin, dmax, step);
382 393
		} else{
383
			inc = new JIncrementalNumberField("", 15,
384
					ValidatingTextField.LONG_VALIDATOR,
385
					ValidatingTextField.DUMMY_CLEANER, dmin, dmax, 1);
394
			spinnerModel = new SpinnerNumberModel((int) dmin, (int) dmin,
395
					(int) dmax, (int) step);
386 396
		}
387
		inc.setName(field.getName());
397
		JSpinner spinner = new JSpinner(spinnerModel);
398
		spinner.setName(field.getName());
388 399
		constr.gridwidth = GridBagConstraints.REMAINDER;
389 400
		constr.weightx = 1;
390
		panel.add(inc, constr);
391
		this.getComponentField().put(field, inc);
401
		panel.add(spinner, constr);
402
		this.getComponentField().put(field, spinner);
392 403
	}
393 404

  
394 405
	private void addFieldChoice(JPanel panel, DynField field) {
......
446 457
	}
447 458

  
448 459
	private void fromParamsToUIRange(DynField field, Component component) {
449
		JIncrementalNumberField inc = (JIncrementalNumberField) component;
460
		JSpinner spinner = (JSpinner) component;
450 461

  
451 462
		Object value = parameters.getDynValue(field.getName());
452 463
		double dValue = 0;
......
461 472
			// FIXME ????
462 473
			dValue = 0;
463 474
		}
464
		inc.setDouble(dValue);
475
		spinner.setValue(dValue);
465 476

  
466 477
	}
467 478

  
......
527 538
	}
528 539

  
529 540
	private void fromDefaultsToUIRange(DynField field, Component component) {
530
		JIncrementalNumberField inc = (JIncrementalNumberField) component;
541
		JSpinner spinner = (JSpinner) component;
531 542
		Object value = field.getDefaultValue();
532 543
		double dValue = 0;
533 544
		if (value == null) {
......
544 555
			dValue = 0;
545 556
		}
546 557

  
547
		inc.setDouble(dValue);
558
		spinner.setValue(dValue);
548 559
	}
549 560

  
550
	private void fromParamsToUI() {
561
	public void fromParamsToUI() {
551 562
		Iterator<Entry<DynField, Component>> iter = this.getComponentField().entrySet().iterator();
552 563
		Entry<DynField, Component> entry;
553 564
		while (iter.hasNext()) {
......
573 584
		}
574 585
	}
575 586

  
576
	private void fromDefaultsToUI() {
587
	public void fromDefaultsToUI() {
577 588
		Iterator<Entry<DynField, Component>> iter = this.getComponentField()
578 589
				.entrySet().iterator();
579 590
		Entry<DynField, Component> entry;
......
601 612
	}
602 613

  
603 614

  
604
	private void fromUIToParams() {
615
	public void fromUIToParams() {
605 616
		Iterator<Entry<DynField, Component>> iter = this.getComponentField()
606 617
				.entrySet().iterator();
607 618
		Entry<DynField, Component> entry;
......
672 683
	}
673 684

  
674 685
	private void fromUIToParamsRange(DynField field, Component component) {
675
		JIncrementalNumberField inc = (JIncrementalNumberField) component;
686
		JSpinner spinner = (JSpinner) component;
687
		parameters.setDynValue(field.getName(), spinner.getValue());
676 688

  
677
		parameters.setDynValue(field.getName(), new Double(inc.getDouble()));
678

  
679 689
	}
680 690

  
681 691

  

Also available in: Unified diff