public class BalloonController extends java.awt.event.MouseAdapter implements SelectListener
Balloon
and handle balloon events. The controller does the following: AbstractBrowserBalloon
identifies its controls by attaching a value to the
PickedObject's AVList under AVKey.ACTION. The controller reads this value and performs the appropriate action. The
possible actions are AVKey.RESIZE, AVKey.BACK, AVKey.FORWARD, and AVKey.CLOSE.Modifier and Type | Class and Description |
---|---|
protected class |
BalloonController.DocumentRetrievalTask
A TimerTask that will request a resource from the
FileStore until it becomes
available, or until a timeout is exceeded. |
Modifier and Type | Field and Description |
---|---|
protected Balloon |
balloon |
static java.lang.String |
BALLOON |
static java.lang.String |
BALLOON_FLY_TO |
protected int |
balloonOffset
Vertical offset, in pixels, between the balloon and the point that the leader shape points to.
|
static int |
DEFAULT_BALLOON_OFFSET |
static java.lang.String |
FLY_TO |
protected java.lang.Object |
lastSelectedObject |
protected BalloonResizeController |
resizeController
A resize controller is created when the mouse enters a resize control on the balloon.
|
protected long |
retrievalPollInterval
Interval between periodic checks for completion of asynchronous document retrieval (in milliseconds).
|
protected long |
retrievalTimeout
Timeout to use when requesting remote documents.
|
protected WorldWindow |
wwd |
Constructor and Description |
---|
BalloonController(WorldWindow wwd)
Create a new balloon controller.
|
Modifier and Type | Method and Description |
---|---|
protected void |
addDocumentLayer(KMLRoot document)
Adds the specified
document to this controller's WorldWindow as a new
Layer . |
protected void |
adjustPosition(Balloon balloon,
java.awt.Point screenPoint)
Adjust the position of a balloon so that the entire balloon is visible on screen.
|
boolean |
canShowBalloon(KMLAbstractFeature feature)
Determines whether or not a balloon must be created for a KML feature.
|
protected Position |
computeIntersection(AbstractShape shape,
java.awt.Point screenPoint)
Compute the intersection of a line through a screen point and a shape.
|
protected void |
configureBalloon(Balloon balloon,
KMLAbstractFeature feature)
Configure a new balloon for a KML feature.
|
protected Balloon |
createBalloon(KMLAbstractFeature feature)
Create a balloon for a KML feature and attach the balloon to the feature.
|
protected void |
createResizeController(Balloon balloon)
Create a resize controller and attach it to the WorldWindow.
|
protected void |
destroyResizeController(SelectEvent event)
Destroy the active resize controller.
|
protected void |
doFeatureLinkActivated(KMLAbstractFeature feature,
java.lang.String directive)
Handle activation of a KML feature link.
|
protected double |
findMaxAltitude(java.util.List<? extends Position> positions)
Get the maximum altitude in a list of positions.
|
protected KMLRoot |
findOpenKmlDocument(java.lang.String url)
Search for a KML document that has already been opened.
|
protected java.lang.String |
getAttachmentMode(KMLAbstractFeature feature)
Get the attachment mode of a KML feature:
AVKey.GLOBE or AVKey.SCREEN . |
protected Balloon |
getBalloon(PickedObject pickedObject)
Get the balloon attached to a PickedObject.
|
protected int |
getBalloonAltitudeMode(java.lang.Object balloonObject)
Get the appropriate altitude mode for a GlobeBalloon, depending on the object that has been selected.
|
int |
getBalloonOffset()
Indicates the vertical distance, in pixels, between the balloon and the point that the leader points to.
|
protected java.awt.Point |
getBalloonPoint(KMLAbstractFeature feature)
Get the screen point for a balloon for a KML feature attached to the screen.
|
protected java.awt.Point |
getBalloonPointForScreenOverlay(KMLScreenOverlay overlay)
Get the screen point for a balloon for a ScreenOverlay.
|
protected Position |
getBalloonPosition(KMLAbstractFeature feature)
Get the position of the balloon for a KML feature attached to the globe.
|
protected Position |
getBalloonPosition(java.util.List<? extends Position> positions)
Get the position of the balloon for a list of positions that bound a feature.
|
protected Position |
getBalloonPosition(java.lang.Object topObject,
java.awt.Point pickPoint)
Get the position of the balloon for a picked object with an attached balloon.
|
protected Position |
getBalloonPositionForGroundOverlay(KMLGroundOverlay overlay)
Get the position of the balloon for a KML GroundOverlay.
|
protected Position |
getBalloonPositionForPlacemark(KMLPlacemark placemark)
Get the position of the balloon for a KML placemark.
|
protected KMLAbstractFeature |
getContext(PickedObject pickedObject)
Get the KML feature that is the context of a picked object.
|
protected java.lang.String |
getUrl(PickedObject pickedObject)
Get the URL attached to a PickedObject.
|
protected void |
hideBalloon()
Hide the active balloon.
|
protected boolean |
isBalloonTrigger(java.awt.event.MouseEvent e)
Inspect a mouse event to see if it should make a balloon visible.
|
protected boolean |
isKmlUrl(java.lang.String url,
java.lang.String contentType)
Does a URL refer to a KML or KMZ document?
|
protected boolean |
isLinkActivationTrigger(SelectEvent event)
Determines if a SelectEvent is an event that activates a hyperlink.
|
protected boolean |
isResizeControl(PickedObject po) |
protected boolean |
isUseBrowserBalloon()
Indicates if the controller will create Balloons of type
AbstractBrowserBalloon . |
void |
mouseClicked(java.awt.event.MouseEvent e)
Handle a mouse click.
|
void |
mouseMoved(java.awt.event.MouseEvent e) |
protected void |
moveToFeature(KMLAbstractFeature feature)
Move the view to look at a KML feature.
|
protected boolean |
mustAdjustPosition(Balloon balloon)
Determines if a balloon position must be adjusted to make the balloon visible in the viewport.
|
protected void |
onBalloonAction(AbstractBrowserBalloon browserBalloon,
java.lang.String action)
Called when a
AbstractBrowserBalloon control is activated (Close, Back, or
Forward). |
protected void |
onDocumentFailed(java.lang.String url,
java.lang.Exception e)
Called when a KML file fails to load due to a network timeout or parsing error.
|
protected void |
onDocumentLoaded(java.lang.String url,
KMLRoot document,
java.lang.String featureRef)
Called when a KML document has been loaded.
|
protected boolean |
onFeatureLinkActivated(KMLRoot doc,
java.lang.String linkFragment,
SelectEvent event)
Called when a link to a KML feature is activated.
|
protected void |
onLinkActivated(SelectEvent event,
java.lang.String url)
Called when a URL in a balloon is activated.
|
protected void |
openInNewBrowser(SelectEvent event,
java.lang.String url)
Open a URL in a new web browser.
|
protected void |
requestDocument(java.lang.String url,
KMLRoot context,
java.lang.String featureRef)
Asynchronously load a KML document.
|
void |
selected(SelectEvent event) |
void |
setBalloonOffset(int balloonOffset)
Sets the vertical distance, in pixels, between the balloon and the point that the leader points to.
|
protected void |
showBalloon(Balloon balloon,
java.lang.Object balloonObject,
java.awt.Point point)
Show a balloon at a screen point.
|
protected void |
showBalloon(Balloon balloon,
Position position)
Show a balloon at a globe position.
|
void |
showBalloon(KMLAbstractFeature feature)
Show a balloon for a KML feature.
|
protected Balloon balloon
public static final java.lang.String BALLOON
public static final java.lang.String BALLOON_FLY_TO
protected int balloonOffset
public static final int DEFAULT_BALLOON_OFFSET
public static final java.lang.String FLY_TO
protected java.lang.Object lastSelectedObject
protected BalloonResizeController resizeController
protected long retrievalPollInterval
protected long retrievalTimeout
protected WorldWindow wwd
public BalloonController(WorldWindow wwd)
wwd
- WorldWindow to attach to.protected void addDocumentLayer(KMLRoot document)
document
to this controller's WorldWindow
as a new
Layer
.
This expects the kmlRoot
's AVKey.DISPLAY_NAME
field to contain a display name suitable
for use as a layer name.document
- the KML document to add a Layer
for.protected void adjustPosition(Balloon balloon, java.awt.Point screenPoint)
balloon
- Balloon to adjust the position of.screenPoint
- Screen point to which the balloon leader points.public boolean canShowBalloon(KMLAbstractFeature feature)
feature
- KML feature to test.true
if a balloon must be created for the feature. Otherwise false
.protected Position computeIntersection(AbstractShape shape, java.awt.Point screenPoint)
shape
- Shape with which to compute intersection.screenPoint
- Compute the intersection of a line through this screen point and the shape.null
if there is no intersection, or if the computation is
interrupted.protected void configureBalloon(Balloon balloon, KMLAbstractFeature feature)
balloon
- Balloon to configure.feature
- Feature that owns the Balloon.protected Balloon createBalloon(KMLAbstractFeature feature)
isUseBrowserBalloon()
. If the feature is attached to a point on
the globe, this method creates a GlobeBalloon
. If the feature is attached to the screen, a ScreenBalloon
is created. If isUseBrowserBalloon() returns true
, the balloon will be a descendant of
AbstractBrowserBalloon
. Otherwise it will be a descendant of AbstractAnnotationBalloon
.feature
- Feature to create balloon for.protected void createResizeController(Balloon balloon)
balloon
- Balloon to resize.protected void destroyResizeController(SelectEvent event)
event
- Event that triggered the controller to be destroyed.protected void doFeatureLinkActivated(KMLAbstractFeature feature, java.lang.String directive)
feature
- Feature to navigate to.directive
- Display directive, one of FLY_TO
, BALLOON
, or BALLOON_FLY_TO
.protected double findMaxAltitude(java.util.List<? extends Position> positions)
positions
- List of positions to search for max altitude.-Double.MAX_VALUE
if positions
is
empty.protected KMLRoot findOpenKmlDocument(java.lang.String url)
url
- URL of the KML document.protected java.lang.String getAttachmentMode(KMLAbstractFeature feature)
AVKey.GLOBE
or AVKey.SCREEN
. Some features, such as a
PointPlacemark, are attached to a point on the globe. Others, such as a ScreenImage, are attached to the screen.feature
- KML feature to test.AVKey.GLOBE
if the feature is attached to a geographic location. Otherwise AVKey.SCREEN
.
Container features (Document and Folder) are considered screen features.protected Balloon getBalloon(PickedObject pickedObject)
canShowBalloon
determines if
a balloon will be created for the feature.pickedObject
- PickedObject to inspect. May not be null.pickedObject
is null.protected int getBalloonAltitudeMode(java.lang.Object balloonObject)
PointPlacemark
, this implementation returns the altitude mode of the
placemark. Otherwise it returns WorldWind.ABSOLUTE
.balloonObject
- The object that the balloon is attached to.WorldWind.ABSOLUTE
, WorldWind.CLAMP_TO_GROUND
, or WorldWind.RELATIVE_TO_GROUND
.public int getBalloonOffset()
protected java.awt.Point getBalloonPoint(KMLAbstractFeature feature)
feature
- Feature for which to find a balloon point.getBalloonPointForScreenOverlay(gov.nasa.worldwind.ogc.kml.KMLScreenOverlay)
,
getBalloonPosition(gov.nasa.worldwind.ogc.kml.KMLAbstractFeature)
protected java.awt.Point getBalloonPointForScreenOverlay(KMLScreenOverlay overlay)
overlay
- ScreenOverlay for which to find a balloon position.getBalloonPoint(gov.nasa.worldwind.ogc.kml.KMLAbstractFeature)
protected Position getBalloonPosition(KMLAbstractFeature feature)
feature
- Feature to find balloon position for.getBalloonPositionForPlacemark(gov.nasa.worldwind.ogc.kml.KMLPlacemark)
,
getBalloonPositionForGroundOverlay(gov.nasa.worldwind.ogc.kml.KMLGroundOverlay)
,
getBalloonPoint(gov.nasa.worldwind.ogc.kml.KMLAbstractFeature)
protected Position getBalloonPosition(java.util.List<? extends Position> positions)
positions
- List of positions to find a balloon position.protected Position getBalloonPosition(java.lang.Object topObject, java.awt.Point pickPoint)
Locatable
, this method returns the position of the Locatable. If the object is an instance of AbstractShape
, the method performs an intersection calculation between a ray through the pick point and the
shape. If neither of the previous conditions are true, or if the object is null
, this method returns the
intersection position of a ray through the pick point and the globe.topObject
- Object that was picked. May be null
.pickPoint
- The point at which the mouse event occurred.null
if a position cannot be determined.protected Position getBalloonPositionForGroundOverlay(KMLGroundOverlay overlay)
overlay
- Ground overlay for which to find a balloon position.getBalloonPosition(gov.nasa.worldwind.ogc.kml.KMLAbstractFeature)
protected Position getBalloonPositionForPlacemark(KMLPlacemark placemark)
placemark
- Placemark for which to find a balloon position.getBalloonPosition(gov.nasa.worldwind.ogc.kml.KMLAbstractFeature)
protected KMLAbstractFeature getContext(PickedObject pickedObject)
AVKey.CONTEXT
.pickedObject
- PickedObject to inspect for context. May not be null.protected java.lang.String getUrl(PickedObject pickedObject)
AVKey.URL
.pickedObject
- PickedObject to inspect. May not be null.protected void hideBalloon()
protected boolean isBalloonTrigger(java.awt.event.MouseEvent e)
e
- Event to inspect.true
if the event is a balloon trigger. This implementation returns true
if the event is
a left click.protected boolean isKmlUrl(java.lang.String url, java.lang.String contentType)
url
- URL to test.contentType
- Mime type of the URL content. May be null.contentType
is the KML or KMZ mime type.protected boolean isLinkActivationTrigger(SelectEvent event)
event
- Event to test. May not be null.true
if the event actives hyperlinks. This implementation returns true
for left click
events.protected boolean isResizeControl(PickedObject po)
protected boolean isUseBrowserBalloon()
AbstractBrowserBalloon
. BrowserBalloons are used
on platforms that support them (currently Windows and Mac). AbstractAnnotationBalloon
is used on other
platforms.true
if the controller will create BrowserBalloons.public void mouseClicked(java.awt.event.MouseEvent e)
AVKey.BALLOON
.mouseClicked
in interface java.awt.event.MouseListener
mouseClicked
in class java.awt.event.MouseAdapter
e
- Mouse eventpublic void mouseMoved(java.awt.event.MouseEvent e)
mouseMoved
in interface java.awt.event.MouseMotionListener
mouseMoved
in class java.awt.event.MouseAdapter
protected void moveToFeature(KMLAbstractFeature feature)
feature
- Feature to look at.protected boolean mustAdjustPosition(Balloon balloon)
balloon
- Balloon to inspect.true
if the balloon position must be adjusted to make the balloon visible.protected void onBalloonAction(AbstractBrowserBalloon browserBalloon, java.lang.String action)
AbstractBrowserBalloon
control is activated (Close, Back, or
Forward).browserBalloon
- Balloon involved in action.action
- Identifier for the action that occurred.protected void onDocumentFailed(java.lang.String url, java.lang.Exception e)
url
- URL of the document that failed to load.e
- Exception that caused the failure.protected void onDocumentLoaded(java.lang.String url, KMLRoot document, java.lang.String featureRef)
url
- URL of the document that has been loaded.document
- Parsed document.featureRef
- Reference to a feature that must be activated (fly to or open balloon).protected boolean onFeatureLinkActivated(KMLRoot doc, java.lang.String linkFragment, SelectEvent event)
doc
- Document to search for the feature.linkFragment
- Reference to the feature. The fragment may contain a display directive. For example
"#myPlacemark", or "#myPlacemark;balloon".event
- The select event that activated the link. This event will be consumed if a KML feature is
found that matches the link fragment. However, the controller only moves to the feature or
opens a balloon if the event is a link activation event, or null. Other events are consumed
to prevent the balloon from handling events for a link that the controller wants handle. This
parameter may be null.protected void onLinkActivated(SelectEvent event, java.lang.String url)
event
- SelectEvent for the URL activation. If the event is a link activation trigger the controller will
take action on the event (by opening a KML document, etc). If the event is not a link activation
trigger, but the URL is a URL that the balloon controller would normally handle, the event is
consumed to prevent the balloon itself from trying to handle the event, but no further action is
taken.url
- URL that was activated.isLinkActivationTrigger(gov.nasa.worldwind.event.SelectEvent)
protected void openInNewBrowser(SelectEvent event, java.lang.String url)
event
- SelectEvent that triggered navigation. The event is consumed if URL can be parsed.url
- URL to open.protected void requestDocument(java.lang.String url, KMLRoot context, java.lang.String featureRef)
onDocumentLoaded
will be called on the Event Dispatch Thread (EDT).
If the document fails to load, onDocumentFailed
will be called.
Failure will be reported if the document does not load within retrievalTimeout
milliseconds.url
- URL of KML doc to open.context
- Context of the URL, used to resolve local references.featureRef
- A reference to a feature in the remote file to animate the globe to once the file is
available.onDocumentLoaded(String, gov.nasa.worldwind.ogc.kml.KMLRoot, String)
,
onDocumentFailed(String, Exception)
public void selected(SelectEvent event)
selected
in interface SelectListener
public void setBalloonOffset(int balloonOffset)
balloonOffset
- Vertical offset, in pixels.protected void showBalloon(Balloon balloon, java.lang.Object balloonObject, java.awt.Point point)
balloon
- Balloon to make visible.balloonObject
- The picked object that owns the balloon. May be null
.point
- Point where mouse was clicked.protected void showBalloon(Balloon balloon, Position position)
balloon
- Balloon to make visible.position
- Position on the globe to locate the balloon. If the balloon is attached to the screen, it will be
position at the screen point currently over this position.public void showBalloon(KMLAbstractFeature feature)
canShowBalloon
determines if a balloon will be created.feature
- KML feature for which to show a balloon.