arcgissamples\trackinganalyst\DisplayTrackingServerLayer.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.trackinganalyst; import java.awt.BorderLayout; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.io.File; import java.io.IOException; import javax.swing.JDialog; import javax.swing.JFrame; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JProgressBar; import javax.swing.SwingUtilities; import arcgissamples.trackinganalyst.commands.DisplayTrackingServerLayerCommand; import com.esri.arcgis.beans.globe.GlobeBean; import com.esri.arcgis.beans.toolbar.ToolbarBean; import com.esri.arcgis.controls.ControlsGlobeFixedZoomInCommand; import com.esri.arcgis.controls.ControlsGlobeFixedZoomOutCommand; import com.esri.arcgis.controls.ControlsGlobeOpenDocCommand; import com.esri.arcgis.controls.ControlsGlobeOrbitalFlyTool; import com.esri.arcgis.controls.ControlsGlobePanDragTool; import com.esri.arcgis.controls.ControlsGlobeWalkTool; import com.esri.arcgis.controls.ControlsGlobeZoomInOutTool; import com.esri.arcgis.interop.AutomationException; import com.esri.arcgis.system.AoInitialize; import com.esri.arcgis.system.EngineInitializer; import com.esri.arcgis.system.esriLicenseProductCode; import com.esri.arcgis.system.esriLicenseStatus; import com.esri.arcgis.systemUI.esriCommandStyles; public class DisplayTrackingServerLayer extends JFrame { /** * */ private static final long serialVersionUID = 1L; private GlobeBean globeBean = null; private ToolbarBean toolbarBean = null; private AoInitialize ao = null; String inputDir, outputDir; JDialog progressDialog = null; public DisplayTrackingServerLayer() { addWindowListener(new WindowAdapter() { public void windowClosed(WindowEvent e) { try { // Release license ao.shutdown(); // Do not make any call to ArcObjects after ShutDownApplication() EngineInitializer.releaseAll(); // Exit app System.exit(0); } catch (AutomationException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } } }); } /* * @param args */ public static void main(String[] args) { System.out.println("Starting DisplayTrackingServerLayer - An ArcObjects Java SDK Developer Sample"); EngineInitializer.initializeVisualBeans(); final DisplayTrackingServerLayer app = new DisplayTrackingServerLayer(); app.initializeArcGISLicenses(); SwingUtilities.invokeLater(new Runnable() { public void run() { try { app.buildAppFrame(); app.setVisible(true); Thread documentLoader = new Thread(new Runnable() { public void run() { app.getProgressDialog().setVisible(true); try { //Get DEVKITHOME Home String devKitHome = System.getenv("AGSDEVKITJAVA"); if (devKitHome == null || devKitHome.equalsIgnoreCase("")) { JOptionPane.showMessageDialog(app, "ERROR - ArcGIS Home invalid. Exiting application..."); System.exit(-1); } String fileName = devKitHome + "java" + File.separator + "samples" + File.separator + "data" + File.separator + "globe_data" + File.separator + "Default_Document.3dd"; File file = new File(fileName); if (!file.exists()) { JOptionPane.showMessageDialog(app, "ERROR - Unable to find 3dd document " + fileName + ".\nPlease use the Open file command to locate your 3DD document."); } else { app.globeBean.load3dFile(fileName); } } catch (java.lang.Throwable e) { e.printStackTrace(); } app.getProgressDialog().setVisible(false); } }, "Globe document loader"); documentLoader.start(); } catch (Exception e) { e.printStackTrace(); } } }); } /* * Build the application frame with Engine Controls and Swing Components */ private void buildAppFrame() throws Exception { this.setSize(800, 600); this.setTitle("Display Tracking Server Layer"); setContentPane(getJContentPane()); this.setVisible(true); setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); } /* * Initializes jContentPane */ private JPanel getJContentPane() throws Exception { JPanel contentPane = new JPanel(); contentPane.setLayout(new BorderLayout()); // Initialize ToolbarBean toolbarBean = new ToolbarBean(); // Adding Open doc command to toolbar toolbarBean.addItem(new ControlsGlobeOpenDocCommand(), 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly); // Adding Fixed zoom in command to toolbar toolbarBean.addItem(new ControlsGlobeFixedZoomInCommand(), 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly); // Adding Fixed zoom out command to toolbar toolbarBean.addItem(new ControlsGlobeFixedZoomOutCommand(), 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly); // Adding Globe Zoom in-out command to toolbar toolbarBean.addItem(new ControlsGlobeZoomInOutTool(), 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly); // Adding Pan Drag command to toolbar toolbarBean.addItem(new ControlsGlobePanDragTool(), 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly); // Adding Globe Orbital Fly tool - Flies in orbital trajectories over the // globe. toolbarBean.addItem(new ControlsGlobeOrbitalFlyTool(), 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly); // Adding Control Globe Walk tool - Walks on the globe surface toolbarBean.addItem(new ControlsGlobeWalkTool(), 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly); // Add Tracking Server Layer Command (defined in AddTSLayerCommand.java) to // toolbar toolbarBean.addItem(new DisplayTrackingServerLayerCommand(), 0, -1, false, 0, esriCommandStyles.esriCommandStyleTextOnly); // Initialize GlobeBean globeBean = new GlobeBean(); // add globe bean as buddy control to toolbar bean toolbarBean.setBuddyControl(globeBean); // add toolbar and globe beans to contentPane contentPane.add(toolbarBean, BorderLayout.NORTH); contentPane.add(globeBean, BorderLayout.CENTER); return contentPane; } /* * Initializes the lowest available ArcGIS License */ private void initializeArcGISLicenses() { try { ao = new AoInitialize(); if (ao.isProductCodeAvailable(esriLicenseProductCode.esriLicenseProductCodeEngine) == esriLicenseStatus.esriLicenseAvailable) { ao.initialize(esriLicenseProductCode.esriLicenseProductCodeEngine); } else if (ao.isProductCodeAvailable(esriLicenseProductCode.esriLicenseProductCodeArcView) == esriLicenseStatus.esriLicenseAvailable) { ao.initialize(esriLicenseProductCode.esriLicenseProductCodeArcView); } else { System.err.println("Could not initialize an Engine or ArcView license. Exiting application."); System.exit(-1); } ao.checkOutExtension(com.esri.arcgis.system.esriLicenseExtensionCode.esriLicenseExtensionCodeTracking); ao.checkOutExtension(com.esri.arcgis.system.esriLicenseExtensionCode.esriLicenseExtensionCode3DAnalyst); } catch (Exception e) { e.printStackTrace(); } } /* * Creates a Dialog box with a Progress bar in it. @return */ private JDialog getProgressDialog() { if (progressDialog == null) { progressDialog = new JDialog(); progressDialog.setTitle("Loading Globe Document..."); 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(); progressDialog.setSize(250, 50); } return progressDialog; } }