Class Anchor

  • Direct Known Subclasses:
    Anchor.HorizontalAnchor

    public abstract class Anchor
    extends java.lang.Object
    Positioning constraint for plotted text. An anchor takes care of text alignment and positioning given a reference point.
    Since:
    12 Feb 2013
    Author:
    Mark Taylor
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  Anchor.HorizontalAnchor
      Anchor for drawing horizontal text.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static Anchor C
      Center - reference point is the center of the text.
      static Anchor E
      East - reference point is to right of horizontal text.
      static Anchor N
      North - reference point is above centre of horizontal text.
      static Anchor S
      South - reference point is below center of horizontal text.
      static Anchor W
      West - reference point is to left of horizontal text.
    • Constructor Summary

      Constructors 
      Constructor Description
      Anchor()  
    • Field Detail

      • N

        public static Anchor N
        North - reference point is above centre of horizontal text.
      • E

        public static Anchor E
        East - reference point is to right of horizontal text.
      • W

        public static Anchor W
        West - reference point is to left of horizontal text.
      • S

        public static Anchor S
        South - reference point is below center of horizontal text.
      • C

        public static Anchor C
        Center - reference point is the center of the text.
    • Constructor Detail

      • Anchor

        public Anchor()
    • Method Detail

      • getCaptionBounds

        public abstract java.awt.Rectangle getCaptionBounds​(Caption label,
                                                            int px,
                                                            int py,
                                                            Captioner captioner)
        Returns a rectangle within which all of the given label will fall.
        Parameters:
        label - text
        px - reference point X position
        py - reference point Y position
        captioner - object that can turn text into graphics
        Returns:
        plotted text bounding box
      • drawCaption

        public abstract void drawCaption​(Caption label,
                                         int px,
                                         int py,
                                         Captioner captioner,
                                         java.awt.Graphics g)
        Draws a text label onto a given graphics context.
        Parameters:
        label - text
        px - reference point X position
        py - reference point Y position
        captioner - object that can turn text into graphics
        g - graphics context
      • createAngledAnchor

        public static Anchor createAngledAnchor​(double theta,
                                                Anchor baseAnchor)
        Returns a new anchor for drawing text at a non-horizontal angle.
        Parameters:
        theta - rotation angle anticlockwise from X axis in radians
        baseAnchor - anchor supplying positioning constraints for horizontal text
        Returns:
        new anchor