arcgissamples\mapbean\SwipeAndChangeTransparency.java—ArcObjects 10.4 Help for Java | ArcGIS for Desktop
Swipe and change transparency
arcgissamples\mapbean\SwipeAndChangeTransparency.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.mapbean;

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

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

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.CommandsEnvironment;
import com.esri.arcgis.controls.ControlsLayerListToolControl;
import com.esri.arcgis.controls.ControlsLayerTransparencyCommand;
import com.esri.arcgis.controls.ControlsMapNavigationToolbar;
import com.esri.arcgis.controls.ControlsMapSwipeTool;
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;
import com.esri.arcgis.systemUI.esriCommandStyles;

public class SwipeAndChangeTransparency 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;
  @SuppressWarnings("unused")
  private CommandsEnvironment commandsEnvironment = null;

  /**
   * 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)
      {
        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 is the default constructor
   */
  public SwipeAndChangeTransparency()
  {
    super();
    initializeArcGISLicenses();
    initialize();
  }

  /**
   * This method initializes this
   * 
   * @return void
   */
  private void initialize()
  {
    this.setSize(802, 572);
    this.setContentPane(getJContentPane());
    this.setTitle("Swipe and Transparency Tools");
    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();
    SwipeAndChangeTransparency map = new SwipeAndChangeTransparency();
    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("");
      try
      {
        toolbarBean.setBuddyControl(getMapBean());
        commandsEnvironment = new CommandsEnvironment();
        toolbarBean.addItem(new ControlsOpenDocCommand(), 0, -1, false, 0,
            esriCommandStyles.esriCommandStyleIconOnly); // open
        toolbarBean.addItem(new ControlsMapNavigationToolbar(), 0, -1, false, 0,
            esriCommandStyles.esriCommandStyleIconOnly); // open
        toolbarBean.addItem(new ControlsLayerListToolControl(), 0, -1, false, 0,
            esriCommandStyles.esriCommandStyleIconOnly); // open
        toolbarBean.addItem(new ControlsMapSwipeTool(), 0, -1, false, 0,
            esriCommandStyles.esriCommandStyleIconOnly); // open
        toolbarBean.addItem(new ControlsLayerTransparencyCommand(), 0, -1, false, 0,
            esriCommandStyles.esriCommandStyleIconOnly); // open

      }
      catch (IOException e)
      {
        e.printStackTrace();
      }
    }
    return toolbarBean;
  }

  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);
    }catch (Exception e){
      e.printStackTrace();
    }
  }
}