gvsig-3d / 2.1 / trunk / org.gvsig.view3d / org.gvsig.view3d.swing / org.gvsig.view3d.swing.impl / src / main / java / org / gvsig / view3d / swing / impl / DefaultView3DPanel.java @ 428
History | View | Annotate | Download (7.33 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.swing.impl; |
26 |
|
27 |
import gov.nasa.worldwind.globes.Earth; |
28 |
import gov.nasa.worldwind.globes.EarthFlat; |
29 |
import gov.nasa.worldwind.globes.Globe; |
30 |
import gov.nasa.worldwind.layers.CompassLayer; |
31 |
import gov.nasa.worldwind.layers.Layer; |
32 |
import gov.nasa.worldwind.layers.LayerList; |
33 |
import gov.nasa.worldwind.layers.ScalebarLayer; |
34 |
import gov.nasa.worldwind.layers.SkyColorLayer; |
35 |
import gov.nasa.worldwind.layers.SkyGradientLayer; |
36 |
import gov.nasa.worldwind.layers.StarsLayer; |
37 |
import gov.nasa.worldwind.layers.WorldMapLayer; |
38 |
|
39 |
import java.awt.BorderLayout; |
40 |
import java.lang.reflect.Constructor; |
41 |
import java.lang.reflect.InvocationTargetException; |
42 |
import java.util.List; |
43 |
|
44 |
import javax.swing.JComponent; |
45 |
|
46 |
import org.slf4j.Logger; |
47 |
import org.slf4j.LoggerFactory; |
48 |
|
49 |
import org.gvsig.fmap.mapcontext.MapContext; |
50 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
51 |
import org.gvsig.fmap.mapcontext.layers.FLayers; |
52 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
53 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager; |
54 |
import org.gvsig.view3d.swing.api.AbstractView3DPanel; |
55 |
|
56 |
/**
|
57 |
* @author llmarques
|
58 |
*
|
59 |
*/
|
60 |
public class DefaultView3DPanel extends AbstractView3DPanel { |
61 |
|
62 |
private static final Logger logger = LoggerFactory |
63 |
.getLogger(DefaultView3DPanel.class); |
64 |
|
65 |
private static final long serialVersionUID = -87105248886531868L; |
66 |
|
67 |
private MapContext mapContext;
|
68 |
|
69 |
private TYPE type;
|
70 |
|
71 |
public DefaultView3DPanel(MapContext theMapContext, TYPE type) {
|
72 |
|
73 |
super(new BorderLayout(), type); |
74 |
|
75 |
this.mapContext = theMapContext;
|
76 |
this.type = type;
|
77 |
|
78 |
// add(this.mapContext.getLayers());
|
79 |
|
80 |
} |
81 |
|
82 |
public void add(FLayer layer) { |
83 |
// TODO
|
84 |
throw new UnsupportedOperationException(); |
85 |
} |
86 |
|
87 |
public void add(FLayers layer) { |
88 |
// TODO
|
89 |
throw new UnsupportedOperationException(); |
90 |
} |
91 |
|
92 |
public MapContext getMapContext() {
|
93 |
return this.mapContext; |
94 |
} |
95 |
|
96 |
public TYPE getType() {
|
97 |
// TODO Auto-generated method stub
|
98 |
return this.type; |
99 |
} |
100 |
|
101 |
public double getVerticalExaggeration() { |
102 |
return getWwd().getSceneController().getVerticalExaggeration();
|
103 |
} |
104 |
|
105 |
public void hideAtmosphere() { |
106 |
hideLayer(SkyGradientLayer.class); |
107 |
} |
108 |
|
109 |
public void hideMiniMap() { |
110 |
hideLayer(WorldMapLayer.class); |
111 |
} |
112 |
|
113 |
public void hideNorthIndicator() { |
114 |
hideLayer(CompassLayer.class); |
115 |
} |
116 |
|
117 |
public void hideScale() { |
118 |
hideLayer(ScalebarLayer.class); |
119 |
} |
120 |
|
121 |
public void hideStarBackground() { |
122 |
hideLayer(StarsLayer.class); |
123 |
} |
124 |
|
125 |
public void reloadLayers() { |
126 |
// TODO
|
127 |
throw new UnsupportedOperationException(); |
128 |
} |
129 |
|
130 |
public void remove(FLayer layer) { |
131 |
// TODO
|
132 |
throw new UnsupportedOperationException(); |
133 |
} |
134 |
|
135 |
public void removeAllLayers() { |
136 |
getWwd().getModel().getLayers().removeAll(); |
137 |
} |
138 |
|
139 |
public void setMapContext(MapContext theMapContext) { |
140 |
this.mapContext = theMapContext;
|
141 |
} |
142 |
|
143 |
public void setVerticalExaggeration(double verticalExaggeration) { |
144 |
getWwd().getSceneController().setVerticalExaggeration( |
145 |
verticalExaggeration); |
146 |
} |
147 |
|
148 |
public void show() { |
149 |
WindowManager wm = ToolsSwingLocator.getWindowManager(); |
150 |
wm.showWindow(this, "_View3D_window", WindowManager.MODE.WINDOW); |
151 |
} |
152 |
|
153 |
public void showAtmosphere() { |
154 |
try {
|
155 |
Globe globe = getWwd().getModel().getGlobe(); |
156 |
if (globe instanceof Earth) { |
157 |
getWwd().getModel().getLayers().add(new SkyGradientLayer());
|
158 |
addLayer(SkyGradientLayer.class); |
159 |
} else if (globe instanceof EarthFlat) { |
160 |
getWwd().getModel().getLayers().add(new SkyColorLayer());
|
161 |
addLayer(SkyColorLayer.class); |
162 |
} |
163 |
} catch (Exception e) { |
164 |
logger.warn( |
165 |
"Can't add " + SkyGradientLayer.class.getCanonicalName()
|
166 |
+ " or " + SkyColorLayer.class.getCanonicalName() + " to " |
167 |
+ getWwd().getModel().toString(), e); |
168 |
} |
169 |
} |
170 |
|
171 |
public void showMiniMap() { |
172 |
try {
|
173 |
addLayer(WorldMapLayer.class); |
174 |
} catch (Exception e) { |
175 |
logger.warn("Can't add " + WorldMapLayer.class.getCanonicalName()
|
176 |
+ "to " + getWwd().getModel().toString(), e);
|
177 |
} |
178 |
} |
179 |
|
180 |
public void showNortIndicator() { |
181 |
try {
|
182 |
addLayer(CompassLayer.class); |
183 |
} catch (Exception e) { |
184 |
logger.warn("Can't add " + CompassLayer.class.getCanonicalName()
|
185 |
+ " to " + getWwd().getModel().toString(), e);
|
186 |
} |
187 |
} |
188 |
|
189 |
public void showScale() { |
190 |
try {
|
191 |
addLayer(ScalebarLayer.class); |
192 |
} catch (Exception e) { |
193 |
logger.warn("Can't add " + ScalebarLayer.class.getCanonicalName()
|
194 |
+ " to " + getWwd().getModel().toString(), e);
|
195 |
} |
196 |
} |
197 |
|
198 |
public void showStarBackgroundLayer() { |
199 |
try {
|
200 |
addLayer(StarsLayer.class); |
201 |
} catch (Exception e) { |
202 |
logger.warn("Can't add " + StarsLayer.class.getCanonicalName()
|
203 |
+ " to " + getWwd().getModel().toString(), e);
|
204 |
} |
205 |
} |
206 |
|
207 |
public void synchronizeViewPorts() { |
208 |
// TODO
|
209 |
throw new UnsupportedOperationException(); |
210 |
} |
211 |
|
212 |
private boolean isAlreadyAdded(LayerList layerList, |
213 |
@SuppressWarnings("rawtypes") Class clazz) { |
214 |
|
215 |
List<Layer> layersByClass = layerList.getLayersByClass(clazz);
|
216 |
|
217 |
return layersByClass.size() > 0; |
218 |
} |
219 |
|
220 |
@SuppressWarnings("rawtypes") |
221 |
private void hideLayer(Class layerClazz) { |
222 |
LayerList layers = getWwd().getModel().getLayers(); |
223 |
List<Layer> layersByClass = layers.getLayersByClass(layerClazz);
|
224 |
layers.removeAll(layersByClass); |
225 |
} |
226 |
|
227 |
@SuppressWarnings("rawtypes") |
228 |
private void addLayer(Class layerClazz) throws InstantiationException, |
229 |
IllegalAccessException, IllegalArgumentException, |
230 |
InvocationTargetException {
|
231 |
LayerList layerList = getWwd().getModel().getLayers(); |
232 |
|
233 |
if (isAlreadyAdded(layerList, layerClazz)) {
|
234 |
return;
|
235 |
} |
236 |
|
237 |
Constructor[] constructors = layerClazz.getConstructors(); |
238 |
for (int i = 0; i < constructors.length; i++) { |
239 |
if (constructors[i].getParameterTypes().length == 0) { |
240 |
layerList.add((Layer) constructors[i].newInstance()); |
241 |
} |
242 |
} |
243 |
} |
244 |
|
245 |
public JComponent asJComponent() { |
246 |
return this; |
247 |
} |
248 |
|
249 |
} |