// manages change of attributes for highlighting, annotation bubble toggle, event firing private void internalHighlight(SurfaceShape shape, boolean noDeselect) { if (!highlightingEnabled) { return; } String shpId = (String) shape.getValue(AVKey.HOVER_TEXT); // if annotation visible and same shape if (shape.equals(prevPopupShape) && shape.isHighlighted()) { if (!noDeselect) { // hide annotation and de-highlight popupAnnotation.getAttributes().setVisible(false); shape.setHighlighted(false); // forget previous highlighted shape and fire deselection event prevPopupShape = null; firePropertyChange(new PropertyChangeEvent(this, PROPERTY_SELECTION, shpId, null)); } } else { if (showAnnotation) { // find shape centroid final Sector boundingSector = Sector.boundingSector(shape.getLocations(wwd.getModel().getGlobe())); Position centroid = new Position(boundingSector.getCentroid(), 0d); // prepare and show annotation popupAnnotation.setText(shpId); popupAnnotation.setPosition(centroid); popupAnnotation.getAttributes().setVisible(true); } // highlight shape shape.setHighlighted(true); if (prevPopupShape != null) { // de-highlight previous shape and fire deselection event prevPopupShape.setHighlighted(false); firePropertyChange( new PropertyChangeEvent( this, PROPERTY_SELECTION, prevPopupShape.getValue(AVKey.HOVER_TEXT), shpId)); } else { // fire event only firePropertyChange(new PropertyChangeEvent(this, PROPERTY_SELECTION, null, shpId)); } // remember shape prevPopupShape = shape; } }
/** * Implementation of WorldWind selection API. * * @param event selection event */ @Override public void selected(SelectEvent event) { // short circuit exit if highlighting is not enabled if (!highlightingEnabled) { return; } if (event.getEventAction().equals(highlightEvent)) { final Object topObject = event.getTopObject(); if (topObject instanceof SurfaceShape) { SurfaceShape shape = (SurfaceShape) topObject; final Object layer = shape.getValue(AVKey.LAYER); if (layer instanceof SurfShapesLayer) { SurfShapesLayer sl = (SurfShapesLayer) layer; if (sl.getName().equals(getName())) { internalHighlight(shape, false); } wwd.redraw(); } } } }