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