18.04.2015 Views

ArcGIS Engine Developer Guide

ArcGIS Engine Developer Guide

ArcGIS Engine Developer Guide

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

BUILDING APPLICATIONS WITH VISUAL JAVABEANS<br />

3. The onCreate method is passed a reference to the control that the command<br />

works with. In this case, it can be a MapBean, PageLayoutBean, or<br />

ToolbarBean. Rather than adding logic in the onCreate method to determine<br />

the type of object passed to the hook method, you will use the HookHelper<br />

class to handle this. A command or tool needs to know how to handle the<br />

hook it gets passed, so a check is needed to determine the type of <strong>ArcGIS</strong><br />

control that has been passed. The HookHelper is used to hold the hook and<br />

return the ActiveView regardless of the type of hook (in this case either a<br />

MapBean, PageLayoutBean, or ToolbarBean).<br />

Import the HookHelper class and add the hookHelper member variable to the<br />

AddDateCommand class:<br />

import com.esri.arcgis.systemUI.ITool;<br />

import com.esri.arcgis.controlcommands.HookHelper;<br />

public class AddDateCommand implements ICommand, ITool{<br />

HookHelper hookHelper;<br />

4. In the onCreate method, construct the hookhelper and use the setHookByRef<br />

method to pass the controls object.<br />

public void onCreate(Object obj) throws IOException, AutomationException<br />

{<br />

// To be added later. Delete this line.<br />

hookHelper = new HookHelper();<br />

hookHelper.setHookByRef( obj );<br />

}<br />

5. Add implementation for all methods defined in the ITool interface to the<br />

AddDateCommand class. Not all methods will be used, but they need to be<br />

implemented to be able to compile the class. In the following code, pay attention<br />

to the onMouseDown method, as this method creates a TextElement<br />

with the current date as its text and adds it to the graphics container of the<br />

hook object.<br />

/*<br />

* see com.esri.arcgis.systemUI.ITool#getCursor()<br />

*/<br />

public int getCursor() throws IOException, AutomationException {<br />

return 0;<br />

}<br />

/*<br />

* see com.esri.arcgis.systemUI.ITool#onMouseDown(int, int, int,<br />

int)<br />

*/<br />

public void onMouseDown(int button, int shift, int x, int y)<br />

throws IOException, AutomationException {<br />

Date today = new Date();<br />

// Format the date in the form "Wed 27 Aug, 2003".<br />

SimpleDateFormat formatter;<br />

formatter = new SimpleDateFormat("EEE d MMM, yyyy");<br />

Chapter 6 • <strong>Developer</strong> scenarios • 323

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!