arcgissamples\globe\AnimationPanelActionListener.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 java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.File; import javax.swing.JFileChooser; import javax.swing.filechooser.FileFilter; import com.esri.arcgis.analyst3d.IBasicScene; import com.esri.arcgis.beans.globe.GlobeBean; public class AnimationPanelActionListener implements ActionListener { private File animationFile; private AnimationPanel animationPanel; private GlobeBean globeBean; public AnimationPanelActionListener(AnimationPanel playPanel, GlobeBean globeBean) { this.animationPanel = playPanel; this.globeBean = globeBean; } public void actionPerformed(ActionEvent event) { if (event.getSource() == animationPanel.getBtnLoad()) { //Pop-up the JFileChooser to allow the user to select an animation file JFileChooser chooser = new JFileChooser(); chooser.setCurrentDirectory(new File(System.getenv("AGSDEVKITJAVA") + "java" + File.separator + "samples" + File.separator + "data" + File.separator + "globe_data")); chooser.setFileFilter(new FileFilter() { public boolean accept(File pathname) { return pathname.isDirectory() || pathname.getAbsolutePath().endsWith("aga"); } public String getDescription() { return "Animation Files (*.aga)"; } }); int returnVal = chooser.showOpenDialog(null); if (returnVal == JFileChooser.APPROVE_OPTION) { // Load the animation animationFile = chooser.getSelectedFile(); try { ((IBasicScene) globeBean.getGlobe()).loadAnimation(animationFile.getAbsolutePath()); // General note : If arcobjects operations take // considerable time then execute them on a worker thread. Don't // hold up Swing's Event Dispatching Thread(EDT). // In this case, loading the animation is an // inexpensive operation and so it can be performed on this thread // itself. } catch (Exception ex) { ex.printStackTrace(); } } } else if (event.getSource() == animationPanel.getBtnPlay()) { //Start the animation on a seprate thread, don't hold up the EDT Runnable animationRunnable = new AnimationRunnable(this.globeBean,this.animationPanel); Thread worker = new Thread(animationRunnable); worker.start(); } } }