Revision 15417 import/ext3D/branches/ext3D_v1.1/libAnimation/src/com/iver/cit/gvsig/animation/AnimationPlayer.java

View differences:

AnimationPlayer.java
17 17
 * @author julio
18 18
 * 
19 19
 */
20
public class AnimationPlayer extends TimerTask implements IUpdateCallBack,IPersistance {
20
public class AnimationPlayer extends TimerTask implements IUpdateCallBack,
21
		IPersistance {
21 22

  
22 23
	public AnimationPlayer() {
23 24

  
......
58 59
	private AnimationTimer AT;
59 60

  
60 61
	private boolean pauseFlag = false;
61
	
62
	private double m_length;
63
	
62

  
63
	private static boolean occupied = false;
64

  
64 65
	private static Animation3D a3D;
65 66

  
66 67
	public void play() {
......
69 70

  
70 71
			animationPlayerState = AnimationPlayer.ANIMATION_PLAY;
71 72
			// Timer Set Up
72
//			timer = new Timer();
73
//			timer.scheduleAtFixedRate(this, 0, animationFrequency);
73
			// timer = new Timer();
74
			// timer.scheduleAtFixedRate(this, 0, animationFrequency);
74 75
			AT = new AnimationTimer();
75 76
			AT.addCallBackObject(this);
76 77
			AT.start(animationFrequency);
......
95 96
	public void stop() {
96 97
		System.out.println("toy en metodo stop");
97 98

  
98
		if ((animationPlayerState != AnimationPlayer.ANIMATION_PLAY) || (animationPlayerState != AnimationPlayer.ANIMATION_PAUSE)) {
99
		if ((animationPlayerState != AnimationPlayer.ANIMATION_PLAY)
100
				|| (animationPlayerState != AnimationPlayer.ANIMATION_PAUSE)) {
99 101

  
100 102
			animationPlayerState = AnimationPlayer.ANIMATION_STOP;
101 103
			// Stop timer
102
//			timer.cancel();
103
//			time = 0.0;
104
			// timer.cancel();
105
			// time = 0.0;
104 106

  
105 107
		} else if (animationPlayerState != AnimationPlayer.ANIMATION_RECORD) {
106 108

  
......
150 152
		}
151 153
	}
152 154

  
153
	
154
	
155
	
156 155
	public void setFrameRate(int frameRate) {
157 156
		// TODO generate method to set frame rate
158 157
		this.frameRate = frameRate;
......
168 167
		// TODO generate method to set time
169 168

  
170 169
	}
171
	
170

  
172 171
	public AnimationContainer getAnimationContainer() {
173 172
		return animationContainer;
174 173
	}
......
209 208
			time = (time > this.getGlobalTime()) ? 0 : time;
210 209

  
211 210
			// Apply and repaint all tracks.
212
//			apply(time / this.getGlobalTime(), 0);
211
			// apply(time / this.getGlobalTime(), 0);
213 212

  
214 213
		} else if (this.animationPlayerState == AnimationPlayer.ANIMATION_STOP) {
215 214

  
......
260 259
		// }
261 260
		// }, 0, frequency);
262 261

  
263
//		// Rellenando la estructura de datos
264
//		AnimationContainer AC = new AnimationContainer();
265
//
266
//		// Creando track del tipo de animacion
267
//		AnimationDatedTrack ADTrack = (AnimationDatedTrack) AC
268
//				.CreateDatedTrack(a3D);
269
//		// Inicializando el track
270
//		ADTrack.setName("Track 1");
271
//		ADTrack.setDescription("track de prueba para series temporales");
272
//		ADTrack.setBeginDate(new Date(0));
273
//		ADTrack.setEndDate(new Date(0));
274
//		// Creando intervalo
275
//		AnimationDatedInterval ADInterval = (AnimationDatedInterval) ADTrack
276
//				.createInterval();
277
//
278
//		// Inicializando intervalo
279
//		Date beginDateInterval = new Date(0);
280
//		ADInterval.setBeginDateInterval(beginDateInterval);
281
//		Date endDateInterval = new Date(0);
282
//		ADInterval.setEndDateInterval(endDateInterval);
283
//
284
//		// Creando intervalo
285
//		AnimationDatedInterval ADInterval1 = (AnimationDatedInterval) ADTrack
286
//				.createInterval();
287
//
288
//		// Inicializando intervalo
289
//		Date beginDateInterval1 = new Date(0);
290
//		ADInterval1.setBeginDateInterval(beginDateInterval1);
291
//		Date endDateInterval1 = new Date(0);
292
//		ADInterval1.setEndDateInterval(endDateInterval1);
293
//
262
		// // Rellenando la estructura de datos
263
		// AnimationContainer AC = new AnimationContainer();
264
		//
265
		// // Creando track del tipo de animacion
266
		// AnimationDatedTrack ADTrack = (AnimationDatedTrack) AC
267
		// .CreateDatedTrack(a3D);
268
		// // Inicializando el track
269
		// ADTrack.setName("Track 1");
270
		// ADTrack.setDescription("track de prueba para series temporales");
271
		// ADTrack.setBeginDate(new Date(0));
272
		// ADTrack.setEndDate(new Date(0));
273
		// // Creando intervalo
274
		// AnimationDatedInterval ADInterval = (AnimationDatedInterval) ADTrack
275
		// .createInterval();
276
		//
277
		// // Inicializando intervalo
278
		// Date beginDateInterval = new Date(0);
279
		// ADInterval.setBeginDateInterval(beginDateInterval);
280
		// Date endDateInterval = new Date(0);
281
		// ADInterval.setEndDateInterval(endDateInterval);
282
		//
283
		// // Creando intervalo
284
		// AnimationDatedInterval ADInterval1 = (AnimationDatedInterval) ADTrack
285
		// .createInterval();
286
		//
287
		// // Inicializando intervalo
288
		// Date beginDateInterval1 = new Date(0);
289
		// ADInterval1.setBeginDateInterval(beginDateInterval1);
290
		// Date endDateInterval1 = new Date(0);
291
		// ADInterval1.setEndDateInterval(endDateInterval1);
292
		//
294 293
		AnimationPlayer AP = new AnimationPlayer();
295
//		AP.setAnimationContainer(AC);
294
		// AP.setAnimationContainer(AC);
296 295
		AP.setGlobalTime(10);
297
//		AP.setAnimationContainer(a);
296
		// AP.setAnimationContainer(a);
298 297
		AP.play();
299
		
298

  
300 299
		try {
301 300
			Thread.sleep(3000);
302 301
		} catch (InterruptedException e) {
......
305 304
		}
306 305
		System.out.println("parando");
307 306
		AP.stop();
308
		
309
		
310 307

  
311 308
	}
312 309

  
......
349 346

  
350 347
	public void update() {
351 348
		// TODO Auto-generated method stub
352
//		System.out.println("refresco");
353
		
354
		
355
		
356
		if (this.animationPlayerState == AnimationPlayer.ANIMATION_PLAY) {
349
		// System.out.println("refresco");
357 350

  
358
			// Calculate the delay
359
			double currentTime = System.currentTimeMillis();
360
			double delay = currentTime - preTime;
361
			preTime = currentTime;
362
			// System.out.println("Retardo: " + delay);
351
		if (!occupied) {
352
			occupied = true;
363 353

  
364
			// if the delay could be hightest than the frequency, we have had
365
			// increased the time with this delay
366
			if ((delay > animationFrequency) && (!pauseFlag))
367
				time += delay;
368
			else
369
				time += animationFrequency;
370
			// time += (delay > animationFrequency) ? delay :
371
			// animationFrequency;
354
			if (this.animationPlayerState == AnimationPlayer.ANIMATION_PLAY) {
372 355

  
373
			System.out.println("tiempo: " + time);
374
			time = (time > this.getGlobalTime()) ? 0 : time;
356
				// Calculate the delay
357
				double currentTime = System.currentTimeMillis();
358
				double delay = currentTime - preTime;
359
				preTime = currentTime;
360
				// System.out.println("Retardo: " + delay);
375 361

  
376
			// Apply and repaint all tracks.
377
//			apply(time / this.getGlobalTime(), 0);
362
				// if the delay could be hightest than the frequency, we have
363
				// had
364
				// increased the time with this delay
365
				if ((delay > animationFrequency) && (!pauseFlag))
366
					time += delay;
367
				else
368
					time += animationFrequency;
369
				// time += (delay > animationFrequency) ? delay :
370
				// animationFrequency;
378 371

  
379
		} else if (this.animationPlayerState == AnimationPlayer.ANIMATION_STOP) {
372
//				System.out.println("tiempo: " + time);
373
				time = (time > this.getGlobalTime()) ? 0 : time;
380 374

  
381
		} else if (this.animationPlayerState == AnimationPlayer.ANIMATION_PAUSE) {
375
				// Apply and repaint all tracks.
376
				apply(time / this.getGlobalTime(), 0);
382 377

  
383
			try {
384
				timer.wait();
385
			} catch (InterruptedException e) {
386
				// TODO Auto-generated catch block
387
				e.printStackTrace();
378
			} else if (this.animationPlayerState == AnimationPlayer.ANIMATION_STOP) {
379

  
380
			} else if (this.animationPlayerState == AnimationPlayer.ANIMATION_PAUSE) {
381

  
382
				try {
383
					timer.wait();
384
				} catch (InterruptedException e) {
385
					// TODO Auto-generated catch block
386
					e.printStackTrace();
387
				}
388
			} else if (this.animationPlayerState == AnimationPlayer.ANIMATION_RECORD) {
389

  
388 390
			}
389
		} else if (this.animationPlayerState == AnimationPlayer.ANIMATION_RECORD) {
390

  
391
			// System.out.println("sigo pasando por aki!!!!");
392
			occupied = false;
391 393
		}
392
		System.out.println("sigo pasando por aki!!!!");
394
		System.out.println("ocupado : " + occupied);
393 395
	}
394
	
395 396

  
396 397
	/*	 
397 398
	 * IPersistance methods.
......
416 417

  
417 418
	public void setXMLEntity(XMLEntity xml) {
418 419
		// TODO Auto-generated method stub
420

  
419 421
		
420 422
		if (xml.contains("mode"))
421 423
			mode = xml.getIntProperty("mode");		

Also available in: Unified diff