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