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