root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / project / documents / view / ProjectViewBase.java @ 24426
History | View | Annotate | Download (7.75 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 | import com.iver.cit.gvsig.fmap.layers.FLayers; |
||
25 | import com.iver.cit.gvsig.fmap.layers.layerOperations.AlphanumericData; |
||
26 | import com.iver.cit.gvsig.project.Project; |
||
27 | import com.iver.cit.gvsig.project.documents.ProjectDocument; |
||
28 | import com.iver.cit.gvsig.project.documents.table.ProjectTable; |
||
29 | import com.iver.cit.gvsig.project.documents.table.ProjectTableFactory; |
||
30 | 7476 | azabala | import com.iver.cit.gvsig.project.documents.view.info.gui.HTMLInfoToolPanel; |
31 | 10165 | caballero | import com.iver.cit.gvsig.project.documents.view.toolListeners.LinkListener; |
32 | 7392 | sbayarri | |
33 | 7414 | sbayarri | public abstract class ProjectViewBase extends ProjectDocument implements ErrorListener, |
34 | 7392 | sbayarri | IProjectView { |
35 | |||
36 | protected MapContext mapOverViewContext;
|
||
37 | protected MapContext mapContext;
|
||
38 | 10165 | caballero | protected int m_typeLink = LinkListener.TYPELINKIMAGE; |
39 | 7392 | sbayarri | protected String m_extLink; |
40 | protected String m_selectedField = null; |
||
41 | |||
42 | // OVERRIDE THESE
|
||
43 | public IWindow createWindow() { return null;} |
||
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 | 7476 | azabala | } |
152 | 7392 | sbayarri | |
153 | /**
|
||
154 | * DOCUMENT ME!
|
||
155 | *
|
||
156 | * @return DOCUMENT ME!
|
||
157 | */
|
||
158 | public IProjection getProjection() {
|
||
159 | return mapContext.getProjection();
|
||
160 | } |
||
161 | |||
162 | /**
|
||
163 | * DOCUMENT ME!
|
||
164 | *
|
||
165 | * @return DOCUMENT ME!
|
||
166 | */
|
||
167 | public IProjection getOverViewProjection() {
|
||
168 | return mapOverViewContext.getProjection();
|
||
169 | } |
||
170 | |||
171 | public void setProjection (IProjection proj) { |
||
172 | mapContext.setProjection(proj); |
||
173 | mapOverViewContext.setProjection(proj); |
||
174 | } |
||
175 | |||
176 | /**
|
||
177 | * DOCUMENT ME!
|
||
178 | *
|
||
179 | * @return DOCUMENT ME!
|
||
180 | */
|
||
181 | public String getExtLink() { |
||
182 | return m_extLink;
|
||
183 | } |
||
184 | |||
185 | /**
|
||
186 | * DOCUMENT ME!
|
||
187 | *
|
||
188 | * @return DOCUMENT ME!
|
||
189 | */
|
||
190 | public int getTypeLink() { |
||
191 | return m_typeLink;
|
||
192 | } |
||
193 | |||
194 | /**
|
||
195 | * Se selecciona la extensi?n para realizar cuando se quiera el link.
|
||
196 | *
|
||
197 | * @param s nombre del campo.
|
||
198 | */
|
||
199 | public void setExtLink(String s) { |
||
200 | m_extLink = s; |
||
201 | } |
||
202 | |||
203 | /**
|
||
204 | * Se selecciona el tipo de fichero para realizar cuando se quiera el link.
|
||
205 | *
|
||
206 | * @param i tipo de fichero.
|
||
207 | */
|
||
208 | public void setTypeLink(int i) { |
||
209 | m_typeLink = i; |
||
210 | } |
||
211 | |||
212 | public void afterRemove() { |
||
213 | FLayers layers=this.getMapContext().getLayers();
|
||
214 | |||
215 | for (int i = layers.getLayersCount()-1; i>=0; i--){ |
||
216 | try {
|
||
217 | if (layers.getLayer(i) instanceof AlphanumericData){ |
||
218 | Project project = ((ProjectExtension)PluginServices.getExtension(ProjectExtension.class)).getProject(); |
||
219 | ProjectTable pt = project.getTable((AlphanumericData) layers.getLayer(i)); |
||
220 | |||
221 | ArrayList tables = project.getDocumentsByType(ProjectTableFactory.registerName);
|
||
222 | for (int j = 0; j < tables.size(); j++) { |
||
223 | if (tables.get(j) == pt){
|
||
224 | project.delDocument((ProjectDocument)tables.get(j)); |
||
225 | break;
|
||
226 | } |
||
227 | } |
||
228 | |||
229 | PluginServices.getMDIManager().closeSingletonWindow(pt); |
||
230 | } |
||
231 | layers.getLayer(i).getParentLayer().removeLayer(layers.getLayer(i)); |
||
232 | } catch (CancelationException e1) {
|
||
233 | e1.printStackTrace(); |
||
234 | } |
||
235 | } |
||
236 | |||
237 | } |
||
238 | |||
239 | public void afterAdd() { |
||
240 | // TODO Auto-generated method stub
|
||
241 | |||
242 | } |
||
243 | |||
244 | |||
245 | /**
|
||
246 | * DOCUMENT ME!
|
||
247 | *
|
||
248 | * @param c DOCUMENT ME!
|
||
249 | */
|
||
250 | public void setBackColor(Color c) { |
||
251 | // getMapContext().getViewPort().addViewPortListener(getMapContext()
|
||
252 | // .getEventBuffer());
|
||
253 | getMapContext().getViewPort().setBackColor(c); |
||
254 | //getMapContext().getViewPort().removeViewPortListener(getMapContext()
|
||
255 | // .getEventBuffer());
|
||
256 | } |
||
257 | |||
258 | /**
|
||
259 | * Se selecciona el nombre del campo para realizar cuando se quiera el
|
||
260 | * link.
|
||
261 | *
|
||
262 | * @param s nombre del campo.
|
||
263 | */
|
||
264 | public void setSelectedField(String s) { |
||
265 | m_selectedField = s; |
||
266 | } |
||
267 | |||
268 | /**
|
||
269 | * DOCUMENT ME!
|
||
270 | *
|
||
271 | * @return DOCUMENT ME!
|
||
272 | */
|
||
273 | public String getSelectedField() { |
||
274 | return m_selectedField;
|
||
275 | } |
||
276 | |||
277 | public void errorThrown(ErrorEvent e) { |
||
278 | JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), |
||
279 | PluginServices.getText(this,"fallo_capas")+" : \n"+ |
||
280 | e.getMessage()); |
||
281 | |||
282 | } |
||
283 | |||
284 | } |