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