Statistics
| Revision:

root / trunk / extensions / extAnimationGUI / src / com / iver / ai2 / animationgui / gui / document / Animation.java @ 20356

History | View | Annotate | Download (12.2 KB)

1
/* gvSIG. Sistema de Informaci�n Geogr�fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *  Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib��ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *      +34 963862235
28
 *   gvsig@gva.es
29
 *      www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   IVER T.I. S.A
34
 *   Salamanca 50
35
 *   46005 Valencia
36
 *   Spain
37
 *
38
 *   +34 963163400
39
 *   dac@iver.es
40
 */
41
package com.iver.ai2.animationgui.gui.document;
42

    
43
import java.awt.Dimension;
44
import java.awt.GridBagConstraints;
45
import java.awt.event.ActionEvent;
46
import java.awt.event.ActionListener;
47
import java.awt.event.ItemEvent;
48
import java.awt.event.ItemListener;
49
import java.util.ArrayList;
50
import java.util.List;
51

    
52
import javax.swing.BorderFactory;
53
import javax.swing.ImageIcon;
54
import javax.swing.JComboBox;
55
import javax.swing.JOptionPane;
56

    
57
import org.gvsig.gui.beans.swing.GridBagLayoutPanel;
58
import org.gvsig.gui.beans.swing.JButton;
59

    
60
import com.iver.ai2.animationgui.gui.AnimationContol3D;
61
import com.iver.ai2.animationgui.gui.AnimationContol3D.StateUpdate;
62
import com.iver.ai2.animationgui.gui.util.AnimationUtils;
63
import com.iver.ai2.gvsig3d.resources.ResourcesFactory;
64
import com.iver.ai2.gvsig3dgui.view.View3D;
65
import com.iver.andami.PluginServices;
66
import com.iver.andami.ui.mdiManager.IWindow;
67
import com.iver.andami.ui.mdiManager.SingletonWindow;
68
import com.iver.andami.ui.mdiManager.WindowInfo;
69
import com.iver.cit.gvsig.animation.AnimationContainer;
70
import com.iver.cit.gvsig.animation.AnimationPlayer;
71
import com.iver.cit.gvsig.fmap.MapControl;
72
import com.iver.cit.gvsig.fmap.layers.FLayer;
73
import com.iver.cit.gvsig.fmap.layers.FLayers;
74
import com.iver.cit.gvsig.project.documents.view.IProjectView;
75
import com.iver.cit.gvsig.project.documents.view.gui.BaseView;
76
import com.iver.cit.gvsig.project.documents.view.gui.View;
77

    
78
/**
79
 * Dialogo donde se muestran las propiedades de una vista
80
 * 
81
 * @author Fernando Gonz�lez Cort�s
82
 */
83
public class Animation extends GridBagLayoutPanel implements SingletonWindow,
84
                ItemListener, ActionListener {
85

    
86
        private int width = 250;
87

    
88
        private int height = 100;
89

    
90
        private AnimationContainer animationContainer;
91

    
92
        private JButton captureKeyFrameButton;
93

    
94
        private JButton captureLayerStateButton;
95

    
96
        private JButton animationControl;
97

    
98
        private JButton advanceManager;
99

    
100
        private JComboBox viewChoice = null;
101

    
102
        private JComboBox layerChoice = null;
103

    
104
        private BaseView viewSelected = null;
105

    
106
        private FLayer layerSelected = null;
107

    
108
        private List<IWindow> viewList;
109

    
110
        private String buttonPath;
111

    
112
        private ImageIcon imageCameraKeyFrame;
113

    
114
        private ImageIcon imageLayer;
115

    
116
        private ImageIcon imageAnimationControl;
117

    
118
        private ProjectAnimationDocument projectAnimationDocument;
119

    
120
        /**
121
         * This is the default constructor
122
         * 
123
         * @param f
124
         *            Frame padre del dialogo
125
         * @param v
126
         *            Vista que se representa
127
         */
128
        public Animation(ProjectAnimationDocument projectAnimationDocument) {
129
                this.projectAnimationDocument = projectAnimationDocument;
130
                animationContainer = projectAnimationDocument.animationContainer;
131
                String oldPath = ResourcesFactory.getExtPath();// Save the path.
132
                ResourcesFactory
133
                                .setExtPath("/gvSIG/extensiones/com.iver.ai2.animationgui.gui/images/");// my
134
                // new
135
                // path
136
                buttonPath = ResourcesFactory.getResourcesPath();
137
                ResourcesFactory.setExtPath(oldPath);// Restore the old path.
138
                initialize();
139
        }
140

    
141
        public BaseView getViewSelected() {
142
                return viewSelected;
143
        }
144

    
145
        public void setViewSelected(BaseView viewSelected) {
146
                this.viewSelected = viewSelected;
147
        }
148

    
149
        public FLayer getLayerSelected() {
150
                return layerSelected;
151
        }
152

    
153
        public void setLayerSelected(FLayer layerSelected) {
154
                this.layerSelected = layerSelected;
155
        }
156

    
157
        /**
158
         * This method initializes this
159
         */
160
        private void initialize() {
161
                // Inicialize component
162
                setName("Animation properties");
163
                // Introducing the margin
164
                setBorder(BorderFactory.createEmptyBorder(6, 6, 6, 6));
165
                // Dimension of the panel
166
                // setSize(new Dimension(width, height));
167
                this.setPreferredSize(new Dimension(width, height));
168

    
169
                // ADDING COMPONENTS
170

    
171
                GridBagConstraints c = new GridBagConstraints();
172

    
173
                /*
174
                 * gridx: column position in grid gridy: row position in grid anchor:
175
                 * bottom of space
176
                 */
177

    
178
                // Creation of four buttons: play, stop, pause y record.
179
                c.gridx = 1;
180
                c.gridy = 0;
181
                this.add(getCaptureKeyFrameButton(), c);
182

    
183
                c.gridx = 2;
184
                c.gridy = 0;
185
                this.add(getCaptureLayerStateButton(), c);
186

    
187
                c.gridx = 3;
188
                c.gridy = 0;
189
                this.add(getAnimationControl(), c);
190

    
191
                c.gridx = 4;
192
                c.gridy = 0;
193
                this.add(getAdvanceManager(), c);
194

    
195
                // choice for mode player selection.
196
                c.gridx = 2;
197
                c.gridy = 3;
198
                c.anchor = GridBagConstraints.WEST;
199
                c.gridwidth = 3;
200
                this.add(getViewChoiceValue(), c);
201
                // choice for mode player selection.
202
                c.gridx = 2;
203
                c.gridy = 4;
204
                c.anchor = GridBagConstraints.WEST;
205
                c.gridwidth = 3;
206
                this.add(getLayerChoiceValue(), c);
207

    
208
                // choice.setSelectedIndex(this.animationPlayer.getAnimationMode());
209
                // Inicialize values
210
                        viewChoice.setSelectedIndex(0);
211
                        if(viewChoice.getComponentCount()!=0){
212
                        int index = viewChoice.getSelectedIndex(); // get select item.
213
                        if (viewList != null && !viewList.isEmpty()) 
214
                                setViewSelected((BaseView) viewList.get(index));}
215
                
216

    
217
        }
218

    
219
        /**
220
         * Method to create the button that control the capture for key Frames.
221
         * The listener to lister this component is this class
222
         * 
223
         * @return JButton component with all values inicilize 
224
         */
225
        private JButton getCaptureKeyFrameButton() {
226
                if (captureKeyFrameButton == null) {
227
                        captureKeyFrameButton = new JButton();
228
                        // path where are the image to load in the button.
229
                        imageCameraKeyFrame = new ImageIcon(buttonPath + "camera_link.png");
230
                        captureKeyFrameButton.setIcon(imageCameraKeyFrame);
231
                        captureKeyFrameButton.setActionCommand("CAMERA_KEY_FRAME");
232
                        captureKeyFrameButton.addActionListener(this);
233
                }
234
                return captureKeyFrameButton;
235
        }
236

    
237
        /**
238
         * Method to create the button that control the capture for Layer properties
239
         * The listener to lister this component is this class
240
         * 
241
         * @return JButton component with all values inicilize 
242
         */
243
        private JButton getCaptureLayerStateButton() {
244
                if (captureLayerStateButton == null) {
245
                        captureLayerStateButton = new JButton();
246
                        // path where are the image to load in the button.
247
                        imageLayer = new ImageIcon(buttonPath + "trans6.png");
248
                        captureLayerStateButton.setIcon(imageLayer);
249
                        captureLayerStateButton.setActionCommand("LAYER_PROPERTIES");
250
                        captureLayerStateButton.addActionListener(this);
251
                }
252
                return captureLayerStateButton;
253
        }
254

    
255
        /**
256
         * Method that generates the button to open the player menu
257
         * The listener to lister this component is this class
258
         * @return
259
         */
260
        private JButton getAnimationControl() {
261
                if (animationControl == null) {
262
                        animationControl = new JButton();
263
                        // path where are the image to load in the button.
264
                        imageAnimationControl = new ImageIcon(buttonPath
265
                                        + "camera_edit.png");
266
                        animationControl.setIcon(imageAnimationControl);
267
                        animationControl.setActionCommand("ANIMATION_CONTROL");
268
                        animationControl.addActionListener(this);
269
                }
270
                return animationControl;
271
        }
272

    
273
        /**
274
         * Method that generates the button to open the advance configuration
275
          * The listener to lister this component is this class
276
         * @return
277
         */
278
        private JButton getAdvanceManager() {
279
                if (advanceManager == null) {
280
                        advanceManager = new JButton();
281
                        advanceManager.setText("Advance");
282
                        // path where are the image to load in the button.
283
                        // image3 = new ImageIcon(buttonPath + "record.png");
284
                        // captureKeyFrameButton.setIcon(image3);
285
                        // captureKeyFrameButton.addActionListener(this);
286
                }
287
                return advanceManager;
288
        }
289

    
290
        /**
291
         * @return Choice. Return the choice with the diferents modes of display.
292
         */
293
        private JComboBox getViewChoiceValue() {
294
                if (viewChoice == null) {
295
                        viewChoice = new JComboBox();
296
                        viewList = new ArrayList<IWindow>();
297
                        IWindow[] activeWindows = PluginServices.getMDIManager()
298
                                        .getAllWindows();
299
                        
300
                        for (int i = 0; i < activeWindows.length; i++) {
301
                                IWindow window = activeWindows[i];
302
                                if ((window.getClass().equals(View.class))
303
                                                || (window.getClass().equals(View3D.class))) {
304
                                        viewChoice.addItem(window.getWindowInfo().getTitle());
305
                                        viewList.add(window);
306
                                }
307
                        }
308
                        if (viewChoice.getItemCount() == 0)
309
                                viewChoice.addItem("-none-");
310

    
311
                        viewChoice.addItemListener(this);
312
                }
313
                
314

    
315
                return viewChoice;
316
        }
317

    
318
        private JComboBox getLayerChoiceValue() {
319
                if (layerChoice == null) {
320
                        layerChoice = new JComboBox();
321
                        // IWindow[] activeWindows = PluginServices.getMDIManager()
322
                        // .getAllWindows();
323
                        // for (int i = 0; i < activeWindows.length; i++) {
324
                        // IWindow window = activeWindows[i];
325
                        // String name = window.getWindowInfo().getTitle();
326
                        // layerChoice.addItem(name);
327
                        // }
328
                        layerChoice.addItem("-none-");
329
                        layerChoice.addItemListener(this);
330
                }
331
                refreshLayerSelector();
332
                return layerChoice;
333
        }
334

    
335
        /* (non-Javadoc)
336
         * @see com.iver.andami.ui.mdiManager.SingletonWindow#getWindowModel()
337
         */
338
        public Object getWindowModel() {
339
                // TODO Auto-generated method stub
340
                return animationContainer;
341
        }
342

    
343
        public WindowInfo getWindowInfo() {
344
                WindowInfo m_viewinfo = new WindowInfo();
345
                m_viewinfo.setTitle("Animation ");
346
                m_viewinfo.setHeight(height);
347
                m_viewinfo.setWidth(width);
348
                return m_viewinfo;
349
        }
350

    
351
        public void itemStateChanged(ItemEvent event) {
352
                // Getting the source
353
                Object obj = event.getSource();
354
                // If the view select has changed
355
                if (obj == viewChoice) {
356
                        int index = viewChoice.getSelectedIndex(); // get select item.
357
                        if (viewList != null) {
358
                                setViewSelected((BaseView) viewList.get(index));
359
                                System.out.println("Vista seleccionada : "
360
                                                + getViewSelected().getWindowInfo().getTitle());
361
                                this.refreshLayerSelector();
362
                        }
363
                }
364

    
365
        }
366

    
367
        private void refreshLayerSelector() {
368
                if (this.getViewSelected() != null) {
369

    
370
                        BaseView view = this.getViewSelected();
371
                        MapControl model = view.getMapControl();
372
                        FLayers flayers = model.getMapContext().getLayers();
373
                        layerChoice.removeAllItems();
374
                        int numLayers = flayers.getLayersCount();
375
                        for (int i = 0; i < numLayers; i++) {
376
                                FLayer layer = flayers.getLayer(i);
377
                                String name = layer.getName();
378
                                layerChoice.addItem(name);
379
                        }
380
                }
381
                this.updateUI();
382
        }
383

    
384
        /* (non-Javadoc)
385
         * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
386
         */
387
        public void actionPerformed(ActionEvent e) {
388
                String actionCommand = e.getActionCommand();
389

    
390
                if (actionCommand.equals("CAMERA_KEY_FRAME")) { // play pressed
391

    
392
                        AnimationUtils.captureEncuadrator(
393
                                        (BaseView) this.getViewSelected(), this.animationContainer,
394
                                        this.projectAnimationDocument.getName());
395

    
396
                } else if (actionCommand.equals("LAYER_PROPERTIES")) {
397

    
398
                        // Generating the animation transparency
399
                        AnimationUtils.createLayerTransparencyAnimation((BaseView) this
400
                                        .getViewSelected(), this.animationContainer,
401
                                        this.projectAnimationDocument.getName());
402

    
403
                } else if (actionCommand.equals("ANIMATION_CONTROL")) {
404
                        AnimationPlayer ap = this.animationContainer.getAnimationPlayer();
405
                        ap.setAnimationContainer(animationContainer);
406
                        AnimationContol3D fp = new AnimationContol3D(ap);
407
                        PluginServices.getMDIManager().addWindow((IWindow) fp);
408
                }
409
        }
410

    
411
}