arcgissamples\display\DynamicApp.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.io.IOException; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JSplitPane; import javax.swing.SwingUtilities; 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.system.AoInitialize; import com.esri.arcgis.systemUI.esriCommandStyles; public class DynamicApp extends JFrame { private static final long serialVersionUID = 1L; private JPanel jContentPane = null; private ToolbarBean toolbarBean = null; private JSplitPane jSplitPane = null; private TOCBean TOCBean = null; private MapBean mapBean = null; /** * @param args */ public static void main(String[] args) { //initialize the interop initializeInterop(); //initialize to a license level initializeArcGISLicenses(); //start the sample final DynamicApp map = new DynamicApp(); map.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); SwingUtilities.invokeLater(new Runnable() { public void run() { map.initializeUI(); map.setVisible(true); } }); } /** * This method initializes jSplitPane * * @return javax.swing.JSplitPane */ private JSplitPane getJSplitPane() { if (jSplitPane == null) { jSplitPane = new JSplitPane(); jSplitPane.setDividerLocation(150); jSplitPane.setDividerSize(2); jSplitPane.setRightComponent(getMapBean()); jSplitPane.setLeftComponent(getTOCBean()); } return jSplitPane; } /** * This method initializes TOCBean * * @return com.esri.arcgis.beans.TOC.TOCBean */ private TOCBean getTOCBean() { if (TOCBean == null) { TOCBean = new TOCBean(); try { TOCBean.setBuddyControl(getMapBean()); } catch (IOException e) { System.out.println("MAIN"); } } return TOCBean; } /** * This method initializes mapBean * * @return com.esri.arcgis.beans.map.MapBean */ private MapBean getMapBean() { if (mapBean == null) { mapBean = new MapBean(); } return mapBean; } /** * This method initializes UI * * @return void */ private void initializeUI() { this.setSize(802, 572); this.setContentPane(getJContentPane()); this.setTitle("Dynamic Display Sample"); this.addWindowListener(new java.awt.event.WindowAdapter() { public void windowClosing(java.awt.event.WindowEvent e) { try{ new AoInitialize().shutdown(); }catch(Exception ex){ ex.printStackTrace(); } } }); } /** * This method initializes jContentPane * * @return javax.swing.JPanel */ private JPanel getJContentPane() { if (jContentPane == null) { jContentPane = new JPanel(); jContentPane.setLayout(new BorderLayout()); jContentPane.add(getToolbarBean(), java.awt.BorderLayout.NORTH); jContentPane.add(getJSplitPane(), java.awt.BorderLayout.CENTER); } return jContentPane; } /** * This method initializes ArcGIs Licenses * * @return javax.swing.JPanel */ static void initializeArcGISLicenses() { try { com.esri.arcgis.system.AoInitialize ao = new com.esri.arcgis.system.AoInitialize(); if (ao.isProductCodeAvailable(com.esri.arcgis.system.esriLicenseProductCode.esriLicenseProductCodeEngine) == com.esri.arcgis.system.esriLicenseStatus.esriLicenseAvailable) ao.initialize(com.esri.arcgis.system.esriLicenseProductCode.esriLicenseProductCodeEngine); } catch (Exception e) { e.printStackTrace(); } } /** * This method initializes Interop * * @return javax.swing.JPanel */ static public void initializeInterop() { com.esri.arcgis.system.EngineInitializer.initializeVisualBeans(); } /** * This method initializes toolbarBean * * @return com.esri.arcgis.beans.toolbar.ToolbarBean */ private ToolbarBean getToolbarBean() { if (toolbarBean == null) { toolbarBean = new ToolbarBean(); toolbarBean.setItemsString("10|controls/ControlsMapFullExtentCommand|0|-1|0|0|1;10|controls/ControlsMapZoomInFixedCommand|0|-1|0|0|1;10|controls/ControlsMapZoomOutFixedCommand|0|-1|0|0|1;10|controls/ControlsMapZoomInTool|0|-1|0|0|1;10|controls/ControlsMapZoomOutTool|0|-1|0|0|1;10|controls/ControlsMapPanTool|0|-1|0|0|1;10|controls/ControlsMapZoomToLastExtentBackCommand|0|-1|0|0|1;10|controls/ControlsMapZoomToLastExtentForwardCommand|0|-1|0|0|1"); try { toolbarBean.setBuddyControl(getMapBean()); //Add custom created DynamicTracking command toolbarBean.addItem(new DynamicTrackingCommand(),0,-1,false,0,esriCommandStyles.esriCommandStyleTextOnly); } catch (Exception e) { System.out.println("Exception in DynamicApp#getToolbarBean"); } } return toolbarBean; } }