Package hec.gfx2d

Class Gfx2dDrawUtil

java.lang.Object
hec.gfx2d.Gfx2dDrawUtil

public class Gfx2dDrawUtil extends Object
This is a static class which implements drawing routines that draw clipped Line Segments and PolyLines. These routines have been adopted from the Visual Basic code written by Mark Jensen @ the Hydrologic Engineering Center
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static int
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    computeVisibleSymbols(int[] xpoints, int[] ypoints, int numPts, boolean autoSkip, int offset, int skip, float sSize, boolean[] visibleSymbols)
     
    static void
    drawConformingString(Graphics g, int[] xarray, int[] yarray, int numPoints, String str, int labelAlign, int labelPosition, double coord, int baseoffset, Font font, Color color, int bank, float priority)
    This is a public method that draws a string label that conforms to a given line.
    static void
    drawPoints(Graphics g, int[] xpoints, int[] ypoints, int numPts, boolean[] showPoints, int symbolType, Color sLineColor, Color sFillColor, float sSize, boolean autoSkip, int offset, int skip)
    Draws the visible points along a line.
    static void
    drawPoints(Graphics g, int[] xpoints, int[] ypoints, int numPts, boolean[] showPoints, int symbolType, Color sLineColor, Color sFillColor, float sSize, boolean autoSkip, int offset, int skip, int symbolThickness)
     
    static void
    drawString(JComponent c, Graphics g, String text, int x, int y)
    Draws the string at the specified location.
    static void
    drawString(JComponent c, Graphics g, String text, int x, int y, int rotate)
     
    static void
    fillPolygonClipped(Graphics g, Rectangle rect, int[] xpoints, int[] ypoints, int numPts)
    This method draws a polygon into a region bounded by a given rectangle.
    static void
    fillPolygonClipped(Graphics g, Rectangle rect, int[] xpoints, int[] ypoints, int numPts, int fillType)
    This method draws a polygon into a region bounded by a given rectangle.
    static void
    fillPolygonClipped(Graphics g, Rectangle rect, int[] xpoints, int[] ypoints, int numPts, Paint fillPaint)
     
    static void
    plotClippedLine(Graphics g, Rectangle rect, int x1, int y1, int x2, int y2)
    This method draws a line segment to a region bounded by a given rectangle.
    static void
    plotPolyLineClipped(Graphics g, Rectangle rect, int[] xpoints, int[] ypoints, int numPts)
    This method draws a poly line into a region bounded by a given rectangle.
    static void
    plotPolyLineClipped(Graphics g, Rectangle rect, int[] xpoints, int[] ypoints, int numPts, boolean showPts)
    This method draws a poly line into a region bounded by a given rectangle.
    static void
    plotPolyLineClipped(Graphics g, Rectangle rect, int[] xpoints, int[] ypoints, int numPts, boolean showLine, boolean showPts)
    This method draws a poly line into a region bounded by a given rectangle.
    static void
    plotPolyLineClipped(Graphics g, Rectangle rect, int[] xpoints, int[] ypoints, int numPts, boolean showLine, Color lineColor, float lineWidth, boolean showPts, int symbolType, float symbolSize, Color sFillColor, Color sLineColor)
    This method draws a poly line into a region bounded by a given rectangle.
    static void
    plotPolyLineClipped(Graphics g, Rectangle rect, int[] xpoints, int[] ypoints, int numPts, boolean showLine, Color lineColor, float lineWidth, boolean showPts, int symbolType, float symbolSize, Color sFillColor, Color sLineColor, boolean autoSkip, int offset, int skip, boolean drawLabel, String label, int labelAlign, int labelPosition, Font labelFont, Color labelColor)
    This method draws a poly line into a region bounded by a given rectangle.
    static void
    plotPolyLineClipped(Graphics g, Rectangle rect, int[] xpoints, int[] ypoints, int numPts, boolean showLine, Color lineColor, float lineWidth, boolean showPts, int symbolType, float symbolSize, Color sFillColor, Color sLineColor, int offset, int skip)
    This method draws a poly line into a region bounded by a given rectangle.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • DEVICE_RESOLUTION

      public static int DEVICE_RESOLUTION
  • Constructor Details

    • Gfx2dDrawUtil

      public Gfx2dDrawUtil()
  • Method Details

    • plotClippedLine

      public static void plotClippedLine(Graphics g, Rectangle rect, int x1, int y1, int x2, int y2)
      This method draws a line segment to a region bounded by a given rectangle. If the line is too large for the rectangle, the line is clipped i.e. only the visible part is drawn. If the line segment occurs outside the rectangle it is ignored.
      Parameters:
      g - - the graphics context to draw to.
      rect - - the bounding box of the drawing area
      x1 - - the x coordinate of the begining of the line
      y1 - - the y coordinate of the begining of the line
      x2 - - the x coordinate of the end of the line
      y2 - - the y coordinate of the end of the line
    • plotPolyLineClipped

      public static void plotPolyLineClipped(Graphics g, Rectangle rect, int[] xpoints, int[] ypoints, int numPts)
      This method draws a poly line into a region bounded by a given rectangle. All points on the line that lie outside the rectangle are clipped off. If the entire poly line occurs outside the rectange then it is ignored
      Parameters:
      g - - the graphics context to draw to
      rect - - the bounding box of the drawing area
      xpoints - - the array of x-coordinates for the poly line
      ypoints - - tha array of y-coordinates for the poly line
      numPts - - the number of coordinates to draw
    • plotPolyLineClipped

      public static void plotPolyLineClipped(Graphics g, Rectangle rect, int[] xpoints, int[] ypoints, int numPts, boolean showPts)
      This method draws a poly line into a region bounded by a given rectangle. All points on the line that lie outside the rectangle are clipped off. If the entire poly line occurs outside the rectange then it is ignored
      Parameters:
      g - - the graphics context to draw to
      rect - - the bounding box of the drawing area
      xpoints - - the array of x-coordinates for the poly line
      ypoints - - tha array of y-coordinates for the poly line
      numPts - - the number of coordinates to draw
      showPts - - if true, plots the data points
    • plotPolyLineClipped

      public static void plotPolyLineClipped(Graphics g, Rectangle rect, int[] xpoints, int[] ypoints, int numPts, boolean showLine, boolean showPts)
      This method draws a poly line into a region bounded by a given rectangle. All points on the line that lie outside the rectangle are clipped off. If the entire poly line occurs outside the rectange then it is ignored
      Parameters:
      g - - the graphics context to draw to
      rect - - the bounding box of the drawing area
      xpoints - - the array of x-coordinates for the poly line
      ypoints - - tha array of y-coordinates for the poly line
      numPts - - the number of coordinates to draw
      showLine - - if true, plots the line
      showPts - - if true, plots the data points
    • plotPolyLineClipped

      public static void plotPolyLineClipped(Graphics g, Rectangle rect, int[] xpoints, int[] ypoints, int numPts, boolean showLine, Color lineColor, float lineWidth, boolean showPts, int symbolType, float symbolSize, Color sFillColor, Color sLineColor)
      This method draws a poly line into a region bounded by a given rectangle. All points on the line that lie outside the rectangle are clipped off. If the entire poly line occurs outside the rectange then it is ignored
      Parameters:
      g - - the graphics context to draw to
      rect - - the bounding box of the drawing area
      xpoints - - the array of x-coordinates for the poly line
      ypoints - - tha array of y-coordinates for the poly line
      numPts - - the number of coordinates to draw
      showLine -
      lineColor - - the color to draw the line, if null, uses the default color of blue.
      showPts - - if true, plots the data points
      lineWidth -
      symbolType - - the type of symbol to draw if showPts is true. Use constant defined in hec.gfx2d.Symbol
      sFillColor - - the fill Color for the symbol. If null, uses default color of blue.
      sLineColor - - the line Color for the symbol. If null, uses default color of blue.
      symbolSize -
    • plotPolyLineClipped

      public static void plotPolyLineClipped(Graphics g, Rectangle rect, int[] xpoints, int[] ypoints, int numPts, boolean showLine, Color lineColor, float lineWidth, boolean showPts, int symbolType, float symbolSize, Color sFillColor, Color sLineColor, int offset, int skip)
      This method draws a poly line into a region bounded by a given rectangle. All points on the line that lie outside the rectangle are clipped off. If the entire poly line occurs outside the rectange then it is ignored
      Parameters:
      g - - the graphics context to draw to
      rect - - the bounding box of the drawing area
      xpoints - - the array of x-coordinates for the poly line
      ypoints - - tha array of y-coordinates for the poly line
      numPts - - the number of coordinates to draw
      showLine -
      lineColor - - the color to draw the line, if null, uses the default color of blue.
      lineWidth -
      showPts - - if true, plots the data points
      symbolType - - the type of symbol to draw if showPts is true. Use constant defined in hec.gfx2d.Symbol
      symbolSize -
      sFillColor - - the fill Color for the symbol. If null, uses default color of blue.
      sLineColor - - the line Color for the symbol. If null, uses default color of blue.
      offset - - the number of points from the start of data to skip
      skip - - the number of points to skip, 0 skip none, 1 - skip every other point, etc
    • plotPolyLineClipped

      public static void plotPolyLineClipped(Graphics g, Rectangle rect, int[] xpoints, int[] ypoints, int numPts, boolean showLine, Color lineColor, float lineWidth, boolean showPts, int symbolType, float symbolSize, Color sFillColor, Color sLineColor, boolean autoSkip, int offset, int skip, boolean drawLabel, String label, int labelAlign, int labelPosition, Font labelFont, Color labelColor)
      This method draws a poly line into a region bounded by a given rectangle. All points on the line that lie outside the rectangle are clipped off. If the entire poly line occurs outside the rectange then it is ignored
      Parameters:
      g - - the graphics context to draw to
      rect - - the bounding box of the drawing area
      xpoints - - the array of x-coordinates for the poly line
      ypoints - - tha array of y-coordinates for the poly line
      numPts - - the number of coordinates to draw
      lineColor - - the color to draw the line, if null, uses the default color of blue.
      showPts - - if true, plots the data points
      symbolType - - the type of symbol to draw if showPts is true. Use constant defined in hec.gfx2d.Symbol
      sFillColor - - the fill Color for the symbol. If null, uses default color of blue.
      sLineColor - - the line Color for the symbol. If null, uses default color of blue.
      autoSkip - - this is true if this method should draw points so they do not overlap. if true the offset and skip values are ignored.
      offset - - the number of points from the start of data to skip
      skip - - the number of points to skip, 0 skip none, 1 - skip every other point, etc
      drawLabel - - if true, draws a label based on the label and label position properties
      label - - the label to draw.
      labelFont - - the font to draw the label with
      labelColor - - the color used to draw the label
    • drawPoints

      public static void drawPoints(Graphics g, int[] xpoints, int[] ypoints, int numPts, boolean[] showPoints, int symbolType, Color sLineColor, Color sFillColor, float sSize, boolean autoSkip, int offset, int skip)
      Draws the visible points along a line.
      Parameters:
      g - - the graphics context to draw to
      xpoints - - the list of visible xpoints
      ypoints - - the list of visible ypoints
      numPts - - the number of visible points
      showPoints - - an array of booleans saying if a particular point is drawn, true to draw false to skip
      symbolType - - the symbol type to use. @see hec.gfx2d.Symbol
      sLineColor - - the symbol line color
      sFillColor - - the symbol fill color
      sSize - - the size of the symbol to use.
      autoSkip - - this is true if this method should draw points so they do not overlap. if true the offset and skip values are ignored.
      offset - - the number of points from the start of data to skip
      skip - - the number of points to skip, 0 skip none, 1 - skip every other point, etc
    • drawPoints

      public static void drawPoints(Graphics g, int[] xpoints, int[] ypoints, int numPts, boolean[] showPoints, int symbolType, Color sLineColor, Color sFillColor, float sSize, boolean autoSkip, int offset, int skip, int symbolThickness)
    • fillPolygonClipped

      public static void fillPolygonClipped(Graphics g, Rectangle rect, int[] xpoints, int[] ypoints, int numPts)
      This method draws a polygon into a region bounded by a given rectangle. All points on the polygon that lie outside the rectangle are clipped off. If the entire polygon occurs outside the rectange then it is ignored. The polygon is filled solid.
      Parameters:
      g - - the graphics context to draw to
      rect - - the bounding box of the drawing area
      xpoints - - the array of x-coordinates for the poly line
      ypoints - - tha array of y-coordinates for the poly line
      numPts - - the number of coordinates to draw
    • fillPolygonClipped

      public static void fillPolygonClipped(Graphics g, Rectangle rect, int[] xpoints, int[] ypoints, int numPts, int fillType)
      This method draws a polygon into a region bounded by a given rectangle. All points on the polygon that lie outside the rectangle are clipped off. If the entire polygon occurs outside the rectange then it is ignored
      Parameters:
      g - - the graphics context to draw to
      rect - - the bounding box of the drawing area
      xpoints - - the array of x-coordinates for the poly line
      ypoints - - tha array of y-coordinates for the poly line
      numPts - - the number of coordinates to draw
      fillType - - the fill type to use, SOLID, DIAGONAL, CROSS, etc
    • fillPolygonClipped

      public static void fillPolygonClipped(Graphics g, Rectangle rect, int[] xpoints, int[] ypoints, int numPts, Paint fillPaint)
    • drawConformingString

      public static void drawConformingString(Graphics g, int[] xarray, int[] yarray, int numPoints, String str, int labelAlign, int labelPosition, double coord, int baseoffset, Font font, Color color, int bank, float priority)
      This is a public method that draws a string label that conforms to a given line. In other words the string trys to match the curve of the line.
      Parameters:
      g - the graphics context to draw the string to
      xarray - the list of x-coordinates points in pixels
      yarray - the list of y-coordinates of the line in pixels
      numPoints - the number of points contained in the xarray/yarray
      str - the string to draw
      labelAlign - Marks the position of the label on the line either G2dLineProperties.LABEL_ALIGN_RIGHT/LABEL_ALIGN_LEFT
      labelPosition -
      coord -
      baseoffset -
      font - the font to use when drawing the string
      color - the color of the string
      bank -
      priority -
    • computeVisibleSymbols

      public static void computeVisibleSymbols(int[] xpoints, int[] ypoints, int numPts, boolean autoSkip, int offset, int skip, float sSize, boolean[] visibleSymbols)
    • drawString

      public static void drawString(JComponent c, Graphics g, String text, int x, int y)
      Draws the string at the specified location.
      Parameters:
      c - JComponent that will display the string, may be null
      g - Graphics to draw the text to
      text - String to display
      x - X coordinate to draw the text at
      y - Y coordinate to draw the text at
    • drawString

      public static void drawString(JComponent c, Graphics g, String text, int x, int y, int rotate)