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

4. In the buildandShow() method, call the createCustomizeDialog() method to<br />

instantiate the Customize dialog box. Also instantiate the customizeCB<br />

JCheckBox:<br />

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

JPanel mapTOCPanel = buildMapTOCPanel();<br />

createCustomizeDialog();<br />

customizeCB = new JCheckBox("Customize");<br />

5. In the addEventListeners method, add a listener to the customizeCB<br />

JCheckBox to start and close the Customize dialog box:<br />

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

...<br />

customizeCB.addActionListener(new ActionListener(){<br />

public void actionPerformed(ActionEvent e) {<br />

try {<br />

if (customizeCB.isSelected()) {<br />

customizeDialog.startDialog(toolbar.getHWnd());<br />

} else {<br />

customizeDialog.closeDialog();<br />

}<br />

} catch (Exception ee) {<br />

ee.printStackTrace();<br />

}<br />

}<br />

});<br />

...<br />

6. To add the Customize check box to the GUI, modify the buildAndShow<br />

method to add the toolbar and check box to a new JPanel. Add this panel to<br />

the BorderLayout.NORTH position instead of adding just the toolbar in that<br />

position.<br />

JPanel topPanel = new JPanel();<br />

topPanel.setLayout(new BorderLayout());<br />

topPanel.add(toolbar, BorderLayout.CENTER);<br />

topPanel.add(customizeCB, BorderLayout.EAST);<br />

this.getContentPane().add(topPanel, BorderLayout.NORTH);<br />

this.getContentPane().add(toolbar, BorderLayout.NORTH);//delete<br />

this line<br />

this.getContentPane().add(pageLayout, BorderLayout.CENTER);<br />

this.getContentPane().add(mapTOCPanel, BorderLayout.WEST);<br />

7. In the addEventListeners method, add an event listener to the Customize dialog<br />

box to put the toolbar in the customize state when the dialog box is started<br />

and in the normal state when it is closed. Since these events are not generated<br />

by Java’s event dispatching thread, modifications to the customizeCB check<br />

box should be made via the SwingUtilities class:<br />

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

...<br />

});<br />

customizeDialog.addICustomizeDialogEventsListener(new<br />

ICustomizeDialogEvents(){<br />

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

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

Saved successfully!

Ooh no, something went wrong!