Statistics
| Revision:

root / trunk / extensions / extRasterTools-SE / src / org / gvsig / rastertools / properties / panels / NoDataPanel.java @ 22365

History | View | Annotate | Download (7.18 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.IOException;
29
import java.text.NumberFormat;
30

    
31
import javax.swing.DefaultComboBoxModel;
32
import javax.swing.JButton;
33
import javax.swing.JComboBox;
34
import javax.swing.JFormattedTextField;
35
import javax.swing.JLabel;
36
import javax.swing.JOptionPane;
37
import javax.swing.text.DefaultFormatterFactory;
38
import javax.swing.text.NumberFormatter;
39

    
40
import org.gvsig.fmap.raster.layers.FLyrRasterSE;
41
import org.gvsig.raster.ConfigurationEvent;
42
import org.gvsig.raster.dataset.RasterDataset;
43
import org.gvsig.raster.datastruct.NoData;
44
import org.gvsig.raster.hierarchy.IRasterProperties;
45
import org.gvsig.raster.util.BasePanel;
46
/**
47
 * Panel para la gestion del valor NoData en el panel de propiedades
48
 *
49
 * @version 18/12/2007
50
 * @author BorSanZa - Borja S?nchez Zamorano (borja.sanchez@iver.es)
51
 */
52
public class NoDataPanel extends BasePanel implements ItemListener, ActionListener {
53
        private static final long   serialVersionUID = 7645641060812458944L;
54

    
55
        private JLabel              jLabelValue       = null;
56
        private JComboBox           jComboBoxSetup    = null;
57
        private JButton             buttonSaveDefault = null;
58
        private JFormattedTextField jTextFieldValue   = null;
59
        private INoDataPanel        noDataPanel       = null;
60
        private IRasterProperties   layer             = null;
61

    
62
        public NoDataPanel(INoDataPanel noDataPanel) {
63
                this.noDataPanel = noDataPanel;
64
                setEnabledComponents(false);
65
                init();
66
                translate();
67
        }
68

    
69
        private JComboBox getComboBoxSetup() {
70
                if (jComboBoxSetup == null) {
71
                        jComboBoxSetup = new JComboBox();
72
                        jComboBoxSetup.addItemListener(this);
73
                }
74
                return jComboBoxSetup;
75
        }
76

    
77
        protected void translate() {
78
                getButtonSaveDefault().setText(getText(this, "guardar_predeterminado"));
79
                getComboBoxSetup().setModel(new DefaultComboBoxModel(new String[] { getText(this, "desactivado"), getText(this, "capa"), getText(this, "personalizado") }));
80
                getLabelValue().setText(getText(this, "value") + ":");
81
        }
82

    
83
        private JButton getButtonSaveDefault() {
84
                if (buttonSaveDefault == null) {
85
                        buttonSaveDefault = new JButton();
86
                        buttonSaveDefault.addActionListener(this);
87
                }
88
                return buttonSaveDefault;
89
        }
90

    
91
        private JFormattedTextField getTextFieldValue() {
92
                if (jTextFieldValue == null) {
93
                        NumberFormat integerFormat = NumberFormat.getNumberInstance();
94
                        integerFormat.setParseIntegerOnly(false);
95
                        integerFormat.setMinimumFractionDigits(0);
96
                        integerFormat.setMaximumFractionDigits(3);
97
                        jTextFieldValue = new JFormattedTextField(new DefaultFormatterFactory(
98
                                        new NumberFormatter(integerFormat),
99
                                        new NumberFormatter(integerFormat),
100
                                        new NumberFormatter(integerFormat)));
101
                }
102
                return jTextFieldValue;
103
        }
104

    
105
        private JLabel getLabelValue() {
106
                if (jLabelValue == null) {
107
                        jLabelValue = new JLabel();
108
                }
109
                return jLabelValue;
110
        }
111

    
112
        protected void init() {
113
                GridBagConstraints gridBagConstraints;
114

    
115
                setLayout(new GridBagLayout());
116

    
117
                int col = 0;
118
                gridBagConstraints = new GridBagConstraints();
119
                gridBagConstraints.gridx = col;
120
                gridBagConstraints.gridy = 0;
121
                gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
122
                gridBagConstraints.weightx = 1.0;
123
                gridBagConstraints.insets = new Insets(5, 5, 5, 2);
124
                add(getComboBoxSetup(), gridBagConstraints);
125

    
126
                col++;
127
                gridBagConstraints = new GridBagConstraints();
128
                gridBagConstraints.gridx = col;
129
                gridBagConstraints.gridy = 0;
130
                gridBagConstraints.insets = new Insets(5, 2, 5, 2);
131
                add(getLabelValue(), gridBagConstraints);
132

    
133
                col++;
134
                gridBagConstraints = new GridBagConstraints();
135
                gridBagConstraints.gridx = col;
136
                gridBagConstraints.gridy = 0;
137
                gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
138
                gridBagConstraints.weightx = 1.0;
139
                gridBagConstraints.insets = new Insets(5, 2, 5, 2);
140
                add(getTextFieldValue(), gridBagConstraints);
141

    
142
                col++;
143
                gridBagConstraints = new GridBagConstraints();
144
                gridBagConstraints.gridx = col;
145
                gridBagConstraints.gridy = 0;
146
                gridBagConstraints.insets = new Insets(5, 2, 5, 5);
147
                add(getButtonSaveDefault(), gridBagConstraints);
148
        }
149

    
150
        /*
151
         * (non-Javadoc)
152
         * @see java.awt.event.ItemListener#itemStateChanged(java.awt.event.ItemEvent)
153
         */
154
        public void itemStateChanged(ItemEvent e) {
155
                if (e.getStateChange() == ItemEvent.SELECTED) {
156
                        if (e.getSource() == getComboBoxSetup()) {
157
                                noDataPanel.SourceStateChanged(this, getComboBoxSetup().getSelectedIndex());
158
                                return;
159
                        }
160
                }
161
        }
162

    
163
        public void setComboValueSetup(int pos) {
164
                getComboBoxSetup().setSelectedIndex(pos);
165
                setEnabledComponents(pos == 2);
166
        }
167

    
168
        public void setEnabledComponents(boolean b) {
169
                getTextFieldValue().setEnabled(b);
170
                getLabelValue().setEnabled(b);
171
        }
172

    
173
        public void setNoDataValue(double value) {
174
                getTextFieldValue().setValue(Double.valueOf(value));
175
        }
176

    
177
        public double getNoDataValue() {
178
                return Double.valueOf(getTextFieldValue().getValue().toString()).doubleValue();
179
        }
180

    
181
        public int getComboSetupIndex() {
182
                return getComboBoxSetup().getSelectedIndex();
183
        }
184

    
185
        /*
186
         * (non-Javadoc)
187
         * @see org.gvsig.fmap.raster.util.ConfigurationListener#actionConfigurationChanged(org.gvsig.fmap.raster.util.ConfigurationEvent)
188
         */
189
        public void actionConfigurationChanged(ConfigurationEvent e) {
190
        }
191

    
192
        public void actionPerformed(ActionEvent e) {
193
                if (e.getSource() == getButtonSaveDefault()) {
194
                        saveToRmf();
195
                        return;
196
                }
197
        }
198

    
199
        /**
200
         * Aqui se definen los parametros iniciales para la transparencia del panel
201
         * @param t
202
         */
203
        public void setLayer(IRasterProperties layer) {
204
                this.layer = layer;
205

    
206
                setComboValueSetup(((FLyrRasterSE) layer).getNoDataType());
207
                setNoDataValue(((FLyrRasterSE) layer).getNoDataValue());
208
        }
209

    
210
        /**
211
         * Salva el valor NoData al fichero rmf.
212
         * @param fName
213
         * @throws IOException
214
         */
215
        private void saveToRmf() {
216
                if (JOptionPane.YES_OPTION == JOptionPane.showConfirmDialog(this, getText(this, "nodata_modificado_continuar"))) {
217
                        RasterDataset dataset = ((FLyrRasterSE) layer).getDataSource().getDataset(0)[0];
218
                        dataset.saveObjectToRmf(NoData.class, new NoData(getNoDataValue(), getComboSetupIndex(), layer.getDataType()[0]));
219
                }
220
        }
221
}