Class ScreenRelativeAnnotation

  • All Implemented Interfaces:
    AVList, Disposable, Annotation, Renderable, Restorable

    public class ScreenRelativeAnnotation
    extends ScreenAnnotation
    Provides a screen annotation positioned relatively to the window rather than absolutely. The annotation's position is specified as fractional locations along the window's X and Y axes. When the window is resized the annotation is repositioned according to its relative coordinates.

    The annotation can be forced to remain fully visible even if its relative position would place a portion of it outside the window. X and Y margins can be specified to ensure distance between the annotation's edges and the window edges.

    • Constructor Detail

      • ScreenRelativeAnnotation

        public ScreenRelativeAnnotation​(java.lang.String text,
                                        double xFraction,
                                        double yFraction)
        Create an annotation with spedified text and relative position.
        Parameters:
        text - the text to display in the annotation.
        xFraction - the relative X position of the annotation. A value of 0 indicates the window's left edge, a value of 1 indicates its right edge. The annotation is centered horizontally on this position prior to applying any X offest specified in the annotation's attributes.
        yFraction - the relative Y position of the annotation. A value of 0 indicates the window's bottom edge, a value of 1 indicates the window's top edge. The annotation's lower edge is justified to this position prior to applying any Y offset specified in the annotation's attributes.
        Throws:
        java.lang.IllegalArgumentException - if the text string is null.
    • Method Detail

      • isKeepFullyVisible

        public boolean isKeepFullyVisible()
        Indicates whether the annotation is kept fully visible in the window.
        Returns:
        true if annotation is kept fully visible, otherwise false.
      • setKeepFullyVisible

        public void setKeepFullyVisible​(boolean keepFullyVisible)
        Specifies whether to adjust the annotation's position so that it is always fully visible when the window has sufficient area to display it, even if it would be fully or partially obscured when placed according to its relative coordinates.
        Parameters:
        keepFullyVisible - true to keep the annotation fully visible, otherwise false.
      • getXFraction

        public double getXFraction()
        Returns the annotation's relative X position.
        Returns:
        the annotation's relative X position, as specified to the constructor or setXFraction(double).
      • setXFraction

        public void setXFraction​(double xFraction)
        Specifies the annotation's relative X position. A value of 0 indicates the window's left edge, a value of 1 indicates its right edge.
        Parameters:
        xFraction - the annotation's relative X position.
      • getYFraction

        public double getYFraction()
        Returns the annotation's relative Y position.
        Returns:
        the annotation's relative Y position, as specified to the constructor or setYFraction(double).
      • setYFraction

        public void setYFraction​(double yFraction)
        Specifies the annotation's relative Y position. A value of 0 indicates the window's lower edge, a value of 1 indicates its top edge.
        Parameters:
        yFraction - the annotation's relative Y position.
      • getXMargin

        public int getXMargin()
        Returns the annotation's X margin.
        Returns:
        the annotation's X margin, in pixels.
      • setXMargin

        public void setXMargin​(int xMargin)
        Specifies the annotation's X margin, the minimum distance to maintain between the annotation's leading and trailing edges and the respective window edge. Used only when the keepFullyVisible flag is true.
        Parameters:
        xMargin - the X margin, in pixels.
      • getYMargin

        public int getYMargin()
        Returns the annotation's Y margin.
        Returns:
        the annotation's Y margin, in pixels.
      • setYMargin

        public void setYMargin​(int yMargin)
        Specifies the annotation's Y margin, the minimum distance to maintain between the annotation's top and bottom edges and the respective window edge. Used only when the keepFullyVisible flag is true.
        Parameters:
        yMargin - the Y margin, in pixels.
      • getScreenPoint

        protected java.awt.Point getScreenPoint​(DrawContext dc)
        Computes and returns the screen point in pixels corresponding to the annotation's relative position coordinates and the current window size.
        Overrides:
        getScreenPoint in class ScreenAnnotation
        Parameters:
        dc - the current draw context.
        Returns:
        the pixel coordinates corresponding to the annotation's relative coordinates. The pixel coordinate origin is the lower left of the window.
      • getRestorableState

        public java.lang.String getRestorableState()
        Returns an XML state document String describing the public attributes of this ScreenAnnotation.
        Specified by:
        getRestorableState in interface Restorable
        Overrides:
        getRestorableState in class ScreenAnnotation
        Returns:
        XML state document string describing this ScreenAnnotation.
      • restoreState

        public void restoreState​(java.lang.String stateInXml)
        Restores publicly settable attribute values found in the specified XML state document String. The document specified by stateInXml must be a well formed XML document String, or this will throw an IllegalArgumentException. Unknown structures in stateInXml are benign, because they will simply be ignored.
        Specified by:
        restoreState in interface Restorable
        Overrides:
        restoreState in class ScreenAnnotation
        Parameters:
        stateInXml - an XML document String describing a ScreenAnnotation.
        Throws:
        java.lang.IllegalArgumentException - If stateInXml is null, or if stateInXml is not a well formed XML document String.