arcgissamples\pagelayoutbean\UsePageLayoutBean.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.pagelayoutbean; import java.awt.BorderLayout; import java.awt.Dimension; import java.io.IOException; import javax.swing.JFrame; import com.esri.arcgis.beans.pagelayout.PageLayoutBean; import com.esri.arcgis.beans.toolbar.ToolbarBean; import com.esri.arcgis.controls.ControlsMapFullExtentCommand; import com.esri.arcgis.controls.ControlsMapPageDownCommand; import com.esri.arcgis.controls.ControlsMapPageLeftCommand; import com.esri.arcgis.controls.ControlsMapPageRightCommand; import com.esri.arcgis.controls.ControlsMapPageUpCommand; 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; /** * Description: Using the PageLayout and Toolbar Control Uses the PageLayoutBean to load a MXD file and a ToolbarBean to * perform page and map zoom/pan functions */ public class UsePageLayoutBean { JFrame frame = null; PageLayoutBean pageLayoutBean = null; ToolbarBean toolbarBean = null; public UsePageLayoutBean() { frame = new JFrame("Java Sample: PageLayoutBean and ToolbarBean");// Known problem in Solaris : Frame has to be // created before controls. pageLayoutBean = new PageLayoutBean(); toolbarBean = new ToolbarBean(); } public void display() throws IOException { frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // set the control size pageLayoutBean.setSize(600, 400); toolbarBean.setSize(800, 25); frame.getContentPane().add(pageLayoutBean, BorderLayout.CENTER); frame.getContentPane().add(toolbarBean, BorderLayout.NORTH); frame.setSize(new Dimension(800, 700)); frame.setVisible(true); // Set the toolbar buddy to the pageLayoutBean toolbarBean.setBuddyControl(pageLayoutBean); toolbarBean.addItem(new ControlsOpenDocCommand(), 0, -1, false, 0, 1); toolbarBean.addItem(new ControlsMapZoomInTool(), 0, -1, false, 0, 1); toolbarBean.addItem(new ControlsMapZoomOutTool(), 0, -1, false, 0, 1); toolbarBean.addItem(new ControlsMapFullExtentCommand(), 0, -1, false, 0, 1); toolbarBean.addItem(new ControlsMapZoomToLastExtentForwardCommand(), 0, -1, false, 0, 1); toolbarBean.addItem(new ControlsMapZoomToLastExtentBackCommand(), 0, -1, false, 0, 1); toolbarBean.addItem(new ControlsMapPanTool(), 0, -1, false, 0, 1); toolbarBean.addItem(new ControlsMapPageUpCommand(), 0, -1, false, 0, 1); toolbarBean.addItem(new ControlsMapPageRightCommand(), 0, -1, false, 0, 1); toolbarBean.addItem(new ControlsMapPageDownCommand(), 0, -1, false, 0, 1); toolbarBean.addItem(new ControlsMapPageLeftCommand(), 0, -1, false, 0, 1); } public static void main(String[] args) throws IOException { EngineInitializer.initializeVisualBeans(); initializeArcGISLicenses(); UsePageLayoutBean arFrame = new UsePageLayoutBean(); try { arFrame.display(); } catch (IOException ioe) { ioe.printStackTrace(); } } 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 if (ao.isProductCodeAvailable(esriLicenseProductCode.esriLicenseProductCodeArcEditor) == esriLicenseStatus.esriLicenseAvailable) ao.initialize(esriLicenseProductCode.esriLicenseProductCodeArcEditor); else if (ao.isProductCodeAvailable(esriLicenseProductCode.esriLicenseProductCodeArcInfo) == esriLicenseStatus.esriLicenseAvailable) ao.initialize(esriLicenseProductCode.esriLicenseProductCodeArcInfo); } catch (Exception e) {e.printStackTrace();} } }