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