Class ShapePortrayal2D

All Implemented Interfaces:
Serializable, Portrayal, Portrayal2D
Direct Known Subclasses:
HexagonalPortrayal2D

public class ShapePortrayal2D extends AbstractShapePortrayal2D
A simple portrayal for 2D visualization of java.awt.Shapes and java.awt.Polygons. It extends the SimplePortrayal2D and it manages the drawing and hit-testing for shapes. Various X and Y point arrays for constructing different default shapes are also provided.
See Also:
  • Field Details

    • shape

      public Shape shape
    • X_POINTS_TRIANGLE_DOWN

      public static final double[] X_POINTS_TRIANGLE_DOWN
    • Y_POINTS_TRIANGLE_DOWN

      public static final double[] Y_POINTS_TRIANGLE_DOWN
    • X_POINTS_TRIANGLE_UP

      public static final double[] X_POINTS_TRIANGLE_UP
    • Y_POINTS_TRIANGLE_UP

      public static final double[] Y_POINTS_TRIANGLE_UP
    • X_POINTS_TRIANGLE_RIGHT

      public static final double[] X_POINTS_TRIANGLE_RIGHT
    • Y_POINTS_TRIANGLE_RIGHT

      public static final double[] Y_POINTS_TRIANGLE_RIGHT
    • X_POINTS_TRIANGLE_LEFT

      public static final double[] X_POINTS_TRIANGLE_LEFT
    • Y_POINTS_TRIANGLE_LEFT

      public static final double[] Y_POINTS_TRIANGLE_LEFT
    • X_POINTS_POINTER_RIGHT

      public static final double[] X_POINTS_POINTER_RIGHT
    • Y_POINTS_POINTER_RIGHT

      public static final double[] Y_POINTS_POINTER_RIGHT
    • X_POINTS_POINTER_LEFT

      public static final double[] X_POINTS_POINTER_LEFT
    • Y_POINTS_POINTER_LEFT

      public static final double[] Y_POINTS_POINTER_LEFT
    • X_POINTS_POINTER_DOWN

      public static final double[] X_POINTS_POINTER_DOWN
    • Y_POINTS_POINTER_DOWN

      public static final double[] Y_POINTS_POINTER_DOWN
    • X_POINTS_POINTER_UP

      public static final double[] X_POINTS_POINTER_UP
    • Y_POINTS_POINTER_UP

      public static final double[] Y_POINTS_POINTER_UP
    • X_POINTS_DIAMOND

      public static final double[] X_POINTS_DIAMOND
    • Y_POINTS_DIAMOND

      public static final double[] Y_POINTS_DIAMOND
    • X_POINTS_SQUARE

      public static final double[] X_POINTS_SQUARE
    • Y_POINTS_SQUARE

      public static final double[] Y_POINTS_SQUARE
    • X_POINTS_BOWTIE

      public static final double[] X_POINTS_BOWTIE
    • Y_POINTS_BOWTIE

      public static final double[] Y_POINTS_BOWTIE
    • X_POINTS_HOURGLASS

      public static final double[] X_POINTS_HOURGLASS
    • Y_POINTS_HOURGLASS

      public static final double[] Y_POINTS_HOURGLASS
    • X_POINTS_COMPASS

      public static final double[] X_POINTS_COMPASS
    • Y_POINTS_COMPASS

      public static final double[] Y_POINTS_COMPASS
    • X_POINTS_STAR

      public static final double[] X_POINTS_STAR
    • Y_POINTS_STAR

      public static final double[] Y_POINTS_STAR
    • X_POINTS_PARALLELOGRAM

      public static final double[] X_POINTS_PARALLELOGRAM
    • Y_POINTS_PARALLELOGRAM

      public static final double[] Y_POINTS_PARALLELOGRAM
    • X_POINTS_OCTAGON

      public static final double[] X_POINTS_OCTAGON
    • Y_POINTS_OCTAGON

      public static final double[] Y_POINTS_OCTAGON
    • X_POINTS_HEXAGON

      public static final double[] X_POINTS_HEXAGON
    • Y_POINTS_HEXAGON

      public static final double[] Y_POINTS_HEXAGON
    • X_POINTS_HEXAGON_ROTATED

      public static final double[] X_POINTS_HEXAGON_ROTATED
    • Y_POINTS_HEXAGON_ROTATED

      public static final double[] Y_POINTS_HEXAGON_ROTATED
    • POLY_TRIANGLE_UP

      public static final int POLY_TRIANGLE_UP
      See Also:
    • POLY_TRIANGLE_DOWN

      public static final int POLY_TRIANGLE_DOWN
      See Also:
    • POLY_TRIANGLE_LEFT

      public static final int POLY_TRIANGLE_LEFT
      See Also:
    • POLY_TRIANGLE_RIGHT

      public static final int POLY_TRIANGLE_RIGHT
      See Also:
    • POLY_POINTER_UP

      public static final int POLY_POINTER_UP
      See Also:
    • POLY_POINTER_DOWN

      public static final int POLY_POINTER_DOWN
      See Also:
    • POLY_POINTER_LEFT

      public static final int POLY_POINTER_LEFT
      See Also:
    • POLY_POINTER_RIGHT

      public static final int POLY_POINTER_RIGHT
      See Also:
    • POLY_DIAMOND

      public static final int POLY_DIAMOND
      See Also:
    • POLY_SQUARE

      public static final int POLY_SQUARE
      See Also:
    • POLY_BOWTIE

      public static final int POLY_BOWTIE
      See Also:
    • POLY_HOURGLASS

      public static final int POLY_HOURGLASS
      See Also:
    • POLY_COMPASS

      public static final int POLY_COMPASS
      See Also:
    • POLY_STAR

      public static final int POLY_STAR
      See Also:
    • POLY_PARALLELOGRAM

      public static final int POLY_PARALLELOGRAM
      See Also:
    • POLY_OCTAGON

      public static final int POLY_OCTAGON
      See Also:
    • POLY_HEXAGON

      public static final int POLY_HEXAGON
      See Also:
    • POLY_HEXAGON_ROTATED

      public static final int POLY_HEXAGON_ROTATED
      See Also:
    • SHAPE_CIRCLE

      public static final Shape SHAPE_CIRCLE
    • SHAPE_ROUND_SQUARE

      public static final Shape SHAPE_ROUND_SQUARE
    • SHAPE_VERY_ROUND_SQUARE

      public static final Shape SHAPE_VERY_ROUND_SQUARE
    • SHAPE_DELAY

      public static final Area SHAPE_DELAY
    • SHAPE_REVERSE_DELAY

      public static final Area SHAPE_REVERSE_DELAY
    • SHAPE_CHOMP

      public static final Area SHAPE_CHOMP
    • SHAPE_PILL

      public static final Area SHAPE_PILL
    • SHAPE_STORAGE

      public static final Area SHAPE_STORAGE
  • Constructor Details

    • ShapePortrayal2D

      public ShapePortrayal2D(double[] xpoints, double[] ypoints)
    • ShapePortrayal2D

      public ShapePortrayal2D(double[] xpoints, double[] ypoints, Paint paint)
    • ShapePortrayal2D

      public ShapePortrayal2D(double[] xpoints, double[] ypoints, double scale)
    • ShapePortrayal2D

      public ShapePortrayal2D(double[] xpoints, double[] ypoints, Paint paint, double scale)
    • ShapePortrayal2D

      public ShapePortrayal2D(double[] xpoints, double[] ypoints, boolean filled)
    • ShapePortrayal2D

      public ShapePortrayal2D(double[] xpoints, double[] ypoints, Paint paint, boolean filled)
    • ShapePortrayal2D

      public ShapePortrayal2D(double[] xpoints, double[] ypoints, double scale, boolean filled)
    • ShapePortrayal2D

      public ShapePortrayal2D(double[] xpoints, double[] ypoints, Paint paint, double scale, boolean filled)
    • ShapePortrayal2D

      public ShapePortrayal2D(Shape shape)
    • ShapePortrayal2D

      public ShapePortrayal2D(Shape shape, Paint paint)
    • ShapePortrayal2D

      public ShapePortrayal2D(Shape shape, double scale)
    • ShapePortrayal2D

      public ShapePortrayal2D(Shape shape, Paint paint, double scale)
    • ShapePortrayal2D

      public ShapePortrayal2D(Shape shape, boolean filled)
    • ShapePortrayal2D

      public ShapePortrayal2D(Shape shape, Paint paint, boolean filled)
    • ShapePortrayal2D

      public ShapePortrayal2D(Shape shape, double scale, boolean filled)
    • ShapePortrayal2D

      public ShapePortrayal2D(Shape shape, Paint paint, double scale, boolean filled)
    • ShapePortrayal2D

      public ShapePortrayal2D(double[] xpoints, double[] ypoints, Paint fillPaint, Paint strokePaint, double strokeWidth, double scale)
      New-style constructors. Rather than having a "filled" flag which determines whether we stroke versus fill, we can do BOTH. We do this by specifying a fill paint and a stroke paint, either of which can be NULL. We also provide a stroke width and a scale.
    • ShapePortrayal2D

      public ShapePortrayal2D(double[] xpoints, double[] ypoints, Paint fillPaint, Paint strokePaint, Stroke stroke, double scale)
      New-style constructors. Rather than having a "filled" flag which determines whether we stroke versus fill, we can do BOTH. We do this by specifying a fill paint and a stroke paint, either of which can be NULL. We also provide a stroke and a scale.
    • ShapePortrayal2D

      public ShapePortrayal2D(int polygon, Paint fillPaint, Paint strokePaint, double strokeWidth, double scale)
      New-style constructors. Rather than having a "filled" flag which determines whether we stroke versus fill, we can do BOTH. We do this by specifying a fill paint and a stroke paint, either of which can be NULL. We also provide a stroke width and a scale.
    • ShapePortrayal2D

      public ShapePortrayal2D(int polygon, Paint fillPaint, Paint strokePaint, Stroke stroke, double scale)
      New-style constructors. Rather than having a "filled" flag which determines whether we stroke versus fill, we can do BOTH. We do this by specifying a fill paint and a stroke paint, either of which can be NULL. We also provide a stroke and a scale.
    • ShapePortrayal2D

      public ShapePortrayal2D(Shape shape, Paint fillPaint, Paint strokePaint, double strokeWidth, double scale)
      New-style constructors. Rather than having a "filled" flag which determines whether we stroke versus fill, we can do BOTH. We do this by specifying a fill paint and a stroke paint, either of which can be NULL. We also provide a stroke width and a scale.
    • ShapePortrayal2D

      public ShapePortrayal2D(Shape shape, Paint fillPaint, Paint strokePaint, Stroke stroke, double scale)
      New-style constructors. Rather than having a "filled" flag which determines whether we stroke versus fill, we can do BOTH. We do this by specifying a fill paint and a stroke paint, either of which can be NULL. We also provide a stroke and a scale.
  • Method Details

    • setShape

      public void setShape(Shape shape)
    • setShape

      public void setShape(double[] xpoints, double[] ypoints)
    • setStroke

      public void setStroke(Stroke s)
    • setStroke

      public void setStroke(double width)
    • draw

      public void draw(Object object, Graphics2D graphics, DrawInfo2D info)
      Description copied from interface: Portrayal2D
      Draw a the given object with an origin at (info.draw.x, info.draw.y), and with the coordinate system scaled by so that 1 unit is in the x and y directions are equal to info.draw.width and info.draw.height respectively in pixels. The rectangle given by info.clip specifies the only region in which it is necessary to draw. If info.precise is true, try to draw using real-valued high-resolution drawing rather than faster integer drawing. It is possible that object is null. The location of the object in the field may (and may not) be stored in info.location. The form of that location varies depending on the kind of field used.
      Specified by:
      draw in interface Portrayal2D
      Overrides:
      draw in class SimplePortrayal2D
    • hitObject

      public boolean hitObject(Object object, DrawInfo2D range)
      Description copied from class: SimplePortrayal2D
      Return true if the given object, when drawn, intersects with a provided rectangle, for hit testing purposes. The object is drawn with an origin at (info.draw.x, info.draw.y), and with the coordinate system scaled by so that 1 unit is in the x and y directions are equal to info.draw.width and info.draw.height respectively in pixels. The rectangle given by info.clip specifies the region to do hit testing in; often this region is actually of 0 width or height, which might represent a single point. It is possible that object is null. The location of the object in the field may (and may not) be stored in info.location. The form of that location varies depending on the kind of field used.
      Overrides:
      hitObject in class SimplePortrayal2D