Package Layout

Class PamAxis

java.lang.Object
Layout.PamAxis
Direct Known Subclasses:
ClassifierHistoryTimeAxis, RepeatedAxis

public class PamAxis extends Object

Draws an axis on a Java Component.

PamAxis contains all the information needed to draw an axis, the actual drawing is generally called from the paintComponent function in the containing window.

for a good example, see PamAxisPanel which will automaticall draw four axis around a central plot.

Author:
Doug Gillespie
See Also:
  • Field Details Link icon

  • Constructor Details Link icon

    • PamAxis Link icon

      public PamAxis(int x1, int y1, int x2, int y2, double minVal, double maxVal, int tickPosition, String label, int labelPos, String format)
      Parameters:
      x1 - first x coordinate of axis
      y1 - first y coordinate of axis
      x2 - second x coordinate of axis
      y2 - second coordinate of axis
      minVal - minimum axis value
      maxVal - maximum axis value
      tickPosition - tick position (ABOVE_LEFT or BELOW_RIGHT)
      label - text for label (or null if no label)
      labelPos - Position of axis label (LABEL_NEAR_MAX, LABEL_NEAR_MIN or LABEL_NEAR_CENTRE)
      format - format for numbers printed on the display. This must be a standard format String such as "%d", "%f", "%3.1f", "%.2 seconds", etc.
    • PamAxis Link icon

      public PamAxis(int x1, int y1, int x2, int y2, double minVal, double maxVal, boolean aboveLeft, String label, String format)
      Parameters:
      x1 - x1
      y1 - y1
      x2 - x2
      y2 - y2
      minVal - min axis value
      maxVal - max axis value
      aboveLeft - above and / or to the left
      label - axis label
      format - format of numbers
  • Method Details Link icon

    • setPosition Link icon

      public void setPosition(int x1, int y1, int x2, int y2)
      Set the axis default coordinates
      Parameters:
      x1 -
      y1 -
      x2 -
      y2 -
    • setInterval Link icon

      public void setInterval(double interval)
      Set the interval between ticks. This is by default set to INTERVAL_AUTO whereby an interval is chosen so that there is a tick mark approximately every 100 pixels.
      Parameters:
      interval - the interval or INTERVAL_AUTO
    • setRange Link icon

      public void setRange(double minVal, double maxVal)
      Set the minimum and maximum values for the axis.
      Parameters:
      minVal -
      maxVal -
    • drawAxis Link icon

      public void drawAxis(Graphics g, int x1, int y1, int x2, int y2)
      Draw the axis in the graphics context g at the given position
      Parameters:
      g -
      x1 -
      y1 -
      x2 -
      y2 -
    • drawAxis Link icon

      public void drawAxis(Graphics g)
      Draw the axis in the Graphics Context g
      Parameters:
      g - graphics context to draw on
    • getAxisPoints Link icon

      public ArrayList<Point> getAxisPoints(boolean extraOne)
      Work out the coordinates of all tick marks.
      Parameters:
      extraOne -
      Returns:
      list of axis points.
    • drawGrid Link icon

      public void drawGrid(Graphics g, Dimension plotSize, int minorGrid)
      Draw a grid to go with the axis. Generally, the graphics handle for grid drawing will be some inner window sitting inside the window containing the axis.
      Parameters:
      g - Graphics context to draw on
      plotSize - size of the graphic
      minorGrid - draw a minor grid as well as lines at the main tick marks.
    • drawGrid Link icon

      public void drawGrid(Graphics g, Dimension plotSize, Insets insets, int minorGrid)
    • getExtent2 Link icon

      public int getExtent2(Graphics g)
      Gets the dimension of the axis perpendicular to the direction of the tickmark - i.e. for a vertical axis, it's half the text height, for a horizontal axis it's half the typical string width.
      Parameters:
      g - graphics handle for component the axis is to be draw on
      Returns:
      axis extent in pixels
    • getExtent2 Link icon

      public int getExtent2(Graphics g, String typicalString)
      Gets the dimension of the axis perpendicular to the direction of the tickmark - i.e. for a vertical axis, it's half the text height, for a horizontal axis it's half the typical string width.
      Parameters:
      g - graphics handle for component the axis is to be draw on
      typicalString - typical text string.
      Returns:
      Axis extent
    • getExtent Link icon

      public int getExtent(Graphics g)
      Gets the dimension of the axis parallel to the direction of the tickmark - i.e. the ticklength + the text height + the label height.
      Parameters:
      g - graphics handle for component the axis is to be draw on
      Returns:
      axis extent in pixels
    • getExtent Link icon

      public int getExtent(Graphics g, String typicalString)
      Gets the dimension of the axis parallel to the direction of the tickmark - i.e. the ticklength + the text height + the label height.
      Parameters:
      g - graphics handle the axis is being draw on
      typicalString - typical label string for a tick
      Returns:
      axisextent in pixels
    • isLogScale Link icon

      public boolean isLogScale()
    • setLogScale Link icon

      public void setLogScale(boolean logScale)
    • isDrawLine Link icon

      public boolean isDrawLine()
    • setDrawLine Link icon

      public void setDrawLine(boolean drawLine)
    • getFormat Link icon

      public String getFormat()
    • setFormat Link icon

      public void setFormat(String format)
      Set the format string for writing out numbers on the axis.
      Parameters:
      format - format string
    • setAutoFormat Link icon

      public void setAutoFormat(boolean isInteger)
      Automatically set the format of axis labels based on the types of numbers in there.
    • getAutoFormat Link icon

      public String getAutoFormat(boolean isInteger)
    • getAutoFormat Link icon

      public static String getAutoFormat(double minVal, double maxVal, boolean isInteger)
    • getNumDecPlaces Link icon

      public static int getNumDecPlaces(double value)
    • isIntegerFormat Link icon

      public boolean isIntegerFormat()
    • getLabel Link icon

      public String getLabel()
    • setLabel Link icon

      public void setLabel(String label)
    • getLabelPos Link icon

      public int getLabelPos()
    • setLabelPos Link icon

      public void setLabelPos(int labelPos)
    • getTickPosition Link icon

      public int getTickPosition()
    • setTickPosition Link icon

      public void setTickPosition(int tickPosition)
    • getMaxVal Link icon

      public double getMaxVal()
    • setMaxVal Link icon

      public void setMaxVal(double maxVal)
    • getMinVal Link icon

      public double getMinVal()
    • setMinVal Link icon

      public void setMinVal(double minVal)
    • getAutoLabelFormat Link icon

      public String getAutoLabelFormat()
      Work out the optimal format for the axis labels based on analysis of previously used axis labels.
      Returns:
      some kind of sensible format string !
    • getDefaultScaleEnd Link icon

      public static double getDefaultScaleEnd(double val, double otherVal)
    • setForceFirstVal Link icon

      public void setForceFirstVal(boolean forceFirstVal, double forcedFirstVal)
    • isLogTenthsScale Link icon

      public boolean isLogTenthsScale()
    • setLogTenthsScale Link icon

      public void setLogTenthsScale(boolean logTenthsScale)
    • getAxisValues Link icon

      public ArrayList<Double> getAxisValues()
    • getX1 Link icon

      public int getX1()
    • setX1 Link icon

      public void setX1(int x1)
    • getX2 Link icon

      public int getX2()
    • setX2 Link icon

      public void setX2(int x2)
    • getY1 Link icon

      public int getY1()
    • setY1 Link icon

      public void setY1(int y1)
    • getY2 Link icon

      public int getY2()
    • setY2 Link icon

      public void setY2(int y2)
    • getPosition Link icon

      public double getPosition(double dataValue)
      Get a distance along the axis within the bounds of the axis, i.e. generally within an inner panel drawn to the same bounds as the axis.

      The axis knows all about scale and can tell us the pixel value for any given data value.

      Parameters:
      dataValue -
      Returns:
      position in pixels along the axis for a given data value.
    • getOuterPosition Link icon

      public double getOuterPosition(double dataValue)
      To get a position in the context that the axis is drawn in, not the inner window relative to the axis. The axis knows all about scale and can tell us the pixel value for any given data value.
      Parameters:
      dataValue -
      Returns:
      position in pixels along the axis for a given data value.
    • getDataValue Link icon

      public double getDataValue(double position)
      Converts a position on the plot into a data value based on the axis max, min and scale.

      This is the exact compliment of getPosition()

      Parameters:
      position - position along the axis in pixels.
      Returns:
      data value.
    • isAllowScaleMultiples Link icon

      public boolean isAllowScaleMultiples()
    • setAllowScaleMultiples Link icon

      public void setAllowScaleMultiples(boolean allowScaleMultiples)
    • setAngleScales Link icon

      public void setAngleScales(boolean angleScales)
      Easy way to make scales end at 45, 90, 180, etc and step in sensible 45, 90, etc. steps.
      Parameters:
      angleScales -
    • isFractionalScale Link icon

      public boolean isFractionalScale()
    • setFractionalScale Link icon

      public void setFractionalScale(boolean fractionalScale)
    • getExtraAxisStartLabel Link icon

      public String getExtraAxisStartLabel()
      Returns:
      the extraAxStartLabel
    • setExtraAxisStartLabel Link icon

      public void setExtraAxisStartLabel(String extraAxStartLabel)
      Parameters:
      extraAxStartLabel - the extraAxStartLabel to set
    • getExtraAxisEndLabel Link icon

      public String getExtraAxisEndLabel()
      Returns:
      the extraAxisEndLabel
    • setExtraAxisEndLabel Link icon

      public void setExtraAxisEndLabel(String extraAxisEndLabel)
      Parameters:
      extraAxisEndLabel - the extraAxisEndLabel to set
    • isCrampLabels Link icon

      public boolean isCrampLabels()
      Cramped labels means that when drawing an axis, the end labels will be shifted to remain within the bounds of the axis itself.
      Returns:
      the crampLables
    • setCrampLabels Link icon

      public void setCrampLabels(boolean crampLabels)
      Cramped labels means that when drawing an axis, the end labels will be shifted to remain within the bounds of the axis itself.
      Parameters:
      crampLabels - the crampLables to set
    • overrideAxisColour Link icon

      public void overrideAxisColour(Color color)
      Overrides the standard axis color;
      Parameters:
      color - - null if default colour.