svn-gvsig-desktop / tags / gvSIGv0_6_1RELEASE / applications / appgvSIG / src / com / iver / cit / gvsig / project / ProjectView.java @ 5222
History | View | Annotate | Download (9.07 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*
|
19 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Ib??ez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* IVER T.I. S.A
|
34 |
* Salamanca 50
|
35 |
* 46005 Valencia
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 963163400
|
39 |
* dac@iver.es
|
40 |
*/
|
41 |
package com.iver.cit.gvsig.project; |
42 |
|
43 |
import java.awt.Color; |
44 |
import java.awt.Component; |
45 |
import java.text.DateFormat; |
46 |
import java.util.Date; |
47 |
|
48 |
import javax.swing.JOptionPane; |
49 |
|
50 |
import org.cresques.cts.IProjection; |
51 |
|
52 |
import com.iver.andami.PluginServices; |
53 |
import com.iver.andami.ui.mdiManager.ViewInfo; |
54 |
import com.iver.cit.gvsig.fmap.DriverException; |
55 |
import com.iver.cit.gvsig.fmap.ErrorEvent; |
56 |
import com.iver.cit.gvsig.fmap.ErrorListener; |
57 |
import com.iver.cit.gvsig.fmap.FMap; |
58 |
import com.iver.cit.gvsig.fmap.ViewPort; |
59 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
60 |
import com.iver.cit.gvsig.fmap.layers.XMLException; |
61 |
import com.iver.cit.gvsig.gui.project.OpenException; |
62 |
import com.iver.cit.gvsig.gui.project.SaveException; |
63 |
import com.iver.utiles.XMLEntity; |
64 |
|
65 |
|
66 |
/**
|
67 |
* Clase que representa una vista del proyecto
|
68 |
*
|
69 |
* @author Fernando Gonz?lez Cort?s
|
70 |
*/
|
71 |
public class ProjectView extends ProjectElement implements ErrorListener { |
72 |
public static int numViews = 0; |
73 |
|
74 |
//public static int METROS = 0;
|
75 |
//public static int KILOMETROS = 1;
|
76 |
//public static int[] unidades = new int[] { METROS, KILOMETROS };
|
77 |
///private Color backgroundColor = new Color(255, 255, 255);
|
78 |
private FMap mapOverViewContext;
|
79 |
private FMap mapContext;
|
80 |
private int m_typeLink = 0; |
81 |
private String m_extLink; |
82 |
private String m_selectedField = null; |
83 |
|
84 |
/**
|
85 |
* DOCUMENT ME!
|
86 |
*
|
87 |
* @return
|
88 |
*/
|
89 |
public FMap getMapContext() {
|
90 |
return mapContext;
|
91 |
} |
92 |
|
93 |
/**
|
94 |
* DOCUMENT ME!
|
95 |
*
|
96 |
* @return
|
97 |
*/
|
98 |
public FMap getMapOverViewContext() {
|
99 |
return mapOverViewContext;
|
100 |
} |
101 |
|
102 |
/**
|
103 |
* DOCUMENT ME!
|
104 |
*
|
105 |
* @param baseName
|
106 |
*
|
107 |
* @return
|
108 |
*/
|
109 |
public static ProjectView createView(String baseName) { |
110 |
ProjectView v = new ProjectView();
|
111 |
v.mapContext = new FMap(new ViewPort(Project.getProjection())); |
112 |
v.mapOverViewContext = new FMap(null); |
113 |
|
114 |
//v.mapOverViewContext = null;
|
115 |
v.setName(baseName + " - " + numViews);
|
116 |
v.setCreationDate(DateFormat.getInstance().format(new Date())); |
117 |
numViews++; |
118 |
|
119 |
return v;
|
120 |
} |
121 |
|
122 |
/**
|
123 |
* @see com.iver.cit.gvsig.project.ProjectView#setMapContext(com.iver.cit.gvsig.fmap.FMap)
|
124 |
*/
|
125 |
public void setMapContext(FMap fmap) { |
126 |
mapContext = fmap; |
127 |
fmap.addErrorListener(this);
|
128 |
} |
129 |
|
130 |
/**
|
131 |
* DOCUMENT ME!
|
132 |
*
|
133 |
* @param fmap DOCUMENT ME!
|
134 |
*/
|
135 |
public void setMapOverViewContext(FMap fmap) { |
136 |
mapOverViewContext = fmap; |
137 |
} |
138 |
|
139 |
/**
|
140 |
* DOCUMENT ME!
|
141 |
*
|
142 |
* @return DOCUMENT ME!
|
143 |
* @throws XMLException
|
144 |
* @throws SaveException
|
145 |
*/
|
146 |
public XMLEntity getXMLEntity() throws SaveException { |
147 |
XMLEntity xml = super.getXMLEntity();
|
148 |
//xml.putProperty("nameClass", this.getClass().getName());
|
149 |
try{
|
150 |
xml.putProperty("numViews", numViews);
|
151 |
xml.putProperty("m_selectedField", m_selectedField);
|
152 |
xml.putProperty("m_typeLink", m_typeLink);
|
153 |
xml.putProperty("m_extLink", m_extLink);
|
154 |
xml.addChild(mapContext.getXMLEntity()); |
155 |
|
156 |
if (mapOverViewContext != null) { |
157 |
if (mapOverViewContext.getViewPort() != null) { |
158 |
xml.putProperty("mapOverView", true); |
159 |
xml.addChild(mapOverViewContext.getXMLEntity()); |
160 |
} else {
|
161 |
xml.putProperty("mapOverView", false); |
162 |
} |
163 |
} else {
|
164 |
xml.putProperty("mapOverView", false); |
165 |
} |
166 |
XMLEntity viewProperties = this.getViewInfoXMLEntity();
|
167 |
if (viewProperties!=null) { //store the properties of the window |
168 |
xml.addChild(viewProperties); |
169 |
} |
170 |
}catch (Exception e) { |
171 |
throw new SaveException(e,this.getClass().getName()); |
172 |
} |
173 |
return xml;
|
174 |
} |
175 |
|
176 |
/**
|
177 |
* DOCUMENT ME!
|
178 |
*
|
179 |
* @param xml DOCUMENT ME!
|
180 |
* @param p DOCUMENT ME!
|
181 |
* @throws XMLException
|
182 |
* @throws DriverException
|
183 |
* @throws DriverIOException
|
184 |
*
|
185 |
* @see com.iver.cit.gvsig.project.ProjectElement#setXMLEntity(com.iver.utiles.XMLEntity)
|
186 |
*/
|
187 |
public void setXMLEntity03(XMLEntity xml, Project p) |
188 |
throws XMLException, DriverException, DriverIOException {
|
189 |
numViews = xml.getIntProperty("numViews");
|
190 |
m_selectedField = xml.getStringProperty("m_selectedField");
|
191 |
m_typeLink = xml.getIntProperty("m_typeLink");
|
192 |
m_extLink = xml.getStringProperty("m_extLink");
|
193 |
setMapContext(FMap.createFromXML03(xml.getChild(0)));
|
194 |
|
195 |
if (xml.getBooleanProperty("mapOverView")) { |
196 |
setMapOverViewContext(FMap.createFromXML03(xml.getChild(1)));
|
197 |
} |
198 |
|
199 |
} |
200 |
|
201 |
/**
|
202 |
* DOCUMENT ME!
|
203 |
*
|
204 |
* @param xml DOCUMENT ME!
|
205 |
* @param p DOCUMENT ME!
|
206 |
* @throws XMLException
|
207 |
* @throws DriverException
|
208 |
* @throws DriverIOException
|
209 |
* @throws OpenException
|
210 |
*
|
211 |
* @see com.iver.cit.gvsig.project.ProjectElement#setXMLEntity(com.iver.utiles.XMLEntity)
|
212 |
*/
|
213 |
public void setXMLEntity(XMLEntity xml, Project p) |
214 |
throws XMLException, DriverException, DriverIOException, OpenException {
|
215 |
try{
|
216 |
int currentChild=0; |
217 |
numViews = xml.getIntProperty("numViews");
|
218 |
m_selectedField = xml.getStringProperty("m_selectedField");
|
219 |
m_typeLink = xml.getIntProperty("m_typeLink");
|
220 |
m_extLink = xml.getStringProperty("m_extLink");
|
221 |
|
222 |
setMapContext(FMap.createFromXML(xml.getChild(currentChild))); |
223 |
currentChild++; |
224 |
if (xml.getBooleanProperty("mapOverView")) { |
225 |
setMapOverViewContext(FMap.createFromXML(xml.getChild(1)));
|
226 |
currentChild++; |
227 |
} |
228 |
if (currentChild<xml.getNumChild()) {
|
229 |
XMLEntity child = xml.getChild(currentChild); |
230 |
if (child.contains("className") && child.getStringProperty("className").equals(this.getClass().getName()) && child.contains("name") && child.getStringProperty("name").equals("ViewInfoProperties")) { |
231 |
seedViewInfo = createViewInfoFromXMLEntity(child); |
232 |
//currentChild++;
|
233 |
} |
234 |
} |
235 |
showErrors(); |
236 |
}catch (Exception e) { |
237 |
throw new OpenException(e,this.getClass().getName()); |
238 |
} |
239 |
} |
240 |
|
241 |
public void showErrors(){ |
242 |
if (mapContext.getLayersError().size()>0){ |
243 |
String layersError=""; |
244 |
for (int i=0;i<mapContext.getLayersError().size();i++){ |
245 |
layersError=layersError+"\n"+(String)mapContext.getLayersError().get(i); |
246 |
} |
247 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), |
248 |
PluginServices.getText(this,"fallo_capas")+" : \n"+ |
249 |
layersError); |
250 |
} |
251 |
} |
252 |
/**
|
253 |
* DOCUMENT ME!
|
254 |
*
|
255 |
* @param p DOCUMENT ME!
|
256 |
*
|
257 |
* @return DOCUMENT ME!
|
258 |
* @throws XMLException
|
259 |
* @throws DriverException
|
260 |
* @throws DriverIOException
|
261 |
* @throws OpenException
|
262 |
*/
|
263 |
/*public ProjectView cloneProjectView(Project p)
|
264 |
throws XMLException, DriverException, DriverIOException, OpenException {
|
265 |
return (ProjectView) createFromXML(getXMLEntity(), p);
|
266 |
}
|
267 |
*/
|
268 |
/**
|
269 |
* DOCUMENT ME!
|
270 |
*
|
271 |
* @return DOCUMENT ME!
|
272 |
*/
|
273 |
public IProjection getProjection() {
|
274 |
return mapContext.getProjection();
|
275 |
} |
276 |
|
277 |
/**
|
278 |
* DOCUMENT ME!
|
279 |
*
|
280 |
* @return DOCUMENT ME!
|
281 |
*/
|
282 |
public IProjection getOverViewProjection() {
|
283 |
return mapOverViewContext.getProjection();
|
284 |
} |
285 |
|
286 |
/**
|
287 |
* DOCUMENT ME!
|
288 |
*
|
289 |
* @return DOCUMENT ME!
|
290 |
*/
|
291 |
public String getExtLink() { |
292 |
return m_extLink;
|
293 |
} |
294 |
|
295 |
/**
|
296 |
* DOCUMENT ME!
|
297 |
*
|
298 |
* @return DOCUMENT ME!
|
299 |
*/
|
300 |
public int getTypeLink() { |
301 |
return m_typeLink;
|
302 |
} |
303 |
|
304 |
/**
|
305 |
* Se selecciona la extensi?n para realizar cuando se quiera el link.
|
306 |
*
|
307 |
* @param s nombre del campo.
|
308 |
*/
|
309 |
public void setExtLink(String s) { |
310 |
m_extLink = s; |
311 |
} |
312 |
|
313 |
/**
|
314 |
* Se selecciona el tipo de fichero para realizar cuando se quiera el link.
|
315 |
*
|
316 |
* @param i tipo de fichero.
|
317 |
*/
|
318 |
public void setTypeLink(int i) { |
319 |
m_typeLink = i; |
320 |
} |
321 |
|
322 |
/**
|
323 |
* DOCUMENT ME!
|
324 |
*
|
325 |
* @param c DOCUMENT ME!
|
326 |
*/
|
327 |
public void setBackColor(Color c) { |
328 |
// getMapContext().getViewPort().addViewPortListener(getMapContext()
|
329 |
// .getEventBuffer());
|
330 |
getMapContext().getViewPort().setBackColor(c); |
331 |
//getMapContext().getViewPort().removeViewPortListener(getMapContext()
|
332 |
// .getEventBuffer());
|
333 |
} |
334 |
|
335 |
/**
|
336 |
* Se selecciona el nombre del campo para realizar cuando se quiera el
|
337 |
* link.
|
338 |
*
|
339 |
* @param s nombre del campo.
|
340 |
*/
|
341 |
public void setSelectedField(String s) { |
342 |
m_selectedField = s; |
343 |
} |
344 |
|
345 |
/**
|
346 |
* DOCUMENT ME!
|
347 |
*
|
348 |
* @return DOCUMENT ME!
|
349 |
*/
|
350 |
public String getSelectedField() { |
351 |
return m_selectedField;
|
352 |
} |
353 |
|
354 |
public void errorThrown(ErrorEvent e) { |
355 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), |
356 |
PluginServices.getText(this,"fallo_capas")+" : \n"+ |
357 |
e.getMessage()); |
358 |
|
359 |
} |
360 |
} |