Creating custom commands and tools


Summary 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 recommended way to create custom tools and commands is by extending ArcObjects to take advantage of the ArcObjects toolbar and 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 interface. To create a custom tool, implement the ICommand and ITool interface. 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:
  • Caption—(String) name of the command; this name is used to display the command.
  • ToolTip—(String) The ToolTip message that displays.
  • Enabled—(boolean) Enables or disables the command by default.
  • BitmapPath—(String) Location to the bitmap used as the icon for this command.
Specify these values in the constructor of your command. See the following code example:
[Java]
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 HookHelper of interest:
[Java]
public void onCreate(Object obj){
    hookHelper = new HookHelper();
    hookHelper.setHookByRef(obj)
}
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 along with the following additional property:
  • CursorPath—(String) Specify the location of the *.cur file used as a cursor when the tool is selected.
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. Please refer to the BaseCommand Javadoc for a complete list of methods.


See Also:

Creating Custom Menus, Palettes and MultiItems




Development licensing Deployment licensing
Engine Developer Kit Engine Runtime
ArcView
ArcEditor
ArcInfo