18.04.2015 Views

ArcGIS Engine Developer Guide

ArcGIS Engine Developer Guide

ArcGIS Engine Developer Guide

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

BUILDING APPLICATIONS WITH VISUAL JAVABEANS<br />

public void addEventListeners() throws IOException {<br />

pageLayout.addIPageLayoutControlEventsListener(<br />

new IPageLayoutControlEventsAdapter() {<br />

public void onPageLayoutReplaced(<br />

IPageLayoutControlEventsOnPageLayoutReplacedEvent evt)<br />

throws IOException{<br />

map.loadMxFile(pageLayout.getDocumentFilename(), null, null);<br />

map.setExtent(map.getFullExtent());<br />

}<br />

});<br />

}<br />

Buddying up the ToolbarBean and TOCBean<br />

Although the components have been added to the JFrame, they do not yet ‘know<br />

about each other’. For the controls to work in sync with each other, the TOC and<br />

toolbar components should know the control with which they are associated.<br />

Otherwise, the toolbar component will not know which component it is ‘controlling’,<br />

and the TOC component will not know which component’s table of<br />

contents it should display.<br />

To set up this communication between the components, add the following code<br />

to the buildAndShow() method after the load document code.<br />

public void buildAndShow() throws IOException {<br />

. . .<br />

// Load a preauthored map document on the pageLayout component.<br />

String documentPath = new java.io.File(<br />

"../../data/gulf of st. lawrence.mxd").getAbsolutePath();<br />

if (pageLayout.checkMxFile(documentPath))<br />

pageLayout.loadMxFile(documentPath,null);<br />

// Set buddy controls to wire up the TOC and Toolbar Beans<br />

// with the PageLayout Bean.<br />

toc.setBuddyControl(pageLayout);<br />

toolbar.setBuddyControl(pageLayout);<br />

} this.setVisible(true);<br />

Adding commands to the toolbar<br />

The toolbar control has been added to the user interface. By default, this control<br />

is not populated with any tools. You will begin to add tools in the following<br />

steps.<br />

The <strong>ArcGIS</strong> <strong>Engine</strong> <strong>Developer</strong> Kit comes with more than 120 commands and<br />

tools that work with the MapBean, the PageLayoutBean, and the ToolbarBean.<br />

These commands and tools provide a lot of frequently used GIS functionality for<br />

map navigation, graphics management, and feature selection. You will now add<br />

some of these commands and tools to your application.<br />

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

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

Saved successfully!

Ooh no, something went wrong!