Class LineMeter

  • All Implemented Interfaces:
    java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, java.lang.Runnable, javax.accessibility.Accessible

    public class LineMeter
    extends javax.swing.JPanel
    implements java.lang.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:
    Serialized Form
    • Nested Class Summary

      • Nested classes/interfaces inherited from class javax.swing.JPanel

        javax.swing.JPanel.AccessibleJPanel
      • Nested classes/interfaces inherited from class javax.swing.JComponent

        javax.swing.JComponent.AccessibleJComponent
      • Nested classes/interfaces inherited from class java.awt.Container

        java.awt.Container.AccessibleAWTContainer
      • Nested classes/interfaces inherited from class java.awt.Component

        java.awt.Component.AccessibleAWTComponent, java.awt.Component.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
    • Constructor Summary

      Constructors 
      Constructor Description
      LineMeter()
      This is the history graph, and sets up and animation thread.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void flushRecentSamples()
      removes the samples from the buffer and transfers them to the history buffer, and resets the recent history to capture new samples.
      java.awt.Dimension getMaximumSize()
      returns the panels maximum size.
      java.awt.Dimension getMinimumSize()
      returns the displays minimum size.
      java.awt.Dimension getPreferredSize()
      returns the panels preferred size.
      void paintComponent​(java.awt.Graphics g)
      repaints the history graph.
      void run()
      when the thread wakes up, if the panel is showing, it will repaint panel, scrolling the graph.
      void setAmplitude​(float amp)
      Sets the most recent point on the history buffer.
      void setLineChartColor​(java.awt.Color c)
      applies the given color to bars which are "lit" and are up to the set amplitude.
      void setPaperColor​(java.awt.Color c)
      applies the given color to the background.
      void setPenColor​(java.awt.Color c)
      applies the given color to bars which are not lit and are above the set amplitude.
      void setSampleRate​(int samRate)
      adjusts the number of samples to be sent to the history in milliseconds.
      void start()
      sets the animation/redraw thread up, then runs it.
      void stop()
      shuts the animation thread off.
      • Methods inherited from class javax.swing.JPanel

        getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
      • Methods inherited from class javax.swing.JComponent

        addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getNextFocusableComponent, getPopupLocation, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
      • Methods inherited from class java.awt.Container

        add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate, validateTree
      • Methods inherited from class java.awt.Component

        action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • serialVersionUID

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

        private int animationFrame
        DOCUMENT ME!
      • animationThread

        private volatile java.lang.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 java.awt.Dimension dim
        DOCUMENT ME!
      • drawingWidth

        private int drawingWidth
        DOCUMENT ME!
      • drawingHeight

        private int drawingHeight
        DOCUMENT ME!
      • g2d

        private java.awt.Graphics2D g2d
        DOCUMENT ME!
      • insets

        private java.awt.Insets insets
        DOCUMENT ME!
      • lineColor

        private java.awt.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 java.awt.Color paperColor
        DOCUMENT ME!
      • penColor

        private java.awt.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 Detail

      • 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 Detail

      • 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 java.awt.Dimension getMaximumSize()
        returns the panels maximum size.
        Overrides:
        getMaximumSize in class javax.swing.JComponent
        Returns:
        DOCUMENT ME!
      • getMinimumSize

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

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

        public void paintComponent​(java.awt.Graphics g)
        repaints the history graph.
        Overrides:
        paintComponent in class javax.swing.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 java.lang.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​(java.awt.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​(java.awt.Color c)
        applies the given color to the background. Thre same as setBackground()
        Parameters:
        c - DOCUMENT ME!
      • setPenColor

        public void setPenColor​(java.awt.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.