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