arcgissamples\pagelayoutbean\UsePageLayoutBean.java—ArcObjects 10.4 Help for Java | ArcGIS for Desktop
Use PageLayout bean
arcgissamples\pagelayoutbean\UsePageLayoutBean.java
/* Copyright 2015 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 at <your ArcGIS install location>/DeveloperKit10.4/userestrictions.txt.
* 
*/
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.esriLicenseProductCodeBasic) 
          == esriLicenseStatus.esriLicenseAvailable)
        ao.initialize(esriLicenseProductCode.esriLicenseProductCodeBasic);
      else if (ao.isProductCodeAvailable(esriLicenseProductCode.esriLicenseProductCodeStandard) 
          == esriLicenseStatus.esriLicenseAvailable)
        ao.initialize(esriLicenseProductCode.esriLicenseProductCodeStandard);
      else if (ao.isProductCodeAvailable(esriLicenseProductCode.esriLicenseProductCodeAdvanced) 
          == esriLicenseStatus.esriLicenseAvailable)
        ao.initialize(esriLicenseProductCode.esriLicenseProductCodeAdvanced);
    } catch (Exception e) {e.printStackTrace();}
  }
}