multigraph
Class Plotter

java.lang.Object
  extended byjava.awt.Component
      extended byjava.awt.Canvas
          extended bymultigraph.DoubleBufferedCanvas
              extended bymultigraph.Plotter
All Implemented Interfaces:
javax.accessibility.Accessible, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable
Direct Known Subclasses:
StretchPlotter

public class Plotter
extends DoubleBufferedCanvas

A Plotter is a DoubleBufferedCanvas that has the following additional functionality:

Version:
$Id: Plotter.java,v 1.1.1.1 2004/11/30 22:30:41 mphillips Exp $
Author:
Mark Phillips
See Also:
PlotFrame, PlotPoint, Serialized Form

Nested Class Summary
 
Nested classes inherited from class java.awt.Canvas
java.awt.Canvas.AccessibleAWTCanvas
 
Nested classes inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
protected  int bottomMargin
          The bottom margin amount, in pixels.
protected  PlotFrame devicePixelFrame
          A PlotFrame representing pixel coordinates for this canvas.
protected  int lastMouseX
          The x coordinate [in devicePixelFrame space] of the last mouse event
protected  int lastMouseY
          The y coordinate [in devicePixelFrame space] of the last mouse event
protected  int leftMargin
          The left margin amount, in pixels.
protected  PlotFrame marginFrame
          A PlotFrame defining a rectangle set inside pixelFrame by given top, bottom, left, and right margin amounts.
protected  int mouseBaseX
          The x coordinate [in devicePixelFrame space] of the last mousePressed event.
protected  int mouseBaseY
          The x coordinate [in devicePixelFrame space] of the last mousePressed event.
protected  PlotFrame pixelFrame
          A PlotFrame whose coordinates are the same as for devicePixelFrame except that the y axis is inverted: (0,0) is the lower left corner.
protected  int rightMargin
          The right margin amount, in pixels.
protected  int topMargin
          The top margin amount, in pixels.
 
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
Plotter(int pixelWidth, int pixelHeight)
          Create a new plotter object having the given width and height, in pixels.
 
Method Summary
 void drawLine(java.awt.Graphics g, PlotPoint p1, PlotPoint p2)
          Draw a line connecting two points.
 void drawRect(java.awt.Graphics g, PlotPoint upperLeft, double width, double height)
          Draw a rectangle specified by its upper left corner, and width and height (in pixels, but specified as doubles).
 void drawRect(java.awt.Graphics g, PlotPoint upperLeft, int width, int height)
          Draw a rectangle specified by its upper left corner, and width and height (in pixels).
 void drawRect(java.awt.Graphics g, PlotPoint lowerLeft, PlotPoint upperRight)
          Draw a rectangle specified by its lower left and upper right corners.
 void drawString(java.awt.Graphics g, PlotPoint base, java.lang.String label)
          Draw a string at a given location.
 void fillArc(java.awt.Graphics g, PlotPoint p1, int width, int height, int a1, int a2)
          Draw a filled arc.
 void fillCircle(java.awt.Graphics g, PlotPoint p1, int radius)
           
 void fillPolygon(java.awt.Graphics g, PlotPoint[] vertices)
          Draw a filled polygon specified by an array of vertices.
 void fillQuad(java.awt.Graphics g, PlotPoint a, PlotPoint b, PlotPoint c, PlotPoint d)
          Draw a filled quadrilateral specified by its 4 vertices.
 void fillRect(java.awt.Graphics g, PlotPoint upperLeft, double width, double height)
          Draw a filled rectangle specified by its upper left corner, and width and height (in pixels, but specified as doubles).
 void fillRect(java.awt.Graphics g, PlotPoint upperLeft, int width, int height)
          Draw a filled rectangle specified by its upper left corner, and width and height (in pixels).
 void fillRect(java.awt.Graphics g, PlotPoint lowerLeft, PlotPoint upperRight)
          Draw a filled rectangle specified by its lower left and upper right corners.
 void fillRectDefinite(java.awt.Graphics g, PlotPoint lowerLeft, PlotPoint upperRight)
          Draw a filled rectangle specified by its lower left and upper right corners, rounding the width and height of the rectangle up to 1 pixel if either would otherwise be 0.
 void fillRectLLDefinite(java.awt.Graphics g, PlotPoint lowerLeft, int width, int height)
          Draw a filled rectangle specified by its lower left corner and width and height in pixels, rounding the width and height of the rectangle up to 1 pixel if either would otherwise be 0.
 PlotFrame getPixelFrame()
          Returns the pixelFrame for this Plotter object.
protected  void keyReleased(int modifiers, char key)
          Process a keyReleased event; the Plotter's handler calls this whenever a keyReleased event occurs.
protected  void keyTyped(int modifiers, char key)
          Process a keyTyped event; the Plotter's handler calls this whenever a keyTyped event occurs.
protected  void mouseDragged(int modifiers, int x, int y)
          Process a mouseDragged event; the Plotter's handler calls this whenever a mouseDragged event occurs.
protected  void mouseMoved(int modifiers, int x, int y)
          Process a mouseMoved event; the Plotter's handler calls this whenever a mouseMoved event occurs.
protected  void mousePressed(int modifiers, int x, int y)
          Process a mousePressed event; the Plotter's handler calls this whenever a mousePressed event occurs.
protected  void mouseReleased(int modifiers, int x, int y)
          Process a mouseReleased event; the Plotter's handler calls this whenever a mouseReleased event occurs.
 void paint(java.awt.Graphics g)
          Erase the background to white (unless renderClear has been called since the last call to paint), and draw a light grey rectangle around the marginFrame.
protected  void renderClear(java.awt.Graphics g)
          Erase the background to white.
 void setMargins(int leftMargin, int rightMargin, int topMargin, int bottomMargin)
          Sets the margins by which marginFrame is inset from pixelFrame.
 
Methods inherited from class multigraph.DoubleBufferedCanvas
getMaximumSize, getMinimumSize, getPreferredSize, update
 
Methods inherited from class java.awt.Canvas
addNotify, createBufferStrategy, createBufferStrategy, getAccessibleContext, getBufferStrategy
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, 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, 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, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, 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, validate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

devicePixelFrame

protected PlotFrame devicePixelFrame
A PlotFrame representing pixel coordinates for this canvas. These coordinates are the same as the coordinates for the underlying java.awt.Canvas object; (0,0) is in the upper left corner and y increases downward across the canvas.


pixelFrame

protected PlotFrame pixelFrame
A PlotFrame whose coordinates are the same as for devicePixelFrame except that the y axis is inverted: (0,0) is the lower left corner.


marginFrame

protected PlotFrame marginFrame
A PlotFrame defining a rectangle set inside pixelFrame by given top, bottom, left, and right margin amounts. The default margin amounts are hardcoded but these may be changed by calling setMargins(). marginFrame coordinates are in terms of pixels (i.e. a 1x1 box in the marginFrame system is exactly one pixel), but marginFrame is offset so that (0,0) is inset from the lower left corner of pixelFrame by (leftMargin,bottomMargin).


leftMargin

protected int leftMargin
The left margin amount, in pixels.


rightMargin

protected int rightMargin
The right margin amount, in pixels.


topMargin

protected int topMargin
The top margin amount, in pixels.


bottomMargin

protected int bottomMargin
The bottom margin amount, in pixels.


lastMouseX

protected int lastMouseX
The x coordinate [in devicePixelFrame space] of the last mouse event


lastMouseY

protected int lastMouseY
The y coordinate [in devicePixelFrame space] of the last mouse event


mouseBaseX

protected int mouseBaseX
The x coordinate [in devicePixelFrame space] of the last mousePressed event.


mouseBaseY

protected int mouseBaseY
The x coordinate [in devicePixelFrame space] of the last mousePressed event.

Constructor Detail

Plotter

public Plotter(int pixelWidth,
               int pixelHeight)
Create a new plotter object having the given width and height, in pixels.

Method Detail

getPixelFrame

public PlotFrame getPixelFrame()
Returns the pixelFrame for this Plotter object.


setMargins

public void setMargins(int leftMargin,
                       int rightMargin,
                       int topMargin,
                       int bottomMargin)
Sets the margins by which marginFrame is inset from pixelFrame. Margin values are measured in pixels. If any of the margin values passed in is negative, the corresponding margin value is left unchanged. Calling setMargins causes marginFrame to be recomputed in terms of the new settings.


paint

public void paint(java.awt.Graphics g)
Erase the background to white (unless renderClear has been called since the last call to paint), and draw a light grey rectangle around the marginFrame. Subclasses can override this method to provide their own rendering.


renderClear

protected void renderClear(java.awt.Graphics g)
Erase the background to white. This is a separate method outside of paint so that subclasses whose paint implementation needs to draw something after the background is cleared but before the grey marginFrame rectangle is drawn can do so by calling renderClear first, doing whatever intermediate drawing is needed, and then calling paint.


drawRect

public void drawRect(java.awt.Graphics g,
                     PlotPoint upperLeft,
                     int width,
                     int height)
Draw a rectangle specified by its upper left corner, and width and height (in pixels).


drawRect

public void drawRect(java.awt.Graphics g,
                     PlotPoint upperLeft,
                     double width,
                     double height)
Draw a rectangle specified by its upper left corner, and width and height (in pixels, but specified as doubles).


drawRect

public void drawRect(java.awt.Graphics g,
                     PlotPoint lowerLeft,
                     PlotPoint upperRight)
Draw a rectangle specified by its lower left and upper right corners.


fillRect

public void fillRect(java.awt.Graphics g,
                     PlotPoint upperLeft,
                     int width,
                     int height)
Draw a filled rectangle specified by its upper left corner, and width and height (in pixels).


fillRect

public void fillRect(java.awt.Graphics g,
                     PlotPoint upperLeft,
                     double width,
                     double height)
Draw a filled rectangle specified by its upper left corner, and width and height (in pixels, but specified as doubles).


fillRect

public void fillRect(java.awt.Graphics g,
                     PlotPoint lowerLeft,
                     PlotPoint upperRight)
Draw a filled rectangle specified by its lower left and upper right corners.


fillRectDefinite

public void fillRectDefinite(java.awt.Graphics g,
                             PlotPoint lowerLeft,
                             PlotPoint upperRight)
Draw a filled rectangle specified by its lower left and upper right corners, rounding the width and height of the rectangle up to 1 pixel if either would otherwise be 0. This insures that something at least one pixel high and one pixel across is drawn.


fillRectLLDefinite

public void fillRectLLDefinite(java.awt.Graphics g,
                               PlotPoint lowerLeft,
                               int width,
                               int height)
Draw a filled rectangle specified by its lower left corner and width and height in pixels, rounding the width and height of the rectangle up to 1 pixel if either would otherwise be 0. This insures that something at least one pixel high and one pixel across is drawn.


fillQuad

public void fillQuad(java.awt.Graphics g,
                     PlotPoint a,
                     PlotPoint b,
                     PlotPoint c,
                     PlotPoint d)
Draw a filled quadrilateral specified by its 4 vertices.


drawLine

public void drawLine(java.awt.Graphics g,
                     PlotPoint p1,
                     PlotPoint p2)
Draw a line connecting two points.


fillArc

public void fillArc(java.awt.Graphics g,
                    PlotPoint p1,
                    int width,
                    int height,
                    int a1,
                    int a2)
Draw a filled arc.


fillCircle

public void fillCircle(java.awt.Graphics g,
                       PlotPoint p1,
                       int radius)

fillPolygon

public void fillPolygon(java.awt.Graphics g,
                        PlotPoint[] vertices)
Draw a filled polygon specified by an array of vertices.


drawString

public void drawString(java.awt.Graphics g,
                       PlotPoint base,
                       java.lang.String label)
Draw a string at a given location.


mousePressed

protected void mousePressed(int modifiers,
                            int x,
                            int y)
Process a mousePressed event; the Plotter's handler calls this whenever a mousePressed event occurs.

Parameters:
modifiers - The event modifier mask returned by java.awt.event.InputEvent.getModifiers()
x - The x coordinate (in devicePixelFrame space) of the event.
y - The y coordinate (in devicePixelFrame space) of the event.

mouseReleased

protected void mouseReleased(int modifiers,
                             int x,
                             int y)
Process a mouseReleased event; the Plotter's handler calls this whenever a mouseReleased event occurs.

Parameters:
modifiers - The event modifier mask returned by java.awt.event.InputEvent.getModifiers()
x - The x coordinate (in devicePixelFrame space) of the event.
y - The y coordinate (in devicePixelFrame space) of the event.

mouseMoved

protected void mouseMoved(int modifiers,
                          int x,
                          int y)
Process a mouseMoved event; the Plotter's handler calls this whenever a mouseMoved event occurs.

Parameters:
modifiers - The event modifier mask returned by java.awt.event.InputEvent.getModifiers()
x - The x coordinate (in devicePixelFrame space) of the event.
y - The y coordinate (in devicePixelFrame space) of the event.

mouseDragged

protected void mouseDragged(int modifiers,
                            int x,
                            int y)
Process a mouseDragged event; the Plotter's handler calls this whenever a mouseDragged event occurs.

Parameters:
modifiers - The event modifier mask returned by java.awt.event.InputEvent.getModifiers()
x - The x coordinate (in devicePixelFrame space) of the event.
y - The y coordinate (in devicePixelFrame space) of the event.

keyTyped

protected void keyTyped(int modifiers,
                        char key)
Process a keyTyped event; the Plotter's handler calls this whenever a keyTyped event occurs.

Parameters:
modifiers - The event modifier mask returned by java.awt.event.InputEvent.getModifiers()
key - The key that was typed.

keyReleased

protected void keyReleased(int modifiers,
                           char key)
Process a keyReleased event; the Plotter's handler calls this whenever a keyReleased event occurs.

Parameters:
modifiers - The event modifier mask returned by java.awt.event.InputEvent.getModifiers()
key - The key that was released.