Statistics
| Revision:

gvsig-raster / org.gvsig.raster.tasseledcap / trunk / org.gvsig.raster.tasseledcap / org.gvsig.raster.tasseledcap.swing / org.gvsig.raster.tasseledcap.swing.impl / src / main / java / org / gvsig / raster / tasseledcap / swing / impl / main / TasseledCapMainPanelImpl.java @ 2381

History | View | Annotate | Download (9.53 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.tasseledcap.swing.impl.main;
23

    
24
import java.awt.BorderLayout;
25
import java.awt.GridBagConstraints;
26
import java.awt.GridBagLayout;
27
import java.io.File;
28
import java.util.EventListener;
29
import java.util.List;
30

    
31
import javax.swing.BorderFactory;
32
import javax.swing.ButtonGroup;
33
import javax.swing.JCheckBox;
34
import javax.swing.JComponent;
35
import javax.swing.JLabel;
36
import javax.swing.JPanel;
37
import javax.swing.JRadioButton;
38

    
39
import org.gvsig.fmap.dal.coverage.store.RasterDataStore;
40
import org.gvsig.i18n.Messages;
41
import org.gvsig.raster.algorithm.BasicAPISwingPanel;
42
import org.gvsig.raster.algorithm.RasterBaseAlgorithmLibrary;
43
import org.gvsig.raster.algorithm.process.DataProcess;
44
import org.gvsig.raster.algorithm.process.ProcessException;
45
import org.gvsig.raster.swing.RasterSwingLocator;
46
import org.gvsig.raster.swing.RasterSwingManager;
47
import org.gvsig.raster.swing.newlayer.CreateNewLayerPanel;
48
import org.gvsig.raster.swing.pagedtable.ModelLoader;
49
import org.gvsig.raster.swing.pagedtable.PagedTable;
50
import org.gvsig.raster.tasseledcap.algorithm.TasseledCapAlgorithmLibrary;
51

    
52
/**
53
 * @author Nacho Brodin (nachobrodin@gmail.com)
54
 */
55
public class TasseledCapMainPanelImpl extends JPanel implements BasicAPISwingPanel {
56
        private static final long               serialVersionUID     = 1L;
57
        private String                          layerName            = null;
58
        private CreateNewLayerPanel             newLayerPanel        = null;
59
        private Object                          inputStore           = null;
60
        private PagedTable                      table                = null;
61
        private JCheckBox                       roisCheck            = null;
62
        private int                             bandList             = 0;
63
        private String                          roisEPSG             = null;
64
        private JRadioButton                    landsatMS            = null;
65
        private JRadioButton                    landsatTM            = null;
66
        private JRadioButton                    landsatETM           = null;
67
        
68
        public TasseledCapMainPanelImpl(Object inputStore, String layerName, int bandList, String roisEPSG) {
69
                this.inputStore = inputStore;
70
                this.layerName = layerName;
71
                this.bandList = bandList;
72
                this.roisEPSG = roisEPSG;
73
                init();
74
        }
75
        
76
        private void init() {
77
                setLayout(new GridBagLayout());
78
                
79
                GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
80
                gridBagConstraints1.fill = java.awt.GridBagConstraints.HORIZONTAL;
81
                gridBagConstraints1.weightx = 1;
82
                gridBagConstraints1.insets = new java.awt.Insets(0, 0, 0, 0);
83
                gridBagConstraints1.gridx = 0;
84
                gridBagConstraints1.gridy = 0;
85
                add(getLayerPanel(), gridBagConstraints1);
86
                
87
                gridBagConstraints1.gridy = 2;
88
                add((JComponent)getOptionsPanel(), gridBagConstraints1);
89
                
90
                gridBagConstraints1.gridy = 3;
91
                add((JComponent)getCreateNewLayerPanel(), gridBagConstraints1);
92
                
93
                if(roisEPSG != null) {
94
                        gridBagConstraints1.gridy = 4;
95
                        add(getROIsCheck(), gridBagConstraints1);
96
                }
97
                
98
                gridBagConstraints1.fill = java.awt.GridBagConstraints.BOTH;
99
                gridBagConstraints1.gridy = 1;
100
                gridBagConstraints1.weighty = 1;
101
                add(getInputsPanel(), gridBagConstraints1);
102
        }
103
        
104
        private JPanel getLayerPanel() {
105
                JPanel p = new JPanel();
106
                p.setBorder(BorderFactory.createTitledBorder(Messages.getText("layer")));
107
                p.setLayout(new GridBagLayout());
108
                GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
109
                gridBagConstraints1.fill = java.awt.GridBagConstraints.HORIZONTAL;
110
                gridBagConstraints1.weightx = 1;
111
                gridBagConstraints1.insets = new java.awt.Insets(0, 0, 2, 0);
112
                
113
                gridBagConstraints1.gridx = 0;
114
                gridBagConstraints1.gridy = 0;
115
                p.add(new JLabel(layerName), gridBagConstraints1);
116
                
117
                return p;
118
        }
119
        
120
        private JPanel getInputsPanel() {
121
                JPanel p = new JPanel();
122
                p.setBorder(BorderFactory.createTitledBorder(Messages.getText("bands")));
123
                p.setLayout(new BorderLayout());
124
                GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
125
                gridBagConstraints1.fill = java.awt.GridBagConstraints.BOTH;
126
                gridBagConstraints1.weightx = 1;
127
                gridBagConstraints1.weighty = 1;
128
                gridBagConstraints1.insets = new java.awt.Insets(2, 2, 2, 2);
129
                
130
                gridBagConstraints1.gridx = 0;
131
                gridBagConstraints1.gridy = 0;
132
                p.add(getPagedTable().getComponent(), BorderLayout.CENTER);
133
                
134
                return p;
135
        }
136
        
137
        public JComponent getComponent() {
138
                return this;
139
        }
140
        
141
        public PagedTable getPagedTable() {
142
                if(table == null) {
143
                        RasterSwingManager manager = RasterSwingLocator.getSwingManager();
144
                        String[] columnNames = {
145
                                        "", 
146
                                        Messages.getText("bands")};
147
                        int[] columnSizes = {30, -1};
148

    
149
                        BandTableModel model = new BandTableModel(columnNames);
150
                        ModelLoader loader = manager.createModelLoader(model);
151
                        CheckBoxColumnRenderer render = new CheckBoxColumnRenderer(null);
152
                        CheckBoxColumnEditor editor = new CheckBoxColumnEditor();
153
                        loader.setRenderForColumn(0, render);
154
                        loader.setCellEditorForColumn(0, editor);
155
                        loader.setColumnNames(columnNames);
156
                        loader.setColumnWidths(columnSizes);
157
                        
158
                        table = manager.createPagedTable(loader);
159
                        table.showControllerTable(false);
160
                        table.showMoveRowsControls(false);
161
                }
162
                return table;
163
        }
164
        
165
        private JPanel getOptionsPanel() {
166
                JPanel p = new JPanel();
167
                
168
                ButtonGroup g = new ButtonGroup();
169
                g.add(getLandsatETMRadioButton());
170
                g.add(getLandsatTMRadioButton());
171
                g.add(getLandsatMSRadioButton());
172
                
173
                p.setBorder(BorderFactory.createTitledBorder(Messages.getText("options")));
174
                p.setLayout(new GridBagLayout());
175
                GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
176
                gridBagConstraints1.fill = java.awt.GridBagConstraints.HORIZONTAL;
177
                gridBagConstraints1.weightx = 1;
178
                gridBagConstraints1.insets = new java.awt.Insets(0, 0, 2, 0);
179
                
180
                gridBagConstraints1.gridx = 0;
181
                gridBagConstraints1.gridy = 0;
182
                p.add(getLandsatMSRadioButton(), gridBagConstraints1);
183
                
184
                gridBagConstraints1.gridy = 1;
185
                p.add(getLandsatTMRadioButton(), gridBagConstraints1);
186
                
187
                gridBagConstraints1.gridy = 2;
188
                p.add(getLandsatETMRadioButton(), gridBagConstraints1);
189
                
190
                return p;
191
        }
192
        
193
        private JRadioButton getLandsatMSRadioButton() {
194
                if(landsatMS == null) {
195
                        landsatMS = new JRadioButton("Landsat MS");
196
                        landsatMS.setSelected(true);
197
                }
198
                return landsatMS;
199
        }
200
        
201
        private JRadioButton getLandsatTMRadioButton() {
202
                if(landsatTM == null) {
203
                        landsatTM = new JRadioButton("Landsat TM");
204
                }
205
                return landsatTM;
206
        }
207
        
208
        private JRadioButton getLandsatETMRadioButton() {
209
                if(landsatETM == null) {
210
                        landsatETM = new JRadioButton("Landsat ETM");
211
                }
212
                return landsatETM;
213
        }
214

    
215
        public DataProcess getResult() throws ProcessException {
216
                DataProcess task = RasterBaseAlgorithmLibrary.getManager().createRasterTask(TasseledCapAlgorithmLibrary.TASSELEDCAP_PROCESS_LABEL);
217
                List<String> params = task.getRasterTaskInputParameters(TasseledCapAlgorithmLibrary.TASSELEDCAP_PROCESS_LABEL);
218
                for (int i = 0; i < params.size(); i++) {
219
                        String paramName = params.get(i);
220
                        Class<?> paramType = task.getParameterTypeByProcess(TasseledCapAlgorithmLibrary.TASSELEDCAP_PROCESS_LABEL, paramName);
221
                        if(paramType == RasterDataStore.class) {
222
                                task.addParam(paramName, (RasterDataStore)inputStore);
223
                        }
224
                        if(paramName.equals("PATH")) {
225
                                String filename = newLayerPanel.getDirectorySelected() + File.separator + newLayerPanel.getFileSelected();
226
                                if(!filename.endsWith(".tif"))
227
                                        filename += ".tif";
228
                                task.addParam(paramName, filename);
229
                        }
230
                        if(paramType == Boolean[].class) {
231
                                boolean[] bands = new boolean[getPagedTable().getRowCount()];
232
                                for (int j = 0; j < getPagedTable().getRowCount(); j++) {
233
                                        Object obj = getPagedTable().getValueAt(j, 0);
234
                                        if(obj instanceof Boolean)
235
                                                bands[j] = ((Boolean)obj).booleanValue();
236
                                }
237
                                task.addParam(paramName, bands);
238
                        }
239
                        
240
                        if(getROIsCheck().isSelected()) {
241
                                if(paramName.equals("ROI_EPSG")) {
242
                                        task.addParam(paramName, roisEPSG);
243
                                }
244
                        }
245
                        
246
                        if(paramType == Integer.class) {
247
                                int type = getSelectedLandsatType();
248
                                task.addParam(paramName, type);
249
                        }
250
                }
251
                return task;
252
        }
253
        
254
        private int getSelectedLandsatType() {
255
                if(getLandsatMSRadioButton().isSelected())
256
                        return 0;
257
                if(getLandsatTMRadioButton().isSelected())
258
                        return 1;
259
                if(getLandsatETMRadioButton().isSelected())
260
                        return 2;
261
                return -1;
262
        }
263
        
264
        public JCheckBox getROIsCheck() {
265
                if(roisCheck == null) {
266
                        roisCheck = new JCheckBox(Messages.getText("use_rois"));
267
                }
268
                return roisCheck;
269
        }
270

    
271
        public CreateNewLayerPanel getCreateNewLayerPanel() {
272
                if(newLayerPanel == null) {
273
                        newLayerPanel = RasterSwingLocator.getSwingManager().createNewLayerPanel();
274
                }
275
                return newLayerPanel;
276
        }
277

    
278
        public void initialize() {
279
                for (int i = 0; i < bandList; i++) {
280
                        getPagedTable().addRow(new Object[]{true, "B" + i});                        
281
                }                        
282
        }
283
        
284
        public int getComponentIDByObject(Object obj) {
285
                return -1;
286
        }
287

    
288
        public void addListener(EventListener listener) {
289
        }
290
}