Revision 443 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
DefaultView3DPanel.java | ||
---|---|---|
24 | 24 |
|
25 | 25 |
package org.gvsig.view3d.swing.impl; |
26 | 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 | 27 |
import java.awt.BorderLayout; |
40 |
import java.lang.reflect.Constructor; |
|
41 |
import java.lang.reflect.InvocationTargetException; |
|
42 |
import java.util.List; |
|
43 | 28 |
|
44 | 29 |
import javax.swing.JComponent; |
30 |
import javax.swing.JPanel; |
|
45 | 31 |
|
46 |
import org.slf4j.Logger; |
|
47 |
import org.slf4j.LoggerFactory; |
|
48 |
|
|
49 | 32 |
import org.gvsig.fmap.mapcontext.MapContext; |
50 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
|
51 |
import org.gvsig.fmap.mapcontext.layers.FLayers; |
|
52 | 33 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
53 | 34 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager; |
54 |
import org.gvsig.view3d.swing.api.AbstractView3DPanel; |
|
35 |
import org.gvsig.view3d.swing.api.MapControl3D; |
|
36 |
import org.gvsig.view3d.swing.api.View3DPanel; |
|
37 |
import org.gvsig.view3d.swing.api.View3DSwingLocator; |
|
38 |
import org.gvsig.view3d.swing.api.View3DSwingManager; |
|
39 |
import org.gvsig.view3d.swing.api.View3DSwingManager.TYPE; |
|
55 | 40 |
|
56 | 41 |
/** |
57 | 42 |
* @author llmarques |
58 | 43 |
* |
59 | 44 |
*/ |
60 |
public class DefaultView3DPanel extends AbstractView3DPanel {
|
|
45 |
public class DefaultView3DPanel extends JPanel implements View3DPanel {
|
|
61 | 46 |
|
62 |
private static final Logger logger = LoggerFactory |
|
63 |
.getLogger(DefaultView3DPanel.class); |
|
64 |
|
|
65 | 47 |
private static final long serialVersionUID = -87105248886531868L; |
66 | 48 |
|
67 |
private MapContext mapContext; |
|
68 |
|
|
69 |
private TYPE type; |
|
49 |
private MapControl3D mapControl3D; |
|
70 | 50 |
|
51 |
/** |
|
52 |
* @param theMapContext |
|
53 |
* @param type |
|
54 |
*/ |
|
71 | 55 |
public DefaultView3DPanel(MapContext theMapContext, TYPE type) { |
56 |
super(new BorderLayout()); |
|
57 |
|
|
58 |
View3DSwingManager swingManager = View3DSwingLocator.getManager(); |
|
59 |
this.mapControl3D = |
|
60 |
swingManager.createMapControl3D(theMapContext, type); |
|
72 | 61 |
|
73 |
super(new BorderLayout(), type); |
|
74 |
|
|
75 |
this.mapContext = theMapContext; |
|
76 |
this.type = type; |
|
77 |
|
|
78 |
// add(this.mapContext.getLayers()); |
|
79 |
|
|
62 |
this.add(mapControl3D.asJComponent(), BorderLayout.CENTER); |
|
80 | 63 |
} |
81 | 64 |
|
82 |
public void add(FLayer layer) { |
|
83 |
// TODO |
|
84 |
throw new UnsupportedOperationException(); |
|
65 |
public JComponent asJComponent() { |
|
66 |
return this; |
|
85 | 67 |
} |
86 | 68 |
|
87 |
public void add(FLayers layer) { |
|
88 |
// TODO |
|
89 |
throw new UnsupportedOperationException(); |
|
69 |
public MapControl3D getMapControl3D() { |
|
70 |
return this.mapControl3D; |
|
90 | 71 |
} |
91 | 72 |
|
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 | 73 |
public void show() { |
149 | 74 |
WindowManager wm = ToolsSwingLocator.getWindowManager(); |
150 |
wm.showWindow(this, "_View3D_window", WindowManager.MODE.WINDOW); |
|
75 |
wm.showWindow(this, "_View3D_window", |
|
76 |
WindowManager.MODE.WINDOW); |
|
151 | 77 |
} |
152 | 78 |
|
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 | 79 |
} |
Also available in: Unified diff