Class LineMeter

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Runnable, Accessible

public class LineMeter extends JPanel implements Runnable
LineMeter is a history-graph panel which updates its display once a second, drawing a curve of the history of inputs to setAmplitude(). It resizes to preserve the proportions given in the graph, and will record enough data to display across the entire screen.

there are a few artifacts in the drawing routine, namely, that setting the update rate to smaller than the animation rate will cause the background graph to update oddly.

See Also:
  • Field Details

    • serialVersionUID

      private static final long serialVersionUID
      Use serialVersionUID for interoperability.
      See Also:
    • animationFrame

      private int animationFrame
      DOCUMENT ME!
    • animationThread

      private volatile Thread animationThread
      monitor animation happens in its own thread.
    • aniSampleRate

      private int aniSampleRate
      DOCUMENT ME!
    • chartWidth

      private int chartWidth
      DOCUMENT ME!
    • chartHeight

      private int chartHeight
      DOCUMENT ME!
    • chartXend

      private int chartXend
      DOCUMENT ME!
    • chartYend

      private int chartYend
      DOCUMENT ME!
    • chartXstart

      private int chartXstart
      DOCUMENT ME!
    • chartYstart

      private int chartYstart
      DOCUMENT ME!
    • counterLock

      private boolean counterLock
      DOCUMENT ME!
    • countSinceLastUpdate

      private int countSinceLastUpdate
      DOCUMENT ME!
    • dim

      private Dimension dim
      DOCUMENT ME!
    • drawingWidth

      private int drawingWidth
      DOCUMENT ME!
    • drawingHeight

      private int drawingHeight
      DOCUMENT ME!
    • g2d

      private Graphics2D g2d
      DOCUMENT ME!
    • insets

      private Insets insets
      DOCUMENT ME!
    • lineColor

      private Color lineColor
      DOCUMENT ME!
    • lineSpacing

      private int lineSpacing
      DOCUMENT ME!
    • numberOfDivisions

      private int numberOfDivisions
      DOCUMENT ME!
    • numberOfSamplesDisplayed

      private int numberOfSamplesDisplayed
      DOCUMENT ME!
    • numberOfSamplesPerDivision

      private int numberOfSamplesPerDivision
      DOCUMENT ME!
    • panelWidth

      private int panelWidth
      DOCUMENT ME!
    • panelHeight

      private int panelHeight
      DOCUMENT ME!
    • paperColor

      private Color paperColor
      DOCUMENT ME!
    • penColor

      private Color penColor
      DOCUMENT ME!
    • pixelsWidePerSample

      private int pixelsWidePerSample
      DOCUMENT ME!
    • recentSamples

      private float[] recentSamples
      DOCUMENT ME!
    • sampleRate

      private int sampleRate
      DOCUMENT ME!
    • samplesPerUpdate

      private int samplesPerUpdate
      DOCUMENT ME!
    • whitespaceH

      private int whitespaceH
      DOCUMENT ME!
    • whitespaceW

      private int whitespaceW
      DOCUMENT ME!
    • yLocHistory

      private float[] yLocHistory
      DOCUMENT ME!
  • Constructor Details

    • LineMeter

      public LineMeter()
      This is the history graph, and sets up and animation thread. The history will be large enough to display samples across the entire screen-size
  • Method Details

    • flushRecentSamples

      public final void flushRecentSamples()
      removes the samples from the buffer and transfers them to the history buffer, and resets the recent history to capture new samples.
    • getMaximumSize

      public Dimension getMaximumSize()
      returns the panels maximum size.
      Overrides:
      getMaximumSize in class JComponent
      Returns:
      DOCUMENT ME!
    • getMinimumSize

      public Dimension getMinimumSize()
      returns the displays minimum size.
      Overrides:
      getMinimumSize in class JComponent
      Returns:
      DOCUMENT ME!
    • getPreferredSize

      public Dimension getPreferredSize()
      returns the panels preferred size.
      Overrides:
      getPreferredSize in class JComponent
      Returns:
      DOCUMENT ME!
    • paintComponent

      public void paintComponent(Graphics g)
      repaints the history graph.
      Overrides:
      paintComponent in class JComponent
      Parameters:
      g - DOCUMENT ME!
    • run

      public void run()
      when the thread wakes up, if the panel is showing, it will repaint panel, scrolling the graph.
      Specified by:
      run in interface Runnable
    • setAmplitude

      public void setAmplitude(float amp)
      Sets the most recent point on the history buffer.
      Parameters:
      amp - -- floating point value between (and including) 0 and 1, which represents the y-coordinate on the graph. It is then adjusted to be drawn based on display size.
    • setLineChartColor

      public void setLineChartColor(Color c)
      applies the given color to bars which are "lit" and are up to the set amplitude.
      Parameters:
      c - DOCUMENT ME!
    • setPaperColor

      public void setPaperColor(Color c)
      applies the given color to the background. Thre same as setBackground()
      Parameters:
      c - DOCUMENT ME!
    • setPenColor

      public void setPenColor(Color c)
      applies the given color to bars which are not lit and are above the set amplitude.
      Parameters:
      c - DOCUMENT ME!
    • setSampleRate

      public void setSampleRate(int samRate)
      adjusts the number of samples to be sent to the history in milliseconds. This allows for a recent buffer for samples not yet displayed. Changes to the sample rate will flush the current set of updates to the history buffer.
      Parameters:
      samRate - -- number of milliseconds per sample.
    • start

      public void start()
      sets the animation/redraw thread up, then runs it.
    • stop

      public void stop()
      shuts the animation thread off.