galapagos
Class DrawingCanvas

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Canvas
              |
              +--galapagos.DrawingCanvas

public class DrawingCanvas
extends java.awt.Canvas

Generic Canvas descendant object for drawing lines. This object does not have any intelligence or memory. This object can have zero or more drawers who will be notified when the component refeshing is needed. This object will pass the Graphics object to the associated DrawingController objects. The notified controllers can then draw whatever they want on the passed Graphics object.

See Also:
Serialized Form

Field Summary
protected  int EMPTY
          A class constant for denoting an empty list.
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Constructor Summary
DrawingCanvas()
          A default constructor that creates an instance of the PlottingCanvas class.
 
Method Summary
 void addOwner(galapagos.DrawingController owner)
          A mutator method that adds another DrawingController that will draw its trajectory on this canvas.
 void clear()
          Erases the current contents of the PlottingCanvas by painting the whole canvas with the background color.
 void drawPolygon(java.awt.Graphics g, java.awt.Polygon polygon, java.awt.Color color)
           
 void init()
          Initializes the necessary objects for double-buffering drawing.
 void paint(java.awt.Graphics g)
          Painting of the canvas is done by drawing the whole contents using the double-buffering technique.
 void plot(java.awt.Graphics graphic, java.awt.Color color, double size, galapagos.Position pt1, galapagos.Position pt2)
          Draws a line between two points pt1 and pt2 on the parameter graphic.
 void setGrid(boolean showGrid)
          A mutator method that sets the flag for drawing the grid lines.
 void setOrigin(int x, int y)
          A mutator method that sets the origin point.
 void setUnit(double pixelsPerUnit)
          A mutator method that sets the scaling factor.
 void update(java.awt.Graphics g)
          Overrides the inherited update so no refreshing is done.
 
Methods inherited from class java.awt.Canvas
addNotify
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addPropertyChangeListener, addPropertyChangeListener, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, deliverEvent, disable, disableEvents, dispatchEvent, doLayout, enable, enable, enableEvents, enableInputMethods, firePropertyChange, getAlignmentX, getAlignmentY, getBackground, getBounds, getBounds, getColorModel, getComponentAt, getComponentAt, getComponentOrientation, getCursor, getDropTarget, getFont, getFontMetrics, getForeground, getGraphics, getHeight, getInputContext, getInputMethodRequests, getLocale, getLocation, getLocation, getLocationOnScreen, getMaximumSize, getMinimumSize, getName, getParent, getPeer, getPreferredSize, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, invalidate, isDisplayable, isDoubleBuffered, isEnabled, isFocusTraversable, 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, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, remove, removeComponentListener, removeFocusListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFont, setForeground, setLocale, setLocation, setLocation, setName, setSize, setSize, setVisible, show, show, size, toString, transferFocus, validate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

EMPTY

protected final int EMPTY
A class constant for denoting an empty list.
Constructor Detail

DrawingCanvas

public DrawingCanvas()
A default constructor that creates an instance of the PlottingCanvas class. Grid lines are drawn, the center position of the canvas is set to (0,0) of the logical (user) coordinate, and the scaling unit is set to the default size defined by the constance DEFAULT_UNIT.
Method Detail

addOwner

public void addOwner(galapagos.DrawingController owner)
A mutator method that adds another DrawingController that will draw its trajectory on this canvas.
Parameters:
owner - A DrawingController that will draw its trajectory on this canvas.

clear

public void clear()
Erases the current contents of the PlottingCanvas by painting the whole canvas with the background color.

init

public void init()
Initializes the necessary objects for double-buffering drawing. Gets the size information of the canvas, which is necessary later in translating logical coordinates into the window's pixel coordinates for drawing. For the drawing to occur correctly, this method MUST be called after the container object (e.g. Frame) that contains this canvas is shown and before a drawing method of this canvas is called.

drawPolygon

public void drawPolygon(java.awt.Graphics g,
                        java.awt.Polygon polygon,
                        java.awt.Color color)

paint

public void paint(java.awt.Graphics g)
Painting of the canvas is done by drawing the whole contents using the double-buffering technique.
Overrides:
paint in class java.awt.Canvas
Parameters:
graphic - A Graphics object the painting takes place.

plot

public void plot(java.awt.Graphics graphic,
                 java.awt.Color color,
                 double size,
                 galapagos.Position pt1,
                 galapagos.Position pt2)
Draws a line between two points pt1 and pt2 on the parameter graphic. This method is intended for drawing the trajectory of a robot. One call to this method draws a line between to points on the trajectory.
Parameters:
graphic - A Graphics object where the line is drawn.
color - A color used to draw the line.
size - The pen size.
pt1 - The starting point of the line.
pt2 - The ending point of the line.

setGrid

public void setGrid(boolean showGrid)
A mutator method that sets the flag for drawing the grid lines. Passing true will make the grid lines to appear.
Parameters:
showGrid - Pass 'true' to show the grid lines.

setOrigin

public void setOrigin(int x,
                      int y)
A mutator method that sets the origin point. The parameter (x,y) specifies the point in the logical coordinate system that corresponds to the physical center position of the canvas. By default, the center of the canvas represents the point (0,0) of the logical coordinate system. For example, if you pass 100 and 200 for the x and y parameters, the logical coordinate center point is shifted 100 units to the left and 200 units down.
Parameters:
x - The x-coordinate of a logical point that corresponds to the center of the canvas.
y - The y-coordinate of a logical point that corresponds to the center of the canvas.

setUnit

public void setUnit(double pixelsPerUnit)
A mutator method that sets the scaling factor. The default scaling is 2 pixels per single logical unit. Increase the number for a more zoomed view and decrease the number for a more zoomed out view.
Parameters:
pixelsPerUnit - The scaling unit.

update

public void update(java.awt.Graphics g)
Overrides the inherited update so no refreshing is done. Since double-buffering is used, new image is drawn over the old one without erasing the old one. This technique avoids flickering. NOTE: do not call this method directly.
Overrides:
update in class java.awt.Component
Parameters:
g - A Graphics object where the drawing takes place.