freegraph
Class GraphPlane

java.lang.Object
  |
  +--java.awt.Component
        |
        +--freegraph.GraphPlane
All Implemented Interfaces:
java.awt.event.ActionListener, java.util.EventListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable

public class GraphPlane
extends java.awt.Component
implements java.awt.event.ActionListener

GraphPlane is a X-Y or cartesian coordinate plane which draws the axis and a list of GraphPlaneItems (typically instances of ExpressionEvaluator). The GraphPlane handles the zooming with the mouse and can be monitored with GraphPlaneListener to receive notification of axis changes or mouse position changes.

No Graphics2D is used to keep it compatible with Java 1.1.

See Also:
Serialized Form

Field Summary
static int XMAX_DEFAULT
           
static int XMIN_DEFAULT
           
static int YMAX_DEFAULT
           
static int YMIN_DEFAULT
           
 
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
GraphPlane()
          constructs a new GraphPlane
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent e)
          dispatches action events from the popup menu.
 void addGraphPlaneItem(GraphPlaneItem gp)
          adds a GraphPlaneItem to be drawn when the graph is drawn
 void addGraphPlaneListener(GraphPlaneListener l)
          adds a GraphPlaneListener to receive events about the mouse location and the size of the GraphPlane.
 int convertX(double x)
          Converts a graph X value to a component X value
 int convertY(double y)
          Converts from a graph Y value to a component Y value
 double deconvertX(int x)
          Converts from a component X value to a graph X value
 double deconvertY(int y)
          Converts from a component Y value to a graph Y value
 double getXMax()
          returns the maximum X value for the GraphPlane
 double getXMin()
          returns the minimum X value for the GraphPlane
 double getYMax()
          returns the maximum Y value for the GraphPlane
 double getYMin()
          returns the minimum Y value for the GraphPlane
 java.util.Enumeration graphPlaneItems()
          returns an Enumeration of the GraphPlanItems
 void mouseClicked(java.awt.event.MouseEvent event)
           
 void mouseDragged(java.awt.event.MouseEvent event)
          draws the zoom (invert) rectangle
 void mouseMoved(java.awt.event.MouseEvent event)
          converts the position of the mouse to graph coordinates and fires event to GraphPlaneListeners.
 void mousePressed(java.awt.event.MouseEvent event)
          If the left mouse button is pressed, global variables are used to store the mouse location for use with a zoom.
If right mouse button is pressed, the popup menu is displayed.
 void mouseReleased(java.awt.event.MouseEvent event)
          If a zoom rectangle is being drawn, the graph's axis are changed and the graph is updated.
 void paint(java.awt.Graphics g)
          paints the graph by drawing the axis and then drawing each GraphPlaneItem.
 void removeGraphPlaneItem(GraphPlaneItem gp)
          removes a GraphPlaneItem
 void removeGraphPlaneListener(GraphPlaneListener l)
          removes a GraphPlaneListener
 void reset()
          resets the GraphPlane to its default values
 void zoomin()
          zooms out the graph
 void zoomout()
          zooms in the graph
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, deliverEvent, disable, disableEvents, dispatchEvent, doLayout, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, getAccessibleContext, getAlignmentX, getAlignmentY, getBackground, getBounds, getBounds, getColorModel, getComponentAt, getComponentAt, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeys, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMaximumSize, getMinimumSize, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, invalidate, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusCycleRoot, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isOpaque, isShowing, isValid, isVisible, keyDown, keyUp, layout, list, list, list, list, list, locate, location, lostFocus, minimumSize, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, paramString, postEvent, preferredSize, prepareImage, prepareImage, print, printAll, processComponentEvent, processEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeys, setFocusTraversalKeysEnabled, setFont, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle, update, validate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

XMIN_DEFAULT

public static int XMIN_DEFAULT

YMIN_DEFAULT

public static int YMIN_DEFAULT

XMAX_DEFAULT

public static int XMAX_DEFAULT

YMAX_DEFAULT

public static int YMAX_DEFAULT
Constructor Detail

GraphPlane

public GraphPlane()
constructs a new GraphPlane

Method Detail

getXMax

public double getXMax()
returns the maximum X value for the GraphPlane


getXMin

public double getXMin()
returns the minimum X value for the GraphPlane


getYMax

public double getYMax()
returns the maximum Y value for the GraphPlane


getYMin

public double getYMin()
returns the minimum Y value for the GraphPlane


graphPlaneItems

public java.util.Enumeration graphPlaneItems()
returns an Enumeration of the GraphPlanItems


addGraphPlaneItem

public void addGraphPlaneItem(GraphPlaneItem gp)
adds a GraphPlaneItem to be drawn when the graph is drawn


removeGraphPlaneItem

public void removeGraphPlaneItem(GraphPlaneItem gp)
removes a GraphPlaneItem


addGraphPlaneListener

public void addGraphPlaneListener(GraphPlaneListener l)
adds a GraphPlaneListener to receive events about the mouse location and the size of the GraphPlane.


removeGraphPlaneListener

public void removeGraphPlaneListener(GraphPlaneListener l)
removes a GraphPlaneListener


reset

public void reset()
resets the GraphPlane to its default values


zoomout

public void zoomout()
zooms in the graph


zoomin

public void zoomin()
zooms out the graph


actionPerformed

public void actionPerformed(java.awt.event.ActionEvent e)
dispatches action events from the popup menu.

Specified by:
actionPerformed in interface java.awt.event.ActionListener

paint

public void paint(java.awt.Graphics g)
paints the graph by drawing the axis and then drawing each GraphPlaneItem.

Overrides:
paint in class java.awt.Component

convertX

public int convertX(double x)
Converts a graph X value to a component X value


deconvertX

public double deconvertX(int x)
Converts from a component X value to a graph X value


convertY

public int convertY(double y)
Converts from a graph Y value to a component Y value


deconvertY

public double deconvertY(int y)
Converts from a component Y value to a graph Y value


mouseClicked

public void mouseClicked(java.awt.event.MouseEvent event)

mousePressed

public void mousePressed(java.awt.event.MouseEvent event)
If the left mouse button is pressed, global variables are used to store the mouse location for use with a zoom.
If right mouse button is pressed, the popup menu is displayed.


mouseReleased

public void mouseReleased(java.awt.event.MouseEvent event)
If a zoom rectangle is being drawn, the graph's axis are changed and the graph is updated. When zooming, the values are rounded based on the range and domain of the graph.


mouseDragged

public void mouseDragged(java.awt.event.MouseEvent event)
draws the zoom (invert) rectangle


mouseMoved

public void mouseMoved(java.awt.event.MouseEvent event)
converts the position of the mouse to graph coordinates and fires event to GraphPlaneListeners. If the mouse position on a pixel which could also be represented by a number more round than the calculated value, the number is rounded.