Statistics
| Revision:

svn-gvsig-desktop / import / ext3D / branches / ext3D_v1.1 / extAnimationGUI / src / com / iver / ai2 / animationgui / gui / AnimationContol3D.java @ 15452

History | View | Annotate | Download (12.9 KB)

1
/* 
2
 * Men? que aparace 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.Choice;
10
import java.awt.Dimension;
11
import java.awt.GridBagConstraints;
12
import java.awt.Insets;
13
import java.awt.TextField;
14
import java.awt.event.ActionEvent;
15
import java.awt.event.ActionListener;
16
import java.awt.event.ItemEvent;
17
import java.awt.event.ItemListener;
18
import java.awt.event.KeyEvent;
19
import java.awt.event.KeyListener;
20

    
21
import javax.swing.ImageIcon;
22
import javax.swing.JButton;
23
import javax.swing.JLabel;
24
import javax.swing.JOptionPane;
25
import javax.swing.JTextField;
26

    
27
import org.gvsig.gui.beans.swing.GridBagLayoutPanel;
28

    
29
import com.iver.ai2.gvsig3d.resources.ResourcesFactory;
30
import com.iver.andami.PluginServices;
31
import com.iver.andami.ui.mdiManager.SingletonWindow;
32
import com.iver.andami.ui.mdiManager.WindowInfo;
33
import com.iver.cit.gvsig.animation.AnimationPlayer;
34

    
35
/**
36
 * @author
37
 * @since 1.1
38
 * 
39
 * Class to create and to process the event's panel animation.
40
 */
41

    
42
public class AnimationContol3D extends GridBagLayoutPanel implements
43
                SingletonWindow, ActionListener, KeyListener, ItemListener {
44

    
45
        /**
46
         * default static final serial version ID
47
         */
48
        private static final long serialVersionUID = 1L;
49

    
50
        private int width = 250;
51

    
52
        private int height = 85;
53

    
54
        private int operation; // Used in choice's functions
55

    
56
        private JLabel label = null;
57

    
58
        private JLabel label2 = null;
59

    
60
        private JTextField textosegs = null;
61

    
62
        private Choice choice = null;
63

    
64
        final static String textopru = "Texto algo largo de prueba";
65

    
66
        private JButton buttonIcon = null;
67

    
68
        private JButton buttonIcon1 = null;
69

    
70
        private JButton buttonIcon2 = null;
71

    
72
        private JButton buttonIcon3 = null;
73

    
74
        private ImageIcon image = null;
75

    
76
        private ImageIcon image1 = null;
77

    
78
        private ImageIcon image2 = null;
79

    
80
        private ImageIcon image3 = null;
81

    
82
        private Checkbox checkbox = null;
83

    
84
        private String buttonPath;
85

    
86
        private double globalTime;
87

    
88
        private AnimationPlayer animationPlayer;
89

    
90
        private int animationMode;
91

    
92
        /**
93
         * Default constructor.
94
         * 
95
         * @param control
96
         */
97
        public AnimationContol3D(AnimationPlayer animationPlayer) {
98

    
99
                this.animationPlayer = animationPlayer;
100

    
101
                // Setting up the button path
102
                String oldPath = ResourcesFactory.getExtPath();// Save the path.
103
                ResourcesFactory
104
                                .setExtPath("/gvSIG/extensiones/com.iver.ai2.animationgui.gui/images/reproductoranim/");// my
105
                // new
106
                // path
107
                buttonPath = ResourcesFactory.getResourcesPath();
108
                ResourcesFactory.setExtPath(oldPath);// Restore the old path.
109
                System.out.println(oldPath);
110
                System.out.println(buttonPath);
111

    
112
                initialize();
113
        }
114

    
115
        /*
116
         * Panel creation.
117
         * 
118
         */
119
        private void initialize() {
120
                this.setPreferredSize(new Dimension(width, height));
121
                this.setSize(new Dimension(width, height));
122

    
123
                // Bag where have declared the characteristic of a Component in the
124
                // panel.
125
                GridBagConstraints c = new GridBagConstraints();
126

    
127
                /*
128
                 * gridx: column position in grid gridy: row position in grid anchor:
129
                 * bottom of space
130
                 */
131

    
132
                // Creation of four buttons: play, stop, pause y record.
133
                c.gridx = 1;
134
                c.gridy = 0;
135
                this.add(getPlayButton(), c);
136

    
137
                c.gridx = 2;
138
                c.gridy = 0;
139
                this.add(getPauseButton(), c);
140

    
141
                c.gridx = 3;
142
                c.gridy = 0;
143
                this.add(getStopButton(), c);
144

    
145
                c.gridx = 4;
146
                c.gridy = 0;
147
                this.add(getRecButton(), c);
148

    
149
                // Space between rows.
150
                c.insets = new Insets(10, 0, 0, 0);
151

    
152
                // Creation of two labels in the panel.
153
                c.gridx = 1;
154
                c.gridy = 1;
155
                c.anchor = GridBagConstraints.WEST;
156
                this.add(getLabelDuration(), c);
157

    
158
                c.gridx = 1;
159
                c.gridy = 3;
160
                c.anchor = GridBagConstraints.WEST;
161
                this.add(getLabelMode(), c);
162

    
163
                // textField to introduce the duration of the movie in seconds or
164
                // frames.
165
                c.gridx = 2;
166
                c.gridy = 1;
167
                c.anchor = GridBagConstraints.WEST;
168
                this.add(getSeconds(), c);
169

    
170
                // checkbox for the provisional selection of video in seconds or frames.
171
                c.gridx = 3;
172
                c.gridy = 1;
173
                c.gridwidth = 2;
174
                c.anchor = GridBagConstraints.EAST;
175
                this.add(getJCheckBox(), c);
176

    
177
                // choice for mode player selection.
178
                c.gridx = 2;
179
                c.gridy = 3;
180
                c.anchor = GridBagConstraints.WEST;
181
                c.gridwidth = 3;
182
                this.add(getChoiceValue(), c);
183

    
184
                this.setPreferredSize(new Dimension(width, height));
185
                this.setSize(new Dimension(width, height));
186
                
187
                textosegs.setText("10");
188
        }
189

    
190
        private JLabel getLabelMode() {
191
                // TODO Auto-generated method stub
192
                label2 = new JLabel(PluginServices.getText(this, "Label_Mode"));
193
                return label2;
194
        }
195

    
196
        private JLabel getLabelDuration() {
197
                // TODO Auto-generated method stub
198
                label = new JLabel(PluginServices.getText(this, "Label_Duration"));
199
                return label;
200
        }
201

    
202
        /**
203
         * @return Checkbox. Return the checkbox of selecion of frames.
204
         */
205
        private Checkbox getJCheckBox() {
206
                if (checkbox == null) {
207
                        checkbox = new Checkbox(PluginServices.getText(this, "Check_Text"),
208
                                        null, false);
209
                        checkbox.addItemListener(this);
210
                }
211
                return checkbox;
212
        }
213

    
214
        /**
215
         * @return Choice. Return the choice with the diferents modes of display.
216
         */
217
        private Choice getChoiceValue() {
218
                // TODO Auto-generated method stub
219
                if (choice == null) {
220
                        choice = new Choice();
221
                        // choice.addItem( textopru );
222
                        choice.addItem("Loop mode");
223
                        choice.addItem("Play once");
224
                        choice.addItem("Loop foward");
225
                        // choice.addItem( "modo3" );
226
                        // choice.addItem( "modo4" );
227
                        choice.addItemListener(this);
228
                }
229
                return choice;
230
        }
231

    
232
        /**
233
         * @return TextField Return textfield where the user put the seconds of the
234
         *         movie.
235
         */
236
        private JTextField getSeconds() {
237
                // TODO Auto-generated method stub
238
                if (textosegs == null) {
239
                        textosegs = new JTextField(
240
                                        PluginServices.getText(this, "Text_Secs"), 4);
241
                        textosegs.setName("SECONDS");
242
                        textosegs.setHorizontalAlignment(JTextField.RIGHT);
243
                        textosegs.addKeyListener(this);
244
                }
245
                return textosegs;
246
        }
247

    
248
        /**
249
         * @return JButton. Return record button.
250
         */
251
        private JButton getRecButton() {
252
                // TODO Auto-generated method stub
253
                if (buttonIcon3 == null) {
254
                        buttonIcon3 = new JButton();
255
                        // path where are the image to load in the button.
256
                        image3 = new ImageIcon(buttonPath + "record.png");
257
                        buttonIcon3.setIcon(image3);
258
                        buttonIcon3.setActionCommand("REC");
259
                        buttonIcon3.addActionListener(this);
260
                }
261
                return buttonIcon3;
262
        }
263

    
264
        /**
265
         * @return JButton. Return stop button.
266
         */
267
        private JButton getStopButton() {
268
                // TODO Auto-generated method stub
269
                if (buttonIcon2 == null) {
270
                        buttonIcon2 = new JButton();
271
                        image2 = new ImageIcon(buttonPath + "stop.png");
272
                        buttonIcon2.setIcon(image2);
273
                        buttonIcon2.setActionCommand("STOP");
274
                        buttonIcon2.addActionListener(this);
275
                }
276
                return buttonIcon2;
277
        }
278

    
279
        /**
280
         * @return JButton. Return pause button.
281
         */
282
        private JButton getPauseButton() {
283
                // TODO Auto-generated method stub
284
                if (buttonIcon1 == null) {
285
                        buttonIcon1 = new JButton();
286
                        image1 = new ImageIcon(buttonPath + "pause.png");
287
                        buttonIcon1.setIcon(image1);
288
                        buttonIcon1.setActionCommand("PAUSE");
289
                        buttonIcon1.addActionListener(this);
290
                }
291
                return buttonIcon1;
292
        }
293

    
294
        /**
295
         * @return JButton. Return play button.
296
         */
297
        public JButton getPlayButton() {
298
                // TODO Auto-generated method stub
299
                if (buttonIcon == null) {
300
                        buttonIcon = new JButton();
301
                        image = new ImageIcon(buttonPath + "play.png");
302
                        buttonIcon.setIcon(image);
303
                        buttonIcon.setActionCommand("PLAY");
304
                        buttonIcon.addActionListener(this);
305
                        buttonIcon.setIcon(image);
306
                }
307
                return buttonIcon;
308
        }
309

    
310
        /**
311
         * @see com.iver.andami.ui.mdiManager.SingletonWindow#getWindowModel()
312
         * @return Object
313
         */
314
        public Object getWindowModel() {
315
                // TODO Auto-generated method stub
316
                return null;
317
        }
318

    
319
        /**
320
         * @see com.iver.andami.ui.mdiManager.IWindow#getWindowInfo()
321
         * @return WindowInfo
322
         */
323
        public WindowInfo getWindowInfo() {
324
                WindowInfo m_viewinfo = new WindowInfo();
325
                m_viewinfo.setTitle(PluginServices.getText(this, "Window_Title"));
326
                m_viewinfo.setHeight(height);
327
                m_viewinfo.setWidth(width);
328
                return m_viewinfo;
329
        }
330

    
331
        /**
332
         * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
333
         *      logic events of pressed buttons.
334
         */
335
        public void actionPerformed(ActionEvent arg0) {
336
                // TODO Auto-generated method stub
337
                String actionCommand = arg0.getActionCommand();
338
                if (actionCommand.equals("PLAY")) { // play pressed
339
                        // pulsadoPlay = true;
340
                        // if(pulsadoPause == true){
341
                        // pulsadoPause = false;
342
                        // image1 = new ImageIcon(buttonPath+"pause.png");
343
                        // buttonIcon1.setIcon(image1);
344
                        // }
345
                        // image = new ImageIcon(buttonPath+"playon.png");
346
                        // buttonIcon.setIcon(image);
347
                        // //System.out.println("pinchado boton de play");
348
                        // JOptionPane.showMessageDialog(null,
349
                        // "Estas viendo la animacion.......",
350
                        // "Alertas de prueba",
351
                        // JOptionPane.WARNING_MESSAGE);
352
                        // if (AP == null)
353
                        // AP = new AnimationPlayer();
354
                        this.animationPlayer
355
                                        .setAnimationPlayerState(AnimationPlayer.ANIMATION_STOP);
356
                        this.animationPlayer.setGlobalTime(globalTime);
357
                        this.animationPlayer.setAnimationMode(animationMode);
358
                        this.animationPlayer.play();
359
                } else if (actionCommand.equals("PAUSE")) { // pause pressed
360
                        // if (pulsadoPlay == true) {
361
                        // pulsadoPlay = false;
362
                        // pulsadoPause = true;
363
                        // image = new ImageIcon(buttonPath + "play.png");
364
                        // buttonIcon.setIcon(image);
365
                        // image1 = new ImageIcon(buttonPath + "pauseon.png");
366
                        // buttonIcon1.setIcon(image1);
367
                        // // System.out.println("pinchado boton de play");
368
                        // JOptionPane.showMessageDialog(null,
369
                        // "Has pausado la animacion.......", "Alertas de prueba",
370
                        // JOptionPane.WARNING_MESSAGE);
371
                        // }
372
                        this.animationPlayer.pause();
373
                } else if (actionCommand.equals("STOP")) {
374
                        // && ((pulsadoPlay == true) || pulsadoPause == true)) { // stop
375
                        // // pressed
376
                        // if (pulsadoPlay == true)
377
                        // pulsadoPlay = false;
378
                        // else if (pulsadoPause = true)
379
                        // pulsadoPause = false;
380
                        // // System.out.println("pinchado boton de play");
381
                        // image = new ImageIcon(buttonPath + "play.png");
382
                        // image1 = new ImageIcon(buttonPath + "pause.png");
383
                        // buttonIcon1.setIcon(image1);
384
                        // buttonIcon.setIcon(image);
385
                        // JOptionPane.showMessageDialog(null,
386
                        // "Has parado la animacion.......", "Alertas de prueba",
387
                        // JOptionPane.WARNING_MESSAGE);
388
                        animationPlayer.stop();
389

    
390
                } else if (actionCommand.equals("REC")) {
391
                        image = new ImageIcon(buttonPath + "play.png");
392
                        buttonIcon.setIcon(image);
393
                        // System.out.println("pinchado boton de play");
394
                        JOptionPane.showMessageDialog(null, "Grabandooooooo",
395
                                        "Alertas de prueba", JOptionPane.WARNING_MESSAGE);
396
                }
397
        }
398

    
399
        /*
400
         * @see java.awt.event.KeyListener#keyPressed(java.awt.event.KeyEvent)
401
         * 
402
         */
403
        public void keyPressed(KeyEvent arg0) {
404
                // TODO Auto-generated method stub
405
        }
406

    
407
        /*
408
         * @see java.awt.event.KeyListener#keyReleased(java.awt.event.KeyEvent)
409
         *      Events when you put the film?s seconds in the animation panel.
410
         */
411
        public void keyReleased(KeyEvent arg0) {
412
                // TODO Auto-generated method stub
413

    
414
                System.out.println("valor del campo segundos: "
415
                                + this.textosegs.getText());
416
                globalTime = new Double(this.textosegs.getText()).doubleValue();
417
                // if (AP == null)
418
                // AP = new AnimationPlayer();
419
                animationPlayer.setGlobalTime(globalTime);
420
        }
421

    
422
        /*
423
         * @see java.awt.event.KeyListener#keyTyped(java.awt.event.KeyEvent)
424
         */
425
        public void keyTyped(KeyEvent arg0) {
426
                // TODO Auto-generated method stub
427
        }
428

    
429
        /**
430
         * @see java.awt.event.ItemListener#itemStateChanged(java.awt.event.ItemEvent)
431
         *      ItemListener methods.
432
         */
433
        public void itemStateChanged(ItemEvent event) {
434
                // TODO Auto-generated method stub
435
                Object obj = event.getSource();
436
                if (obj == choice) {
437
                        operation = choice.getSelectedIndex(); // get select item.
438
                        getMensaje(operation);
439
                } else if (obj == checkbox) {
440
                        System.out.println("opcion seleccionada checkbox");
441
                }
442
        }
443

    
444
        /*
445
         * funci?n que seg?n la opci?n del choice ejecuta una operaci?n definida.
446
         * esta luego no se usar? 'creo'.
447
         */
448
        private void getMensaje(int option) {
449
                // TODO Auto-generated method stub
450
                String mode = choice.getItem(option);
451
                if (mode.equals("Play once")) {
452
                        animationMode = AnimationPlayer.PLAY_ONCE;
453
                } else if (mode.equals("Loop mode")) {
454
                        animationMode = AnimationPlayer.LOOP;
455
                } else if (mode.equals("Loop foward")) {
456
                        animationMode = AnimationPlayer.LOOP_FORWARD;
457
                }
458
                
459
                System.out.println("opcion: " + mode);
460

    
461
//                switch (option) {
462
//                case 0:
463
//                        JOptionPane.showMessageDialog(null, "opcion1", "Alertas de prueba",
464
//                                        JOptionPane.WARNING_MESSAGE);
465
//                        break;
466
//                case 1:
467
//                        JOptionPane.showMessageDialog(null, "opcion2", "Alertas de prueba",
468
//                                        JOptionPane.WARNING_MESSAGE);
469
//
470
//                        break;
471
//
472
//                }
473
        }
474
}