arcgissamples\display\HUDApplication.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.display; import java.awt.BorderLayout; import java.awt.Rectangle; import java.io.File; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.SwingUtilities; import com.esri.arcgis.beans.map.MapBean; import com.esri.arcgis.beans.toolbar.ToolbarBean; import com.esri.arcgis.controls.ControlsMapRoamTool; import com.esri.arcgis.controls.ControlsMapRotateTool; import com.esri.arcgis.controls.ControlsMapZoomPanTool; 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 HUDApplication extends JFrame { private static final long serialVersionUID = 1L; public static void main(String[] args) { // initialize the interop initializeInterop(); // initialize to a license level initializeArcGISLicenses(); // start the sample final HUDApplication thisClass = new HUDApplication(); thisClass.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); SwingUtilities.invokeLater(new Runnable() { public void run() { thisClass.initializeUI(); thisClass.setVisible(true); } }); } private void initializeUI() { this.setContentPane(getJContentPane()); this.setTitle("Dynamic Heads-Up-Display Sample"); this.setBounds(new Rectangle(0, 0, 600, 500)); } private JPanel jContentPane = null; private JPanel getJContentPane() { if (jContentPane == null) { jContentPane = new JPanel(); jContentPane.setLayout(new BorderLayout()); jContentPane.add(getMap(), BorderLayout.CENTER); jContentPane.add(getToolbar(), BorderLayout.NORTH); } return jContentPane; } private MapBean map = null; private MapBean getMap() { if (map == null) { try { map = new MapBean(); //Get DEVKITHOME Home String devKitHome = System.getenv("AGSDEVKITJAVA"); map.loadMxFile(devKitHome + "java" + File.separator + "samples" + File.separator + "data" + File.separator + "mxds" + File.separator + "brazil.mxd", null, null); } catch (java.lang.Throwable e) { e.printStackTrace(); } } return map; } private ToolbarBean toolbar = null; private ToolbarBean getToolbar() { if (toolbar == null) { try { toolbar = new ToolbarBean(); toolbar.addItem(new ShowHUDCommand(), 0, 0, false, 0, esriCommandStyles.esriCommandStyleIconAndText); toolbar.addItem(new ControlsMapRotateTool(), 0, 1, false, 0, esriCommandStyles.esriCommandStyleIconAndText); toolbar.addItem(new ControlsMapZoomPanTool(), 0, 2, false, 0, esriCommandStyles.esriCommandStyleIconAndText); toolbar.addItem(new ControlsMapRoamTool(), 0, 3, false, 0, esriCommandStyles.esriCommandStyleIconAndText); toolbar.setBuddyControl(getMap()); } 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.esriLicenseProductCodeArcView) == esriLicenseStatus.esriLicenseAvailable) ao.initialize(esriLicenseProductCode.esriLicenseProductCodeArcView); else { System.err.println("Could not initialize an Engine or ArcView license. Exiting application."); System.exit(-1); } } catch (Exception e) { e.printStackTrace(); } } }