arcgissamples\globe\LoadAndPlayApplication.java—ArcObjects 10.4 Help for Java | ArcGIS for Desktop
Camera and layer animation in the Globe control
arcgissamples\globe\LoadAndPlayApplication.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.io.File;

import javax.swing.JDesktopPane;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JProgressBar;
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.ControlsGlobeOpenDocCommand;
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 LoadAndPlayApplication extends JFrame {

  public static void main(String[] args) throws Exception {
  // TODO: Add the .aga file in .NET devkit to java
  // initialize the interop
  initializeInterop();
  // initialize to a license level
  initializeArcGISLicenses();
  UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());

  // start the sample
  final LoadAndPlayApplication thisClass = new LoadAndPlayApplication();
  thisClass.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  thisClass.setContentPane(new JDesktopPane());
  SwingUtilities.invokeLater(new Runnable() {
    public void run() {
    thisClass.initializeUI();
    thisClass.setVisible(true);
    thisClass.getProgressDialog().setVisible(true);
    Thread documentLoader = new Thread(new Runnable() {
      public void run() {
      try {
        //Get DEVKITHOME Home
        String devKitHome = System.getenv("AGSDEVKITJAVA");
        thisClass.getGlobeBean().load3dFile(devKitHome + "java" + File.separator + 
                                   "samples" + File.separator + 
                                   "data" + File.separator + 
                                   "globe_data" + File.separator + 
                                   "Default_Document.3dd");
        thisClass.getProgressDialog().setVisible(false);
      } catch (java.lang.Throwable e) {
        e.printStackTrace();
      }
      }
    }, " Globe document loader");
    documentLoader.start();
    }
  });
  }

  private void initializeUI() {
  this.setSize(700, 700);
  this.setContentPane(getJContentPane());
  this.setTitle("Globe Animation");
  }

  private JPanel getJContentPane() {
  if (jContentPane == null) {
    jContentPane = new JPanel();
    jContentPane.setLayout(new BorderLayout());
    jContentPane.add(getGlobeBean(), BorderLayout.CENTER);
    jContentPane.add(getToolbar(), BorderLayout.NORTH);
    jContentPane.add(getAnimationPanel(), BorderLayout.SOUTH);

  }
  return jContentPane;
  }
 private AnimationPanel getAnimationPanel() {
  if (animationPanel == null) {
    animationPanel = new AnimationPanel();
    try {
    AnimationPanelActionListener listener = new AnimationPanelActionListener(
      animationPanel, getGlobeBean());
    animationPanel.getBtnPlay().addActionListener(listener);
    animationPanel.getBtnLoad().addActionListener(listener);
    } catch (Exception e) {
    e.printStackTrace();
    }
  }
  return animationPanel;
  }

  private GlobeBean getGlobeBean() {
  if (globe == null) {
    try {
    globe = new GlobeBean();
    } catch (java.lang.Throwable e) {
    e.printStackTrace();
    }
  }
  return globe;
  }

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

 private JDialog getProgressDialog() {
  if (progressDialog == null) {
    progressDialog = new JDialog();
    progressDialog.setTitle("Loading...");
    JProgressBar bar = new JProgressBar();
    bar.setBorderPainted(true);
    bar.setIndeterminate(true);
    progressDialog.setLocationRelativeTo(this);
    progressDialog.setLocation(this.getWidth() / 2, this.getHeight() / 2);
    progressDialog.add(bar, BorderLayout.PAGE_START);
    progressDialog.pack();
  }
  return progressDialog;
  }

  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();
  }
  }

  private static final long serialVersionUID = 1L;

  private JPanel jContentPane = null;

  private GlobeBean globe = null;

  private ToolbarBean toolbar = null;

  private AnimationPanel animationPanel = null;

  private JDialog progressDialog = null;





} // @jve:decl-index=0:visual-constraint="62,37"