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