org.concord.util
Class BarGraph

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--javax.swing.JComponent
                    |
                    +--org.concord.util.BarGraph
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, ValueGraph

public class BarGraph
extends javax.swing.JComponent
implements ValueGraph

Bar graph component. This component in its default form provides a simple bar graph. Setting a value at a particular index will show a graphic bar at that height at that offset. This component is built out of an array of gauges, each of which has it's own set of properties.

In addition, there is a more complicated use of this component that involves remapping the index values used in the updateValue, setColor and getColor methods. Since each gauge also has indexed values and color, updating the values of the bar graph with a single index requires some special setup. This setup is done with index mapping. Using the addMapEntry method, the developer can specify that the graph index 'i' will reference sub-bar 'k' in gauge 'j'. This would be done by calling 'addMapEntry(i, j, k)'. In the absence of mapping for a paticular index, the gauge at that index will be treated as a simple, single bar.

See Also:
Serialized Form

Inner classes inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Inner classes inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Inner classes inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent
 
Field Summary
protected  java.awt.Color background
           
static int DEFAULT_GAUGE_WIDTH
           
static int DEFAULT_NUMBER_OF_GAUGES
           
protected  boolean editable
           
protected  Gauge[] gauges
           
protected  int gaugeWidth
           
protected  java.util.Vector indexMap
           
protected  int numberOfGauges
           
static java.util.Vector oldGauges
           
protected  java.awt.event.ComponentAdapter sizeChanged
           
protected  javax.swing.JSlider slider
           
protected  javax.swing.event.ChangeListener sliderChanged
           
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface org.concord.util.ValueGraph
colors
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
BarGraph()
          Bar graph constructor.
 
Method Summary
 void addMapEntry(int index, int i, int j)
          Add or replace an index map entry.
 void clearMap()
          Resets the index mapping.
 java.awt.Color getBackground()
           
 java.awt.Color getColor(int index)
          Returns color associated with a particular index.
 Gauge getGauge(int index)
          Returns the gauge component at a particular index.
 int getGaugeWidth()
          Gets value that determines pixel spaceing between gauges.
 double getMax()
           
 javax.swing.JSlider getSlider()
           
 double getValue()
           
 double getValue(int index)
          Get value of graph element at index.
 boolean isEditable()
          Returns editable state.
protected  double log10(double x)
           
static void main(java.lang.String[] args)
           
 void paintComponent(java.awt.Graphics g)
           
 void removeMapEntry(int index, int i, int j)
          Removes an index map for a particular index.
 void setBackground(java.awt.Color color)
           
protected  void setBarGraphSize(java.awt.Dimension size)
           
 void setColor(java.awt.Color color, int index)
          Sets the color associated with a particular index.
 void setEditable(boolean value)
          Make gauges editable.
 void setGaugeWidth(int width)
          Sets value that determines pixel spaceing between gauges.
 void setMax(double value)
           
 void setNumberOfGauges(int number)
          Sets the number of gauges in this graph.
 void setScaleMax(int scale)
           
 void setSlider(javax.swing.JSlider slider)
           
 void setSliderValue()
           
 void updateValue(double x)
           
 void updateValue(double x, int index)
          Updates graph element at index with new value.
 void updateValue(float x)
           
 void updateValue(float x, int index)
           
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getAccessibleContext, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getGraphics, getHeight, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getUIClassID, getVerifyInputWhenFocusTarget, getVisibleRect, getWidth, getX, getY, grabFocus, hasFocus, hide, isDoubleBuffered, isFocusCycleRoot, isFocusTraversable, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, paramString, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processFocusEvent, processKeyBinding, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBorder, setDebugGraphicsOptions, setDoubleBuffered, setEnabled, setFont, setForeground, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update, updateUI
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getLayout, insets, invalidate, isAncestorOf, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setLayout, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, getBounds, getColorModel, getComponentOrientation, getCursor, getDropTarget, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getInputContext, getInputMethodRequests, getLocale, getLocation, getLocationOnScreen, getName, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, imageUpdate, inside, isDisplayable, isEnabled, isLightweight, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

oldGauges

public static java.util.Vector oldGauges

DEFAULT_GAUGE_WIDTH

public static final int DEFAULT_GAUGE_WIDTH

DEFAULT_NUMBER_OF_GAUGES

public static final int DEFAULT_NUMBER_OF_GAUGES

gaugeWidth

protected int gaugeWidth

numberOfGauges

protected int numberOfGauges

background

protected java.awt.Color background

gauges

protected Gauge[] gauges

editable

protected boolean editable

indexMap

protected java.util.Vector indexMap

sliderChanged

protected javax.swing.event.ChangeListener sliderChanged

slider

protected javax.swing.JSlider slider

sizeChanged

protected java.awt.event.ComponentAdapter sizeChanged
Constructor Detail

BarGraph

public BarGraph()
Bar graph constructor. Sets the default number of gauges for this graph.
Method Detail

addMapEntry

public void addMapEntry(int index,
                        int i,
                        int j)
Add or replace an index map entry. If the values provided to the graph are shown non-sequentially, then index mapping must be done to assign the value to the correct gauge and sub-bar.

Parameters:
index - - int index of the graph to be associated with a value.
i - - index refers to the offset of a gauge within the graph.
j - - index refers to the sub-bar within a particular gauge.

removeMapEntry

public void removeMapEntry(int index,
                           int i,
                           int j)
Removes an index map for a particular index.

Parameters:
index - - int index of the graph to be associated with a value.
i - - index refers to the offset of a gauge within the graph.
j - - index refers to the sub-bar within a particular gauge.

clearMap

public void clearMap()
Resets the index mapping.

getBackground

public java.awt.Color getBackground()
Overrides:
getBackground in class java.awt.Component

setBackground

public void setBackground(java.awt.Color color)
Overrides:
setBackground in class javax.swing.JComponent

setNumberOfGauges

public void setNumberOfGauges(int number)
Sets the number of gauges in this graph. Recylcles gauges from previous setting, creating new ones as necessary.

Parameters:
number - - int number of gauges.

setMax

public void setMax(double value)

setScaleMax

public void setScaleMax(int scale)

getMax

public double getMax()

log10

protected double log10(double x)

setSliderValue

public void setSliderValue()

isEditable

public boolean isEditable()
Returns editable state. Gauge values can be set with pointer device interaction. This method returns whether or not that feature is enabled.


setEditable

public void setEditable(boolean value)
Make gauges editable. Gauge values can be set with pointer device interaction. This method enables and disables that feature.


getSlider

public javax.swing.JSlider getSlider()

setSlider

public void setSlider(javax.swing.JSlider slider)

getColor

public java.awt.Color getColor(int index)
Returns color associated with a particular index.

Specified by:
getColor in interface ValueGraph
Parameters:
index - - int index of graph element.
Returns:
- Color color of graph element.

setColor

public void setColor(java.awt.Color color,
                     int index)
Sets the color associated with a particular index.

Specified by:
setColor in interface ValueGraph
Parameters:
color - - Color of graph element.
index - - int index of graph element.

setGaugeWidth

public void setGaugeWidth(int width)
Sets value that determines pixel spaceing between gauges.

Parameters:
gap - - int gap between gauges.

getGaugeWidth

public int getGaugeWidth()
Gets value that determines pixel spaceing between gauges.

Returns:
- int gap between gauges.

getGauge

public Gauge getGauge(int index)
Returns the gauge component at a particular index. This method does not use index mapping.

Parameters:
index - - int index of gauge.
Returns:
- Gauge gauge at index.

setBarGraphSize

protected void setBarGraphSize(java.awt.Dimension size)

getValue

public double getValue(int index)
Get value of graph element at index. Uses index mapping to determine the graph element.
Parameters:
index - - int index of graph element.

getValue

public double getValue()

updateValue

public void updateValue(double x,
                        int index)
Updates graph element at index with new value. Uses index mapping to determine the graph element.
Specified by:
updateValue in interface ValueGraph
Parameters:
x - - double value to update.
index - - int index of graph element.

updateValue

public void updateValue(double x)
Specified by:
updateValue in interface ValueGraph

updateValue

public void updateValue(float x,
                        int index)
Specified by:
updateValue in interface ValueGraph

updateValue

public void updateValue(float x)
Specified by:
updateValue in interface ValueGraph

paintComponent

public void paintComponent(java.awt.Graphics g)
Overrides:
paintComponent in class javax.swing.JComponent

main

public static void main(java.lang.String[] args)