Creating custom commands and tools

This topic explains key features and helper classes needed to create custom commands and tools.

In this topic

About creating custom commands and tools

Commands are operations that are performed by clicking a button. Tools are more interactive as a user needs to click a button to activate the tool and perform an action, such as identify on the map.
In ArcObjects Java, the way to create custom tools and commands is by extending ArcObjects to take advantage of the ArcObjects toolbar, then add these to the ToolbarBean. When using the custom command and tool, you also have access to the HookHelper object, which makes it simple to access the underlying map.
You cannot add JButton to the ArcObjects ToolBarBean.
The ArcGIS Engine Java application programming interface (API) allows you to create custom commands and tools by extending ArcObjects. To create a custom command, implement ICommand. To create a custom tool, implement ICommand and ITool. BaseCommand and BaseTool classes are provided to help the implementation.
HookHelper is another concept common to commands and tools. There are different HookHelpers for different controls (SceneHookHelper for SceneControl, GlobeHookHelper for Globe, and HookHelper for Map and PageLayout).
HookHelper provides generic access to the ActiveView and the underlying map and layers. The command needs to determine the type of hook passed to it so it can manage it accordingly.

Create custom commands

To create custom commands, extend the BaseCommand class, which implements the ITool interface.
All the behavioral properties are exposed as attributes. Set these attributes to specify the behavior of your command. The following are the various important attributes associated with a BaseCommand:
Specify these values in the constructor of your command. See the following code example:
public class MyCommand extends BaseCommand{
    public MyCommand(){
        caption = "MyCommand";
        toolTip = "This is MyCommand which does...";
        enabled = true;
        bitmapPath = "/icons/image1.bmp";
    .. .. ..
Use the following code example to set up the applicable HookHelper:
public void onCreate(Object obj){
    hookHelper = new HookHelper();
By using the HookHelper, you can access the ActiveView, focus map, and layers.
Now you can override the onClick() method to specify the behavior of your command.

Create custom tools

Creating a custom tool is similar to creating a custom command. You need to extend the BaseTool class, which in turn, extends the BaseCommand and implements the ITool interface. You can specify the properties of the tool similarly. All the properties with the command are applicable with the following additional property:
Do not be concerned with managing the selection and deselection of tools, as the ToolbarBean does that. When you click the tool, the last selected tool is deselected.
You can specify the HookHelper object similar to the previous explanation using the BaseCommand. You can also specify the behavior of your tool by overriding methods of your choice, such as onMouseMove, onMouseDown, onKeyUp, and so on. For a complete list of methods, see the BaseCommand JavaDoc.

See Also:

Creating custom menus, palettes, and MultiItems

Development licensingDeployment licensing
Engine Developer KitEngine
ArcGIS for Desktop Basic
ArcGIS for Desktop Standard
ArcGIS for Desktop Advanced