svn-gvsig-desktop / trunk / extensions / extRasterTools-SE / src / org / gvsig / rastertools / properties / panels / NoDataPanel.java @ 18014
History | View | Annotate | Download (8.15 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2005 IVER T.I. and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*/
|
19 |
package org.gvsig.rastertools.properties.panels; |
20 |
|
21 |
import java.awt.GridBagConstraints; |
22 |
import java.awt.GridBagLayout; |
23 |
import java.awt.Insets; |
24 |
import java.awt.event.ActionEvent; |
25 |
import java.awt.event.ActionListener; |
26 |
import java.awt.event.ItemEvent; |
27 |
import java.awt.event.ItemListener; |
28 |
import java.io.FileNotFoundException; |
29 |
import java.io.IOException; |
30 |
import java.text.NumberFormat; |
31 |
|
32 |
import javax.swing.DefaultComboBoxModel; |
33 |
import javax.swing.JButton; |
34 |
import javax.swing.JComboBox; |
35 |
import javax.swing.JFormattedTextField; |
36 |
import javax.swing.JLabel; |
37 |
import javax.swing.JOptionPane; |
38 |
import javax.swing.text.DefaultFormatterFactory; |
39 |
import javax.swing.text.NumberFormatter; |
40 |
|
41 |
import org.gvsig.fmap.raster.layers.FLyrRasterSE; |
42 |
import org.gvsig.raster.Configuration; |
43 |
import org.gvsig.raster.ConfigurationEvent; |
44 |
import org.gvsig.raster.ConfigurationListener; |
45 |
import org.gvsig.raster.dataset.io.rmf.RmfBlocksManager; |
46 |
import org.gvsig.raster.datastruct.serializer.NoDataRmfSerializer; |
47 |
import org.gvsig.raster.hierarchy.IRasterProperties; |
48 |
import org.gvsig.raster.util.PanelBase; |
49 |
import org.gvsig.rastertools.properties.panels.interfaces.INoDataPanel; |
50 |
/**
|
51 |
* Panel para la gestion del valor NoData en el panel de propiedades
|
52 |
*
|
53 |
* @version 18/12/2007
|
54 |
* @author BorSanZa - Borja S?nchez Zamorano (borja.sanchez@iver.es)
|
55 |
*/
|
56 |
public class NoDataPanel extends PanelBase implements ItemListener, ConfigurationListener, ActionListener { |
57 |
private static final long serialVersionUID = 7645641060812458944L; |
58 |
|
59 |
private JLabel jLabelValue = null; |
60 |
private JComboBox jComboBoxSetup = null; |
61 |
private JButton buttonSaveDefault = null; |
62 |
private JFormattedTextField jTextFieldValue = null; |
63 |
private INoDataPanel noDataPanel = null; |
64 |
private IRasterProperties layer = null; |
65 |
|
66 |
public NoDataPanel(INoDataPanel noDataPanel) {
|
67 |
initialize(); |
68 |
translate(); |
69 |
this.noDataPanel = noDataPanel;
|
70 |
Configuration.addValueChangedListener(this); |
71 |
setEnabledComponents(false);
|
72 |
} |
73 |
|
74 |
private JComboBox getComboBoxSetup() { |
75 |
if (jComboBoxSetup == null) { |
76 |
jComboBoxSetup = new JComboBox(); |
77 |
jComboBoxSetup.addItemListener(this);
|
78 |
} |
79 |
return jComboBoxSetup;
|
80 |
} |
81 |
|
82 |
private void translate() { |
83 |
getButtonSaveDefault().setText(getText(this, "guardar_predeterminado")); |
84 |
getComboBoxSetup().setModel(new DefaultComboBoxModel(new String[] { getText(this, "global"), getText(this, "capa"), getText(this, "personalizado") })); |
85 |
getLabelValue().setText(getText(this, "value") + ":"); |
86 |
} |
87 |
|
88 |
private JButton getButtonSaveDefault() { |
89 |
if (buttonSaveDefault == null) { |
90 |
buttonSaveDefault = new JButton(); |
91 |
buttonSaveDefault.addActionListener(this);
|
92 |
} |
93 |
return buttonSaveDefault;
|
94 |
} |
95 |
|
96 |
private JFormattedTextField getTextFieldValue() { |
97 |
if (jTextFieldValue == null) { |
98 |
NumberFormat integerFormat = NumberFormat.getNumberInstance(); |
99 |
integerFormat.setParseIntegerOnly(false);
|
100 |
integerFormat.setMinimumFractionDigits(0);
|
101 |
integerFormat.setMaximumFractionDigits(3);
|
102 |
jTextFieldValue = new JFormattedTextField(new DefaultFormatterFactory( |
103 |
new NumberFormatter(integerFormat), |
104 |
new NumberFormatter(integerFormat), |
105 |
new NumberFormatter(integerFormat))); |
106 |
} |
107 |
return jTextFieldValue;
|
108 |
} |
109 |
|
110 |
private JLabel getLabelValue() { |
111 |
if (jLabelValue == null) { |
112 |
jLabelValue = new JLabel(); |
113 |
} |
114 |
return jLabelValue;
|
115 |
} |
116 |
|
117 |
private void initialize() { |
118 |
GridBagConstraints gridBagConstraints;
|
119 |
|
120 |
getPanel().setLayout(new GridBagLayout()); |
121 |
|
122 |
int col = 0; |
123 |
gridBagConstraints = new GridBagConstraints(); |
124 |
gridBagConstraints.gridx = col; |
125 |
gridBagConstraints.gridy = 0;
|
126 |
gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
|
127 |
gridBagConstraints.weightx = 1.0;
|
128 |
gridBagConstraints.insets = new Insets(5, 5, 5, 2); |
129 |
getPanel().add(getComboBoxSetup(), gridBagConstraints); |
130 |
|
131 |
col++; |
132 |
gridBagConstraints = new GridBagConstraints(); |
133 |
gridBagConstraints.gridx = col; |
134 |
gridBagConstraints.gridy = 0;
|
135 |
gridBagConstraints.insets = new Insets(5, 2, 5, 2); |
136 |
getPanel().add(getLabelValue(), gridBagConstraints); |
137 |
|
138 |
col++; |
139 |
gridBagConstraints = new GridBagConstraints(); |
140 |
gridBagConstraints.gridx = col; |
141 |
gridBagConstraints.gridy = 0;
|
142 |
gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
|
143 |
gridBagConstraints.weightx = 1.0;
|
144 |
gridBagConstraints.insets = new Insets(5, 2, 5, 2); |
145 |
getPanel().add(getTextFieldValue(), gridBagConstraints); |
146 |
|
147 |
col++; |
148 |
gridBagConstraints = new GridBagConstraints(); |
149 |
gridBagConstraints.gridx = col; |
150 |
gridBagConstraints.gridy = 0;
|
151 |
gridBagConstraints.insets = new Insets(5, 2, 5, 5); |
152 |
getPanel().add(getButtonSaveDefault(), gridBagConstraints); |
153 |
|
154 |
getPanel().setVisible(Configuration.getValue("nodata_transparency_enabled", Boolean.FALSE).booleanValue()); |
155 |
} |
156 |
|
157 |
/*
|
158 |
* (non-Javadoc)
|
159 |
* @see java.awt.event.ItemListener#itemStateChanged(java.awt.event.ItemEvent)
|
160 |
*/
|
161 |
public void itemStateChanged(ItemEvent e) { |
162 |
if (e.getStateChange() == ItemEvent.SELECTED) { |
163 |
if (e.getSource() == getComboBoxSetup()) {
|
164 |
noDataPanel.SourceStateChanged(this, getComboBoxSetup().getSelectedIndex());
|
165 |
return;
|
166 |
} |
167 |
} |
168 |
} |
169 |
|
170 |
public void setComboValueSetup(int pos) { |
171 |
getComboBoxSetup().setSelectedIndex(pos); |
172 |
setEnabledComponents(pos == 2);
|
173 |
} |
174 |
|
175 |
public void setEnabledComponents(boolean b) { |
176 |
getTextFieldValue().setEnabled(b); |
177 |
getLabelValue().setEnabled(b); |
178 |
} |
179 |
|
180 |
public void setNoDataValue(double value) { |
181 |
getTextFieldValue().setValue(Double.valueOf(value));
|
182 |
} |
183 |
|
184 |
public double getNoDataValue() { |
185 |
return Double.valueOf(getTextFieldValue().getValue().toString()).doubleValue(); |
186 |
} |
187 |
|
188 |
public int getComboSetupIndex() { |
189 |
return getComboBoxSetup().getSelectedIndex();
|
190 |
} |
191 |
|
192 |
/*
|
193 |
* (non-Javadoc)
|
194 |
* @see org.gvsig.fmap.raster.util.ConfigurationListener#actionConfigurationChanged(org.gvsig.fmap.raster.util.ConfigurationEvent)
|
195 |
*/
|
196 |
public void actionConfigurationChanged(ConfigurationEvent e) { |
197 |
if (e.getKey().equals("nodata_transparency_enabled")) { |
198 |
getPanel().setVisible(((Boolean) e.getValue()).booleanValue());
|
199 |
} |
200 |
|
201 |
if (e.getKey().equals("nodata_value")) { |
202 |
if (getComboSetupIndex() == 0) |
203 |
setNoDataValue(((Double) e.getValue()).doubleValue());
|
204 |
} |
205 |
} |
206 |
|
207 |
public void actionPerformed(ActionEvent e) { |
208 |
if (e.getSource() == getButtonSaveDefault()) {
|
209 |
saveToRmf(); |
210 |
return;
|
211 |
} |
212 |
} |
213 |
|
214 |
/**
|
215 |
* Aqui se definen los parametros iniciales para la transparencia del panel
|
216 |
* @param t
|
217 |
*/
|
218 |
public void setLayer(IRasterProperties layer) { |
219 |
this.layer = layer;
|
220 |
|
221 |
setComboValueSetup(((FLyrRasterSE) layer).getNoDataType()); |
222 |
setNoDataValue(((FLyrRasterSE) layer).getNoDataValue()); |
223 |
} |
224 |
|
225 |
/**
|
226 |
* Salva el valor NoData al fichero rmf.
|
227 |
* @param fName
|
228 |
* @throws IOException
|
229 |
*/
|
230 |
private void saveToRmf() { |
231 |
if (JOptionPane.YES_OPTION == JOptionPane.showConfirmDialog(getPanel(), getText(this, "nodata_modificado_continuar"))) { |
232 |
|
233 |
RmfBlocksManager manager = ((FLyrRasterSE) layer).getDataSource().getDataset(0)[0].getRmfBlocksManager(); |
234 |
NoDataRmfSerializer ser; |
235 |
ser = new NoDataRmfSerializer(Double.valueOf(getNoDataValue())); |
236 |
|
237 |
if (!manager.checkRmf())
|
238 |
return;
|
239 |
manager.addClient(ser); |
240 |
try {
|
241 |
manager.write(true);
|
242 |
} catch (FileNotFoundException e) { |
243 |
} catch (IOException e) { |
244 |
|
245 |
} |
246 |
manager.removeClient(ser.getClass()); |
247 |
} |
248 |
} |
249 |
} |