arcgissamples\globe\GroupLayerAnimationApplication.java—ArcObjects 10.4 Help for Java | ArcGIS for Desktop
Animation in the Globe control
arcgissamples\globe\GroupLayerAnimationApplication.java
/* Copyright 2015 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 at <your ArcGIS install location>/DeveloperKit10.4/userestrictions.txt.
* 
*/
package arcgissamples.globe;

import java.awt.BorderLayout;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;

import com.esri.arcgis.beans.globe.GlobeBean;
import com.esri.arcgis.beans.toolbar.ToolbarBean;
import com.esri.arcgis.controls.ControlsGlobeGlobeToolbar;
import com.esri.arcgis.controls.esriToolbarOrientation;
import com.esri.arcgis.system.AoInitialize;
import com.esri.arcgis.system.EngineInitializer;
import com.esri.arcgis.system.esriLicenseExtensionCode;
import com.esri.arcgis.system.esriLicenseProductCode;
import com.esri.arcgis.system.esriLicenseStatus;
import com.esri.arcgis.systemUI.esriCommandStyles;

public class GroupLayerAnimationApplication extends JFrame {
  private static final long serialVersionUID = 1L;

  public static void main(String[] args) throws Exception {
    // initialize the interop
    initializeInterop();
    // initialize to a license level
    initializeArcGISLicenses();
    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    // start the sample
    final GroupLayerAnimationApplication thisClass = new GroupLayerAnimationApplication();
    thisClass.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    SwingUtilities.invokeLater(new Runnable() {
      public void run() {
        thisClass.initializeUI();
        thisClass.setVisible(true);
        try {
          //Get DEVKITHOME Home
          String devKitHome = System.getenv("AGSDEVKITJAVA");
          if (devKitHome != null) {
            thisClass.getGlobeBean().load3dFile(devKitHome + "java" + File.separator + 
                                     "samples" + File.separator + 
                                     "data" + File.separator + 
                                     "globe_data" + File.separator + 
                                     "Default_Document.3dd");
          } else {
            System.out.println("AGSDEVKITJAVA environment variable not set. Exiting application.");
            System.exit(-1);
          }
        } catch (java.lang.Throwable e) {
          e.printStackTrace();
        }
      }
    });
  }

  private void initializeUI() {
    this.setContentPane(getJContentPane());
    this.setTitle("Digitize Points Sample");
    this.setBounds(new Rectangle(0, 0, 900, 600));
  }

  private JPanel jContentPane = null;

  private JPanel getJContentPane() {
    if (jContentPane == null) {
      jContentPane = new JPanel();
      jContentPane.setLayout(new BorderLayout());
      jContentPane.add(getGlobeBean(), BorderLayout.CENTER);
      jContentPane.add(getToolbar(), BorderLayout.WEST);
      final AnimationPanel animationPanel = new AnimationPanel();
      jContentPane.add(animationPanel, BorderLayout.EAST);
      // Register the action listener
      animationPanel.getBtnPlay().addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
          // Start the animation on a worker thread
          Thread animationThread = new Thread(new AnimationRunnable(getGlobeBean(), animationPanel));
          animationThread.start();
        }

      });
    }
    return jContentPane;
  }

  private GlobeBean globeBean = null;

  private GlobeBean getGlobeBean() {
    if (globeBean == null) {
      globeBean = new GlobeBean();
    }
    return globeBean;
  }

  private ToolbarBean toolbar = null;

  private ToolbarBean getToolbar() {
    if (toolbar == null) {
      try {
        toolbar = new ToolbarBean();
        toolbar.setOrientation(esriToolbarOrientation.esriToolbarOrientationVertical);
        toolbar.addItem(new ControlsGlobeGlobeToolbar(), 0, 0, false, 0, esriCommandStyles.esriCommandStyleIconOnly);
        toolbar.setBuddyControl(getGlobeBean());
      } catch (java.lang.Throwable e) {
        e.printStackTrace();
      }
    }
    return toolbar;
  }

  static void initializeInterop() {
    // Visual beans mode required for multi-threaded applciations like
    // Swing.
    EngineInitializer.initializeVisualBeans();
  }

  static void initializeArcGISLicenses() {
    try {
      AoInitialize ao = new AoInitialize();
      if (ao.isProductCodeAvailable(esriLicenseProductCode.esriLicenseProductCodeEngine) == esriLicenseStatus.esriLicenseAvailable)
        ao.initialize(esriLicenseProductCode.esriLicenseProductCodeEngine);
      else if (ao.isProductCodeAvailable(esriLicenseProductCode.esriLicenseProductCodeBasic) == esriLicenseStatus.esriLicenseAvailable)
        ao.initialize(esriLicenseProductCode.esriLicenseProductCodeBasic);
      else {
        System.err.println("Could not initialize an Engine or Basic License. Exiting application.");
        System.exit(-1);
      }
      ao.checkOutExtension(esriLicenseExtensionCode.esriLicenseExtensionCode3DAnalyst);
    } catch (Exception e) {
      e.printStackTrace();
    }
  }

} // @jve:decl-index=0:visual-constraint="51,2"