arcgissamples\display\DynamicDisplayApp.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 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.controls.ControlsAddDataCommand; import com.esri.arcgis.controls.ControlsMapRoamTool; import com.esri.arcgis.system.AoInitialize; import com.esri.arcgis.systemUI.esriCommandStyles; public class DynamicDisplayApp 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; public static void main(String[] args) { // initialize the interop initializeInterop(); //initialize to a license level initializeArcGISLicenses(); //start the sample final DynamicDisplayApp map = new DynamicDisplayApp(); 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 (Exception e) { e.printStackTrace(); } } 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 this * * @return void */ private void initializeUI() { this.setSize(802, 572); this.setContentPane(getJContentPane()); this.setTitle("Dynamic Layers"); 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("5|controls/ControlsOpenDocCommand|0|-1|0|0|1;5|controls/ControlsSaveAsDocCommand|0|-1|0|0|1;11|controls/ControlsMapFullExtentCommand|0|-1|0|0|1;11|controls/ControlsMapZoomInFixedCommand|0|-1|0|0|1;11|controls/ControlsMapZoomOutFixedCommand|0|-1|0|0|1;11|controls/ControlsMapPanTool|0|-1|0|0|1;11|controls/ControlsMapZoomInTool|0|-1|0|0|1;11|controls/ControlsMapZoomOutTool|0|-1|0|0|1;11|controls/ControlsMapZoomToLastExtentBackCommand|0|-1|0|0|1;11|controls/ControlsMapZoomToLastExtentForwardCommand|0|-1|0|0|1"); try { //Add the out of the box Add Item Command toolbarBean.addItem(ControlsAddDataCommand.getClsid(), 0, 0, false, 0, esriCommandStyles.esriCommandStyleIconAndText); //Add the out of the box Roam Command toolbarBean.addItem(new ControlsMapRoamTool(), 0, 0, false, 0, esriCommandStyles.esriCommandStyleIconAndText); //Add the custom created Toggle Dynamic Mode Command toolbarBean.addItem(new ToggleDynamicDisplayCommand(), 0, 0, false, 0, esriCommandStyles.esriCommandStyleTextOnly); //Add the custom created Dynamic Tracking Command toolbarBean.addItem(new AddDynamicLayerCommand(), 0, 0, false, 0, esriCommandStyles.esriCommandStyleTextOnly); toolbarBean.setBuddyControl(getMapBean()); } catch (Exception e) { e.printStackTrace(); } } return toolbarBean; } }