Revision 865

View differences:

org.gvsig.raster.tools/trunk/org.gvsig.raster.tools/org.gvsig.raster.tools.app/org.gvsig.raster.tools.app.basic/src/main/java/org/gvsig/raster/tools/app/basic/tool/properties/panel/NoDataNewPanel.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
package org.gvsig.raster.tools.app.basic.tool.properties.panel;
23

  
24
import java.awt.GridBagConstraints;
25
import java.awt.GridBagLayout;
26
import java.awt.Insets;
27
import java.awt.event.ActionEvent;
28
import java.awt.event.ActionListener;
29
import java.text.NumberFormat;
30

  
31
import javax.swing.BorderFactory;
32
import javax.swing.JButton;
33
import javax.swing.JCheckBox;
34
import javax.swing.JFormattedTextField;
35
import javax.swing.JLabel;
36
import javax.swing.JPanel;
37
import javax.swing.text.DefaultFormatterFactory;
38
import javax.swing.text.NumberFormatter;
39

  
40
import org.gvsig.fmap.dal.coverage.RasterLibrary;
41
import org.gvsig.fmap.dal.coverage.dataset.Buffer;
42
import org.gvsig.fmap.dal.coverage.datastruct.NoData;
43
import org.gvsig.raster.fmap.layers.FLyrRaster;
44
import org.gvsig.raster.tools.app.basic.RasterToolsUtil;
45
import org.gvsig.raster.util.BasePanel;
46

  
47
/**
48
 * Panel para la gestion del valor NoData en el panel de propiedades
49
 *
50
 * @author Nacho Brodin (nachobrodin@gmail.com)
51
 */
52
public class NoDataNewPanel extends BasePanel implements ActionListener {
53
	private static final long   serialVersionUID = 7645641060812458944L;
54

  
55
	private JLabel              jLabelValue            = null;
56
	private JButton             buttonSave             = null;
57
	private JButton             buttonDelete           = null;
58
	private JButton             buttonDefaultValue     = null;
59
	private JButton             buttonRestore          = null;
60
	private JFormattedTextField jTextFieldValue        = null;
61
	private JPanel              panelCenter            = null;
62
	private JPanel              panelUp                = null;
63
	private JPanel              panelDown              = null;
64
	private JCheckBox           jCheckBoxNoDataEnabled = null;
65
	private NoData              noData                 = null;
66
	private int                 dataType               = Buffer.TYPE_UNDEFINED;
67

  
68
	public NoDataNewPanel() {
69
		init();
70
		translate();
71
	}
72

  
73
	protected void translate() {
74
		getButtonSave().setText(getText(this, "guardar"));
75
		getButtonSave().setToolTipText(getText(this, "guardar_box_value"));
76
		getButtonRestore().setText(getText(this, "restore"));
77
		getButtonRestore().setToolTipText(getText(this, "restore_native_value"));
78
		getButtonDefaultValue().setText(getText(this, "default_value"));
79
		getButtonDefaultValue().setToolTipText(getText(this, "set_configuration_value"));
80
		getButtonDelete().setText(getText(this, "delete"));
81
		getButtonDelete().setToolTipText(getText(this, "delete_value"));
82
		getCheckBoxNoDataEnabled().setText(getText(this, "tratar_nodata_transparente"));
83
		getCheckBoxNoDataEnabled().setToolTipText(getCheckBoxNoDataEnabled().getText());
84
		getLabelValue().setText(getText(this, "value") + ":");
85
	}
86

  
87
	private JButton getButtonSave() {
88
		if (buttonSave == null) {
89
			buttonSave = new JButton();
90
			buttonSave.addActionListener(this);
91
		}
92
		return buttonSave;
93
	}
94
	
95
	private JButton getButtonDelete() {
96
		if (buttonDelete == null) {
97
			buttonDelete = new JButton();
98
			buttonDelete.addActionListener(this);
99
		}
100
		return buttonDelete;
101
	}
102
	
103
	private JButton getButtonDefaultValue() {
104
		if (buttonDefaultValue == null) {
105
			buttonDefaultValue = new JButton();
106
			buttonDefaultValue.addActionListener(this);
107
		}
108
		return buttonDefaultValue;
109
	}
110
	
111
	private JButton getButtonRestore() {
112
		if (buttonRestore == null) {
113
			buttonRestore = new JButton();
114
			buttonRestore.addActionListener(this);
115
		}
116
		return buttonRestore;
117
	}
118

  
119
	private JFormattedTextField getTextFieldValue() {
120
		if (jTextFieldValue == null) {
121
			NumberFormat integerFormat = NumberFormat.getNumberInstance();
122
			integerFormat.setParseIntegerOnly(false);
123
			integerFormat.setMinimumFractionDigits(0);
124
			integerFormat.setMaximumFractionDigits(3);
125
			jTextFieldValue = new JFormattedTextField(new DefaultFormatterFactory(
126
					new NumberFormatter(integerFormat),
127
					new NumberFormatter(integerFormat),
128
					new NumberFormatter(integerFormat)));
129
		}
130
		return jTextFieldValue;
131
	}
132

  
133
	private JLabel getLabelValue() {
134
		if (jLabelValue == null) {
135
			jLabelValue = new JLabel();
136
		}
137
		return jLabelValue;
138
	}
139

  
140
	protected void init() {
141
		GridBagConstraints gridBagConstraints;
142

  
143
		setLayout(new GridBagLayout());
144

  
145
		gridBagConstraints = new GridBagConstraints();
146
		gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
147
		gridBagConstraints.weightx = 1.0;
148
		add(getPanelUp(), gridBagConstraints);
149

  
150
		gridBagConstraints.gridy = 1;
151
		add(getPanelCenter(), gridBagConstraints);
152

  
153
		gridBagConstraints.gridy = 2;
154
		add(getPanelDown(), gridBagConstraints);
155
	}
156
	
157
	public JCheckBox getCheckBoxNoDataEnabled() {
158
		if (jCheckBoxNoDataEnabled == null) {
159
			jCheckBoxNoDataEnabled = new JCheckBox();
160
			jCheckBoxNoDataEnabled.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
161
			jCheckBoxNoDataEnabled.setMargin(new Insets(0, 0, 0, 0));
162
		}
163
		return jCheckBoxNoDataEnabled;
164
	}
165
	
166
	
167
	private void setCheckBoxValue(double d) {
168
		String text = d + "";
169
		text = text.replaceAll("\\.", ",");
170
		getTextFieldValue().setText(text);
171
	}
172
	
173
	private String getCheckBoxValue() {
174
		String text = getTextFieldValue().getText();
175
		text = text.replaceAll("\\.", "");
176
		text = text.replaceAll(",", "\\.");
177
		return text;
178
	}
179

  
180
	public void setEnabledComponents(boolean b) {
181
		getTextFieldValue().setEnabled(b);
182
		getLabelValue().setEnabled(b);
183
		getButtonDelete().setEnabled(b);
184
		getButtonRestore().setEnabled(b);
185
		getButtonSave().setEnabled(b);
186
		getButtonDefaultValue().setEnabled(b);
187
	}
188

  
189
	public NoData getNoDataValue() {
190
		return noData;
191
	}
192
	
193
	/**
194
	 * Loads the NoData value using the selected text. If the text is
195
	 * null then it reads the text from the text field.
196
	 * @param text
197
	 */
198
	private void loadNoDataFromText(String text) {
199
		if(text == null) 
200
			text = getCheckBoxValue();
201
		
202
		Number number = null;
203
		try {
204
			switch (dataType) {
205
			case Buffer.TYPE_BYTE:
206
				number = new Byte(text);
207
				break;
208
			case Buffer.TYPE_SHORT:
209
				number = new Short(text);
210
				break;
211
			case Buffer.TYPE_INT:
212
				number = new Integer(text);
213
				break;
214
			case Buffer.TYPE_FLOAT:
215
				number = new Float(text);
216
				break;
217
			case Buffer.TYPE_DOUBLE:
218
				number = new Double(text);
219
				break;
220
			}
221
			noData.setValue(number);
222
			noData.save();
223
		}catch (NumberFormatException e1) {
224
			RasterToolsUtil.messageBoxError("error_creating_nodata", this);
225
		}
226
	}
227

  
228
	public void actionPerformed(ActionEvent e) {
229
		//Saves nodata value
230
		if (e.getSource() == getButtonSave()) {
231
			loadNoDataFromText(null);
232
		}
233
		
234
		//Saves default nodata
235
		if (e.getSource() == getButtonDefaultValue()) {
236
			switch (dataType) {
237
			case Buffer.TYPE_BYTE:
238
				loadNoDataFromText(RasterLibrary.defaultByteNoDataValue + "");
239
				break;
240
			case Buffer.TYPE_SHORT:
241
				loadNoDataFromText(RasterLibrary.defaultShortNoDataValue + "");
242
				break;
243
			case Buffer.TYPE_INT:
244
				loadNoDataFromText(RasterLibrary.defaultIntegerNoDataValue + "");
245
				break;
246
			case Buffer.TYPE_FLOAT:
247
				loadNoDataFromText(RasterLibrary.defaultFloatNoDataValue + "");
248
				break;
249
			case Buffer.TYPE_DOUBLE:
250
				loadNoDataFromText(RasterLibrary.defaultDoubleNoDataValue + "");
251
				break;
252
			}
253
			if(noData.isDefined()) {
254
				setCheckBoxValue(noData.getValue().doubleValue());
255
			}
256
		}
257
		
258
		//Deletes nodata value
259
		if (e.getSource() == getButtonDelete()) {
260
			noData.delete();
261
			noData.save();
262
			getTextFieldValue().setText("Not Defined");
263
		}
264
		
265
		//Restores original nodata value
266
		if (e.getSource() == getButtonRestore()) {
267
			noData.restore();
268
			noData.save();
269
			if(noData.isDefined()) {
270
				setCheckBoxValue(noData.getValue().doubleValue());
271
			} else {
272
				getTextFieldValue().setText("Not Defined");
273
			}
274
		}
275
	}
276

  
277
	/**
278
	 * Assigns the data source
279
	 * @param t
280
	 */
281
	public void setLayer(FLyrRaster layer) {
282
		this.noData = layer.getNoDataValue();
283
		this.dataType = layer.getDataStore().getDataType()[0];
284
		if(noData.isDefined()) {
285
			setCheckBoxValue(noData.getValue().doubleValue());
286
		} else {
287
			getTextFieldValue().setText("Not Defined");
288
		}
289
		getCheckBoxNoDataEnabled().setSelected(noData.isNoDataTransparent());
290
	}
291

  
292
	public JPanel getPanelCenter() {
293
		if(panelCenter == null) {
294
			panelCenter = new JPanel();
295
			panelCenter.setLayout(new GridBagLayout());
296
			
297
			GridBagConstraints gridBagConstraints = new GridBagConstraints();
298
			gridBagConstraints.fill = GridBagConstraints.NONE;
299
			gridBagConstraints.insets = new Insets(2, 2, 2, 2);
300
			panelCenter.add(getLabelValue(), gridBagConstraints);
301
			
302
			gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
303
			gridBagConstraints.weightx = 1.0;
304
			gridBagConstraints.gridx = 1;
305
			panelCenter.add(getTextFieldValue(), gridBagConstraints);
306
			
307
			gridBagConstraints.fill = GridBagConstraints.NONE;
308
			gridBagConstraints.weightx = 0.0;
309
			gridBagConstraints.gridx = 2;
310
			panelCenter.add(getButtonSave(), gridBagConstraints);
311
			
312
			gridBagConstraints.gridx = 3;
313
			panelCenter.add(getButtonDelete(), gridBagConstraints);
314

  
315
		}
316
		return panelCenter;
317
	}
318

  
319
	public JPanel getPanelUp() {
320
		if(panelUp == null) {
321
			panelUp = new JPanel();
322
			panelUp.setLayout(new GridBagLayout());
323
			
324
			GridBagConstraints gridBagConstraints = new GridBagConstraints();
325
			gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
326
			gridBagConstraints.weightx = 1.0;
327
			gridBagConstraints.insets = new Insets(2, 2, 2, 2);
328
			panelUp.add(getCheckBoxNoDataEnabled(), gridBagConstraints);
329
		}
330
		return panelUp;
331
	}
332

  
333
	public JPanel getPanelDown() {
334
		if(panelDown == null) {
335
			panelDown = new JPanel();
336
			panelDown.setLayout(new GridBagLayout());
337
			
338
			GridBagConstraints gridBagConstraints = new GridBagConstraints();
339
			gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
340
			gridBagConstraints.weightx = 1.0;
341
			gridBagConstraints.insets = new Insets(2, 2, 2, 2);
342
			panelDown.add(getButtonDefaultValue(), gridBagConstraints);
343
			
344
			gridBagConstraints.gridx = 1;
345
			panelDown.add(getButtonRestore(), gridBagConstraints);
346
		}
347
		return panelDown;
348
	}
349

  
350
}
org.gvsig.raster.tools/trunk/org.gvsig.raster.tools/org.gvsig.raster.tools.app/org.gvsig.raster.tools.app.basic/src/main/java/org/gvsig/raster/tools/app/basic/tool/properties/panel/NoDataPanel.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
package org.gvsig.raster.tools.app.basic.tool.properties.panel;
23

  
24
import java.awt.GridBagConstraints;
25
import java.awt.GridBagLayout;
26
import java.awt.Insets;
27
import java.awt.event.ActionEvent;
28
import java.awt.event.ActionListener;
29
import java.text.NumberFormat;
30

  
31
import javax.swing.BorderFactory;
32
import javax.swing.JButton;
33
import javax.swing.JCheckBox;
34
import javax.swing.JFormattedTextField;
35
import javax.swing.JLabel;
36
import javax.swing.JPanel;
37
import javax.swing.text.DefaultFormatterFactory;
38
import javax.swing.text.NumberFormatter;
39

  
40
import org.gvsig.fmap.dal.coverage.RasterLibrary;
41
import org.gvsig.fmap.dal.coverage.dataset.Buffer;
42
import org.gvsig.fmap.dal.coverage.datastruct.NoData;
43
import org.gvsig.raster.fmap.layers.FLyrRaster;
44
import org.gvsig.raster.tools.app.basic.RasterExtension;
45
import org.gvsig.raster.tools.app.basic.RasterToolsUtil;
46
import org.gvsig.raster.util.BasePanel;
47

  
48
/**
49
 * Panel para la gestion del valor NoData en el panel de propiedades
50
 *
51
 * @author Nacho Brodin (nachobrodin@gmail.com)
52
 */
53
public class NoDataPanel extends BasePanel implements ActionListener {
54
	private static final long   serialVersionUID       = 7645641060812458944L;
55
	private static final String NULL_NODATA            = "Not Defined";
56
	private JLabel              jLabelValue            = null;
57
	private JButton             buttonSave             = null;
58
	private JButton             buttonDelete           = null;
59
	private JButton             buttonDefaultValue     = null;
60
	private JButton             buttonRestore          = null;
61
	private JFormattedTextField jTextFieldValue        = null;
62
	private JPanel              panelCenter            = null;
63
	private JPanel              panelUp                = null;
64
	private JPanel              panelDown              = null;
65
	private JCheckBox           jCheckBoxNoDataEnabled = null;
66
	private NoData              noData                 = null;
67
	private int                 dataType               = Buffer.TYPE_UNDEFINED;
68
	private FLyrRaster          lyr                    = null;
69

  
70
	public NoDataPanel() {
71
		init();
72
		translate();
73
	}
74

  
75
	protected void translate() {
76
		getButtonSave().setText(getText(this, "guardar"));
77
		getButtonSave().setToolTipText(getText(this, "guardar_box_value"));
78
		getButtonRestore().setText(getText(this, "restore"));
79
		getButtonRestore().setToolTipText(getText(this, "restore_native_value"));
80
		getButtonDefaultValue().setText(getText(this, "default_value"));
81
		getButtonDefaultValue().setToolTipText(getText(this, "set_configuration_value"));
82
		getButtonDelete().setText(getText(this, "delete"));
83
		getButtonDelete().setToolTipText(getText(this, "delete_value"));
84
		getCheckBoxNoDataEnabled().setText(getText(this, "tratar_nodata_transparente"));
85
		getCheckBoxNoDataEnabled().setToolTipText(getCheckBoxNoDataEnabled().getText());
86
		getLabelValue().setText(getText(this, "value") + ":");
87
	}
88

  
89
	private JButton getButtonSave() {
90
		if (buttonSave == null) {
91
			buttonSave = new JButton();
92
			buttonSave.addActionListener(this);
93
		}
94
		return buttonSave;
95
	}
96
	
97
	private JButton getButtonDelete() {
98
		if (buttonDelete == null) {
99
			buttonDelete = new JButton();
100
			buttonDelete.addActionListener(this);
101
		}
102
		return buttonDelete;
103
	}
104
	
105
	private JButton getButtonDefaultValue() {
106
		if (buttonDefaultValue == null) {
107
			buttonDefaultValue = new JButton();
108
			buttonDefaultValue.addActionListener(this);
109
		}
110
		return buttonDefaultValue;
111
	}
112
	
113
	private JButton getButtonRestore() {
114
		if (buttonRestore == null) {
115
			buttonRestore = new JButton();
116
			buttonRestore.addActionListener(this);
117
		}
118
		return buttonRestore;
119
	}
120

  
121
	private JFormattedTextField getTextFieldValue() {
122
		if (jTextFieldValue == null) {
123
			NumberFormat integerFormat = NumberFormat.getNumberInstance();
124
			integerFormat.setParseIntegerOnly(false);
125
			integerFormat.setMinimumFractionDigits(0);
126
			integerFormat.setMaximumFractionDigits(3);
127
			jTextFieldValue = new JFormattedTextField(new DefaultFormatterFactory(
128
					new NumberFormatter(integerFormat),
129
					new NumberFormatter(integerFormat),
130
					new NumberFormatter(integerFormat)));
131
		}
132
		return jTextFieldValue;
133
	}
134

  
135
	private JLabel getLabelValue() {
136
		if (jLabelValue == null) {
137
			jLabelValue = new JLabel();
138
		}
139
		return jLabelValue;
140
	}
141

  
142
	protected void init() {
143
		GridBagConstraints gridBagConstraints;
144

  
145
		setLayout(new GridBagLayout());
146

  
147
		gridBagConstraints = new GridBagConstraints();
148
		gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
149
		gridBagConstraints.weightx = 1.0;
150
		add(getPanelUp(), gridBagConstraints);
151

  
152
		gridBagConstraints.gridy = 1;
153
		add(getPanelCenter(), gridBagConstraints);
154

  
155
		gridBagConstraints.gridy = 2;
156
		add(getPanelDown(), gridBagConstraints);
157
	}
158
	
159
	public JCheckBox getCheckBoxNoDataEnabled() {
160
		if (jCheckBoxNoDataEnabled == null) {
161
			jCheckBoxNoDataEnabled = new JCheckBox();
162
			jCheckBoxNoDataEnabled.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
163
			jCheckBoxNoDataEnabled.setMargin(new Insets(0, 0, 0, 0));
164
		}
165
		return jCheckBoxNoDataEnabled;
166
	}
167
	
168
	
169
	private void setCheckBoxValue(double d) {
170
		String text = d + "";
171
		text = text.replaceAll("\\.", ",");
172
		getTextFieldValue().setText(text);
173
	}
174
	
175
	private String getCheckBoxValue() {
176
		String text = getTextFieldValue().getText();
177
		text = text.replaceAll("\\.", "");
178
		text = text.replaceAll(",", "\\.");
179
		return text;
180
	}
181

  
182
	public void setEnabledComponents(boolean b) {
183
		getTextFieldValue().setEnabled(b);
184
		getLabelValue().setEnabled(b);
185
		getButtonDelete().setEnabled(b);
186
		getButtonRestore().setEnabled(b);
187
		getButtonSave().setEnabled(b);
188
		getButtonDefaultValue().setEnabled(b);
189
	}
190

  
191
	public NoData getNoDataValue() {
192
		return noData;
193
	}
194
	
195
	/**
196
	 * Loads the NoData value using the selected text. If the text is
197
	 * null then it reads the text from the text field.
198
	 * @param text
199
	 */
200
	private void loadNoDataFromText(String text) {
201
		if(text == null) 
202
			text = getCheckBoxValue();
203
		
204
		if(text.compareTo(NULL_NODATA) == 0) {
205
			noData.setValue(null);
206
			noData.save();
207
			return;
208
		}
209
		
210
		Number number = null;
211
		try {
212
			switch (dataType) {
213
			case Buffer.TYPE_BYTE:
214
				if(text.contains(".")) 
215
					text = text.substring(0, text.lastIndexOf("."));
216
				number = new Byte(text);
217
				break;
218
			case Buffer.TYPE_SHORT:
219
				if(text.contains(".")) 
220
					text = text.substring(0, text.lastIndexOf("."));
221
				number = new Short(text);
222
				break;
223
			case Buffer.TYPE_INT:
224
				if(text.contains(".")) 
225
					text = text.substring(0, text.lastIndexOf("."));
226
				number = new Integer(text);
227
				break;
228
			case Buffer.TYPE_FLOAT:
229
				number = new Float(text);
230
				break;
231
			case Buffer.TYPE_DOUBLE:
232
				number = new Double(text);
233
				break;
234
			}
235
			noData.setValue(number);
236
			noData.save();
237
		}catch (NumberFormatException e1) {
238
			RasterToolsUtil.messageBoxError("value_not_valid", this);
239
		}
240
	}
241

  
242
	public void actionPerformed(ActionEvent e) {
243
		//Saves nodata value
244
		if (e.getSource() == getButtonSave()) {
245
			loadNoDataFromText(null);
246
		}
247
		
248
		//Saves default nodata
249
		if (e.getSource() == getButtonDefaultValue()) {
250
			switch (dataType) {
251
			case Buffer.TYPE_BYTE:
252
				loadNoDataFromText(RasterLibrary.defaultByteNoDataValue + "");
253
				break;
254
			case Buffer.TYPE_SHORT:
255
				loadNoDataFromText(RasterLibrary.defaultShortNoDataValue + "");
256
				break;
257
			case Buffer.TYPE_INT:
258
				loadNoDataFromText(RasterLibrary.defaultIntegerNoDataValue + "");
259
				break;
260
			case Buffer.TYPE_FLOAT:
261
				loadNoDataFromText(RasterLibrary.defaultFloatNoDataValue + "");
262
				break;
263
			case Buffer.TYPE_DOUBLE:
264
				loadNoDataFromText(RasterLibrary.defaultDoubleNoDataValue + "");
265
				break;
266
			}
267
			if(noData.isDefined()) {
268
				setCheckBoxValue(noData.getValue().doubleValue());
269
			}
270
		}
271
		
272
		//Deletes nodata value
273
		if (e.getSource() == getButtonDelete()) {
274
			noData.delete();
275
			noData.save();
276
			getTextFieldValue().setText(NULL_NODATA);
277
		}
278
		
279
		//Restores original nodata value
280
		if (e.getSource() == getButtonRestore()) {
281
			noData.restore();
282
			noData.save();
283
			if(noData.isDefined()) {
284
				setCheckBoxValue(noData.getValue().doubleValue());
285
			} else {
286
				getTextFieldValue().setText(NULL_NODATA);
287
			}
288
		}
289
		
290
		if (RasterExtension.autoRefreshView) {
291
			if (lyr == null || lyr.getDataStore() == null)
292
				return;
293

  
294
			lyr.setNoDataTransparent(getCheckBoxNoDataEnabled().isSelected());
295

  
296
			// Redibujamos
297
			lyr.getMapContext().invalidate();
298
		}
299
	}
300

  
301
	/**
302
	 * Assigns the data source
303
	 * @param t
304
	 */
305
	public void setLayer(FLyrRaster layer) {
306
		this.lyr = layer;
307
		this.noData = layer.getNoDataValue();
308
		this.dataType = layer.getDataStore().getDataType()[0];
309
		if(noData.isDefined()) {
310
			setCheckBoxValue(noData.getValue().doubleValue());
311
		} else {
312
			getTextFieldValue().setText("Not Defined");
313
		}
314
		getCheckBoxNoDataEnabled().setSelected(noData.isNoDataTransparent());
315
	}
316

  
317
	public JPanel getPanelCenter() {
318
		if(panelCenter == null) {
319
			panelCenter = new JPanel();
320
			panelCenter.setLayout(new GridBagLayout());
321
			
322
			GridBagConstraints gridBagConstraints = new GridBagConstraints();
323
			gridBagConstraints.fill = GridBagConstraints.NONE;
324
			gridBagConstraints.insets = new Insets(2, 2, 2, 2);
325
			panelCenter.add(getLabelValue(), gridBagConstraints);
326
			
327
			gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
328
			gridBagConstraints.weightx = 1.0;
329
			gridBagConstraints.gridx = 1;
330
			panelCenter.add(getTextFieldValue(), gridBagConstraints);
331
			
332
			gridBagConstraints.fill = GridBagConstraints.NONE;
333
			gridBagConstraints.weightx = 0.0;
334
			gridBagConstraints.gridx = 2;
335
			panelCenter.add(getButtonSave(), gridBagConstraints);
336
			
337
			gridBagConstraints.gridx = 3;
338
			panelCenter.add(getButtonDelete(), gridBagConstraints);
339

  
340
		}
341
		return panelCenter;
342
	}
343

  
344
	public JPanel getPanelUp() {
345
		if(panelUp == null) {
346
			panelUp = new JPanel();
347
			panelUp.setLayout(new GridBagLayout());
348
			
349
			GridBagConstraints gridBagConstraints = new GridBagConstraints();
350
			gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
351
			gridBagConstraints.weightx = 1.0;
352
			gridBagConstraints.insets = new Insets(2, 2, 2, 2);
353
			panelUp.add(getCheckBoxNoDataEnabled(), gridBagConstraints);
354
		}
355
		return panelUp;
356
	}
357

  
358
	public JPanel getPanelDown() {
359
		if(panelDown == null) {
360
			panelDown = new JPanel();
361
			panelDown.setLayout(new GridBagLayout());
362
			
363
			GridBagConstraints gridBagConstraints = new GridBagConstraints();
364
			gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
365
			gridBagConstraints.weightx = 1.0;
366
			gridBagConstraints.insets = new Insets(2, 2, 2, 2);
367
			panelDown.add(getButtonDefaultValue(), gridBagConstraints);
368
			
369
			gridBagConstraints.gridx = 1;
370
			panelDown.add(getButtonRestore(), gridBagConstraints);
371
		}
372
		return panelDown;
373
	}
374

  
375
}
0 376

  
org.gvsig.raster.tools/trunk/org.gvsig.raster.tools/org.gvsig.raster.tools.app/org.gvsig.raster.tools.app.basic/src/main/java/org/gvsig/raster/tools/app/basic/tool/properties/panel/GeneralPanel.java
79 79
	private JButton             calcButton          = null;
80 80
	private JPanel              scalePanel          = null;
81 81
	private JPanel              recalcStatsPanel    = null;
82
	private NoDataNewPanel      pNoDataPanel        = null;
82
	private NoDataPanel      pNoDataPanel        = null;
83 83
	//private Transparency        transparency        = null;
84 84
	
85 85
	private JScrollPane         jScrollPane         = null;
......
175 175
	 * This method initializes TranspOpacitySliderPanel
176 176
	 * @return javax.swing.JPanel
177 177
	 */
178
	public NoDataNewPanel getNoDataPanel() {
178
	public NoDataPanel getNoDataPanel() {
179 179
		if (pNoDataPanel == null) {
180
			pNoDataPanel = new NoDataNewPanel();
180
			pNoDataPanel = new NoDataPanel();
181 181
			pNoDataPanel.setBorder(BorderFactory.createTitledBorder(null, PluginServices.getText(this, "nodata"), TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, null, null));
182 182
		}
183 183

  
org.gvsig.raster.tools/trunk/org.gvsig.raster.tools/org.gvsig.raster.tools.app/org.gvsig.raster.tools.app.basic/src/main/resources/text.properties
542 542
delete=Eliminar
543 543
delete_value=Eliminar valor NoData de la imagen
544 544
tratar_nodata_transparente=Tratar valor NoData como transparente
545
value_not_valid=Valor no valido para un valor NoData
org.gvsig.raster.tools/trunk/org.gvsig.raster.tools/org.gvsig.raster.tools.app/org.gvsig.raster.tools.app.basic/src/main/resources/text_en.properties
526 526
set_configuration_value=Assigns the NoData value by default in gvSIG configuration
527 527
delete=Delete
528 528
delete_value=Deletes the NoData value of this layer
529
tratar_nodata_transparente=Draw the NoData values transparent
529
tratar_nodata_transparente=Draw the NoData values transparent
530
value_not_valid=This NoData value is not valid
org.gvsig.raster.tools/trunk/org.gvsig.raster.tools/org.gvsig.raster.tools.app/org.gvsig.raster.tools.app.basic/src/test/java/org/gvsig/raster/app/extension/TestNoDataPanel.java
2 2

  
3 3
import javax.swing.JFrame;
4 4

  
5
import org.gvsig.raster.tools.app.basic.tool.properties.panel.NoDataNewPanel;
5
import org.gvsig.raster.tools.app.basic.tool.properties.panel.NoDataPanel;
6 6

  
7 7
public class TestNoDataPanel {
8 8
		private int                          w        = 510;
9 9
		private int                          h        = 300;
10 10
		private JFrame                       frame    = new JFrame();
11
		private NoDataNewPanel               desc     = null;
11
		private NoDataPanel               desc     = null;
12 12

  
13 13
		public TestNoDataPanel() {
14
			desc = new NoDataNewPanel();
14
			desc = new NoDataPanel();
15 15
			frame.getContentPane().add(desc);
16 16
			frame.setSize(w, h);
17 17
			frame.setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

Also available in: Unified diff