root / branches / v2_0_0_prep / applications / appgvSIG / src / org / gvsig / app / extension / AddLayer.java @ 38614
History | View | Annotate | Download (8.08 KB)
1 | 14821 | jmvivo | /* gvSIG. Sistema de Informaci�n Geogr�fica de la Generalitat Valenciana
|
---|---|---|---|
2 | 2268 | fjp | *
|
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 | 29596 | jpiera | package org.gvsig.app.extension; |
20 | 2268 | fjp | |
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 | 38564 | jjdelcerro | import org.gvsig.andami.IconThemeHelper; |
30 | 29596 | jpiera | import org.gvsig.andami.PluginServices; |
31 | import org.gvsig.andami.plugins.Extension; |
||
32 | import org.gvsig.app.addlayer.AddLayerDialog; |
||
33 | import org.gvsig.app.gui.WizardPanel; |
||
34 | 31496 | jjdelcerro | import org.gvsig.app.project.documents.AbstractDocument; |
35 | import org.gvsig.app.project.documents.view.gui.AbstractViewPanel; |
||
36 | 29596 | jpiera | import org.gvsig.app.project.documents.view.gui.IView; |
37 | 26889 | jmvivo | import org.gvsig.fmap.dal.serverexplorer.filesystem.swing.FilesystemExplorerAddLayerWizardPanel; |
38 | 20994 | jmvivo | import org.gvsig.fmap.mapcontext.ViewPort; |
39 | import org.gvsig.fmap.mapcontext.layers.FLayer; |
||
40 | import org.gvsig.fmap.mapcontext.layers.FLayers; |
||
41 | import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
||
42 | import org.gvsig.fmap.mapcontrol.MapControl; |
||
43 | 2268 | fjp | |
44 | |||
45 | |||
46 | /**
|
||
47 | 14821 | jmvivo | * Extensi�n que abre un di�logo para seleccionar la capa o capas que se quieren
|
48 | * a�adir a la vista.
|
||
49 | 7537 | sbayarri | *
|
50 | 14821 | jmvivo | * @author Fernando Gonz�lez Cort�s
|
51 | 2268 | fjp | */
|
52 | 5005 | jorpiell | public class AddLayer extends Extension { |
53 | 13541 | bsanchez | public AddLayerDialog fopen = null; |
54 | 7476 | azabala | |
55 | 25104 | jmvivo | private static ArrayList<Class<? extends WizardPanel>> wizardStack = null; |
56 | 7476 | azabala | |
57 | 2268 | fjp | static {
|
58 | 25104 | jmvivo | AddLayer.wizardStack = new ArrayList<Class<? extends WizardPanel>>(); |
59 | 14821 | jmvivo | // A�adimos el panel al wizard de cargar capa. (Esto es temporal hasta que
|
60 | 13541 | bsanchez | // el actual sea totalmente extensible)
|
61 | 25793 | jmvivo | // AddLayer.addWizard(FileOpenWizard.class);
|
62 | 26889 | jmvivo | AddLayer.addWizard(FilesystemExplorerAddLayerWizardPanel.class); |
63 | 2268 | fjp | } |
64 | 7476 | azabala | |
65 | 25104 | jmvivo | public static void addWizard(Class<? extends WizardPanel> wpClass) { |
66 | 2268 | fjp | AddLayer.wizardStack.add(wpClass); |
67 | } |
||
68 | 7476 | azabala | |
69 | 34288 | jjdelcerro | private static WizardPanel getInstance(int i, MapControl mapControl) |
70 | 7476 | azabala | throws IllegalArgumentException, SecurityException, |
71 | InstantiationException, IllegalAccessException, |
||
72 | InvocationTargetException, NoSuchMethodException { |
||
73 | 25104 | jmvivo | Class<? extends WizardPanel> wpClass = AddLayer.wizardStack.get(i); |
74 | 7476 | azabala | Object[] params = {}; |
75 | 25104 | jmvivo | WizardPanel wp = wpClass.getConstructor() |
76 | 7476 | azabala | .newInstance(params); |
77 | 34288 | jjdelcerro | wp.setMapCtrl(mapControl); |
78 | 2268 | fjp | wp.initWizard(); |
79 | 7476 | azabala | |
80 | 2268 | fjp | return wp;
|
81 | } |
||
82 | |||
83 | /**
|
||
84 | 5005 | jorpiell | * @see com.iver.mdiApp.plugins.IExtension#isVisible()
|
85 | 2268 | fjp | */
|
86 | public boolean isVisible() { |
||
87 | 29596 | jpiera | org.gvsig.andami.ui.mdiManager.IWindow window = PluginServices.getMDIManager() |
88 | 7537 | sbayarri | .getActiveWindow(); |
89 | 2268 | fjp | |
90 | 7537 | sbayarri | if (window == null) { |
91 | 2268 | fjp | return false; |
92 | } |
||
93 | |||
94 | 7537 | sbayarri | // Any view derived from BaseView should have AddLayer available
|
95 | |||
96 | IView view; |
||
97 | try {
|
||
98 | view = (IView)window; |
||
99 | } |
||
100 | catch (ClassCastException e) { |
||
101 | return false; |
||
102 | } |
||
103 | |||
104 | 23031 | jmvivo | if (view == null) { |
105 | 7537 | sbayarri | return false; |
106 | 23031 | jmvivo | } |
107 | 7537 | sbayarri | |
108 | 31496 | jjdelcerro | AbstractViewPanel baseView = (AbstractViewPanel)view; |
109 | 7537 | sbayarri | return (baseView != null); |
110 | 2268 | fjp | } |
111 | |||
112 | /**
|
||
113 | 29596 | jpiera | * @see org.gvsig.andami.plugins.IExtension#postInitialize()
|
114 | 2268 | fjp | */
|
115 | 9634 | caballero | public void postInitialize() { |
116 | 21743 | vcaballero | // LayerFactory.initialize();
|
117 | // DriverManager dm=LayerFactory.getDM();
|
||
118 | // PluginServices.addLoaders(dm.getDriverClassLoaders());
|
||
119 | // WriterManager wm=LayerFactory.getWM();
|
||
120 | // PluginServices.addLoaders(wm.getWriterClassLoaders());
|
||
121 | 14821 | jmvivo | |
122 | 25936 | jmvivo | // ToolsLocator.getExtensionPointManager().add("FileExtendingOpenDialog",
|
123 | // "").append("FileOpenVectorial", "", VectorialFileOpen.class);
|
||
124 | 2268 | fjp | } |
125 | |||
126 | 11359 | caballero | public static void checkProjection(FLayer lyr, ViewPort viewPort) { |
127 | 10840 | caballero | if (lyr instanceof FLayers){ |
128 | FLayers layers=(FLayers)lyr; |
||
129 | for (int i=0;i<layers.getLayersCount();i++){ |
||
130 | checkProjection(layers.getLayer(i),viewPort); |
||
131 | } |
||
132 | } |
||
133 | 7476 | azabala | if (lyr instanceof FLyrVect) { |
134 | FLyrVect lyrVect = (FLyrVect) lyr; |
||
135 | IProjection proj = lyr.getProjection(); |
||
136 | 14821 | jmvivo | // Comprobar que la projecci�n es la misma que la vista
|
137 | 7476 | azabala | if (proj == null) { |
138 | 14821 | jmvivo | // SUPONEMOS que la capa est� en la proyecci�n que
|
139 | 7476 | azabala | // estamos pidiendo (que ya es mucho suponer, ya).
|
140 | lyrVect.setProjection(viewPort.getProjection()); |
||
141 | return;
|
||
142 | } |
||
143 | 10840 | caballero | int option = JOptionPane.YES_OPTION; |
144 | 7476 | azabala | if (proj != viewPort.getProjection()) {
|
145 | 10840 | caballero | option = JOptionPane.showConfirmDialog((Component)PluginServices.getMainFrame(), PluginServices |
146 | 11359 | caballero | .getText(AddLayer.class, "reproyectar_aviso")+"\n"+ PluginServices.getText(AddLayer.class,"Capa")+": "+lyrVect.getName(), PluginServices |
147 | .getText(AddLayer.class, "reproyectar_pregunta"),
|
||
148 | 7476 | azabala | JOptionPane.YES_NO_OPTION);
|
149 | 3095 | fjp | |
150 | 8916 | caballero | if (option != JOptionPane.OK_OPTION) { |
151 | 7476 | azabala | return;
|
152 | } |
||
153 | 10840 | caballero | |
154 | ICoordTrans ct = proj.getCT(viewPort.getProjection()); |
||
155 | lyrVect.setCoordTrans(ct); |
||
156 | System.err.println("coordTrans = " + proj.getAbrev() + " " |
||
157 | + viewPort.getProjection().getAbrev()); |
||
158 | 7476 | azabala | } |
159 | } |
||
160 | 3095 | fjp | |
161 | 7476 | azabala | } |
162 | |||
163 | 2268 | fjp | /**
|
164 | 29596 | jpiera | * @see org.gvsig.andami.plugins.IExtension#execute(java.lang.String)
|
165 | 2268 | fjp | */
|
166 | public void execute(String actionCommand) { |
||
167 | 7476 | azabala | // Project project = ((ProjectExtension)
|
168 | // PluginServices.getExtension(ProjectExtension.class)).getProject();
|
||
169 | 31496 | jjdelcerro | AbstractViewPanel theView = (AbstractViewPanel) PluginServices.getMDIManager().getActiveWindow(); |
170 | 7675 | caballero | MapControl mapControl=theView.getMapControl(); |
171 | this.addLayers(mapControl);
|
||
172 | mapControl.getMapContext().callLegendChanged(); |
||
173 | 31496 | jjdelcerro | ((AbstractDocument)theView.getModel()).setModified(true); |
174 | 5190 | jmvivo | } |
175 | |||
176 | /**
|
||
177 | 29596 | jpiera | * @see org.gvsig.andami.plugins.IExtension#isEnabled()
|
178 | 5190 | jmvivo | */
|
179 | public boolean isEnabled() { |
||
180 | return true; |
||
181 | } |
||
182 | |||
183 | /**
|
||
184 | 7476 | azabala | * Creates FOpenDialog, and adds file tab, and additional registered tabs
|
185 | 7537 | sbayarri | *
|
186 | 7476 | azabala | * @return FOpenDialog
|
187 | */
|
||
188 | 34017 | cordinyana | private AddLayerDialog createFOpenDialog(MapControl mapControl) {
|
189 | 13541 | bsanchez | fopen = new AddLayerDialog();
|
190 | 7476 | azabala | |
191 | // after that, all registerez tabs (wizardpanels implementations)
|
||
192 | for (int i = 0; i < wizardStack.size(); i++) { |
||
193 | 2268 | fjp | WizardPanel wp; |
194 | try {
|
||
195 | 34288 | jjdelcerro | wp = AddLayer.getInstance(i, mapControl); |
196 | |||
197 | 7476 | azabala | fopen.addWizardTab(wp.getTabName(), wp); |
198 | 2268 | fjp | } catch (IllegalArgumentException e) { |
199 | e.printStackTrace(); |
||
200 | } catch (SecurityException e) { |
||
201 | e.printStackTrace(); |
||
202 | } catch (InstantiationException e) { |
||
203 | e.printStackTrace(); |
||
204 | } catch (IllegalAccessException e) { |
||
205 | e.printStackTrace(); |
||
206 | } catch (InvocationTargetException e) { |
||
207 | e.printStackTrace(); |
||
208 | } catch (NoSuchMethodException e) { |
||
209 | e.printStackTrace(); |
||
210 | } |
||
211 | 7476 | azabala | }// for
|
212 | return fopen;
|
||
213 | } |
||
214 | |||
215 | /**
|
||
216 | * Adds to mapcontrol all layers selected by user in the specified WizardPanel.
|
||
217 | 7537 | sbayarri | *
|
218 | * @param mapControl
|
||
219 | 7476 | azabala | * MapControl on which we want to load user selected layers.
|
220 | 7537 | sbayarri | * @param wizardPanel
|
221 | 7476 | azabala | * WizardPanel where user selected the layers to load
|
222 | * @return
|
||
223 | */
|
||
224 | private boolean loadGenericWizardPanelLayers(MapControl mapControl, WizardPanel wp) { |
||
225 | wp.setMapCtrl(mapControl); |
||
226 | wp.execute(); |
||
227 | 25104 | jmvivo | return true; |
228 | 7476 | azabala | } |
229 | 7537 | sbayarri | |
230 | 7476 | azabala | /**
|
231 | 14821 | jmvivo | * Abre dialogo para a�adir capas y las a�ade en mapControl
|
232 | 7537 | sbayarri | *
|
233 | 14821 | jmvivo | * Devuelve true si se han a�adido capas.
|
234 | 7476 | azabala | */
|
235 | public boolean addLayers(MapControl mapControl) { |
||
236 | // create and show the modal fopen dialog
|
||
237 | 34017 | cordinyana | fopen = createFOpenDialog(mapControl); |
238 | 7476 | azabala | PluginServices.getMDIManager().addWindow(fopen); |
239 | 2268 | fjp | |
240 | 7476 | azabala | if (fopen.isAccepted()) {
|
241 | 13541 | bsanchez | if (fopen.getSelectedTab() instanceof WizardPanel) { |
242 | 2268 | fjp | WizardPanel wp = (WizardPanel) fopen.getSelectedTab(); |
243 | 8790 | jmvivo | return loadGenericWizardPanelLayers(mapControl, wp);
|
244 | 2268 | fjp | } else {
|
245 | 7476 | azabala | JOptionPane.showMessageDialog((Component) PluginServices |
246 | 12323 | caballero | .getMainFrame(), PluginServices.getText(this,"ninguna_capa_seleccionada")); |
247 | 2268 | fjp | } |
248 | } |
||
249 | 5190 | jmvivo | return false; |
250 | 2268 | fjp | } |
251 | 9634 | caballero | |
252 | 17120 | vcaballero | /* (non-Javadoc)
|
253 | * @see com.iver.andami.plugins.IExtension#initialize()
|
||
254 | */
|
||
255 | 9634 | caballero | public void initialize() { |
256 | 38564 | jjdelcerro | IconThemeHelper.registerIcon("action", "view-layer-add", this); |
257 | 9634 | caballero | } |
258 | 2268 | fjp | } |