svn-gvsig-desktop / branches / gvSIG_1.11.0_Mejoras_gvSIG-EIEL / libraries / libFMap / src / com / iver / cit / gvsig / fmap / layers / FLayerGenericVectorial.java @ 35647
History | View | Annotate | Download (6.13 KB)
1 | 6763 | jmvivo | package com.iver.cit.gvsig.fmap.layers; |
---|---|---|---|
2 | |||
3 | import org.cresques.cts.IProjection; |
||
4 | |||
5 | import com.hardcode.driverManager.DriverLoadException; |
||
6 | 10627 | caballero | import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
7 | import com.iver.cit.gvsig.exceptions.layers.DriverLayerException; |
||
8 | import com.iver.cit.gvsig.exceptions.layers.LegendLayerException; |
||
9 | import com.iver.cit.gvsig.exceptions.layers.LoadLayerException; |
||
10 | import com.iver.cit.gvsig.exceptions.layers.NameLayerException; |
||
11 | import com.iver.cit.gvsig.exceptions.layers.ProjectionLayerException; |
||
12 | import com.iver.cit.gvsig.exceptions.layers.XMLLayerException; |
||
13 | 6763 | jmvivo | import com.iver.cit.gvsig.fmap.crs.CRSFactory; |
14 | import com.iver.cit.gvsig.fmap.drivers.VectorialDriver; |
||
15 | import com.iver.cit.gvsig.fmap.drivers.WithDefaultLegend; |
||
16 | 13913 | jaume | import com.iver.cit.gvsig.fmap.rendering.IVectorLegend; |
17 | 6763 | jmvivo | import com.iver.cit.gvsig.fmap.rendering.LegendFactory; |
18 | 18621 | jdominguez | import com.iver.cit.gvsig.fmap.rendering.styling.labeling.AttrInTableLabelingStrategy; |
19 | import com.iver.cit.gvsig.fmap.rendering.styling.labeling.ILabelingStrategy; |
||
20 | 13913 | jaume | import com.iver.utiles.IPersistence; |
21 | 6763 | jmvivo | import com.iver.utiles.XMLEntity; |
22 | |||
23 | public class FLayerGenericVectorial extends FLyrVect { |
||
24 | private boolean loaded = false; |
||
25 | |||
26 | private VectorialDriver vDriver = null; |
||
27 | 10627 | caballero | |
28 | |||
29 | 6763 | jmvivo | /* Esto deberia ir en el FLyrDefault */
|
30 | 10627 | caballero | public void setProjectionByName(String projectionName) throws Exception{ |
31 | 6763 | jmvivo | IProjection proj = CRSFactory.getCRS(projectionName); |
32 | if (proj == null) { |
||
33 | throw new Exception("No se ha encontrado la proyeccion: "+ projectionName); |
||
34 | } |
||
35 | this.setProjection(proj);
|
||
36 | 10627 | caballero | |
37 | 6763 | jmvivo | } |
38 | |||
39 | 10627 | caballero | |
40 | 6763 | jmvivo | public void setDriver(VectorialDriver vDriver) { |
41 | this.vDriver = vDriver;
|
||
42 | } |
||
43 | 10627 | caballero | |
44 | 6763 | jmvivo | public VectorialDriver getDriver() {
|
45 | return this.vDriver ; |
||
46 | } |
||
47 | |||
48 | 10665 | caballero | public void setDriverByName(String driverName) throws DriverLoadException { |
49 | 6763 | jmvivo | this.setDriver(
|
50 | 10627 | caballero | (VectorialDriver)LayerFactory.getDM().getDriver(driverName) |
51 | 6763 | jmvivo | ); |
52 | } |
||
53 | |||
54 | 10627 | caballero | |
55 | 6763 | jmvivo | /* Esto deberia ir en FLyrVect */
|
56 | 10627 | caballero | private void initializeLegendDefault() throws LegendLayerException, ReadDriverException { |
57 | 6763 | jmvivo | if (this.getLegend() == null) { |
58 | if (this.getRecordset().getDriver() instanceof WithDefaultLegend) { |
||
59 | WithDefaultLegend aux = (WithDefaultLegend) this.getRecordset().getDriver();
|
||
60 | 13884 | jaume | this.setLegend((IVectorLegend) aux.getDefaultLegend());
|
61 | 10813 | jaume | |
62 | ILabelingStrategy labeler = aux.getDefaultLabelingStrategy(); |
||
63 | 18621 | jdominguez | if (labeler instanceof AttrInTableLabelingStrategy) { |
64 | ((AttrInTableLabelingStrategy) labeler).setLayer(this);
|
||
65 | 10813 | jaume | } |
66 | |||
67 | this.setLabelingStrategy(labeler);
|
||
68 | 6763 | jmvivo | } else {
|
69 | this.setLegend(LegendFactory.createSingleSymbolLegend(
|
||
70 | this.getShapeType()));
|
||
71 | } |
||
72 | 10627 | caballero | } |
73 | 6763 | jmvivo | } |
74 | /* FIXME: esto tendria que tener declarado un throws de algo*/
|
||
75 | 10627 | caballero | public void wakeUp() throws LoadLayerException { |
76 | 6763 | jmvivo | if (!loaded) {
|
77 | 10627 | caballero | this.load();
|
78 | 6763 | jmvivo | } |
79 | 10627 | caballero | |
80 | 6763 | jmvivo | } |
81 | |||
82 | 10627 | caballero | |
83 | public void load() throws LoadLayerException { |
||
84 | 6763 | jmvivo | if (this.getName() == null || this.getName().length() == 0) { |
85 | this.setAvailable(false); |
||
86 | 10627 | caballero | throw new NameLayerException(getName(),null); |
87 | 6763 | jmvivo | } |
88 | if (this.vDriver == null) { |
||
89 | this.setAvailable(false); |
||
90 | 10627 | caballero | throw new DriverLayerException(getName(),null); |
91 | 6763 | jmvivo | } |
92 | if (this.getProjection() == null) { |
||
93 | this.setAvailable(false); |
||
94 | 10627 | caballero | throw new ProjectionLayerException(getName(),null); |
95 | 6763 | jmvivo | } |
96 | 10627 | caballero | |
97 | 6763 | jmvivo | VectorialAdapter adapter = null;
|
98 | 10627 | caballero | adapter = new VectorialDefaultAdapter();
|
99 | adapter.setDriver(this.vDriver);
|
||
100 | this.setSource(adapter);
|
||
101 | |||
102 | 6763 | jmvivo | try {
|
103 | this.putLoadSelection();
|
||
104 | this.putLoadLegend();
|
||
105 | this.initializeLegendDefault();
|
||
106 | 10627 | caballero | |
107 | } catch (LegendLayerException e) {
|
||
108 | 6763 | jmvivo | this.setAvailable(false); |
109 | 10627 | caballero | throw new LegendLayerException(getName(),e); |
110 | } catch (XMLException e) {
|
||
111 | this.setAvailable(false); |
||
112 | throw new XMLLayerException(getName(),e); |
||
113 | } catch (ReadDriverException e) {
|
||
114 | this.setAvailable(false); |
||
115 | throw new LoadLayerException(getName(),e); |
||
116 | 6763 | jmvivo | } |
117 | this.cleanLoadOptions();
|
||
118 | } |
||
119 | |||
120 | public void setXMLEntity(XMLEntity xml) throws XMLException { |
||
121 | IProjection proj = null;
|
||
122 | if (xml.contains("proj")) { |
||
123 | proj = CRSFactory.getCRS(xml.getStringProperty("proj"));
|
||
124 | } |
||
125 | else
|
||
126 | { |
||
127 | 6881 | cesar | proj = this.getMapContext().getViewPort().getProjection();
|
128 | 6763 | jmvivo | } |
129 | this.setName(xml.getName());
|
||
130 | this.setProjection(proj);
|
||
131 | 10627 | caballero | |
132 | 6763 | jmvivo | String driverName = xml.getStringProperty("other"); |
133 | VectorialDriver driver = null;
|
||
134 | try {
|
||
135 | driver = (VectorialDriver) LayerFactory.getDM().getDriver(driverName); |
||
136 | } catch (DriverLoadException e) {
|
||
137 | // Si no existe ese driver, no pasa nada.
|
||
138 | // Puede que el desarrollador no quiera que
|
||
139 | // aparezca en el cuadro de di?logo y ha metido
|
||
140 | // el jar con sus clases en nuestro directorio lib.
|
||
141 | // Intentamos cargar esa clase "a pelo".
|
||
142 | if (xml.getChild(2).contains("className")) |
||
143 | { |
||
144 | String className2 = xml.getChild(2).getStringProperty("className"); |
||
145 | try {
|
||
146 | driver = (VectorialDriver) Class.forName(className2).newInstance();
|
||
147 | } catch (Exception e1) { |
||
148 | throw new XMLException(e1); |
||
149 | } |
||
150 | } |
||
151 | } catch (NullPointerException npe) { |
||
152 | // Si no existe ese driver, no pasa nada.
|
||
153 | // Puede que el desarrollador no quiera que
|
||
154 | // aparezca en el cuadro de di?logo y ha metido
|
||
155 | // el jar con sus clases en nuestro directorio lib.
|
||
156 | // Intentamos cargar esa clase "a pelo".
|
||
157 | if (xml.getChild(2).contains("className")) |
||
158 | { |
||
159 | String className2 = xml.getChild(2).getStringProperty("className"); |
||
160 | try {
|
||
161 | driver = (VectorialDriver) Class.forName(className2).newInstance();
|
||
162 | } catch (Exception e1) { |
||
163 | throw new XMLException(e1); |
||
164 | } |
||
165 | } |
||
166 | } |
||
167 | if (driver == null) { |
||
168 | throw new XMLException(new Exception("Error al cargar el driver")); |
||
169 | } |
||
170 | 13913 | jaume | if (driver instanceof IPersistence) |
171 | 6763 | jmvivo | { |
172 | 13913 | jaume | IPersistence persist = (IPersistence) driver; |
173 | 6763 | jmvivo | persist.setXMLEntity(xml.getChild(2));
|
174 | } |
||
175 | this.setDriver(driver);
|
||
176 | 6769 | jmvivo | super.setXMLEntityNew(xml);
|
177 | 6763 | jmvivo | } |
178 | } |