svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / project / documents / view / ProjectViewBase.java @ 35756
History | View | Annotate | Download (8.2 KB)
1 | 7392 | sbayarri | package com.iver.cit.gvsig.project.documents.view; |
---|---|---|---|
2 | |||
3 | import java.awt.Color; |
||
4 | import java.awt.Component; |
||
5 | 10626 | caballero | import java.awt.Dimension; |
6 | 7392 | sbayarri | import java.util.ArrayList; |
7 | 7476 | azabala | import java.util.List; |
8 | 7392 | sbayarri | |
9 | import javax.swing.JOptionPane; |
||
10 | 10626 | caballero | import javax.swing.JPanel; |
11 | import javax.swing.JScrollPane; |
||
12 | 7392 | sbayarri | |
13 | import org.cresques.cts.IProjection; |
||
14 | 10626 | caballero | import org.gvsig.exceptions.BaseException; |
15 | 7392 | sbayarri | |
16 | import com.iver.andami.PluginServices; |
||
17 | import com.iver.andami.ui.mdiManager.IWindow; |
||
18 | 7476 | azabala | import com.iver.andami.ui.mdiManager.WindowInfo; |
19 | 7392 | sbayarri | import com.iver.cit.gvsig.ProjectExtension; |
20 | import com.iver.cit.gvsig.fmap.ErrorEvent; |
||
21 | import com.iver.cit.gvsig.fmap.ErrorListener; |
||
22 | import com.iver.cit.gvsig.fmap.MapContext; |
||
23 | import com.iver.cit.gvsig.fmap.layers.CancelationException; |
||
24 | 27660 | vcaballero | import com.iver.cit.gvsig.fmap.layers.FLayer; |
25 | 7392 | sbayarri | import com.iver.cit.gvsig.fmap.layers.FLayers; |
26 | import com.iver.cit.gvsig.fmap.layers.layerOperations.AlphanumericData; |
||
27 | import com.iver.cit.gvsig.project.Project; |
||
28 | import com.iver.cit.gvsig.project.documents.ProjectDocument; |
||
29 | import com.iver.cit.gvsig.project.documents.table.ProjectTable; |
||
30 | import com.iver.cit.gvsig.project.documents.table.ProjectTableFactory; |
||
31 | 7476 | azabala | import com.iver.cit.gvsig.project.documents.view.info.gui.HTMLInfoToolPanel; |
32 | 10165 | caballero | import com.iver.cit.gvsig.project.documents.view.toolListeners.LinkListener; |
33 | 7392 | sbayarri | |
34 | 7414 | sbayarri | public abstract class ProjectViewBase extends ProjectDocument implements ErrorListener, |
35 | 7392 | sbayarri | IProjectView { |
36 | |||
37 | protected MapContext mapOverViewContext;
|
||
38 | protected MapContext mapContext;
|
||
39 | 10165 | caballero | protected int m_typeLink = LinkListener.TYPELINKIMAGE; |
40 | 7392 | sbayarri | protected String m_extLink; |
41 | protected String m_selectedField = null; |
||
42 | |||
43 | // OVERRIDE THESE
|
||
44 | public IWindow getProperties() { return null;} |
||
45 | |||
46 | /**
|
||
47 | * Gets the FMap's contexts of the main map in the view.
|
||
48 | *
|
||
49 | * @return
|
||
50 | */
|
||
51 | public MapContext getMapContext() {
|
||
52 | return mapContext;
|
||
53 | } |
||
54 | |||
55 | /**
|
||
56 | * Gets the FMap's context from the locator, which is the
|
||
57 | * small map in the left-bottom corner of the View.
|
||
58 | *
|
||
59 | * @return
|
||
60 | */
|
||
61 | public MapContext getMapOverViewContext() {
|
||
62 | return mapOverViewContext;
|
||
63 | } |
||
64 | |||
65 | /**
|
||
66 | * @see com.iver.cit.gvsig.project.documents.view.ProjectView#setMapContext(com.iver.cit.gvsig.fmap.MapContext)
|
||
67 | */
|
||
68 | public void setMapContext(MapContext fmap) { |
||
69 | mapContext = fmap; |
||
70 | fmap.addErrorListener(this);
|
||
71 | } |
||
72 | |||
73 | /**
|
||
74 | * DOCUMENT ME!
|
||
75 | *
|
||
76 | * @param fmap DOCUMENT ME!
|
||
77 | */
|
||
78 | public void setMapOverViewContext(MapContext fmap) { |
||
79 | mapOverViewContext = fmap; |
||
80 | mapOverViewContext.setProjection(mapContext.getProjection()); |
||
81 | } |
||
82 | |||
83 | public void showErrors(){ |
||
84 | if (mapContext.getLayersError().size()>0){ |
||
85 | String layersError=""; |
||
86 | for (int i=0;i<mapContext.getLayersError().size();i++){ |
||
87 | layersError=layersError+"\n"+(String)mapContext.getLayersError().get(i); |
||
88 | } |
||
89 | JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), |
||
90 | PluginServices.getText(this,"fallo_capas")+" : \n"+ |
||
91 | layersError); |
||
92 | } |
||
93 | } |
||
94 | 10165 | caballero | |
95 | 7476 | azabala | /**
|
96 | * Reports to the user a bundle of driver exceptions produced in the
|
||
97 | * same atomic MapContext transaction
|
||
98 | */
|
||
99 | public void reportDriverExceptions(String introductoryText, List driverExceptions) { |
||
100 | 15843 | vcaballero | HtmlWindow htmlPanel = new HtmlWindow(570, 600, PluginServices.getText(this,"driver_error")); |
101 | 9214 | fdiaz | String htmlText = ""; |
102 | 7476 | azabala | if(introductoryText == null){ |
103 | 15843 | vcaballero | htmlText += "<h2 text=\"#000080\">"+PluginServices.getText(this,"se_han_producido_los_siguientes_errores_durante_la_carga_de_las_capas")+"</h2>"; |
104 | 7476 | azabala | }else{
|
105 | htmlText += introductoryText; |
||
106 | } |
||
107 | int numErrors = driverExceptions.size();
|
||
108 | for(int i = 0; i < numErrors; i++){ |
||
109 | 10626 | caballero | //htmlText += "<br>\n";
|
110 | BaseException exception = (BaseException) driverExceptions.get(i); |
||
111 | 15843 | vcaballero | htmlText +="<p text=\"#550080\">_________________________________________________________________________________________</p>";
|
112 | htmlText += "<h3>"+PluginServices.getText(this,exception.getMessageKey())+"</h3>"; |
||
113 | 10626 | caballero | htmlText += "<p>"+exception.getMessage()+"</p>"; |
114 | 15843 | vcaballero | htmlText +="<p text=\"#550080\">_________________________________________________________________________________________</p>";
|
115 | 7476 | azabala | } |
116 | 10626 | caballero | |
117 | 7476 | azabala | System.out.println(htmlText);
|
118 | htmlPanel.show(htmlText); |
||
119 | 10165 | caballero | |
120 | 7476 | azabala | PluginServices.getMDIManager().addCentredWindow(htmlPanel); |
121 | 10165 | caballero | |
122 | 7476 | azabala | } |
123 | 10165 | caballero | |
124 | 7476 | azabala | /**
|
125 | * HtmlInfoToolPanel that implements IWindow
|
||
126 | * @author azabala
|
||
127 | *
|
||
128 | */
|
||
129 | 10626 | caballero | class HtmlWindow extends JPanel implements IWindow { |
130 | private HTMLInfoToolPanel htmlPanel=new HTMLInfoToolPanel(); |
||
131 | 7476 | azabala | WindowInfo viewInfo = null;
|
132 | public HtmlWindow(int width, int height, String windowTitle){ |
||
133 | 15843 | vcaballero | htmlPanel.setBackground(Color.white);
|
134 | 10626 | caballero | JScrollPane scrollPane=new JScrollPane(htmlPanel); |
135 | scrollPane.setPreferredSize(new Dimension(width-30,height-30)); |
||
136 | this.add(scrollPane);
|
||
137 | 7476 | azabala | viewInfo = new WindowInfo(WindowInfo.MODELESSDIALOG);
|
138 | viewInfo.setTitle(windowTitle); |
||
139 | viewInfo.setWidth(width); |
||
140 | viewInfo.setHeight(height); |
||
141 | } |
||
142 | 10165 | caballero | |
143 | 10626 | caballero | public void show(String htmlText) { |
144 | htmlPanel.show(htmlText); |
||
145 | } |
||
146 | |||
147 | 7476 | azabala | public WindowInfo getWindowInfo() {
|
148 | return viewInfo;
|
||
149 | } |
||
150 | 10165 | caballero | |
151 | 24986 | jcampos | public Object getWindowProfile() { |
152 | // TODO Auto-generated method stub
|
||
153 | return WindowInfo.PROPERTIES_PROFILE;
|
||
154 | } |
||
155 | |||
156 | 7476 | azabala | } |
157 | 7392 | sbayarri | |
158 | /**
|
||
159 | * DOCUMENT ME!
|
||
160 | *
|
||
161 | * @return DOCUMENT ME!
|
||
162 | */
|
||
163 | public IProjection getProjection() {
|
||
164 | return mapContext.getProjection();
|
||
165 | } |
||
166 | |||
167 | /**
|
||
168 | * DOCUMENT ME!
|
||
169 | *
|
||
170 | * @return DOCUMENT ME!
|
||
171 | */
|
||
172 | public IProjection getOverViewProjection() {
|
||
173 | return mapOverViewContext.getProjection();
|
||
174 | } |
||
175 | |||
176 | public void setProjection (IProjection proj) { |
||
177 | mapContext.setProjection(proj); |
||
178 | mapOverViewContext.setProjection(proj); |
||
179 | } |
||
180 | |||
181 | /**
|
||
182 | * DOCUMENT ME!
|
||
183 | *
|
||
184 | * @return DOCUMENT ME!
|
||
185 | */
|
||
186 | public String getExtLink() { |
||
187 | return m_extLink;
|
||
188 | } |
||
189 | |||
190 | /**
|
||
191 | * DOCUMENT ME!
|
||
192 | *
|
||
193 | * @return DOCUMENT ME!
|
||
194 | */
|
||
195 | public int getTypeLink() { |
||
196 | return m_typeLink;
|
||
197 | } |
||
198 | |||
199 | /**
|
||
200 | * Se selecciona la extensi?n para realizar cuando se quiera el link.
|
||
201 | *
|
||
202 | * @param s nombre del campo.
|
||
203 | */
|
||
204 | public void setExtLink(String s) { |
||
205 | m_extLink = s; |
||
206 | } |
||
207 | |||
208 | /**
|
||
209 | * Se selecciona el tipo de fichero para realizar cuando se quiera el link.
|
||
210 | *
|
||
211 | * @param i tipo de fichero.
|
||
212 | */
|
||
213 | public void setTypeLink(int i) { |
||
214 | m_typeLink = i; |
||
215 | } |
||
216 | |||
217 | public void afterRemove() { |
||
218 | FLayers layers=this.getMapContext().getLayers();
|
||
219 | |||
220 | for (int i = layers.getLayersCount()-1; i>=0; i--){ |
||
221 | try {
|
||
222 | if (layers.getLayer(i) instanceof AlphanumericData){ |
||
223 | Project project = ((ProjectExtension)PluginServices.getExtension(ProjectExtension.class)).getProject(); |
||
224 | ProjectTable pt = project.getTable((AlphanumericData) layers.getLayer(i)); |
||
225 | |||
226 | ArrayList tables = project.getDocumentsByType(ProjectTableFactory.registerName);
|
||
227 | for (int j = 0; j < tables.size(); j++) { |
||
228 | if (tables.get(j) == pt){
|
||
229 | project.delDocument((ProjectDocument)tables.get(j)); |
||
230 | break;
|
||
231 | } |
||
232 | } |
||
233 | |||
234 | PluginServices.getMDIManager().closeSingletonWindow(pt); |
||
235 | } |
||
236 | layers.getLayer(i).getParentLayer().removeLayer(layers.getLayer(i)); |
||
237 | 24624 | vcaballero | PluginServices.getMainFrame().enableControls(); |
238 | } catch (CancelationException e1) {
|
||
239 | 7392 | sbayarri | e1.printStackTrace(); |
240 | } |
||
241 | } |
||
242 | |||
243 | } |
||
244 | |||
245 | public void afterAdd() { |
||
246 | // TODO Auto-generated method stub
|
||
247 | |||
248 | } |
||
249 | |||
250 | |||
251 | /**
|
||
252 | * DOCUMENT ME!
|
||
253 | *
|
||
254 | * @param c DOCUMENT ME!
|
||
255 | */
|
||
256 | public void setBackColor(Color c) { |
||
257 | // getMapContext().getViewPort().addViewPortListener(getMapContext()
|
||
258 | // .getEventBuffer());
|
||
259 | getMapContext().getViewPort().setBackColor(c); |
||
260 | //getMapContext().getViewPort().removeViewPortListener(getMapContext()
|
||
261 | // .getEventBuffer());
|
||
262 | } |
||
263 | |||
264 | /**
|
||
265 | * Se selecciona el nombre del campo para realizar cuando se quiera el
|
||
266 | * link.
|
||
267 | *
|
||
268 | * @param s nombre del campo.
|
||
269 | */
|
||
270 | public void setSelectedField(String s) { |
||
271 | m_selectedField = s; |
||
272 | } |
||
273 | |||
274 | /**
|
||
275 | * DOCUMENT ME!
|
||
276 | *
|
||
277 | * @return DOCUMENT ME!
|
||
278 | */
|
||
279 | public String getSelectedField() { |
||
280 | return m_selectedField;
|
||
281 | } |
||
282 | |||
283 | public void errorThrown(ErrorEvent e) { |
||
284 | JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), |
||
285 | PluginServices.getText(this,"fallo_capas")+" : \n"+ |
||
286 | e.getMessage()); |
||
287 | |||
288 | } |
||
289 | |||
290 | 27660 | vcaballero | public boolean isLocked() { |
291 | if(super.isLocked()) return true; |
||
292 | FLayers layers = getMapContext().getLayers(); |
||
293 | for(int i=0; i<layers.getLayersCount(); i++){ |
||
294 | FLayer layer = layers.getLayer(i); |
||
295 | if (layer.isEditing()){
|
||
296 | return true; |
||
297 | } |
||
298 | } |
||
299 | return false; |
||
300 | } |
||
301 | |||
302 | |||
303 | 7392 | sbayarri | } |