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.

JAVA APPLICATION PROGRAMMING INTERFACE<br />

to update the status bar with the current map coordinates as the mouse moves<br />

over the control.<br />

public void updateStatusBar(<br />

IARControlEventsOnMouseMoveEvent params,<br />

IARControl arControl,<br />

JLabel statusLabel) throws IOException {<br />

/*<br />

* Create two single-dimension arrays of type double to serve as<br />

* "out" parameters in a call to toMapPoint.<br />

*/<br />

double[] dXcoord = {0.0};<br />

double[] dYcoord = {0.0};<br />

int screenX = params.getX();<br />

int screenY = params.getY();<br />

IARMap arMap = arControl.getARPageLayout().getFocusARMap();<br />

arMap.toMapPoint(screenX, screenY, dXcoord, dYcoord);<br />

statusLabel.setText("Map x,y: " + dXcoord[0] + ", " + dYcoord[0]);<br />

}<br />

The <strong>ArcGIS</strong> API for Java will not allow developers to populate an array with a<br />

superclass type, even when it has been cast to a superclass type. Consider the<br />

following Java example:<br />

Integer[] integers = { new Integer(0), new Integer(1), new Integer(2)};<br />

Object[] integersAsObjects = (Object[])integers;<br />

integersAsObjects[0] = new Object();<br />

The above is not allowed and will cause an ArrayStoreException. Consider the<br />

following ArcObjects example:<br />

Polyline[] polyline = {new Polyline()};<br />

tin.interpolateShape( breakline, polyline, null );<br />

Polyline firstPolyLine = polyline[0];<br />

The above is not allowed and will cause the same ArrayStoreException as the<br />

earlier example. Take a look at the interpolateShape method of ISurface and analyze<br />

what is going on here.<br />

public void interpolateShape(IGeometry pShape,<br />

IGeometry[] ppOutShape,<br />

Object pStepSize)<br />

throws IOException,<br />

AutomationException<br />

Parameters:<br />

pShape - A reference to a com.esri.arcgis.geometry.IGeometry (in)<br />

ppOutShape - A reference to a com.esri.arcgis.geometry.IGeometry<br />

(out: use single element array)<br />

pStepSize - A Variant (in, optional, pass null if not required)<br />

Throws:<br />

IOException - If there are communications problems.<br />

AutomationException - If the remote server throws an exception.<br />

IGeometry is a superinterface to IPolyline, and the Polyline class implements both<br />

interfaces. In the first attempt you tried to send a single element Polyline array into<br />

a method that requires an in/out IGeometry parameter. This causes an<br />

Chapter 4 • <strong>Developer</strong> environments • 193

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

Saved successfully!

Ooh no, something went wrong!