svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.app / org.gvsig.app.mainplugin / src / main / java / org / gvsig / app / project / documents / view / BaseViewDocument.java @ 40558
History | View | Annotate | Download (8.75 KB)
1 | 40558 | jjdelcerro | /**
|
---|---|---|---|
2 | * gvSIG. Desktop Geographic Information System.
|
||
3 | *
|
||
4 | * Copyright (C) 2007-2013 gvSIG Association.
|
||
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 3
|
||
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 | * For any additional information, do not hesitate to contact us
|
||
22 | * at info AT gvsig.com, or visit our website www.gvsig.com.
|
||
23 | */
|
||
24 | 40435 | jjdelcerro | /* gvSIG. Geographic Information System of the Valencian Government
|
25 | *
|
||
26 | * Copyright (C) 2007-2009 Infrastructures and Transports Department
|
||
27 | * of the Valencian Government (CIT)
|
||
28 | *
|
||
29 | * This program is free software; you can redistribute it and/or
|
||
30 | * modify it under the terms of the GNU General Public License
|
||
31 | * as published by the Free Software Foundation; either version 2
|
||
32 | * of the License, or (at your option) any later version.
|
||
33 | *
|
||
34 | * This program is distributed in the hope that it will be useful,
|
||
35 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
36 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
37 | * GNU General Public License for more details.
|
||
38 | *
|
||
39 | * You should have received a copy of the GNU General Public License
|
||
40 | * along with this program; if not, write to the Free Software
|
||
41 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||
42 | * MA 02110-1301, USA.
|
||
43 | *
|
||
44 | */
|
||
45 | |||
46 | /*
|
||
47 | * AUTHORS (In addition to CIT):
|
||
48 | * 2004-2009 IVER TI
|
||
49 | *
|
||
50 | */
|
||
51 | |||
52 | package org.gvsig.app.project.documents.view; |
||
53 | |||
54 | import java.awt.Color; |
||
55 | import java.awt.Component; |
||
56 | import java.awt.Dimension; |
||
57 | import java.util.List; |
||
58 | |||
59 | import javax.swing.JOptionPane; |
||
60 | import javax.swing.JPanel; |
||
61 | import javax.swing.JScrollPane; |
||
62 | |||
63 | import org.cresques.cts.IProjection; |
||
64 | |||
65 | import org.gvsig.andami.PluginServices; |
||
66 | import org.gvsig.andami.ui.mdiManager.IWindow; |
||
67 | import org.gvsig.andami.ui.mdiManager.WindowInfo; |
||
68 | import org.gvsig.app.project.documents.AbstractDocument; |
||
69 | import org.gvsig.app.project.documents.DocumentManager; |
||
70 | import org.gvsig.app.project.documents.view.info.gui.HTMLInfoToolPanel; |
||
71 | import org.gvsig.fmap.mapcontext.MapContext; |
||
72 | import org.gvsig.fmap.mapcontext.events.ErrorEvent; |
||
73 | import org.gvsig.fmap.mapcontext.events.listeners.ErrorListener; |
||
74 | import org.gvsig.fmap.mapcontext.layers.CancelationException; |
||
75 | import org.gvsig.fmap.mapcontext.layers.FLayer; |
||
76 | import org.gvsig.fmap.mapcontext.layers.FLayers; |
||
77 | import org.gvsig.tools.exception.BaseException; |
||
78 | import org.gvsig.tools.persistence.PersistentState; |
||
79 | import org.gvsig.tools.persistence.exception.PersistenceException; |
||
80 | |||
81 | /**
|
||
82 | *
|
||
83 | * @author 2005- Vicente Caballero
|
||
84 | * @author 2009- Joaquin del Cerro
|
||
85 | *
|
||
86 | */
|
||
87 | |||
88 | public abstract class BaseViewDocument extends AbstractDocument implements ErrorListener, |
||
89 | ViewDocument { |
||
90 | |||
91 | /**
|
||
92 | *
|
||
93 | */
|
||
94 | private static final long serialVersionUID = -2621709089720665902L; |
||
95 | |||
96 | public static final String PERSISTENCE_DEFINITION_NAME = "BaseViewDocument"; |
||
97 | |||
98 | protected MapContext mapOverViewContext;
|
||
99 | protected MapContext mapContext;
|
||
100 | |||
101 | public BaseViewDocument() {
|
||
102 | super();
|
||
103 | } |
||
104 | |||
105 | public BaseViewDocument(DocumentManager factory) {
|
||
106 | super(factory);
|
||
107 | } |
||
108 | |||
109 | /**
|
||
110 | * Gets the MapContext of the main map in the view.
|
||
111 | *
|
||
112 | * @return the main MapContext
|
||
113 | */
|
||
114 | public MapContext getMapContext() {
|
||
115 | return mapContext;
|
||
116 | } |
||
117 | |||
118 | /**
|
||
119 | * Gets the MapContext from the locator, which is the
|
||
120 | * small map in the left-bottom corner of the View.
|
||
121 | *
|
||
122 | * @return the locator MapContext
|
||
123 | */
|
||
124 | public MapContext getMapOverViewContext() {
|
||
125 | return mapOverViewContext;
|
||
126 | } |
||
127 | |||
128 | public void setMapContext(MapContext fmap) { |
||
129 | mapContext = fmap; |
||
130 | fmap.addErrorListener(this);
|
||
131 | } |
||
132 | |||
133 | public void setMapOverViewContext(MapContext fmap) { |
||
134 | mapOverViewContext = fmap; |
||
135 | mapOverViewContext.setProjection(mapContext.getProjection()); |
||
136 | } |
||
137 | |||
138 | public void showErrors(){ |
||
139 | if (mapContext.getLayersError().size()>0){ |
||
140 | String layersError=""; |
||
141 | for (int i=0;i<mapContext.getLayersError().size();i++){ |
||
142 | layersError=layersError+"\n"+(String)mapContext.getLayersError().get(i); |
||
143 | } |
||
144 | JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), |
||
145 | PluginServices.getText(this,"fallo_capas")+" : \n"+ |
||
146 | layersError); |
||
147 | } |
||
148 | } |
||
149 | |||
150 | /**
|
||
151 | * Reports to the user a bundle of driver exceptions produced in the
|
||
152 | * same atomic MapContext transaction
|
||
153 | */
|
||
154 | @SuppressWarnings("rawtypes") |
||
155 | public void reportDriverExceptions(String introductoryText, List driverExceptions) { |
||
156 | HtmlWindow htmlPanel = new HtmlWindow(570, 600, PluginServices.getText(this,"driver_error")); |
||
157 | String htmlText = ""; |
||
158 | if(introductoryText == null){ |
||
159 | htmlText += "<h2 text=\"#000080\">"+PluginServices.getText(this,"se_han_producido_los_siguientes_errores_durante_la_carga_de_las_capas")+"</h2>"; |
||
160 | }else{
|
||
161 | htmlText += introductoryText; |
||
162 | } |
||
163 | int numErrors = driverExceptions.size();
|
||
164 | for(int i = 0; i < numErrors; i++){ |
||
165 | //htmlText += "<br>\n";
|
||
166 | BaseException exception = (BaseException) driverExceptions.get(i); |
||
167 | htmlText +="<p text=\"#550080\">_________________________________________________________________________________________</p>";
|
||
168 | htmlText += "<h3>"+PluginServices.getText(this,exception.getMessageKey())+"</h3>"; |
||
169 | htmlText += "<p>"+exception.getMessage()+"</p>"; |
||
170 | htmlText +="<p text=\"#550080\">_________________________________________________________________________________________</p>";
|
||
171 | } |
||
172 | |||
173 | System.out.println(htmlText);
|
||
174 | htmlPanel.show(htmlText); |
||
175 | |||
176 | PluginServices.getMDIManager().addCentredWindow(htmlPanel); |
||
177 | |||
178 | } |
||
179 | |||
180 | /**
|
||
181 | * HtmlInfoToolPanel that implements IWindow
|
||
182 | * @author azabala
|
||
183 | *
|
||
184 | */
|
||
185 | class HtmlWindow extends JPanel implements IWindow { |
||
186 | /**
|
||
187 | *
|
||
188 | */
|
||
189 | private static final long serialVersionUID = 1151465547277478664L; |
||
190 | |||
191 | private HTMLInfoToolPanel htmlPanel=new HTMLInfoToolPanel(); |
||
192 | WindowInfo viewInfo = null;
|
||
193 | public HtmlWindow(int width, int height, String windowTitle){ |
||
194 | htmlPanel.setBackground(Color.white);
|
||
195 | JScrollPane scrollPane=new JScrollPane(htmlPanel); |
||
196 | scrollPane.setPreferredSize(new Dimension(width-30,height-30)); |
||
197 | this.add(scrollPane);
|
||
198 | viewInfo = new WindowInfo(WindowInfo.MODELESSDIALOG);
|
||
199 | viewInfo.setTitle(windowTitle); |
||
200 | viewInfo.setWidth(width); |
||
201 | viewInfo.setHeight(height); |
||
202 | } |
||
203 | |||
204 | public void show(String htmlText) { |
||
205 | htmlPanel.show(htmlText); |
||
206 | } |
||
207 | |||
208 | public WindowInfo getWindowInfo() {
|
||
209 | return viewInfo;
|
||
210 | } |
||
211 | public Object getWindowProfile() { |
||
212 | return WindowInfo.PROPERTIES_PROFILE;
|
||
213 | } |
||
214 | |||
215 | } |
||
216 | |||
217 | public IProjection getProjection() {
|
||
218 | return mapContext.getProjection();
|
||
219 | } |
||
220 | |||
221 | public void setProjection (IProjection proj) { |
||
222 | mapContext.setProjection(proj); |
||
223 | mapOverViewContext.setProjection(proj); |
||
224 | } |
||
225 | |||
226 | public IProjection getOverViewProjection() {
|
||
227 | return mapOverViewContext.getProjection();
|
||
228 | } |
||
229 | |||
230 | public void afterRemove() { |
||
231 | // FIXME: Parece que no recorre correctamente el arbol de capas
|
||
232 | |||
233 | FLayers layers=this.getMapContext().getLayers();
|
||
234 | |||
235 | for (int i = layers.getLayersCount()-1; i>=0; i--){ |
||
236 | try {
|
||
237 | layers.getLayer(i).getParentLayer().removeLayer(layers.getLayer(i)); |
||
238 | } catch (CancelationException e1) {
|
||
239 | e1.printStackTrace(); |
||
240 | } |
||
241 | } |
||
242 | getMapContext().dispose(); |
||
243 | getMapOverViewContext().dispose(); |
||
244 | } |
||
245 | |||
246 | public void afterAdd() { |
||
247 | // Do nothing
|
||
248 | } |
||
249 | |||
250 | |||
251 | public void setBackColor(Color c) { |
||
252 | getMapContext().getViewPort().setBackColor(c); |
||
253 | } |
||
254 | |||
255 | public void errorThrown(ErrorEvent e) { |
||
256 | JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), |
||
257 | PluginServices.getText(this,"fallo_capas")+" : \n"+ |
||
258 | e.getMessage()); |
||
259 | |||
260 | } |
||
261 | |||
262 | public boolean isLocked() { |
||
263 | if(super.isLocked()) return true; |
||
264 | FLayers layers = getMapContext().getLayers(); |
||
265 | for(int i=0; i<layers.getLayersCount(); i++){ |
||
266 | FLayer layer = layers.getLayer(i); |
||
267 | if (layer.isEditing()){
|
||
268 | return true; |
||
269 | } |
||
270 | } |
||
271 | return false; |
||
272 | } |
||
273 | |||
274 | public void saveToState(PersistentState state) throws PersistenceException { |
||
275 | super.saveToState(state);
|
||
276 | state.set("mainMapContext", this.getMapContext()); |
||
277 | if( this.getMapOverViewContext() != null ) { |
||
278 | state.set("useMapOverview", true); |
||
279 | } else {
|
||
280 | state.set("useMapOverview", false); |
||
281 | } |
||
282 | state.set("overviewMapContext", this.getMapOverViewContext()); |
||
283 | } |
||
284 | |||
285 | public void loadFromState(PersistentState state) throws PersistenceException { |
||
286 | super.loadFromState(state);
|
||
287 | this.mapContext = (MapContext) state.get("mainMapContext"); |
||
288 | if( state.getBoolean("useMapOverview") ) { |
||
289 | this.mapOverViewContext = (MapContext) state.get("overviewMapContext"); |
||
290 | } else {
|
||
291 | this.mapOverViewContext = null; |
||
292 | } |
||
293 | } |
||
294 | |||
295 | } |