Statistics
| Revision:

root / trunk / extensions / extRasterTools-SE / src / org / gvsig / raster / gui / preferences / panels / PreferenceNoData.java @ 17491

History | View | Annotate | Download (5.78 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.raster.gui.preferences.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.text.NumberFormat;
27

    
28
import javax.swing.BorderFactory;
29
import javax.swing.JCheckBox;
30
import javax.swing.JFormattedTextField;
31
import javax.swing.JLabel;
32
import javax.swing.text.DefaultFormatterFactory;
33
import javax.swing.text.NumberFormatter;
34

    
35
import org.gvsig.fmap.raster.util.Configuration;
36
import org.gvsig.raster.RasterLibrary;
37
import org.gvsig.raster.util.PanelBase;
38
/**
39
 *
40
 * @version 10/12/2007
41
 * @author BorSanZa - Borja S?nchez Zamorano (borja.sanchez@iver.es)
42
 */
43
public class PreferenceNoData extends PanelBase implements ActionListener {
44
        private static final long serialVersionUID = -8964531984609056094L;
45
        private JCheckBox           jCheckBoxNoDataEnabled = null;
46
        private JLabel              jLabelGeneralValue     = null;
47
        private JFormattedTextField textFieldGeneralValue  = null;
48

    
49
        public PreferenceNoData() {
50
                initialize();
51
                translate();
52
        }
53

    
54
        private void translate() {
55
                getPanel().setBorder(BorderFactory.createTitledBorder(getText(this, "nodata")));
56
                getCheckBoxNoDataEnabled().setText(getText(this, "activar_uso_nodata"));
57
                getCheckBoxNoDataEnabled().setToolTipText(getText(this, "activar_uso_nodata"));
58
                getLabelGeneralValue().setText(getText(this, "valor_general") + ":");
59
        }
60

    
61
        private void initialize() {
62
                getPanel().setLayout(new GridBagLayout());
63

    
64
                int posy = 0;
65
                GridBagConstraints gridBagConstraints;
66
                gridBagConstraints = new GridBagConstraints();
67
                gridBagConstraints.gridy = posy;
68
                gridBagConstraints.gridwidth = 2;
69
                gridBagConstraints.anchor = GridBagConstraints.WEST;
70
                gridBagConstraints.insets = new Insets(5, 5, 2, 5);
71
                getPanel().add(getCheckBoxNoDataEnabled(), gridBagConstraints);
72

    
73
                posy++;
74
                gridBagConstraints = new GridBagConstraints();
75
                gridBagConstraints.gridx = 0;
76
                gridBagConstraints.gridy = posy;
77
                gridBagConstraints.anchor = GridBagConstraints.EAST;
78
                gridBagConstraints.insets = new Insets(2, 5, 2, 2);
79
                getPanel().add(getLabelGeneralValue(), gridBagConstraints);
80

    
81
                gridBagConstraints = new GridBagConstraints();
82
                gridBagConstraints.gridx = 1;
83
                gridBagConstraints.gridy = posy;
84
                gridBagConstraints.fill = GridBagConstraints.BOTH;
85
                gridBagConstraints.anchor = GridBagConstraints.WEST;
86
                gridBagConstraints.weightx = 1.0;
87
                gridBagConstraints.insets = new Insets(2, 2, 2, 5);
88
                getPanel().add(getTextFieldGeneralValue(), gridBagConstraints);
89
        }
90

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

    
105
        private JCheckBox getCheckBoxNoDataEnabled() {
106
                if (jCheckBoxNoDataEnabled == null) {
107
                        jCheckBoxNoDataEnabled = new JCheckBox();
108
                        jCheckBoxNoDataEnabled.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
109
                        jCheckBoxNoDataEnabled.setMargin(new Insets(0, 0, 0, 0));
110
                        jCheckBoxNoDataEnabled.addActionListener(this);
111
                }
112
                return jCheckBoxNoDataEnabled;
113
        }
114

    
115
        private JLabel getLabelGeneralValue() {
116
                if (jLabelGeneralValue == null) {
117
                        jLabelGeneralValue = new JLabel();
118
                }
119
                return jLabelGeneralValue;
120
        }
121

    
122
        private void setNoDataEnabled(boolean enabled) {
123
                getLabelGeneralValue().setEnabled(enabled);
124
                getTextFieldGeneralValue().setEnabled(enabled);
125
        }
126

    
127
        public void initializeDefaults() {
128
                Boolean enabled = (Boolean) Configuration.getDefaultValue("nodata_enabled");
129
                getCheckBoxNoDataEnabled().setSelected(enabled.booleanValue());
130
                setNoDataEnabled(enabled.booleanValue());
131
                getTextFieldGeneralValue().setValue((Double) Configuration.getDefaultValue("nodata_value"));
132
        }
133

    
134
        public void initializeValues() {
135
                Boolean enabled = Configuration.getValue("nodata_enabled", Boolean.valueOf(RasterLibrary.noDataEnabled));
136
                getCheckBoxNoDataEnabled().setSelected(enabled.booleanValue());
137
                setNoDataEnabled(enabled.booleanValue());
138
                getTextFieldGeneralValue().setValue(Configuration.getValue("nodata_value", Double.valueOf(RasterLibrary.noDataValue)));
139
        }
140

    
141
        public void storeValues() {
142
                Configuration.setValue("nodata_enabled", Boolean.valueOf(getCheckBoxNoDataEnabled().isSelected()));
143
                try {
144
                        Configuration.setValue("nodata_value", Double.valueOf(getTextFieldGeneralValue().getText()));
145
                } catch (NumberFormatException e) {
146
                }
147
        }
148

    
149
        public void actionPerformed(ActionEvent e) {
150
                if (e.getSource() == getCheckBoxNoDataEnabled()) {
151
                        setNoDataEnabled(getCheckBoxNoDataEnabled().isSelected());
152
                }
153
        }
154
}