Animation in the Globe control
arcgissamples\globe\AnimationRunnable.java
/* Copyright 2010 ESRI
* 
* All rights reserved under the copyright laws of the United States
* and applicable international laws, treaties, and conventions.
* 
* You may freely redistribute and use this sample code, with or
* without modification, provided you include the original copyright
* notice and use restrictions.
* 
* See the use restrictions.
* 
*/
package arcgissamples.globe;

import com.esri.arcgis.analyst3d.IBasicScene2;
import com.esri.arcgis.analyst3d.IScene;
import com.esri.arcgis.animation.AGAnimationUtils;
import com.esri.arcgis.animation.AGGroupAnimationOptions;
import com.esri.arcgis.animation.IAGAnimationContainer;
import com.esri.arcgis.animation.IAGAnimationEnvironment;
import com.esri.arcgis.animation.IAGAnimationPlayer;
import com.esri.arcgis.animation.IAGAnimationTracks;
import com.esri.arcgis.animation.IAGAnimationUtils;
import com.esri.arcgis.animation.IAGGroupAnimationOptions;
import com.esri.arcgis.beans.globe.GlobeBean;
import com.esri.arcgis.carto.IDataLayer;
import com.esri.arcgis.carto.IEnumLayer;
import com.esri.arcgis.carto.ILayer;
import com.esri.arcgis.system.Array;
import com.esri.arcgis.system.IArray;
import com.esri.arcgis.system.UID;


public class AnimationRunnable implements Runnable {
  private GlobeBean globeBean;
  private AnimationPanel animationPanel;

  public AnimationRunnable(GlobeBean globeBean, AnimationPanel animationPanel) {
    super();
    this.globeBean = globeBean;
    this.animationPanel = animationPanel;
  }

  public void run() {
    try {
      IAGAnimationUtils animationUtil = new AGAnimationUtils();
      IBasicScene2 basicScene = (IBasicScene2) this.globeBean.getGlobe();
      IAGAnimationEnvironment env = basicScene.getAnimationExtension().getAnimationEnvironment();

      IScene scene = (IScene) basicScene; // Explicit
      IArray layers = new Array();

      // Create a UID for IDataLayer
      UID uid = new UID();
      uid.setValue(IDataLayer.class); //6CA416B1-E160-11D2-9F4E-00C04F6BC78E

      //Animate all the layers in the globe document
      IEnumLayer enumLayer = scene.getLayers(uid, false);
      enumLayer.reset();
      ILayer layer = enumLayer.next();
      while (layer != null) {
        layers.add(layer);
        layer = enumLayer.next();
      }

      // Set the animation options
      IAGGroupAnimationOptions animationOptions = new AGGroupAnimationOptions();
      IAGAnimationTracks tracks = basicScene.getAnimationExtension().getAnimationTracks();
      animationOptions.setAnimationEnvironmentByRef(env);
      animationOptions.setLayerSetByRef(layers);
      animationOptions.setAnimationTracksByRef(tracks);
      animationOptions.setBlending(this.animationPanel.getChkboxBlendLayer().isSelected());
      animationOptions.setCycleAnimation(this.animationPanel.getChkboxLoopAnimation().isSelected());
      animationOptions.setFadingPercentage(this.animationPanel.getSliderTransition().getValue());
      animationOptions.setOverwriteExisting(this.animationPanel.getChkboxOverwrite().isSelected());
      animationOptions.putTrackInterval(new Double(this.animationPanel.getTxtBegin().getText()), new Double(
        this.animationPanel.getTxtEnd().getText()));
      animationOptions.putVisibilitySettings(this.animationPanel.getChkboxOneLayer().isSelected(), this.animationPanel
        .getChkboxLayerAppear().isSelected(), this.animationPanel.getChkboxInvertOrder().isSelected());
      IAGAnimationContainer animationContainer = (IAGAnimationContainer) scene;
      //Create the group layer animation
      animationUtil.createLayerGroupAnimation(animationContainer, animationOptions);
      //Play the animation
      ((IAGAnimationPlayer) animationUtil).playAnimation((IAGAnimationTracks) animationContainer, env, null);
    } catch (Exception ex) {
      ex.printStackTrace();
    }
  }

}