root / trunk / extensions / extAnimationGUI / src / com / iver / ai2 / animationgui / gui / document / Animation.java @ 20095
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 |
if (viewChoice.getItemCount() > 0) { |
211 |
viewChoice.setSelectedIndex(0);
|
212 |
int index = viewChoice.getSelectedIndex(); // get select item. |
213 |
if (viewList != null) |
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_add.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 + "camera_edit.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_link.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 |
for (int i = 0; i < activeWindows.length; i++) { |
300 |
IWindow window = activeWindows[i]; |
301 |
if ((window.getClass().equals(View.class)) |
302 |
|| (window.getClass().equals(View3D.class))) { |
303 |
viewChoice.addItem(window.getWindowInfo().getTitle()); |
304 |
viewList.add(window); |
305 |
} |
306 |
} |
307 |
if (viewChoice.getItemCount() == 0) |
308 |
viewChoice.addItem("-none-");
|
309 |
|
310 |
viewChoice.addItemListener(this);
|
311 |
} |
312 |
|
313 |
|
314 |
return viewChoice;
|
315 |
} |
316 |
|
317 |
private JComboBox getLayerChoiceValue() { |
318 |
if (layerChoice == null) { |
319 |
layerChoice = new JComboBox(); |
320 |
// IWindow[] activeWindows = PluginServices.getMDIManager()
|
321 |
// .getAllWindows();
|
322 |
// for (int i = 0; i < activeWindows.length; i++) {
|
323 |
// IWindow window = activeWindows[i];
|
324 |
// String name = window.getWindowInfo().getTitle();
|
325 |
// layerChoice.addItem(name);
|
326 |
// }
|
327 |
layerChoice.addItem("-none-");
|
328 |
layerChoice.addItemListener(this);
|
329 |
} |
330 |
refreshLayerSelector(); |
331 |
return layerChoice;
|
332 |
} |
333 |
|
334 |
/* (non-Javadoc)
|
335 |
* @see com.iver.andami.ui.mdiManager.SingletonWindow#getWindowModel()
|
336 |
*/
|
337 |
public Object getWindowModel() { |
338 |
// TODO Auto-generated method stub
|
339 |
return animationContainer;
|
340 |
} |
341 |
|
342 |
public WindowInfo getWindowInfo() {
|
343 |
WindowInfo m_viewinfo = new WindowInfo();
|
344 |
m_viewinfo.setTitle("Animation ");
|
345 |
m_viewinfo.setHeight(height); |
346 |
m_viewinfo.setWidth(width); |
347 |
return m_viewinfo;
|
348 |
} |
349 |
|
350 |
public void itemStateChanged(ItemEvent event) { |
351 |
// Getting the source
|
352 |
Object obj = event.getSource();
|
353 |
// If the view select has changed
|
354 |
if (obj == viewChoice) {
|
355 |
int index = viewChoice.getSelectedIndex(); // get select item. |
356 |
if (viewList != null) { |
357 |
setViewSelected((BaseView) viewList.get(index)); |
358 |
System.out.println("Vista seleccionada : " |
359 |
+ getViewSelected().getWindowInfo().getTitle()); |
360 |
this.refreshLayerSelector();
|
361 |
} |
362 |
} |
363 |
|
364 |
} |
365 |
|
366 |
private void refreshLayerSelector() { |
367 |
if (this.getViewSelected() != null) { |
368 |
|
369 |
BaseView view = this.getViewSelected();
|
370 |
MapControl model = view.getMapControl(); |
371 |
FLayers flayers = model.getMapContext().getLayers(); |
372 |
layerChoice.removeAllItems(); |
373 |
int numLayers = flayers.getLayersCount();
|
374 |
for (int i = 0; i < numLayers; i++) { |
375 |
FLayer layer = flayers.getLayer(i); |
376 |
String name = layer.getName();
|
377 |
layerChoice.addItem(name); |
378 |
} |
379 |
} |
380 |
this.updateUI();
|
381 |
} |
382 |
|
383 |
/* (non-Javadoc)
|
384 |
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
|
385 |
*/
|
386 |
public void actionPerformed(ActionEvent e) { |
387 |
String actionCommand = e.getActionCommand();
|
388 |
|
389 |
if (actionCommand.equals("CAMERA_KEY_FRAME")) { // play pressed |
390 |
|
391 |
AnimationUtils.captureEncuadrator( |
392 |
(BaseView) this.getViewSelected(), this.animationContainer, |
393 |
this.projectAnimationDocument.getName());
|
394 |
|
395 |
} else if (actionCommand.equals("LAYER_PROPERTIES")) { |
396 |
|
397 |
// Generating the animation transparency
|
398 |
AnimationUtils.createLayerTransparencyAnimation((BaseView) this
|
399 |
.getViewSelected(), this.animationContainer,
|
400 |
this.projectAnimationDocument.getName());
|
401 |
|
402 |
} else if (actionCommand.equals("ANIMATION_CONTROL")) { |
403 |
AnimationPlayer ap = this.animationContainer.getAnimationPlayer();
|
404 |
ap.setAnimationContainer(animationContainer); |
405 |
AnimationContol3D fp = new AnimationContol3D(ap);
|
406 |
PluginServices.getMDIManager().addWindow((IWindow) fp); |
407 |
} |
408 |
} |
409 |
|
410 |
} |