svn-gvsig-desktop / branches / v2_0_0_prep / applications / appgvSIG / src / org / gvsig / app / project / documents / view / BaseViewDocument.java @ 36443
History | View | Annotate | Download (7.81 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 |
|
42 |
import org.gvsig.andami.PluginServices; |
43 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
44 |
import org.gvsig.andami.ui.mdiManager.WindowInfo; |
45 |
import org.gvsig.app.project.documents.AbstractDocument; |
46 |
import org.gvsig.app.project.documents.DocumentManager; |
47 |
import org.gvsig.app.project.documents.view.info.gui.HTMLInfoToolPanel; |
48 |
import org.gvsig.fmap.mapcontext.MapContext; |
49 |
import org.gvsig.fmap.mapcontext.events.ErrorEvent; |
50 |
import org.gvsig.fmap.mapcontext.events.listeners.ErrorListener; |
51 |
import org.gvsig.fmap.mapcontext.layers.CancelationException; |
52 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
53 |
import org.gvsig.fmap.mapcontext.layers.FLayers; |
54 |
import org.gvsig.tools.exception.BaseException; |
55 |
import org.gvsig.tools.persistence.PersistentState; |
56 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
57 |
|
58 |
/**
|
59 |
*
|
60 |
* @author 2005- Vicente Caballero
|
61 |
* @author 2009- Joaquin del Cerro
|
62 |
*
|
63 |
*/
|
64 |
|
65 |
public abstract class BaseViewDocument extends AbstractDocument implements ErrorListener, |
66 |
ViewDocument { |
67 |
|
68 |
/**
|
69 |
*
|
70 |
*/
|
71 |
private static final long serialVersionUID = -2621709089720665902L; |
72 |
|
73 |
public static final String PERSISTENCE_DEFINITION_NAME = "BaseViewDocument"; |
74 |
|
75 |
protected MapContext mapOverViewContext;
|
76 |
protected MapContext mapContext;
|
77 |
|
78 |
public BaseViewDocument() {
|
79 |
super();
|
80 |
} |
81 |
|
82 |
public BaseViewDocument(DocumentManager factory) {
|
83 |
super(factory);
|
84 |
} |
85 |
|
86 |
/**
|
87 |
* Gets the MapContext of the main map in the view.
|
88 |
*
|
89 |
* @return the main MapContext
|
90 |
*/
|
91 |
public MapContext getMapContext() {
|
92 |
return mapContext;
|
93 |
} |
94 |
|
95 |
/**
|
96 |
* Gets the MapContext from the locator, which is the
|
97 |
* small map in the left-bottom corner of the View.
|
98 |
*
|
99 |
* @return the locator MapContext
|
100 |
*/
|
101 |
public MapContext getMapOverViewContext() {
|
102 |
return mapOverViewContext;
|
103 |
} |
104 |
|
105 |
public void setMapContext(MapContext fmap) { |
106 |
mapContext = fmap; |
107 |
fmap.addErrorListener(this);
|
108 |
} |
109 |
|
110 |
public void setMapOverViewContext(MapContext fmap) { |
111 |
mapOverViewContext = fmap; |
112 |
mapOverViewContext.setProjection(mapContext.getProjection()); |
113 |
} |
114 |
|
115 |
public void showErrors(){ |
116 |
if (mapContext.getLayersError().size()>0){ |
117 |
String layersError=""; |
118 |
for (int i=0;i<mapContext.getLayersError().size();i++){ |
119 |
layersError=layersError+"\n"+(String)mapContext.getLayersError().get(i); |
120 |
} |
121 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), |
122 |
PluginServices.getText(this,"fallo_capas")+" : \n"+ |
123 |
layersError); |
124 |
} |
125 |
} |
126 |
|
127 |
/**
|
128 |
* Reports to the user a bundle of driver exceptions produced in the
|
129 |
* same atomic MapContext transaction
|
130 |
*/
|
131 |
@SuppressWarnings("rawtypes") |
132 |
public void reportDriverExceptions(String introductoryText, List driverExceptions) { |
133 |
HtmlWindow htmlPanel = new HtmlWindow(570, 600, PluginServices.getText(this,"driver_error")); |
134 |
String htmlText = ""; |
135 |
if(introductoryText == null){ |
136 |
htmlText += "<h2 text=\"#000080\">"+PluginServices.getText(this,"se_han_producido_los_siguientes_errores_durante_la_carga_de_las_capas")+"</h2>"; |
137 |
}else{
|
138 |
htmlText += introductoryText; |
139 |
} |
140 |
int numErrors = driverExceptions.size();
|
141 |
for(int i = 0; i < numErrors; i++){ |
142 |
//htmlText += "<br>\n";
|
143 |
BaseException exception = (BaseException) driverExceptions.get(i); |
144 |
htmlText +="<p text=\"#550080\">_________________________________________________________________________________________</p>";
|
145 |
htmlText += "<h3>"+PluginServices.getText(this,exception.getMessageKey())+"</h3>"; |
146 |
htmlText += "<p>"+exception.getMessage()+"</p>"; |
147 |
htmlText +="<p text=\"#550080\">_________________________________________________________________________________________</p>";
|
148 |
} |
149 |
|
150 |
System.out.println(htmlText);
|
151 |
htmlPanel.show(htmlText); |
152 |
|
153 |
PluginServices.getMDIManager().addCentredWindow(htmlPanel); |
154 |
|
155 |
} |
156 |
|
157 |
/**
|
158 |
* HtmlInfoToolPanel that implements IWindow
|
159 |
* @author azabala
|
160 |
*
|
161 |
*/
|
162 |
class HtmlWindow extends JPanel implements IWindow { |
163 |
/**
|
164 |
*
|
165 |
*/
|
166 |
private static final long serialVersionUID = 1151465547277478664L; |
167 |
|
168 |
private HTMLInfoToolPanel htmlPanel=new HTMLInfoToolPanel(); |
169 |
WindowInfo viewInfo = null;
|
170 |
public HtmlWindow(int width, int height, String windowTitle){ |
171 |
htmlPanel.setBackground(Color.white);
|
172 |
JScrollPane scrollPane=new JScrollPane(htmlPanel); |
173 |
scrollPane.setPreferredSize(new Dimension(width-30,height-30)); |
174 |
this.add(scrollPane);
|
175 |
viewInfo = new WindowInfo(WindowInfo.MODELESSDIALOG);
|
176 |
viewInfo.setTitle(windowTitle); |
177 |
viewInfo.setWidth(width); |
178 |
viewInfo.setHeight(height); |
179 |
} |
180 |
|
181 |
public void show(String htmlText) { |
182 |
htmlPanel.show(htmlText); |
183 |
} |
184 |
|
185 |
public WindowInfo getWindowInfo() {
|
186 |
return viewInfo;
|
187 |
} |
188 |
public Object getWindowProfile() { |
189 |
return WindowInfo.PROPERTIES_PROFILE;
|
190 |
} |
191 |
|
192 |
} |
193 |
|
194 |
public IProjection getProjection() {
|
195 |
return mapContext.getProjection();
|
196 |
} |
197 |
|
198 |
public void setProjection (IProjection proj) { |
199 |
mapContext.setProjection(proj); |
200 |
mapOverViewContext.setProjection(proj); |
201 |
} |
202 |
|
203 |
public IProjection getOverViewProjection() {
|
204 |
return mapOverViewContext.getProjection();
|
205 |
} |
206 |
|
207 |
public void afterRemove() { |
208 |
// FIXME: Parece que no recorre correctamente el arbol de capas
|
209 |
|
210 |
FLayers layers=this.getMapContext().getLayers();
|
211 |
|
212 |
for (int i = layers.getLayersCount()-1; i>=0; i--){ |
213 |
try {
|
214 |
layers.getLayer(i).getParentLayer().removeLayer(layers.getLayer(i)); |
215 |
} catch (CancelationException e1) {
|
216 |
e1.printStackTrace(); |
217 |
} |
218 |
} |
219 |
getMapContext().dispose(); |
220 |
getMapOverViewContext().dispose(); |
221 |
} |
222 |
|
223 |
public void afterAdd() { |
224 |
// Do nothing
|
225 |
} |
226 |
|
227 |
|
228 |
public void setBackColor(Color c) { |
229 |
getMapContext().getViewPort().setBackColor(c); |
230 |
} |
231 |
|
232 |
public void errorThrown(ErrorEvent e) { |
233 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), |
234 |
PluginServices.getText(this,"fallo_capas")+" : \n"+ |
235 |
e.getMessage()); |
236 |
|
237 |
} |
238 |
|
239 |
public boolean isLocked() { |
240 |
if(super.isLocked()) return true; |
241 |
FLayers layers = getMapContext().getLayers(); |
242 |
for(int i=0; i<layers.getLayersCount(); i++){ |
243 |
FLayer layer = layers.getLayer(i); |
244 |
if (layer.isEditing()){
|
245 |
return true; |
246 |
} |
247 |
} |
248 |
return false; |
249 |
} |
250 |
|
251 |
public void saveToState(PersistentState state) throws PersistenceException { |
252 |
super.saveToState(state);
|
253 |
state.set("mainMapContext", this.getMapContext()); |
254 |
if( this.getMapOverViewContext() != null ) { |
255 |
state.set("useMapOverview", true); |
256 |
} else {
|
257 |
state.set("useMapOverview", false); |
258 |
} |
259 |
state.set("overviewMapContext", this.getMapOverViewContext()); |
260 |
} |
261 |
|
262 |
public void loadFromState(PersistentState state) throws PersistenceException { |
263 |
super.loadFromState(state);
|
264 |
this.mapContext = (MapContext) state.get("mainMapContext"); |
265 |
if( state.getBoolean("useMapOverview") ) { |
266 |
this.mapOverViewContext = (MapContext) state.get("overviewMapContext"); |
267 |
} else {
|
268 |
this.mapOverViewContext = null; |
269 |
} |
270 |
} |
271 |
|
272 |
} |