root / branches / v2_0_0_prep / applications / appgvSIG / src / org / gvsig / app / project / documents / view / BaseViewDocument.java @ 38601
History | View | Annotate | Download (7.81 KB)
1 | 31496 | jjdelcerro | /* gvSIG. Geographic Information System of the Valencian Government
|
---|---|---|---|
2 | *
|
||
3 | * Copyright (C) 2007-2009 Infrastructures and Transports Department
|
||
4 | 31544 | cordinyana | * of the Valencian Government (CIT)
|
5 | 31496 | jjdelcerro | *
|
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 | 29598 | jpiera | package org.gvsig.app.project.documents.view; |
30 | 7392 | sbayarri | |
31 | import java.awt.Color; |
||
32 | import java.awt.Component; |
||
33 | 10626 | caballero | import java.awt.Dimension; |
34 | 7476 | azabala | import java.util.List; |
35 | 7392 | sbayarri | |
36 | import javax.swing.JOptionPane; |
||
37 | 10626 | caballero | import javax.swing.JPanel; |
38 | import javax.swing.JScrollPane; |
||
39 | 7392 | sbayarri | |
40 | import org.cresques.cts.IProjection; |
||
41 | 36443 | cordinyana | |
42 | 29598 | jpiera | import org.gvsig.andami.PluginServices; |
43 | import org.gvsig.andami.ui.mdiManager.IWindow; |
||
44 | import org.gvsig.andami.ui.mdiManager.WindowInfo; |
||
45 | 32880 | jjdelcerro | import org.gvsig.app.project.documents.AbstractDocument; |
46 | 31496 | jjdelcerro | import org.gvsig.app.project.documents.DocumentManager; |
47 | 29598 | jpiera | import org.gvsig.app.project.documents.view.info.gui.HTMLInfoToolPanel; |
48 | 20994 | jmvivo | 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 | 28066 | fdiaz | import org.gvsig.fmap.mapcontext.layers.FLayer; |
53 | 20994 | jmvivo | import org.gvsig.fmap.mapcontext.layers.FLayers; |
54 | 23214 | jmvivo | import org.gvsig.tools.exception.BaseException; |
55 | 31496 | jjdelcerro | import org.gvsig.tools.persistence.PersistentState; |
56 | 32880 | jjdelcerro | import org.gvsig.tools.persistence.exception.PersistenceException; |
57 | 7392 | sbayarri | |
58 | 31496 | jjdelcerro | /**
|
59 | *
|
||
60 | * @author 2005- Vicente Caballero
|
||
61 | * @author 2009- Joaquin del Cerro
|
||
62 | *
|
||
63 | */
|
||
64 | 7392 | sbayarri | |
65 | 31496 | jjdelcerro | public abstract class BaseViewDocument extends AbstractDocument implements ErrorListener, |
66 | ViewDocument { |
||
67 | 7392 | sbayarri | |
68 | 31496 | jjdelcerro | /**
|
69 | *
|
||
70 | */
|
||
71 | private static final long serialVersionUID = -2621709089720665902L; |
||
72 | |||
73 | 33275 | jjdelcerro | public static final String PERSISTENCE_DEFINITION_NAME = "BaseViewDocument"; |
74 | |||
75 | 7392 | sbayarri | protected MapContext mapOverViewContext;
|
76 | protected MapContext mapContext;
|
||
77 | 31496 | jjdelcerro | |
78 | public BaseViewDocument() {
|
||
79 | super();
|
||
80 | } |
||
81 | |||
82 | public BaseViewDocument(DocumentManager factory) {
|
||
83 | super(factory);
|
||
84 | } |
||
85 | |||
86 | 7392 | sbayarri | /**
|
87 | 31496 | jjdelcerro | * Gets the MapContext of the main map in the view.
|
88 | 7392 | sbayarri | *
|
89 | 31496 | jjdelcerro | * @return the main MapContext
|
90 | 7392 | sbayarri | */
|
91 | public MapContext getMapContext() {
|
||
92 | return mapContext;
|
||
93 | } |
||
94 | |||
95 | /**
|
||
96 | 31496 | jjdelcerro | * Gets the MapContext from the locator, which is the
|
97 | 7392 | sbayarri | * small map in the left-bottom corner of the View.
|
98 | *
|
||
99 | 31496 | jjdelcerro | * @return the locator MapContext
|
100 | 7392 | sbayarri | */
|
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 | 10165 | caballero | |
127 | 7476 | azabala | /**
|
128 | * Reports to the user a bundle of driver exceptions produced in the
|
||
129 | * same atomic MapContext transaction
|
||
130 | */
|
||
131 | 33275 | jjdelcerro | @SuppressWarnings("rawtypes") |
132 | 7476 | azabala | public void reportDriverExceptions(String introductoryText, List driverExceptions) { |
133 | 15843 | vcaballero | HtmlWindow htmlPanel = new HtmlWindow(570, 600, PluginServices.getText(this,"driver_error")); |
134 | 9214 | fdiaz | String htmlText = ""; |
135 | 7476 | azabala | if(introductoryText == null){ |
136 | 15843 | vcaballero | htmlText += "<h2 text=\"#000080\">"+PluginServices.getText(this,"se_han_producido_los_siguientes_errores_durante_la_carga_de_las_capas")+"</h2>"; |
137 | 7476 | azabala | }else{
|
138 | htmlText += introductoryText; |
||
139 | } |
||
140 | int numErrors = driverExceptions.size();
|
||
141 | for(int i = 0; i < numErrors; i++){ |
||
142 | 10626 | caballero | //htmlText += "<br>\n";
|
143 | BaseException exception = (BaseException) driverExceptions.get(i); |
||
144 | 15843 | vcaballero | htmlText +="<p text=\"#550080\">_________________________________________________________________________________________</p>";
|
145 | htmlText += "<h3>"+PluginServices.getText(this,exception.getMessageKey())+"</h3>"; |
||
146 | 10626 | caballero | htmlText += "<p>"+exception.getMessage()+"</p>"; |
147 | 15843 | vcaballero | htmlText +="<p text=\"#550080\">_________________________________________________________________________________________</p>";
|
148 | 7476 | azabala | } |
149 | 10626 | caballero | |
150 | 7476 | azabala | System.out.println(htmlText);
|
151 | htmlPanel.show(htmlText); |
||
152 | 10165 | caballero | |
153 | 7476 | azabala | PluginServices.getMDIManager().addCentredWindow(htmlPanel); |
154 | 10165 | caballero | |
155 | 7476 | azabala | } |
156 | 10165 | caballero | |
157 | 7476 | azabala | /**
|
158 | * HtmlInfoToolPanel that implements IWindow
|
||
159 | * @author azabala
|
||
160 | *
|
||
161 | */
|
||
162 | 10626 | caballero | class HtmlWindow extends JPanel implements IWindow { |
163 | 31496 | jjdelcerro | /**
|
164 | *
|
||
165 | */
|
||
166 | private static final long serialVersionUID = 1151465547277478664L; |
||
167 | |||
168 | 10626 | caballero | private HTMLInfoToolPanel htmlPanel=new HTMLInfoToolPanel(); |
169 | 7476 | azabala | WindowInfo viewInfo = null;
|
170 | public HtmlWindow(int width, int height, String windowTitle){ |
||
171 | 15843 | vcaballero | htmlPanel.setBackground(Color.white);
|
172 | 10626 | caballero | JScrollPane scrollPane=new JScrollPane(htmlPanel); |
173 | scrollPane.setPreferredSize(new Dimension(width-30,height-30)); |
||
174 | this.add(scrollPane);
|
||
175 | 7476 | azabala | viewInfo = new WindowInfo(WindowInfo.MODELESSDIALOG);
|
176 | viewInfo.setTitle(windowTitle); |
||
177 | viewInfo.setWidth(width); |
||
178 | viewInfo.setHeight(height); |
||
179 | } |
||
180 | 10165 | caballero | |
181 | 10626 | caballero | public void show(String htmlText) { |
182 | htmlPanel.show(htmlText); |
||
183 | } |
||
184 | |||
185 | 7476 | azabala | public WindowInfo getWindowInfo() {
|
186 | return viewInfo;
|
||
187 | } |
||
188 | 26449 | jmvivo | public Object getWindowProfile() { |
189 | return WindowInfo.PROPERTIES_PROFILE;
|
||
190 | } |
||
191 | 10165 | caballero | |
192 | 7476 | azabala | } |
193 | 7392 | sbayarri | |
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 | 31496 | jjdelcerro | public IProjection getOverViewProjection() {
|
204 | return mapOverViewContext.getProjection();
|
||
205 | } |
||
206 | |||
207 | 7392 | sbayarri | public void afterRemove() { |
208 | 31496 | jjdelcerro | // FIXME: Parece que no recorre correctamente el arbol de capas
|
209 | |||
210 | 7392 | sbayarri | 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 | 31284 | cordinyana | getMapContext().dispose(); |
220 | getMapOverViewContext().dispose(); |
||
221 | 7392 | sbayarri | } |
222 | |||
223 | public void afterAdd() { |
||
224 | 31496 | jjdelcerro | // Do nothing
|
225 | 7392 | sbayarri | } |
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 | 28066 | fdiaz | 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 | 31496 | jjdelcerro | |
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 | 33275 | jjdelcerro | if( state.getBoolean("useMapOverview") ) { |
266 | this.mapOverViewContext = (MapContext) state.get("overviewMapContext"); |
||
267 | } else {
|
||
268 | this.mapOverViewContext = null; |
||
269 | } |
||
270 | 31496 | jjdelcerro | } |
271 | 33275 | jjdelcerro | |
272 | 7392 | sbayarri | } |