gvsig-3d / org.gvsig.animation3d / trunk / org.gvsig.animation3d / org.gvsig.animation3d.swing / org.gvsig.animation3d.swing.impl / src / main / java / org / gvsig / animation3d / swing / impl / DefaultAnimation3DSwingManager.java @ 684
History | View | Annotate | Download (6.9 KB)
1 |
package org.gvsig.animation3d.swing.impl; |
---|---|
2 |
|
3 |
import gov.nasa.worldwind.View; |
4 |
import gov.nasa.worldwind.WorldWind; |
5 |
import gov.nasa.worldwind.animation.AnimationSupport; |
6 |
import gov.nasa.worldwind.avlist.AVKey; |
7 |
import gov.nasa.worldwind.awt.WorldWindowGLJPanel; |
8 |
import gov.nasa.worldwind.geom.Angle; |
9 |
import gov.nasa.worldwind.geom.LatLon; |
10 |
import gov.nasa.worldwind.geom.Position; |
11 |
import gov.nasa.worldwind.view.orbit.FlyToOrbitViewAnimator; |
12 |
import gov.nasa.worldwind.view.orbit.OrbitView; |
13 |
|
14 |
import java.util.ArrayList; |
15 |
import java.util.Collection; |
16 |
import java.util.List; |
17 |
import java.util.Map; |
18 |
|
19 |
import org.gvsig.animation3d.swing.api.Animation3D; |
20 |
import org.gvsig.animation3d.swing.api.Animation3DPanel; |
21 |
import org.gvsig.animation3d.swing.api.Animation3DSwingManager; |
22 |
import org.gvsig.animation3d.swing.api.Animator; |
23 |
import org.gvsig.animation3d.swing.api.Frame3D; |
24 |
import org.gvsig.animation3d.swing.api.Frame3DCreationException; |
25 |
import org.gvsig.fmap.geom.Geometry.SUBTYPES; |
26 |
import org.gvsig.fmap.geom.GeometryLocator; |
27 |
import org.gvsig.fmap.geom.exception.CreateGeometryException; |
28 |
import org.gvsig.fmap.geom.primitive.Point; |
29 |
import org.gvsig.fmap.mapcontext.layers.ExtendedPropertiesSupport; |
30 |
import org.gvsig.tools.persistence.impl.DelegatedList; |
31 |
import org.gvsig.view3d.swing.api.MapControl3D; |
32 |
|
33 |
/**
|
34 |
* @author <a href="mailto:lmarques@disid.com">Lluis Marques</a>
|
35 |
*
|
36 |
*/
|
37 |
public class DefaultAnimation3DSwingManager implements Animation3DSwingManager { |
38 |
|
39 |
@SuppressWarnings("unchecked") |
40 |
@Override
|
41 |
public List<Animation3D> getAnimations(ExtendedPropertiesSupport properties) { |
42 |
Object animationsList = properties.getProperty("animations"); |
43 |
if (animationsList == null) { |
44 |
List<Animation3D> animations = new ArrayList<Animation3D>(); |
45 |
setAnimations(properties, animations); |
46 |
return animations;
|
47 |
} else {
|
48 |
if (animationsList instanceof DelegatedList) { |
49 |
List<Animation3D> animations = new ArrayList<Animation3D>(); |
50 |
animations.addAll((Collection<? extends Animation3D>) animationsList); |
51 |
setAnimations(properties, animations); |
52 |
return animations;
|
53 |
} else {
|
54 |
return (List<Animation3D>) animationsList; |
55 |
} |
56 |
} |
57 |
} |
58 |
|
59 |
@Override
|
60 |
public void setAnimations(ExtendedPropertiesSupport properties, List<Animation3D> animations) { |
61 |
properties.setProperty("animations", animations);
|
62 |
} |
63 |
|
64 |
@Override
|
65 |
public Frame3D createFrame3D(String name, MapControl3D mapControl3D) |
66 |
throws Frame3DCreationException {
|
67 |
|
68 |
OrbitView orbitView = getOrbitView(mapControl3D); |
69 |
double heading = orbitView.getHeading().getDegrees();
|
70 |
double pitch = orbitView.getPitch().getDegrees();
|
71 |
double elevation = orbitView.getCenterPosition().getElevation();
|
72 |
double zoom = orbitView.getZoom();
|
73 |
|
74 |
Point position = null; |
75 |
double x = orbitView.getCenterPosition().getLongitude().getDegrees();
|
76 |
double y = orbitView.getCenterPosition().getLatitude().getDegrees();
|
77 |
try {
|
78 |
position = GeometryLocator.getGeometryManager().createPoint(x, y, SUBTYPES.GEOM2D); |
79 |
} catch (CreateGeometryException e) {
|
80 |
String msg =
|
81 |
String.format("Can not create frame position [longitude: %1s latitude: %2s]", |
82 |
new Object[] { x, y }); |
83 |
throw new Frame3DCreationException(msg, e); |
84 |
} |
85 |
|
86 |
return createFrame3D(name, heading, pitch, elevation, position, zoom);
|
87 |
} |
88 |
|
89 |
public Frame3D createFrame3D(String name, double heading, double pitch, double elevation, |
90 |
Point position, double zoom) { |
91 |
return new DefaultFrame3D(name, heading, pitch, elevation, position, zoom); |
92 |
} |
93 |
|
94 |
@Override
|
95 |
public Animation3D createAnimation3D(String name, List<Frame3D> sphericalFrames, |
96 |
List<Frame3D> flatFrames) {
|
97 |
return new DefaultAnimation3D(name, sphericalFrames, flatFrames); |
98 |
} |
99 |
|
100 |
@Override
|
101 |
public Animation3DPanel createAnimationPanel(Map<String, ExtendedPropertiesSupport> properties) { |
102 |
return new DefaultAnimation3DPanelController(properties); |
103 |
} |
104 |
|
105 |
@Override
|
106 |
public Animator createGoToAnimator(MapControl3D mapControl3D, Frame3D frame,
|
107 |
final long minMillis, final long maxMillis) { |
108 |
|
109 |
OrbitView orbitView = getOrbitView(mapControl3D); |
110 |
double longitude = frame.getPosition().getX();
|
111 |
double latitude = frame.getPosition().getY();
|
112 |
Position endPos =
|
113 |
new Position(LatLon.fromDegrees(latitude, longitude), frame.getElevation()); |
114 |
|
115 |
Position beginPos =
|
116 |
Position.fromDegrees(orbitView.getCenterPosition().getLatitude().getDegrees(),
|
117 |
orbitView.getCenterPosition().getLongitude().getDegrees(), orbitView |
118 |
.getCenterPosition().getElevation()); |
119 |
long timeToMove =
|
120 |
AnimationSupport.getScaledTimeMillisecs(beginPos, endPos, minMillis, maxMillis); |
121 |
|
122 |
gov.nasa.worldwind.animation.Animator animator = |
123 |
FlyToOrbitViewAnimator.createFlyToOrbitViewAnimator(orbitView, beginPos, endPos, |
124 |
orbitView.getHeading(), Angle.fromDegrees(frame.getHeading()), |
125 |
orbitView.getPitch(), Angle.fromDegrees(frame.getPitch()), orbitView.getZoom(), |
126 |
frame.getZoom(), timeToMove, WorldWind.ABSOLUTE); |
127 |
return new DefaultAnimatorWrapper(animator); |
128 |
} |
129 |
|
130 |
@Override
|
131 |
public Animator createGoToAnimator(MapControl3D mapControl3D, List<Frame3D> frames, |
132 |
long minMillis, long maxMillis) { |
133 |
OrbitView orbitView = getOrbitView(mapControl3D); |
134 |
gov.nasa.worldwind.animation.Animator animator = |
135 |
new MultipleFlyToOrbitViewAnimator(orbitView, frames, minMillis, maxMillis);
|
136 |
return new DefaultAnimatorWrapper(animator); |
137 |
} |
138 |
|
139 |
@Override
|
140 |
public void addAnimator(MapControl3D mapControl3D, Animator animator) { |
141 |
OrbitView orbitView = getOrbitView(mapControl3D); |
142 |
orbitView.addAnimator(new DefaultWWAnimationWrapper(animator));
|
143 |
orbitView.firePropertyChange(AVKey.VIEW, null, orbitView);
|
144 |
} |
145 |
|
146 |
@Override
|
147 |
public boolean isAnimating(MapControl3D mapControl3D) { |
148 |
OrbitView orbitView = getOrbitView(mapControl3D); |
149 |
return orbitView.isAnimating();
|
150 |
} |
151 |
|
152 |
@Override
|
153 |
public void stopAnimations(MapControl3D mapControl3D) { |
154 |
OrbitView orbitView = getOrbitView(mapControl3D); |
155 |
orbitView.stopAnimations(); |
156 |
} |
157 |
|
158 |
private OrbitView getOrbitView(MapControl3D mapControl3D) {
|
159 |
Object underLineComponent = mapControl3D.getUnderLineComponent();
|
160 |
if (underLineComponent instanceof WorldWindowGLJPanel) { |
161 |
WorldWindowGLJPanel wwd = (WorldWindowGLJPanel) underLineComponent; |
162 |
View view = wwd.getView();
|
163 |
if (view instanceof OrbitView) { |
164 |
return (OrbitView) view;
|
165 |
} |
166 |
} |
167 |
throw new IllegalArgumentException( |
168 |
"Can not get WorldWind view from under line MapControl3D component");
|
169 |
} |
170 |
} |