grapher
Class Grapher

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JPanel
                  extended by grapher.Grapher
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, javax.accessibility.Accessible

public class Grapher
extends javax.swing.JPanel

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
 
Field Summary
 
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 java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
Grapher()
          Default constructor.
Grapher(java.lang.String xLabel, java.lang.String yLabel)
          Constructor that takes text labels for the x and y axis.
 
Method Summary
 void enableAxis(boolean axisEnabled)
          Enables or disables showing the y-axis and x-axis and scale labels.
 void enableAxisLabelsOnIndicators(boolean axisLabels)
          Enables or disables showing the axis label string on the indicator lines in addition to just the value.
 void enableGrid(boolean gridEnabled)
          Enables or disables the unit grid.
 void expandScale(float changeScale)
          Expands the visible x and y axis by a factor of changeScale
 float getMaxX()
          Returns the maximum displayed x value on the scale.
 float getMaxY()
          Returns the maximum displayed y value on the scale.
 float getMinX()
          Returns the minimum displayed x value on the scale.
 float getMinY()
          Returns the minimum displayed y value on the scale.
 float getXValue()
          Returns the value the vertical x-axis indicator is currently on.
 float getYValue()
          Returns the value the horizontal y-axis indicator is currently on.
 boolean isAxisEnabled()
          Returns whether showing the axis is enabled.
 boolean isAxisLabelsOnIndicatorsEnabled()
          Returns whether showing the axis label string on the indicator lines in addition to just the value is enabled.
 boolean isGridEnabled()
          Returns whether the unit grid is enabled.
 void paintComponent(java.awt.Graphics g)
          Draws the graph.
 boolean setCoords(float[][] xCoords1, float[][] yCoords1)
          If the number of x and y points are the same, sets the coordinates using references and returns true.
 void setMaxX(float newMaxX)
          Sets the maximum displayed x value.
 void setMaxY(float newMaxY)
          Sets the maximum displayed y value.
 void setMinX(float newMinX)
          Sets the minimum displayed x value.
 void setMinY(float newMinY)
          Sets the minimum displayed y value.
 boolean setScale(float minX1, float maxX1, float minY1, float maxY1)
          If the scale is valid (minimums are smaller than maximums), sets the minimum and maximum values to display and returns true.
 boolean setScale(int line)
          Sets the minimum and maximum values to display to the min and max of the coordinates of the given line.
 void setXIndicator(float value, int line)
          Sets the value for the vertical indicator line.
 void setYIndicator(float value, int line)
          Sets the value for the horizontal indicator line.
 
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, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, 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, transferFocusBackward, 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, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, 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, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Grapher

public Grapher()
Default constructor. Does nothing.


Grapher

public Grapher(java.lang.String xLabel,
               java.lang.String yLabel)
Constructor that takes text labels for the x and y axis.

Parameters:
xLabel - Label for the x-axis.
yLabel - Label for the y-axis.
Method Detail

setCoords

public boolean setCoords(float[][] xCoords1,
                         float[][] yCoords1)
If the number of x and y points are the same, sets the coordinates using references and returns true. Overwrites old coordinates. Coordinates are given in a two dimensional array where the first index indicates the line number and the second dimension contains the actual data.

Parameters:
xCoords1 - A new set of x-coordinates to display on the graph.
yCoords1 - A new set of y-coordinates to display on the graph.
Returns:
True if setting the coordinates was successful. False if the number of lines or the number of points in the first line don't match up, or if either set of coordinates is null.

setScale

public boolean setScale(float minX1,
                        float maxX1,
                        float minY1,
                        float maxY1)
If the scale is valid (minimums are smaller than maximums), sets the minimum and maximum values to display and returns true. If the given values don't make sense, returns false.

Parameters:
minX1 - Minimum value to display on the x-axis.
maxX1 - Maximum value to display on the x-axis.
minY1 - Minimum value to display on the y-axis.
maxY1 - Maximum value to display on the y-axis.
Returns:
True if the scale is valid, false if not.

setScale

public boolean setScale(int line)
Sets the minimum and maximum values to display to the min and max of the coordinates of the given line. Returns false if the line does not exist.

Parameters:
line - Integer >= 0 indicating a line to use to set the scale.
Returns:
True if setting the scale was successful.

expandScale

public void expandScale(float changeScale)
Expands the visible x and y axis by a factor of changeScale

Parameters:
changeScale - Factor to expand by.

setMinX

public void setMinX(float newMinX)
Sets the minimum displayed x value.

Parameters:
newMinX - The new minimum x value.

setMaxX

public void setMaxX(float newMaxX)
Sets the maximum displayed x value.

Parameters:
newMaxX - The new maximum x value.

setMinY

public void setMinY(float newMinY)
Sets the minimum displayed y value.

Parameters:
newMinX - The new minimum y value.

setMaxY

public void setMaxY(float newMaxY)
Sets the maximum displayed y value.

Parameters:
newMaxX - The new maximum y value.

setXIndicator

public void setXIndicator(float value,
                          int line)
Sets the value for the vertical indicator line. Sets the value of the horizontal indicator line to the first closest value in the given line. If no close value is found, doesn't change the y indicator.

Parameters:
value - Value for the vertical (x-axis) indicator line.
line - The line to use to find the horizontal indicator value.

setYIndicator

public void setYIndicator(float value,
                          int line)
Sets the value for the horizontal indicator line. Sets the value of the vertical indicator line to the first closest value in the given line.

Parameters:
value - Value for the horizontal (y-axis) indicator line.
line - The line to use to find the vertical indicator value.

getXValue

public float getXValue()
Returns the value the vertical x-axis indicator is currently on.

Returns:
The X value.

getYValue

public float getYValue()
Returns the value the horizontal y-axis indicator is currently on.

Returns:
The Y value.

getMinX

public float getMinX()
Returns the minimum displayed x value on the scale.

Returns:
The x minimum.

getMaxX

public float getMaxX()
Returns the maximum displayed x value on the scale.

Returns:
The x maximum.

getMinY

public float getMinY()
Returns the minimum displayed y value on the scale.

Returns:
The y minimum.

getMaxY

public float getMaxY()
Returns the maximum displayed y value on the scale.

Returns:
The y maximum.

enableGrid

public void enableGrid(boolean gridEnabled)
Enables or disables the unit grid.

Parameters:
gridEnabled - True to enable the grid, false to disable.

isGridEnabled

public boolean isGridEnabled()
Returns whether the unit grid is enabled.

Returns:
True if the grid is enabled.

enableAxis

public void enableAxis(boolean axisEnabled)
Enables or disables showing the y-axis and x-axis and scale labels.

Parameters:
axisEnabled - True to enable the axis, false to disable.

isAxisEnabled

public boolean isAxisEnabled()
Returns whether showing the axis is enabled.

Returns:
True if the axis is shown.

enableAxisLabelsOnIndicators

public void enableAxisLabelsOnIndicators(boolean axisLabels)
Enables or disables showing the axis label string on the indicator lines in addition to just the value.

Parameters:
axisEnabled - True to enable the axis, false to disable.

isAxisLabelsOnIndicatorsEnabled

public boolean isAxisLabelsOnIndicatorsEnabled()
Returns whether showing the axis label string on the indicator lines in addition to just the value is enabled.

Returns:
True if the axis is shown.

paintComponent

public void paintComponent(java.awt.Graphics g)
Draws the graph.

Overrides:
paintComponent in class javax.swing.JComponent