Statistics
| Revision:

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

History | View | Annotate | Download (5.63 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.text.NumberFormat;
25

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

    
33
import org.gvsig.raster.Configuration;
34
import org.gvsig.raster.RasterLibrary;
35
import org.gvsig.raster.util.BasePanel;
36
/**
37
 * Panel para la gesti?n del valor NoData en el panel de preferencias de gvSIG.
38
 *
39
 * @version 10/12/2007
40
 * @author BorSanZa - Borja S?nchez Zamorano (borja.sanchez@iver.es)
41
 */
42
public class PreferenceNoData extends BasePanel {
43
        private static final long   serialVersionUID = -8964531984609056094L;
44
        private JCheckBox           jCheckBoxNoDataEnabled = null;
45
        private JLabel              jLabelGeneralValue     = null;
46
        private JFormattedTextField textFieldGeneralValue  = null;
47

    
48
        /**
49
         *Inicializa componentes gr?ficos y traduce
50
         */
51
        public PreferenceNoData() {
52
                init();
53
                translate();
54
        }
55
        
56
        /*
57
         * (non-Javadoc)
58
         * @see org.gvsig.raster.util.BasePanel#translate()
59
         */
60
        protected void translate() {
61
                setBorder(BorderFactory.createTitledBorder(getText(this, "nodata")));
62
                getCheckBoxNoDataEnabled().setText(getText(this, "tratar_nodata_transparente"));
63
                getCheckBoxNoDataEnabled().setToolTipText(getCheckBoxNoDataEnabled().getText());
64
                getLabelGeneralValue().setText(getText(this, "valor_general") + ":");
65
        }
66

    
67
        /*
68
         * (non-Javadoc)
69
         * @see org.gvsig.raster.util.BasePanel#init()
70
         */
71
        protected void init() {
72
                setLayout(new GridBagLayout());
73

    
74
                int posy = 0;
75
                GridBagConstraints gridBagConstraints;
76
                gridBagConstraints = new GridBagConstraints();
77
                gridBagConstraints.gridy = posy;
78
                gridBagConstraints.gridwidth = 2;
79
                gridBagConstraints.anchor = GridBagConstraints.WEST;
80
                gridBagConstraints.insets = new Insets(5, 5, 2, 5);
81
                add(getCheckBoxNoDataEnabled(), gridBagConstraints);
82

    
83
                posy++;
84
                gridBagConstraints = new GridBagConstraints();
85
                gridBagConstraints.gridx = 0;
86
                gridBagConstraints.gridy = posy;
87
                gridBagConstraints.anchor = GridBagConstraints.EAST;
88
                gridBagConstraints.insets = new Insets(2, 5, 2, 2);
89
                add(getLabelGeneralValue(), gridBagConstraints);
90

    
91
                gridBagConstraints = new GridBagConstraints();
92
                gridBagConstraints.gridx = 1;
93
                gridBagConstraints.gridy = posy;
94
                gridBagConstraints.fill = GridBagConstraints.BOTH;
95
                gridBagConstraints.anchor = GridBagConstraints.WEST;
96
                gridBagConstraints.weightx = 1.0;
97
                gridBagConstraints.insets = new Insets(2, 2, 2, 5);
98
                add(getTextFieldGeneralValue(), gridBagConstraints);
99
        }
100

    
101
        private JFormattedTextField getTextFieldGeneralValue() {
102
                if (textFieldGeneralValue == null) {
103
                        NumberFormat integerFormat = NumberFormat.getNumberInstance();
104
                        integerFormat.setParseIntegerOnly(false);
105
                        integerFormat.setMinimumFractionDigits(0);
106
                        integerFormat.setMaximumFractionDigits(3);
107
                        textFieldGeneralValue = new JFormattedTextField(new DefaultFormatterFactory(
108
                                        new NumberFormatter(integerFormat),
109
                                        new NumberFormatter(integerFormat),
110
                                        new NumberFormatter(integerFormat)));
111
                }
112
                return textFieldGeneralValue;
113
        }
114

    
115
        private JCheckBox getCheckBoxNoDataEnabled() {
116
                if (jCheckBoxNoDataEnabled == null) {
117
                        jCheckBoxNoDataEnabled = new JCheckBox();
118
                        jCheckBoxNoDataEnabled.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
119
                        jCheckBoxNoDataEnabled.setMargin(new Insets(0, 0, 0, 0));
120
                }
121
                return jCheckBoxNoDataEnabled;
122
        }
123

    
124
        private JLabel getLabelGeneralValue() {
125
                if (jLabelGeneralValue == null) {
126
                        jLabelGeneralValue = new JLabel();
127
                }
128
                return jLabelGeneralValue;
129
        }
130

    
131
        /**
132
         * Establece los valores por defecto
133
         */
134
        public void initializeDefaults() {
135
                Boolean enabled = (Boolean) Configuration.getDefaultValue("nodata_transparency_enabled");
136
                getCheckBoxNoDataEnabled().setSelected(enabled.booleanValue());
137
                getTextFieldGeneralValue().setValue((Double) Configuration.getDefaultValue("nodata_value"));
138
        }
139

    
140
        /**
141
         * Carga los valores definidos por el usuario
142
         */
143
        public void initializeValues() {
144
                Boolean enabled = Configuration.getValue("nodata_transparency_enabled", Boolean.FALSE);
145
                getCheckBoxNoDataEnabled().setSelected(enabled.booleanValue());
146
                getTextFieldGeneralValue().setValue(Configuration.getValue("nodata_value", Double.valueOf(RasterLibrary.defaultNoDataValue)));
147
        }
148

    
149
        /**
150
         * Guarda los valores definidos por el usuario
151
         */
152
        public void storeValues() {
153
                Configuration.setValue("nodata_transparency_enabled", Boolean.valueOf(getCheckBoxNoDataEnabled().isSelected()));
154
                try {
155
                        Configuration.setValue("nodata_value", (Double) getTextFieldGeneralValue().getValue());
156
                } catch (NumberFormatException e) {
157
                }
158
        }
159
}