root / branches / v2_0_0_prep / applications / appgvSIG / src / org / gvsig / app / project / documents / view / BaseViewDocument.java @ 31496
History | View | Annotate | Download (9.85 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2009 Infrastructures and Transports Department
|
4 |
* of the Valencian Gobernment (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.Document; |
47 |
import org.gvsig.app.project.documents.DocumentManager; |
48 |
import org.gvsig.app.project.documents.AbstractDocument; |
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.app.project.documents.view.toolListeners.LinkListener; |
53 |
import org.gvsig.fmap.mapcontext.MapContext; |
54 |
import org.gvsig.fmap.mapcontext.events.ErrorEvent; |
55 |
import org.gvsig.fmap.mapcontext.events.listeners.ErrorListener; |
56 |
import org.gvsig.fmap.mapcontext.layers.CancelationException; |
57 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
58 |
import org.gvsig.fmap.mapcontext.layers.FLayers; |
59 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
60 |
import org.gvsig.tools.exception.BaseException; |
61 |
import org.gvsig.tools.persistence.PersistenceException; |
62 |
import org.gvsig.tools.persistence.PersistentState; |
63 |
|
64 |
/**
|
65 |
*
|
66 |
* @author 2005- Vicente Caballero
|
67 |
* @author 2009- Joaquin del Cerro
|
68 |
*
|
69 |
*/
|
70 |
|
71 |
public abstract class BaseViewDocument extends AbstractDocument implements ErrorListener, |
72 |
ViewDocument { |
73 |
|
74 |
/**
|
75 |
*
|
76 |
*/
|
77 |
private static final long serialVersionUID = -2621709089720665902L; |
78 |
|
79 |
protected MapContext mapOverViewContext;
|
80 |
protected MapContext mapContext;
|
81 |
|
82 |
protected int m_typeLink = LinkListener.TYPELINKIMAGE; |
83 |
protected String m_extLink; |
84 |
protected String m_selectedField = null; |
85 |
|
86 |
public BaseViewDocument() {
|
87 |
super();
|
88 |
} |
89 |
|
90 |
public BaseViewDocument(DocumentManager factory) {
|
91 |
super(factory);
|
92 |
} |
93 |
|
94 |
/**
|
95 |
* Gets the MapContext of the main map in the view.
|
96 |
*
|
97 |
* @return the main MapContext
|
98 |
*/
|
99 |
public MapContext getMapContext() {
|
100 |
return mapContext;
|
101 |
} |
102 |
|
103 |
/**
|
104 |
* Gets the MapContext from the locator, which is the
|
105 |
* small map in the left-bottom corner of the View.
|
106 |
*
|
107 |
* @return the locator MapContext
|
108 |
*/
|
109 |
public MapContext getMapOverViewContext() {
|
110 |
return mapOverViewContext;
|
111 |
} |
112 |
|
113 |
public void setMapContext(MapContext fmap) { |
114 |
mapContext = fmap; |
115 |
fmap.addErrorListener(this);
|
116 |
} |
117 |
|
118 |
public void setMapOverViewContext(MapContext fmap) { |
119 |
mapOverViewContext = fmap; |
120 |
mapOverViewContext.setProjection(mapContext.getProjection()); |
121 |
} |
122 |
|
123 |
public void showErrors(){ |
124 |
if (mapContext.getLayersError().size()>0){ |
125 |
String layersError=""; |
126 |
for (int i=0;i<mapContext.getLayersError().size();i++){ |
127 |
layersError=layersError+"\n"+(String)mapContext.getLayersError().get(i); |
128 |
} |
129 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), |
130 |
PluginServices.getText(this,"fallo_capas")+" : \n"+ |
131 |
layersError); |
132 |
} |
133 |
} |
134 |
|
135 |
/**
|
136 |
* Reports to the user a bundle of driver exceptions produced in the
|
137 |
* same atomic MapContext transaction
|
138 |
*/
|
139 |
@SuppressWarnings("unchecked") |
140 |
public void reportDriverExceptions(String introductoryText, List driverExceptions) { |
141 |
HtmlWindow htmlPanel = new HtmlWindow(570, 600, PluginServices.getText(this,"driver_error")); |
142 |
String htmlText = ""; |
143 |
if(introductoryText == null){ |
144 |
htmlText += "<h2 text=\"#000080\">"+PluginServices.getText(this,"se_han_producido_los_siguientes_errores_durante_la_carga_de_las_capas")+"</h2>"; |
145 |
}else{
|
146 |
htmlText += introductoryText; |
147 |
} |
148 |
int numErrors = driverExceptions.size();
|
149 |
for(int i = 0; i < numErrors; i++){ |
150 |
//htmlText += "<br>\n";
|
151 |
BaseException exception = (BaseException) driverExceptions.get(i); |
152 |
htmlText +="<p text=\"#550080\">_________________________________________________________________________________________</p>";
|
153 |
htmlText += "<h3>"+PluginServices.getText(this,exception.getMessageKey())+"</h3>"; |
154 |
htmlText += "<p>"+exception.getMessage()+"</p>"; |
155 |
htmlText +="<p text=\"#550080\">_________________________________________________________________________________________</p>";
|
156 |
} |
157 |
|
158 |
System.out.println(htmlText);
|
159 |
htmlPanel.show(htmlText); |
160 |
|
161 |
PluginServices.getMDIManager().addCentredWindow(htmlPanel); |
162 |
|
163 |
} |
164 |
|
165 |
/**
|
166 |
* HtmlInfoToolPanel that implements IWindow
|
167 |
* @author azabala
|
168 |
*
|
169 |
*/
|
170 |
class HtmlWindow extends JPanel implements IWindow { |
171 |
/**
|
172 |
*
|
173 |
*/
|
174 |
private static final long serialVersionUID = 1151465547277478664L; |
175 |
|
176 |
private HTMLInfoToolPanel htmlPanel=new HTMLInfoToolPanel(); |
177 |
WindowInfo viewInfo = null;
|
178 |
public HtmlWindow(int width, int height, String windowTitle){ |
179 |
htmlPanel.setBackground(Color.white);
|
180 |
JScrollPane scrollPane=new JScrollPane(htmlPanel); |
181 |
scrollPane.setPreferredSize(new Dimension(width-30,height-30)); |
182 |
this.add(scrollPane);
|
183 |
viewInfo = new WindowInfo(WindowInfo.MODELESSDIALOG);
|
184 |
viewInfo.setTitle(windowTitle); |
185 |
viewInfo.setWidth(width); |
186 |
viewInfo.setHeight(height); |
187 |
} |
188 |
|
189 |
public void show(String htmlText) { |
190 |
htmlPanel.show(htmlText); |
191 |
} |
192 |
|
193 |
public WindowInfo getWindowInfo() {
|
194 |
return viewInfo;
|
195 |
} |
196 |
public Object getWindowProfile() { |
197 |
return WindowInfo.PROPERTIES_PROFILE;
|
198 |
} |
199 |
|
200 |
} |
201 |
|
202 |
public IProjection getProjection() {
|
203 |
return mapContext.getProjection();
|
204 |
} |
205 |
|
206 |
public void setProjection (IProjection proj) { |
207 |
mapContext.setProjection(proj); |
208 |
mapOverViewContext.setProjection(proj); |
209 |
} |
210 |
|
211 |
public IProjection getOverViewProjection() {
|
212 |
return mapOverViewContext.getProjection();
|
213 |
} |
214 |
|
215 |
public String getExtLink() { |
216 |
return m_extLink;
|
217 |
} |
218 |
|
219 |
public int getTypeLink() { |
220 |
return m_typeLink;
|
221 |
} |
222 |
|
223 |
/**
|
224 |
* Se selecciona la extensi?n para realizar cuando se quiera el link.
|
225 |
*
|
226 |
* @param s nombre del campo.
|
227 |
*/
|
228 |
public void setExtLink(String s) { |
229 |
m_extLink = s; |
230 |
} |
231 |
|
232 |
/**
|
233 |
* Se selecciona el tipo de fichero para realizar cuando se quiera el link.
|
234 |
*
|
235 |
* @param i tipo de fichero.
|
236 |
*/
|
237 |
public void setTypeLink(int i) { |
238 |
m_typeLink = i; |
239 |
} |
240 |
|
241 |
public void afterRemove() { |
242 |
// FIXME: Parece que no recorre correctamente el arbol de capas
|
243 |
|
244 |
FLayers layers=this.getMapContext().getLayers();
|
245 |
|
246 |
for (int i = layers.getLayersCount()-1; i>=0; i--){ |
247 |
try {
|
248 |
if (layers.getLayer(i) instanceof FLyrVect){ |
249 |
Project project = ((ProjectExtension)PluginServices.getExtension(ProjectExtension.class)).getProject(); |
250 |
TableDocument pt = project.getTable((FLyrVect) layers.getLayer(i)); |
251 |
|
252 |
List<Document> tables = project.getDocuments(TableManager.TYPENAME); |
253 |
for (int j = 0; j < tables.size(); j++) { |
254 |
if (tables.get(j) == pt){
|
255 |
project.remove(tables.get(j)); |
256 |
break;
|
257 |
} |
258 |
} |
259 |
|
260 |
PluginServices.getMDIManager().closeSingletonWindow(pt); |
261 |
} |
262 |
layers.getLayer(i).getParentLayer().removeLayer(layers.getLayer(i)); |
263 |
} catch (CancelationException e1) {
|
264 |
e1.printStackTrace(); |
265 |
} |
266 |
} |
267 |
getMapContext().dispose(); |
268 |
getMapOverViewContext().dispose(); |
269 |
} |
270 |
|
271 |
public void afterAdd() { |
272 |
// Do nothing
|
273 |
} |
274 |
|
275 |
|
276 |
public void setBackColor(Color c) { |
277 |
getMapContext().getViewPort().setBackColor(c); |
278 |
} |
279 |
|
280 |
/**
|
281 |
* Se selecciona el nombre del campo para realizar cuando se quiera el
|
282 |
* link.
|
283 |
*
|
284 |
* @param s nombre del campo.
|
285 |
*/
|
286 |
public void setSelectedField(String s) { |
287 |
m_selectedField = s; |
288 |
} |
289 |
|
290 |
public String getSelectedField() { |
291 |
return m_selectedField;
|
292 |
} |
293 |
|
294 |
public void errorThrown(ErrorEvent e) { |
295 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), |
296 |
PluginServices.getText(this,"fallo_capas")+" : \n"+ |
297 |
e.getMessage()); |
298 |
|
299 |
} |
300 |
|
301 |
public boolean isLocked() { |
302 |
if(super.isLocked()) return true; |
303 |
FLayers layers = getMapContext().getLayers(); |
304 |
for(int i=0; i<layers.getLayersCount(); i++){ |
305 |
FLayer layer = layers.getLayer(i); |
306 |
if (layer.isEditing()){
|
307 |
return true; |
308 |
} |
309 |
} |
310 |
return false; |
311 |
} |
312 |
|
313 |
public void saveToState(PersistentState state) throws PersistenceException { |
314 |
super.saveToState(state);
|
315 |
state.set("linkType", this.getTypeLink()); |
316 |
state.set("linkExtension",this.getExtLink()); |
317 |
state.set("selectedField", this.getSelectedField()); |
318 |
state.set("mainMapContext", this.getMapContext()); |
319 |
if( this.getMapOverViewContext() != null ) { |
320 |
state.set("useMapOverview", true); |
321 |
} else {
|
322 |
state.set("useMapOverview", false); |
323 |
} |
324 |
state.set("overviewMapContext", this.getMapOverViewContext()); |
325 |
} |
326 |
|
327 |
public void loadFromState(PersistentState state) throws PersistenceException { |
328 |
super.loadFromState(state);
|
329 |
this.setTypeLink( state.getInt("linkType")); |
330 |
this.setExtLink(state.getString("linkExtension")); |
331 |
this.setSelectedField(state.getString("selectedField")); |
332 |
|
333 |
this.mapContext = (MapContext) state.get("mainMapContext"); |
334 |
this.mapOverViewContext = (MapContext) state.get("overviewMapContext"); |
335 |
} |
336 |
|
337 |
} |