Statistics
| Revision:

svn-gvsig-desktop / trunk / libraries / libAnimationCommon / src / main / java / com / iver / cit / gvsig / animation / animationType / AnimationTransparency.java @ 23596

History | View | Annotate | Download (6.55 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
import com.iver.andami.ui.mdiManager.IWindow;
24
import com.iver.cit.gvsig.animation.IAnimationType;
25
import com.iver.cit.gvsig.animation.animatedObject.AnimationObjectTransparency;
26
import com.iver.cit.gvsig.animation.animatedObject.IAnimatedObject;
27
import com.iver.cit.gvsig.animation.keyFrame.KeyFrameTransparency;
28
import com.iver.cit.gvsig.animation.keyframe.IAnimationTypeKeyFrame;
29
import com.iver.cit.gvsig.animation.keyframe.interpolator.FuntionFactory;
30
import com.iver.cit.gvsig.animation.keyframe.interpolator.IInterpolator;
31
import com.iver.cit.gvsig.animation.keyframe.interpolator.IInterpolatorTimeFuntion;
32
import com.iver.cit.gvsig.fmap.layers.FLyrDefault;
33
import com.iver.cit.gvsig.project.documents.view.gui.BaseView;
34
import com.iver.utiles.IPersistence;
35
import com.iver.utiles.XMLEntity;
36

    
37

    
38
public class AnimationTransparency implements IAnimationTypeKeyFrame {
39

    
40
        private String description = "Animacion basada en Transparencias";
41
        private String name = "AnimationTransparency";
42
        private int typeTrack = IAnimationType.TIME_TYPE_TRACK;
43
        private IInterpolator interpolator;
44
        private String nameView;
45
        private IAnimatedObject animationObjectTransparency = new AnimationObjectTransparency() ;
46
        private String titleWindow;
47

    
48
        public AnimationTransparency() {
49
        }
50

    
51
        public String getClassName() {
52
                return this.getClass().getName();
53
        }
54

    
55
        public String getDescription() {
56
                return description;
57
        }
58

    
59
        public String getName() {
60
                return name;
61
        }
62

    
63
        public void setClassName(String className) {
64
        }
65

    
66
        public void setDescription(String description) {
67
                this.description = description;
68
        }
69

    
70
        public void setName(String name) {
71
                this.name = name;
72
        }
73

    
74
        /**
75
         * 
76
         * @param animate : Object to animate.
77
         *  Application of attributes to our object animated.
78
         *  In this animation the object is a layer(FLyerDefault).
79
         *  Attributes: layer transparency.
80
         *  invalidate(): repaint the view. 
81
         */
82
        
83
        public void AppliesToObject(Object animated) {
84

    
85
                KeyFrameTransparency kf = (KeyFrameTransparency) animated;
86
                FLyrDefault layer = (FLyrDefault)kf.getAnimatedObject();
87
                int trans = (int)kf.getLevelTransparency();
88
                
89
        //        System.err.println("antes: " + System.currentTimeMillis());
90
        //        long antes = System.currentTimeMillis();
91
                
92
                layer.setTransparency(trans);                
93
                layer.setDirty(true);
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.animationObject3DFlat.setAnimatedView(newView);
132
                                                        this.setAnimatedObject(this.animationObjectTransparency);
133
                                                        IInterpolatorTimeFuntion funtion = FuntionFactory.createObject("com.iver.cit.gvsig.animation.keyframe.interpolator.LinearFuntion");
134
                                                        this.interpolator.setFuntion(funtion);
135
                                                }
136
                                        }
137
                                }
138
                        }catch(Exception e) {
139
                                e.printStackTrace();
140
                        }
141
                }
142
                return this.animationObjectTransparency;
143
        }
144

    
145
        public void setAnimatedObject(Object object) {
146
                //this.animationObjectTransparency = (AnimationObjectTransparency) object;
147
                this.animationObjectTransparency = (IAnimatedObject) object;
148
        }
149

    
150
        /*
151
         * IPersistence methods.
152
         */
153
        
154
        public XMLEntity getXMLEntity() {
155
                
156
                
157
                XMLEntity xml = new XMLEntity();
158
                xml.putProperty("className", this.getClassName());
159
                xml.putProperty("description", description);
160
                xml.putProperty("animationTrackTipe", typeTrack);
161
                
162
                BaseView myActualView =  (BaseView) animationObjectTransparency.getAnimatedObject("view");
163
                xml.putProperty("nameClassView", myActualView.getClass().getName());
164
                
165
                titleWindow = myActualView.getWindowInfo().getTitle();
166
                xml.putProperty("titleWindow", titleWindow);
167
                xml.addChild(((IPersistence)this.interpolator).getXMLEntity());
168
                return xml;
169
        }
170

    
171
        public void setXMLEntity(XMLEntity xml) {
172
                
173
                
174
                if (xml.contains("animationTrackTipe"))
175
                        this.typeTrack = xml.getIntProperty("animationTrackTipe");
176
                if (xml.contains("nameView"))
177
                        this.nameView =        xml.getStringProperty("nameView");
178
                
179
                //Acceding to the InterpolatorX of the AnimationTypeX
180
                XMLEntity xmlInterpolator = xml.getChild(0);
181
                try {
182
                        String class_name = xmlInterpolator.getStringProperty("className");
183
                        Class<?> classInterpolator = Class.forName(class_name);
184
                        Object obj = classInterpolator .newInstance();
185
                        IPersistence objPersist = (IPersistence) obj;
186
                        objPersist.setXMLEntity(xmlInterpolator);
187
                        this.interpolator = (IInterpolator) obj;
188
                        this.setInterpolator(interpolator);
189
                        //this.setAnimatedObject();
190
                        
191
                } catch (Exception e) {
192
                        e.printStackTrace();
193
                }
194
                
195
        }
196
}