Supported with:
Additional library information: Contents, Object Model Diagram
See the following sections for more information about this namespace:
- Engine
Additional library information: Contents, Object Model Diagram
ArcGIS Engine includes a set of reusable components, the ArcGIS controls, as prebuilt software code designed to provide graphical functions and allow high-level development. The Java application programming interface (API) for ArcObjects makes these controls available for use as visual JavaBeans at design time.
See the following sections for more information about this namespace:
- Common themes and concepts
- MapBean
- PageLayoutBean
- GlobeBean
- SceneBean
- TOCBean
- ToolbarBean
- SymbologyBean
Common themes and concepts
Each JavaBean has full access to their corresponding control commands that can include a set of commands, tools, menus, and palettes; however, before discussing details of each of these areas, the following are some common themes and concepts applicable to each of the ArcGIS Engine Beans that should be understood to effectively build applications using them:
- Embeddable components
- Property pages
- Encapsulated ArcObjects
- Events
- Buddy controls
- Map authoring
- Products
- Extensions
- Shutdown
Embeddable components
Each ArcGIS Bean is an embeddable component that can be dropped in a container form or dialog box provided by an integrated development environment (IDE). The ArcGIS Engine Beans can be embedded into an existing application to add additional 2D or 3D mapping capability or to create a new stand-alone application. Once in a container, each ArcGIS Bean can be resized and repositioned with other embeddable components, such as command buttons and combo boxes, to provide a user interface in the application.
Property pages
Each ArcGIS Bean has a set of property pages, which are accessible in common ways from most IDEs. For example, by right-clicking the MapBean in Eclipse, you can choose the Customize Java Bean option to open its properties. These property pages provide shortcuts to a selection of a bean's properties and methods and allows a developer to build an application with minimal or no code.
Encapsulated ArcObjects
Each ArcGIS Bean simplifies the development process by encapsulating coarse-grained ArcObjects, while still providing access to finer-grained ArcObjects. For example, the PageLayoutBean encapsulates the PageLayout object. The PageLayout contains at least one MapFrame element containing a map and the map can contain multiple RasterLayer, FeatureLayer, or custom layer objects.
Each ArcGIS Bean provides shortcuts to frequently used properties and methods on the ArcObjects component they encapsulate. For example, the MapBean has a SpatialReference property that is a shortcut to the SpatialReference property of the Map object. Each ArcGIS Bean also has helper methods that perform common tasks. For example, the MapBean has an AddShapeFile method. The ArcGIS Engine Beans are a starting point for developing applications not only because they provide a user interface, but also by providing a direct route into the object model.
Events
Each ArcGIS Bean fires events in response to keyboard and mouse interactions by the user. Other events fire in response to actions occurring in the controls. For example, when a map document is loaded into the MapBean, the OnMapReplaced event is fired or when an object is dragged over the MapBean by dragging and dropping, the OnOleDrop event is fired.
Buddy controls
An individual ArcGIS Bean can be embedded into an application; the TOCBean and ToolbarBean can be used with another ArcGIS Bean to provide part of the application's framework. The ToolbarBean and TOCBean work in conjunction with one other buddy control. Typically, the buddy control is a MapBean, PageLayoutBean, GlobeBean, or SceneBean.
The buddy control can be set at design time, though the property pages programmatically use the SetBuddyControl method. The TOCBean uses the buddy control to display an interactive tree view of its map, layer, and symbology contents, while the ToolbarBean hosts a panel of commands, tools, menus, and palettes that work with the display of the buddy control. See the following code example:
[Java]
try{
TOCBean.setBuddyControl(aMapBean);
}
catch (IOException e){
e.printStackTrace();
}
Map authoring
The ArcGIS Desktop applications can be used to preauthor documents that can be loaded into the ArcGIS Engine Beans, to quickly produce high quality mapping. For example, ArcMap can be used to author map documents that can be loaded into the MapBean and PageLayoutBean; ArcGlobe to author globe documents that can be loaded into the GlobeBean; and ArcScene to author scene documents that can be loaded into the SceneBean.
Preauthoring documents can save a substantial amount of time, as it eliminates the need to programmatically create maps, renderers, symbols, and set their properties. Once a document is loaded into an ArcGIS Bean, layers, elements, and symbols can be accessed programmatically through the object model if their appearance needs changing.
The following table summarizes the types of document that can be loaded into applicable ArcGIS Engine Beans:
|
MapBean
|
PageLayoutBean
|
GlobeBean
|
SceneBean
|
Map document (*.mxd, *.mxt)
|
Yes
|
Yes
|
No
|
No
|
Layer file (*.lyr)
|
Yes
|
Yes1
|
No
|
No
|
Globe document (*.3dd, *.sdt)
|
No
|
No
|
Yes
|
No
|
Scene document (*.sxd, *.sxt)
|
No
|
No
|
No
|
Yes
|
Published map files (*.pmf) with no permission to load in a customized application or restricted access to its contents
|
No
|
No
|
No
|
No
|
Published map files (*.pmf) with permission to load in a customized application and unrestricted access to its contents
|
Yes
|
Yes
|
No
|
No
|
1There are no properties on this ArcGIS Bean to load layer files (*.lyr); however, they can be loaded indirectly by the MapDocument object.
|
Products
Select at least one product license the application can be initialized with. If the product you require is not licensed, you can optionally initialize the application with a higher product license. If no product licenses are available, the application fails to initialize. Once an application is initialized with a product license, it is not possible to reinitialize the application for the duration of the application's life.
The following code example tries to initialize the ArcGIS Engine license (the lower license). If it is not available, it uses an ArcView license. The ArcGIS Eclipse plug-in provides a LicenseUI to automatically generate this code by the product license levels.
[Java]
try{
AoInitialize ao = new AoInitialize();
if (ao.isProductCodeAvailable
(esriLicenseProductCode.esriLicenseProductCodeEngine) ==
esriLicenseStatus.esriLicenseAvailable)
ao.initialize(esriLicenseProductCode.esriLicenseProductCodeEngine);
else if (ao.isProductCodeAvailable
(esriLicenseProductCode.esriLicenseProductCodeArcView) ==
esriLicenseStatus.esriLicenseAvailable)
ao.initialize(esriLicenseProductCode.esriLicenseProductCodeArcView);
}
catch (Exception e){
e.printStackTrace();
}
Extensions
Select the extension licenses required by the application. Not every extension license is available with every product license; as such, the list of available extension licenses will change as different product licenses become selected. If the ArcGIS Engine product license is selected and an ArcGIS Desktop product is selected, only the ArcGIS Engine extension licenses displays.
The availability of each extension license is checked in conjunction with the product license that the application will ultimately be initialized with. If any of the selected extensions are not available, the application fails to initialize.
The LicenseUI in the Eclipse plug-in can also generate extension license code. See the following screen shot:
Shutdown
When an ArcGIS Engine application is closed or shutdown, the ArcObjects that were initialized when the application started, must be shutdown. Call the shutdown() method of AoInitialze as the program exits. See the following code example:
[Java]
private static void shutdownArcObjects(){
try{
aoInit.shutdown();
}
catch (Exception ex){
ex.printStackTrace();
System.exit(0);
}
}
MapBean
The MapBean corresponds to the data view of the ArcMap Desktop application and encapsulates the Map object. Map documents preauthored with the ArcMap application can be loaded into the MapBean eliminating the need to programmatically compose the cartography.
Loading map documents
The map document can be set at design time through the MapBean property pages and the MapBean can be set to link or contain the map document. When linking, the MapBean reads the map document when the MapBean is created on the container, and displays recent updates to the map document.
When containing, the MapBean copies the contents of the map document into the MapBean and will not display further updates to the map document. Containing increases the size of the application's executable containing the MapBean. See the following screen shot:
Alternatively, a map document can be loaded into the MapBean programmatically using the CheckMxFile method to determine if the document is valid and the LoadMxFile method to load the map document. The ReadMxMaps can be used in conjunction with the LoadMxFile method to load a specific map from a map document into the MapBean. See the following code example:
[Java]
String filePath = "C:\\Temp\\myDocument.mxd";
try{
if (mapBean.checkMxFile(filePath) == true){
mapBean.loadMxFile(filePath, null, null);
}
}
catch (AutomationException e){
e.printStackTrace();
}
catch (IOException e){
e.printStackTrace();
}
Saving map documents
As well as reading map documents, the MapBean can also write map documents (*.mxd). The MapBean implements the IMxdContents interface that enables the MapDocument object to write the contents of the MapBean to a new map document.
Layers
The MapBean provides shortcuts to frequently used members on the Map object, such as AddLayer, DeleteLayer, and ClearLayers, and helper members, such as AddLayerFromFile, AddShapefile, and MoveLayerTo, which manages the individual layers in the map.
Display
The display area of the MapBean can be altered by using the SetVisibleRegion method to change the shape of the display area and the SetRotation method to alter the angle where data is drawn on the display.
Helper methods, such as TrackRectangle, TrackPolygon, TrackLine, and TrackCircle exist on the MapBean for tracking or rubber banding shapes on the display. For example, to zoom in on the display, set the envelope returned from the TrackRectangle method into the SetExtent property. Shapes can be drawn on the display with the DrawShape, DrawText, and FlashShape methods, typically in the IMapControl2.onAfterDraw event. See the following code example:
[Java]
public void onMouseDown(com.esri.arcgis.controls.IMapControlEvents2OnMouseDownEvent
e){
try{
mapBean.setExtent(mapBean.trackRectangle());
}
catch (AutomationException e){
e.printStackTrace();
}
catch (IOException e){
e.printStackTrace();
}
}
PageLayoutBean
The PageLayoutBean corresponds to the layout view of the ArcMap Desktop application and encapsulates the PageLayout object. Map documents authored with the ArcMap application can be loaded into the PageLayoutBean, eliminating the need to programmatically compose the cartography. See the following screen shot:
Loading map documents
The map document can be set at design time though the PageLayoutBean property pages and the PageLayoutBean can be set to link or contain the map document. When linking, the PageLayoutBean reads the map document when the PageLayoutBean is created on the container and displays the recent updates to the map document.
When containing, the PageLayoutBean copies the contents of the map document into the PageLayoutBean and will not display further updates to the map document. Containing increases the size of the application's executable containing the PageLayoutBean.
Alternatively, a map document can be loaded into the PageLayoutBean programmatically using the CheckMxFile method to determine whether the document is valid and the LoadMxFile method to load the map document.
Saving map documents
As well as reading map documents, the PageLayoutBean can also write map documents (*.mxd). The PageLayoutBean implements the IMxdContents interface that enables the MapDocument object to write the contents of the PageLayoutBean to a new map document. See the following code example:
[Java]
try{
mapDocument = new MapDocument();
mapDocument.esri_new("C:\\Temp\\myDocument.mxd");
mapDocument.replaceContents((IMxdContents)pagelayoutbean.getObject());
mapDocument.setActiveView(pagelayoutbean.getActiveView());
mapDocument.save(true, true);
}
catch (UnknownHostException e){
e.printStackTrace();
}
catch (IOException e){
e.printStackTrace();
}
Elements
The PageLayoutBean provides shortcuts to frequently used members, such as the GraphicsContainer and AddElement, and helper methods, such as FindElementByName and LocateFrontElement to manage individual elements in the PageLayout.
Printing
The PageLayoutBean provides shortcuts to frequently used members on the PageLayout object such as Page and Printer, and helper members, such as GetPrinterPageCount and GetPageLayout to assist with printing tasks.
GlobeBean
The GlobeBean corresponds to the 3D view of the ArcGlobe Desktop application and provides a 3D view of data on a globe surface in true geodetic location. See the following screen shot:
Globe objects
The GlobeBean encapsulates an object implementing IGlobeViewer. This is the same IGlobeViewer object found inside the ArcGlobe application. The IGlobeViewer object contains a GlobeDisplay and the GlobeDisplay contains a globe. The GlobeBean provides shortcuts to frequently used properties and methods on the object it encapsulates. For example, the GlobeBean has GetGlobeCamera, GetGlobe, GetGlobeDisplay, and GetGlobeViewer properties. For more information, see the GlobeCore library.
Loading globe documents
The globe document can be set at design time through the GlobeBean property pages (in development environments that support property page capability). The GlobeBean attempts to load this document when it is created. Alternatively, a globe document can be loaded into the GlobeBean programmatically using the Check3dFile method to determine whether the document is valid and the Load3dFile method to load the globe document. See the following code example:
[Java]
String filePath = "C:\\Temp\\MyGlobeDocument.3dd";
try{
if (globeBean.check3dFile(filePath) == true){
globeBean.load3dFile(filePath);
}
}
catch (AutomationException e){
e.printStackTrace();
}
catch (IOException e){
e.printStackTrace();
}
The GlobeBean requires the ArcGIS Engine 3D Analyst extension.
Navigation
The GlobeBean has built in navigation functionality that can be switched on at design time through the GlobeBean property pages or programmatically with the SetNavigate property. The functionality enables the user to click the left mouse button to navigate backwards and forwards and to the left and right of the display, and the right mouse button to zoom in and out on the display.
SceneBean
The SceneBean corresponds to the 3D view of the ArcScene Desktop application and provides a way to view and investigate spatial data layers in 3D. See the following screen shot:
Scene objects
The SceneBean encapsulates an object implementing ISceneViewer. This is the same ISceneViewer object found inside the ArcScene application. The ISceneViewer object contains a camera and the camera contains an observer and target position. The SceneBean provides shortcuts to frequently used properties and methods on the object it encapsulates. For example, the SceneBean has GetCamera, GetScene, GetSceneGraph, and GetSceneViewer properties. For more information, see the 3DAnalyst library.
Loading scene documents
The scene document can be set at design time through the SceneBean property pages. The SceneBean attempts to load this document when it is created. Alternatively, a scene document can be loaded into the SceneBean programmatically using the CheckSxFile method to determine whether the document is valid and the LoadSxFile method to load the scene document. See the following code example:
[Java]
String filePath = "C:\\Temp\\MySceneDocument.sxd";
try{
if (sceneBean.checkSxFile(filePath) == true){
sceneBean.loadSxFile(filePath);
}
}
catch (AutomationException e){
e.printStackTrace();
}
catch (IOException e){
e.printStackTrace();
}
Navigation
The SceneBean has built in navigation functionality that can be switched on at design time through the SceneBean property pages or programmatically with the SetNavigate property. The functionality enables the user to click the left mouse button to navigate backwards and forwards and to the left and right of the display, and the right mouse button to zoom in and out on the display.
The SceneBean requires the ArcGIS Engine 3D Analyst extension.
TOCBean
The TOCBean works in conjunction with a buddy control. The buddy control can be a MapBean, PageLayoutBean, GlobeBean, or SceneBean. The buddy control can be set at design time though the TOCBean property pages or programmatically using the SetBuddyControl method when the container hosting the TOCBean is displayed. See the following code example:
[Java]
try{
TOCBean.setBuddyControl(aMapBean);
}
catch (Exception e){
e.printStackTrace();
}
Each TOCBean buddy control implements the ITOCBuddy interface and can fire methods on the ITOCBuddyEvents interface. The TOCBean uses the buddy control to display an interactive tree view of its map, layer, and symbology contents and to keep its contents synchronized with the buddy control. For example, if the TOCBean has a MapBean as its buddy, and a map layer is removed from the MapBean, the map layer will also be removed from the TOCBean. Likewise, if the user interacts with the TOCBean to uncheck a map layer's visibility, the layer will not be visible in the MapBean.
Layer drag and drop
The TOCBean can support the dragging and dropping of layers in the control when TOCBean.SetEnableLayerDragDrop(true) is called. Layers can be moved or copied (press the Ctrl key) in the following ways: in a map; to and from group layers; between maps; and between maps in different TOCBeans.
Selected item
An item can be selected in the TOCBean, either interactively by the user clicking the TOCBean or programmatically using the TOCBean.SelectItem method. The TOCBean.GetSelectedItem method returns the selected item. See the following code example:
[Java]
try{
IBasicMap basicmap[] = {
null
};
ILayer layer[] = {
null
};
Object other[] = {
null
};
int itemType[] = {
0
};
Object pIndex[] = {
null
};
toc.hitTest(e.getX(), e.getY(), itemType, basicmap, layer, pIndex, other);
System.out.println("Item Type: " + itemType[0]);
}
catch (Exception ex){
ex.printStackTrace();
}
ToolbarBean
The ToolbarBean works in conjunction with a buddy control. The buddy control can be a MapBean, PageLayoutBean, GlobeBean, or SceneBean. The buddy control can be set at design time through the ToolbarBean property pages or programmatically using the SetBuddyControl method when the container hosting the ToolbarBean displays. The ToolbarBean hosts a panel of commands, tools, tool control's, menus and palettes that work with the display of the buddy control. See the following code example:
[Java]
toolbarBean.setBuddyControl(aMapBean);
Each ToolbarBean buddy control implements the IToolbarBuddy interface. This interface is used to set the GetCurrentTool property of the buddy control. For example, imagine a ToolbarBean that is hosting a Page Zoom In tool and has a PageLayoutBean as its buddy. When the user clicks the Page Zoom In tool on the ToolbarBean, it becomes the CurrentTool of the PageLayoutBean. The implementation of the Page Zoom In tool queries the ToolbarBean to access its buddy control (PageLayoutBean) and retrieves the PageLayout. It then provides the implementation for displaying the rectangle dragged by the user and changes the extent of the PageLayout. See the following screen shot:
The ToolbarBean is used with a selection of the control commands and a buddy control to provide a functional geographic information system (GIS) application. The ToolbarBean is not only providing a part of the user interface, it is also providing a part of the application's framework. ArcGIS desktop applications like ArcMap, ArcGlobe, and ArcScene have a powerful and flexible framework that includes user interface components, such as toolbars, commands, menus, dockable windows, and status bars. This framework enables the user to customize the application by allowing them to reposition, add, and remove most of these user interface components.
Many development environments provide pieces of a framework in the form of dialog boxes, forms, and multiple docking interface (MDI) applications. They also provide generic user interface components, such as buttons, status bars, and list boxes. However, a substantial amount of coding can still be required to provide toolbars, menus, and palettes that host commands, especially if they need to be customized by the user. The ToolbarBean and the objects in its library can supply pieces of a framework similar to the ArcGIS Desktop application framework. The developer can use some or all of these framework pieces when building an application with the ToolbarBean.
ToolbarBean can also be configured with tools and commands from in the design time environment of the Eclipse IDE.
Commands
ArcGIS Engine provides several suites of control commands that work with the ArcGIS Engine Beans to perform specific actions. You can extend this suite of control commands by creating customized commands that perform a specific piece of work. All of these command objects implement the ICommand interface that is used by the ToolbarBean to call methods and access properties at appropriate times. For convenience, BaseCommand is provided as a base class that implements ICommand and can be extended by custom commands. Similarly, BaseTool is proveded for custom tools and implements ITool.
The ICommand.OnCreate method is called after the Command object is hosted on the ToolbarBean. The method is passed a handle or hook to the application that the command works with. The implementation of a command normally tests to see if the hook object is supported (that is, the command tests to see that the hook is an object that the command can work with). If the hook is not supported, the command disables. If the hook is supported, the command stores the hook for later use. For example, if an Open Map Document command works with the MapBean or PageLayoutBean and they are passed to the OnCreate method as the hook, the command stores the hook for later use. If the ToolbarBean is passed to the OnCreate event as the hook, the command checks the type of buddy control being used in conjunction with the ToolbarBean using the buddy property. For example, if a command hosted on the ToolbarBean only works with the GlobeBean and the ToolbarBean's buddy is a MapBean, the command disables.
The ICommand.OnClick method is called when the user clicks on a command item hosted on the ToolbarBean. Depending on the type of command, it will typically do some work using the hook to access the required objects from the buddy control. The following are the types of commands:
- A command item implementing the ICommand interface that responds to a single click. A click results in a call to the ICommand.OnClick method and some action is performed. By changing the ICommand.IsChecked value, simple command items can behave like a toggle.
- A command item or tool implementing the ICommand and ITool interfaces that requires user interaction with the display of the buddy control. The ToolbarBean maintains one CurrentTool. When the user clicks the tool on the ToolbarBean, it becomes the CurrentTool and the previous tool is deactivated. The ToolbarBean sets the CurrentTool of the buddy control. While the tool is the CurrentTool, it receives mouse and key events from the buddy control.
- A command item or tool control implementing the ICommand and IToolControl interfaces. This is typically a user interface component, such as a Listbox or ComboBox hosted on the ToolbarBean. The ToolbarBean hosts a small window supplied by a window handle from the IToolControl.GetHWnd property. Only a single instance of a particular tool control can be added to the ToolbarBean.
See the following illustration:
Commands can be added to the ToolbarBean programmatically or at design time in the Eclipse IDE. Commands can be added programmatically by specifying an instance of an existing Command object to the AddItem method. See the following code example:
[Java]
toolbarBean1.setBuddyControl(mapBean1);
toolbarBean1.addItem(new ControlsMapFullExtentCommand(), 0, 0, false, 0,
esriCommandStyles.esriCommandStyleIconAndText);
toolbarBean1.addItem(new ControlsMapZoomOutTool(), 0, 0, false, 0,
esriCommandStyles.esriCommandStyleIconAndText);
toolbarBean1.addItem(new ControlsMapZoomInTool(), 0, 0, true, 0,
esriCommandStyles.esriCommandStyleIconAndText);
toolbarBean1.addItem(new ControlsOpenDocCommand(), 0, 0, false, 0,
esriCommandStyles.esriCommandStyleIconAndText);
ToolbarItem
A ToolbarItem is a single command, menu, or palette hosted on a ToolbarBean, ToolbarMenu, or ToolbarPalette. The IToolbarItem interface has properties to determine the appearance of the item to the user. For example, whether the item has a vertical line to its left signifying that it begins a group and whether the style of the item displays with a bitmap, caption, or both. The GetItem(int index) returns a ToolbarItem. From the ToolbarItem, the GetCommand(), GetMenu(), GetPalette(), and MultiItem() methods can be called to return the actual command, menu, palette, or multiitem that the ToolbarItem represents.
A MultiItem object can only exist on a ToolbarMenu.
Updating commands
By default, the ToolbarBean updates automatically every half a second. This ensures that the appearance of each ToolbarItem hosted on the ToolbarBean is synchronized with the Enabled, Bitmap, Checked, and Caption properties of its underlying command. Changing the UpdateInterval property can alter the frequency of the update. An UpdateInterval of 0 stops updates from happening automatically—call the Update method programmatically to refresh the state of each ToolbarItem.
The first time the Update method is called in an application, the ToolbarBean checks whether the onCreate method of each ToolbarItem's underlying command has been called. If the method has not been called, the ToolbarBean is automatically passed as the hook to the OnCreate method.
ToolbarMenu
The ToolbarBean can host an item that is a drop-down menu. A ToolbarMenu item presents a vertical list of single click command items. The user must select one of the command items on the ToolbarMenu or click outside the ToolbarMenu to make it disappear. The ToolbarMenu can be hosted on the ToolbarBean, hosted on another ToolbarMenu as a sub menu, or it can appear as a popup menu and used as a right-click context menu. See the following code example:
[Java]
toolbarBean1.addItem(new ControlsMapViewMenu(), 0, 0, false, 0,
esriCommandStyles.esriCommandStyleIconAndText);
The IToolbarMenu2 interface provides an AddMultiItem method that enables IMultiItem objects to be appended to an existing ToolbarMenu. The IMultiItem object allows a single object to act like several adjacent menu items, for example, a list of recently loaded map documents or a list of the spatial bookmarks in a map.
ToolbarPalette
The ToolbarBean can host an item that is a drop-down palette. A ToolbarPalette item consists of tools that interact with the display of the buddy control when set as the CurrentTool. The user must select one of the command items on the ToolbarPalette or click outside the ToolbarPalette to make it disappear. The ToolbarPalette can be hosted on the ToolbarBean, hosted on a ToolbarMenu as a sub menu, or appear as a popup palette and used as a right-click context palette. See the following code example:
[Java]
toolbarPalette1 = new ToolbarPalette();
toolbarPalette1.addItem(new ControlsSelectTool(), 0, - 1);
toolbarPalette1.addItem(new ControlsNewCircleTool(), 0, - 1);
toolbarPalette1.addItem(new ControlsNewCurveTool(), 0, - 1);
toolbarBean1.addItem(toolbarPalette1, 0, - 1, true, - 1,
esriCommandStyles.esriCommandStyleIconOnly);
CommandPool
Each ToolbarBean, ToolbarMenu, and ToolbarPalette has a CommandPool that is used to manage the collection of command objects that it is using. Normally, as a developer, you won't interact with the CommandPool. When a command is added to the ToolbarBean, through the property pages of the ToolbarBean or programmatically, the command is automatically added to the CommandPool. Command objects are added to the CommandPool as an existing instance of a command object. They can also be added as unique identifier (UID) objects.
If an existing instance of a command object is added, there is no unique identifier for the command and multiple instances of the same command can exist in the CommandPool. If a UID object is supplied, the CommandPool can identify whether the command exists in the CommandPool, and if so, the previous instance of the command can be reused. The CommandPool manages this by tracking whether the OnCreate method of a command has been called. If the OnCreate method has been called, it reuses the command and increments its UsageCount.
For example, if a Zoom In tool is added to a ToolbarBean twice with the UID supplied, when one of the Zoom In items on the ToolbarBean is selected and appears pressed, the other Zoom In item also appears pressed because they are both using the same command object. When an application contains multiple ToolbarBeans, ToolbarMenus, or ToolbarPalettes, ensure each ToolbarBean, ToolbarMenu, and ToolbarPalette uses the same CommandPool; this prohibits more than one instance of a command being created in the application.
Customization
The ToolbarBean has a SetCustomize method that can put the ToolbarBean into customize mode. This changes the behavior of the ToolbarBean and allows the user to rearrange, remove, and add items, as well as change their appearance.
- Click to select an item on the ToolbarBean, drag the selected item to a new position or drag-and-drop the item off the ToolbarBean to remove it.
- Right-click to select an item and display a customize menu. The Customize menu can be used to remove the item or change the style (bitmap, caption, or both) and group properties of the ToolbarItem.
While the ToolbarBean is in customize mode, you can programmatically launch the modeless CustomizeDialog. The CustomizeDialog lists all of the control commands with any custom commands, toolsets, menus, and palettes. It does this by reading entries from the ESRI controls commands, ESRI controls toolbars, ESRI controls menus, and ESRI controls palettes component categories. If required, you can change the CustomizeDialog to use alternative component categories with CommandsCategory, ToolbarsCategory, MenusCategory, and PalettesCategory properties. The user can add these commands, toolsets, menus, and palettes to the ToolbarBean by dragging-and-dropping them on the ToolbarBean or double-clicking them.
The CustomizeDialog is modeless to allow the user to interact with the ToolbarBean. When the CustomizeDialog is launched with the StartDialog method, the method call returns immediately while the CustomizeDialog remains open on the screen. To keep a reference to the CustomizeDialog while it is open, store a class level variable to the CustomizeDialog and to listen to its ICustomizeDialogEvents.
Use the SaveItems method to save the contents of a ToolbarBean after it has been customized by the user at runtime. The LoadItems method can be used to reload the contents back into a ToolbarBean.
Operation stack
The ToolbarBean has a GetOperationStack that returns an IOperationStack, which is used to manage undo and redo functionality. Operations are added to the operation stack by each ToolbarItem's underlying command, so that the operation can be rolled forward and then rolled back as desired. For example, when a graphic element is moved, the operation can be undone by moving the graphic back to its original location. Whether or not a command makes use of an OperationStack depends upon its implementation. Typically, as a developer, you create a single ControlsOperationStack for an application (by default GetOperationStack returns null) and set it into each ToolbarBean. Undo and Redo commands can be added to the ToolbarBean that step through the OperationStack. The Undo and Redo commands of the ArcGIS Engine Controls exist in the Control Commands. Any extent changes in an ActiveView are added to the GetExtentStack and not an OperationStack.
Appearance
The appearance of the ToolbarBean can be controlled by members of the IToolbarControl2 interface. The orientation of a ToolbarBean can be set to horizontal or vertical using the GetOrientation or SetOrientation method. The BackColor (Get and Set), FadeColor (Get and Set) and FillDirection (Get and Set) properties control the background shading of the ToolbarBean. Alternatively, the Transparent (Is and Set) property can set the background to be transparent. The ShowHiddenItems (Is and Set) property determines whether any hidden items on the ToolbarBean are visible on a hidden items menu indicated to the end user by two chevrons.
Control commands
The Control commands are commands, tools, toolcontrols, toolsets, menus, and palettes that work with the ArcGIS Engine controls to perform a specific action. For example, there is a suite of map navigation, map inquiry, feature selection, graphic element, feature editing, and ink commands that work with the MapBean and PageLayoutBean; a suite of Globe commands that work with the GlobeBean; a suite of Scene commands that work with the SceneBean; and a suite of Network and Schematics commands that work with the Network Analyst and Schematics extensions, respectively. You can extend this suite of Control commands by creating your own customized commands that perform a specific piece of work.
For a full list of the Control commands, refer to the Javadoc.
Control Commands with the ToolbarBean
For applications using the ToolbarBean in conjunction with a buddy control, these commands can be added to the ToolbarBean as follows:
- In a design-time environment of the Eclipse IDE—On the design-time canvas, right-click the ToolbarBean and click Customize Java Bean. This invokes a dialog box that allows the interactive placement, repositioning, and removal of items on the toolbar. It also allows for the look and feel of the toolbar and toolbar items to be modified.
- Programmatically using the AddItem, AddMenuItem, and AddToolbarDef methods—The commands can be added to a ToolbarMenu using the AddItem and AddSubMenu methods, and the commands can be added to a ToolbarPalette using the AddItem method.
- By the end user if the ToolbarBean is in customize mode.
Control Commands without the ToolbarBean
While building applications with the ToolbarBean can quickly provide pieces of a framework similar to the ArcGIS Desktop application framework, there are times when the ToolbarBean is not required for an application: the visual appearance of the ToolbarBean may not match that of the application; the overhead of implementing command objects for the ToolbarBean is not required; or there is an existing application framework in the application.
The Control commands can work directly with the MapBean, PageLayoutBean, GlobeBean, and SceneBean by programmatically creating a new instance of a command and passing the MapBean, PageLayoutBean, GlobeBean, and Scenebean to the OnCreate method. The developer becomes responsible for overriding the OnCreate and OnClick methods at the appropriate times and reading properties on the ICommand interface to build up the user interface as follows:
- A new instance of a Ccmmand is created programmatically and the individual ArcGIS control is passed to the OnCreate event. For example, if the Zoom FullExtent command is to work with the MapBean, pass the MapBean as the hook to the OnCreate method.
- A developer can use the CommandPool object without the ToolbarBean to manage the commands used by an application. The CommandPool provides support for calling the OnCreate method of each command based on its hook property.
- If the command only implements the ICommand interface, call the OnClick method at the appropriate time to perform the specific action. If the command is a tool that implements the ICommand and ITool interfaces, set the tool to be the CurrentTool in the ArcGIS control. The ArcGIS control sends any keyboard and mouse events to the tool.
- A command's Enabled, Caption, and Bitmap properties can be read and set into the properties of a command button supplied by the development environment to build up the user interface of the application.
See the following code example:
[Java]
ControlsSelectFeaturesTool command = new ControlsSelectFeaturesTool();
command.OnCreate(aMapBean);
aMapBean.setCurrentToolByRef(command);
Creating custom commands
To extend the suite of control commands, you can create custom commands, tools, menus, and palettes to work with the ArcGIS Engine controls. The HookHelper, GlobeHookHelper, and SceneHookHelper objects can be used to simplify this development. The HookHelper object makes it straightforward to create a command that works with the MapBean, PageLayoutBean, ToolbarBean, and the ArcMap application; the GlobeHookHelper to create a command that works with the GlobeBean, ToolbarBean, and the ArcGlobe application; and the SceneHookHelper to create a command that works with the SceneBean, ToolbarBean, and the ArcScene application.
Rather than adding code into an OnCreate method to determine the type of hook passed to the command, the HookHelper, GlobeHookHelper, and SceneHookHelper objects handles this.
- The HookHelper object is used to hold onto the hook and the IHookHelper interface it implements can return the ActiveView, PageLayout, and Map regardless of the type of hook that is passed.
- The GlobeHookHelper object is used to hold onto the hook and the IGlobeHookHelper interface it implements can return the Camera, Globe, GlobeDisplay, and ActiveViewer regardless of the type of hook that is passed.
- The SceneHookHelper object is used to hold onto the hook and the ISceneHookHelper interface it implements can return the SceneViewer, Scene, SceneGraph, and Camera regardless of the type of hook that is passed.
See the following code example:
[Java]
public void onCreate(Object obj){
try{
hookHelper = new HookHelper();
hookHelper.setHookByRef(obj);
}
catch (IOException ex){
System.out.println("Exception");
throw new RuntimeException(ex);
}
}
When a change is made to the HookHelper, GlobeHookHelper, and SceneHookHelper objects, the IHookHelperEvents.OnHookUpdated event is fired. For example, the event is fired in response to the IToolbarControlEvents.OnBuddyChanged event and the IPageLayoutControlEvents.OnPageLayoutReplaced event. Use the event to resynch any member variables storing IHookHelper, IGlobeHookHelper, and ISceneHookHelper properties, and to resynch any event listeners, such as IActiveViewEvents.
The HookHelper and GlobeHookHelper implement the IHookActions interface, which provides methods to flash, pan or zoom, and create graphics, labels and callouts on the specified IPoint, IEnvelope, IPolyline, and IPolygon objects. For example, the DoActionOnMultiple method can be used to zoom to the extent of the selected features in the map. See the following code example:
[Java]
public void onClick(){
try{
Array myArray = new Array();
MapSelection selection = new MapSelection(hookHelper.getFocusMap()
.getFeatureSelection());
IEnumFeature enumFeature = (IEnumFeature)selection;
IFeature feature = null;
// Add the selected features geometry to the array.
enumFeature.reset();
feature = enumFeature.next();
while (feature != null){
myArray.add(feature.getShape());
feature = enumFeature.next();
}
// If zooming is supported, zoom to the selected features.
if (hookHelper.isActionSupportedOnMultiple(myArray,
esriHookActions.esriHookActionsZoom)){
hookHelper.doActionOnMultiple(myArray,
esriHookActions.esriHookActionsZoom);
}
}
catch (Exception e){
e.printStackTrace();
}
}
Singleton objects
The are several singleton objects that only support one instance of the object in an application that are used by the Control commands. You can also make use of these objects in your custom commands.
- The CommandEnvironment object implements the IGraphicProperties and ILayerEffectProperties interfaces. The members of IGraphicProperties manage the default MarkerSymbol, LineSymbol, and FillSymbol used by the Control commands.
- The EngineEditor object implements the IEngineEditProperties, IEngineEditProperties2, and IEngineSnapEnvironment interfaces. The members of these interfaces manage the properties of edit sessions and snap agents.
- The EngineInkEnvironment object implements the IEngineInkEnvironment and IEngineInkEnvironmentEvents interfaces. The members of these interfaces manage the ink collection and manage tablet properties.
- The EngineNetworkAnalystEnvironment object implements the IEngineNetworkAnalystEnvironment, IEngineNetworkAnalystEnvironmentEvents, and IEngineNetworkAnalystHelper interfaces. The members of these interfaces manage the collection of network layers, the current network layer, solving and getting directions.
- The MyPlaceCollection object implements the IEnumPlace and IPlaceCollection interfaces. The members of these interfaces manage the addition and removal of Place objects to the place collection.
SymbologyBean
The SymbologyBean is used to display the contents of server style files (*.ServerStyle) and custom symbology. The symbology can be used to update part of an application, such as a layer's renderer or an element's symbol. You can use or embed the SymbologyBean to produce custom Swing dialog boxes. See the following screen shot:
Loading server style files
Server style files can be loaded at design-time through the SymbologyBean property pages (in development environments that support property page capability) and the SymbologyBean can be set to link or contain the symbology. When linking, the SymbologyBean reads the server style files whenever the SymbologyBean is created on the container. When containing, the SymbologyBean copies the contents of the server style file into the SymbologyBean. Containing increases the size of the application's executable containing the SymbologyBean.
Alternatively, server style files can be loaded into the SymbologyBean programmatically using the LoadStyleFile method, and removed using the RemoveFile method. See the following code example:
[Java]
aSymbologyBean.loadStyleFile( / apps / ArcGIS / Styles / ESRI.ServerStyle ");
SymbologyStyleClass
The SymbologyBean displays the contents of one SymbologyStyleClass at any time. Use the SetStyleClass method to set the current SymbologyStyleClass and the GetStyleClass method to return a specific SymbologyStyleClass.
The ISymbologyStyleClass interface has properties and methods for managing each ServerStyleGalleryItem in a SymbologyStyleClass. Individual items can be removed, selected, and previewed using the RemoveItem, SelectItem and PreviewItem methods. Custom symbology can be added using the AddItem method. See the following code example:
[Java]
IStyleGalleryItem serverStyleGalleryItem = aSymbologyBean.getStyleClass2
(aSymbologyBean.getStyleClass()).getSelectedItem();
System.out.println(serverStyleGalleryItem.getName());
When the contents of a server style file is loaded into the SymbologyBean with the LoadStyleFile method, items are demand loaded to the end of a SymbologyStyleClass item collection. This is done to increase performance, which indicates items are only loaded into a SymbologyStyleClass when it is the current SetStyleClass. To increase the speed that items display themselves in the SymbologyBean, the Update method can be used to force items to be loaded into a SymbologyStyleClass, when it is not the current SetStyleClass .