|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.awt.Component
java.awt.Canvas
galapagos.DrawingCanvas
public class DrawingCanvas
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 refReshing 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. Date Modified: Feb 24, 2009 Changed the array of DrawingController to List of DrawingController and removed the restriction of maximum number of DrawingController objects associated to this DrawingCanvas.
Nested Class Summary |
---|
Nested classes/interfaces inherited from class java.awt.Canvas |
---|
java.awt.Canvas.AccessibleAWTCanvas |
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 | |
---|---|
private int |
canvasHeight
The current height, in pixels, of the canvas. |
private int |
canvasWidth
The current width, in pixels, of the canvas. |
private int |
centerX
The x-coordinate of the point in the logical coordinate system that corresponds to the physical center of the canvas. |
private int |
centerY
The y-coordinate of the point in the logical coordinate system that corresponds to the physical center of the canvas. |
private double |
DEFAULT_UNIT
A class constant for the scaling factor, # of pixels per logical unit. |
private java.util.List<DrawingController> |
drawers
An array of objects that implements DrawingController interface. |
private boolean |
drawGrid
Set to true to draw grid lines. |
private java.awt.Graphics |
graphic
A Graphics object for this canvas. |
private int |
GRID_INTERVAL_FACTOR
A class constant for the number of logical units between the grid lines. |
private java.awt.Graphics |
offScreenGraphics
A Graphics object associated to the offscreen Image used for double-buffering. |
private java.awt.Image |
offScreenImage
An Image used for double-buffering. |
private int |
originX
The window's pixel coordinate value that corresponds to the x-coordinate of the origin (0,0). |
private int |
originY
The window's pixel coordinate value that corresponds to the y-coordinate of the origin (0,0). |
private static long |
serialVersionUID
|
private double |
unit
The current scaling factor value. |
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 | |
---|---|
DrawingCanvas()
A default constructor that creates an instance of the PlottingCanvas class. |
Method Summary | |
---|---|
void |
addOwner(DrawingController newdrawer)
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. |
private void |
drawAxis(java.awt.Graphics g)
Draws the X and Y axis in black if the grid lines are shown and in gray if the no grid lines are shown. |
private void |
drawContents(java.awt.Graphics g)
Asks the owner DrawingController objects to draw their contents |
private void |
drawGrids(java.awt.Graphics g)
Draws the grid lines in cyan. |
void |
drawPolygon(java.awt.Graphics g,
java.awt.Polygon polygon,
java.awt.Color color)
Draws the polygon in the specified color on Graphics g |
void |
drawText(java.awt.Graphics g,
java.awt.Color color,
int pensize,
Position position,
java.lang.String text)
Draws the text on the Graphics g in the specified color with pensize thickness at position location. |
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,
Position pt1,
Position pt2)
Draws a line between two points pt1 and pt2 on the parameter graphic in the specified color and pen size. |
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, 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, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAlignmentX, getAlignmentY, getBackground, getBaseline, getBaselineResizeBehavior, 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, getMousePosition, 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, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, 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, setMaximumSize, setMinimumSize, setName, setPreferredSize, 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 |
---|
private static final long serialVersionUID
private final double DEFAULT_UNIT
private final int GRID_INTERVAL_FACTOR
private java.awt.Graphics graphic
private int originX
private int originY
private int centerX
private int centerY
private double unit
private boolean drawGrid
private java.awt.Image offScreenImage
private java.awt.Graphics offScreenGraphics
private int canvasWidth
private int canvasHeight
private java.util.List<DrawingController> drawers
Constructor Detail |
---|
public DrawingCanvas()
Method Detail |
---|
public void addOwner(DrawingController newdrawer)
newdrawer
- A DrawingController that will draw its trajectory
on this canvas.public void clear()
public void drawPolygon(java.awt.Graphics g, java.awt.Polygon polygon, java.awt.Color color)
g
- polygon
- color
- public void drawText(java.awt.Graphics g, java.awt.Color color, int pensize, Position position, java.lang.String text)
g
- the Graphics to draw text oncolor
- the color of the penpensize
- the thickness of the penposition
- the position to draw the texttext
- the content to displaypublic void init()
public void paint(java.awt.Graphics g)
paint
in class java.awt.Canvas
g
- A Graphics object the painting takes place.public void plot(java.awt.Graphics graphic, java.awt.Color color, double size, Position pt1, Position pt2)
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.public void setGrid(boolean showGrid)
showGrid
- Pass 'true' to show the grid lines.public void setOrigin(int x, int y)
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.public void setUnit(double pixelsPerUnit)
pixelsPerUnit
- The scaling unit.public void update(java.awt.Graphics g)
update
in class java.awt.Canvas
g
- A Graphics object where the drawing takes place.private void drawAxis(java.awt.Graphics g)
g
- The Graphics object where the X and Y axis are drawn.private void drawContents(java.awt.Graphics g)
g
- The Graphics object where the contents are drawn.private void drawGrids(java.awt.Graphics g)
g
- The Graphics object where the grid lines are drawn.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |