arcgissamples\toolbarbean\commands\FullExtentCommand.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.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.systemUI.ICommand; import com.esri.arcgis.systemUI.ITool; /** * Description: This class is a custom implementation 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 FullExtentCommand implements ICommand, ITool { MapAsToolbarBuddy application; public int getBitmap() { return 0; } public String getCaption() { return "FullExtent"; } public String getCategory() { return "CustomCommands"; } public int getHelpContextID() { return -1; } public String getHelpFile() { return null; } public String getMessage() { return "Zooms the Display To Full Extent of the Data"; } public String getName() { return "Sample_Pan/FullExtent"; } public String getTooltip() { return "Full Extent"; } public boolean isChecked() { return false; } public boolean isEnabled() { return true; } public void onClick() { try { //Get the active control if(MapAsToolbarBuddy.ACTIVECONTROL == MapAsToolbarBuddy.MAPCONTROL) { MapBean mapBean = application.getMapBean(); //Zoom to the full extent of the control mapBean.setExtent(mapBean.getFullExtent()); } else if (MapAsToolbarBuddy.ACTIVECONTROL == MapAsToolbarBuddy.PAGELAYOUTCONTROL) { PageLayoutBean pageLayoutBean = application.getPageLayoutBean(); //Zoom to the full extent of the control pageLayoutBean.zoomToWholePage(); } } catch (Exception ex) { System.out.println( "Exception in FullExtent#onMouseDown : " + ex); ex.printStackTrace(); } } 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) { } 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) { } }