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 />

8. Compile and run the application to confirm that the GUI has been laid out as<br />

shown:<br />

A standard Java layout manager (BorderLayout) has been used to position the<br />

components. It manages the layout and sizes of the components for you. You<br />

should be able to resize the window and see that the components get updated<br />

appropriately without requiring any explicit resizing code.<br />

Loading map documents<br />

1. Now that the components have been added, you can load map documents into<br />

the controls. To do this, add the following imports to MapViewerFrame.java:<br />

For cross-platform compatibility, the filenames<br />

and pathnames used to store data must be<br />

lowercased for Solaris and Linux.<br />

import com.esri.arcgis.beans.pagelayout.IPageLayoutControlEventsAdapter;<br />

import<br />

com.esri.arcgis.beans.pagelayout.IPageLayoutControlEventsOnPageLayoutReplacedEvent;<br />

2. Add the following code to the end of the buildAndShow method, just before<br />

the call to this.setVisible.<br />

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

. . .<br />

. . .<br />

addEventListeners();<br />

310 • <strong>ArcGIS</strong> <strong>Engine</strong> <strong>Developer</strong> <strong>Guide</strong><br />

// Load a preauthored map document into the PageLayout bean.<br />

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

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

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

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

this.setVisible(true);<br />

2. When the document is loaded into the pageLayout bean, an<br />

onPageLayoutReplaced event is generated. You will add code to load the same<br />

map document in the map component in response to this event. In the<br />

addEventListeners() method, add the event listener to the pageLayout component<br />

for the onPageLayoutReplaced event, as an anonymous inner class, using<br />

IPageLayoutControlEventsAdapter.

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

Saved successfully!

Ooh no, something went wrong!