Statistics
| Revision:

gvsig-raster / org.gvsig.raster.principalcomponents / trunk / org.gvsig.raster.principalcomponents / org.gvsig.raster.principalcomponents.swing / org.gvsig.raster.principalcomponents.swing.impl / src / main / java / org / gvsig / raster / principalcomponents / swing / impl / main / PCAMainPanelImpl.java @ 2125

History | View | Annotate | Download (7.52 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.principalcomponents.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.JCheckBox;
33
import javax.swing.JComponent;
34
import javax.swing.JLabel;
35
import javax.swing.JPanel;
36

    
37
import org.gvsig.fmap.dal.coverage.store.RasterDataStore;
38
import org.gvsig.i18n.Messages;
39
import org.gvsig.raster.algorithm.BasicAPISwingPanel;
40
import org.gvsig.raster.algorithm.RasterBaseAlgorithmLibrary;
41
import org.gvsig.raster.algorithm.process.DataProcess;
42
import org.gvsig.raster.algorithm.process.ProcessException;
43
import org.gvsig.raster.principalcomponents.algorithm.PrincipalComponentsAlgorithmLibrary;
44
import org.gvsig.raster.roi.ROI;
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

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

    
142
                        BandTableModel model = new BandTableModel(columnNames);
143
                        ModelLoader loader = manager.createModelLoader(model);
144
                        CheckBoxColumnRenderer render = new CheckBoxColumnRenderer(null);
145
                        CheckBoxColumnEditor editor = new CheckBoxColumnEditor();
146
                        loader.setRenderForColumn(0, render);
147
                        loader.setCellEditorForColumn(0, editor);
148
                        loader.setColumnNames(columnNames);
149
                        loader.setColumnWidths(columnSizes);
150
                        
151
                        table = manager.createPagedTable(loader);
152
                        table.showControllerTable(false);
153
                        table.showMoveRowsControls(false);
154
                }
155
                return table;
156
        }
157

    
158
        public DataProcess getResult() throws ProcessException {
159
                DataProcess task = RasterBaseAlgorithmLibrary.getManager().createRasterTask(PrincipalComponentsAlgorithmLibrary.PC_STATS_PROCESS_LABEL);
160
                List<String> params = task.getRasterTaskInputParameters(PrincipalComponentsAlgorithmLibrary.PC_STATS_PROCESS_LABEL);
161
                for (int i = 0; i < params.size(); i++) {
162
                        String paramName = params.get(i);
163
                        Class<?> paramType = task.getParameterTypeByProcess(PrincipalComponentsAlgorithmLibrary.PC_STATS_PROCESS_LABEL, paramName);
164
                        if(paramType == RasterDataStore.class) {
165
                                task.addParam(paramName, (RasterDataStore)inputStore);
166
                        }
167
                        if(paramType == String.class) {
168
                                String filename = newLayerPanel.getDirectorySelected() + File.separator + newLayerPanel.getFileSelected();
169
                                if(!filename.endsWith(".tif"))
170
                                        filename += ".tif";
171
                                task.addParam(paramName, filename);
172
                        }
173
                        if(paramType == Boolean[].class) {
174
                                boolean[] bands = new boolean[getPagedTable().getRowCount()];
175
                                for (int j = 0; j < getPagedTable().getRowCount(); j++) {
176
                                        Object obj = getPagedTable().getValueAt(j, 0);
177
                                        if(obj instanceof Boolean)
178
                                                bands[j] = ((Boolean)obj).booleanValue();
179
                                }
180
                                task.addParam(paramName, bands);
181
                        }
182
                        
183
                        if(getROIsCheck().isSelected()) {
184
                                if(paramType == List.class) {
185
                                        task.addParam(paramName, rois);
186
                                }
187
                        }
188
                }
189
                return task;
190
        }
191
        
192
        public JCheckBox getROIsCheck() {
193
                if(roisCheck == null) {
194
                        roisCheck = new JCheckBox(Messages.getText("use_rois"));
195
                }
196
                return roisCheck;
197
        }
198

    
199
        public CreateNewLayerPanel getCreateNewLayerPanel() {
200
                if(newLayerPanel == null) {
201
                        newLayerPanel = RasterSwingLocator.getSwingManager().createNewLayerPanel();
202
                }
203
                return newLayerPanel;
204
        }
205

    
206
        public void initialize() {
207
                for (int i = 0; i < bandList; i++) {
208
                        getPagedTable().addRow(new Object[]{true, "B" + i});                        
209
                }                        
210
        }
211

    
212
        public int getComponentIDByObject(Object obj) {
213
                return -1;
214
        }
215

    
216
        public void addListener(EventListener listener) {
217
        }
218
}