Print active view
arcgissamples\mapbean\PrintActiveView.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.mapbean;

import java.awt.BorderLayout;
import java.io.IOException;

import javax.swing.JPanel;
import javax.swing.JFrame;

import arcgissamples.mapbean.commands.PrintActiveViewCommand;

import com.esri.arcgis.beans.toolbar.ToolbarBean;
import javax.swing.JSplitPane;
import com.esri.arcgis.beans.TOC.TOCBean;
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;
import com.esri.arcgis.beans.map.MapBean;

public class PrintActiveView 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;

  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)
      {
        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;
  }

  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(com.esri.arcgis.system.esriLicenseProductCode.esriLicenseProductCodeArcView);
    } catch (Exception e) {e.printStackTrace();}
  }

  /**
   * This is the default constructor
   */
  public PrintActiveView()
  {
    super();
    initializeArcGISLicenses();
    initialize();
  }

  /**
   * This method initializes this
   * 
   * @return void
   */
  private void initialize()
  {
    this.setSize(802, 572);
    this.setContentPane(getJContentPane());
    this.setTitle("JFrame");
    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;
  }

  /**
   * @param args
   */
  public static void main(String[] args)
  {
    EngineInitializer.initializeVisualBeans();
    PrintActiveView map = new PrintActiveView();
    map.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    map.setVisible(true);
  }

  /**
   * 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;11|controls/ControlsMapZoomInTool|0|-1|0|0|1;11|controls/ControlsMapZoomOutTool|0|-1|0|0|1;11|controls/ControlsMapPanTool|0|-1|0|0|1;11|controls/ControlsMapFullExtentCommand|0|-1|0|0|1;11|controls/ControlsMapZoomToLastExtentBackCommand|0|-1|0|0|1;11|controls/ControlsMapZoomToLastExtentForwardCommand|0|-1|0|0|1;4|controls/ControlsSelectFeaturesTool|0|-1|0|0|1;4|controls/ControlsClearSelectionCommand|0|-1|0|0|1");
      try
      {
        toolbarBean.setBuddyControl(getMapBean());
        toolbarBean.addItem(new PrintActiveViewCommand(), 0, -1, false, 0,
            esriCommandStyles.esriCommandStyleIconOnly);
      }
      catch (IOException e)
      {
        e.printStackTrace();
      }
    }
    return toolbarBean;
  }
}