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