svn-gvsig-desktop / tags / v1_1_Build_1015 / libraries / libFMap / src / com / iver / cit / gvsig / fmap / layers / FLayerFileVectorial.java @ 13679
History | View | Annotate | Download (5.33 KB)
1 | 6763 | jmvivo | package com.iver.cit.gvsig.fmap.layers; |
---|---|---|---|
2 | |||
3 | import java.io.File; |
||
4 | import java.io.FileNotFoundException; |
||
5 | |||
6 | import org.cresques.cts.IProjection; |
||
7 | |||
8 | import com.hardcode.driverManager.DriverLoadException; |
||
9 | import com.hardcode.gdbms.engine.instruction.FieldNotFoundException; |
||
10 | import com.iver.cit.gvsig.fmap.DriverException; |
||
11 | import com.iver.cit.gvsig.fmap.crs.CRSFactory; |
||
12 | import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
||
13 | import com.iver.cit.gvsig.fmap.drivers.VectorialDriver; |
||
14 | import com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver; |
||
15 | import com.iver.cit.gvsig.fmap.drivers.WithDefaultLegend; |
||
16 | import com.iver.cit.gvsig.fmap.rendering.LegendFactory; |
||
17 | import com.iver.cit.gvsig.fmap.rendering.VectorialLegend; |
||
18 | import com.iver.utiles.XMLEntity; |
||
19 | |||
20 | public class FLayerFileVectorial extends FLyrVect{ |
||
21 | private boolean loaded = false; |
||
22 | private File dataFile = null; |
||
23 | private VectorialFileDriver fileDriver = null; |
||
24 | |||
25 | public FLayerFileVectorial() {
|
||
26 | super();
|
||
27 | } |
||
28 | |||
29 | public FLayerFileVectorial(String name, String fileName,String driverName,String projectionName) throws Exception { |
||
30 | super();
|
||
31 | |||
32 | this.setName(name);
|
||
33 | |||
34 | this.setFileName(fileName);
|
||
35 | |||
36 | this.setDriverByName(driverName);
|
||
37 | |||
38 | this.setProjectionByName(projectionName);
|
||
39 | } |
||
40 | |||
41 | /* Esto deberia ir en el FLyrDefault */
|
||
42 | public void setProjectionByName(String projectionName) throws Exception{ |
||
43 | IProjection proj = CRSFactory.getCRS(projectionName); |
||
44 | if (proj == null) { |
||
45 | throw new Exception("No se ha encontrado la proyeccion: "+ projectionName); |
||
46 | } |
||
47 | this.setProjection(proj);
|
||
48 | |||
49 | } |
||
50 | |||
51 | public void setFileName(String filePath) throws FileNotFoundException{ |
||
52 | if (dataFile != null) { |
||
53 | //TODO: que excepcion lanzar???
|
||
54 | return;
|
||
55 | } |
||
56 | File file = new File(filePath); |
||
57 | if (!file.exists()) {
|
||
58 | throw new FileNotFoundException(filePath); |
||
59 | } |
||
60 | this.dataFile = file;
|
||
61 | } |
||
62 | |||
63 | public void setFile(File file) throws FileNotFoundException { |
||
64 | if (dataFile != null) { |
||
65 | //TODO: que excepcion lanzar???
|
||
66 | return;
|
||
67 | } |
||
68 | if (!file.exists()) {
|
||
69 | throw new FileNotFoundException(file.getAbsolutePath()); |
||
70 | } |
||
71 | this.dataFile = new File(file.getAbsolutePath()); |
||
72 | } |
||
73 | |||
74 | public String getFileName() { |
||
75 | if (this.dataFile == null) { |
||
76 | return null; |
||
77 | } |
||
78 | return this.dataFile.getAbsolutePath(); |
||
79 | } |
||
80 | |||
81 | |||
82 | public void setDriver(VectorialFileDriver driver) { |
||
83 | this.fileDriver = driver;
|
||
84 | } |
||
85 | |||
86 | public void setDriverByName(String driverName) { |
||
87 | this.setDriver(
|
||
88 | (VectorialFileDriver)LayerFactory.getDM().getDriver(driverName) |
||
89 | ); |
||
90 | } |
||
91 | |||
92 | public VectorialFileDriver getDriver() {
|
||
93 | return this.fileDriver; |
||
94 | } |
||
95 | |||
96 | /* FIXME: esto tendria que tener declarado un throws de algo*/
|
||
97 | public void wakeUp() { |
||
98 | if (!loaded) {
|
||
99 | try {
|
||
100 | this.load();
|
||
101 | } catch (DriverIOException e) {
|
||
102 | // TODO Auto-generated catch block
|
||
103 | e.printStackTrace(); |
||
104 | } |
||
105 | } |
||
106 | |||
107 | } |
||
108 | |||
109 | |||
110 | public void load() throws DriverIOException { |
||
111 | if (this.dataFile == null) { |
||
112 | this.setAvailable(false); |
||
113 | //TODO: traducir???
|
||
114 | throw new DriverIOException("No se ha especificado fichero"); |
||
115 | } |
||
116 | if (this.getName() == null || this.getName().length() == 0) { |
||
117 | this.setAvailable(false); |
||
118 | //TODO: traducir???
|
||
119 | throw new DriverIOException("No se ha especificado nombre de capa"); |
||
120 | } |
||
121 | if (this.fileDriver == null) { |
||
122 | this.setAvailable(false); |
||
123 | //TODO: traducir???
|
||
124 | throw new DriverIOException("No se ha especificado driver"); |
||
125 | } |
||
126 | if (this.getProjection() == null) { |
||
127 | this.setAvailable(false); |
||
128 | //TODO: traducir???
|
||
129 | throw new DriverIOException("No se ha especificado proyeccion"); |
||
130 | } |
||
131 | |||
132 | try {
|
||
133 | VectorialFileAdapter adapter = new VectorialFileAdapter(this.dataFile); |
||
134 | adapter.setDriver((VectorialDriver) this.fileDriver);
|
||
135 | |||
136 | this.setSource(adapter);
|
||
137 | } catch (Exception e) { |
||
138 | this.setAvailable(false); |
||
139 | throw new DriverIOException(e); |
||
140 | } |
||
141 | |||
142 | |||
143 | try {
|
||
144 | this.putLoadSelection();
|
||
145 | this.putLoadLegend();
|
||
146 | this.initializeLegendDefault();
|
||
147 | |||
148 | } catch (Exception e) { |
||
149 | this.setAvailable(false); |
||
150 | throw new DriverIOException(e); |
||
151 | } |
||
152 | this.cleanLoadOptions();
|
||
153 | this.loaded = true; |
||
154 | } |
||
155 | |||
156 | /* Esto deberia ir en FLyrVect */
|
||
157 | private void initializeLegendDefault() throws FieldNotFoundException, DriverException { |
||
158 | if (this.getLegend() == null) { |
||
159 | if (this.getRecordset().getDriver() instanceof WithDefaultLegend) { |
||
160 | WithDefaultLegend aux = (WithDefaultLegend) this.getRecordset().getDriver();
|
||
161 | this.setLegend((VectorialLegend) aux.getDefaultLegend());
|
||
162 | } else {
|
||
163 | this.setLegend(LegendFactory.createSingleSymbolLegend(
|
||
164 | this.getShapeType()));
|
||
165 | } |
||
166 | } |
||
167 | } |
||
168 | |||
169 | public void setXMLEntity(XMLEntity xml) throws XMLException { |
||
170 | IProjection proj = null;
|
||
171 | if (xml.contains("proj")) { |
||
172 | proj = CRSFactory.getCRS(xml.getStringProperty("proj"));
|
||
173 | } |
||
174 | else
|
||
175 | { |
||
176 | 6881 | cesar | proj = this.getMapContext().getViewPort().getProjection();
|
177 | 6763 | jmvivo | } |
178 | this.setName(xml.getName());
|
||
179 | this.setProjection(proj);
|
||
180 | try {
|
||
181 | this.setDriver(
|
||
182 | (VectorialFileDriver)LayerFactory.getDM().getDriver( |
||
183 | xml.getStringProperty("driverName")
|
||
184 | ) |
||
185 | ); |
||
186 | } catch (DriverLoadException e) {
|
||
187 | throw new XMLException(e); |
||
188 | } catch (ClassCastException e) { |
||
189 | throw new XMLException(e); |
||
190 | } |
||
191 | try {
|
||
192 | this.setFileName(xml.getStringProperty("file")); |
||
193 | } catch (FileNotFoundException e) { |
||
194 | throw new XMLException(e); |
||
195 | } |
||
196 | |||
197 | 6769 | jmvivo | super.setXMLEntityNew(xml);
|
198 | 6763 | jmvivo | } |
199 | } |