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.

JAVA APPLICATION PROGRAMMING INTERFACE<br />

The following code uses an anonymous inner class with the<br />

IARControlEventsAdapter to add event listeners for onDocumentLoaded and<br />

onDocumentUnloaded events to the arControl object:<br />

arControl = new ARControl();<br />

...<br />

/*wire up the events for arControl*/<br />

arControl.addIARControlEventsListener(new IARControlEventsAdapter(){<br />

public void onDocumentLoaded(IARControlEventsOnDocumentLoadedEvent evt)<br />

throws IOException{<br />

/*set the statusbar text to point to the currently loaded document*/<br />

java.awt.EventQueue.invokeLater(<br />

new Runnable() {<br />

public void run() {<br />

statusLabel.setText(<br />

" Document filename: "+ arControl.getDocumentFilename());<br />

}<br />

}<br />

);<br />

}<br />

public void onDocumentUnloaded(<br />

IARControlEventsOnDocumentUnloadedEvent evt) throws IOException{<br />

/*set the statusbar text to empty string*/<br />

java.awt.EventQueue.invokeLater(<br />

new Runnable() {<br />

public void run() {<br />

statusLabel.setText("");<br />

}<br />

}<br />

);<br />

}<br />

});<br />

It is worthwhile to note that the events fired by the beans are custom events for<br />

which the listeners are provided as part of the <strong>ArcGIS</strong> API for Java. Adding<br />

listeners from the java.awt.event package, such as MouseListener, to the beans will<br />

not be helpful as the JavaBeans do not fire those events. Instead, you could use<br />

similar events, such as onMouseDown, onMouseUp, and onMouseMove, provided by<br />

the corresponding event listener, which in the case of ARControl is<br />

IARControlEvents.<br />

In addition, these custom events are not fired from within Java’s event dispatch<br />

thread. Whenever you wish to change the state of a pure Java GUI component<br />

from within one of these events, be sure to do so via java.awt.EventQueue’s<br />

invokeLater method. On the other hand, the <strong>ArcGIS</strong> components do not run in<br />

Java’s event dispatch thread. Because of this, you can change their state directly<br />

from within any of the custom <strong>ArcGIS</strong> events. For example, you could call<br />

Map.refresh from within an ITransformEventsListener without using invokeLater.<br />

196 • <strong>ArcGIS</strong> <strong>Engine</strong> <strong>Developer</strong> <strong>Guide</strong>

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

Saved successfully!

Ooh no, something went wrong!