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