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