svn-gvsig-desktop / import / ext3D / branches / ext3D_v1.1 / extAnimationGUI / src / com / iver / ai2 / animationgui / gui / MenuAnimationTransparency.java @ 15495
History | View | Annotate | Download (9.1 KB)
1 |
package com.iver.ai2.animationgui.gui; |
---|---|
2 |
|
3 |
import java.util.ArrayList; |
4 |
import java.util.List; |
5 |
|
6 |
import com.iver.andami.PluginServices; |
7 |
import com.iver.andami.plugins.Extension; |
8 |
import com.iver.andami.plugins.IExtension; |
9 |
import com.iver.andami.ui.mdiManager.IWindow; |
10 |
import com.iver.cit.gvsig.ProjectExtension; |
11 |
import com.iver.cit.gvsig.animation.AnimationContainer; |
12 |
import com.iver.cit.gvsig.animation.AnimationPlayer; |
13 |
import com.iver.cit.gvsig.animation.AnimationTransparency; |
14 |
import com.iver.cit.gvsig.animation.InterpolatorTransparency; |
15 |
import com.iver.cit.gvsig.animation.KeyFrameTransparency; |
16 |
import com.iver.cit.gvsig.animation.interval.AnimationKeyFrameInterval; |
17 |
import com.iver.cit.gvsig.animation.traks.AnimationTimeTrack; |
18 |
import com.iver.cit.gvsig.animation.traks.IAnimationTrack; |
19 |
import com.iver.cit.gvsig.fmap.MapContext; |
20 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
21 |
import com.iver.cit.gvsig.fmap.layers.FLayers; |
22 |
import com.iver.cit.gvsig.project.Project; |
23 |
import com.iver.cit.gvsig.project.documents.view.IProjectView; |
24 |
import com.iver.cit.gvsig.project.documents.view.gui.BaseView; |
25 |
import com.iver.utiles.extensionPoints.ExtensionPoint; |
26 |
import com.iver.utiles.extensionPoints.ExtensionPoints; |
27 |
import com.iver.utiles.extensionPoints.ExtensionPointsSingleton; |
28 |
|
29 |
|
30 |
/**
|
31 |
* @author ?ngel
|
32 |
* @since 1.1
|
33 |
*
|
34 |
* Menu of animation transparency toolbar's options.
|
35 |
*/
|
36 |
|
37 |
public class MenuAnimationTransparency extends Extension { |
38 |
|
39 |
private Project project;
|
40 |
|
41 |
private AnimationContainer ac = null; |
42 |
private AnimationTimeTrack animationTimeTrack = null; |
43 |
private AnimationKeyFrameInterval AKFinterval = null; |
44 |
private List keyFrameList = null; |
45 |
|
46 |
public void execute(String actionCommand) { |
47 |
// TODO Auto-generated method stub
|
48 |
|
49 |
// if the button pressed is "this"
|
50 |
if (actionCommand.equals("CREARANIMTRANSP")) { |
51 |
System.out.println("pulsado boton transparencias !!!"); |
52 |
|
53 |
// Getting the active windows
|
54 |
IWindow window = PluginServices.getMDIManager().getActiveWindow(); |
55 |
ac = this.getAnimationContainer();
|
56 |
|
57 |
//List of keyframes.
|
58 |
// If the window is instance of View
|
59 |
if (window instanceof BaseView) { |
60 |
|
61 |
BaseView view = (BaseView) window; |
62 |
|
63 |
// Generating the list of keyframes
|
64 |
//keyFrameList = new ArrayList();
|
65 |
IProjectView model = view.getModel(); |
66 |
MapContext mapContext = model.getMapContext(); |
67 |
FLayers layers = mapContext.getLayers(); |
68 |
FLayer[] actives = layers.getActives();
|
69 |
|
70 |
double fin = 1;//AKFinterval.getEndTime(); |
71 |
double ini = 0;//AKFinterval.getInitialTime(); |
72 |
double tiempo = 0.0; |
73 |
int size = actives.length;
|
74 |
double incremento = ((fin - ini) / (size));
|
75 |
|
76 |
for(int i = size-1; i >= 0; i--){// order in TOC. |
77 |
|
78 |
AnimationTimeTrack animationTimeTrack = null;
|
79 |
animationTimeTrack = this.getAnimationTimeTrack("Track_layer_" + i, ac); |
80 |
animationTimeTrack.setEnabale(true);
|
81 |
|
82 |
// Generating the interval.
|
83 |
AKFinterval = (AnimationKeyFrameInterval) animationTimeTrack |
84 |
.createKeyFrameInterval(); |
85 |
AKFinterval.setInitialTime(0.0);
|
86 |
AKFinterval.setEndTime(1.0);
|
87 |
|
88 |
keyFrameList = new ArrayList(); |
89 |
KeyFrameTransparency kfTransAux = new KeyFrameTransparency();
|
90 |
KeyFrameTransparency kfTransIni = new KeyFrameTransparency();
|
91 |
KeyFrameTransparency kfTransFin = new KeyFrameTransparency();
|
92 |
|
93 |
//Calculating the time insertion.
|
94 |
if (i == size-1) // the keyframe is the first in the list. |
95 |
tiempo = ini + 0.001;
|
96 |
|
97 |
//Three keyframes by track.
|
98 |
//Keyframe 1 of the layer i.
|
99 |
kfTransAux.setName("KF1_layer_" + i);//name of keyframe. |
100 |
kfTransAux.setTime(ini); // initial time interval.
|
101 |
kfTransAux.setAnimatedObject(actives[i]);//set the object to animate(a layer).
|
102 |
//kfTransAux.setLevelTransparency(255);
|
103 |
kfTransAux.CapturesProperties(); //capturing actual transparency.
|
104 |
keyFrameList.add(kfTransAux); // adding in the list.
|
105 |
|
106 |
//keyframe 2 of the layer i.
|
107 |
kfTransIni.setName("KF2_layer_" + i);//name of keyframe. |
108 |
kfTransIni.setTime(tiempo); // initial time interval.
|
109 |
kfTransIni.setAnimatedObject(actives[i]);//set the same layer in the second keyframe.
|
110 |
kfTransIni.CapturesProperties(); //capturing actual transparency.
|
111 |
keyFrameList.add(kfTransIni); // adding in the list.
|
112 |
|
113 |
//keyframe 3 of the layer i.
|
114 |
try {
|
115 |
if(i == 0) // the keyframe is the last in the list. |
116 |
tiempo = fin; |
117 |
else
|
118 |
tiempo += incremento; |
119 |
|
120 |
kfTransFin.setName("KF3_layer_" + i);//name of keyframe. |
121 |
kfTransFin.setTime(tiempo);// saving final time interval.
|
122 |
kfTransFin.setLevelTransparency(0);// interpolation: layer transparency in the moment to 0. |
123 |
kfTransFin.setAnimatedObject(actives[i]); //save the same layer in the third keyframe
|
124 |
keyFrameList.add(kfTransFin);//adding to the list.
|
125 |
} catch (Exception e) { |
126 |
// TODO Auto-generated catch block
|
127 |
e.printStackTrace(); |
128 |
} |
129 |
AKFinterval.setKeyFrameList(keyFrameList);// Adding the list of keyframes to the interval.
|
130 |
} |
131 |
} |
132 |
} |
133 |
|
134 |
// Menu Player.
|
135 |
AnimationContainer ac = (AnimationContainer) project.getAnimationContainer(); |
136 |
AnimationPlayer ap = ac.getAnimationPlayer(); |
137 |
ap.setAnimationContainer(ac); |
138 |
AnimationContol3D fp = new AnimationContol3D(ap);
|
139 |
PluginServices.getMDIManager().addWindow((IWindow) fp); |
140 |
} |
141 |
public void postInitialize(){ |
142 |
// Getting the project using plugin services.
|
143 |
IExtension extension = PluginServices |
144 |
.getExtension(com.iver.cit.gvsig.ProjectExtension.class); |
145 |
ProjectExtension pe = (ProjectExtension) extension; |
146 |
project = pe.getProject(); |
147 |
|
148 |
} |
149 |
public void initialize() { |
150 |
// TODO Auto-generated method stub
|
151 |
} |
152 |
|
153 |
private AnimationContainer getAnimationContainer() {
|
154 |
return (AnimationContainer) project.getAnimationContainer();
|
155 |
} |
156 |
|
157 |
/**
|
158 |
*
|
159 |
* @param name : Track name.
|
160 |
* @param ac : animation container.
|
161 |
* @return : Return a animation track based in time.
|
162 |
*
|
163 |
* Creating a animation track based in time.
|
164 |
*/
|
165 |
private AnimationTimeTrack getAnimationTimeTrack(String name,AnimationContainer ac) { |
166 |
|
167 |
AnimationTimeTrack at = this.animationTimeTrack;
|
168 |
|
169 |
IAnimationTrack animationTrack= ac.findTrack(name); |
170 |
if (animationTrack == null) { |
171 |
|
172 |
ExtensionPoints extensionPoints = ExtensionPointsSingleton |
173 |
.getInstance(); |
174 |
ExtensionPoint extPoint = ((ExtensionPoint) extensionPoints |
175 |
.get("Animation"));
|
176 |
com.iver.andami.ui.mdiManager.IWindow f = PluginServices // window active.
|
177 |
.getMDIManager().getActiveWindow(); |
178 |
|
179 |
if (f instanceof BaseView) { |
180 |
AnimationTransparency animTransp = null;
|
181 |
try {
|
182 |
System.out.println(extPoint.getDescription());
|
183 |
|
184 |
//Instancing my new animation based in transparency.
|
185 |
animTransp = (AnimationTransparency)extPoint.create("AnimationTransparency");
|
186 |
} catch (InstantiationException e) { |
187 |
// TODO Auto-generated catch block
|
188 |
e.printStackTrace(); |
189 |
} catch (IllegalAccessException e) { |
190 |
e.printStackTrace(); |
191 |
} |
192 |
at = (AnimationTimeTrack) ac.CreateTimeTrack(animTransp); |
193 |
at.setName(name); |
194 |
//Saving the view( in this case a BaseView).
|
195 |
BaseView view = (BaseView)f; |
196 |
at.setAnimatedObject(view); |
197 |
animTransp.setAnimatedObject(view); |
198 |
//My interpolator based in time and transparency.
|
199 |
InterpolatorTransparency interTransparency = new InterpolatorTransparency();
|
200 |
animTransp.setInterpolator(interTransparency); |
201 |
at.setAnimationType(animTransp); |
202 |
interTransparency.setAnimatedObject(view); |
203 |
} |
204 |
} |
205 |
return at;
|
206 |
} |
207 |
|
208 |
/**
|
209 |
* @see com.iver.andami.plugins.IExtension#isVisible()
|
210 |
* Options to see the button in the tool bar.
|
211 |
* View: must be a base view.
|
212 |
* One or more layers in the view.
|
213 |
*/
|
214 |
public boolean isVisible() { |
215 |
com.iver.andami.ui.mdiManager.IWindow f = PluginServices |
216 |
.getMDIManager().getActiveWindow(); |
217 |
|
218 |
if (f == null) { |
219 |
return false; |
220 |
} |
221 |
|
222 |
// Only isVisible = true, where the view have layers.
|
223 |
if (f instanceof BaseView) { |
224 |
BaseView vista = (BaseView) f; |
225 |
IProjectView model = vista.getModel(); |
226 |
MapContext mapa = model.getMapContext(); |
227 |
|
228 |
return mapa.getLayers().getLayersCount() > 0; |
229 |
} |
230 |
return false; |
231 |
} |
232 |
|
233 |
/**
|
234 |
* @see com.iver.andami.plugins.IExtension#isEnabled()
|
235 |
* Options when we can use this animation type.
|
236 |
* View: must be a base view.
|
237 |
* One or more ACTIVATED layers in the view.
|
238 |
*/
|
239 |
public boolean isEnabled() { |
240 |
// TODO Auto-generated method stub
|
241 |
|
242 |
com.iver.andami.ui.mdiManager.IWindow f = PluginServices |
243 |
.getMDIManager().getActiveWindow(); |
244 |
|
245 |
//if the view is not activated.
|
246 |
if (f == null) |
247 |
return false; |
248 |
//if the view is a instance of a base view.
|
249 |
if (f instanceof BaseView ) { |
250 |
BaseView baseView = (BaseView) f; |
251 |
IProjectView model = baseView.getModel(); |
252 |
MapContext mapContext = model.getMapContext(); |
253 |
FLayers layers = mapContext.getLayers(); |
254 |
FLayer[] actives = layers.getActives();
|
255 |
//only is enabled with one or more layers activated.
|
256 |
if (actives.length > 0){ |
257 |
return true; |
258 |
} |
259 |
} |
260 |
return false; |
261 |
} |
262 |
} |
263 |
|