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 / TasseledCapPanelImpl.java @ 2381
History | View | Annotate | Download (6.93 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.JComponent; |
33 |
import javax.swing.JLabel; |
34 |
import javax.swing.JPanel; |
35 |
|
36 |
import org.gvsig.fmap.dal.coverage.store.RasterDataStore; |
37 |
import org.gvsig.i18n.Messages; |
38 |
import org.gvsig.raster.algorithm.BasicAPISwingPanel; |
39 |
import org.gvsig.raster.algorithm.RasterBaseAlgorithmLibrary; |
40 |
import org.gvsig.raster.algorithm.process.DataProcess; |
41 |
import org.gvsig.raster.algorithm.process.ProcessException; |
42 |
import org.gvsig.raster.tasseledcap.algorithm.TasseledCapAlgorithmLibrary; |
43 |
import org.gvsig.raster.swing.RasterSwingLocator; |
44 |
import org.gvsig.raster.swing.RasterSwingManager; |
45 |
import org.gvsig.raster.swing.newlayer.CreateNewLayerPanel; |
46 |
import org.gvsig.raster.swing.pagedtable.ModelLoader; |
47 |
import org.gvsig.raster.swing.pagedtable.PagedTable; |
48 |
|
49 |
/**
|
50 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
51 |
*/
|
52 |
public class TasseledCapPanelImpl extends JPanel implements BasicAPISwingPanel { |
53 |
private static final long serialVersionUID = 1L; |
54 |
private String layerName = null; |
55 |
private CreateNewLayerPanel newLayerPanel = null; |
56 |
private Object inputStore = null; |
57 |
private PagedTable table = null; |
58 |
private int bandList = 0; |
59 |
|
60 |
public TasseledCapPanelImpl(Object inputStore, String layerName, int bandList) { |
61 |
this.inputStore = inputStore;
|
62 |
this.layerName = layerName;
|
63 |
this.bandList = bandList;
|
64 |
init(); |
65 |
} |
66 |
|
67 |
private void init() { |
68 |
setLayout(new GridBagLayout()); |
69 |
|
70 |
GridBagConstraints gridBagConstraints1 = new GridBagConstraints(); |
71 |
gridBagConstraints1.fill = java.awt.GridBagConstraints.HORIZONTAL; |
72 |
gridBagConstraints1.weightx = 1;
|
73 |
gridBagConstraints1.insets = new java.awt.Insets(0, 0, 0, 0); |
74 |
gridBagConstraints1.gridx = 0;
|
75 |
gridBagConstraints1.gridy = 0;
|
76 |
add(getLayerPanel(), gridBagConstraints1); |
77 |
|
78 |
gridBagConstraints1.gridy = 2;
|
79 |
add((JComponent)getCreateNewLayerPanel(), gridBagConstraints1);
|
80 |
|
81 |
gridBagConstraints1.fill = java.awt.GridBagConstraints.BOTH; |
82 |
gridBagConstraints1.gridy = 1;
|
83 |
gridBagConstraints1.weighty = 1;
|
84 |
add(getInputsPanel(), gridBagConstraints1); |
85 |
} |
86 |
|
87 |
private JPanel getLayerPanel() { |
88 |
JPanel p = new JPanel(); |
89 |
p.setBorder(BorderFactory.createTitledBorder(Messages.getText("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(Messages.getText("bands"))); |
106 |
p.setLayout(new BorderLayout()); |
107 |
GridBagConstraints gridBagConstraints1 = new GridBagConstraints(); |
108 |
gridBagConstraints1.fill = java.awt.GridBagConstraints.BOTH; |
109 |
gridBagConstraints1.weightx = 1;
|
110 |
gridBagConstraints1.weighty = 1;
|
111 |
gridBagConstraints1.insets = new java.awt.Insets(2, 2, 2, 2); |
112 |
|
113 |
gridBagConstraints1.gridx = 0;
|
114 |
gridBagConstraints1.gridy = 0;
|
115 |
p.add(getPagedTable().getComponent(), BorderLayout.CENTER);
|
116 |
|
117 |
return p;
|
118 |
} |
119 |
|
120 |
public JComponent getComponent() { |
121 |
return this; |
122 |
} |
123 |
|
124 |
public PagedTable getPagedTable() {
|
125 |
if(table == null) { |
126 |
RasterSwingManager manager = RasterSwingLocator.getSwingManager(); |
127 |
String[] columnNames = { |
128 |
"",
|
129 |
Messages.getText("bands")};
|
130 |
int[] columnSizes = {30, -1}; |
131 |
|
132 |
BandTableModel model = new BandTableModel(columnNames);
|
133 |
ModelLoader loader = manager.createModelLoader(model); |
134 |
CheckBoxColumnRenderer render = new CheckBoxColumnRenderer(null); |
135 |
CheckBoxColumnEditor editor = new CheckBoxColumnEditor();
|
136 |
loader.setRenderForColumn(0, render);
|
137 |
loader.setCellEditorForColumn(0, editor);
|
138 |
loader.setColumnNames(columnNames); |
139 |
loader.setColumnWidths(columnSizes); |
140 |
|
141 |
table = manager.createPagedTable(loader); |
142 |
table.showControllerTable(false);
|
143 |
table.showMoveRowsControls(false);
|
144 |
} |
145 |
return table;
|
146 |
} |
147 |
|
148 |
public DataProcess getResult() throws ProcessException { |
149 |
DataProcess task = RasterBaseAlgorithmLibrary.getManager().createRasterTask(TasseledCapAlgorithmLibrary.TASSELEDCAP_PROCESS_LABEL); |
150 |
List<String> params = task.getRasterTaskInputParameters(TasseledCapAlgorithmLibrary.TASSELEDCAP_PROCESS_LABEL); |
151 |
for (int i = 0; i < params.size(); i++) { |
152 |
String paramName = params.get(i);
|
153 |
Class<?> paramType = task.getParameterTypeByProcess(TasseledCapAlgorithmLibrary.TASSELEDCAP_PROCESS_LABEL, paramName);
|
154 |
if(paramType == RasterDataStore[].class) { |
155 |
task.addParam(paramName, new RasterDataStore[]{(RasterDataStore)inputStore}); |
156 |
} |
157 |
if(paramType == String.class) { |
158 |
String filename = newLayerPanel.getDirectorySelected() + File.separator + newLayerPanel.getFileSelected(); |
159 |
if(!filename.endsWith(".tif")) |
160 |
filename += ".tif";
|
161 |
task.addParam(paramName, filename); |
162 |
} |
163 |
if(paramType == Boolean[].class) { |
164 |
boolean[] bands = new boolean[getPagedTable().getRowCount()]; |
165 |
for (int j = 0; j < getPagedTable().getRowCount(); j++) { |
166 |
Object obj = getPagedTable().getValueAt(j, 0); |
167 |
if(obj instanceof Boolean) |
168 |
bands[j] = ((Boolean)obj).booleanValue();
|
169 |
} |
170 |
task.addParam(paramName, bands); |
171 |
} |
172 |
|
173 |
} |
174 |
return task;
|
175 |
} |
176 |
|
177 |
public CreateNewLayerPanel getCreateNewLayerPanel() {
|
178 |
if(newLayerPanel == null) { |
179 |
newLayerPanel = RasterSwingLocator.getSwingManager().createNewLayerPanel(); |
180 |
} |
181 |
return newLayerPanel;
|
182 |
} |
183 |
|
184 |
public void initialize() { |
185 |
for (int i = 0; i < bandList; i++) { |
186 |
getPagedTable().addRow(new Object[]{true, "B" + i}); |
187 |
} |
188 |
} |
189 |
|
190 |
public int getComponentIDByObject(Object obj) { |
191 |
return -1; |
192 |
} |
193 |
|
194 |
public void addListener(EventListener listener) { |
195 |
// TODO Auto-generated method stub
|
196 |
|
197 |
} |
198 |
|
199 |
} |