gvsig-3d / 2.1 / trunk / org.gvsig.view3d / org.gvsig.view3d.main / src / main / java / org / gvsig / view3d / main / PaletteActions.java @ 407
History | View | Annotate | Download (9.66 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright ? 2007-2015 gvSIG Association
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 2
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
|
25 |
package org.gvsig.view3d.main; |
26 |
|
27 |
import java.awt.event.ActionEvent; |
28 |
import java.io.File; |
29 |
import java.util.HashMap; |
30 |
import java.util.Map; |
31 |
|
32 |
import javax.swing.AbstractAction; |
33 |
import javax.swing.Action; |
34 |
import javax.swing.JFileChooser; |
35 |
import javax.swing.SwingUtilities; |
36 |
|
37 |
import org.gvsig.fmap.dal.DALLocator; |
38 |
import org.gvsig.fmap.dal.DataManager; |
39 |
import org.gvsig.fmap.dal.DataStoreParameters; |
40 |
import org.gvsig.fmap.dal.exception.InitializeException; |
41 |
import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException; |
42 |
import org.gvsig.fmap.dal.exception.ValidateDataParametersException; |
43 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
44 |
import org.gvsig.fmap.mapcontext.MapContextLocator; |
45 |
import org.gvsig.fmap.mapcontext.MapContextManager; |
46 |
import org.gvsig.fmap.mapcontext.exceptions.LoadLayerException; |
47 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
48 |
import org.gvsig.raster.fmap.layers.FLyrRaster; |
49 |
import org.gvsig.raster.impl.store.DefaultRasterStore; |
50 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
51 |
import org.gvsig.tools.swing.api.threadsafedialogs.ThreadSafeDialogsManager; |
52 |
import org.gvsig.utils.GenericFileFilter; |
53 |
import org.gvsig.view3d.swing.api.View3DLocator; |
54 |
import org.gvsig.view3d.swing.api.View3DManager; |
55 |
import org.gvsig.view3d.swing.api.View3DPanel; |
56 |
|
57 |
/**
|
58 |
* @author llmarques
|
59 |
*
|
60 |
*/
|
61 |
public class PaletteActions { |
62 |
|
63 |
Map<String, Action> actions; |
64 |
Main main; |
65 |
|
66 |
public PaletteActions(Main main) {
|
67 |
|
68 |
this.main = main;
|
69 |
|
70 |
actions = new HashMap<String, Action>(); |
71 |
|
72 |
actions.put("exit", getExitAction());
|
73 |
actions.put("add-vectorial-layer", getAddVectorialLayerAction());
|
74 |
actions.put("add-raster-layer", getAddRasterLayerAction());
|
75 |
actions.put("create-sphere-view-3d", getCreateSphereViewAction());
|
76 |
actions.put("create-flat-view-3d", getCreateFlatViewAction());
|
77 |
actions.put("create-reload-view-3d", getCreateReloadLayersAction());
|
78 |
actions.put("create-synchronize-view-3d", getCreateSynchronizeAction());
|
79 |
|
80 |
} |
81 |
|
82 |
public Action getAction(String actionCommand) { |
83 |
return actions.get(actionCommand);
|
84 |
} |
85 |
|
86 |
private AbstractAction getAddVectorialLayerAction() { |
87 |
return new AbstractAction("Add Vectorial layer") { |
88 |
|
89 |
/**
|
90 |
*
|
91 |
*/
|
92 |
private static final long serialVersionUID = 7506436995278783992L; |
93 |
|
94 |
public void actionPerformed(ActionEvent e) { |
95 |
ThreadSafeDialogsManager dlgManager = |
96 |
ToolsSwingLocator.getThreadSafeDialogsManager(); |
97 |
|
98 |
File[] file = |
99 |
dlgManager.showChooserDialog( |
100 |
"Seleccione una capa vectorial",
|
101 |
JFileChooser.OPEN_DIALOG, JFileChooser.FILES_ONLY, |
102 |
false, new File(System.getProperty("user.home")), |
103 |
new GenericFileFilter(new String[] { ".shp" }, |
104 |
"(*.shp)"), true); |
105 |
|
106 |
if (file != null) { |
107 |
try {
|
108 |
for (int i = 0; i < file.length; i++) { |
109 |
addVectorialLayer(file[i].getAbsolutePath()); |
110 |
} |
111 |
} catch (Exception ex) { |
112 |
ex.printStackTrace(); |
113 |
} |
114 |
} |
115 |
} |
116 |
}; |
117 |
} |
118 |
|
119 |
public void addRasterLayer(String layerPath) throws InitializeException, |
120 |
ProviderNotRegisteredException, ValidateDataParametersException, |
121 |
LoadLayerException { |
122 |
|
123 |
DataStoreParameters params; |
124 |
DataManager dataManager = DALLocator.getDataManager(); |
125 |
MapContextManager mapContextManager = |
126 |
MapContextLocator.getMapContextManager(); |
127 |
|
128 |
params = dataManager.createStoreParameters("Gdal Store");
|
129 |
params.setDynValue("uri", layerPath);
|
130 |
params.validate(); |
131 |
|
132 |
DefaultRasterStore store = |
133 |
(DefaultRasterStore) dataManager.openStore( |
134 |
params.getDataStoreName(), params); |
135 |
|
136 |
FLyrRaster layer = |
137 |
(FLyrRaster) mapContextManager.createLayer(store.getName(), store); |
138 |
|
139 |
this.main.getMapContext().beginAtomicEvent();
|
140 |
this.main.getMapContext().getLayers().addLayer(layer);
|
141 |
this.main.getMapContext().invalidate();
|
142 |
this.main.getMapContext().endAtomicEvent();
|
143 |
|
144 |
// XXX Forces component repaint.
|
145 |
SwingUtilities.updateComponentTreeUI(this.main.mainFrame); |
146 |
} |
147 |
|
148 |
private AbstractAction getAddRasterLayerAction() { |
149 |
return new AbstractAction("Add Raster layer") { |
150 |
|
151 |
/**
|
152 |
*
|
153 |
*/
|
154 |
private static final long serialVersionUID = 7506436995278783992L; |
155 |
|
156 |
public void actionPerformed(ActionEvent e) { |
157 |
ThreadSafeDialogsManager dlgManager = |
158 |
ToolsSwingLocator.getThreadSafeDialogsManager(); |
159 |
|
160 |
File[] file = |
161 |
dlgManager.showChooserDialog("Seleccione una capa raster",
|
162 |
JFileChooser.OPEN_DIALOG, JFileChooser.FILES_ONLY, |
163 |
false, new File(System.getProperty("user.home")), null, |
164 |
true);
|
165 |
|
166 |
if (file != null) { |
167 |
try {
|
168 |
for (int i = 0; i < file.length; i++) { |
169 |
addRasterLayer(file[i].getAbsolutePath()); |
170 |
} |
171 |
} catch (Exception ex) { |
172 |
ex.printStackTrace(); |
173 |
} |
174 |
} |
175 |
} |
176 |
}; |
177 |
} |
178 |
|
179 |
public void addVectorialLayer(String layerPath) throws InitializeException, |
180 |
ProviderNotRegisteredException, ValidateDataParametersException, |
181 |
LoadLayerException { |
182 |
|
183 |
DataStoreParameters params; |
184 |
DataManager dataManager = DALLocator.getDataManager(); |
185 |
MapContextManager mapContextManager = |
186 |
MapContextLocator.getMapContextManager(); |
187 |
|
188 |
params = dataManager.createStoreParameters("Shape");
|
189 |
|
190 |
File shpFile = new File(layerPath); |
191 |
|
192 |
params.setDynValue("shpFile", shpFile.getPath());
|
193 |
params.setDynValue("CRS", this.main.getDefaultProjection()); |
194 |
params.validate(); |
195 |
|
196 |
FeatureStore store = |
197 |
(FeatureStore) dataManager.openStore(params.getDataStoreName(), |
198 |
params); |
199 |
|
200 |
FLayer layer = mapContextManager.createLayer(store.getName(), store); |
201 |
this.main.getMapContext().beginAtomicEvent();
|
202 |
this.main.getMapContext().getLayers().addLayer(layer);
|
203 |
this.main.getMapContext().invalidate();
|
204 |
this.main.getMapContext().endAtomicEvent();
|
205 |
|
206 |
// XXX Forces component repaint.
|
207 |
SwingUtilities.updateComponentTreeUI(this.main.mainFrame); |
208 |
} |
209 |
|
210 |
private AbstractAction getExitAction() { |
211 |
return new AbstractAction("Exit") { |
212 |
|
213 |
/**
|
214 |
*
|
215 |
*/
|
216 |
private static final long serialVersionUID = 7506436995278783992L; |
217 |
|
218 |
public void actionPerformed(ActionEvent e) { |
219 |
System.exit(0); |
220 |
} |
221 |
}; |
222 |
} |
223 |
|
224 |
private Action getCreateSphereViewAction() { |
225 |
return new AbstractAction("Create Sphere 3D visor") { |
226 |
|
227 |
/**
|
228 |
*
|
229 |
*/
|
230 |
private static final long serialVersionUID = 7506436995278783992L; |
231 |
|
232 |
public void actionPerformed(ActionEvent e) { |
233 |
View3DManager manager = View3DLocator.getManager(); |
234 |
View3DPanel view3dPanel = |
235 |
manager.createView3DPanel(main.getMapContext(), 0);
|
236 |
// Change value for constant key
|
237 |
view3dPanel.show(); |
238 |
} |
239 |
}; |
240 |
} |
241 |
|
242 |
private Action getCreateSynchronizeAction() { |
243 |
return new AbstractAction("Synchronize views") { |
244 |
|
245 |
/**
|
246 |
*
|
247 |
*/
|
248 |
private static final long serialVersionUID = 7506436995278783992L; |
249 |
|
250 |
public void actionPerformed(ActionEvent e) { |
251 |
// TODO
|
252 |
} |
253 |
}; |
254 |
} |
255 |
|
256 |
private Action getCreateReloadLayersAction() { |
257 |
return new AbstractAction("Reload layers") { |
258 |
|
259 |
/**
|
260 |
*
|
261 |
*/
|
262 |
private static final long serialVersionUID = 7506436995278783992L; |
263 |
|
264 |
public void actionPerformed(ActionEvent e) { |
265 |
// TODO
|
266 |
} |
267 |
}; |
268 |
} |
269 |
|
270 |
private Action getCreateFlatViewAction() { |
271 |
return new AbstractAction("Create Flat 3D visor") { |
272 |
|
273 |
/**
|
274 |
*
|
275 |
*/
|
276 |
private static final long serialVersionUID = 7506436995278783992L; |
277 |
|
278 |
public void actionPerformed(ActionEvent e) { |
279 |
View3DManager manager = View3DLocator.getManager(); |
280 |
View3DPanel view3dPanel = |
281 |
manager.createView3DPanel(main.getMapContext(), 1);
|
282 |
// Change value for constant key
|
283 |
view3dPanel.show(); |
284 |
} |
285 |
}; |
286 |
} |
287 |
} |