gov.nasa.worldwind.render.ScreenAnnotation Java Examples

The following examples show how to use gov.nasa.worldwind.render.ScreenAnnotation. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WWJPanel.java    From openvisualtraceroute with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Highlight the given annotation
 *
 * @param annotation
 * @param point
 */
private void highlightAnnotation(final LabeledPath label, final GeoPoint point) {
	final ScreenAnnotation annotation = label.getAnnotation();
	if (_lastSelection != null) {
		final LabeledPath lastSelectedLabel = _lastSelection.getLeft();
		final ScreenAnnotation lastSelectedAnnotation = lastSelectedLabel.getAnnotation();
		final GeoPoint lastSelectedPoint = _lastSelection.getRight();
		if (_mapShowLabel) {
			lastSelectedAnnotation.setAttributes(createAnnotationAttr(false, lastSelectedPoint.getCountryFlag(IMAGE_RESOLUTION), getText(lastSelectedPoint)));
			lastSelectedAnnotation.setAlwaysOnTop(false);
		} else {
			_renderableLayer.removeRenderable(lastSelectedLabel);
		}
	}
	final ImageIcon image = point.getCountryFlag(IMAGE_RESOLUTION);
	final String text = getText(point);
	annotation.setAttributes(createAnnotationAttr(true, image, text));
	annotation.setAlwaysOnTop(true);
	if (!_mapShowLabel) {
		_renderableLayer.addRenderable(label);
		_controller.redraw();
	}
	_lastSelection = Pair.of(label, point);
}
 
Example #2
Source File: ViewControlsSelectListener.java    From hortonmachine with GNU General Public License v3.0 6 votes vote down vote up
protected Angle computePanAmount(Globe globe, OrbitView view, ScreenAnnotation control, double panStep)
{
    // Compute last pick point distance relative to pan control center
    double size = control.getAttributes().getSize().width * control.getAttributes().getScale();
    Vec4 center = new Vec4(control.getScreenPoint().x, control.getScreenPoint().y + size / 2, 0);
    double px = lastPickPoint.x - center.x;
    double py = view.getViewport().getHeight() - lastPickPoint.y - center.y;
    double pickDistance = Math.sqrt(px * px + py * py);
    double pickDistanceFactor = Math.min(pickDistance / 10, 5);

    // Compute globe angular distance depending on eye altitude
    Position eyePos = view.getEyePosition();
    double radius = globe.getRadiusAt(eyePos);
    double minValue = 0.5 * (180.0 / (Math.PI * radius)); // Minimum change ~0.5 meters
    double maxValue = 1.0; // Maximum change ~1 degree

    // Compute an interpolated value between minValue and maxValue, using (eye altitude)/(globe radius) as
    // the interpolant. Interpolation is performed on an exponential curve, to keep the value from
    // increasing too quickly as eye altitude increases.
    double a = eyePos.getElevation() / radius;
    a = (a < 0 ? 0 : (a > 1 ? 1 : a));
    double expBase = 2.0; // Exponential curve parameter.
    double value = minValue + (maxValue - minValue) * ((Math.pow(expBase, a) - 1.0) / (expBase - 1.0));

    return Angle.fromDegrees(value * pickDistanceFactor * panStep);
}
 
Example #3
Source File: ViewControlsLayer.java    From hortonmachine with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Specifies the control to highlight. Any currently highlighted control is un-highlighted.
 *
 * @param control the control to highlight.
 */
public void highlight(Object control)
{
    // Manage highlighting of controls.
    if (this.currentControl == control)
        return; // same thing selected

    // Turn off highlight if on.
    if (this.currentControl != null)
    {
        this.currentControl.getAttributes().setImageOpacity(-1); // use default opacity
        this.currentControl = null;
    }

    // Turn on highlight if object selected.
    if (control != null && control instanceof ScreenAnnotation)
    {
        this.currentControl = (ScreenAnnotation) control;
        this.currentControl.getAttributes().setImageOpacity(1);
    }
}
 
Example #4
Source File: WWJPanel.java    From openvisualtraceroute with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Make screen annotation
 *
 * @param text text
 * @param image image
 * @return the annotation
 */
private ScreenAnnotation makeLabelAnnotation(final String text, final ImageIcon image) {
	final String normalizedText = text == null ? " " : text;
	final ScreenAnnotation screenAnnotation = new ScreenAnnotation(normalizedText, new Point());
	screenAnnotation.setAttributes(createAnnotationAttr(false, image, normalizedText));
	screenAnnotation.setPickEnabled(true);
	return screenAnnotation;
}
 
Example #5
Source File: ViewControlsSelectListener.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
protected Angle computePanHeading(OrbitView view, ScreenAnnotation control)
{
    // Compute last pick point 'heading' relative to pan control center
    double size = control.getAttributes().getSize().width * control.getAttributes().getScale();
    Vec4 center = new Vec4(control.getScreenPoint().x, control.getScreenPoint().y + size / 2, 0);
    double px = lastPickPoint.x - center.x;
    double py = view.getViewport().getHeight() - lastPickPoint.y - center.y;
    Angle heading = view.getHeading().add(Angle.fromRadians(Math.atan2(px, py)));
    heading = heading.degrees >= 0 ? heading : heading.addDegrees(360);
    return heading;
}
 
Example #6
Source File: ViewControlsSelectListener.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
protected Angle computeLookHeading(OrbitView view, ScreenAnnotation control, double headingStep)
{
    // Compute last pick point 'heading' relative to look control center on x
    double size = control.getAttributes().getSize().width * control.getAttributes().getScale();
    Vec4 center = new Vec4(control.getScreenPoint().x, control.getScreenPoint().y + size / 2, 0);
    double px = lastPickPoint.x - center.x;
    double pickDistanceFactor = Math.min(Math.abs(px) / 3000, 5) * Math.signum(px);
    // New heading
    Angle heading = view.getHeading().add(Angle.fromRadians(headingStep * pickDistanceFactor));
    heading = heading.degrees >= 0 ? heading : heading.addDegrees(360);
    return heading;
}
 
Example #7
Source File: ViewControlsSelectListener.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
protected Angle computeLookPitch(OrbitView view, ScreenAnnotation control, double pitchStep)
{
    // Compute last pick point 'pitch' relative to look control center on y
    double size = control.getAttributes().getSize().width * control.getAttributes().getScale();
    Vec4 center = new Vec4(control.getScreenPoint().x, control.getScreenPoint().y + size / 2, 0);
    double py = view.getViewport().getHeight() - lastPickPoint.y - center.y;
    double pickDistanceFactor = Math.min(Math.abs(py) / 3000, 5) * Math.signum(py);
    // New pitch
    Angle pitch = view.getPitch().add(Angle.fromRadians(pitchStep * pickDistanceFactor));
    pitch = pitch.degrees >= 0 ? (pitch.degrees <= 90 ? pitch : Angle.fromDegrees(90)) : Angle.ZERO;
    return pitch;
}
 
Example #8
Source File: ViewControlsLayer.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Get the control type associated with the given object or null if unknown.
 *
 * @param control the control object
 *
 * @return the control type. Can be one of {@link AVKey#VIEW_PAN}, {@link AVKey#VIEW_LOOK}, {@link
 *         AVKey#VIEW_HEADING_LEFT}, {@link AVKey#VIEW_HEADING_RIGHT}, {@link AVKey#VIEW_ZOOM_IN}, {@link
 *         AVKey#VIEW_ZOOM_OUT}, {@link AVKey#VIEW_PITCH_UP}, {@link AVKey#VIEW_PITCH_DOWN}, {@link
 *         AVKey#VIEW_FOV_NARROW} or {@link AVKey#VIEW_FOV_WIDE}. <p> Returns null if the object is not a view
 *         control associated with this layer. </p>
 */
public String getControlType(Object control)
{
    if (control == null || !(control instanceof ScreenAnnotation))
        return null;

    if (showPanControls && controlPan.equals(control))
        return AVKey.VIEW_PAN;
    else if (showLookControls && controlLook.equals(control))
        return AVKey.VIEW_LOOK;
    else if (showHeadingControls && controlHeadingLeft.equals(control))
        return AVKey.VIEW_HEADING_LEFT;
    else if (showHeadingControls && controlHeadingRight.equals(control))
        return AVKey.VIEW_HEADING_RIGHT;
    else if (showZoomControls && controlZoomIn.equals(control))
        return AVKey.VIEW_ZOOM_IN;
    else if (showZoomControls && controlZoomOut.equals(control))
        return AVKey.VIEW_ZOOM_OUT;
    else if (showPitchControls && controlPitchUp.equals(control))
        return AVKey.VIEW_PITCH_UP;
    else if (showPitchControls && controlPitchDown.equals(control))
        return AVKey.VIEW_PITCH_DOWN;
    else if (showFovControls && controlFovNarrow.equals(control))
        return AVKey.VIEW_FOV_NARROW;
    else if (showFovControls && controlFovWide.equals(control))
        return AVKey.VIEW_FOV_WIDE;
    else if (showVeControls && controlVeUp.equals(control))
        return AVKey.VERTICAL_EXAGGERATION_UP;
    else if (showVeControls && controlVeDown.equals(control))
        return AVKey.VERTICAL_EXAGGERATION_DOWN;

    return null;
}
 
Example #9
Source File: ViewControlsSelectListener.java    From hortonmachine with GNU General Public License v3.0 4 votes vote down vote up
public void selected(SelectEvent event)
{
    if (this.wwd == null)
        return;

    if (!(this.wwd.getView() instanceof OrbitView))
        return;

    OrbitView view = (OrbitView) this.wwd.getView();

    if (this.viewControlsLayer.getHighlightedObject() != null)
    {
        this.viewControlsLayer.highlight(null);
        this.wwd.redraw(); // must redraw so the de-highlight can take effect
    }

    if (event.getMouseEvent() != null && event.getMouseEvent().isConsumed())
        return;

    if (event.getTopObject() == null || event.getTopPickedObject().getParentLayer() != this.getParentLayer()
        || !(event.getTopObject() instanceof AVList))
        return;

    String controlType = ((AVList) event.getTopObject()).getStringValue(AVKey.VIEW_OPERATION);
    if (controlType == null)
        return;

    ScreenAnnotation selectedObject = (ScreenAnnotation) event.getTopObject();

    this.lastPickPoint = event.getPickPoint();
    if (event.getEventAction().equals(SelectEvent.ROLLOVER))
    {
        // Highlight on rollover
        this.viewControlsLayer.highlight(selectedObject);
        this.wwd.redraw();
    }
    if (event.getEventAction().equals(SelectEvent.DRAG))
    {
        // just consume drag events
        event.consume();
    }
    else if (event.getEventAction().equals(SelectEvent.HOVER))
    {
        // Highlight on hover
        this.viewControlsLayer.highlight(selectedObject);
        this.wwd.redraw();
    }
    else if (event.getEventAction().equals(SelectEvent.LEFT_PRESS) ||
        (event.getEventAction().equals(SelectEvent.DRAG) && controlType.equals(AVKey.VIEW_PAN)) ||
        (event.getEventAction().equals(SelectEvent.DRAG) && controlType.equals(AVKey.VIEW_LOOK)))
    {
        // Handle left press on controls
        this.pressedControl = selectedObject;
        this.pressedControlType = controlType;

        // Consume drag events, but do not consume left press events. It is not necessary to consume left press
        // events here, and doing so prevents the WorldWindow from gaining focus.
        if (event.getEventAction().equals(SelectEvent.DRAG))
            event.consume();
    }
    else if (event.getEventAction().equals(SelectEvent.LEFT_CLICK)
        || event.getEventAction().equals(SelectEvent.LEFT_DOUBLE_CLICK)
        || event.getEventAction().equals(SelectEvent.DRAG_END))
    {
        // Release pressed control

        if (pressedControl != null)
            event.consume();

        this.pressedControl = null;
        resetOrbitView(view);
        view.firePropertyChange(AVKey.VIEW, null, view);
    }

    // Keep pressed control highlighted - overrides rollover non currently pressed controls
    if (this.pressedControl != null)
    {
        this.viewControlsLayer.highlight(this.pressedControl);
        this.wwd.redraw();
    }
}
 
Example #10
Source File: LayerPanelLayer.java    From snap-desktop with GNU General Public License v3.0 4 votes vote down vote up
/**
 * <code>SelectListener</code> implementation.
 *
 * @param event the current <code>SelectEvent</code>
 */
@Override
public void selected(SelectEvent event) {
    //System.out.println("event.getEventAction(): " + event.getEventAction());

    final ScreenAnnotation annotation = getAnnotation();
    if (event.hasObjects() && event.getTopObject() == annotation) {
        boolean update = false;
        if (event.getEventAction().equals(SelectEvent.ROLLOVER)
                || event.getEventAction().equals(SelectEvent.LEFT_CLICK)) {
            // Highlight annotation
            if (!annotation.getAttributes().isHighlighted()) {
                annotation.getAttributes().setHighlighted(true);
                update = true;
            }
            // Check for text or url
            final PickedObject po = event.getTopPickedObject();
            if (po.getValue(AVKey.URL) != null) {
                // Set cursor hand on hyperlinks
                ((Component) this.wwd).setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
                int i = Integer.parseInt((String) po.getValue(AVKey.URL));
                // Select current hyperlink
                if (getSelectedIndex() != i) {
                    setSelectedIndex(i);
                    update = true;
                }
                // Enable/disable layer on left click
                if (event.getEventAction().equals(SelectEvent.LEFT_CLICK)) {
                    final LayerList layers = getValidLayers();
                    if (i >= 0 && i < layers.size()) {
                        final Layer layer = layers.get(i);
                        final boolean enable = !layer.isEnabled();
                        layer.setEnabled(enable);
                        updateVirtualEarthLayers(layer, enable);
                        update = true;
                    }
                }
            } else {
                // Unselect if not on an hyperlink
                if (getSelectedIndex() != -1) {
                    setSelectedIndex(-1);
                    update = true;
                }
                // Set cursor
                if (this.isComponentDragEnabled())
                    ((Component) this.wwd).setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
                else
                    ((Component) this.wwd).setCursor(Cursor.getDefaultCursor());
            }
        }
        if (event.getEventAction().equals(SelectEvent.DRAG)
                || event.getEventAction().equals(SelectEvent.DRAG_END)) {
            // Handle dragging
            if (this.isComponentDragEnabled() || this.isLayerDragEnabled()) {
                final boolean wasDraggingLayer = this.draggingLayer;
                this.drag(event);
                // Update list if dragging a layer, otherwise just redraw the world window
                if (this.draggingLayer || wasDraggingLayer)
                    update = true;
                else
                    this.wwd.redraw();
            }
        }
        // Redraw annotation if needed
        if (update)
            this.update();
    } else if (event.getEventAction().equals(SelectEvent.ROLLOVER) && annotation.getAttributes().isHighlighted()) {
        // de-highlight annotation
        annotation.getAttributes().setHighlighted(false);
        ((Component) this.wwd).setCursor(Cursor.getDefaultCursor());
        this.update();
    }
}