arcgissamples\graphicstracker\EngineVisualApp.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.graphicstracker; import java.awt.BorderLayout; import java.awt.Dimension; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.io.File; import javax.swing.JFrame; import javax.swing.UIManager; import com.esri.arcgis.beans.TOC.TOCBean; import com.esri.arcgis.beans.map.MapBean; import com.esri.arcgis.beans.toolbar.ToolbarBean; import com.esri.arcgis.controls.ControlsMapFullExtentCommand; import com.esri.arcgis.controls.ControlsMapPanTool; import com.esri.arcgis.controls.ControlsMapZoomInTool; import com.esri.arcgis.controls.ControlsMapZoomOutTool; import com.esri.arcgis.controls.ControlsMapZoomToLastExtentBackCommand; import com.esri.arcgis.controls.ControlsMapZoomToLastExtentForwardCommand; import com.esri.arcgis.controls.ControlsOpenDocCommand; 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 EngineVisualApp extends JFrame { private static final long serialVersionUID = 1L; private static AoInitialize aoInit; public static void main(String[] args) { String devKitHome = System.getenv("AGSDEVKITJAVA"); if (!(new File(devKitHome).exists())){ System.out.println(devKitHome + " does not exist.\nExiting..."); System.exit(-1); } // Change the following line if you want to load a different mxd file at startup. String mxFile = devKitHome + "java" + File.separator + "samples" + File.separator + "data" + File.separator + "mxds" + File.separator + "usa.mxd"; try { EngineInitializer.initializeVisualBeans(); UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); initializeArcGISLicenses(); EngineVisualApp thisApp = new EngineVisualApp(); thisApp.display(mxFile); } catch (Exception ex) { System.out.println("Sample failed: " + ex.getMessage()); ex.printStackTrace(); } } static void initializeArcGISLicenses() { try { aoInit = new AoInitialize(); if (aoInit.isProductCodeAvailable(esriLicenseProductCode.esriLicenseProductCodeEngine) == esriLicenseStatus.esriLicenseAvailable) aoInit.initialize(esriLicenseProductCode.esriLicenseProductCodeEngine); } catch (Exception e) {e.printStackTrace();} } public void display(String mxFile) throws Exception { MapBean mapBean = new MapBean(); TOCBean tocBean = new TOCBean(); ToolbarBean toolbarBean = new ToolbarBean(); addWindowListener(new WindowAdapter() { // @Override public void windowClosing(WindowEvent e) { try { aoInit.shutdown(); } catch (Exception ex){} e.getWindow().dispose(); } }); mapBean.clearLayers(); setVisible(true); mapBean.loadMxFile(mxFile, null, null); // set the control size mapBean.setSize(600, 600); tocBean.setSize(200, 600); toolbarBean.setSize(800, 25); getContentPane().add(mapBean, BorderLayout.CENTER); getContentPane().add(tocBean, BorderLayout.WEST); getContentPane().add(toolbarBean, BorderLayout.NORTH); setSize(new Dimension(800, 700)); setTitle("Add Graphics Tracker Sample"); toolbarBean.addItem(new ControlsOpenDocCommand(), 0, 0, false, 0, esriCommandStyles.esriCommandStyleIconOnly); // open toolbarBean.addItem(new ControlsMapZoomInTool(), 0, -1, true, 0, esriCommandStyles.esriCommandStyleIconAndText); // ZoomIn toolbarBean.addItem(new ControlsMapZoomOutTool(), 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconAndText); // ZoomOut toolbarBean.addItem(new ControlsMapPanTool(), 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconAndText); // Pan toolbarBean.addItem(new ControlsMapFullExtentCommand(), 0, -1, true, 20, esriCommandStyles.esriCommandStyleTextOnly); // FullExtent toolbarBean.addItem(new ControlsMapZoomToLastExtentBackCommand(), 0, -1, false, 0, esriCommandStyles.esriCommandStyleTextOnly); // ZoomToLastExtentBackCommand toolbarBean.addItem(new ControlsMapZoomToLastExtentForwardCommand(), 0, -1, false, 0, esriCommandStyles.esriCommandStyleTextOnly); // ZoomToLastExtentForwardCommand toolbarBean.addItem(new AddPointGTCommand(),0, -1, false, 0, esriCommandStyles.esriCommandStyleTextOnly); // Set the TOC and toolbar buddy to the mapBean tocBean.setBuddyControl(mapBean); toolbarBean.setBuddyControl(mapBean); setDefaultCloseOperation(EXIT_ON_CLOSE); } }