Statistics
| Revision:

gvsig-raster / org.gvsig.raster.tools / trunk / org.gvsig.raster.tools / org.gvsig.raster.tools.app.basic / src / main / java / org / gvsig / raster / tools / app / basic / raster / gui / preference / panel / PreferenceNoData.java @ 2123

History | View | Annotate | Download (4.74 KB)

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.raster.gui.preference.panel;
23

    
24
import java.awt.GridBagConstraints;
25
import java.awt.GridBagLayout;
26
import java.awt.Insets;
27
import java.text.NumberFormat;
28

    
29
import javax.swing.BorderFactory;
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.raster.mainplugin.config.Configuration;
36
import org.gvsig.raster.util.BasePanel;
37
/**
38
 * Panel para la gesti?n del valor NoData en el panel de preferencias de gvSIG.
39
 *
40
 * @version 10/12/2007
41
 * @author BorSanZa - Borja S?nchez Zamorano 
42
 */
43
public class PreferenceNoData extends BasePanel {
44
        private static final long   serialVersionUID = -8964531984609056094L;
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
                getLabelGeneralValue().setText(getText(this, "valor_general") + ":");
63
        }
64

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

    
72
                GridBagConstraints gridBagConstraints;
73

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

    
81
                gridBagConstraints = new GridBagConstraints();
82
                gridBagConstraints.gridx = 1;
83
                gridBagConstraints.gridy = 0;
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
                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 JLabel getLabelGeneralValue() {
106
                if (jLabelGeneralValue == null) {
107
                        jLabelGeneralValue = new JLabel();
108
                }
109
                return jLabelGeneralValue;
110
        }
111

    
112
        /**
113
         * Establece los valores por defecto
114
         */
115
        public void initializeDefaults() {
116
                getTextFieldGeneralValue().setValue((Double) Configuration.getDefaultValue("nodata_value"));
117
        }
118

    
119
        /**
120
         * Carga los valores definidos por el usuario
121
         */
122
        public void initializeValues() {
123
                //getTextFieldGeneralValue().setValue(Configuration.getValue("nodata_value", Double.valueOf(RasterLibrary.defaultNoDataValue)));
124
        }
125

    
126
        /**
127
         * Guarda los valores definidos por el usuario
128
         */
129
        public void storeValues() {
130
                try {
131
                        if(getTextFieldGeneralValue().getValue() instanceof Double)
132
                                Configuration.setValue("nodata_value", (Double) getTextFieldGeneralValue().getValue());
133
                        if(getTextFieldGeneralValue().getValue() instanceof String)
134
                                Configuration.setValue("nodata_value", new Double((String)getTextFieldGeneralValue().getValue()));
135
                        if(getTextFieldGeneralValue().getValue() instanceof Long)
136
                                Configuration.setValue("nodata_value", new Double(((Long)getTextFieldGeneralValue().getValue()).longValue()));
137
                } catch (NumberFormatException e) {
138
                }
139
        }
140
}