edu.uah.math.devices
Class Graph

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 edu.uah.math.devices.Graph
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, javax.accessibility.Accessible
Direct Known Subclasses:
BallotGraph, BertrandFloor, BetaGraph, CoinFloor, CoinTossLLNGraph, DistributionGraph, ErrorGraph, EstimateGraph, GaltonBoard, Histogram, NeedleFloor, ProbabilityPlot, RandomWalkGraph, RedBlackGraph, ScatterPlot, Stick, Timeline

public class Graph
extends javax.swing.JPanel
implements java.io.Serializable

This class defines a basic two-dimensional graph to be sub-classed. The class provides basic drawing methods.

Version:
August, 2003
Author:
Kyle Siegrist, Dawn Duehring
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
static int ABOVE
           
static int BELOW
           
static int HORIZONTAL
           
static int LEFT
           
static int RIGHT
           
protected  boolean showModelDistribution
           
static int VERTICAL
           
 
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()
          This default constructor creates a new graph with x and y between 0 and 1.
Graph(double x0, double x1, double y0, double y1)
          This general constructor creates a new graph with specified ranges on the x an y axes,
 
Method Summary
 void drawAxis(java.awt.Graphics g, Domain d, double c, int o)
          This method draws an axis corresponding to a sepcified domain at specified poisiton relative to the other variable, with a specified orientation.
 void drawAxis(java.awt.Graphics g, double a, double b, double w, double c, int o)
          This method draws an axis corresponding to a specified continuous domain, at a specified position relative to the other variable, with a specified orientation.
 void drawAxis(java.awt.Graphics g, double a, double b, double w, int t, double c, int o)
          This method draws an axis corresponding to a sepcified domain at specified poisiton relative to the other variable, with a specified orientation.
 void drawBox(java.awt.Graphics g, double x0, double y0, double x1, double y1)
          This method draws a box between the specified corner points in scale units.
 void drawBox(java.awt.Graphics g, int s, double x, double y, double l, int i, int j)
          This method draws a box at a specified point with a specified length and width.
 void drawBoxPlot(java.awt.Graphics g, double x1, double x2, double x3, double x4, double x5, int y)
          The following method draws a five-number, horizontal boxplot.
 void drawBoxPlot(java.awt.Graphics g, double x, double r, int y)
          The following method draws a symmetric, horizontal boxplot, centered at at a specified point with a specified radius (in scale units), at a specified vertical position in pixels.
 void drawCircle(java.awt.Graphics g, double x, double y, double r)
          This method draws a circle with a specified center and radius (in scale units).
 void drawLabel(java.awt.Graphics g, java.lang.String s, double x, double y, int o)
          This method draws a sepcified label at a specified orientation next to a specified point.
 void drawLine(java.awt.Graphics g, double x1, double y1, double x2, double y2)
          This method draws a line between (x1, y1) and (x2, y2), where the coordinates are in scale units.
 void drawPoint(java.awt.Graphics g, double x, double y)
          This method draws a point at the specified x and y coordinates (in scale units).
 void drawTick(java.awt.Graphics g, double x, double y, int o)
          This method draws a tick mark at a specified point, 3 pixels in the each direction, with a specified oreintation.
 void drawTick(java.awt.Graphics g, double x, double y, int i, int j, int o)
          This method draws a tick mark at a specified point (in scale units), a specified number of pixels in the positive and negative directions, with a specified orientation.
 void fillBox(java.awt.Graphics g, double x0, double y0, double x1, double y1)
          This method fills a box between the specified corner points in scale units.
 void fillBox(java.awt.Graphics g, int s, double x, double y, double l, int i, int j)
          This method fills a box at a specified point with a specified length and width.
 void fillBoxPlot(java.awt.Graphics g, double x1, double x2, double x3, double x4, double x5, int y)
          The following method fills a five-number, horizontal boxplot.
 void fillBoxPlot(java.awt.Graphics g, double x, double r, int y)
          The following method fills a symmetric, horizontal boxplot, centered at a specified point, with a specified radius r (in scale units), at a specified vertical poisiton in pixels.
 void fillCircle(java.awt.Graphics g, double x, double y, double r)
          This method fills a circle with a specified center and radius (in scale units).
 java.lang.String format(double x)
          This method formats a specified number.
 int getBottomMargin()
          This method gets the bottom margin.
 int getLeftMargin()
          This method gets the left margin.
 int getPointSize()
          This method returns the points size.
 int getRightMargin()
          This method gets the right margin.
 int getTopMargin()
          This method gets the top margin.
 int getXGraph(double x)
          This method converts between scale and graph units.
 double getXMax()
          This method returns the maximum x value.
 double getXMin()
          This method returns the minimum x value.
 int getXPixels(double x)
          This method converts scale units to graph units for the x variable.
 double getXScale(int x)
          This method converts between graph and scale units for the x variable.
 int getYGraph(double y)
          This method converts between scale and graph units for the y variable.
 double getYMax()
          This method returns the maximum y value.
 double getYMin()
          This method returns the minimum y value.
 int getYPixels(double y)
          This method converts scale units to graph units for the y variable.
 double getYScale(int y)
          This method converts between graph and scale units for the y variable.
 void setMargins(int l, int r, int b, int t)
          This method sets the margin (in pixels).
 void setPointSize(int n)
          This method sets the point size (in pixels) for drawing points.
 void setScale(double x0, double x1, double y0, double y1)
          This method sets the minimum and maximum values on the x and y axes.
 void setShowModelDistribution(boolean b)
           
 
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, paintComponent, 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
 

Field Detail

LEFT

public static final int LEFT
See Also:
Constant Field Values

RIGHT

public static final int RIGHT
See Also:
Constant Field Values

ABOVE

public static final int ABOVE
See Also:
Constant Field Values

BELOW

public static final int BELOW
See Also:
Constant Field Values

VERTICAL

public static final int VERTICAL
See Also:
Constant Field Values

HORIZONTAL

public static final int HORIZONTAL
See Also:
Constant Field Values

showModelDistribution

protected boolean showModelDistribution
Constructor Detail

Graph

public Graph(double x0,
             double x1,
             double y0,
             double y1)
This general constructor creates a new graph with specified ranges on the x an y axes,

Parameters:
x0 - the minimum x value
x1 - the maximum x value
y0 - the minimun y value
y1 - the maximum y value

Graph

public Graph()
This default constructor creates a new graph with x and y between 0 and 1.

Method Detail

setShowModelDistribution

public void setShowModelDistribution(boolean b)

setScale

public void setScale(double x0,
                     double x1,
                     double y0,
                     double y1)
This method sets the minimum and maximum values on the x and y axes.

Parameters:
x0 - the minimum x value
x1 - the maximum x value
y0 - the minimum y value
y1 - the maximum y value

getXMin

public double getXMin()
This method returns the minimum x value.

Returns:
the minimum x value

getXMax

public double getXMax()
This method returns the maximum x value.

Returns:
the maximum x value

getYMin

public double getYMin()
This method returns the minimum y value.

Returns:
the minimum y value

getYMax

public double getYMax()
This method returns the maximum y value.

Returns:
the maximum y value

setMargins

public void setMargins(int l,
                       int r,
                       int b,
                       int t)
This method sets the margin (in pixels).

Parameters:
l - the left margin
r - the right margin
b - the bottom margin
t - the top margin

getLeftMargin

public int getLeftMargin()
This method gets the left margin.

Returns:
the left margin

getRightMargin

public int getRightMargin()
This method gets the right margin.

Returns:
the right margin

getTopMargin

public int getTopMargin()
This method gets the top margin.

Returns:
the top margin

getBottomMargin

public int getBottomMargin()
This method gets the bottom margin.

Returns:
the bottom margin

getXGraph

public int getXGraph(double x)
This method converts between scale and graph units.

Parameters:
x - the x-coordinate in scale units
Returns:
the x-coordinate in graph units

getYGraph

public int getYGraph(double y)
This method converts between scale and graph units for the y variable.

Parameters:
y - the y-coordinate in scale units
Returns:
the y-coordinate in graph units

getXScale

public double getXScale(int x)
This method converts between graph and scale units for the x variable.

Parameters:
x - the x-coordinate in graph units
Returns:
the x-coordinate in scale units.

getYScale

public double getYScale(int y)
This method converts between graph and scale units for the y variable.

Parameters:
y - the y-coordinate in graph units
Returns:
the y-coordinate in scale units

getXPixels

public int getXPixels(double x)
This method converts scale units to graph units for the x variable.

Parameters:
x - the value in scale units
Returns:
the value in graph units

getYPixels

public int getYPixels(double y)
This method converts scale units to graph units for the y variable.

Parameters:
y - the value in scale units
Returns:
the value in graph units

drawLine

public void drawLine(java.awt.Graphics g,
                     double x1,
                     double y1,
                     double x2,
                     double y2)
This method draws a line between (x1, y1) and (x2, y2), where the coordinates are in scale units.

Parameters:
x1 - the x-coordinate of the first point
x2 - the x-coordinate of the second point
y1 - the y-coordinate of the first point
y2 - the y-coordinate of the second point

drawTick

public void drawTick(java.awt.Graphics g,
                     double x,
                     double y,
                     int i,
                     int j,
                     int o)
This method draws a tick mark at a specified point (in scale units), a specified number of pixels in the positive and negative directions, with a specified orientation.

Parameters:
g - the graphics context
x - the x-coordinate of the point in scale units
y - the y-coordinate of the point in scale units
i - the size of the tick mark in the positive direction
j - the size of the tick mark in the negative direction
o - the orientation (HORIZONTAL or VERTICAL)

drawTick

public void drawTick(java.awt.Graphics g,
                     double x,
                     double y,
                     int o)
This method draws a tick mark at a specified point, 3 pixels in the each direction, with a specified oreintation.

Parameters:
g - the graphics context
x - the x-coordinate of the point in scale units
y - the y-coordinate of the point in scale units
o - the orientation (HORIZONTAL or VERTICAL)

drawLabel

public void drawLabel(java.awt.Graphics g,
                      java.lang.String s,
                      double x,
                      double y,
                      int o)
This method draws a sepcified label at a specified orientation next to a specified point.

Parameters:
g - the graphics context
s - the label
x - the x-coordinate of the point in scale units
y - the y-coordinate of the point in scale units
o - the orientation (LEFT, RIGHT, ABOVE, BELOW)

drawAxis

public void drawAxis(java.awt.Graphics g,
                     Domain d,
                     double c,
                     int o)
This method draws an axis corresponding to a sepcified domain at specified poisiton relative to the other variable, with a specified orientation. The type of domain (DISCRETE or CONTINUOUS) determines whether the midpoints or the bounds are indicated with tick marks.

Parameters:
g - the graphics context
d - the domain
c - the position relative to the other variable
o - the orientatin (HORIZONTAL or VERTICAL)

drawAxis

public void drawAxis(java.awt.Graphics g,
                     double a,
                     double b,
                     double w,
                     int t,
                     double c,
                     int o)
This method draws an axis corresponding to a sepcified domain at specified poisiton relative to the other variable, with a specified orientation. The type of domain (DISCRETE or CONTINUOUS) determines whether the midpoints or the bounds are indicated with tick marks.

Parameters:
g - the graphics context
a - the lower bound or value of the domain
b - the upper bound or value of the domain
w - the step size of the domain
t - the type of domain (DISCRETE or CONTINUOUS)
c - the position relative to the other variable
o - the orientation (HORIZONTAL or VERTICAL)

drawAxis

public void drawAxis(java.awt.Graphics g,
                     double a,
                     double b,
                     double w,
                     double c,
                     int o)
This method draws an axis corresponding to a specified continuous domain, at a specified position relative to the other variable, with a specified orientation.

Parameters:
g - the graphics context
a - the lower bound of the domain
b - the upper bound of the domain
w - the step size of the domain
c - the position relative to the other variable
o - the orientation

drawBox

public void drawBox(java.awt.Graphics g,
                    double x0,
                    double y0,
                    double x1,
                    double y1)
This method draws a box between the specified corner points in scale units.

Parameters:
g - the graphics context
x0 - the x-coordinate of the first point
y0 - the y-coordinate of the first point
x1 - the x-coordinate of the second point
y1 - the y-coordinate of the second point

fillBox

public void fillBox(java.awt.Graphics g,
                    double x0,
                    double y0,
                    double x1,
                    double y1)
This method fills a box between the specified corner points in scale units.

Parameters:
g - the graphics context
x0 - the x-coordinate of the first point
y0 - the y-coordinate of the first point
x1 - the x-coordinate of the second point
y1 - the y-coordinate of the second point

drawPoint

public void drawPoint(java.awt.Graphics g,
                      double x,
                      double y)
This method draws a point at the specified x and y coordinates (in scale units).

Parameters:
g - the graphics context
x - the x-coordinate
y - the y-coordinate

setPointSize

public void setPointSize(int n)
This method sets the point size (in pixels) for drawing points.

Parameters:
n - the point size

getPointSize

public int getPointSize()
This method returns the points size.

Returns:
the point size

drawBoxPlot

public void drawBoxPlot(java.awt.Graphics g,
                        double x,
                        double r,
                        int y)
The following method draws a symmetric, horizontal boxplot, centered at at a specified point with a specified radius (in scale units), at a specified vertical position in pixels.

Parameters:
g - the graphics context
x - the center of the boxplot
r - the radius of the boxplot
y - the vertical poistion of the boxplot

fillBoxPlot

public void fillBoxPlot(java.awt.Graphics g,
                        double x,
                        double r,
                        int y)
The following method fills a symmetric, horizontal boxplot, centered at a specified point, with a specified radius r (in scale units), at a specified vertical poisiton in pixels.

Parameters:
g - the graphics context
x - the center of the boxplot
r - the radius of the boxplot
y - the vertical position of the boxplot

drawBoxPlot

public void drawBoxPlot(java.awt.Graphics g,
                        double x1,
                        double x2,
                        double x3,
                        double x4,
                        double x5,
                        int y)
The following method draws a five-number, horizontal boxplot.

Parameters:
g - the graphics context
x1 - the minimum value
x2 - the lower quartile value
x3 - the median value
x4 - the upper quartile value
x5 - the maximum value
y - the vertical position in pixels.

fillBoxPlot

public void fillBoxPlot(java.awt.Graphics g,
                        double x1,
                        double x2,
                        double x3,
                        double x4,
                        double x5,
                        int y)
The following method fills a five-number, horizontal boxplot.

Parameters:
g - the graphics context
x1 - the minimum value
x2 - the lower quartile value
x3 - the median value
x4 - the upper quartile value
x5 - the maximum value
y - the vertical position in pixels.

drawBox

public void drawBox(java.awt.Graphics g,
                    int s,
                    double x,
                    double y,
                    double l,
                    int i,
                    int j)
This method draws a box at a specified point with a specified length and width. One dimension is given in scale units and the other in pixels.

Parameters:
g - the graphics context
s - the orientation (HORIZONTAL or VERTICAL)
x - the x-coordinate of the point (in scale units)
y - the y-coordinate of the point (in scale units)
l - the length in scale units
i - the width in the negative direction (in pixels)
j - the with in the positive direction (in pixels)

fillBox

public void fillBox(java.awt.Graphics g,
                    int s,
                    double x,
                    double y,
                    double l,
                    int i,
                    int j)
This method fills a box at a specified point with a specified length and width. One dimension is given in scale units and the other in pixels.

Parameters:
g - the graphics context
s - the orientation (HORIZONTAL or VERTICAL)
x - the x-coordinate of the point (in scale units)
y - the y-coordinate of the point (in scale units)
l - the length in scale units
i - the width in the negative direction (in pixels)
j - the with in the positive direction (in pixels)

drawCircle

public void drawCircle(java.awt.Graphics g,
                       double x,
                       double y,
                       double r)
This method draws a circle with a specified center and radius (in scale units).

Parameters:
g - the graphics context
x - the x-coordinate of the center
y - the y-coordinate of the center
r - the radius of the circle

fillCircle

public void fillCircle(java.awt.Graphics g,
                       double x,
                       double y,
                       double r)
This method fills a circle with a specified center and radius (in scale units).

Parameters:
g - the graphics context
x - the x-coordinate of the center
y - the y-coordinate of the center
r - the radius of the circle

format

public java.lang.String format(double x)
This method formats a specified number.

Parameters:
x - the number
Returns:
the formated number as a string