svn-gvsig-desktop / trunk / extensions / extAnimationGUI / src / com / iver / ai2 / animationgui / gui / AnimationContol3D.java @ 23105
History | View | Annotate | Download (15.2 KB)
1 |
/*
|
---|---|
2 |
* Controles que aparacen una vez pulsado el bot?n del grupo animaci?n,"control de animaci?n".
|
3 |
*
|
4 |
*/
|
5 |
|
6 |
package com.iver.ai2.animationgui.gui; |
7 |
|
8 |
import java.awt.Checkbox; |
9 |
import java.awt.Dimension; |
10 |
import java.awt.GridBagConstraints; |
11 |
import java.awt.Insets; |
12 |
import java.awt.event.ActionEvent; |
13 |
import java.awt.event.ActionListener; |
14 |
import java.awt.event.ItemEvent; |
15 |
import java.awt.event.ItemListener; |
16 |
import java.awt.event.KeyEvent; |
17 |
import java.awt.event.KeyListener; |
18 |
import java.net.URL; |
19 |
import java.util.Iterator; |
20 |
import java.util.List; |
21 |
|
22 |
import javax.swing.ImageIcon; |
23 |
import javax.swing.JButton; |
24 |
import javax.swing.JComboBox; |
25 |
import javax.swing.JLabel; |
26 |
import javax.swing.JOptionPane; |
27 |
import javax.swing.JTextField; |
28 |
|
29 |
import org.gvsig.gui.beans.swing.GridBagLayoutPanel; |
30 |
import org.gvsig.gvsig3dgui.view.View3D; |
31 |
import org.gvsig.osgvp.viewer.IViewerContainer; |
32 |
|
33 |
import com.iver.ai2.gvsig3d.resources.ResourcesFactory; |
34 |
import com.iver.andami.PluginServices; |
35 |
import com.iver.andami.ui.mdiManager.SingletonWindow; |
36 |
import com.iver.andami.ui.mdiManager.WindowInfo; |
37 |
import com.iver.cit.gvsig.animation.AnimationContainer; |
38 |
import com.iver.cit.gvsig.animation.AnimationPlayer; |
39 |
import com.iver.cit.gvsig.animation.animatedObject.IAnimatedObject; |
40 |
import com.iver.cit.gvsig.animation.traks.IAnimationTrack; |
41 |
|
42 |
/**
|
43 |
* @author
|
44 |
* @since 1.1
|
45 |
*
|
46 |
* Class to create and to process the event's panel animation.
|
47 |
*/
|
48 |
|
49 |
public class AnimationContol3D extends GridBagLayoutPanel implements |
50 |
SingletonWindow, ActionListener, KeyListener, ItemListener { |
51 |
|
52 |
/**
|
53 |
* default static final serial version ID
|
54 |
*/
|
55 |
private static final long serialVersionUID = 1L; |
56 |
|
57 |
private int width = 240; |
58 |
|
59 |
private int height = 85; |
60 |
|
61 |
private int operation; // Used in choice's functions |
62 |
|
63 |
private JLabel label = null; |
64 |
|
65 |
private JLabel label2 = null; |
66 |
|
67 |
private JTextField textosegs = null; |
68 |
|
69 |
private JComboBox choice = null; |
70 |
|
71 |
private JButton buttonIcon = null; |
72 |
|
73 |
private JButton buttonIcon1 = null; |
74 |
|
75 |
private JButton buttonIcon2 = null; |
76 |
|
77 |
private JButton buttonIcon3 = null; |
78 |
|
79 |
private ImageIcon image = null; |
80 |
|
81 |
private ImageIcon image1 = null; |
82 |
|
83 |
private ImageIcon image2 = null; |
84 |
|
85 |
private ImageIcon image3 = null; |
86 |
|
87 |
private Checkbox checkbox = null; |
88 |
|
89 |
private String buttonPath; |
90 |
|
91 |
private double globalTime; |
92 |
|
93 |
private AnimationPlayer animationPlayer;
|
94 |
|
95 |
private int animationMode; |
96 |
|
97 |
private int animationState; |
98 |
|
99 |
private boolean playFlag = false; |
100 |
|
101 |
private boolean pauseFlag = false; |
102 |
|
103 |
private StateUpdate runnable;
|
104 |
|
105 |
/**
|
106 |
* Default constructor.
|
107 |
*
|
108 |
* @param control
|
109 |
*/
|
110 |
public AnimationContol3D(AnimationPlayer animationPlayer) {
|
111 |
|
112 |
this.animationPlayer = animationPlayer;
|
113 |
|
114 |
// Setting up the button path
|
115 |
String oldPath = ResourcesFactory.getExtPath();// Save the path. |
116 |
ResourcesFactory |
117 |
.setExtPath("/gvSIG/extensiones/com.iver.ai2.animationgui.gui/images/reproductoranim/");// my |
118 |
// new
|
119 |
// path
|
120 |
ResourcesFactory.setExtPath("/images/reproductoranim/");// my new path |
121 |
buttonPath = ResourcesFactory.getResourcesPath(); |
122 |
URL path;
|
123 |
path = this.getClass().getClassLoader().getResource("images/reproductoranim/"); |
124 |
buttonPath = path.getPath(); |
125 |
ResourcesFactory.setExtPath(oldPath);// Restore the old path.
|
126 |
System.out.println(oldPath);
|
127 |
System.out.println(buttonPath);
|
128 |
|
129 |
initialize(); |
130 |
} |
131 |
|
132 |
|
133 |
private void updateAnimatedObjects(AnimationPlayer animationPlayer) { |
134 |
IViewerContainer canvas = null;
|
135 |
AnimationContainer ac = animationPlayer.getAnimationContainer(); |
136 |
List<IAnimationTrack> atl = ac.getAnimationTrackList();
|
137 |
for (Iterator iterator = atl.iterator(); iterator.hasNext();) { |
138 |
IAnimationTrack track = (IAnimationTrack) iterator.next(); |
139 |
IAnimatedObject animatedObject = (IAnimatedObject) track.getAnimatedObject(); |
140 |
try {
|
141 |
//if persistence is loaded, the canvas is null in this step
|
142 |
canvas = (IViewerContainer) animatedObject.getAnimatedObject("canvas");
|
143 |
} |
144 |
catch (Exception e) { |
145 |
//if canvas is null, do nothing
|
146 |
} |
147 |
|
148 |
if (canvas == null) { |
149 |
//Getting the name of the view
|
150 |
View3D view = (View3D) animatedObject.getAnimatedObject("view");
|
151 |
//Getting the canvas and insert this canvas in the animated object
|
152 |
animatedObject.addAnimatedObject("canvas", view.getCanvas3d());
|
153 |
} |
154 |
} |
155 |
|
156 |
} |
157 |
|
158 |
/*
|
159 |
* Panel creation.
|
160 |
*
|
161 |
*/
|
162 |
private void initialize() { |
163 |
this.setPreferredSize(new Dimension(width, height)); |
164 |
this.setSize(new Dimension(width, height)); |
165 |
|
166 |
// Bag where have declared the characteristic of a Component in the
|
167 |
// panel.
|
168 |
GridBagConstraints c = new GridBagConstraints(); |
169 |
|
170 |
/*
|
171 |
* gridx: column position in grid gridy: row position in grid anchor:
|
172 |
* bottom of space
|
173 |
*/
|
174 |
|
175 |
// Creation of four buttons: play, stop, pause y record.
|
176 |
c.gridx = 1;
|
177 |
c.gridy = 0;
|
178 |
this.add(getPlayButton(), c);
|
179 |
|
180 |
c.gridx = 2;
|
181 |
c.gridy = 0;
|
182 |
this.add(getPauseButton(), c);
|
183 |
|
184 |
c.gridx = 3;
|
185 |
c.gridy = 0;
|
186 |
this.add(getStopButton(), c);
|
187 |
|
188 |
c.gridx = 4;
|
189 |
c.gridy = 0;
|
190 |
this.add(getRecButton(), c);
|
191 |
|
192 |
// Space between rows.
|
193 |
c.insets = new Insets(10, 0, 0, 0); |
194 |
|
195 |
// Creation of two labels in the panel.
|
196 |
c.gridx = 1;
|
197 |
c.gridy = 1;
|
198 |
c.anchor = GridBagConstraints.WEST;
|
199 |
this.add(getLabelDuration(), c);
|
200 |
|
201 |
c.gridx = 1;
|
202 |
c.gridy = 3;
|
203 |
c.anchor = GridBagConstraints.WEST;
|
204 |
this.add(getLabelMode(), c);
|
205 |
|
206 |
// textField to introduce the duration of the movie in seconds or
|
207 |
// frames.
|
208 |
c.gridx = 2;
|
209 |
c.gridy = 1;
|
210 |
c.anchor = GridBagConstraints.WEST;
|
211 |
this.add(getSeconds(), c);
|
212 |
|
213 |
// checkbox for the provisional selection of video in seconds or frames.
|
214 |
// c.gridx = 3;
|
215 |
// c.gridy = 1;
|
216 |
// c.gridwidth = 2;
|
217 |
// c.anchor = GridBagConstraints.EAST;
|
218 |
// this.add(getJCheckBox(), c);
|
219 |
|
220 |
// choice for mode player selection.
|
221 |
c.gridx = 2;
|
222 |
c.gridy = 3;
|
223 |
c.anchor = GridBagConstraints.WEST;
|
224 |
c.gridwidth = 3;
|
225 |
this.add(getChoiceValue(), c);
|
226 |
choice.setSelectedIndex(this.animationPlayer.getAnimationMode());
|
227 |
|
228 |
this.setPreferredSize(new Dimension(width, height)); |
229 |
this.setSize(new Dimension(width, height)); |
230 |
setGlobalTime(this.animationPlayer.getGlobalTime() / 1000); |
231 |
|
232 |
// textosegs.setText(Double.toString(globalTime));
|
233 |
} |
234 |
|
235 |
private JLabel getLabelMode() { |
236 |
label2 = new JLabel(PluginServices.getText(this, "Label_Mode")); |
237 |
return label2;
|
238 |
} |
239 |
|
240 |
private JLabel getLabelDuration() { |
241 |
label = new JLabel(PluginServices.getText(this, "Label_Duration")); |
242 |
return label;
|
243 |
} |
244 |
|
245 |
/**
|
246 |
* @return Checkbox. Return the checkbox of selecion of frames.
|
247 |
*/
|
248 |
private Checkbox getJCheckBox() { |
249 |
if (checkbox == null) { |
250 |
checkbox = new Checkbox(PluginServices.getText(this, "Check_Text"), |
251 |
null, false); |
252 |
checkbox.addItemListener(this);
|
253 |
} |
254 |
return checkbox;
|
255 |
} |
256 |
|
257 |
/**
|
258 |
* @return Choice. Return the choice with the diferents modes of display.
|
259 |
*/
|
260 |
private JComboBox getChoiceValue() { |
261 |
if (choice == null) { |
262 |
choice = new JComboBox(); |
263 |
choice.addItem("Loop mode");
|
264 |
choice.addItem("Ping pong loop");
|
265 |
choice.addItem("Play once");
|
266 |
choice.addItem("Loop once backwards");
|
267 |
choice.addItemListener(this);
|
268 |
} |
269 |
return choice;
|
270 |
} |
271 |
|
272 |
/**
|
273 |
* @return TextField Return textfield where the user put the seconds of the
|
274 |
* movie.
|
275 |
*/
|
276 |
private JTextField getSeconds() { |
277 |
if (textosegs == null) { |
278 |
textosegs = new JTextField(PluginServices |
279 |
.getText(this, "Text_Secs"), 4); |
280 |
textosegs.setName("SECONDS");
|
281 |
textosegs.setHorizontalAlignment(JTextField.RIGHT);
|
282 |
textosegs.addKeyListener(this);
|
283 |
} |
284 |
return textosegs;
|
285 |
} |
286 |
|
287 |
/**
|
288 |
* @return JButton. Return record button.
|
289 |
*/
|
290 |
private JButton getRecButton() { |
291 |
if (buttonIcon3 == null) { |
292 |
buttonIcon3 = new JButton(); |
293 |
// path where are the image to load in the button.
|
294 |
image3 = new ImageIcon(buttonPath + "/record.png"); |
295 |
buttonIcon3.setIcon(image3); |
296 |
buttonIcon3.setActionCommand("REC");
|
297 |
buttonIcon3.addActionListener(this);
|
298 |
} |
299 |
return buttonIcon3;
|
300 |
} |
301 |
|
302 |
/**
|
303 |
* @return JButton. Return stop button.
|
304 |
*/
|
305 |
private JButton getStopButton() { |
306 |
if (buttonIcon2 == null) { |
307 |
buttonIcon2 = new JButton(); |
308 |
image2 = new ImageIcon(buttonPath + "/stop.png"); |
309 |
buttonIcon2.setIcon(image2); |
310 |
buttonIcon2.setActionCommand("STOP");
|
311 |
buttonIcon2.addActionListener(this);
|
312 |
} |
313 |
return buttonIcon2;
|
314 |
} |
315 |
|
316 |
/**
|
317 |
* @return JButton. Return pause button.
|
318 |
*/
|
319 |
private JButton getPauseButton() { |
320 |
if (buttonIcon1 == null) { |
321 |
buttonIcon1 = new JButton(); |
322 |
image1 = new ImageIcon(buttonPath + "/pause.png"); |
323 |
buttonIcon1.setIcon(image1); |
324 |
buttonIcon1.setActionCommand("PAUSE");
|
325 |
buttonIcon1.addActionListener(this);
|
326 |
} |
327 |
return buttonIcon1;
|
328 |
} |
329 |
|
330 |
/**
|
331 |
* @return JButton. Return play button.
|
332 |
*/
|
333 |
public JButton getPlayButton() { |
334 |
if (buttonIcon == null) { |
335 |
buttonIcon = new JButton(); |
336 |
image = new ImageIcon(buttonPath + "/play.png"); |
337 |
buttonIcon.setIcon(image); |
338 |
buttonIcon.setActionCommand("PLAY");
|
339 |
buttonIcon.addActionListener(this);
|
340 |
buttonIcon.setIcon(image); |
341 |
} |
342 |
return buttonIcon;
|
343 |
} |
344 |
|
345 |
/**
|
346 |
* @see com.iver.andami.ui.mdiManager.SingletonWindow#getWindowModel()
|
347 |
* @return Object
|
348 |
*/
|
349 |
public Object getWindowModel() { |
350 |
// TODO Auto-generated method stub
|
351 |
return null; |
352 |
} |
353 |
|
354 |
/**
|
355 |
* @see com.iver.andami.ui.mdiManager.IWindow#getWindowInfo()
|
356 |
* @return WindowInfo
|
357 |
*/
|
358 |
public WindowInfo getWindowInfo() {
|
359 |
WindowInfo m_viewinfo = new WindowInfo();
|
360 |
m_viewinfo.setTitle(PluginServices.getText(this, "Window_Title")); |
361 |
m_viewinfo.setHeight(height); |
362 |
m_viewinfo.setWidth(width); |
363 |
return m_viewinfo;
|
364 |
} |
365 |
|
366 |
/**
|
367 |
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
|
368 |
* logic events of pressed buttons.
|
369 |
*/
|
370 |
public void actionPerformed(ActionEvent arg0) { |
371 |
String actionCommand = arg0.getActionCommand();
|
372 |
|
373 |
this.animationPlayer
|
374 |
.setAnimationPlayerState(AnimationPlayer.ANIMATION_INITIAL); |
375 |
|
376 |
if (actionCommand.equals("PLAY")) { // play pressed |
377 |
if (runnable == null) { |
378 |
runnable = new StateUpdate();
|
379 |
// Create the thread supplying it with the runnable object
|
380 |
Thread thread = new Thread(runnable); |
381 |
// Start the thread
|
382 |
thread.start(); |
383 |
} |
384 |
|
385 |
// this.animationPlayer.setGlobalTime(globalTime);
|
386 |
// this.animationPlayer.setAnimationFrequency(this.animationPlayer.getAnimationFrequency());//frequency
|
387 |
// in the AnimationPlayer.
|
388 |
|
389 |
updateAnimatedObjects(this.animationPlayer);
|
390 |
|
391 |
this.animationPlayer.play();
|
392 |
playFlag = true;
|
393 |
if (this.animationPlayer.getAnimationPlayerState() == AnimationPlayer.ANIMATION_PLAY) { |
394 |
image = new ImageIcon(buttonPath + "/playon.png"); |
395 |
buttonIcon.setIcon(image); |
396 |
if (pauseFlag) {
|
397 |
image1 = new ImageIcon(buttonPath + "/pause.png"); |
398 |
buttonIcon1.setIcon(image1); |
399 |
} |
400 |
|
401 |
} |
402 |
|
403 |
} else if (actionCommand.equals("PAUSE")) { // pause pressed |
404 |
|
405 |
this.animationPlayer.pause();
|
406 |
if (runnable != null) |
407 |
runnable.end(); |
408 |
if (this.animationPlayer.getAnimationPlayerState() == AnimationPlayer.ANIMATION_PAUSE |
409 |
&& playFlag) { |
410 |
playFlag = false;
|
411 |
pauseFlag = true;
|
412 |
image = new ImageIcon(buttonPath + "/play.png"); |
413 |
buttonIcon.setIcon(image); |
414 |
image1 = new ImageIcon(buttonPath + "/pauseon.png"); |
415 |
buttonIcon1.setIcon(image1); |
416 |
} |
417 |
} else if (actionCommand.equals("STOP")) { |
418 |
|
419 |
animationPlayer.stop(); |
420 |
if (runnable != null) |
421 |
runnable.end(); |
422 |
if (this.animationPlayer.getAnimationPlayerState() == AnimationPlayer.ANIMATION_STOP |
423 |
&& (playFlag || pauseFlag)) { |
424 |
|
425 |
if (playFlag) {
|
426 |
image = new ImageIcon(buttonPath + "/play.png"); |
427 |
buttonIcon.setIcon(image); |
428 |
playFlag = false;
|
429 |
} else {
|
430 |
image1 = new ImageIcon(buttonPath + "/pause.png"); |
431 |
buttonIcon1.setIcon(image1); |
432 |
pauseFlag = false;
|
433 |
} |
434 |
} |
435 |
|
436 |
} else if (actionCommand.equals("REC")) { |
437 |
animationPlayer.record(); |
438 |
JOptionPane.showMessageDialog(null, "Grabandooooooo", |
439 |
"Alertas de prueba", JOptionPane.WARNING_MESSAGE); |
440 |
|
441 |
}// if
|
442 |
}// public void
|
443 |
|
444 |
/*
|
445 |
* @see java.awt.event.KeyListener#keyPressed(java.awt.event.KeyEvent)
|
446 |
*
|
447 |
*/
|
448 |
public void keyPressed(KeyEvent arg0) { |
449 |
// TODO Auto-generated method stub
|
450 |
} |
451 |
|
452 |
/*
|
453 |
* @see java.awt.event.KeyListener#keyReleased(java.awt.event.KeyEvent)
|
454 |
* Events when you put the film?s seconds in the animation panel.
|
455 |
*/
|
456 |
public void keyReleased(KeyEvent arg0) { |
457 |
// TODO Auto-generated method stub
|
458 |
|
459 |
System.out.println("valor del campo segundos: " |
460 |
+ this.textosegs.getText());
|
461 |
globalTime = new Double(this.textosegs.getText()).doubleValue(); |
462 |
// if (AP == null)
|
463 |
// AP = new AnimationPlayer();
|
464 |
this.animationPlayer.setGlobalTime(globalTime);
|
465 |
} |
466 |
|
467 |
/*
|
468 |
* @see java.awt.event.KeyListener#keyTyped(java.awt.event.KeyEvent)
|
469 |
*/
|
470 |
public void keyTyped(KeyEvent arg0) { |
471 |
// TODO Auto-generated method stub
|
472 |
} |
473 |
|
474 |
/**
|
475 |
* @see java.awt.event.ItemListener#itemStateChanged(java.awt.event.ItemEvent)
|
476 |
* ItemListener methods.
|
477 |
*/
|
478 |
public void itemStateChanged(ItemEvent event) { |
479 |
// TODO Auto-generated method stub
|
480 |
Object obj = event.getSource();
|
481 |
if (obj == choice) {
|
482 |
operation = choice.getSelectedIndex(); // get select item.
|
483 |
setMode(operation); |
484 |
} else if (obj == checkbox) { |
485 |
System.out.println("opcion seleccionada checkbox"); |
486 |
} |
487 |
} |
488 |
|
489 |
/*
|
490 |
* funci?n que seg?n la opci?n del choice ejecuta una operaci?n definida.
|
491 |
* esta luego no se usar? 'creo'.
|
492 |
*/
|
493 |
private void setMode(int option) { |
494 |
// TODO Auto-generated method stub
|
495 |
String mode = String.valueOf(choice.getItemAt(option)); |
496 |
if (mode.equals("Play once")) { |
497 |
animationMode = AnimationPlayer.PLAY_ONCE; |
498 |
} else if (mode.equals("Loop mode")) { |
499 |
animationMode = AnimationPlayer.LOOP; |
500 |
} else if (mode.equals("Loop once backwards")) { |
501 |
animationMode = AnimationPlayer.PLAY_ONCE_BACKWARDS; |
502 |
} else if (mode.equals("Ping pong loop")) |
503 |
animationMode = AnimationPlayer.PING_PONG_LOOP; |
504 |
|
505 |
this.animationPlayer.setAnimationMode(animationMode);
|
506 |
|
507 |
System.out.println("opcion: " + mode); |
508 |
} |
509 |
|
510 |
public void setGlobalTime(double time) { |
511 |
textosegs.setText(Double.toString(time));
|
512 |
} |
513 |
|
514 |
/*
|
515 |
* Class to control the automatically stop state of the actual animation.
|
516 |
*/
|
517 |
|
518 |
public class StateUpdate implements Runnable { |
519 |
|
520 |
private boolean finish = false; |
521 |
|
522 |
// private int ani
|
523 |
// private AnimationPlayer animationPlayer;
|
524 |
|
525 |
public void run() { |
526 |
// TODO Auto-generated method stub
|
527 |
|
528 |
while (true) { |
529 |
try {
|
530 |
Thread.sleep(800); |
531 |
synchronized (this) { |
532 |
if (finish) {
|
533 |
break;
|
534 |
} |
535 |
} |
536 |
} catch (InterruptedException e) { |
537 |
|
538 |
e.printStackTrace(); |
539 |
} |
540 |
animationState = animationPlayer.getAnimationPlayerState(); |
541 |
if (animationPlayer.getAnimationPlayerState() == AnimationPlayer.ANIMATION_STOP
|
542 |
&& (playFlag || pauseFlag)) { |
543 |
|
544 |
if (playFlag) {
|
545 |
image = new ImageIcon(buttonPath + "/play.png"); |
546 |
buttonIcon.setIcon(image); |
547 |
playFlag = false;
|
548 |
} else {
|
549 |
image1 = new ImageIcon(buttonPath + "/pause.png"); |
550 |
buttonIcon1.setIcon(image1); |
551 |
pauseFlag = false;
|
552 |
} |
553 |
runnable.end(); |
554 |
}// long if
|
555 |
} |
556 |
} |
557 |
|
558 |
/*
|
559 |
* function to stop the thread.
|
560 |
*/
|
561 |
|
562 |
public synchronized void end() { |
563 |
finish = true;
|
564 |
runnable = null;
|
565 |
} |
566 |
}// end class StateUpdate.
|
567 |
|
568 |
}// end class AnimationContol3D.
|