arcgissamples\toolbarbean\commands\ZoomInCommand.java—ArcObjects 10.4 Help for Java | ArcGIS for Desktop
Map as toolbar buddy
arcgissamples\toolbarbean\commands\ZoomInCommand.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.toolbarbean.commands;

import java.io.IOException;

import arcgissamples.toolbarbean.MapAsToolbarBuddy;

import com.esri.arcgis.beans.map.MapBean;
import com.esri.arcgis.beans.pagelayout.PageLayoutBean;
import com.esri.arcgis.controls.ToolbarControl;
import com.esri.arcgis.geometry.IEnvelope;
import com.esri.arcgis.systemUI.ICommand;
import com.esri.arcgis.systemUI.ITool;

/**
 * Description: This class is a custom implementaion of tool button. Instance of this class can be added to toolbar control
 * using toolbarBean#addItem.
 * @see com.esri.arcgis.systemUI.ICommand
 * @see com.esri.arcgis.systemUI.ITool
 * */

public class ZoomInCommand implements ITool, ICommand {
  MapAsToolbarBuddy application;

  public int getBitmap() {
    return 0;
  }

  public String getCaption() {
    return "Zoom In";
  }

  public String getCategory() {
    return "CustomCommands";
  }

  public int getHelpContextID() {
    return -1;
  }

  public String getHelpFile() {
    return null;
  }

  public String getMessage() {
    return "Zooms the Display In By Rectangle Or Single Click";
  }

  public String getName() {
    return "Sample_Pan/Zoom_Zoom In";
  }

  public String getTooltip() {
    return "Zoom In";
  }

  public boolean isChecked() {
    return false;
  }

  public boolean isEnabled() {
    return true;
  }

  public void onClick() {
  }

  public void onCreate(Object hook) {
    try {
      ToolbarControl toolbarControl = new ToolbarControl(hook);
      application = (MapAsToolbarBuddy)toolbarControl.getBuddy();
    }
    catch (IOException ex) {
    }

  }

  public boolean deactivate() {
    return true;
  }

  public int getCursor() {
    return 0;
  }

  public boolean onContextMenu(int x, int y) {
    return false;
  }

  public void onDblClick() {
  }

  public void onKeyDown(int keyCode, int shift) {
  }

  public void onKeyUp(int keyCode, int shift) {
  }

  public void onMouseDown(int button, int shift, int x, int y) {
    try {
      //Get the active control
      if(MapAsToolbarBuddy.ACTIVECONTROL == MapAsToolbarBuddy.MAPCONTROL) {
        MapBean mapBean = application.getMapBean();
        IEnvelope envelope = mapBean.trackRectangle();
        mapBean.setExtent(envelope);
      }
      else if (MapAsToolbarBuddy.ACTIVECONTROL == MapAsToolbarBuddy.PAGELAYOUTCONTROL) {
        PageLayoutBean pageLayoutBean = application.getPageLayoutBean();
        IEnvelope envelope = pageLayoutBean.trackRectangle();
        pageLayoutBean.setExtent(envelope);
      }
    }

    catch (Exception ex) {
      System.out.println(
          "Exception in Zoomin#onMouseDown : " +
          ex);
      ex.printStackTrace();
    }
  }

  public void onMouseMove(int button, int shift, int x, int y) {
  }

  public void onMouseUp(int button, int shift, int x, int y) {
  }

  public void refresh(int hdc) {
  }
}