Statistics
| Revision:

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

History | View | Annotate | Download (6.3 KB)

1
package com.iver.cit.gvsig.animation.animationType;
2

    
3
import com.iver.ai2.gvsig3dgui.view.View3D;
4
import com.iver.andami.PluginServices;
5
import com.iver.andami.ui.mdiManager.IWindow;
6
import com.iver.cit.gvsig.animation.IAnimationType;
7
import com.iver.cit.gvsig.animation.animatedObject.AnimationObjectTransparency;
8
import com.iver.cit.gvsig.animation.animatedObject.IAnimatedObject;
9
import com.iver.cit.gvsig.animation.keyFrame.KeyFrameTransparency;
10
import com.iver.cit.gvsig.animation.keyframe.IAnimationTypeKeyFrame;
11
import com.iver.cit.gvsig.animation.keyframe.interpolator.FuntionFactory;
12
import com.iver.cit.gvsig.animation.keyframe.interpolator.IInterpolator;
13
import com.iver.cit.gvsig.animation.keyframe.interpolator.IInterpolatorTimeFuntion;
14
import com.iver.cit.gvsig.fmap.layers.FLyrDefault;
15
import com.iver.cit.gvsig.project.documents.view.gui.BaseView;
16
import com.iver.utiles.IPersistence;
17
import com.iver.utiles.XMLEntity;
18

    
19

    
20
public class AnimationTransparency implements IAnimationTypeKeyFrame {
21

    
22
        private String className;// = this.getClass().getName();
23
        private String description = "Animacion basada en Transparencias";
24
        private String name = "AnimationTransparency";
25
        private int typeTrack = IAnimationType.TIME_TYPE_TRACK;
26
        private IInterpolator interpolator;
27
        private BaseView view;
28
        String nameView;
29
        //private AnimationObjectTransparency animationObjectTransparency;
30
        private IAnimatedObject animationObjectTransparency = new AnimationObjectTransparency() ;
31
        private String titleWindow;
32

    
33
        public AnimationTransparency() {
34
        }
35

    
36
        public String getClassName() {
37
                return this.getClass().getName();
38
        }
39

    
40
        public String getDescription() {
41
                return description;
42
        }
43

    
44
        public String getName() {
45
                return name;
46
        }
47

    
48
        public void setClassName(String className) {
49
                this.className = className;
50
        }
51

    
52
        public void setDescription(String description) {
53
                this.description = description;
54
        }
55

    
56
        public void setName(String name) {
57
                this.name = name;
58
        }
59

    
60
        /**
61
         * 
62
         * @param animate : Object to animate.
63
         *  Application of attributes to our object animated.
64
         *  In this animation the object is a layer(FLyerDefault).
65
         *  Attributes: layer transparency.
66
         *  invalidate(): repaint the view. 
67
         */
68
        
69
        public void AppliesToObject(Object animated) {
70

    
71
                KeyFrameTransparency kf = (KeyFrameTransparency) animated;
72
                FLyrDefault layer = (FLyrDefault)kf.getAnimatedObject();
73
                int trans = (int)kf.getLevelTransparency();
74
                
75
        //        System.err.println("antes: " + System.currentTimeMillis());
76
        //        long antes = System.currentTimeMillis();
77
                
78
                layer.setTransparency(trans);                
79
                layer.setDirty(true);
80
                layer.getMapContext().invalidate();
81
                
82
        //        System.err.println("despues: " + System.currentTimeMillis());
83
        //        long despues = System.currentTimeMillis();
84
        //        System.err.println("intervalo de tiempo: " + (despues-antes));
85
                
86
                System.err.println("aplicando transparencia " + trans + " al objeto " + layer.getName());
87
        }
88

    
89
        public int getTypeTrack() {
90
                return typeTrack;
91
        }
92

    
93
        public void setTypeTrack(int typeTrack) {
94
                this.typeTrack = typeTrack;
95
        }
96

    
97
        public IInterpolator getInterpolator() {
98
                return this.interpolator;
99
        }
100

    
101
        public void setInterpolator(IInterpolator interpolator) {
102
                this.interpolator = interpolator;
103
        }
104

    
105
        public Object getAnimatedObject() {
106
                if(this.animationObjectTransparency != null){
107
                        // getting all views.
108
                        try{
109
                                IWindow[] viewArray = PluginServices.getMDIManager().getAllWindows();
110
                                for (int i = 0; i < viewArray.length; i++) {
111
                                        IWindow window = viewArray[i];
112
                                        if (window.getClass().getName().equals(this.nameView)){
113
                                                // get the actual name of the view, and compare it with the view saved in xml.
114
                                                if(window.getWindowInfo().getTitle().equals(this.titleWindow)){
115
                                                        BaseView newView = (BaseView)window;
116
                                                        this.animationObjectTransparency.addAnimatedObject("view", newView);
117
//                                                        this.animationObject3DFlat.setAnimatedView(newView);
118
                                                        this.setAnimatedObject(this.animationObjectTransparency);
119
                                                        IInterpolatorTimeFuntion funtion = FuntionFactory.createObject("com.iver.cit.gvsig.animation.keyframe.interpolator.LinearFuntion");
120
                                                        this.interpolator.setFuntion(funtion);
121
                                                }
122
                                        }
123
                                }
124
                        }catch(Exception e) {
125
                                e.printStackTrace();
126
                        }
127
                }
128
                return this.animationObjectTransparency;
129
        }
130

    
131
        public void setAnimatedObject(Object object) {
132
                //this.animationObjectTransparency = (AnimationObjectTransparency) object;
133
                this.animationObjectTransparency = (IAnimatedObject) object;
134
        }
135

    
136
        /*
137
         * IPersistence methods.
138
         */
139
        
140
        public XMLEntity getXMLEntity() {
141
                
142
                //View3D myActualView = null;
143
                
144
                XMLEntity xml = new XMLEntity();
145
                xml.putProperty("className", this.getClassName());
146
                xml.putProperty("description", description);
147
                xml.putProperty("animationTrackTipe", typeTrack);
148
                //xml.putProperty("nameClassView", animationObjectTransparency.getNameView());
149
                //myActualView = (View3D) animationObjectTransparency.getAnimatedView();
150
                
151
                View3D myActualView = (View3D) animationObjectTransparency.getAnimatedObject("view");
152
                xml.putProperty("nameClassView", myActualView.getClass().getName());
153
                
154
                
155
                
156
                titleWindow = myActualView.getWindowInfo().getTitle();
157
                xml.putProperty("titleWindow", titleWindow);
158
                xml.addChild(((IPersistence)this.interpolator).getXMLEntity());
159
                return xml;
160
        }
161

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