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

import com.esri.arcgis.beans.TOC.esriTOCControlEdit;<br />

2. In the buildAndShow() method, set the labelEdit to manual:<br />

. . .<br />

// Set label editing to manual.<br />

toc.setLabelEdit(esriTOCControlEdit.esriTOCControlManual);<br />

// Add popup menu items.<br />

. . .<br />

3. In the addEventListeners() method, add an event listener to the toc component<br />

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

ITOCControlEventsAdapter. After adding this, your addEventListeners()<br />

method should look like this:<br />

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

. . .<br />

toc.addITOCControlEventsListener(new ITOCControlEventsAdapter(){<br />

public void onEndLabelEdit(<br />

ITOCControlEventsOnEndLabelEditEvent labelEditEvt)<br />

throws IOException {<br />

String newLabel = labelEditEvt.getNewLabel();<br />

// If the new label is an empty string, prevent the edit.<br />

if (newLabel.equals(""))<br />

labelEditEvt.setCanEdit(false);<br />

}<br />

});<br />

}<br />

4. Run the application. To edit a map, layer, heading, or legend class label in the<br />

toc component, click it once, then click it a second time to invoke label<br />

editing. Try replacing the label with an empty string. You will be able to replace<br />

the label with strings other than an empty string. You can use the Esc<br />

key on the keyboard at any time during the edit to cancel it.<br />

316 • <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!