Statistics
| Revision:

gvsig-raster / org.gvsig.raster.tools / trunk / org.gvsig.raster.tools / org.gvsig.raster.tools.algorithm / org.gvsig.raster.tools.algorithm.swing / org.gvsig.raster.tools.algorithm.swing.impl / src / main / java / org / gvsig / raster / tools / algorithm / swing / impl / layerdatatype / LayerDatatypePanelImpl.java @ 1350

History | View | Annotate | Download (7.57 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.algorithm.swing.impl.layerdatatype;
23

    
24
import java.awt.GridBagConstraints;
25
import java.awt.GridBagLayout;
26
import java.io.File;
27

    
28
import javax.swing.BorderFactory;
29
import javax.swing.JComboBox;
30
import javax.swing.JComponent;
31
import javax.swing.JLabel;
32
import javax.swing.JPanel;
33

    
34
import org.gvsig.i18n.Messages;
35
import org.gvsig.raster.cache.buffer.Buffer;
36
import org.gvsig.raster.swing.RasterSwingLocator;
37
import org.gvsig.raster.swing.newlayer.CreateNewLayerPanel;
38
import org.gvsig.raster.tools.algorithm.base.process.RasterProcess;
39
import org.gvsig.raster.tools.algorithm.layerdatatype.LayerDatatypeProcess;
40
import org.gvsig.raster.tools.algorithm.swing.BaseAlgorithmPanel;
41
import org.gvsig.raster.tools.algorithm.swing.impl.FileNameManagementImpl;
42

    
43
/**
44
 * @author Nacho Brodin (nachobrodin@gmail.com)
45
 */
46
public class LayerDatatypePanelImpl extends JPanel implements BaseAlgorithmPanel {
47
        private static final long               serialVersionUID     = 1L;
48
        private JComboBox                       comboOutput          = null;
49
        private JComboBox                       comboDec2Int         = null;
50
        private JComboBox                       comboBig2Small       = null;
51
        private String                          inputDatatype        = null;
52
        private String                          layerName            = null;
53
        private CreateNewLayerPanel             newLayerPanel        = null;
54
        private Object                          inputStore           = null;
55
        
56
        public LayerDatatypePanelImpl(Object inputStore, String inputDatatype, String layerName) {
57
                this.inputStore = inputStore;
58
                this.layerName = layerName;
59
                this.inputDatatype = inputDatatype;
60
                init();
61
        }
62
        
63
        private void init() {
64
                setLayout(new GridBagLayout());
65
                
66
                GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
67
                gridBagConstraints1.fill = java.awt.GridBagConstraints.HORIZONTAL;
68
                gridBagConstraints1.weightx = 1;
69
                gridBagConstraints1.insets = new java.awt.Insets(0, 0, 2, 0);
70
                gridBagConstraints1.gridx = 0;
71
                gridBagConstraints1.gridy = 0;
72
                add(getLayerPanel(), gridBagConstraints1);
73
                
74
                gridBagConstraints1.gridy = 1;
75
                add(getInputsPanel(), gridBagConstraints1);
76
                
77
                gridBagConstraints1.insets = new java.awt.Insets(0, 2, 0, 2);
78
                gridBagConstraints1.gridy = 2;
79
                add((JComponent)getCreateNewLayerPanel(), gridBagConstraints1);
80
                
81
                gridBagConstraints1.fill = java.awt.GridBagConstraints.BOTH;
82
                gridBagConstraints1.weighty = 1;
83
                gridBagConstraints1.gridy = 3;
84
                add(new JPanel(), gridBagConstraints1);
85
        }
86
        
87
        private JPanel getLayerPanel() {
88
                JPanel p = new JPanel();
89
                p.setBorder(BorderFactory.createTitledBorder("Layer"));
90
                p.setLayout(new GridBagLayout());
91
                GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
92
                gridBagConstraints1.fill = java.awt.GridBagConstraints.HORIZONTAL;
93
                gridBagConstraints1.weightx = 1;
94
                gridBagConstraints1.insets = new java.awt.Insets(0, 0, 2, 0);
95
                
96
                gridBagConstraints1.gridx = 0;
97
                gridBagConstraints1.gridy = 0;
98
                p.add(new JLabel(layerName), gridBagConstraints1);
99
                
100
                return p;
101
        }
102
        
103
        private JPanel getInputsPanel() {
104
                JPanel p = new JPanel();
105
                p.setBorder(BorderFactory.createTitledBorder("Datatype"));
106
                p.setLayout(new GridBagLayout());
107
                GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
108
                gridBagConstraints1.fill = java.awt.GridBagConstraints.HORIZONTAL;
109
                gridBagConstraints1.weightx = 1;
110
                gridBagConstraints1.insets = new java.awt.Insets(0, 0, 2, 0);
111
                
112
                gridBagConstraints1.gridx = 0;
113
                gridBagConstraints1.gridy = 0;
114
                p.add(new JLabel(Messages.getText("entrada")), gridBagConstraints1);
115
                
116
                gridBagConstraints1.gridx = 1;
117
                gridBagConstraints1.gridy = 0;
118
                p.add(new JLabel(inputDatatype), gridBagConstraints1);
119
                
120
                gridBagConstraints1.gridx = 0;
121
                gridBagConstraints1.gridy = 1;
122
                p.add(new JLabel(Messages.getText("salida")), gridBagConstraints1);
123
                
124
                gridBagConstraints1.gridx = 1;
125
                gridBagConstraints1.gridy = 1;
126
                p.add(getComboOutput(), gridBagConstraints1);
127
                
128
                gridBagConstraints1.gridx = 0;
129
                gridBagConstraints1.gridy = 2;
130
                p.add(new JLabel(Messages.getText("adjust_dec2int")), gridBagConstraints1);
131
                
132
                gridBagConstraints1.gridx = 1;
133
                gridBagConstraints1.gridy = 2;
134
                p.add(getComboDec2Int(), gridBagConstraints1);
135
                
136
                gridBagConstraints1.gridx = 0;
137
                gridBagConstraints1.gridy = 3;
138
                p.add(new JLabel(Messages.getText("adjust_big2small")), gridBagConstraints1);
139
                
140
                gridBagConstraints1.gridx = 1;
141
                gridBagConstraints1.gridy = 3;
142
                p.add(getComboBig2Small(), gridBagConstraints1);
143
                
144
                return p;
145
        }
146
        
147
        public JComponent getComponent() {
148
                return this;
149
        }
150

    
151
        public RasterProcess getProcess() throws NumberFormatException {
152
                RasterProcess task = new LayerDatatypeProcess();
153
                task.addParam(LayerDatatypeProcess.RASTER_STORE1, inputStore);
154
                String filename = newLayerPanel.getDirectorySelected() + File.separator + newLayerPanel.getFileSelected();
155
                if(!filename.endsWith(".tif"))
156
                        filename += ".tif";
157
        task.addParam(LayerDatatypeProcess.PATH, filename);
158
        task.addParam(LayerDatatypeProcess.DATATYPE, getDatatypeFromCombo());
159
        task.addParam(LayerDatatypeProcess.ADJUST_DEC2INT, getComboDec2Int().getSelectedIndex());
160
        task.addParam(LayerDatatypeProcess.ADJUST_BIG2SMALL, getComboBig2Small().getSelectedIndex());
161
                return task;
162
        }
163

    
164
        public JComboBox getComboOutput() {
165
                if(comboOutput == null) {
166
                        comboOutput = new JComboBox();
167
                        comboOutput.addItem("BYTE");
168
                        comboOutput.addItem("SHORT");
169
                        comboOutput.addItem("INT");
170
                        comboOutput.addItem("FLOAT");
171
                        comboOutput.addItem("DOUBLE");
172
                }
173
                return comboOutput;
174
        }
175
        
176
        private int getDatatypeFromCombo() {
177
                String item = (String)getComboOutput().getSelectedItem();
178
                if(item.equals("BYTE"))
179
                        return Buffer.TYPE_BYTE;
180
                if(item.equals("SHORT"))
181
                        return Buffer.TYPE_SHORT;
182
                if(item.equals("INT"))
183
                        return Buffer.TYPE_INT;
184
                if(item.equals("FLOAT"))
185
                        return Buffer.TYPE_FLOAT;
186
                if(item.equals("DOUBLE"))
187
                        return Buffer.TYPE_DOUBLE;
188
                return -1;
189
        }
190

    
191
        public JComboBox getComboDec2Int() {
192
                if(comboDec2Int == null) {
193
                        comboDec2Int = new JComboBox();
194
                        for (int i = 0; i < LayerDatatypeProcess.DEC2INT_OPTIONS.length; i++) {
195
                                comboDec2Int.addItem(LayerDatatypeProcess.DEC2INT_OPTIONS[i]);
196
                        }
197
                }
198
                return comboDec2Int;
199
        }
200

    
201
        public JComboBox getComboBig2Small() {
202
                if(comboBig2Small == null) {
203
                        comboBig2Small = new JComboBox();
204
                        for (int i = 0; i < LayerDatatypeProcess.BIG2SMALL_OPTIONS.length; i++) {
205
                                comboBig2Small.addItem(LayerDatatypeProcess.BIG2SMALL_OPTIONS[i]);
206
                        }
207
                }
208
                return comboBig2Small;
209
        }
210
        
211
        public CreateNewLayerPanel getCreateNewLayerPanel() {
212
                if(newLayerPanel == null) {
213
                        newLayerPanel = RasterSwingLocator.getSwingManager().createNewLayerPanel(new FileNameManagementImpl());
214
                        //newLayerPanel = new CreateNewLayerPanelImpl(new FileNameManagementImpl());
215
                }
216
                return newLayerPanel;
217
        }
218

    
219
}