root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / project / ProjectView.java @ 6877
History | View | Annotate | Download (9.49 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 |
* Gets the FMap's contexts of the main map in the view.
|
86 |
*
|
87 |
* @return
|
88 |
*/
|
89 |
public FMap getMapContext() {
|
90 |
return mapContext;
|
91 |
} |
92 |
|
93 |
/**
|
94 |
* Gets the FMap's context from the locator, which is the
|
95 |
* small map in the left-bottom corner of the View.
|
96 |
*
|
97 |
* @return
|
98 |
*/
|
99 |
public FMap getMapOverViewContext() {
|
100 |
return mapOverViewContext;
|
101 |
} |
102 |
|
103 |
/**
|
104 |
* Crea una ProjectView, que es el modelo que hay detr?s de una vista.
|
105 |
*
|
106 |
* @param viewName
|
107 |
*
|
108 |
* @return
|
109 |
*/
|
110 |
public static ProjectView createView(String viewName) { |
111 |
ProjectView v = new ProjectView();
|
112 |
v.mapContext = new FMap(new ViewPort(Project.getProjection())); |
113 |
v.mapOverViewContext = new FMap(null); |
114 |
v.mapOverViewContext.setProjection(v.mapContext.getProjection()); |
115 |
|
116 |
//v.mapOverViewContext = null;
|
117 |
v.setName(viewName); |
118 |
v.setCreationDate(DateFormat.getInstance().format(new Date())); |
119 |
|
120 |
return v;
|
121 |
} |
122 |
|
123 |
/**
|
124 |
* @see com.iver.cit.gvsig.project.ProjectView#setMapContext(com.iver.cit.gvsig.fmap.FMap)
|
125 |
*/
|
126 |
public void setMapContext(FMap fmap) { |
127 |
mapContext = fmap; |
128 |
fmap.addErrorListener(this);
|
129 |
} |
130 |
|
131 |
/**
|
132 |
* DOCUMENT ME!
|
133 |
*
|
134 |
* @param fmap DOCUMENT ME!
|
135 |
*/
|
136 |
public void setMapOverViewContext(FMap fmap) { |
137 |
mapOverViewContext = fmap; |
138 |
mapOverViewContext.setProjection(mapContext.getProjection()); |
139 |
} |
140 |
|
141 |
/**
|
142 |
* DOCUMENT ME!
|
143 |
*
|
144 |
* @return DOCUMENT ME!
|
145 |
* @throws XMLException
|
146 |
* @throws SaveException
|
147 |
*/
|
148 |
public XMLEntity getXMLEntity() throws SaveException { |
149 |
XMLEntity xml = super.getXMLEntity();
|
150 |
//xml.putProperty("nameClass", this.getClass().getName());
|
151 |
try{
|
152 |
xml.putProperty("numViews", numViews);
|
153 |
xml.putProperty("m_selectedField", m_selectedField);
|
154 |
xml.putProperty("m_typeLink", m_typeLink);
|
155 |
xml.putProperty("m_extLink", m_extLink);
|
156 |
xml.addChild(mapContext.getXMLEntity()); |
157 |
|
158 |
if (mapOverViewContext != null) { |
159 |
if (mapOverViewContext.getViewPort() != null) { |
160 |
xml.putProperty("mapOverView", true); |
161 |
xml.addChild(mapOverViewContext.getXMLEntity()); |
162 |
} else {
|
163 |
xml.putProperty("mapOverView", false); |
164 |
} |
165 |
} else {
|
166 |
xml.putProperty("mapOverView", false); |
167 |
} |
168 |
XMLEntity viewProperties = this.getViewInfoXMLEntity();
|
169 |
if (viewProperties!=null) { //store the properties of the window |
170 |
xml.addChild(viewProperties); |
171 |
} |
172 |
}catch (Exception e) { |
173 |
throw new SaveException(e,this.getClass().getName()); |
174 |
} |
175 |
return xml;
|
176 |
} |
177 |
|
178 |
/**
|
179 |
* DOCUMENT ME!
|
180 |
*
|
181 |
* @param xml DOCUMENT ME!
|
182 |
* @param p DOCUMENT ME!
|
183 |
* @throws XMLException
|
184 |
* @throws DriverException
|
185 |
* @throws DriverIOException
|
186 |
*
|
187 |
* @see com.iver.cit.gvsig.project.ProjectElement#setXMLEntity(com.iver.utiles.XMLEntity)
|
188 |
*/
|
189 |
public void setXMLEntity03(XMLEntity xml, Project p) |
190 |
throws XMLException, DriverException, DriverIOException {
|
191 |
numViews = xml.getIntProperty("numViews");
|
192 |
m_selectedField = xml.getStringProperty("m_selectedField");
|
193 |
m_typeLink = xml.getIntProperty("m_typeLink");
|
194 |
m_extLink = xml.getStringProperty("m_extLink");
|
195 |
setMapContext(FMap.createFromXML03(xml.getChild(0)));
|
196 |
|
197 |
if (xml.getBooleanProperty("mapOverView")) { |
198 |
setMapOverViewContext(FMap.createFromXML03(xml.getChild(1)));
|
199 |
} |
200 |
|
201 |
} |
202 |
|
203 |
/**
|
204 |
* DOCUMENT ME!
|
205 |
*
|
206 |
* @param xml DOCUMENT ME!
|
207 |
* @param p DOCUMENT ME!
|
208 |
* @throws XMLException
|
209 |
* @throws DriverException
|
210 |
* @throws DriverIOException
|
211 |
* @throws OpenException
|
212 |
*
|
213 |
* @see com.iver.cit.gvsig.project.ProjectElement#setXMLEntity(com.iver.utiles.XMLEntity)
|
214 |
*/
|
215 |
public void setXMLEntity(XMLEntity xml, Project p) |
216 |
throws XMLException, DriverException, DriverIOException, OpenException {
|
217 |
try{
|
218 |
int currentChild=0; |
219 |
numViews = xml.getIntProperty("numViews");
|
220 |
m_selectedField = xml.getStringProperty("m_selectedField");
|
221 |
m_typeLink = xml.getIntProperty("m_typeLink");
|
222 |
m_extLink = xml.getStringProperty("m_extLink");
|
223 |
|
224 |
setMapContext(FMap.createFromXML(xml.getChild(currentChild))); |
225 |
currentChild++; |
226 |
if (xml.getBooleanProperty("mapOverView")) { |
227 |
setMapOverViewContext(FMap.createFromXML(xml.getChild(currentChild))); |
228 |
currentChild++; |
229 |
} |
230 |
if (currentChild<xml.getChildrenCount()) {
|
231 |
XMLEntity child = xml.getChild(currentChild); |
232 |
if (child.contains("className") && child.getStringProperty("className").equals(this.getClass().getName()) && child.contains("name") && child.getStringProperty("name").equals("ViewInfoProperties")) { |
233 |
seedViewInfo = createViewInfoFromXMLEntity(child); |
234 |
//currentChild++;
|
235 |
} |
236 |
} |
237 |
showErrors(); |
238 |
}catch (Exception e) { |
239 |
throw new OpenException(e,this.getClass().getName()); |
240 |
} |
241 |
} |
242 |
|
243 |
public void showErrors(){ |
244 |
if (mapContext.getLayersError().size()>0){ |
245 |
String layersError=""; |
246 |
for (int i=0;i<mapContext.getLayersError().size();i++){ |
247 |
layersError=layersError+"\n"+(String)mapContext.getLayersError().get(i); |
248 |
} |
249 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), |
250 |
PluginServices.getText(this,"fallo_capas")+" : \n"+ |
251 |
layersError); |
252 |
} |
253 |
} |
254 |
/**
|
255 |
* DOCUMENT ME!
|
256 |
*
|
257 |
* @param p DOCUMENT ME!
|
258 |
*
|
259 |
* @return DOCUMENT ME!
|
260 |
* @throws XMLException
|
261 |
* @throws DriverException
|
262 |
* @throws DriverIOException
|
263 |
* @throws OpenException
|
264 |
*/
|
265 |
/*public ProjectView cloneProjectView(Project p)
|
266 |
throws XMLException, DriverException, DriverIOException, OpenException {
|
267 |
return (ProjectView) createFromXML(getXMLEntity(), p);
|
268 |
}
|
269 |
*/
|
270 |
/**
|
271 |
* DOCUMENT ME!
|
272 |
*
|
273 |
* @return DOCUMENT ME!
|
274 |
*/
|
275 |
public IProjection getProjection() {
|
276 |
return mapContext.getProjection();
|
277 |
} |
278 |
|
279 |
/**
|
280 |
* DOCUMENT ME!
|
281 |
*
|
282 |
* @return DOCUMENT ME!
|
283 |
*/
|
284 |
public IProjection getOverViewProjection() {
|
285 |
return mapOverViewContext.getProjection();
|
286 |
} |
287 |
|
288 |
public void setProjection (IProjection proj) { |
289 |
mapContext.setProjection(proj); |
290 |
mapOverViewContext.setProjection(proj); |
291 |
} |
292 |
|
293 |
/**
|
294 |
* DOCUMENT ME!
|
295 |
*
|
296 |
* @return DOCUMENT ME!
|
297 |
*/
|
298 |
public String getExtLink() { |
299 |
return m_extLink;
|
300 |
} |
301 |
|
302 |
/**
|
303 |
* DOCUMENT ME!
|
304 |
*
|
305 |
* @return DOCUMENT ME!
|
306 |
*/
|
307 |
public int getTypeLink() { |
308 |
return m_typeLink;
|
309 |
} |
310 |
|
311 |
/**
|
312 |
* Se selecciona la extensi?n para realizar cuando se quiera el link.
|
313 |
*
|
314 |
* @param s nombre del campo.
|
315 |
*/
|
316 |
public void setExtLink(String s) { |
317 |
m_extLink = s; |
318 |
} |
319 |
|
320 |
/**
|
321 |
* Se selecciona el tipo de fichero para realizar cuando se quiera el link.
|
322 |
*
|
323 |
* @param i tipo de fichero.
|
324 |
*/
|
325 |
public void setTypeLink(int i) { |
326 |
m_typeLink = i; |
327 |
} |
328 |
|
329 |
/**
|
330 |
* DOCUMENT ME!
|
331 |
*
|
332 |
* @param c DOCUMENT ME!
|
333 |
*/
|
334 |
public void setBackColor(Color c) { |
335 |
// getMapContext().getViewPort().addViewPortListener(getMapContext()
|
336 |
// .getEventBuffer());
|
337 |
getMapContext().getViewPort().setBackColor(c); |
338 |
//getMapContext().getViewPort().removeViewPortListener(getMapContext()
|
339 |
// .getEventBuffer());
|
340 |
} |
341 |
|
342 |
/**
|
343 |
* Se selecciona el nombre del campo para realizar cuando se quiera el
|
344 |
* link.
|
345 |
*
|
346 |
* @param s nombre del campo.
|
347 |
*/
|
348 |
public void setSelectedField(String s) { |
349 |
m_selectedField = s; |
350 |
} |
351 |
|
352 |
/**
|
353 |
* DOCUMENT ME!
|
354 |
*
|
355 |
* @return DOCUMENT ME!
|
356 |
*/
|
357 |
public String getSelectedField() { |
358 |
return m_selectedField;
|
359 |
} |
360 |
|
361 |
public void errorThrown(ErrorEvent e) { |
362 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), |
363 |
PluginServices.getText(this,"fallo_capas")+" : \n"+ |
364 |
e.getMessage()); |
365 |
|
366 |
} |
367 |
} |