svn-gvsig-desktop / branches / v2_0_0_prep / applications / appgvSIG / src / org / gvsig / app / project / documents / view / BaseViewDocument.java @ 33275
History | View | Annotate | Download (10.8 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2009 Infrastructures and Transports Department
|
4 |
* of the Valencian Government (CIT)
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 2
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
*/
|
22 |
|
23 |
/*
|
24 |
* AUTHORS (In addition to CIT):
|
25 |
* 2004-2009 IVER TI
|
26 |
*
|
27 |
*/
|
28 |
|
29 |
package org.gvsig.app.project.documents.view; |
30 |
|
31 |
import java.awt.Color; |
32 |
import java.awt.Component; |
33 |
import java.awt.Dimension; |
34 |
import java.util.List; |
35 |
|
36 |
import javax.swing.JOptionPane; |
37 |
import javax.swing.JPanel; |
38 |
import javax.swing.JScrollPane; |
39 |
|
40 |
import org.cresques.cts.IProjection; |
41 |
import org.gvsig.andami.PluginServices; |
42 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
43 |
import org.gvsig.andami.ui.mdiManager.WindowInfo; |
44 |
import org.gvsig.app.extension.ProjectExtension; |
45 |
import org.gvsig.app.project.Project; |
46 |
import org.gvsig.app.project.documents.AbstractDocument; |
47 |
import org.gvsig.app.project.documents.Document; |
48 |
import org.gvsig.app.project.documents.DocumentManager; |
49 |
import org.gvsig.app.project.documents.table.TableDocument; |
50 |
import org.gvsig.app.project.documents.table.TableManager; |
51 |
import org.gvsig.app.project.documents.view.info.gui.HTMLInfoToolPanel; |
52 |
import org.gvsig.fmap.mapcontext.MapContext; |
53 |
import org.gvsig.fmap.mapcontext.events.ErrorEvent; |
54 |
import org.gvsig.fmap.mapcontext.events.listeners.ErrorListener; |
55 |
import org.gvsig.fmap.mapcontext.layers.CancelationException; |
56 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
57 |
import org.gvsig.fmap.mapcontext.layers.FLayers; |
58 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
59 |
import org.gvsig.tools.ToolsLocator; |
60 |
import org.gvsig.tools.dynobject.DynStruct; |
61 |
import org.gvsig.tools.exception.BaseException; |
62 |
import org.gvsig.tools.persistence.PersistenceManager; |
63 |
import org.gvsig.tools.persistence.PersistentState; |
64 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
65 |
|
66 |
/**
|
67 |
*
|
68 |
* @author 2005- Vicente Caballero
|
69 |
* @author 2009- Joaquin del Cerro
|
70 |
*
|
71 |
*/
|
72 |
|
73 |
public abstract class BaseViewDocument extends AbstractDocument implements ErrorListener, |
74 |
ViewDocument { |
75 |
|
76 |
/**
|
77 |
*
|
78 |
*/
|
79 |
private static final long serialVersionUID = -2621709089720665902L; |
80 |
|
81 |
public static final String PERSISTENCE_DEFINITION_NAME = "BaseViewDocument"; |
82 |
|
83 |
protected MapContext mapOverViewContext;
|
84 |
protected MapContext mapContext;
|
85 |
|
86 |
// protected int m_typeLink = LinkListener.TYPELINKIMAGE;
|
87 |
// protected String m_extLink;
|
88 |
// protected String m_selectedField = null;
|
89 |
|
90 |
public BaseViewDocument() {
|
91 |
super();
|
92 |
} |
93 |
|
94 |
public BaseViewDocument(DocumentManager factory) {
|
95 |
super(factory);
|
96 |
} |
97 |
|
98 |
/**
|
99 |
* Gets the MapContext of the main map in the view.
|
100 |
*
|
101 |
* @return the main MapContext
|
102 |
*/
|
103 |
public MapContext getMapContext() {
|
104 |
return mapContext;
|
105 |
} |
106 |
|
107 |
/**
|
108 |
* Gets the MapContext from the locator, which is the
|
109 |
* small map in the left-bottom corner of the View.
|
110 |
*
|
111 |
* @return the locator MapContext
|
112 |
*/
|
113 |
public MapContext getMapOverViewContext() {
|
114 |
return mapOverViewContext;
|
115 |
} |
116 |
|
117 |
public void setMapContext(MapContext fmap) { |
118 |
mapContext = fmap; |
119 |
fmap.addErrorListener(this);
|
120 |
} |
121 |
|
122 |
public void setMapOverViewContext(MapContext fmap) { |
123 |
mapOverViewContext = fmap; |
124 |
mapOverViewContext.setProjection(mapContext.getProjection()); |
125 |
} |
126 |
|
127 |
public void showErrors(){ |
128 |
if (mapContext.getLayersError().size()>0){ |
129 |
String layersError=""; |
130 |
for (int i=0;i<mapContext.getLayersError().size();i++){ |
131 |
layersError=layersError+"\n"+(String)mapContext.getLayersError().get(i); |
132 |
} |
133 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), |
134 |
PluginServices.getText(this,"fallo_capas")+" : \n"+ |
135 |
layersError); |
136 |
} |
137 |
} |
138 |
|
139 |
/**
|
140 |
* Reports to the user a bundle of driver exceptions produced in the
|
141 |
* same atomic MapContext transaction
|
142 |
*/
|
143 |
@SuppressWarnings("rawtypes") |
144 |
public void reportDriverExceptions(String introductoryText, List driverExceptions) { |
145 |
HtmlWindow htmlPanel = new HtmlWindow(570, 600, PluginServices.getText(this,"driver_error")); |
146 |
String htmlText = ""; |
147 |
if(introductoryText == null){ |
148 |
htmlText += "<h2 text=\"#000080\">"+PluginServices.getText(this,"se_han_producido_los_siguientes_errores_durante_la_carga_de_las_capas")+"</h2>"; |
149 |
}else{
|
150 |
htmlText += introductoryText; |
151 |
} |
152 |
int numErrors = driverExceptions.size();
|
153 |
for(int i = 0; i < numErrors; i++){ |
154 |
//htmlText += "<br>\n";
|
155 |
BaseException exception = (BaseException) driverExceptions.get(i); |
156 |
htmlText +="<p text=\"#550080\">_________________________________________________________________________________________</p>";
|
157 |
htmlText += "<h3>"+PluginServices.getText(this,exception.getMessageKey())+"</h3>"; |
158 |
htmlText += "<p>"+exception.getMessage()+"</p>"; |
159 |
htmlText +="<p text=\"#550080\">_________________________________________________________________________________________</p>";
|
160 |
} |
161 |
|
162 |
System.out.println(htmlText);
|
163 |
htmlPanel.show(htmlText); |
164 |
|
165 |
PluginServices.getMDIManager().addCentredWindow(htmlPanel); |
166 |
|
167 |
} |
168 |
|
169 |
/**
|
170 |
* HtmlInfoToolPanel that implements IWindow
|
171 |
* @author azabala
|
172 |
*
|
173 |
*/
|
174 |
class HtmlWindow extends JPanel implements IWindow { |
175 |
/**
|
176 |
*
|
177 |
*/
|
178 |
private static final long serialVersionUID = 1151465547277478664L; |
179 |
|
180 |
private HTMLInfoToolPanel htmlPanel=new HTMLInfoToolPanel(); |
181 |
WindowInfo viewInfo = null;
|
182 |
public HtmlWindow(int width, int height, String windowTitle){ |
183 |
htmlPanel.setBackground(Color.white);
|
184 |
JScrollPane scrollPane=new JScrollPane(htmlPanel); |
185 |
scrollPane.setPreferredSize(new Dimension(width-30,height-30)); |
186 |
this.add(scrollPane);
|
187 |
viewInfo = new WindowInfo(WindowInfo.MODELESSDIALOG);
|
188 |
viewInfo.setTitle(windowTitle); |
189 |
viewInfo.setWidth(width); |
190 |
viewInfo.setHeight(height); |
191 |
} |
192 |
|
193 |
public void show(String htmlText) { |
194 |
htmlPanel.show(htmlText); |
195 |
} |
196 |
|
197 |
public WindowInfo getWindowInfo() {
|
198 |
return viewInfo;
|
199 |
} |
200 |
public Object getWindowProfile() { |
201 |
return WindowInfo.PROPERTIES_PROFILE;
|
202 |
} |
203 |
|
204 |
} |
205 |
|
206 |
public IProjection getProjection() {
|
207 |
return mapContext.getProjection();
|
208 |
} |
209 |
|
210 |
public void setProjection (IProjection proj) { |
211 |
mapContext.setProjection(proj); |
212 |
mapOverViewContext.setProjection(proj); |
213 |
} |
214 |
|
215 |
public IProjection getOverViewProjection() {
|
216 |
return mapOverViewContext.getProjection();
|
217 |
} |
218 |
|
219 |
// public String getExtLink() {
|
220 |
// return m_extLink;
|
221 |
// }
|
222 |
//
|
223 |
// public int getTypeLink() {
|
224 |
// return m_typeLink;
|
225 |
// }
|
226 |
//
|
227 |
// /**
|
228 |
// * Se selecciona la extensi?n para realizar cuando se quiera el link.
|
229 |
// *
|
230 |
// * @param s nombre del campo.
|
231 |
// */
|
232 |
// public void setExtLink(String s) {
|
233 |
// m_extLink = s;
|
234 |
// }
|
235 |
//
|
236 |
// /**
|
237 |
// * Se selecciona el tipo de fichero para realizar cuando se quiera el link.
|
238 |
// *
|
239 |
// * @param i tipo de fichero.
|
240 |
// */
|
241 |
// public void setTypeLink(int i) {
|
242 |
// m_typeLink = i;
|
243 |
// }
|
244 |
|
245 |
public void afterRemove() { |
246 |
// FIXME: Parece que no recorre correctamente el arbol de capas
|
247 |
|
248 |
FLayers layers=this.getMapContext().getLayers();
|
249 |
|
250 |
for (int i = layers.getLayersCount()-1; i>=0; i--){ |
251 |
try {
|
252 |
if (layers.getLayer(i) instanceof FLyrVect){ |
253 |
Project project = ((ProjectExtension)PluginServices.getExtension(ProjectExtension.class)).getProject(); |
254 |
TableDocument pt = project.getTable((FLyrVect) layers.getLayer(i)); |
255 |
|
256 |
List<Document> tables = project.getDocuments(TableManager.TYPENAME); |
257 |
for (int j = 0; j < tables.size(); j++) { |
258 |
if (tables.get(j) == pt){
|
259 |
project.remove(tables.get(j)); |
260 |
break;
|
261 |
} |
262 |
} |
263 |
|
264 |
PluginServices.getMDIManager().closeSingletonWindow(pt); |
265 |
} |
266 |
layers.getLayer(i).getParentLayer().removeLayer(layers.getLayer(i)); |
267 |
} catch (CancelationException e1) {
|
268 |
e1.printStackTrace(); |
269 |
} |
270 |
} |
271 |
getMapContext().dispose(); |
272 |
getMapOverViewContext().dispose(); |
273 |
} |
274 |
|
275 |
public void afterAdd() { |
276 |
// Do nothing
|
277 |
} |
278 |
|
279 |
|
280 |
public void setBackColor(Color c) { |
281 |
getMapContext().getViewPort().setBackColor(c); |
282 |
} |
283 |
|
284 |
// /**
|
285 |
// * Se selecciona el nombre del campo para realizar cuando se quiera el
|
286 |
// * link.
|
287 |
// *
|
288 |
// * @param s nombre del campo.
|
289 |
// */
|
290 |
// public void setSelectedField(String s) {
|
291 |
// m_selectedField = s;
|
292 |
// }
|
293 |
//
|
294 |
// public String getSelectedField() {
|
295 |
// return m_selectedField;
|
296 |
// }
|
297 |
|
298 |
public void errorThrown(ErrorEvent e) { |
299 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), |
300 |
PluginServices.getText(this,"fallo_capas")+" : \n"+ |
301 |
e.getMessage()); |
302 |
|
303 |
} |
304 |
|
305 |
public boolean isLocked() { |
306 |
if(super.isLocked()) return true; |
307 |
FLayers layers = getMapContext().getLayers(); |
308 |
for(int i=0; i<layers.getLayersCount(); i++){ |
309 |
FLayer layer = layers.getLayer(i); |
310 |
if (layer.isEditing()){
|
311 |
return true; |
312 |
} |
313 |
} |
314 |
return false; |
315 |
} |
316 |
|
317 |
public void saveToState(PersistentState state) throws PersistenceException { |
318 |
super.saveToState(state);
|
319 |
// state.set("linkType", this.getTypeLink());
|
320 |
// state.set("linkExtension",this.getExtLink());
|
321 |
// state.set("selectedField", this.getSelectedField());
|
322 |
state.set("mainMapContext", this.getMapContext()); |
323 |
if( this.getMapOverViewContext() != null ) { |
324 |
state.set("useMapOverview", true); |
325 |
} else {
|
326 |
state.set("useMapOverview", false); |
327 |
} |
328 |
state.set("overviewMapContext", this.getMapOverViewContext()); |
329 |
} |
330 |
|
331 |
public void loadFromState(PersistentState state) throws PersistenceException { |
332 |
super.loadFromState(state);
|
333 |
// this.setTypeLink( state.getInt("linkType"));
|
334 |
// this.setExtLink(state.getString("linkExtension"));
|
335 |
// this.setSelectedField(state.getString("selectedField"));
|
336 |
|
337 |
this.mapContext = (MapContext) state.get("mainMapContext"); |
338 |
if( state.getBoolean("useMapOverview") ) { |
339 |
this.mapOverViewContext = (MapContext) state.get("overviewMapContext"); |
340 |
} else {
|
341 |
this.mapOverViewContext = null; |
342 |
} |
343 |
} |
344 |
|
345 |
public static void registerPersistent() { |
346 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
347 |
DynStruct definition = manager.addDefinition( |
348 |
BaseViewDocument.class, |
349 |
PERSISTENCE_DEFINITION_NAME, |
350 |
"Base view document persistence definition",
|
351 |
null,
|
352 |
null
|
353 |
); |
354 |
definition.extend(manager.getDefinition(AbstractDocument.PERSISTENCE_DEFINITION_NAME));
|
355 |
|
356 |
definition.addDynFieldBoolean("useMapOverview").setMandatory(true); |
357 |
definition.addDynFieldObject("mainMapContext").setClassOfValue(MapContext.class).setMandatory(true); |
358 |
definition.addDynFieldObject("overviewMapContext").setClassOfValue(MapContext.class).setMandatory(false); |
359 |
} |
360 |
|
361 |
} |