root / trunk / libraries / libAnimationCommon / src / main / java / com / iver / cit / gvsig / animation / animationType / AnimationTransparency.java @ 25870
History | View | Annotate | Download (6.44 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.animationType; |
21 |
|
22 |
import com.iver.andami.PluginServices; |
23 |
|
24 |
import com.iver.andami.ui.mdiManager.IWindow; |
25 |
import com.iver.cit.gvsig.animation.IAnimationType; |
26 |
import com.iver.cit.gvsig.animation.animatedObject.AnimationObjectTransparency; |
27 |
import com.iver.cit.gvsig.animation.animatedObject.IAnimatedObject; |
28 |
import com.iver.cit.gvsig.animation.keyFrame.KeyFrameTransparency; |
29 |
import com.iver.cit.gvsig.animation.keyframe.IAnimationTypeKeyFrame; |
30 |
import com.iver.cit.gvsig.animation.keyframe.interpolator.FuntionFactory; |
31 |
import com.iver.cit.gvsig.animation.keyframe.interpolator.IInterpolator; |
32 |
import com.iver.cit.gvsig.animation.keyframe.interpolator.IInterpolatorTimeFuntion; |
33 |
import com.iver.cit.gvsig.fmap.layers.FLyrDefault; |
34 |
import com.iver.cit.gvsig.project.documents.view.gui.BaseView; |
35 |
import com.iver.utiles.IPersistence; |
36 |
import com.iver.utiles.XMLEntity; |
37 |
|
38 |
|
39 |
/**
|
40 |
* @author ?ngel Fraile Gri??n e-mail: angel.fraile@iver.es
|
41 |
* @since 1.1
|
42 |
*
|
43 |
*/
|
44 |
public class AnimationTransparency implements IAnimationTypeKeyFrame { |
45 |
|
46 |
private String description = "Animacion basada en Transparencias"; |
47 |
private String name = "AnimationTransparency"; |
48 |
private int typeTrack = IAnimationType.TIME_TYPE_TRACK; |
49 |
private IInterpolator interpolator;
|
50 |
private String nameView; |
51 |
private IAnimatedObject animationObjectTransparency = new AnimationObjectTransparency() ; |
52 |
private String titleWindow; |
53 |
|
54 |
public AnimationTransparency() {
|
55 |
} |
56 |
|
57 |
public String getClassName() { |
58 |
return this.getClass().getName(); |
59 |
} |
60 |
|
61 |
public String getDescription() { |
62 |
return description;
|
63 |
} |
64 |
|
65 |
public String getName() { |
66 |
return name;
|
67 |
} |
68 |
|
69 |
public void setClassName(String className) { |
70 |
} |
71 |
|
72 |
public void setDescription(String description) { |
73 |
this.description = description;
|
74 |
} |
75 |
|
76 |
public void setName(String name) { |
77 |
this.name = name;
|
78 |
} |
79 |
|
80 |
/**
|
81 |
*
|
82 |
* @param animate : Object to animate.
|
83 |
* Application of attributes to our object animated.
|
84 |
* In this animation the object is a layer(FLyerDefault).
|
85 |
* Attributes: layer transparency.
|
86 |
* invalidate(): repaint the view.
|
87 |
*/
|
88 |
|
89 |
public void AppliesToObject(Object animated) { |
90 |
|
91 |
KeyFrameTransparency kf = (KeyFrameTransparency) animated; |
92 |
FLyrDefault layer = (FLyrDefault)kf.getAnimatedObject(); |
93 |
int trans = (int)kf.getLevelTransparency(); |
94 |
|
95 |
// System.err.println("antes: " + System.currentTimeMillis());
|
96 |
// long antes = System.currentTimeMillis();
|
97 |
|
98 |
layer.setTransparency(trans); |
99 |
layer.getMapContext().invalidate(); |
100 |
|
101 |
// System.err.println("despues: " + System.currentTimeMillis());
|
102 |
// long despues = System.currentTimeMillis();
|
103 |
// System.err.println("intervalo de tiempo: " + (despues-antes));
|
104 |
|
105 |
} |
106 |
|
107 |
public int getTypeTrack() { |
108 |
return typeTrack;
|
109 |
} |
110 |
|
111 |
public void setTypeTrack(int typeTrack) { |
112 |
this.typeTrack = typeTrack;
|
113 |
} |
114 |
|
115 |
public IInterpolator getInterpolator() {
|
116 |
return this.interpolator; |
117 |
} |
118 |
|
119 |
public void setInterpolator(IInterpolator interpolator) { |
120 |
this.interpolator = interpolator;
|
121 |
} |
122 |
|
123 |
/**
|
124 |
* Getting the animated object, in movement track animation; the view
|
125 |
*/
|
126 |
public Object getAnimatedObject() { |
127 |
if(this.animationObjectTransparency != null){ |
128 |
// getting all views.
|
129 |
try{
|
130 |
IWindow[] viewArray = PluginServices.getMDIManager().getAllWindows();
|
131 |
for (int i = 0; i < viewArray.length; i++) { |
132 |
IWindow window = viewArray[i]; |
133 |
if (window.getClass().getName().equals(this.nameView)){ |
134 |
// get the actual name of the view, and compare it with the view saved in xml.
|
135 |
if(window.getWindowInfo().getTitle().equals(this.titleWindow)){ |
136 |
BaseView newView = (BaseView)window; |
137 |
this.animationObjectTransparency.addAnimatedObject("view", newView); |
138 |
this.setAnimatedObject(this.animationObjectTransparency); |
139 |
IInterpolatorTimeFuntion funtion = FuntionFactory.createObject("com.iver.cit.gvsig.animation.keyframe.interpolator.LinearFuntion");
|
140 |
this.interpolator.setFuntion(funtion);
|
141 |
} |
142 |
} |
143 |
} |
144 |
}catch(Exception e) { |
145 |
e.printStackTrace(); |
146 |
} |
147 |
} |
148 |
return this.animationObjectTransparency; |
149 |
} |
150 |
|
151 |
public void setAnimatedObject(Object object) { |
152 |
this.animationObjectTransparency = (IAnimatedObject) object;
|
153 |
} |
154 |
|
155 |
/*
|
156 |
* IPersistence methods.
|
157 |
*/
|
158 |
|
159 |
public XMLEntity getXMLEntity() {
|
160 |
|
161 |
|
162 |
XMLEntity xml = new XMLEntity();
|
163 |
xml.putProperty("className", this.getClassName()); |
164 |
xml.putProperty("description", description);
|
165 |
xml.putProperty("animationTrackTipe", typeTrack);
|
166 |
|
167 |
BaseView myActualView = (BaseView) animationObjectTransparency.getAnimatedObject("view");
|
168 |
xml.putProperty("nameClassView", myActualView.getClass().getName());
|
169 |
|
170 |
titleWindow = myActualView.getWindowInfo().getTitle(); |
171 |
xml.putProperty("titleWindow", titleWindow);
|
172 |
xml.addChild(((IPersistence)this.interpolator).getXMLEntity());
|
173 |
return xml;
|
174 |
} |
175 |
|
176 |
public void setXMLEntity(XMLEntity xml) { |
177 |
|
178 |
|
179 |
if (xml.contains("animationTrackTipe")) |
180 |
this.typeTrack = xml.getIntProperty("animationTrackTipe"); |
181 |
if (xml.contains("nameView")) |
182 |
this.nameView = xml.getStringProperty("nameView"); |
183 |
|
184 |
//Acceding to the InterpolatorX of the AnimationTypeX
|
185 |
XMLEntity xmlInterpolator = xml.getChild(0);
|
186 |
try {
|
187 |
String class_name = xmlInterpolator.getStringProperty("className"); |
188 |
Class<?> classInterpolator = Class.forName(class_name); |
189 |
Object obj = classInterpolator .newInstance();
|
190 |
IPersistence objPersist = (IPersistence) obj; |
191 |
objPersist.setXMLEntity(xmlInterpolator); |
192 |
this.interpolator = (IInterpolator) obj;
|
193 |
this.setInterpolator(interpolator);
|
194 |
|
195 |
} catch (Exception e) { |
196 |
e.printStackTrace(); |
197 |
} |
198 |
|
199 |
} |
200 |
} |