This document explains key features and helper classes needed to create custom commands and tools. Commands are operations that are performed by clicking a button. Tools are more interactive in that 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 of creating custom tools and commands is by extending ArcObjects so that you can take advantage of the ArcObjects toolbar and add these to the ToolbarBean. When using the custom command and tool, you also have access to an object, HookHelper, which makes it simple to access the underlying map.
You cannot add JButton to the ArcObjects ToolBarBean.
ArcGIS Engine Java API allows you to create custom commands and tools by extending ArcObjects. To create a custom command, you need to implement ICommand interface, and to create a custom tool, you need to implement the ICommand and ITool interface. BaseCommand and BaseTool classes are provided to help in implementation.
HookHelper is another concept common to both commands and tools. There are different HookHelpers for different controls. SceneHookHelper for SceneControl, GlobeHookHelper for Globe and HookHelper for Map and PageLayout. HookHelper can provide generic access to the ActiveView and the underlying map and layers. The command needs to determine the type of hook passed to it so that it can manage it accordingly.
Refer to the following sections for more details on commands or tools:
To create custom commands simply extend the BaseCommand class, which implements the ITool interface.
All the behavioral properties are exposed as attributes. You can set these attributes to specify the behavior of your command. The various important attributes associated with a BaseCommand are:
caption—(String) name of the command. This name is used to display the command.
toolTip—(String) The ToolTip message that is displayed
enabled—(boolean) It is used to enable or disable the command by default.
bitmapPath—(String) Location to the bitmap to be used as the icon for this command.
You can specify these values in the constructor of your command.
For example:
public class MyCommand extends BaseCommand{
public MyCommand(){
caption = "MyCommand";
toolTip="This is MyCommand which does...";
enabled=true;
bitmapPath="/icons/image1.bmp";
}
..
..
..
}
You should use the following method to set up the HookHelper of interest:
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.
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 one additional property:
cursorPath—(String) Specify the location of the *.cur file to be used as a cursor when the tool is selected.
You need not be concerned with managing the selection and deselection of tools. The ToolbarBean does that for you. As soon as you click this 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.