Revision 25512

View differences:

tags/3D_Animation_v1_0alpha_Build_5/extensions/extAnimationGUI/src/com/iver/ai2/animationgui/gui/WindowClosedListener.java
1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
*
3
* Copyright (C) 2005 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
package com.iver.ai2.animationgui.gui;
20

  
21
import java.util.EventListener;
22
import java.util.EventObject;
23

  
24
public interface WindowClosedListener extends EventListener {
25
	/**
26
	 * Evento que se dispara cuando se cierra una ventana.
27
	 * @param e
28
	 */
29
	public void actionClosed(EventObject e);
30
}
tags/3D_Animation_v1_0alpha_Build_5/extensions/extAnimationGUI/src/com/iver/ai2/animationgui/gui/MenuAnimation3D.java
1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
*
3
* Copyright (C) 2005 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

  
20
package com.iver.ai2.animationgui.gui;
21

  
22
import javax.swing.JOptionPane;
23

  
24
import com.iver.ai2.animationgui.gui.document.ProjectAnimationDocument;
25
import com.iver.ai2.animationgui.gui.toc.TocAnimationDate;
26
import com.iver.ai2.animationgui.gui.util.AnimationUtils;
27
import com.iver.ai2.gvsig3d.camera.ProjectCamera;
28
import com.iver.andami.PluginServices;
29
import com.iver.andami.plugins.Extension;
30
import com.iver.andami.plugins.IExtension;
31
import com.iver.andami.ui.mdiManager.IWindow;
32
import com.iver.cit.gvsig.ProjectExtension;
33
import com.iver.cit.gvsig.animation.AnimationContainer;
34
import com.iver.cit.gvsig.animation.AnimationPlayer;
35
import com.iver.cit.gvsig.project.Project;
36
import com.iver.cit.gvsig.project.documents.view.gui.BaseView;
37
import com.iver.utiles.extensionPoints.ExtensionPoints;
38
import com.iver.utiles.extensionPoints.ExtensionPointsSingleton;
39

  
40
/**
41
 * @author
42
 * @since 1.1
43
 * 
44
 * Menu of animation toolbar's options.
45
 */
46

  
47
public class MenuAnimation3D extends Extension {
48

  
49
	// private variable that contains the project
50
	private Project project;
51
	// It is the project Document create to create a fast animation.
52
	private ProjectAnimationDocument pad;
53

  
54
	public void execute(String actionCommand) {
55

  
56
		AnimationContainer ac;
57
		String prefix = "Default-animation-document";
58
		// if the button pressed is animation control the animation panel is
59
		// created.
60
		if (actionCommand.equals("CONTROLES")) {
61
			// Getting the animation container.
62
			if (pad != null) {
63
				ac = pad.getAnimationContainer();
64
				AnimationPlayer ap = ac.getAnimationPlayer();
65
				ap.setAnimationContainer(ac);
66
				AnimationContol3D fp = new AnimationContol3D(ap);
67
				PluginServices.getMDIManager().addWindow((IWindow) fp);
68
			} else {
69
				if (AnimationUtils.exitsProject(prefix, project)){
70
					ac = AnimationUtils.getProjectDocument(prefix, project).getAnimationContainer();
71
					AnimationPlayer ap = ac.getAnimationPlayer();
72
					ap.setAnimationContainer(ac);
73
					AnimationContol3D fp = new AnimationContol3D(ap);
74
					PluginServices.getMDIManager().addWindow((IWindow) fp);
75
				}else{
76
					// Show a message that indicates why it is impossible to open
77
					// the player
78
					JOptionPane
79
					.showMessageDialog(null,
80
					"There is not any animation document. Please create one");
81
				}
82
			}
83

  
84
		} else if (actionCommand.equals("ENCUADRECAP")) {// button capture
85
			// if there is not create the default animation. we will create it.
86
			pad = AnimationUtils.createAnimationDocument(prefix, project);
87
			if (!AnimationUtils.exitsProject(prefix, project)){
88
				project.addDocument(pad);
89
			}
90

  
91
			// Getting the active windows
92
			IWindow w = PluginServices.getMDIManager().getActiveWindow();
93

  
94
			// Getting the animation container.
95
			ac = pad.getAnimationContainer();
96

  
97
			// Capture the new encuadrator
98
			AnimationUtils.captureEncuadrator((BaseView) w, ac, prefix);
99

  
100
		} else if (actionCommand.equals("CAPACAP")) {// button capture layer
101
			// pressed.
102
			System.out.println("pulsado boton de capturar capa!!!");
103
		} else if (actionCommand.equals("CLEAR_TRACK")) {
104
			//removeCameras(AnimationPrefix);
105
			// // AKFinterval = null;
106
			// cont = 0;
107
			// ac = this.getAnimationContainer();
108
			// ac.removeAllTrack();
109
		}
110

  
111
	}
112

  
113
	/**
114
	 * This method removes all the captures that there are in the encuadrator
115
	 * with the substring "substring"
116
	 * 
117
	 * @param substring
118
	 *            the method removes all the captures that contain this
119
	 *            substring.
120
	 * 
121
	 */
122
	void removeCameras(String substring) {
123
		// Remove all animation keyframe from the encuadrator.
124
		Object[] pcList = project.getCameras();
125
		int i = 0;
126
		while (i < pcList.length) {
127
			ProjectCamera projectCamera = (ProjectCamera) pcList[i];
128
			if (projectCamera.getDescription().contains(substring)) {
129
				project.removeCamera(i);
130
				pcList = project.getCameras();
131
			} else {
132
				i++;
133
			}
134
		}
135
	}
136

  
137
	public void postInitialize() {
138

  
139
		IExtension extension = PluginServices
140
				.getExtension(com.iver.cit.gvsig.ProjectExtension.class);
141
		ProjectExtension pe = (ProjectExtension) extension;
142
		project = pe.getProject();
143

  
144
		PluginServices.getIconTheme().registerDefault(
145
				"camera-link-icon",
146
				this.getClass().getClassLoader().getResource(
147
						"images/camera_link.png"));
148
		PluginServices.getIconTheme().registerDefault(
149
				"camera-add-icon",
150
				this.getClass().getClassLoader().getResource(
151
						"images/camera_add.png"));
152
		PluginServices.getIconTheme().registerDefault(
153
				"camera-edit-icon",
154
				this.getClass().getClassLoader().getResource(
155
						"images/camera_edit.png"));
156

  
157
	}
158

  
159
	public void initialize() {
160

  
161
		// Registering TOC actions
162
		ExtensionPoints extensionPoints = ExtensionPointsSingleton
163
				.getInstance();
164
		extensionPoints.add("View_TocActions", "Generar animacion temporal",
165
				new TocAnimationDate());
166
	}
167

  
168
	public boolean isEnabled() {
169
		return true;
170
	}
171

  
172
	public boolean isVisible() {
173

  
174
		com.iver.andami.ui.mdiManager.IWindow f = PluginServices
175
				.getMDIManager().getActiveWindow();
176

  
177
		if (f == null) {
178
			return false;
179
		}
180

  
181
		// Only isVisible = true, where the view3D have layers
182
		if (f instanceof BaseView) {
183
			return true;
184
		}
185
		return false;
186
	}
187

  
188
}
tags/3D_Animation_v1_0alpha_Build_5/extensions/extAnimationGUI/src/com/iver/ai2/animationgui/gui/util/AnimationUtils.java
1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
*
3
* Copyright (C) 2005 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

  
20
package com.iver.ai2.animationgui.gui.util;
21

  
22
import java.util.ArrayList;
23
import java.util.Iterator;
24
import java.util.List;
25

  
26
import org.gvsig.gvsig3dgui.view.View3D;
27
import org.gvsig.osgvp.planets.Planet;
28
import org.gvsig.osgvp.viewer.Camera;
29

  
30
import com.iver.ai2.animationgui.gui.document.ProjectAnimationDocument;
31
import com.iver.ai2.animationgui.gui.document.ProjectAnimationDocumentFactory;
32
import com.iver.ai2.gvsig3d.camera.ProjectCamera;
33
import com.iver.andami.PluginServices;
34
import com.iver.andami.plugins.IExtension;
35
import com.iver.cit.gvsig.ProjectExtension;
36
import com.iver.cit.gvsig.animation.AnimationContainer;
37
import com.iver.cit.gvsig.animation.IAnimationType;
38
import com.iver.cit.gvsig.animation.animatedObject.AnimatedObjectBase;
39
import com.iver.cit.gvsig.animation.animatedObject.AnimationObject2D;
40
import com.iver.cit.gvsig.animation.animatedObject.AnimationObject3DFlat;
41
import com.iver.cit.gvsig.animation.animatedObject.IAnimatedObject;
42
import com.iver.cit.gvsig.animation.interval.AnimationKeyFrameInterval;
43
import com.iver.cit.gvsig.animation.keyframe.IKeyFrame;
44
import com.iver.cit.gvsig.animation.keyframe.interpolator.FuntionFactory;
45
import com.iver.cit.gvsig.animation.keyframe.interpolator.IInterpolator;
46
import com.iver.cit.gvsig.animation.keyframe.interpolator.IInterpolatorTimeFuntion;
47
import com.iver.cit.gvsig.animation.keyframe.interpolator.InterpolatorFactory;
48
import com.iver.cit.gvsig.animation.traks.AnimationTimeTrack;
49
import com.iver.cit.gvsig.animation.traks.IAnimationTrack;
50
import com.iver.cit.gvsig.fmap.MapContext;
51
import com.iver.cit.gvsig.fmap.MapControl;
52
import com.iver.cit.gvsig.fmap.layers.FLayer;
53
import com.iver.cit.gvsig.fmap.layers.FLayers;
54
import com.iver.cit.gvsig.project.Project;
55
import com.iver.cit.gvsig.project.ProjectExtent;
56
import com.iver.cit.gvsig.project.ProjectFactory;
57
import com.iver.cit.gvsig.project.documents.ProjectDocument;
58
import com.iver.cit.gvsig.project.documents.ProjectDocumentFactory;
59
import com.iver.cit.gvsig.project.documents.view.IProjectView;
60
import com.iver.cit.gvsig.project.documents.view.gui.BaseView;
61
import com.iver.cit.gvsig.project.documents.view.gui.View;
62
import com.iver.utiles.extensionPoints.ExtensionPoint;
63
import com.iver.utiles.extensionPoints.ExtensionPoints;
64
import com.iver.utiles.extensionPoints.ExtensionPointsSingleton;
65

  
66
public class AnimationUtils {
67

  
68
	private static String AnimationPrefix = "Animation-";
69
	private static int cont2D = 0;
70
	private static int cont3D = 0;
71
	private static Project project;
72

  
73
	static {
74
		IExtension extension = PluginServices
75
				.getExtension(com.iver.cit.gvsig.ProjectExtension.class);
76
		ProjectExtension pe = (ProjectExtension) extension;
77
		project = pe.getProject();
78
	}
79

  
80
	public static void captureEncuadrator(BaseView view, AnimationContainer ac,
81
			String prefix) {
82
		// snapshot pressed.
83
		System.out.println("pulsado boton de capturar encuadres!!!");
84

  
85
		// If the window instance is View, it will manage extends 2D
86
		if (view instanceof View) {
87
			AnimationUtils.captureEncuadrator2D((View) view, ac, prefix);
88
		}
89
		else
90
			if (view instanceof BaseView) {
91
				AnimationUtils.captureEncuadrator3D((View3D) view, ac, prefix);
92
			}
93
		
94

  
95
		System.out.println(ac);
96

  
97
	}
98

  
99
	public static void captureEncuadrator2D(View view, AnimationContainer ac,
100
			String prefix) {
101

  
102
		AnimationTimeTrack animationTimeTrack = null;
103
		AnimationKeyFrameInterval AKFinterval = null;
104
		List<IKeyFrame> keyFrameList = null;
105

  
106
		String baseName = prefix + "-" + view.getWindowInfo().getTitle() + "-"
107
				+ AnimationPrefix;
108
		String name = baseName + cont2D++;
109

  
110
		// Getting the animation extension point.
111
		ExtensionPoints extensionPoints = ExtensionPointsSingleton
112
				.getInstance();
113
		ExtensionPoint extPoint = ((ExtensionPoint) extensionPoints
114
				.get("Animation"));
115

  
116
		// Creating new track
117
		animationTimeTrack = AnimationUtils.getAnimationTimeTrack(baseName
118
				+ "-encuadrator_track_2D", ac, view);
119
		// Creating the interval
120
		List intervalList = animationTimeTrack.getIntervalList();
121
		
122
		if (intervalList != null) {
123
			for (Iterator<AnimationKeyFrameInterval> iterator = intervalList.iterator(); iterator
124
					.hasNext();) {
125
				AnimationKeyFrameInterval animationKeyFrameInterval = iterator.next();
126
				if (animationKeyFrameInterval != null) {
127
					AKFinterval = animationKeyFrameInterval;
128
				}
129
			}
130
			if (intervalList.size() == 0) {
131
				AKFinterval = (AnimationKeyFrameInterval) animationTimeTrack
132
						.createKeyFrameInterval();
133
				// Setting up interval properties.
134
				AKFinterval.setInitialTime(0.0);
135
				AKFinterval.setEndTime(1.0);
136
			}
137
		}
138
		
139
		
140

  
141
		// Getting the current extend and adding to project extends.
142
		MapControl mapa = view.getMapControl();
143
		ProjectExtent extent = ProjectFactory.createExtent();
144
		extent.setDescription(name);
145
		extent.setExtent(mapa.getViewPort().getExtent());
146
		project.addExtent(extent);
147

  
148
		// Creating the keyframe list.
149
		ProjectExtent[] extentsList = project.getExtents();
150
		keyFrameList = new ArrayList<IKeyFrame>();
151
		for (int i = 0; i < extentsList.length; i++) {
152
			ProjectExtent projectExtent = extentsList[i];
153
			if (projectExtent.getDescription().contains(baseName)) {
154
				IKeyFrame kf2D = null;
155
				try {
156
					kf2D = (IKeyFrame) extPoint.create("KeyFrame2D");
157
				} catch (InstantiationException e) {
158
					e.printStackTrace();
159
				} catch (IllegalAccessException e) {
160
					e.printStackTrace();
161
				}
162

  
163
				// Setting up the initial and end time interval.
164
				double fin = AKFinterval.getEndTime();
165
				double ini = AKFinterval.getInitialTime();
166
				double size = extentsList.length;
167
				// Calculating the insertion time.
168
				double tiempo = 0.0;
169
				if (i != 0)
170
					tiempo = i * ((fin - ini) / (size - 1.0));
171
				kf2D.setTime(tiempo);
172
				// hacer funcion de insercion o adapter
173
				kf2D.setAnimatedObject(projectExtent);
174
				kf2D.CapturesProperties();
175
				keyFrameList.add(kf2D);
176
			}
177
		}
178
		AKFinterval.setKeyFrameList(keyFrameList);
179
	}
180

  
181
	public static Project getProject() {
182
		return project;
183
	}
184
	
185
	
186
	public static String getAnimationPrefix() {
187
		return AnimationPrefix;
188
	}
189

  
190
	public static void captureEncuadrator3D(View3D view, AnimationContainer ac,
191
			String prefix) {
192
		AnimationTimeTrack animationTimeTrack = null;
193
		AnimationKeyFrameInterval AKFinterval = null;
194
		List<IKeyFrame> keyFrameList = null;
195

  
196
		String baseName = prefix + "-" + view.getWindowInfo().getTitle() + "-"
197
				+ AnimationPrefix;
198
		String name = baseName + cont3D++;
199

  
200
		// Getting the animation extension point.
201
		ExtensionPoints extensionPoints = ExtensionPointsSingleton
202
				.getInstance();
203
		ExtensionPoint extPoint = ((ExtensionPoint) extensionPoints
204
				.get("Animation"));
205

  
206
		// Creating new track
207
		animationTimeTrack = AnimationUtils.getAnimationTimeTrack(baseName
208
				+ "-encuadrator_track_3D", ac, view);
209

  
210
		// Creating the interval
211
		List intervalList = animationTimeTrack
212
				.getIntervalList();
213
		if (intervalList != null) {
214
			for (Iterator iterator = intervalList.iterator(); iterator
215
					.hasNext();) {
216
				AnimationKeyFrameInterval animationKeyFrameInterval = (AnimationKeyFrameInterval) iterator
217
						.next();
218
				if (animationKeyFrameInterval != null) {
219
					AKFinterval = animationKeyFrameInterval;
220
				}
221
			}
222
			if (intervalList.size() == 0) {
223
				AKFinterval = (AnimationKeyFrameInterval) animationTimeTrack
224
						.createKeyFrameInterval();
225
				// Setting up interval properties.
226
				AKFinterval.setInitialTime(0.0);
227
				AKFinterval.setEndTime(1.0);
228
			}
229
		}
230
		// Getting the current camera position and insert it into project camera
231
		// list.
232
		Camera ca = view.getCamera();
233
		ProjectCamera camera = new ProjectCamera();
234
		camera.setDescription(name);
235
		camera.setCamera(ca);
236
		project.addCamera(camera);
237

  
238
		List<ProjectCamera> extentsList = filterExtendsList(baseName, project);
239
		keyFrameList = new ArrayList<IKeyFrame>();
240
		for (int i = 0; i < extentsList.size(); i++) {
241
			ProjectCamera projectCamera = (ProjectCamera) extentsList.get(i);
242
			IKeyFrame kf3D = null;
243
			try {
244
				kf3D = (IKeyFrame) extPoint.create("KeyFrame3DFlat");
245
			} catch (InstantiationException e) {
246
				e.printStackTrace();
247
			} catch (IllegalAccessException e) {
248
				e.printStackTrace();
249
			}
250

  
251
			// Setting up the initial and end time interval.
252
			double fin = AKFinterval.getEndTime();
253
			double ini = AKFinterval.getInitialTime();
254
			double size = extentsList.size();
255
			// Calculating the correct time for this key frame.
256
			double tiempo = 0.0;
257
			if (i != 0)
258
				tiempo = i * ((fin - ini) / (size - 1.0));
259
			// Setting the time.
260
			kf3D.setTime(tiempo);
261
			// hacer funcion de insercion o adapter
262
			kf3D.setAnimatedObject(projectCamera);
263
			kf3D.CapturesProperties();
264
			keyFrameList.add(kf3D);
265
		}
266
		AKFinterval.setKeyFrameList(keyFrameList);
267

  
268
	}
269

  
270
	private static List<ProjectCamera> filterExtendsList(String baseName,
271
			Project project2) {
272
		List<ProjectCamera> extendsList = null;
273
		Object[] extentsList = project2.getCameras();
274
		for (int i = 0; i < extentsList.length; i++) {
275
			ProjectCamera projectCamera = (ProjectCamera) extentsList[i];
276
			if (projectCamera.getDescription().contains(baseName)) {
277
				if (extendsList == null)
278
					extendsList = new ArrayList<ProjectCamera>();
279
				extendsList.add(projectCamera);
280
			}
281
		}
282
		return extendsList;
283
	}
284

  
285
	private static AnimationTimeTrack getAnimationTimeTrack(String name,
286
			AnimationContainer ac, BaseView view) {
287

  
288
		AnimationTimeTrack att = null;
289
		if (view instanceof View) {
290
			att = AnimationUtils.getAnimationTimeTrackForView(name, ac,
291
					(View) view);
292
		}
293

  
294
		if (view instanceof View3D) {
295
			att = AnimationUtils.getAnimationTimeTrackForView3D(name, ac,
296
					(View3D) view);
297
		}
298
		return att;
299
	}
300

  
301
	private static AnimationTimeTrack getAnimationTimeTrackForView(String name,
302
			AnimationContainer ac, View view) {
303

  
304
		AnimationTimeTrack at = null;
305
		IAnimationTrack aa = ac.findTrack(name);
306
		if (aa == null) {
307

  
308
			// Getting the extension point.
309
			ExtensionPoints extensionPoints = ExtensionPointsSingleton
310
					.getInstance();
311
			ExtensionPoint extPoint = ((ExtensionPoint) extensionPoints
312
					.get("Animation"));
313

  
314
			IAnimationType animationLayer2D = null;
315
			try {
316
				animationLayer2D = (IAnimationType) extPoint
317
						.create("AnimationLayer2D");
318
			} catch (InstantiationException e) {
319
				// TODO Auto-generated catch block
320
				e.printStackTrace();
321
			} catch (IllegalAccessException e) {
322
				// TODO Auto-generated catch block
323
				e.printStackTrace();
324
			}
325
			// Setting up the track properties
326
			at = (AnimationTimeTrack) ac.CreateTimeTrack(animationLayer2D);
327
			at.setName(name);
328
			at.setEnable(true);
329
			// Setting up the animated object
330
			// Creating the object 2D
331
			AnimatedObjectBase object2D = new AnimationObject2D();
332

  
333
			// Getting the interpolator
334
			IInterpolator inter2D = InterpolatorFactory
335
					.createObject("Interpolator2D");
336
			((AnimationObject2D)object2D).setAnimatedView(view);
337
			
338
			// Getting the interpolator funcion
339
			IInterpolatorTimeFuntion funtion = FuntionFactory
340
					.createObject("com.iver.cit.gvsig.animation.keyframe.interpolator.LinearFuntion");
341
			inter2D.setFuntion(funtion);
342

  
343
			animationLayer2D.setInterpolator(inter2D);
344
			at.setAnimationType(animationLayer2D);
345
			animationLayer2D.setAnimatedObject(object2D);
346
			
347
			at.setAnimatedObject(object2D);
348
		} else {
349
			at = (AnimationTimeTrack) aa;
350
		}
351

  
352
		return at;
353

  
354
	}
355

  
356
	private static AnimationTimeTrack getAnimationTimeTrackForView3D(
357
			String name, AnimationContainer ac, View3D view) {
358

  
359
		AnimationTimeTrack at = null;
360
		IAnimationTrack aa = ac.findTrack(name);
361
		if (aa == null) {
362

  
363
			// Getting the extension point.
364
			ExtensionPoints extensionPoints = ExtensionPointsSingleton
365
					.getInstance();
366
			ExtensionPoint extPoint = ((ExtensionPoint) extensionPoints
367
					.get("Animation"));
368

  
369
			IAnimationType animationLayer3DFlat = null;
370
			try {
371
				animationLayer3DFlat = (IAnimationType) extPoint
372
						.create("AnimationLayer3DFlat");
373
			} catch (InstantiationException e) {
374
				// TODO Auto-generated catch block
375
				e.printStackTrace();
376
			} catch (IllegalAccessException e) {
377
				e.printStackTrace();
378
			}
379
			at = (AnimationTimeTrack) ac.CreateTimeTrack(animationLayer3DFlat);
380

  
381
			at.setName(name);
382
			at.setEnable(true);
383

  
384
			AnimatedObjectBase object3D = new AnimationObject3DFlat();
385
			((AnimationObject3DFlat)object3D).setAnimatedCanvas3D(view.getCanvas3d());
386
			((AnimationObject3DFlat)object3D).setAnimatedView(view);
387
			
388
			at.setAnimatedObject(object3D);
389

  
390
			/** ******************************************************************* */
391
			IInterpolator interpolator3D = null;
392
			if (view.getPlanet().getCoordinateSystemType() == Planet.CoordinateSystemType.PROJECTED) {
393
				interpolator3D = InterpolatorFactory
394
						.createObject("Interpolator3DFlat");
395
			} else if (view.getPlanet().getCoordinateSystemType() == Planet.CoordinateSystemType.GEOCENTRIC) {
396
				interpolator3D = InterpolatorFactory
397
						.createObject("Interpolator3DSpherical");
398
			}
399

  
400
			IInterpolatorTimeFuntion funtion = FuntionFactory
401
					.createObject("com.iver.cit.gvsig.animation.keyframe.interpolator.LinearFuntion");
402
			interpolator3D.setFuntion(funtion);
403
			animationLayer3DFlat.setInterpolator(interpolator3D);
404
			at.setAnimationType(animationLayer3DFlat);
405
			
406
			animationLayer3DFlat.setAnimatedObject(object3D);
407

  
408
			/** ********************************************************************* */
409
			/*******************************************************************
410
			 * old code * IInterpolator inter3DFlat = InterpolatorFactory
411
			 * .createObject("Interpolator3DFlat"); IInterpolatorTimeFuntion
412
			 * funtion = FuntionFactory
413
			 * .createObject("com.iver.cit.gvsig.animation.keyframe.interpolator.LinearFuntion");
414
			 * inter3DFlat.setFuntion(funtion);
415
			 * animationLayer3DFlat.setInterpolator(inter3DFlat);
416
			 * at.setAnimationType(animationLayer3DFlat);
417
			 * animationLayer3DFlat.setAnimatedObject(object3D); /
418
			 ******************************************************************/
419
		} else {
420
			at = (AnimationTimeTrack) aa;
421
		}
422
		return at;
423

  
424
	}
425

  
426
	public static ProjectAnimationDocument createAnimationDocument(
427
			String viewName, Project project) {
428
		ProjectAnimationDocument pv = null;
429
		ArrayList<ProjectDocument> projectList = project
430
				.getDocumentsByType(ProjectAnimationDocumentFactory.registerName);
431
		Iterator<ProjectDocument> it = projectList.iterator();
432
		while (it.hasNext()) {
433
			ProjectDocument projectDocument = (ProjectDocument) it.next();
434
			if (viewName.equals(projectDocument.getName())) {
435
				pv = (ProjectAnimationDocument) projectDocument;
436
			}
437

  
438
		}
439
		if (pv == null) {
440
			ExtensionPoints extensionPoints = ExtensionPointsSingleton
441
					.getInstance();
442
			ExtensionPoint extPoint = ((ExtensionPoint) extensionPoints
443
					.get("Documents"));
444
			ProjectDocumentFactory pdf = null;
445
			try {
446
				pdf = (ProjectDocumentFactory) extPoint
447
						.create(ProjectAnimationDocumentFactory.registerName);
448
			} catch (InstantiationException e) {
449
				e.printStackTrace();
450
			} catch (IllegalAccessException e) {
451
				e.printStackTrace();
452
			}
453
			pv = (ProjectAnimationDocument) pdf.create((Project) null);
454
			pv.setProjectDocumentFactory(pdf);
455
			pv.setName(viewName);
456
		}
457
		return pv;
458
	}
459

  
460
	public static ProjectAnimationDocument getProjectDocument(String name,
461
			Project project) {
462
		ProjectAnimationDocument pv = null;
463
		ArrayList<ProjectDocument> projectList = project
464
				.getDocumentsByType(ProjectAnimationDocumentFactory.registerName);
465
		Iterator<ProjectDocument> it = projectList.iterator();
466
		while (it.hasNext()) {
467
			ProjectDocument projectDocument = (ProjectDocument) it.next();
468
			if (name.equals(projectDocument.getName())) {
469
				pv = (ProjectAnimationDocument) projectDocument;
470
			}
471

  
472
		}
473
		return pv;
474
	}
475

  
476
	public static boolean exitsProject(String name, Project project) {
477
		boolean pv = false;
478
		ArrayList<ProjectDocument> projectList = project
479
				.getDocumentsByType(ProjectAnimationDocumentFactory.registerName);
480
		Iterator<ProjectDocument> it = projectList.iterator();
481
		while (it.hasNext()) {
482
			ProjectDocument projectDocument = (ProjectDocument) it.next();
483
			if (name.equals(projectDocument.getName())) {
484
				pv = true;
485
			}
486

  
487
		}
488
		return pv;
489
	}
490

  
491
	/**
492
	 * 
493
	 * @param name :
494
	 *            Track name.
495
	 * @param ac :
496
	 *            animation container.
497
	 * @param object
498
	 * @return at : Return a animation track based in time.
499
	 * 
500
	 * Creating a animation track based in time.
501
	 */
502
	public static AnimationTimeTrack getAnimationTimeTrackTransparency(
503
			String name, AnimationContainer ac, BaseView view,
504
			IAnimatedObject object) {
505

  
506
		AnimationTimeTrack at = null;// this.animationTimeTrack;
507

  
508
		IAnimationTrack animationTrack = ac.findTrack(name);
509
		if (animationTrack == null) {
510

  
511
			ExtensionPoints extensionPoints = ExtensionPointsSingleton
512
					.getInstance();
513
			ExtensionPoint extPoint = ((ExtensionPoint) extensionPoints
514
					.get("Animation"));
515

  
516
			IAnimationType animTransp = null;
517
			try {
518
				System.out.println(extPoint.getDescription());
519

  
520
				// Instancing my new animation based in transparency.
521
				animTransp = (IAnimationType) extPoint
522
						.create("AnimationTransparency");
523
			} catch (InstantiationException e) {
524
				e.printStackTrace();
525
			} catch (IllegalAccessException e) {
526
				e.printStackTrace();
527
			}
528

  
529
			at = (AnimationTimeTrack) ac.CreateTimeTrack(animTransp);
530
			at.setName(name);
531

  
532
			// Saving the view( in this case a BaseView).
533

  
534
			object.addAnimatedObject("view", view);
535

  
536
			at.setAnimatedObject(object);
537
			animTransp.setAnimatedObject(object);
538
			// My interpolator based in time and transparency.
539
			IInterpolator interTransparency = InterpolatorFactory
540
					.createObject("InterpolatorTransparency");
541
			animTransp.setInterpolator(interTransparency);
542
			at.setAnimationType(animTransp);
543
		} else {
544
			at = (AnimationTimeTrack) animationTrack;
545
		}
546
		return at;
547
	}
548

  
549
	public static void createLayerTransparencyAnimation(BaseView window,
550
			AnimationContainer ac, String prefix) {
551
		System.out.println("pulsado boton transparencias !!!");
552

  
553
		AnimationTimeTrack animationTimeTrack = null;
554
		AnimationKeyFrameInterval AKFinterval = null;
555
		List<IKeyFrame> keyFrameList = null;
556
		AnimatedObjectBase object = new AnimatedObjectBase();
557
		// Getting the animation extension point
558
		ExtensionPoints extensionPoints = ExtensionPointsSingleton
559
				.getInstance();
560
		ExtensionPoint extPoint = ((ExtensionPoint) extensionPoints
561
				.get("Animation"));
562

  
563
		// List of keyframes.
564
		// If the window is instance of View
565
		if (window instanceof BaseView) {
566

  
567
			BaseView view = (BaseView) window;
568

  
569
			// Generating the list of keyframes
570
			// keyFrameList = new ArrayList();
571
			IProjectView model = view.getModel();
572
			MapContext mapContext = model.getMapContext();
573
			FLayers layers = mapContext.getLayers();
574
			FLayer[] actives = layers.getActives();
575

  
576
			double fin = 1;// AKFinterval.getEndTime();
577
			double ini = 0;// AKFinterval.getInitialTime();
578
			double tiempo = 0.0;
579
			int size = actives.length;
580
			double incremento = ((fin - ini) / (size));
581
			for (int i = size - 1; i >= 0; i--) {// order in TOC.
582

  
583
				animationTimeTrack = null;
584
				animationTimeTrack = AnimationUtils
585
						.getAnimationTimeTrackTransparency("Track_layer_" + i,
586
								ac, view, object);
587
				animationTimeTrack.setEnable(true);
588
				object.addAnimatedObject("layer", actives[i]);
589

  
590
				// Generating the interval.
591
				AKFinterval = (AnimationKeyFrameInterval) animationTimeTrack
592
						.createKeyFrameInterval();
593
				AKFinterval.setInitialTime(0.0);
594
				AKFinterval.setEndTime(1.0);
595

  
596
				keyFrameList = new ArrayList<IKeyFrame>();
597
				IKeyFrame kfTransAux = null;
598
				IKeyFrame kfTransIni = null;
599
				IKeyFrame kfTransFin = null;
600
				try {
601
					kfTransAux = (IKeyFrame) extPoint
602
							.create("KeyFrameTransparency");
603
					kfTransIni = (IKeyFrame) extPoint
604
							.create("KeyFrameTransparency");
605
					kfTransFin = (IKeyFrame) extPoint
606
							.create("KeyFrameTransparency");
607
				} catch (InstantiationException e1) {
608
					e1.printStackTrace();
609
				} catch (IllegalAccessException e1) {
610
					e1.printStackTrace();
611
				}
612
				// Calculating the time insertion.
613
				if (i == size - 1) // the keyframe is the first in the list.
614
					tiempo = ini + 0.001;
615

  
616
				// Three keyframes by track.
617
				// Keyframe 1 of the layer i.
618
				kfTransAux.setName("KF1_layer_" + i);// name of keyframe.
619
				kfTransAux.setTime(ini); // initial time interval.
620
				kfTransAux.setAnimatedObject(actives[i]);// set the object to
621
				// animate(a layer).
622
				kfTransAux.CapturesProperties(); // capturing actual
623
				// transparency.
624
				keyFrameList.add(kfTransAux); // adding in the list.
625

  
626
				// keyframe 2 of the layer i.
627
				kfTransIni.setName("KF2_layer_" + i);// name of keyframe.
628
				kfTransIni.setTime(tiempo); // initial time interval.
629
				kfTransIni.setAnimatedObject(actives[i]);// set the same
630
				// layer in the
631
				// second keyframe.
632
				kfTransIni.CapturesProperties(); // capturing actual
633
				// transparency.
634
				keyFrameList.add(kfTransIni); // adding in the list.
635

  
636
				// keyframe 3 of the layer i.
637
				try {
638
					if (i == 0) // the keyframe is the last in the list.
639
						tiempo = fin;
640
					else
641
						tiempo += incremento;
642

  
643
					kfTransFin.setName("KF3_layer_" + i);// name of keyframe.
644
					kfTransFin.setTime(tiempo);// saving final time interval.
645
					// kfTransFin.setLevelTransparency(0);// interpolation:
646
					// layer transparency in
647
					// the moment to 0.
648
					kfTransFin.setAnimatedObject(actives[i]); // save the same
649
					// layer in the
650
					// third
651
					// keyframe
652
					keyFrameList.add(kfTransFin);// adding to the list.
653
				} catch (Exception e) {
654
					// TODO Auto-generated catch block
655
					e.printStackTrace();
656
				}
657
				AKFinterval.setKeyFrameList(keyFrameList);// Adding the list
658
				// of keyframes to
659
				// the interval.
660

  
661
			}
662
		}
663
	}
664

  
665
}
tags/3D_Animation_v1_0alpha_Build_5/extensions/extAnimationGUI/src/com/iver/ai2/animationgui/gui/MenuAnimationTransparency.java
1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
*
3
* Copyright (C) 2005 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

  
20
package com.iver.ai2.animationgui.gui;
21

  
22
import com.iver.ai2.animationgui.gui.document.ProjectAnimationDocument;
23
import com.iver.ai2.animationgui.gui.util.AnimationUtils;
24
import com.iver.andami.PluginServices;
25
import com.iver.andami.plugins.Extension;
26
import com.iver.andami.plugins.IExtension;
27
import com.iver.andami.ui.mdiManager.IWindow;
28
import com.iver.cit.gvsig.ProjectExtension;
29
import com.iver.cit.gvsig.animation.AnimationContainer;
30
import com.iver.cit.gvsig.animation.IAnimationType;
31
import com.iver.cit.gvsig.animation.animatedObject.AnimatedObjectBase;
32
import com.iver.cit.gvsig.animation.keyframe.interpolator.IInterpolator;
33
import com.iver.cit.gvsig.animation.keyframe.interpolator.InterpolatorFactory;
34
import com.iver.cit.gvsig.animation.traks.AnimationTimeTrack;
35
import com.iver.cit.gvsig.animation.traks.IAnimationTrack;
36
import com.iver.cit.gvsig.fmap.MapContext;
37
import com.iver.cit.gvsig.fmap.layers.FLayer;
38
import com.iver.cit.gvsig.fmap.layers.FLayers;
39
import com.iver.cit.gvsig.project.Project;
40
import com.iver.cit.gvsig.project.documents.view.IProjectView;
41
import com.iver.cit.gvsig.project.documents.view.gui.BaseView;
42
import com.iver.utiles.extensionPoints.ExtensionPoint;
43
import com.iver.utiles.extensionPoints.ExtensionPoints;
44
import com.iver.utiles.extensionPoints.ExtensionPointsSingleton;
45

  
46
/**
47
 * @author ?ngel
48
 * @since 1.1
49
 * 
50
 * Menu of animation transparency toolbar's options.
51
 */
52

  
53
public class MenuAnimationTransparency extends Extension {
54

  
55
	private Project project;
56

  
57
	// private AnimationContainer ac = null;
58
	private AnimationTimeTrack animationTimeTrack = null;
59
	private AnimatedObjectBase object = new AnimatedObjectBase();
60

  
61
	// It is the project Document create to create a fast animation.
62
	private ProjectAnimationDocument pad;
63

  
64
	public void execute(String actionCommand) {
65

  
66
		AnimationContainer ac;
67
		// if the button pressed is "this"
68
		if (actionCommand.equals("CREARANIMTRANSP")) {
69

  
70
			String prefix = "Default-animation-document";
71
			// if there is not create the default animation. we will create it.
72
			pad = AnimationUtils.createAnimationDocument(prefix, project);
73
			if (!AnimationUtils.exitsProject(prefix, project)){
74
				project.addDocument(pad);
75
			}
76

  
77
			// Getting the active windows
78
			IWindow window = PluginServices.getMDIManager().getActiveWindow();
79

  
80
			// Getting the animation container
81
			ac = pad.getAnimationContainer();
82
			// Generating the animation transparency
83
			AnimationUtils.createLayerTransparencyAnimation((BaseView) window,
84
					ac, prefix);
85

  
86
			// Menu Player.
87
			// AnimationPlayer ap = ac.getAnimationPlayer();
88
			// ap.setAnimationContainer(ac);
89
			// AnimationContol3D fp = new AnimationContol3D(ap);
90
			// PluginServices.getMDIManager().addWindow((IWindow) fp);
91
		}
92

  
93
		// System.out.println("pulsado boton transparencias !!!");
94
		//			
95
		// // Getting the active windows
96
		// IWindow window = PluginServices.getMDIManager().getActiveWindow();
97
		//			
98
		// // Getting the animation container
99
		// ac = this.getAnimationContainer();
100
		//			
101
		//			
102
		// // Getting the animation extension point
103
		// ExtensionPoints extensionPoints =
104
		// ExtensionPointsSingleton.getInstance();
105
		// ExtensionPoint extPoint = ((ExtensionPoint)
106
		// extensionPoints.get("Animation"));
107
		//			
108
		//			
109
		// //List of keyframes.
110
		// // If the window is instance of View
111
		// if (window instanceof BaseView) {
112
		//
113
		// BaseView view = (BaseView) window;
114
		//
115
		// // Generating the list of keyframes
116
		// //keyFrameList = new ArrayList();
117
		// IProjectView model = view.getModel();
118
		// MapContext mapContext = model.getMapContext();
119
		// FLayers layers = mapContext.getLayers();
120
		// FLayer[] actives = layers.getActives();
121
		//				
122
		// double fin = 1;//AKFinterval.getEndTime();
123
		// double ini = 0;//AKFinterval.getInitialTime();
124
		// double tiempo = 0.0;
125
		// int size = actives.length;
126
		// double incremento = ((fin - ini) / (size));
127
		// for(int i = size-1; i >= 0; i--){// order in TOC.
128
		//					
129
		// animationTimeTrack = null;
130
		// animationTimeTrack =
131
		// AnimationUtils.getAnimationTimeTrackTransparency("Track_layer_" + i,
132
		// ac);
133
		// animationTimeTrack.setEnabale(true);
134
		// object.addAnimatedObject("layer",actives[i]);
135
		//					
136
		//					
137
		// // Generating the interval.
138
		// AKFinterval = (AnimationKeyFrameInterval) animationTimeTrack
139
		// .createKeyFrameInterval();
140
		// AKFinterval.setInitialTime(0.0);
141
		// AKFinterval.setEndTime(1.0);
142
		//					
143
		// keyFrameList = new ArrayList<IKeyFrame>();
144
		// // KeyFrameTransparency kfTransAux = new KeyFrameTransparency();
145
		// IKeyFrame kfTransAux = null;
146
		// IKeyFrame kfTransIni = null;
147
		// IKeyFrame kfTransFin = null;
148
		// try {
149
		// kfTransAux = (IKeyFrame)extPoint.create("KeyFrameTransparency");
150
		// kfTransIni = (IKeyFrame)extPoint.create("KeyFrameTransparency");
151
		// kfTransFin = (IKeyFrame)extPoint.create("KeyFrameTransparency");
152
		// }
153
		// catch (InstantiationException e1) {
154
		// e1.printStackTrace();
155
		// } catch (IllegalAccessException e1) {
156
		// e1.printStackTrace();
157
		// }
158
		// //Calculating the time insertion.
159
		// if (i == size-1) // the keyframe is the first in the list.
160
		// tiempo = ini + 0.001;
161
		//					
162
		// //Three keyframes by track.
163
		// //Keyframe 1 of the layer i.
164
		// kfTransAux.setName("KF1_layer_" + i);//name of keyframe.
165
		// kfTransAux.setTime(ini); // initial time interval.
166
		// kfTransAux.setAnimatedObject(actives[i]);//set the object to
167
		// animate(a layer).
168
		// //kfTransAux.setLevelTransparency(255);
169
		// kfTransAux.CapturesProperties(); //capturing actual transparency.
170
		// keyFrameList.add(kfTransAux); // adding in the list.
171
		//					
172
		// //keyframe 2 of the layer i.
173
		// kfTransIni.setName("KF2_layer_" + i);//name of keyframe.
174
		// kfTransIni.setTime(tiempo); // initial time interval.
175
		// kfTransIni.setAnimatedObject(actives[i]);//set the same layer in the
176
		// second keyframe.
177
		// kfTransIni.CapturesProperties(); //capturing actual transparency.
178
		// keyFrameList.add(kfTransIni); // adding in the list.
179
		//					
180
		// //keyframe 3 of the layer i.
181
		// try {
182
		// if(i == 0) // the keyframe is the last in the list.
183
		// tiempo = fin;
184
		// else
185
		// tiempo += incremento;
186
		//						
187
		// kfTransFin.setName("KF3_layer_" + i);//name of keyframe.
188
		// kfTransFin.setTime(tiempo);// saving final time interval.
189
		// // kfTransFin.setLevelTransparency(0);// interpolation: layer
190
		// transparency in the moment to 0.
191
		// kfTransFin.setAnimatedObject(actives[i]); //save the same layer in
192
		// the third keyframe
193
		// keyFrameList.add(kfTransFin);//adding to the list.
194
		// } catch (Exception e) {
195
		// // TODO Auto-generated catch block
196
		// e.printStackTrace();
197
		// }
198
		// AKFinterval.setKeyFrameList(keyFrameList);// Adding the list of
199
		// keyframes to the interval.
200
		//					
201
		// }
202
		// }
203
		// }
204

  
205
	}
206

  
207
	public void postInitialize() {
208
		// Getting the project using plugin services.
209
		IExtension extension = PluginServices
210
				.getExtension(com.iver.cit.gvsig.ProjectExtension.class);
211
		ProjectExtension pe = (ProjectExtension) extension;
212
		project = pe.getProject();
213

  
214
		PluginServices.getIconTheme().registerDefault(
215
				"transparency-icon",
216
				this.getClass().getClassLoader().getResource(
217
						"images/trans6.png"));
218
	}
219

  
220
	public void initialize() {
221
		// TODO Auto-generated method stub
222
	}
223

  
224
	
225
	/**
226
	 * 
227
	 * @param name :
228
	 *            Track name.
229
	 * @param ac :
230
	 *            animation container.
231
	 * @return at : Return a animation track based in time.
232
	 * 
233
	 * Creating a animation track based in time.
234
	 */
235
	private AnimationTimeTrack getAnimationTimeTrack_DELETED(String name,
236
			AnimationContainer ac) {
237

  
238
		AnimationTimeTrack at = this.animationTimeTrack;
239

  
240
		IAnimationTrack animationTrack = ac.findTrack(name);
241
		if (animationTrack == null) {
242

  
243
			ExtensionPoints extensionPoints = ExtensionPointsSingleton
244
					.getInstance();
245
			ExtensionPoint extPoint = ((ExtensionPoint) extensionPoints
246
					.get("Animation"));
247
			com.iver.andami.ui.mdiManager.IWindow f = PluginServices // window
248
																		// active.
249
					.getMDIManager().getActiveWindow();
250

  
251
			if (f instanceof BaseView) {
252
				IAnimationType animTransp = null;
253
				try {
254
					System.out.println(extPoint.getDescription());
255

  
256
					// Instancing my new animation based in transparency.
257
					animTransp = (IAnimationType) extPoint
258
							.create("AnimationTransparency");
259
				} catch (InstantiationException e) {
260
					e.printStackTrace();
261
				} catch (IllegalAccessException e) {
262
					e.printStackTrace();
263
				}
264

  
265
				at = (AnimationTimeTrack) ac.CreateTimeTrack(animTransp);
266
				at.setName(name);
267

  
268
				// Saving the view( in this case a BaseView).
269
				BaseView view = (BaseView) f;
270

  
271
				object.addAnimatedObject("view", view);
272

  
273
				at.setAnimatedObject(object);
274
				animTransp.setAnimatedObject(object);
275
				// My interpolator based in time and transparency.
276
				IInterpolator interTransparency = InterpolatorFactory
277
						.createObject("InterpolatorTransparency");
278
				animTransp.setInterpolator(interTransparency);
279
				at.setAnimationType(animTransp);
280
			}
281
		}
282
		return at;
283
	}
284

  
285
	/**
286
	 * @see com.iver.andami.plugins.IExtension#isVisible() Options to see the
287
	 *      button in the tool bar. View: must be a base view. One or more
288
	 *      layers in the view.
289
	 */
290
	public boolean isVisible() {
291
		com.iver.andami.ui.mdiManager.IWindow f = PluginServices
292
				.getMDIManager().getActiveWindow();
293

  
294
		if (f == null) {
295
			return false;
296
		}
297

  
298
		// Only isVisible = true, where the view have layers.
299
		if (f instanceof BaseView) {
300
			BaseView vista = (BaseView) f;
301
			IProjectView model = vista.getModel();
302
			MapContext mapa = model.getMapContext();
303

  
304
			return mapa.getLayers().getLayersCount() > 0;
305
		}
306
		return false;
307
	}
308

  
309
	/**
310
	 * @see com.iver.andami.plugins.IExtension#isEnabled() Options when we can
311
	 *      use this animation type. View: must be a base view. One or more
312
	 *      ACTIVATED layers in the view.
313
	 */
314
	public boolean isEnabled() {
315
		// TODO Auto-generated method stub
316

  
317
		com.iver.andami.ui.mdiManager.IWindow f = PluginServices
318
				.getMDIManager().getActiveWindow();
319

  
320
		// if the view is not activated.
321
		if (f == null)
322
			return false;
323
		// if the view is a instance of a base view.
324
		if (f instanceof BaseView) {
325
			BaseView baseView = (BaseView) f;
326
			IProjectView model = baseView.getModel();
327
			MapContext mapContext = model.getMapContext();
328
			FLayers layers = mapContext.getLayers();
329
			FLayer[] actives = layers.getActives();
330
			// only is enabled with one or more layers activated.
331
			if (actives.length > 0) {
332
				return true;
333
			}
334
		}
335
		return false;
336
	}
337
}
tags/3D_Animation_v1_0alpha_Build_5/extensions/extAnimationGUI/src/com/iver/ai2/animationgui/gui/document/ProjectAnimationDocument.java
1
package com.iver.ai2.animationgui.gui.document;
2

  
3
import java.util.Iterator;
4

  
5
import org.gvsig.gvsig3dgui.view.View3D;
6

  
7
import com.hardcode.gdbms.driver.exceptions.ReadDriverException;
8
import com.iver.andami.ui.mdiManager.IWindow;
9
import com.iver.cit.gvsig.animation.AnimationContainer;
10
import com.iver.cit.gvsig.fmap.layers.XMLException;
11
import com.iver.cit.gvsig.project.Project;
12
import com.iver.cit.gvsig.project.documents.ProjectDocument;
13
import com.iver.cit.gvsig.project.documents.exceptions.OpenException;
14
import com.iver.cit.gvsig.project.documents.exceptions.SaveException;
15
import com.iver.utiles.IPersistence;
16
import com.iver.utiles.XMLEntity;
17

  
18
public class ProjectAnimationDocument extends ProjectDocument {
19

  
20
	/**
21
	 * 
22
	 */
23
	private static final long serialVersionUID = 1L;
24
	AnimationContainer animationContainer;
25
	private Animation animation = null;
26

  
27
	public ProjectAnimationDocument() {
28
		super();
29
		this.animationContainer = new AnimationContainer();
30
	}
31

  
32
	public void afterAdd() {
33
		// TODO Auto-generated method stub
34

  
35
	}
36

  
37
	public void afterRemove() {
38
		// TODO Auto-generated method stub
39

  
40
	}
41

  
42
	public IWindow createWindow() {
43
		// TODO Auto-generated method stub
44
		// Introduce here the code to make the gui.
45
		if (animation == null)
46
			animation = new Animation(this);
47
		return animation;
48
	}
49

  
50
	public void exportToXML(XMLEntity root, Project project) {
51
		// TODO Auto-generated method stub
52
	}
53

  
54
	public IWindow getProperties() {
55
		// TODO Auto-generated method stub
56
		// Introduce here the code to make the gui for the properties.
57
		return new AnimationProperties(this, false);
58
	}
59

  
60
	public void importFromXML(XMLEntity root, XMLEntity typeRoot,
61
			int elementIndex, Project project, boolean removeDocumentsFromRoot) {
62
		// TODO Auto-generated method stub
63

  
64
	}
65

  
66
	public AnimationContainer getAnimationContainer() {
67
		return animationContainer;
68
	}
69

  
70
	public void setAnimationContainer(AnimationContainer animationContainer) {
71
		this.animationContainer = animationContainer;
72
	}
73

  
74
	public XMLEntity getXMLEntity() {
75
		XMLEntity xml = null;
76
		try {
77
			xml = super.getXMLEntity();
78
			xml.addChild(this.animationContainer.getXMLEntity());
79
		} catch (SaveException e) {
80
			// TODO Auto-generated catch block
81
			e.printStackTrace();
82
		}
83
		return xml;
84
	}
85

  
86
	public void setXMLEntity(XMLEntity xml) {
87
		// Busqueda de un hijo a partir de su nombre.
88
		// Node AnimationContainer in the animation tree. Calling setXmlEntity()
89
		// methods.
90
		// Reconstruyendo el framework. Primer paso: nuevo container para
91
		// almacenar.
92
		try {
93
			super.setXMLEntity(xml);
94

  
95
			int animations = 0;
96
			Iterator<XMLEntity> iterator = xml.findChildren(
97
					"animationContainer", "true");
98
			if (iterator.hasNext()) {
99
				XMLEntity xmlAC = iterator.next();
100
				animations++;
101
					String classAC = xmlAC.getStringProperty("className");
102
					Class<?> clase = Class.forName(classAC);
103
					animationContainer = (AnimationContainer) clase
104
							.newInstance();
105
			}
106

  
107
			// Crear objeto a partir de su clase.
108
			Iterator<XMLEntity> iterXML = xml.findChildren("className",
109
					"com.iver.cit.gvsig.animation.AnimationContainer");
110
			if (iterXML.hasNext()) {
111
				((IPersistence) animationContainer)
112
						.setXMLEntity((XMLEntity) iterXML.next());
113
			}
114

  
115
		} catch (XMLException e1) {
116
			// TODO Auto-generated catch block
117
			e1.printStackTrace();
118
		} catch (OpenException e1) {
119
			// TODO Auto-generated catch block
120
			e1.printStackTrace();
121
		} catch (ReadDriverException e1) {
122
			// TODO Auto-generated catch block
123
			e1.printStackTrace();
124
		} catch (InstantiationException e) {
125
			// TODO Auto-generated catch block
126
			e.printStackTrace();
127
		} catch (IllegalAccessException e) {
128
			// TODO Auto-generated catch block
129
			e.printStackTrace();
130
		} catch (ClassNotFoundException e) {
131
			// TODO Auto-generated catch block
132
			e.printStackTrace();
133
		}
134

  
135
	}
136

  
137

  
138
}
tags/3D_Animation_v1_0alpha_Build_5/extensions/extAnimationGUI/src/com/iver/ai2/animationgui/gui/document/AnimationProperties.java
1
/* gvSIG. Sistema de Informaci�n Geogr�fica de la Generalitat Valenciana
2
*
3
* Copyright (C) 2005 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

  
20
package com.iver.ai2.animationgui.gui.document;
21

  
22
import java.awt.Dimension;
23
import java.awt.Insets;
24
import java.awt.event.ActionListener;
25

  
26
import javax.swing.BorderFactory;
27
import javax.swing.JLabel;
28
import javax.swing.JScrollPane;
29
import javax.swing.JTextArea;
30
import javax.swing.JTextField;
31

  
32
import org.gvsig.gui.beans.swing.GridBagLayoutPanel;
33
import org.gvsig.gui.beans.swing.JButton;
34

  
35
import com.iver.andami.PluginServices;
36
import com.iver.andami.ui.mdiManager.SingletonWindow;
37
import com.iver.andami.ui.mdiManager.WindowInfo;
38
import com.iver.cit.gvsig.project.documents.ProjectDocument;
39

  
40
/**
41
 * Dialogo donde se muestran las propiedades de una vista
42
 * 
43
 * @author Fernando Gonz�lez Cort�s
44
 */
45
public class AnimationProperties extends GridBagLayoutPanel implements
46
		SingletonWindow {
47

  
48
	/**
49
	 * 
50
	 */
51
	private static final long serialVersionUID = 1L;
52

  
53
	private JTextField txtName;
54

  
55
	private JTextField txtDate;
56

  
57
	private JTextField txtOwner;
58

  
59
	private int width = 390;
60

  
61
	private int height = 250;
62

  
63
	private JScrollPane jScrollPane;
64

  
65
	private JTextArea txtComments;
66
	
67
	private GridBagLayoutPanel okCancelPanel;
68
	
69
	private boolean editable;
70

  
71
	private JButton okButton;
72

  
73
	private JButton cancelButton;
74

  
75
	private ProjectDocument projectDocument;
76

  
77
	/**
78
	 * This is the default constructor
79
	 * 
80
	 * @param f
81
	 *            Frame padre del dialogo
82
	 * @param v
83
	 *            Vista que se representa
84
	 */
85
	public AnimationProperties(ProjectDocument p, boolean edit) {
86
		projectDocument = p;
87
		setEditable(edit);
88
		initialize();
89
	}
90

  
91
	/**
92
	 * This method initializes this
93
	 */
94
	private void initialize() {
95
		// Inicialize component
96
		setName("Animation properties");
97
		// Introducing the margin 
98
		setBorder(BorderFactory.createEmptyBorder(6, 6, 6, 6));
99
		// Dimension of the panel
100
//		setSize(new Dimension(width, height));
101
		this.setPreferredSize(new Dimension(width, height));
102
		
103
		// ADDING COMPONENTS
104
		
105
		// Name Component
106
		this.addComponent(PluginServices.getText(this, "Name"), getTxtName(), new Insets(0,10,2,10));
107
		// Date component
108
		this.addComponent(PluginServices.getText(this, "Creation_Date"), getTxtDate(), new Insets(2,10,2,10));
109
		// Owner component
110
		this.addComponent(PluginServices.getText(this, "Owner"), getTxtOwner(), new Insets(2,10,2,10));
111
		// Description component
112
		GridBagLayoutPanel aux = new GridBagLayoutPanel();
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff