ciips.animation
Class Histogram

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--java.awt.Panel
                    |
                    +--ciips.animation.Histogram
All Implemented Interfaces:
javax.accessibility.Accessible, DrawingObj, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable

public class Histogram
extends java.awt.Panel
implements DrawingObj

This is one example of the drawing object inheriting java.awt.Panel which can be added to the drawing panel (DrawingPanel).

Since DrawingPanel is also an extension of panel, this Histogram panel has to be added to the drawing panel by using the following statement (otherwise, the layout manager of this class might interprete its dimension as null during the panel initialization and nothing will show up):

	Histogram histogram = new Histogram();
	drawingPanel.setLayout(null);
	drawingPanel.add(histogram);
 	...
	histogram.setTitle("title");
	histogram.setXLabel("x-axis label");
	histogram.setYLabel("y-axis label");
	histogram.setYMax(maxY);
	histogram.setXMax(maxX);
 	histogram.setYStep(10);
	histogram.setXStep(5);
	histogram.reshape(x, y, width, height);
 
drawingPanel is an instance of the class object DrawingPanel, which can be typically obtained from the instance of AlgAnimFrame, by calling the getDrawingPanel() method of the class. e.g. in AlgThread, the instance of AlgAnimFrame is passed in as frame. Therefore,
 	drawingPanel = frame.getDrawingPanel();
 
The reshape method is inherited from a parent class. It is called to move the histogram to position (x, y) and set the dimension of the histogram to width x height.

See Also:
DrawingPanel, AlgAnimFrame, Panel, Serialized Form

Inner classes inherited from class java.awt.Panel
java.awt.Panel.AccessibleAWTPanel
 
Inner classes inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Inner classes inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent
 
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
Histogram()
          A constructor to this class which set the background of the panel to white, font to size 12 PLAIN courier, and initializes the title, x-axis label, y-axis label, etc.
 
Method Summary
 void draw(java.awt.Graphics g)
          Same as paint().
 int getX()
          Get the left most position of the panel.
 int getY()
          Get the top most position of the panel.
 void incValueX(int x)
          Increment the Y value of vertical bar specified by the parameter.
 void init()
          Initialize the histogram, removing all bars from the graph.
 void paint(java.awt.Graphics g)
          Method to draw objects on the histogram panel.
 void setTitle(java.lang.String title)
          Set a title for the histogram.
 void setValueXY(int x, int y)
          Set the Y value for the vertical bar at the specified X position.
 void setXLabel(java.lang.String xLabel)
          Set a title for the x-axis.
 void setXMax(int xMax)
          Set the maximum value for the x-axis of the histogram.
 void setXMin(int xMin)
          Set the minimum value for the x-axis of the histogram.
 void setXStep(int step)
          Set the incremental step for the x-axis of the histogram.
 void setYLabel(java.lang.String yLabel)
          Set a title for the y-axis of the histogram.
 void setYMax(int yMax)
          Set the maximum value for the y-axis of the histogram.
 void setYMin(int yMin)
          Set the minimum value for the y-axis of the histogram.
 void setYStep(int step)
          Set the incremental step for the y-axis.
 void update(java.awt.Graphics g)
          This method is invoked when the repaint() method is called.
 
Methods inherited from class java.awt.Panel
addNotify, getAccessibleContext
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getInsets, getLayout, getListeners, getMaximumSize, getMinimumSize, getPreferredSize, insets, invalidate, isAncestorOf, layout, list, list, locate, minimumSize, paintComponents, paramString, preferredSize, print, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, removeNotify, setFont, setLayout, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addPropertyChangeListener, addPropertyChangeListener, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, getBackground, getBounds, getBounds, getColorModel, getComponentOrientation, getCursor, getDropTarget, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getInputContext, getInputMethodRequests, getLocale, getLocation, getLocation, getLocationOnScreen, getName, getParent, getPeer, getSize, getSize, getToolkit, getTreeLock, getWidth, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isDisplayable, isDoubleBuffered, isEnabled, isFocusTraversable, isLightweight, isOpaque, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setForeground, setLocale, setLocation, setLocation, setName, setSize, setSize, setVisible, show, show, size, toString, transferFocus
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface ciips.animation.DrawingObj
move
 

Constructor Detail

Histogram

public Histogram()
A constructor to this class which set the background of the panel to white, font to size 12 PLAIN courier, and initializes the title, x-axis label, y-axis label, etc. Note that although the initial background color is set to white, it can be changed at any time after this contructor is called by using the setBackground method inherited. e.g.
	Histogram histogram = new Histogram();
	histogram.setBackground(Color.lightGray);
 
For detail of what color can be set, refer to java.awt.Color.
Method Detail

init

public void init()
Initialize the histogram, removing all bars from the graph.

getX

public int getX()
Get the left most position of the panel.
Specified by:
getX in interface DrawingObj
Overrides:
getX in class java.awt.Component
Returns:
The x-coordinate of the top-left position of the histogram.

getY

public int getY()
Get the top most position of the panel.
Specified by:
getY in interface DrawingObj
Overrides:
getY in class java.awt.Component
Returns:
The y-coordinate of the top-left position of the histogram.

setTitle

public void setTitle(java.lang.String title)
Set a title for the histogram.
Parameters:
title - The new title of the histogram.

setXLabel

public void setXLabel(java.lang.String xLabel)
Set a title for the x-axis.
Parameters:
xLabel - new title for the x-axis of the histogram.

setYLabel

public void setYLabel(java.lang.String yLabel)
Set a title for the y-axis of the histogram.
Parameters:
yLabel - new title for the y-axis of the histogram.

setYMax

public void setYMax(int yMax)
Set the maximum value for the y-axis of the histogram.
Parameters:
yMax - The maximum value for the y-axis of the histogram.

setYStep

public void setYStep(int step)
Set the incremental step for the y-axis. For example, if the minimum value of the y-axis is 0, and this incremental step is set to 5, then the value 0, 5, 10, 15, 20, ... will be displayed on the y-axis of the histogram.
Parameters:
step - The incremental step for the y-axis of the histogram.

setYMin

public void setYMin(int yMin)
Set the minimum value for the y-axis of the histogram.
Parameters:
yMin - The new minimum value for the y-axis of the histogram.

setXMax

public void setXMax(int xMax)
Set the maximum value for the x-axis of the histogram.
Parameters:
xMax - The maximum value for the x-axis of the histogram.

setXStep

public void setXStep(int step)
Set the incremental step for the x-axis of the histogram.
Parameters:
step - The new incremental step for the x-axis of the histogram.
See Also:
setYStep(int)

setXMin

public void setXMin(int xMin)
Set the minimum value for the x-axis of the histogram.
Parameters:
xMin - The new minimum value for the x-axis of the histogram.

setValueXY

public void setValueXY(int x,
                       int y)
Set the Y value for the vertical bar at the specified X position. If the x or y value specified in the parameter is larger than the maximum x or y value, the maximum value will be set to the specified value + 1.
Parameters:
x - The vertical bar at X = x

y - The value of the vertical bar specified by the first parameter.

incValueX

public void incValueX(int x)
Increment the Y value of vertical bar specified by the parameter. Initially, all x values are set to zero. If the x-value does not exist in the hashtable governing the histogram, it will be added.
Parameters:
x - Specifies the vertical bar at X = x.

update

public void update(java.awt.Graphics g)
This method is invoked when the repaint() method is called. The update method is override here to eleminate flashing during the updating of the histogram panel.
Overrides:
update in class java.awt.Container

draw

public void draw(java.awt.Graphics g)
Same as paint(). This method just calls the paint() method. It must be defined here to implement the DrawingObj interface.
Specified by:
draw in interface DrawingObj
See Also:
paint(java.awt.Graphics)

paint

public void paint(java.awt.Graphics g)
Method to draw objects on the histogram panel.
Overrides:
paint in class java.awt.Container