Statistics
| Revision:

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

History | View | Annotate | Download (6.36 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.ItemEvent;
25
import java.awt.event.ItemListener;
26

    
27
import javax.swing.DefaultComboBoxModel;
28
import javax.swing.JCheckBox;
29
import javax.swing.JComboBox;
30
import javax.swing.JFormattedTextField;
31
import javax.swing.JLabel;
32

    
33
import org.gvsig.raster.util.PanelBase;
34
import org.gvsig.rastertools.properties.panels.interfaces.INoDataPanel;
35

    
36
public class NoDataPanel extends PanelBase implements ItemListener {
37
        private static final long serialVersionUID = 7645641060812458944L;
38

    
39
        private JCheckBox           jCheckBoxTransparent = null;
40
        private JLabel              jLabelValue          = null;
41
        private JLabel              jLabelBand           = null;
42
        private JComboBox           jComboBoxSetup       = null;
43
        private JComboBox           jComboBoxBand        = null;
44
        private JFormattedTextField jTextFieldValue      = null;
45
        private INoDataPanel        noDataPanel          = null;
46

    
47
        public NoDataPanel(INoDataPanel noDataPanel) {
48
                initialize();
49
                this.noDataPanel = noDataPanel;
50
        }
51

    
52
        private JComboBox getComboBoxSetup() {
53
                if (jComboBoxSetup == null) {
54
                        jComboBoxSetup = new JComboBox();
55
                        jComboBoxSetup.setModel(new DefaultComboBoxModel(new String[] { "Global", "Capa", "Personalizado" }));
56
                        jComboBoxSetup.addItemListener(this);
57
                }
58
                return jComboBoxSetup;
59
        }
60

    
61
        private JComboBox getComboBoxBand() {
62
                if (jComboBoxBand == null) {
63
                        jComboBoxBand = new JComboBox();
64
                        jComboBoxBand.setModel(new DefaultComboBoxModel(new String[] { "0", "1", "2" }));
65
                        jComboBoxBand.addItemListener(this);
66
                }
67
                return jComboBoxBand;
68
        }
69

    
70
        private JFormattedTextField getTextFieldValue() {
71
                if (jTextFieldValue == null) {
72
                        jTextFieldValue = new JFormattedTextField();
73
                        jTextFieldValue.setText("");
74
                }
75
                return jTextFieldValue;
76
        }
77

    
78
        private JCheckBox getCheckBoxTransparent() {
79
                if (jCheckBoxTransparent == null) {
80
                        jCheckBoxTransparent = new JCheckBox();
81
                        jCheckBoxTransparent.setText("Transparente");
82
                }
83
                return jCheckBoxTransparent;
84
        }
85

    
86
        private JLabel getLabelValue() {
87
                if (jLabelValue == null) {
88
                        jLabelValue = new JLabel();
89
                        jLabelValue.setText(getText(this, "value") + ":");
90
                }
91
                return jLabelValue;
92
        }
93

    
94
        private JLabel getLabelBand() {
95
                if (jLabelBand == null) {
96
                        jLabelBand = new JLabel();
97
                        jLabelBand.setText(getText(this, "band") + ":");
98
                }
99
                return jLabelBand;
100
        }
101

    
102
        private void initialize() {
103
                GridBagConstraints gridBagConstraints;
104

    
105
                getPanel().setLayout(new GridBagLayout());
106

    
107
                int col = 0;
108
                gridBagConstraints = new GridBagConstraints();
109
                gridBagConstraints.gridx = col;
110
                gridBagConstraints.gridy = 0;
111
                gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
112
                gridBagConstraints.weightx = 1.0;
113
                gridBagConstraints.insets = new Insets(5, 5, 5, 2);
114
                getPanel().add(getComboBoxSetup(), gridBagConstraints);
115

    
116
                col++;
117
                gridBagConstraints = new GridBagConstraints();
118
                gridBagConstraints.gridx = col;
119
                gridBagConstraints.gridy = 0;
120
                gridBagConstraints.insets = new Insets(5, 2, 5, 2);
121
                getPanel().add(getLabelBand(), gridBagConstraints);
122

    
123
                col++;
124
                gridBagConstraints = new GridBagConstraints();
125
                gridBagConstraints.gridx = col;
126
                gridBagConstraints.gridy = 0;
127
                gridBagConstraints.insets = new Insets(5, 2, 5, 2);
128
                getPanel().add(getComboBoxBand(), gridBagConstraints);
129

    
130
                col++;
131
                gridBagConstraints = new GridBagConstraints();
132
                gridBagConstraints.gridx = col;
133
                gridBagConstraints.gridy = 0;
134
                gridBagConstraints.insets = new Insets(5, 2, 5, 2);
135
                getPanel().add(getLabelValue(), gridBagConstraints);
136

    
137
                col++;
138
                gridBagConstraints = new GridBagConstraints();
139
                gridBagConstraints.gridx = col;
140
                gridBagConstraints.gridy = 0;
141
                gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
142
                gridBagConstraints.weightx = 1.0;
143
                gridBagConstraints.insets = new Insets(5, 2, 5, 2);
144
                getPanel().add(getTextFieldValue(), gridBagConstraints);
145

    
146
                col++;
147
                gridBagConstraints = new GridBagConstraints();
148
                gridBagConstraints.gridx = col;
149
                gridBagConstraints.gridy = 0;
150
                gridBagConstraints.insets = new Insets(5, 2, 5, 5);
151
                getPanel().add(getCheckBoxTransparent(), gridBagConstraints);
152
        }
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
                        if (e.getSource() == getComboBoxBand()) {
162
                                noDataPanel.BandStateChanged(this, getComboBoxBand().getSelectedIndex());
163
                                return;
164
                        }
165
                }
166
        }
167

    
168
        public void setComboValueSetup(int pos) {
169
                getComboBoxSetup().setSelectedIndex(pos);
170
        }
171

    
172
        public void setEnabledComponents(boolean b) {
173
                getCheckBoxTransparent().setEnabled(b);
174
                getTextFieldValue().setEnabled(b);
175
                getLabelValue().setEnabled(b);
176
        }
177

    
178
        public void setNoDataValue(double value) {
179
                getTextFieldValue().setValue(Double.valueOf(value));
180
        }
181

    
182
        public void setTransparent(boolean value) {
183
                getCheckBoxTransparent().setSelected(value);
184
        }
185

    
186
        public void setNumBands(int nband) {
187
                getComboBoxBand().removeAllItems();
188
                for (int i = 0; i < nband; i++) {
189
                        getComboBoxBand().addItem(Integer.valueOf(i));
190
                }
191
                getLabelBand().setVisible(nband > 1);
192
                getComboBoxBand().setVisible(nband > 1);
193
        }
194

    
195
        public int getComboBandIndex() {
196
                return getComboBoxBand().getSelectedIndex();
197
        }
198

    
199
        public int getComboSetupIndex() {
200
                return getComboBoxSetup().getSelectedIndex();
201
        }
202
}