svn-gvsig-desktop / import / ext3D / branches / ext3D_v1.1 / libAnimation / src / com / iver / cit / gvsig / animation / interval / AnimationKeyFrameInterval.java @ 15445
History | View | Annotate | Download (4.27 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 |
import com.iver.cit.gvsig.animation.IAnimationType; |
7 |
|
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.project.ProjectExtent; |
12 |
import com.iver.cit.gvsig.project.documents.view.gui.View; |
13 |
import com.iver.utiles.XMLEntity; |
14 |
|
15 |
public class AnimationKeyFrameInterval implements IAnimationTimeInterval { |
16 |
|
17 |
private List KeyFrameList; |
18 |
|
19 |
private double initialTime = 0; |
20 |
|
21 |
private double endTime = 1; |
22 |
|
23 |
private double intervalTime = endTime - initialTime; |
24 |
|
25 |
private String className; |
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 |
boolean asigned = false; |
93 |
if (KFtime <= tini) {
|
94 |
if (previus != null) { |
95 |
if (KFtime > previus.getTime())
|
96 |
previus = element; |
97 |
} else {
|
98 |
previus = element; |
99 |
} |
100 |
asigned = true;
|
101 |
} |
102 |
if ((KFtime > tini) && (!asigned)) {
|
103 |
if (next != null) { |
104 |
if (KFtime < previus.getTime())
|
105 |
next = element; |
106 |
} else {
|
107 |
next = element; |
108 |
} |
109 |
|
110 |
} |
111 |
|
112 |
} |
113 |
KFLInterpolate.add(previus); |
114 |
KFLInterpolate.add(next); |
115 |
} |
116 |
|
117 |
IKeyFrame frame = null;
|
118 |
if (KFLInterpolate != null) { |
119 |
// IInterpolator in = (IInterpolator) interpolator;
|
120 |
frame = interpolator.interpolate(KFLInterpolate, 0, tini);
|
121 |
} |
122 |
if (frame != null) |
123 |
animationType.AppliesToObject(frame); |
124 |
|
125 |
} |
126 |
|
127 |
public XMLEntity getXMLEntity() {
|
128 |
// TODO Auto-generated method stub
|
129 |
XMLEntity xml = new XMLEntity();
|
130 |
|
131 |
xml.putProperty("class_name", this.getClassName()); |
132 |
xml.putProperty("begin_time", initialTime);
|
133 |
xml.putProperty("end_time", endTime);
|
134 |
xml.putProperty("interval_time", intervalTime);
|
135 |
|
136 |
/* for (int i = 0; i < this.KeyFrameList.size(); i++) {
|
137 |
IKeyFrame keyFrameItem = (IKeyFrame) this.KeyFrameList.get(i);
|
138 |
keyFrameItem.getXMLEntity();
|
139 |
} */
|
140 |
return xml;
|
141 |
|
142 |
} |
143 |
|
144 |
public void setXMLEntity(XMLEntity xml) { |
145 |
// TODO Auto-generated method stub
|
146 |
|
147 |
if (xml.contains("class_name")) |
148 |
className= xml.getStringProperty("class_name");
|
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 |
|
156 |
/* for (int i = 0; i < this.KeyFrameList.size(); i++) {
|
157 |
IKeyFrame keyFrameItem = (IKeyFrame) this.KeyFrameList.get(i);
|
158 |
keyFrameItem.setXMLEntity(xml);
|
159 |
}*/
|
160 |
|
161 |
} |
162 |
|
163 |
public String getClassName() { |
164 |
// TODO Auto-generated method stub
|
165 |
return this.getClass().getName(); |
166 |
} |
167 |
} |