root / branches / v2_0_0_prep / extensions / extSextanteGvsigBindings / src / org / gvsig / sextante / gui / gvPostProcessTask.java @ 31496
History | View | Annotate | Download (8.11 KB)
1 |
package org.gvsig.sextante.gui; |
---|---|
2 |
|
3 |
import java.awt.Component; |
4 |
import java.lang.reflect.InvocationTargetException; |
5 |
import java.util.ArrayList; |
6 |
import java.util.List; |
7 |
|
8 |
import javax.swing.BorderFactory; |
9 |
import javax.swing.JScrollPane; |
10 |
import javax.swing.JTextPane; |
11 |
import javax.swing.SwingUtilities; |
12 |
import javax.swing.border.BevelBorder; |
13 |
|
14 |
import org.gvsig.andami.PluginServices; |
15 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
16 |
import org.gvsig.app.extension.ProjectExtension; |
17 |
import org.gvsig.app.project.Project; |
18 |
import org.gvsig.app.project.ProjectManager; |
19 |
import org.gvsig.app.project.documents.Document; |
20 |
import org.gvsig.app.project.documents.table.TableDocument; |
21 |
import org.gvsig.app.project.documents.view.DefaultViewDocument; |
22 |
import org.gvsig.app.project.documents.view.ViewManager; |
23 |
import org.gvsig.fmap.mapcontext.MapContext; |
24 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
25 |
import org.gvsig.fmap.mapcontext.layers.FLayers; |
26 |
import org.gvsig.fmap.mapcontext.layers.LayersIterator; |
27 |
import org.gvsig.fmap.raster.layers.FLyrRasterSE; |
28 |
|
29 |
import es.unex.sextante.core.GeoAlgorithm; |
30 |
import es.unex.sextante.core.ObjectAndDescription; |
31 |
import es.unex.sextante.core.OutputObjectsSet; |
32 |
import es.unex.sextante.core.ParametersSet; |
33 |
import es.unex.sextante.dataObjects.IDataObject; |
34 |
import es.unex.sextante.dataObjects.ILayer; |
35 |
import es.unex.sextante.dataObjects.IRasterLayer; |
36 |
import es.unex.sextante.dataObjects.ITable; |
37 |
import es.unex.sextante.dataObjects.IVectorLayer; |
38 |
import es.unex.sextante.gui.additionalResults.AdditionalResults; |
39 |
import es.unex.sextante.gui.core.SextanteGUI; |
40 |
import es.unex.sextante.outputs.Output; |
41 |
import es.unex.sextante.parameters.Parameter; |
42 |
import es.unex.sextante.parameters.RasterLayerAndBand; |
43 |
|
44 |
public class gvPostProcessTask implements Runnable{ |
45 |
|
46 |
private MapContext m_MapContext;
|
47 |
GeoAlgorithm m_Algorithm; |
48 |
private OutputObjectsSet m_Output;
|
49 |
//private IProjection m_Projection;
|
50 |
|
51 |
public gvPostProcessTask(GeoAlgorithm algorithm){
|
52 |
|
53 |
m_Output = algorithm.getOutputObjects(); |
54 |
m_Algorithm = algorithm; |
55 |
|
56 |
} |
57 |
|
58 |
public void run(){ |
59 |
|
60 |
setOutputView(); |
61 |
|
62 |
addResults(); |
63 |
|
64 |
} |
65 |
|
66 |
private void setOutputView() { |
67 |
|
68 |
DefaultViewDocument view = null;
|
69 |
ParametersSet parameters = m_Algorithm.getParameters(); |
70 |
for (int i = 0; i < parameters.getNumberOfParameters(); i++) { |
71 |
Parameter param = parameters.getParameter(i); |
72 |
Object object = param.getParameterValueAsObject();
|
73 |
if (object instanceof ILayer){ |
74 |
view = getViewFromLayer((ILayer) object); |
75 |
m_MapContext = view.getMapContext(); |
76 |
return;
|
77 |
} |
78 |
else if (object instanceof ArrayList){ |
79 |
ArrayList list = (ArrayList) object; |
80 |
for (int j = 0; j < list.size(); j++) { |
81 |
Object obj = list.get(j);
|
82 |
if (obj instanceof ILayer){ |
83 |
view = getViewFromLayer((ILayer) obj); |
84 |
m_MapContext = view.getMapContext(); |
85 |
return;
|
86 |
} |
87 |
else if(obj instanceof RasterLayerAndBand){ |
88 |
RasterLayerAndBand rlab = (RasterLayerAndBand) obj; |
89 |
view = getViewFromLayer(rlab.getRasterLayer()); |
90 |
m_MapContext = view.getMapContext(); |
91 |
return;
|
92 |
} |
93 |
} |
94 |
} |
95 |
} |
96 |
|
97 |
final DefaultViewDocument newView = (DefaultViewDocument) ProjectManager.getInstance().createDocument(ViewManager.TYPENAME,"NUEVA"); |
98 |
final Project project = ProjectManager.getInstance().getCurrentProject();
|
99 |
project.add(newView); |
100 |
final IWindow window = newView.getFactory().getMainWindow(newView);
|
101 |
|
102 |
Runnable doWorkRunnable = new Runnable() { |
103 |
public void run() { |
104 |
PluginServices.getMDIManager().addWindow(window); |
105 |
m_MapContext = newView.getMapContext(); |
106 |
} |
107 |
}; |
108 |
try {
|
109 |
SwingUtilities.invokeAndWait(doWorkRunnable);
|
110 |
} catch (InterruptedException e) { |
111 |
e.printStackTrace(); |
112 |
} catch (InvocationTargetException e) { |
113 |
|
114 |
e.printStackTrace(); |
115 |
} |
116 |
|
117 |
} |
118 |
|
119 |
private DefaultViewDocument getViewFromLayer(ILayer layer) {
|
120 |
|
121 |
FLayer gvSIGBaseLayer = (FLayer) layer.getBaseDataObject(); |
122 |
//Project project = ((ProjectExtension)PluginServices.getExtension(ProjectExtension.class)).getProject();
|
123 |
final Project project = ProjectManager.getInstance().getCurrentProject();
|
124 |
List<Document> views = project.getDocuments(ViewManager.TYPENAME); |
125 |
|
126 |
for (int i = 0; i < views.size(); i++) { |
127 |
DefaultViewDocument view = (DefaultViewDocument) views.get(i); |
128 |
FLayers layers = view.getMapContext().getLayers(); |
129 |
LayersIterator iter = new LayersIterator(layers);
|
130 |
while (iter.hasNext()){
|
131 |
FLayer gvSIGLayer = iter.nextLayer(); |
132 |
if (gvSIGLayer.equals(gvSIGBaseLayer)){
|
133 |
return view;
|
134 |
} |
135 |
} |
136 |
|
137 |
} |
138 |
|
139 |
return null; |
140 |
|
141 |
} |
142 |
|
143 |
private void addResults(){ |
144 |
|
145 |
FLayer layer = null;
|
146 |
String sDescription;
|
147 |
boolean bInvalidate = false; |
148 |
boolean bShowAdditionalPanel = false; |
149 |
|
150 |
if (m_MapContext != null){ |
151 |
m_MapContext.beginAtomicEvent(); |
152 |
} |
153 |
|
154 |
for (int i = 0; i < m_Output.getOutputObjectsCount(); i++) { |
155 |
|
156 |
Output out = m_Output.getOutput(i); |
157 |
sDescription = out.getDescription(); |
158 |
Object object = out.getOutputObject();
|
159 |
if (object instanceof IVectorLayer){ |
160 |
layer = (FLayer) ((IVectorLayer)object).getBaseDataObject(); |
161 |
if (layer != null){ |
162 |
layer.setName(sDescription); |
163 |
m_MapContext.getLayers().addLayer(layer); |
164 |
bInvalidate = true;
|
165 |
SextanteGUI.getInputFactory().addDataObject((IDataObject) object); |
166 |
} |
167 |
} |
168 |
else if (object instanceof ITable){ |
169 |
try {
|
170 |
TableDocument table = (TableDocument) ((ITable)object).getBaseDataObject(); |
171 |
if (table != null){ |
172 |
((ProjectExtension) PluginServices.getExtension(ProjectExtension.class)) |
173 |
.getProject().add(table); |
174 |
|
175 |
SextanteGUI.getInputFactory().addDataObject((IDataObject) object); |
176 |
} |
177 |
} catch (Exception e) { |
178 |
e.printStackTrace(); |
179 |
} |
180 |
} |
181 |
else if (object instanceof IRasterLayer){ |
182 |
IRasterLayer rasterLayer = (IRasterLayer) object; |
183 |
layer = (FLayer) rasterLayer.getBaseDataObject(); |
184 |
if (layer != null){ |
185 |
((FLyrRasterSE)layer).setNoDataValue(rasterLayer.getNoDataValue()); |
186 |
layer.setName(sDescription); |
187 |
m_MapContext.getLayers().addLayer(layer); |
188 |
bInvalidate = true;
|
189 |
SextanteGUI.getInputFactory().addDataObject((IDataObject) object); |
190 |
} |
191 |
} |
192 |
else if (object instanceof String){ |
193 |
JTextPane jTextPane;
|
194 |
JScrollPane jScrollPane;
|
195 |
jTextPane = new JTextPane(); |
196 |
jTextPane.setEditable(false);
|
197 |
jTextPane.setContentType("text/html");
|
198 |
jTextPane.setText((String) object);
|
199 |
jScrollPane = new JScrollPane(); |
200 |
jScrollPane.setViewportView(jTextPane); |
201 |
jScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
|
202 |
jTextPane.setBorder(BorderFactory.createEtchedBorder(BevelBorder.LOWERED)); |
203 |
AdditionalResults.addComponent(new ObjectAndDescription(sDescription, jScrollPane));
|
204 |
bShowAdditionalPanel = true;
|
205 |
} |
206 |
else if (object instanceof Component){ |
207 |
AdditionalResults.addComponent(new ObjectAndDescription(sDescription, object));
|
208 |
bShowAdditionalPanel = true;
|
209 |
} |
210 |
|
211 |
} |
212 |
|
213 |
if (m_MapContext != null){ |
214 |
m_MapContext.endAtomicEvent(); |
215 |
} |
216 |
|
217 |
if (bInvalidate){
|
218 |
m_MapContext.invalidate(); |
219 |
} |
220 |
|
221 |
if (bShowAdditionalPanel){
|
222 |
AdditionalResults.showPanel(); |
223 |
} |
224 |
|
225 |
} |
226 |
|
227 |
} |