GrapherGUI
Class Graph

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--javax.swing.JComponent
                    |
                    +--javax.swing.JPanel
                          |
                          +--GrapherGUI.Graph
All Implemented Interfaces:
javax.accessibility.Accessible, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable

public class Graph
extends javax.swing.JPanel

Creates a panel object which draws the given functions.

See Also:
Serialized Form

Nested Class Summary
 class Graph.MouseTracker
          MouseMotionListener object to handle mouse events.
 
Field Summary
 int MAXFUNCTIONS
          maximum number of functions one plot can display
 int X
          width in pixels of the graph
 int Y
          height in pixels of the visible graph
 short ZOOM_IN_X
          constant passed into zoom
 short ZOOM_IN_Y
          constant passed into zoom
 short ZOOM_OUT_X
          constant passed into zoom
 short ZOOM_OUT_Y
          constant passed into zoom
 
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
Graph()
          Class constructor.
Graph(GrapherGUI.SliderMatrix sm, double minx, double maxx, double miny, double maxy)
          Class constructor specifying dimensions of graph.
 
Method Summary
 boolean addFunc(GrapherGUI.Function f)
          Adds a function to the graph.
 java.awt.Point cart2screen(double x, double y)
          Converts a point on the cartesian coordinate plane to a pixel coordinate on the drawing canvas.
 void changeStateLinkPoints()
          Change the state of the boolean handling whether points on the graph are tied together by lines.
 void changeStateShowKey()
          Show/remove key.
 void drawFunctions()
          Draws each function.
 void drawGrid()
          Draws the axes and all appropriate labels.
 void drawKey()
          Draw the key onto the top left corner of the graph.
 int getDensity()
          Get the number of points that are used to draw each function.
 double getTheta(java.awt.geom.Line2D l)
          Gets the angle in polar coordinates of a line.
 double maxx()
          Get the maximum x value
 double maxy()
          Get the maximum y value
 double minx()
          Get the minimum x value
 double miny()
          Get the minimum y value
 javax.swing.JLabel mouseLabel()
          Returns a link to the mouse label.
 void paint(java.awt.Graphics g)
          Redraws the graph according to the current parameter set.
 void scale()
          Called after a change in scale.
 java.awt.geom.Point2D.Double screen2cart(int x, int y)
          Converts a point on the canvas plane to a point on the cartesian coordinate plane.
 void setAxesIcons(java.lang.String xfile, java.lang.String yfile)
          Set an icon for the axes of the graph.
 void setAxisLabels(java.lang.String x, java.lang.String y)
          Set an string for the axes of the graph.
 boolean setDensity(int d)
          Set the number of points that are used to draw each function.
 void setMaxx(double d)
          Set the maximum x value on the graph.
 void setMaxy(double d)
          Set the maximum y value on the graph.
 void setMinx(double d)
          Set the minimum x value on the graph.
 void setMiny(double d)
          Set the minimum y value on the graph.
 void setTickIncrementX(double d)
          Set the frequency in which tick marks and labels show up on the x-axis..
 void setTickIncrementY(double d)
          Set the frequency in which tick marks and labels show up on the y-axis..
 java.lang.String strMouseCoord()
          Returns a string representation of the current mouse coordinates on the graph.
 void zoom(short how)
          Increases/decreases the domain and range of the graph according to the parameter it recieves.
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
 
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, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getGraphics, getHeight, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFont, setForeground, 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, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, 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, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, 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, processMouseEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, 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
 

Field Detail

X

public final int X
width in pixels of the graph

See Also:
Constant Field Values

Y

public final int Y
height in pixels of the visible graph

See Also:
Constant Field Values

ZOOM_IN_X

public final short ZOOM_IN_X
constant passed into zoom

See Also:
Graph.zoom, Constant Field Values

ZOOM_IN_Y

public final short ZOOM_IN_Y
constant passed into zoom

See Also:
Graph.zoom, Constant Field Values

ZOOM_OUT_X

public final short ZOOM_OUT_X
constant passed into zoom

See Also:
Graph.zoom, Constant Field Values

ZOOM_OUT_Y

public final short ZOOM_OUT_Y
constant passed into zoom

See Also:
Graph.zoom, Constant Field Values

MAXFUNCTIONS

public final int MAXFUNCTIONS
maximum number of functions one plot can display

See Also:
Constant Field Values
Constructor Detail

Graph

public Graph()
Class constructor. Sets x values (-10, 10) and y values (-10, 10).


Graph

public Graph(GrapherGUI.SliderMatrix sm,
             double minx,
             double maxx,
             double miny,
             double maxy)
Class constructor specifying dimensions of graph.

Parameters:
sm - the list of parameters
minx - minimum x value
maxx - maximum x value
miny - minimum y value
maxy - maximum y value
Method Detail

setTickIncrementX

public void setTickIncrementX(double d)
Set the frequency in which tick marks and labels show up on the x-axis..

Parameters:
d - value between tick marks

setTickIncrementY

public void setTickIncrementY(double d)
Set the frequency in which tick marks and labels show up on the y-axis..

Parameters:
d - value between tick marks.

scale

public void scale()
Called after a change in scale. This resets appropriate variables so that paint() works correctly after a zoom call.


getDensity

public int getDensity()
Get the number of points that are used to draw each function.

Returns:
density

setDensity

public boolean setDensity(int d)
Set the number of points that are used to draw each function.

Parameters:
d - number of points to use in drawing each function
Returns:
true if set was successful otherwise false

addFunc

public boolean addFunc(GrapherGUI.Function f)
Adds a function to the graph. A total of ten functions is allowed on any one plot.

Parameters:
f - function to be added to the plot
Returns:
true if adding was successful. False if f is null or if the plot has ten functions already
See Also:
Function

setAxesIcons

public void setAxesIcons(java.lang.String xfile,
                         java.lang.String yfile)
Set an icon for the axes of the graph.

Parameters:
xfile - filename of the independent icon file (must be JPEG or GIF)
yfile - filename of the dependent icon (must be JPEG or GIF)

setAxisLabels

public void setAxisLabels(java.lang.String x,
                          java.lang.String y)
Set an string for the axes of the graph. The strings will be used in the case that icons are not provided or the images cannot be found.

Parameters:
x - x-axis label
y - y-axis label

changeStateLinkPoints

public void changeStateLinkPoints()
Change the state of the boolean handling whether points on the graph are tied together by lines.


changeStateShowKey

public void changeStateShowKey()
Show/remove key.


zoom

public void zoom(short how)
Increases/decreases the domain and range of the graph according to the parameter it recieves.

Parameters:
how - either zoom in x/y or out x/y
See Also:
Graph.ZOOM_IN_X, Graph.ZOOM_IN_Y, Graph.ZOOM_OUT_X, Graph.ZOOM_OUT_Y

paint

public void paint(java.awt.Graphics g)
Redraws the graph according to the current parameter set.

Overrides:
paint in class javax.swing.JComponent
Parameters:
g - graphics object on which to draw
See Also:
Graphics, Function

drawGrid

public void drawGrid()
Draws the axes and all appropriate labels.

If the user specified an image to use for a variable name, that will be drawn near its respective axis. Otherwise, the string name of the parameter will be drawn.


drawFunctions

public void drawFunctions()
Draws each function.


drawKey

public void drawKey()
Draw the key onto the top left corner of the graph. It will be drawn transparent if this feature is available.


cart2screen

public java.awt.Point cart2screen(double x,
                                  double y)
Converts a point on the cartesian coordinate plane to a pixel coordinate on the drawing canvas.

Parameters:
x - x value (cartesian coordinates)
y - y value (cartesian coordinates)
Returns:
Point object representing the coordinate of the pixel at which (x, y) represent.
See Also:
Point

screen2cart

public java.awt.geom.Point2D.Double screen2cart(int x,
                                                int y)
Converts a point on the canvas plane to a point on the cartesian coordinate plane.

Parameters:
x - pixel x coordinate
y - pixel y coordinate
Returns:
Point object representing the coordinate on the cartesian plane.
See Also:
Point2D

getTheta

public double getTheta(java.awt.geom.Line2D l)
Gets the angle in polar coordinates of a line. The first endpoint represents the origin.

Parameters:
l - object representing the line
Returns:
angle in radians
See Also:
Line2D

strMouseCoord

public java.lang.String strMouseCoord()
Returns a string representation of the current mouse coordinates on the graph.

Returns:
string in the form of (x,y)

mouseLabel

public javax.swing.JLabel mouseLabel()
Returns a link to the mouse label. Used in GUI class.

Returns:
JLabel showing mouse coordinates.

minx

public double minx()
Get the minimum x value

Returns:
minimum x

miny

public double miny()
Get the minimum y value

Returns:
minimum y

maxx

public double maxx()
Get the maximum x value

Returns:
maximum x

maxy

public double maxy()
Get the maximum y value

Returns:
maximum y

setMinx

public void setMinx(double d)
Set the minimum x value on the graph. Remember to call scale() to properly display the new setting(s).

Parameters:
d - minimum x value

setMiny

public void setMiny(double d)
Set the minimum y value on the graph. Remember to call scale() to properly display the new setting(s).

Parameters:
d - minimum y value

setMaxx

public void setMaxx(double d)
Set the maximum x value on the graph. Remember to call scale() to properly display the new setting(s).

Parameters:
d - maximum x value

setMaxy

public void setMaxy(double d)
Set the maximum y value on the graph. Remember to call scale() to properly display the new setting(s).

Parameters:
d - maximum y value