svn-gvsig-desktop / import / ext3D / branches / ext3D_v1.1 / libAnimation / src / com / iver / cit / gvsig / animation / interval / AnimationKeyFrameInterval.java @ 15416
History | View | Annotate | Download (4.17 KB)
1 |
package com.iver.cit.gvsig.animation.interval; |
---|---|
2 |
|
3 |
import java.util.ArrayList; |
4 |
import java.util.Iterator; |
5 |
import java.util.List; |
6 |
|
7 |
import com.iver.cit.gvsig.animation.IAnimationType; |
8 |
import com.iver.cit.gvsig.animation.keyframe.IAnimationTypeKeyFrame; |
9 |
import com.iver.cit.gvsig.animation.keyframe.IInterpolator; |
10 |
import com.iver.cit.gvsig.animation.keyframe.IKeyFrame; |
11 |
import com.iver.cit.gvsig.animation.test.Interpolator2D; |
12 |
import com.iver.cit.gvsig.animation.test.KeyFrame2D; |
13 |
import com.iver.cit.gvsig.project.ProjectExtent; |
14 |
import com.iver.cit.gvsig.project.documents.view.gui.View; |
15 |
import com.iver.utiles.XMLEntity; |
16 |
|
17 |
public class AnimationKeyFrameInterval implements IAnimationTimeInterval { |
18 |
|
19 |
private List KeyFrameList; |
20 |
|
21 |
private double initialTime = 0; |
22 |
|
23 |
private double endTime = 1; |
24 |
|
25 |
private double intervalTime = endTime - initialTime; |
26 |
|
27 |
public List getKeyFrameList() { |
28 |
return KeyFrameList;
|
29 |
} |
30 |
|
31 |
public void setKeyFrameList(List keyFrameList) { |
32 |
KeyFrameList = keyFrameList; |
33 |
} |
34 |
|
35 |
public double getEndTime() { |
36 |
return endTime;
|
37 |
} |
38 |
|
39 |
public double getInitialTime() { |
40 |
return initialTime;
|
41 |
} |
42 |
|
43 |
public double getIntervalTime() { |
44 |
return (endTime - initialTime);
|
45 |
} |
46 |
|
47 |
public void setEndTime(double time) { |
48 |
this.endTime = time;
|
49 |
|
50 |
} |
51 |
|
52 |
public void setInitialTime(double time) { |
53 |
this.initialTime = time;
|
54 |
} |
55 |
|
56 |
public void setIntervalTime(double time) { |
57 |
this.intervalTime = time;
|
58 |
} |
59 |
|
60 |
public String toString() { |
61 |
|
62 |
String result;
|
63 |
List KFL = this.KeyFrameList; |
64 |
if (KFL != null) { |
65 |
result = "Mostrando lista de KeyFrames del intervalo Tini:"
|
66 |
+ this.getInitialTime() + " Tend" + this.getEndTime(); |
67 |
for (Iterator iter = KFL.iterator(); iter.hasNext();) { |
68 |
Object element = (Object) iter.next(); |
69 |
result += "\n" + element;
|
70 |
} |
71 |
} else {
|
72 |
result = "Lista de key frame vacia";
|
73 |
} |
74 |
return result;
|
75 |
} |
76 |
|
77 |
public void apply(double tini, double tend, IAnimationType animationType, |
78 |
Object animated) {
|
79 |
|
80 |
IAnimationTypeKeyFrame animationTypeFrame = (IAnimationTypeKeyFrame) animationType; |
81 |
IInterpolator interpolator = animationTypeFrame.getInterpolator(); |
82 |
|
83 |
IKeyFrame previus = null;
|
84 |
IKeyFrame next = null;
|
85 |
List KFLInterpolate = new ArrayList(); |
86 |
|
87 |
List KFL = this.KeyFrameList; |
88 |
if (KFL != null) { |
89 |
for (Iterator iter = KFL.iterator(); iter.hasNext();) { |
90 |
IKeyFrame element = (IKeyFrame) iter.next(); |
91 |
double KFtime = element.getTime();
|
92 |
if (KFtime <= tini) {
|
93 |
if (previus != null) { |
94 |
if (KFtime > previus.getTime())
|
95 |
previus = element; |
96 |
} else {
|
97 |
previus = element; |
98 |
} |
99 |
|
100 |
|
101 |
} |
102 |
if (KFtime > tini) {
|
103 |
if (next != null) { |
104 |
if (KFtime < previus.getTime())
|
105 |
next = element; |
106 |
} else {
|
107 |
next = element; |
108 |
} |
109 |
|
110 |
} |
111 |
|
112 |
|
113 |
} |
114 |
KFLInterpolate.add(previus); |
115 |
KFLInterpolate.add(next); |
116 |
} |
117 |
|
118 |
IKeyFrame frame = null;
|
119 |
if (KFLInterpolate != null) { |
120 |
// IInterpolator in = (IInterpolator) interpolator;
|
121 |
frame = interpolator.interpolate(KFLInterpolate, 0, tini);
|
122 |
} |
123 |
|
124 |
animationType.AppliesToObject(frame); |
125 |
|
126 |
|
127 |
|
128 |
} |
129 |
|
130 |
public XMLEntity getXMLEntity() {
|
131 |
// TODO Auto-generated method stub
|
132 |
XMLEntity xml = new XMLEntity();
|
133 |
xml.putProperty("className", this.getClassName()); |
134 |
|
135 |
xml.putProperty("begin_time", initialTime);
|
136 |
xml.putProperty("end_time", endTime);
|
137 |
xml.putProperty("interval_time", intervalTime);
|
138 |
|
139 |
for (int i = 0; i < this.KeyFrameList.size(); i++) { |
140 |
IKeyFrame keyFrameItem = (IKeyFrame) this.KeyFrameList.get(i);
|
141 |
keyFrameItem.getXMLEntity(); |
142 |
} |
143 |
return null; |
144 |
} |
145 |
|
146 |
public void setXMLEntity(XMLEntity xml) { |
147 |
// TODO Auto-generated method stub
|
148 |
|
149 |
if (xml.contains("begin_time")) |
150 |
initialTime = xml.getDoubleProperty("begin_time");
|
151 |
if (xml.contains("end_time")) |
152 |
endTime = xml.getDoubleProperty("end_time");
|
153 |
if (xml.contains("interval_time")) |
154 |
intervalTime = xml.getDoubleProperty("interval_time");
|
155 |
for (int i = 0; i < this.KeyFrameList.size(); i++) { |
156 |
IKeyFrame keyFrameItem = (IKeyFrame) this.KeyFrameList.get(i);
|
157 |
keyFrameItem.setXMLEntity(xml); |
158 |
} |
159 |
|
160 |
} |
161 |
|
162 |
public String getClassName() { |
163 |
// TODO Auto-generated method stub
|
164 |
return this.getClass().getName(); |
165 |
} |
166 |
} |