root / trunk / libraries / libAnimationCommon / src / main / java / com / iver / cit / gvsig / animation / interpolator / InterpolatorTransparency.java @ 23596
History | View | Annotate | Download (4.62 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2005 IVER T.I. and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*/
|
19 |
|
20 |
package com.iver.cit.gvsig.animation.interpolator; |
21 |
|
22 |
import java.util.List; |
23 |
|
24 |
import com.iver.cit.gvsig.animation.animatedObject.AnimationObjectTransparency; |
25 |
import com.iver.cit.gvsig.animation.keyFrame.KeyFrameTransparency; |
26 |
import com.iver.cit.gvsig.animation.keyframe.IKeyFrame; |
27 |
import com.iver.cit.gvsig.animation.keyframe.interpolator.IInterpolator; |
28 |
import com.iver.cit.gvsig.animation.keyframe.interpolator.IInterpolatorTimeFuntion; |
29 |
import com.iver.cit.gvsig.fmap.layers.FLyrDefault; |
30 |
import com.iver.cit.gvsig.project.documents.view.gui.BaseView; |
31 |
import com.iver.utiles.XMLEntity; |
32 |
|
33 |
|
34 |
/**
|
35 |
* Class to interpolate the transparency of a activated layer.
|
36 |
*/
|
37 |
|
38 |
public class InterpolatorTransparency implements IInterpolator { |
39 |
|
40 |
public BaseView view;
|
41 |
private String description = "Interpolaci?n basada en Transparencias"; |
42 |
private String name = "InterpolatorTransparency"; |
43 |
|
44 |
private AnimationObjectTransparency animationObjectTransparency = new AnimationObjectTransparency() ; |
45 |
|
46 |
public IKeyFrame interpolate(List<IKeyFrame> kfList, int index, double time) { |
47 |
KeyFrameTransparency KF = new KeyFrameTransparency();
|
48 |
|
49 |
// if the list of keyframes is empty.
|
50 |
if (kfList == null) |
51 |
return null; |
52 |
|
53 |
|
54 |
switch (kfList.size()) {
|
55 |
// this case when there are only has 2 keyframes
|
56 |
case 2: |
57 |
|
58 |
KeyFrameTransparency kf1 = (KeyFrameTransparency) kfList.get(0);
|
59 |
KeyFrameTransparency kf2 = (KeyFrameTransparency) kfList.get(1);
|
60 |
|
61 |
if (index == 1) { |
62 |
KeyFrameTransparency kaux = kf1; |
63 |
kf1 = kf2; |
64 |
kf2 = kaux; |
65 |
} |
66 |
|
67 |
if ((kf1 == null) ||(kf2 == null)) |
68 |
return null; |
69 |
//initial transparency level.
|
70 |
double transparencia1 = kf1.getLevelTransparency();
|
71 |
//final transparency level.
|
72 |
double transparencia2 = kf2.getLevelTransparency();
|
73 |
|
74 |
// Object to animate getting the keyframe.
|
75 |
FLyrDefault fd1 = (FLyrDefault) kf1.getAnimatedObject(); |
76 |
//FLyrDefault fd2 = (FLyrDefault) kf2.getAnimatedObject();
|
77 |
|
78 |
double time1 = kf1.getTime();//initial time. |
79 |
double time2 = kf2.getTime();//final time. |
80 |
double valorTrans = linearInterpolate(transparencia1, transparencia2, time1, time2, time);
|
81 |
System.out.println("valor interpolado " + valorTrans); |
82 |
|
83 |
//Creating the keyframe KF to return.
|
84 |
try {
|
85 |
KF.setLevelTransparency((int)valorTrans);
|
86 |
KF.setAnimatedObject(fd1);// keyframe with the layer and the new transparecy to apply.
|
87 |
} catch (Exception e) { |
88 |
// TODO Auto-generated catch block
|
89 |
e.printStackTrace(); |
90 |
} |
91 |
} |
92 |
return KF;
|
93 |
} |
94 |
|
95 |
|
96 |
private double linearInterpolate(double minX, double minX2, double timePos, |
97 |
double timePos2, double time) { |
98 |
// P1 + (P2-P1)*((t-t1)/(t2-t1))
|
99 |
return (minX + (minX2 - minX)
|
100 |
* ((time - timePos) / (timePos2 - timePos))); |
101 |
} |
102 |
|
103 |
|
104 |
public Object getAnimatedObject() { |
105 |
return this.animationObjectTransparency; |
106 |
} |
107 |
|
108 |
|
109 |
public void setAnimatedObject(Object object) { |
110 |
this.animationObjectTransparency = (AnimationObjectTransparency) object;
|
111 |
this.view = (BaseView) animationObjectTransparency.getAnimatedView();
|
112 |
} |
113 |
|
114 |
public IInterpolatorTimeFuntion getFuntion() {
|
115 |
return null; |
116 |
} |
117 |
|
118 |
|
119 |
public void setFuntion(IInterpolatorTimeFuntion arg0) { |
120 |
// TODO Auto-generated method stub
|
121 |
} |
122 |
|
123 |
public String getClassName() { |
124 |
return this.getClass().getName(); |
125 |
} |
126 |
|
127 |
public String getDescription() { |
128 |
return this.description; |
129 |
} |
130 |
|
131 |
public String getName() { |
132 |
return this.name; |
133 |
} |
134 |
|
135 |
/*
|
136 |
* IPersistence methods.
|
137 |
*/
|
138 |
|
139 |
public XMLEntity getXMLEntity() {
|
140 |
XMLEntity xml = new XMLEntity();
|
141 |
xml.putProperty("className", this.getClassName()); |
142 |
xml.putProperty("description", this.description); |
143 |
return xml;
|
144 |
} |
145 |
|
146 |
public void setXMLEntity(XMLEntity xml) { |
147 |
if (xml.contains("description")) |
148 |
this.description = xml.getStringProperty("description"); |
149 |
} |
150 |
|
151 |
} |