Statistics
| Revision:

svn-gvsig-desktop / import / ext3D / branches / ext3D_v1.1 / libAnimation / src / com / iver / cit / gvsig / animation / AnimationContainer.java @ 15445

History | View | Annotate | Download (4.8 KB)

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

    
3
import java.util.ArrayList;
4
import java.util.List;
5

    
6
import com.iver.cit.gvsig.animation.traks.AnimationDatedTrack;
7
import com.iver.cit.gvsig.animation.traks.AnimationTimeTrack;
8
import com.iver.cit.gvsig.animation.traks.IAnimationTrack;
9
import com.iver.utiles.IPersistance;
10
import com.iver.utiles.XMLEntity;
11

    
12
public class AnimationContainer implements IPersistance{
13

    
14
        // IAnimationTrakc List
15
        public List AnimationTrackList;
16

    
17
        private String className;
18
        
19
        private static AnimationPlayer animationPlayer = new AnimationPlayer();
20

    
21
        public AnimationContainer() {
22
                List aniTrackList = this.getAnimationTrackList();
23
                aniTrackList = new ArrayList();
24
                this.setAnimationTrackList(aniTrackList);
25
        }
26

    
27
        /**
28
         * @param animationType
29
         * @return
30
         */
31
        public List getTackListOfType(IAnimationType animationType) {
32
                List typeList = new ArrayList();
33
                for (int i = 0; i < this.AnimationTrackList.size(); i++) {
34
                        IAnimationTrack trackElement = (IAnimationTrack) this.AnimationTrackList
35
                                        .get(i);
36
                        if (animationType.getClassName().equals(
37
                                        trackElement.getAnimationType().getClassName())) {
38
                                typeList.add(trackElement);
39
                        }
40

    
41
                }
42
                return typeList;
43
        }
44

    
45
        /**
46
         * @param animationType
47
         * @return
48
         */
49
        public IAnimationTrack CreateDatedTrack(IAnimationType animationType) {
50

    
51
                List aniTrackList = this.getAnimationTrackList();
52
                if (aniTrackList == null) {
53
                        aniTrackList = new ArrayList();
54
                }
55
                AnimationDatedTrack ADTrack = new AnimationDatedTrack(animationType);
56
                aniTrackList.add(ADTrack);
57
                this.setAnimationTrackList(aniTrackList);
58
                return ADTrack;
59
        }
60

    
61
        public IAnimationTrack CreateTimeTrack(IAnimationType animationType) {
62

    
63
                List aniTrackList = this.getAnimationTrackList();
64
                if (aniTrackList == null) {
65
                        aniTrackList = new ArrayList();
66
                }
67
                AnimationTimeTrack ADTrack = new AnimationTimeTrack(animationType);
68
                aniTrackList.add(ADTrack);
69
                this.setAnimationTrackList(aniTrackList);
70
                return ADTrack;
71
        }
72

    
73
        /**
74
         * @param animationTrack
75
         */
76
        public void addTrack(IAnimationTrack animationTrack) {
77
                IAnimationTrack track = findTrack(animationTrack.getName());
78
                if (track == null) {
79
                        this.AnimationTrackList.add(animationTrack);
80
                }
81
        }
82

    
83
        /**
84
         * @param name
85
         * @return
86
         */
87
        public IAnimationTrack findTrack(String name) {
88

    
89
                IAnimationTrack IAT = null;
90
                for (int i = 0; i < this.AnimationTrackList.size(); i++) {
91
                        IAnimationTrack trackElement = (IAnimationTrack) this.AnimationTrackList
92
                                        .get(i);
93
                        if (trackElement.getName().equals(name)) {
94
                                IAT = trackElement;
95
                        }
96

    
97
                }
98
                return IAT;
99
        }
100

    
101
        /**
102
         * @param animationTrack
103
         */
104
        public void removeTrack(IAnimationTrack animationTrack) {
105
                animationTrack.removeAllIntervals();
106
                this.AnimationTrackList.remove(animationTrack);
107
        }
108

    
109
        /**
110
         * 
111
         */
112
        public void removeAllTrack() {
113
                this.AnimationTrackList.clear();
114
        }
115

    
116
        /**
117
         * @return
118
         */
119
        public List getAnimationTrackList() {
120
                return AnimationTrackList;
121
        }
122

    
123
        /**
124
         * @param animationTrackList
125
         */
126
        public void setAnimationTrackList(List animationTrackList) {
127
                AnimationTrackList = animationTrackList;
128
        }
129

    
130
        /*         
131
         * IPersistance methods.
132
         */
133
        
134
        public String getClassName() {
135
                // TODO Auto-generated method stub
136
                return this.getClass().getName();                
137
        }
138
        
139
        /**
140
         * @return
141
         */
142
        public XMLEntity getXMLEntity() {
143
                XMLEntity xml = new XMLEntity();
144
                xml.putProperty("class_name", this.getClassName());                
145
                for (int i = 0; i < this.AnimationTrackList.size(); i++) {                        
146
                        IAnimationTrack trackElement = (IAnimationTrack) this.AnimationTrackList.get(i);                        
147
                        trackElement.getXMLEntity();
148
                }                
149
                return xml;
150
        }
151

    
152
        /**
153
         * @param xml
154
         */
155
        public void setXMLEntity(XMLEntity xml) {
156
                if (xml.contains("class_name"))
157
                        className = xml.getStringProperty("class_name");        
158
                for (int i = 0; i < this.AnimationTrackList.size(); i++) {
159
                        IAnimationTrack trackElement = (IAnimationTrack) this.AnimationTrackList.get(i);                        
160
                        trackElement.setXMLEntity(xml);                        
161
                }                                        
162
        }
163

    
164
        public String toString() {
165
                String result = "";
166
                List ATL = this.AnimationTrackList;
167
                result += "Mostrando lista de tracks:";
168
                if ((ATL == null) || ATL.isEmpty()) {
169
                        result += "\nLista vacia";
170
                } else {
171
                        for (int i = 0; i < ATL.size(); i++) {
172
                                Object element = ATL.get(i);
173
                                result += "\n" + element;
174
                        }
175
                }
176
                return result;
177

    
178
        }
179

    
180
        public void apply(double Tini, double Tend) {
181
                List ATL = this.AnimationTrackList;
182
                System.out.println("Tiempo de inicio: " + Tini + " tiempo final "
183
                                + Tend);
184
                if ((ATL != null) && !ATL.isEmpty()) {
185
                        for (int i = 0; i < ATL.size(); i++) {
186
                                IAnimationTrack element = (IAnimationTrack) ATL.get(i);
187
                                element.apply(Tini, Tend);
188
                        }
189
                }
190
        }
191

    
192
        public AnimationPlayer getAnimationPlayer() {
193
                return this.animationPlayer;
194
        }
195
}