svn-gvsig-desktop / branches / v2_0_0_prep / applications / appgvSIG / src / org / gvsig / app / extension / AddLayer.java @ 34007
History | View | Annotate | Download (8.68 KB)
1 |
/* gvSIG. Sistema de Informaci�n Geogr�fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*/
|
19 |
package org.gvsig.app.extension; |
20 |
|
21 |
import java.awt.Component; |
22 |
import java.lang.reflect.InvocationTargetException; |
23 |
import java.util.ArrayList; |
24 |
|
25 |
import javax.swing.JOptionPane; |
26 |
|
27 |
import org.cresques.cts.ICoordTrans; |
28 |
import org.cresques.cts.IProjection; |
29 |
import org.gvsig.andami.PluginServices; |
30 |
import org.gvsig.andami.plugins.Extension; |
31 |
import org.gvsig.app.addlayer.AddLayerDialog; |
32 |
import org.gvsig.app.gui.WizardPanel; |
33 |
import org.gvsig.app.project.documents.AbstractDocument; |
34 |
import org.gvsig.app.project.documents.view.gui.AbstractViewPanel; |
35 |
import org.gvsig.app.project.documents.view.gui.IView; |
36 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.swing.FilesystemExplorerAddLayerWizardPanel; |
37 |
import org.gvsig.fmap.mapcontext.ViewPort; |
38 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
39 |
import org.gvsig.fmap.mapcontext.layers.FLayers; |
40 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
41 |
import org.gvsig.fmap.mapcontrol.MapControl; |
42 |
|
43 |
|
44 |
|
45 |
/**
|
46 |
* Extensi�n que abre un di�logo para seleccionar la capa o capas que se quieren
|
47 |
* a�adir a la vista.
|
48 |
*
|
49 |
* @author Fernando Gonz�lez Cort�s
|
50 |
*/
|
51 |
public class AddLayer extends Extension { |
52 |
public AddLayerDialog fopen = null; |
53 |
|
54 |
private static ArrayList<Class<? extends WizardPanel>> wizardStack = null; |
55 |
|
56 |
static {
|
57 |
AddLayer.wizardStack = new ArrayList<Class<? extends WizardPanel>>(); |
58 |
// A�adimos el panel al wizard de cargar capa. (Esto es temporal hasta que
|
59 |
// el actual sea totalmente extensible)
|
60 |
// AddLayer.addWizard(FileOpenWizard.class);
|
61 |
AddLayer.addWizard(FilesystemExplorerAddLayerWizardPanel.class); |
62 |
} |
63 |
|
64 |
public static void addWizard(Class<? extends WizardPanel> wpClass) { |
65 |
AddLayer.wizardStack.add(wpClass); |
66 |
} |
67 |
|
68 |
public static WizardPanel getInstance(int i) |
69 |
throws IllegalArgumentException, SecurityException, |
70 |
InstantiationException, IllegalAccessException, |
71 |
InvocationTargetException, NoSuchMethodException { |
72 |
Class<? extends WizardPanel> wpClass = AddLayer.wizardStack.get(i); |
73 |
Object[] params = {}; |
74 |
WizardPanel wp = wpClass.getConstructor() |
75 |
.newInstance(params); |
76 |
|
77 |
wp.initWizard(); |
78 |
|
79 |
return wp;
|
80 |
} |
81 |
|
82 |
/**
|
83 |
* @see com.iver.mdiApp.plugins.IExtension#isVisible()
|
84 |
*/
|
85 |
public boolean isVisible() { |
86 |
org.gvsig.andami.ui.mdiManager.IWindow window = PluginServices.getMDIManager() |
87 |
.getActiveWindow(); |
88 |
|
89 |
if (window == null) { |
90 |
return false; |
91 |
} |
92 |
|
93 |
// Any view derived from BaseView should have AddLayer available
|
94 |
|
95 |
IView view; |
96 |
try {
|
97 |
view = (IView)window; |
98 |
} |
99 |
catch (ClassCastException e) { |
100 |
return false; |
101 |
} |
102 |
|
103 |
if (view == null) { |
104 |
return false; |
105 |
} |
106 |
|
107 |
AbstractViewPanel baseView = (AbstractViewPanel)view; |
108 |
return (baseView != null); |
109 |
} |
110 |
|
111 |
/**
|
112 |
* @see org.gvsig.andami.plugins.IExtension#postInitialize()
|
113 |
*/
|
114 |
public void postInitialize() { |
115 |
// LayerFactory.initialize();
|
116 |
// DriverManager dm=LayerFactory.getDM();
|
117 |
// PluginServices.addLoaders(dm.getDriverClassLoaders());
|
118 |
// WriterManager wm=LayerFactory.getWM();
|
119 |
// PluginServices.addLoaders(wm.getWriterClassLoaders());
|
120 |
|
121 |
// ToolsLocator.getExtensionPointManager().add("FileExtendingOpenDialog",
|
122 |
// "").append("FileOpenVectorial", "", VectorialFileOpen.class);
|
123 |
} |
124 |
|
125 |
public static void checkProjection(FLayer lyr, ViewPort viewPort) { |
126 |
if (lyr instanceof FLayers){ |
127 |
FLayers layers=(FLayers)lyr; |
128 |
for (int i=0;i<layers.getLayersCount();i++){ |
129 |
checkProjection(layers.getLayer(i),viewPort); |
130 |
} |
131 |
} |
132 |
if (lyr instanceof FLyrVect) { |
133 |
FLyrVect lyrVect = (FLyrVect) lyr; |
134 |
IProjection proj = lyr.getProjection(); |
135 |
// Comprobar que la projecci�n es la misma que la vista
|
136 |
if (proj == null) { |
137 |
// SUPONEMOS que la capa est� en la proyecci�n que
|
138 |
// estamos pidiendo (que ya es mucho suponer, ya).
|
139 |
lyrVect.setProjection(viewPort.getProjection()); |
140 |
return;
|
141 |
} |
142 |
int option = JOptionPane.YES_OPTION; |
143 |
if (proj != viewPort.getProjection()) {
|
144 |
option = JOptionPane.showConfirmDialog((Component)PluginServices.getMainFrame(), PluginServices |
145 |
.getText(AddLayer.class, "reproyectar_aviso")+"\n"+ PluginServices.getText(AddLayer.class,"Capa")+": "+lyrVect.getName(), PluginServices |
146 |
.getText(AddLayer.class, "reproyectar_pregunta"),
|
147 |
JOptionPane.YES_NO_OPTION);
|
148 |
|
149 |
if (option != JOptionPane.OK_OPTION) { |
150 |
return;
|
151 |
} |
152 |
|
153 |
ICoordTrans ct = proj.getCT(viewPort.getProjection()); |
154 |
lyrVect.setCoordTrans(ct); |
155 |
System.err.println("coordTrans = " + proj.getAbrev() + " " |
156 |
+ viewPort.getProjection().getAbrev()); |
157 |
} |
158 |
} |
159 |
|
160 |
} |
161 |
|
162 |
/**
|
163 |
* @see org.gvsig.andami.plugins.IExtension#execute(java.lang.String)
|
164 |
*/
|
165 |
public void execute(String actionCommand) { |
166 |
// Project project = ((ProjectExtension)
|
167 |
// PluginServices.getExtension(ProjectExtension.class)).getProject();
|
168 |
AbstractViewPanel theView = (AbstractViewPanel) PluginServices.getMDIManager().getActiveWindow(); |
169 |
MapControl mapControl=theView.getMapControl(); |
170 |
this.addLayers(mapControl);
|
171 |
mapControl.getMapContext().callLegendChanged(); |
172 |
((AbstractDocument)theView.getModel()).setModified(true); |
173 |
} |
174 |
|
175 |
/**
|
176 |
* @see org.gvsig.andami.plugins.IExtension#isEnabled()
|
177 |
*/
|
178 |
public boolean isEnabled() { |
179 |
return true; |
180 |
} |
181 |
|
182 |
/**
|
183 |
* Creates FOpenDialog, and adds file tab, and additional registered tabs
|
184 |
*
|
185 |
* @return FOpenDialog
|
186 |
*/
|
187 |
private AddLayerDialog createFOpenDialog() {
|
188 |
fopen = new AddLayerDialog();
|
189 |
|
190 |
// after that, all registerez tabs (wizardpanels implementations)
|
191 |
for (int i = 0; i < wizardStack.size(); i++) { |
192 |
WizardPanel wp; |
193 |
try {
|
194 |
wp = AddLayer.getInstance(i); |
195 |
fopen.addWizardTab(wp.getTabName(), wp); |
196 |
} catch (IllegalArgumentException e) { |
197 |
e.printStackTrace(); |
198 |
} catch (SecurityException e) { |
199 |
e.printStackTrace(); |
200 |
} catch (InstantiationException e) { |
201 |
e.printStackTrace(); |
202 |
} catch (IllegalAccessException e) { |
203 |
e.printStackTrace(); |
204 |
} catch (InvocationTargetException e) { |
205 |
e.printStackTrace(); |
206 |
} catch (NoSuchMethodException e) { |
207 |
e.printStackTrace(); |
208 |
} |
209 |
}// for
|
210 |
return fopen;
|
211 |
} |
212 |
|
213 |
/**
|
214 |
* Adds to mapcontrol all layers selected by user in the specified WizardPanel.
|
215 |
*
|
216 |
* @param mapControl
|
217 |
* MapControl on which we want to load user selected layers.
|
218 |
* @param wizardPanel
|
219 |
* WizardPanel where user selected the layers to load
|
220 |
* @return
|
221 |
*/
|
222 |
private boolean loadGenericWizardPanelLayers(MapControl mapControl, WizardPanel wp) { |
223 |
wp.setMapCtrl(mapControl); |
224 |
wp.execute(); |
225 |
return true; |
226 |
} |
227 |
|
228 |
/**
|
229 |
* Abre dialogo para a�adir capas y las a�ade en mapControl
|
230 |
*
|
231 |
* Devuelve true si se han a�adido capas.
|
232 |
*/
|
233 |
public boolean addLayers(MapControl mapControl) { |
234 |
// create and show the modal fopen dialog
|
235 |
fopen = createFOpenDialog(); |
236 |
PluginServices.getMDIManager().addWindow(fopen); |
237 |
|
238 |
if (fopen.isAccepted()) {
|
239 |
if (fopen.getSelectedTab() instanceof WizardPanel) { |
240 |
WizardPanel wp = (WizardPanel) fopen.getSelectedTab(); |
241 |
return loadGenericWizardPanelLayers(mapControl, wp);
|
242 |
} else {
|
243 |
JOptionPane.showMessageDialog((Component) PluginServices |
244 |
.getMainFrame(), PluginServices.getText(this,"ninguna_capa_seleccionada")); |
245 |
} |
246 |
} |
247 |
return false; |
248 |
} |
249 |
|
250 |
/* (non-Javadoc)
|
251 |
* @see com.iver.andami.plugins.IExtension#initialize()
|
252 |
*/
|
253 |
public void initialize() { |
254 |
//Listener para resolver un FileDriverNotFoundException
|
255 |
// LayerFactory.addSolveErrorForLayer(FileNotFoundDriverException.class,new FileNotFoundSolve());
|
256 |
|
257 |
|
258 |
|
259 |
// Register.selfRegister();
|
260 |
// org.gvsig.fmap.data.feature.file.dgn.Register.selfRegister();
|
261 |
// org.gvsig.fmap.data.feature.file.dgn.operation.Register.selfRegister();
|
262 |
// org.gvsig.fmap.data.feature.file.dxf.Register.selfRegister();
|
263 |
// org.gvsig.fmap.data.feature.file.dxf.operation.Register.selfRegister();
|
264 |
// org.gvsig.fmap.data.feature.file.shp.Register.selfRegister();
|
265 |
// org.gvsig.fmap.data.feature.db.jdbc.postgresql.Register.selfRegister();
|
266 |
// org.gvsig.fmap.data.feature.db.jdbc.h2.Register.selfRegister();
|
267 |
PluginServices.getIconTheme().registerDefault( |
268 |
"layer-add",
|
269 |
this.getClass().getClassLoader().getResource("images/addlayer.png") |
270 |
); |
271 |
|
272 |
} |
273 |
} |