gvsig-geoprocess / org.gvsig.geoprocess / trunk / org.gvsig.geoprocess / org.gvsig.geoprocess.lib / org.gvsig.geoprocess.lib.sextante / src / main / java / org / gvsig / geoprocess / lib / sextante / core / gvOutputFactory.java @ 220
History | View | Annotate | Download (6.25 KB)
1 |
package org.gvsig.geoprocess.lib.sextante.core; |
---|---|
2 |
|
3 |
import java.util.Date; |
4 |
|
5 |
import javax.swing.JDialog; |
6 |
|
7 |
import es.unex.sextante.core.AnalysisExtent; |
8 |
import es.unex.sextante.core.ITaskMonitor; |
9 |
import es.unex.sextante.core.OutputFactory; |
10 |
import es.unex.sextante.dataObjects.IRasterLayer; |
11 |
import es.unex.sextante.dataObjects.ITable; |
12 |
import es.unex.sextante.dataObjects.IVectorLayer; |
13 |
import es.unex.sextante.exceptions.UnsupportedOutputChannelException; |
14 |
import es.unex.sextante.gui.core.DefaultTaskMonitor; |
15 |
import es.unex.sextante.outputs.FileOutputChannel; |
16 |
import es.unex.sextante.outputs.IOutputChannel; |
17 |
|
18 |
import org.gvsig.andami.Utilities; |
19 |
import org.gvsig.andami.messages.NotificationManager; |
20 |
import org.gvsig.app.ApplicationLocator; |
21 |
import org.gvsig.app.project.ProjectPreferences; |
22 |
import org.gvsig.geoprocess.lib.sextante.dataObjects.FileTools; |
23 |
import org.gvsig.geoprocess.lib.sextante.dataObjects.gvRasterLayerWrite; |
24 |
import org.gvsig.geoprocess.lib.sextante.dataObjects.gvTable; |
25 |
import org.gvsig.geoprocess.lib.sextante.dataObjects.gvVectorLayer; |
26 |
import org.gvsig.geoprocess.lib.sextante.outputs.CompositeSourceOutputChannel; |
27 |
|
28 |
/**
|
29 |
* An OutputFactory based on the gvSIG data model. Supports only file-based
|
30 |
* outputs.
|
31 |
*
|
32 |
* @author volaya
|
33 |
*
|
34 |
*/
|
35 |
public class gvOutputFactory extends OutputFactory { |
36 |
|
37 |
@Override
|
38 |
public IVectorLayer getNewVectorLayer(final String name, |
39 |
final int shapeType, final Class[] types, final String[] fields, |
40 |
final IOutputChannel channel, final Object crs) |
41 |
throws UnsupportedOutputChannelException {
|
42 |
|
43 |
final int[] sizes = new int[types.length]; |
44 |
for (int i = 0; i < sizes.length; i++) { |
45 |
sizes[i] = getSizeFromTypeClass(types[i]); |
46 |
} |
47 |
return getNewVectorLayer(name, shapeType, types, fields, channel, crs,
|
48 |
sizes); |
49 |
|
50 |
} |
51 |
|
52 |
@Override
|
53 |
public IVectorLayer getNewVectorLayer(final String sName, |
54 |
final int iShapeType, final Class[] types, final String[] sFields, |
55 |
final IOutputChannel channel, final Object crs, final int[] fieldSize) |
56 |
throws UnsupportedOutputChannelException {
|
57 |
|
58 |
if (channel != null) { |
59 |
if (channel instanceof CompositeSourceOutputChannel) { |
60 |
gvVectorLayer layer = new gvVectorLayer();
|
61 |
Object inputParams =
|
62 |
((CompositeSourceOutputChannel) channel).getParameters(); |
63 |
layer.create(sName, inputParams, iShapeType, types, sFields, |
64 |
crs, fieldSize); |
65 |
return layer;
|
66 |
|
67 |
} else
|
68 |
if (channel instanceof FileOutputChannel) { |
69 |
gvVectorLayer layer = new gvVectorLayer();
|
70 |
String fileName =
|
71 |
((FileOutputChannel) channel).getFilename(); |
72 |
layer.create(sName, fileName, iShapeType, types, sFields, |
73 |
crs, fieldSize); |
74 |
return layer;
|
75 |
} |
76 |
} |
77 |
|
78 |
|
79 |
throw new UnsupportedOutputChannelException(); |
80 |
} |
81 |
|
82 |
@Override
|
83 |
public IRasterLayer getNewRasterLayer(final String sName, |
84 |
final int iDataType, final AnalysisExtent extent, final int iBands, |
85 |
final IOutputChannel channel, final Object crs) |
86 |
throws UnsupportedOutputChannelException {
|
87 |
|
88 |
if (channel instanceof FileOutputChannel) { |
89 |
final String sFilename = |
90 |
((FileOutputChannel) channel).getFilename(); |
91 |
final gvRasterLayerWrite layer = new gvRasterLayerWrite(); |
92 |
layer.create(sName, sFilename, extent, iDataType, iBands, crs); |
93 |
return layer;
|
94 |
} else {
|
95 |
throw new UnsupportedOutputChannelException(); |
96 |
} |
97 |
|
98 |
} |
99 |
|
100 |
@Override
|
101 |
public ITable getNewTable(final String sName, final Class types[], |
102 |
final String[] sFields, final IOutputChannel channel) |
103 |
throws UnsupportedOutputChannelException {
|
104 |
|
105 |
if (channel instanceof FileOutputChannel) { |
106 |
final String sFilename = |
107 |
((FileOutputChannel) channel).getFilename(); |
108 |
final gvTable table = new gvTable(); |
109 |
table.create(sName, sFilename, types, sFields); |
110 |
return table;
|
111 |
} else {
|
112 |
throw new UnsupportedOutputChannelException(); |
113 |
} |
114 |
|
115 |
} |
116 |
|
117 |
@Override
|
118 |
public String getTempFolder() { |
119 |
|
120 |
return Utilities.createTempDirectory(); |
121 |
|
122 |
} |
123 |
|
124 |
@Override
|
125 |
public String[] getRasterLayerOutputExtensions() { |
126 |
|
127 |
return FileTools.RASTER_EXT_IN;
|
128 |
|
129 |
} |
130 |
|
131 |
@Override
|
132 |
public String[] getVectorLayerOutputExtensions() { |
133 |
|
134 |
return new String[] { "shp", "dxf" }; |
135 |
|
136 |
} |
137 |
|
138 |
@Override
|
139 |
public String[] getTableOutputExtensions() { |
140 |
|
141 |
return new String[] { "dbf" }; |
142 |
|
143 |
} |
144 |
|
145 |
public void addMessage(final String s) { |
146 |
|
147 |
NotificationManager.addInfo(s, null);
|
148 |
|
149 |
} |
150 |
|
151 |
@Override
|
152 |
public ITaskMonitor getTaskMonitor(final String sTitle, |
153 |
final boolean bDeterminate, final JDialog parent) { |
154 |
|
155 |
return new DefaultTaskMonitor(sTitle, bDeterminate, parent); |
156 |
|
157 |
} |
158 |
|
159 |
@Override
|
160 |
public Object getDefaultCRS() { |
161 |
|
162 |
return ((ProjectPreferences) ApplicationLocator.getManager()
|
163 |
.getPreferences("project")).getDefaultProjection();
|
164 |
|
165 |
} |
166 |
|
167 |
private int getSizeFromTypeClass(final Class<?> type) { |
168 |
|
169 |
if (type.equals(Integer.class)) { |
170 |
return 10; |
171 |
} else
|
172 |
if (type.equals(Long.class)) { |
173 |
return 20; |
174 |
} else
|
175 |
if (type.equals(Double.class)) { |
176 |
return 20; |
177 |
} else
|
178 |
if (type.equals(Float.class)) { |
179 |
return 15; |
180 |
} else
|
181 |
if (type.equals(String.class)) { |
182 |
return 80; |
183 |
} else
|
184 |
if (type.equals(Date.class)) { |
185 |
return 10; |
186 |
} else
|
187 |
if (type.equals(Boolean.class)) { |
188 |
return 1; |
189 |
} else {
|
190 |
return 20; |
191 |
} |
192 |
|
193 |
} |
194 |
|
195 |
} |