svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.app / org.gvsig.app.mainplugin / src / main / java / org / gvsig / app / extension / AddLayer.java @ 41258
History | View | Annotate | Download (7.95 KB)
1 | 40558 | jjdelcerro | /**
|
---|---|---|---|
2 | * gvSIG. Desktop Geographic Information System.
|
||
3 | 40435 | jjdelcerro | *
|
4 | 40558 | jjdelcerro | * Copyright (C) 2007-2013 gvSIG Association.
|
5 | 40435 | jjdelcerro | *
|
6 | 41248 | jjdelcerro | * This program is free software; you can redistribute it and/or modify it under
|
7 | * the terms of the GNU General Public License as published by the Free Software
|
||
8 | * Foundation; either version 3 of the License, or (at your option) any later
|
||
9 | * version.
|
||
10 | 40435 | jjdelcerro | *
|
11 | 41248 | jjdelcerro | * This program is distributed in the hope that it will be useful, but WITHOUT
|
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||
13 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||
14 | * details.
|
||
15 | 40435 | jjdelcerro | *
|
16 | 41248 | jjdelcerro | * You should have received a copy of the GNU General Public License along with
|
17 | * this program; if not, write to the Free Software Foundation, Inc., 51
|
||
18 | * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||
19 | 40558 | jjdelcerro | *
|
20 | 41248 | jjdelcerro | * For any additional information, do not hesitate to contact us at info AT
|
21 | * gvsig.com, or visit our website www.gvsig.com.
|
||
22 | 40435 | jjdelcerro | */
|
23 | package org.gvsig.app.extension; |
||
24 | |||
25 | import java.awt.Component; |
||
26 | import java.lang.reflect.InvocationTargetException; |
||
27 | import java.util.ArrayList; |
||
28 | |||
29 | import javax.swing.JOptionPane; |
||
30 | |||
31 | import org.cresques.cts.ICoordTrans; |
||
32 | import org.cresques.cts.IProjection; |
||
33 | import org.gvsig.andami.IconThemeHelper; |
||
34 | import org.gvsig.andami.PluginServices; |
||
35 | import org.gvsig.andami.plugins.Extension; |
||
36 | 40485 | jldominguez | import org.gvsig.app.ApplicationLocator; |
37 | 41248 | jjdelcerro | import org.gvsig.app.ApplicationManager; |
38 | 40435 | jjdelcerro | import org.gvsig.app.addlayer.AddLayerDialog; |
39 | import org.gvsig.app.gui.WizardPanel; |
||
40 | 41248 | jjdelcerro | import org.gvsig.app.project.documents.view.ViewDocument; |
41 | 40435 | jjdelcerro | import org.gvsig.app.project.documents.view.gui.IView; |
42 | import org.gvsig.fmap.dal.serverexplorer.filesystem.swing.FilesystemExplorerAddLayerWizardPanel; |
||
43 | import org.gvsig.fmap.mapcontext.ViewPort; |
||
44 | import org.gvsig.fmap.mapcontext.layers.FLayer; |
||
45 | import org.gvsig.fmap.mapcontext.layers.FLayers; |
||
46 | import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
||
47 | import org.gvsig.fmap.mapcontrol.MapControl; |
||
48 | 41258 | jjdelcerro | import org.slf4j.Logger; |
49 | import org.slf4j.LoggerFactory; |
||
50 | 40435 | jjdelcerro | |
51 | /**
|
||
52 | 41248 | jjdelcerro | * Extensi�n que abre un di�logo para seleccionar la capa o capas que se
|
53 | * quieren anadir a la vista.
|
||
54 | 40435 | jjdelcerro | *
|
55 | */
|
||
56 | public class AddLayer extends Extension { |
||
57 | 41258 | jjdelcerro | private static final Logger logger = LoggerFactory.getLogger(AddLayer.class); |
58 | |||
59 | 41248 | jjdelcerro | private static ArrayList<Class<? extends WizardPanel>> wizardStack = null; |
60 | 40435 | jjdelcerro | |
61 | 41248 | jjdelcerro | static {
|
62 | AddLayer.wizardStack = new ArrayList<Class<? extends WizardPanel>>(); |
||
63 | // Anadimos el panel al wizard de cargar capa. (Esto es temporal hasta que
|
||
64 | // el actual sea totalmente extensible)
|
||
65 | AddLayer.addWizard(FilesystemExplorerAddLayerWizardPanel.class); |
||
66 | } |
||
67 | 40435 | jjdelcerro | |
68 | 41248 | jjdelcerro | public static void addWizard(Class<? extends WizardPanel> wpClass) { |
69 | AddLayer.wizardStack.add(wpClass); |
||
70 | } |
||
71 | 40435 | jjdelcerro | |
72 | 41248 | jjdelcerro | private static WizardPanel getInstance(int i, MapControl mapControl) |
73 | throws IllegalArgumentException, SecurityException, |
||
74 | InstantiationException, IllegalAccessException, |
||
75 | InvocationTargetException, NoSuchMethodException { |
||
76 | Class<? extends WizardPanel> wpClass = AddLayer.wizardStack.get(i); |
||
77 | Object[] params = {}; |
||
78 | WizardPanel wp = wpClass.getConstructor() |
||
79 | .newInstance(params); |
||
80 | wp.setMapCtrl(mapControl); |
||
81 | wp.initWizard(); |
||
82 | 40435 | jjdelcerro | |
83 | 41248 | jjdelcerro | return wp;
|
84 | } |
||
85 | 40435 | jjdelcerro | |
86 | 41248 | jjdelcerro | public boolean isVisible() { |
87 | ApplicationManager application = ApplicationLocator.getManager(); |
||
88 | 40485 | jldominguez | |
89 | 41248 | jjdelcerro | return application.getActiveDocument(ViewDocument.class) != null; |
90 | } |
||
91 | 40435 | jjdelcerro | |
92 | 41248 | jjdelcerro | public void postInitialize() { |
93 | super.postInitialize();
|
||
94 | } |
||
95 | 40435 | jjdelcerro | |
96 | 41248 | jjdelcerro | public static void checkProjection(FLayer lyr, ViewPort viewPort) { |
97 | if (lyr instanceof FLayers) { |
||
98 | FLayers layers = (FLayers) lyr; |
||
99 | for (int i = 0; i < layers.getLayersCount(); i++) { |
||
100 | checkProjection(layers.getLayer(i), viewPort); |
||
101 | } |
||
102 | } |
||
103 | if (lyr instanceof FLyrVect) { |
||
104 | FLyrVect lyrVect = (FLyrVect) lyr; |
||
105 | IProjection proj = lyr.getProjection(); |
||
106 | // Comprobar que la projecci�n es la misma que la vista
|
||
107 | if (proj == null) { |
||
108 | 41258 | jjdelcerro | // SUPONEMOS que la capa est� en la proyecci�n que
|
109 | 41248 | jjdelcerro | // estamos pidiendo (que ya es mucho suponer, ya).
|
110 | lyrVect.setProjection(viewPort.getProjection()); |
||
111 | return;
|
||
112 | } |
||
113 | int option = JOptionPane.YES_OPTION; |
||
114 | if (proj != viewPort.getProjection()) {
|
||
115 | option = JOptionPane.showConfirmDialog((Component) PluginServices.getMainFrame(), PluginServices |
||
116 | .getText(AddLayer.class, "reproyectar_aviso") + "\n" + PluginServices.getText(AddLayer.class, "Capa") + ": " + lyrVect.getName(), PluginServices |
||
117 | .getText(AddLayer.class, "reproyectar_pregunta"),
|
||
118 | JOptionPane.YES_NO_OPTION);
|
||
119 | 40435 | jjdelcerro | |
120 | 41248 | jjdelcerro | if (option != JOptionPane.OK_OPTION) { |
121 | return;
|
||
122 | } |
||
123 | 40435 | jjdelcerro | |
124 | 41248 | jjdelcerro | ICoordTrans ct = proj.getCT(viewPort.getProjection()); |
125 | lyrVect.setCoordTrans(ct); |
||
126 | System.err.println("coordTrans = " + proj.getAbrev() + " " |
||
127 | + viewPort.getProjection().getAbrev()); |
||
128 | } |
||
129 | } |
||
130 | 40435 | jjdelcerro | |
131 | 41248 | jjdelcerro | } |
132 | 40435 | jjdelcerro | |
133 | 41248 | jjdelcerro | public void execute(String actionCommand) { |
134 | ApplicationManager application = ApplicationLocator.getManager(); |
||
135 | 40435 | jjdelcerro | |
136 | 41248 | jjdelcerro | ViewDocument document = (ViewDocument) application.getActiveDocument(ViewDocument.class); |
137 | if (document == null) { |
||
138 | return;
|
||
139 | } |
||
140 | IView theView = (IView) document.getMainComponent(); |
||
141 | 40435 | jjdelcerro | |
142 | 41248 | jjdelcerro | MapControl mapControl = theView.getMapControl(); |
143 | this.addLayers(mapControl);
|
||
144 | mapControl.getMapContext().callLegendChanged(); |
||
145 | document.setModified(true);
|
||
146 | } |
||
147 | |||
148 | public boolean isEnabled() { |
||
149 | return true; |
||
150 | } |
||
151 | |||
152 | /**
|
||
153 | * Creates FOpenDialog, and adds file tab, and additional registered tabs
|
||
154 | *
|
||
155 | * @return FOpenDialog
|
||
156 | */
|
||
157 | 40435 | jjdelcerro | private AddLayerDialog createFOpenDialog(MapControl mapControl) {
|
158 | 41258 | jjdelcerro | AddLayerDialog fopen = new AddLayerDialog();
|
159 | 41248 | jjdelcerro | for (int i = 0; i < wizardStack.size(); i++) { |
160 | WizardPanel wp; |
||
161 | try {
|
||
162 | wp = AddLayer.getInstance(i, mapControl); |
||
163 | 40435 | jjdelcerro | |
164 | 41248 | jjdelcerro | fopen.addWizardTab(wp.getTabName(), wp); |
165 | 41258 | jjdelcerro | } catch (Exception e) { |
166 | logger.warn("Can't create layer open dialog.",e);
|
||
167 | 41248 | jjdelcerro | } |
168 | 41258 | jjdelcerro | } |
169 | 41248 | jjdelcerro | return fopen;
|
170 | } |
||
171 | 40435 | jjdelcerro | |
172 | 41248 | jjdelcerro | /**
|
173 | * Adds to mapcontrol all layers selected by user in the specified
|
||
174 | * WizardPanel.
|
||
175 | *
|
||
176 | * @param mapControl MapControl on which we want to load user selected
|
||
177 | * layers.
|
||
178 | * @param wizardPanel WizardPanel where user selected the layers to load
|
||
179 | * @return
|
||
180 | */
|
||
181 | private boolean loadGenericWizardPanelLayers(MapControl mapControl, WizardPanel wp) { |
||
182 | wp.setMapCtrl(mapControl); |
||
183 | wp.execute(); |
||
184 | return true; |
||
185 | } |
||
186 | |||
187 | /**
|
||
188 | * Abre dialogo para a�adir capas y las a�ade en mapControl
|
||
189 | *
|
||
190 | * Devuelve true si se han a�adido capas.
|
||
191 | 41258 | jjdelcerro | * @param mapControl
|
192 | * @return
|
||
193 | 41248 | jjdelcerro | */
|
194 | public boolean addLayers(MapControl mapControl) { |
||
195 | // create and show the modal fopen dialog
|
||
196 | 41258 | jjdelcerro | AddLayerDialog fopen = null;
|
197 | try {
|
||
198 | fopen = createFOpenDialog(mapControl); |
||
199 | PluginServices.getMDIManager().addWindow(fopen); |
||
200 | 40435 | jjdelcerro | |
201 | 41258 | jjdelcerro | if (fopen.isAccepted()) {
|
202 | if (fopen.getSelectedTab() instanceof WizardPanel) { |
||
203 | WizardPanel wp = (WizardPanel) fopen.getSelectedTab(); |
||
204 | return loadGenericWizardPanelLayers(mapControl, wp);
|
||
205 | } else {
|
||
206 | JOptionPane.showMessageDialog((Component) PluginServices |
||
207 | .getMainFrame(), PluginServices.getText(this, "ninguna_capa_seleccionada")); |
||
208 | } |
||
209 | 41248 | jjdelcerro | } |
210 | 41258 | jjdelcerro | return false; |
211 | } finally {
|
||
212 | if (fopen != null) { |
||
213 | fopen.dispose(); |
||
214 | fopen = null;
|
||
215 | } |
||
216 | 41248 | jjdelcerro | } |
217 | } |
||
218 | 40435 | jjdelcerro | |
219 | 41248 | jjdelcerro | public void initialize() { |
220 | IconThemeHelper.registerIcon("action", "view-layer-add", this); |
||
221 | } |
||
222 | 40435 | jjdelcerro | } |