|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.awt.Component | +--java.awt.Canvas | +--edu.hws.jcm.draw.DisplayCanvas
A DisplayCanvas is a drawing area that can contain one or more CoordinateRects. Each CoordinateRect can, in turn, contain Drawable items. If you only want one CoordinateRect that fills the whole canvas, you can for the most part ignore the CoordinateRect and work only with the canvas. The option of using an offscreen image for double buffering is provided. By default, this option is on.
If a DisplayCanvas is added to a Controller, then it will take care of calling the checkInput() and compute() methods of the InputObjects and Computables that it contains, so there is no need to add them individually to the Controller. If the DisplayCanvas is added to a JCMPanel, it is automatically added to the Controller for that JCMPanel. (On the other hand, if a DisplayCanvas is added to a Controller, this means that all the items in the DisplayCanvas will be recomputed, even if only some of them need to be.)
The canvas can display an error message that goes away when the canvas is clicked or when clearErrorMessage() is called. This allows the Canvas to be used as an ErrorReporter for a Controller or LimitControlPanel.
When any changes are made to the contents of the Canvas, doRedraw() must be called for those changes to take effect. Normally, doRedraw() is called by the CoordinateRect or by one of the Drawables in a CoordinateRect. Use doRedraw(CoordinateRect c) or doRedraw(int index) to redraw a single CoordinateRect. Note that repainting the canvas is not enough, because this will not automatically refresh the off-screen image.
Inner classes inherited from class java.awt.Canvas |
java.awt.Canvas.AccessibleAWTCanvas |
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 | |
DisplayCanvas()
Create a DisplayCanvas with a white background containing no CoordinateRects. |
|
DisplayCanvas(CoordinateRect c)
Create a DisplayCanvas with a white background and containing the specified CoordinateRect. |
Method Summary | |
void |
add(Drawable d)
Add the specified Drawable item to the first CoordinateRect in this DisplayCanvas. |
void |
add(Drawable d,
int coordRectIndex)
Add a Drawable item to one of the CoordinateRects associated with the Canvas. |
void |
addCoordinateRect(CoordinateRect c)
Add the specified CoordinateRect to this DisplayCanvas, filling the entire canvas, and with background color equal to the background color of the canvas. |
void |
addCoordinateRect(CoordinateRect coords,
double hmin,
double hmax,
double vmin,
double vmax,
java.awt.Color background)
Add a CoordinateRect to the canvas, occupying a specified region of the canvas. |
int |
addNewCoordinateRect(double hmin,
double hmax,
double vmin,
double vmax)
Add a newly created CoordinateRect covering the specified section of the canvas. |
int |
addNewCoordinateRect(double hmin,
double hmax,
double vmin,
double vmax,
java.awt.Color background)
Add a newly created CoordinateRect covering the specified section of the canvas, with the specfied background color. |
void |
checkInput()
This is generally called by a Controller. |
void |
clearErrorMessage()
Clear the error message, if any, that is currently displayed on the canvas. |
void |
compute()
This is generally called by a Controller. |
void |
doRedraw()
Should be called whenever the contents of the canvas have changed and so it needs to need to be redrawn. |
void |
doRedraw(CoordinateRect coords)
To be called when the contents of one of the CordinateRects have changed and so it needs to need to be redrawn. |
void |
doRedraw(int coordRectIndex)
To be called when the contents of one of the CordinateRects have changed and so it needs to need to be redrawn. |
void |
drawTemp(DrawTemp drawItem)
Draws the specified item in the first CoordinateRect in this canvas. |
void |
drawTemp(DrawTemp drawItem,
int coordRectIndex)
Draws the specified item in the specified CoordinateRect in this canvas. |
CoordinateRect |
findCoordinateRectAt(int pixelX,
int pixelY)
Return CoordinateRect that contains the specified pixel, or null if there is none. |
CoordinateRect |
getCoordinateRect()
Get the first CoordinateRect in this canvas. |
CoordinateRect |
getCoordinateRect(int i)
Get the i-th CoordinateRect in this DisplayCanvas. |
java.awt.Color |
getErrorBackground()
Get color that is used as a background when the canvas displays an error message. |
java.awt.Color |
getErrorForeground()
Get color that is used for the text when the canvas displays an error message. |
java.lang.String |
getErrorMessage()
Get the error message that is currently displayed on the canvas. |
boolean |
getHandleMouseZooms()
Get the "handleMouseZooms" property of this DisplayCanvas, which determines whether the canvas reacts to mouse events by zooming the CoordinateRect that is clicked. |
java.awt.Dimension |
getPreferredSize()
This has been overridden to return a default size of 350-by-350 pixels. |
boolean |
getUseOffscreenCanvas()
Set the "useOffscreenCanvas" property of this DisplayCanvas. |
void |
notifyControllerOnChange(Controller c)
Method required by InputObject interface; in this class, calls the same method recursively on any CoordinateRects contained in this DisplayCanvas. |
void |
paint(java.awt.Graphics g)
Draw the contents of the DisplayCanvas. |
void |
processMouseEvent(java.awt.event.MouseEvent evt)
This has been overridden to handle the mouse zoom feature. |
void |
processMouseMotionEvent(java.awt.event.MouseEvent evt)
This has been overridden to handle the mouse zoom feature. |
void |
releaseResources()
Release the memory used the by the off-screen image, if any, that is used for double-buffering. |
void |
setErrorBackground(java.awt.Color c)
Set color to be used as a background when the canvas displays an error message. |
void |
setErrorForeground(java.awt.Color c)
Set color to be used for the text when the canvas displays an error message. |
void |
setErrorMessage(Controller c,
java.lang.String message)
Set an error message to be displayed on the canvas. |
void |
setHandleMouseZooms(boolean handle)
Set the "handleMouseZooms" property of this DisplayCanvas. |
void |
setUseOffscreenCanvas(boolean use)
Get the "useOffscreenCanvas" property of this DisplayCanvas, which determines whether double-buffering is used. |
void |
update(java.awt.Graphics g)
This has been overridden to implemnt double-buffering. |
Methods inherited from class java.awt.Canvas |
addNotify, getAccessibleContext |
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, 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, getGraphicsConfiguration, getHeight, getInputContext, getInputMethodRequests, getListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMaximumSize, getMinimumSize, getName, getParent, getPeer, 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, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, 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 |
Constructor Detail |
public DisplayCanvas()
public DisplayCanvas(CoordinateRect c)
c
- The CoordinateRect that will fill the canvas. If c is null, no CoordinateRect is added to the canvas.Method Detail |
public void releaseResources()
public void setHandleMouseZooms(boolean handle)
public boolean getHandleMouseZooms()
public boolean getUseOffscreenCanvas()
public void setUseOffscreenCanvas(boolean use)
public void add(Drawable d)
public void add(Drawable d, int coordRectIndex)
d
- The Drawable item to be added to a CoordinateRectcoordRectIndex
- The index of the CoordinateRect, where the index of the first
CoordinateRect that was added to the cavas is zero, the index of the second is one,
and so on. A CoordinateRect with the specified index must already exist in the
canvas, or an IllegalArgumentException is thrown.public void addCoordinateRect(CoordinateRect c)
c
- the CoordinateRect to be added. If null, an IllegalArgumentException is thrown.public void addCoordinateRect(CoordinateRect coords, double hmin, double hmax, double vmin, double vmax, java.awt.Color background)
coords
- The CoordinateRect to be added. If this is null, an IllegalArgumentExceptionis thrown.hmin
- Specifies the left edge of the CoordinateRect in the canvas, as a fraction of the size of the canvas.
This must be in the range form 0 to 1, or an IllegalArgumentException is thrown.hmax
- Specifies the right edge of the CoordinateRect in the canvas, as a fraction of the size of the canvas.
This must be in the range form 0 to 1 and must be strictly greater than hmin, or an IllegalArgumentException is thrown.vmin
- Specifies the top edge of the CoordinateRect in the canvas, as a fraction of the size of the canvas.
This must be in the range form 0 to 1, or an IllegalArgumentException is thrown.vmax
- Specifies the bottom edge of the CoordinateRect in the canvas, as a fraction of the size of the canvas.
This must be in the range form 0 to 1 and must be strictly greater than vmin, or an IllegalArgumentException is thrown.background
- The background color of the CoordinateRect. The CoordinateRect is filled with this color
before the Drawables that it contains are drawn. If background is null, no filling takes place
and the canvas shows through.public int addNewCoordinateRect(double hmin, double hmax, double vmin, double vmax)
public int addNewCoordinateRect(double hmin, double hmax, double vmin, double vmax, java.awt.Color background)
public CoordinateRect getCoordinateRect()
public CoordinateRect getCoordinateRect(int i)
public CoordinateRect findCoordinateRectAt(int pixelX, int pixelY)
public void doRedraw()
public void doRedraw(int coordRectIndex)
coordRectIndex
- The index of the CoordinateRect to be redrawn, where the first CoordinateRect is at index zero.
If there is no such CoordinateRect, then nothing is done.public void doRedraw(CoordinateRect coords)
coords
- The CoordinateRect to be redrawn. If coords is not in this DisplayCanvas, nothing is done.public void checkInput()
checkInput
in interface InputObject
public void compute()
compute
in interface Computable
public void notifyControllerOnChange(Controller c)
notifyControllerOnChange
in interface InputObject
public java.awt.Color getErrorBackground()
public void setErrorBackground(java.awt.Color c)
public java.awt.Color getErrorForeground()
public void setErrorForeground(java.awt.Color c)
public java.lang.String getErrorMessage()
getErrorMessage
in interface ErrorReporter
public void setErrorMessage(Controller c, java.lang.String message)
setErrorMessage
in interface ErrorReporter
c
- The Controller, if any, that is calling this routine. This controller will be notified
when the error message is cleared. If the method is not being called by a contrller, this
parameter should be set to null.message
- The error message to be displayed. If the value is null or is a blank string,
the current message, if any, is cleared.public void clearErrorMessage()
clearErrorMessage
in interface ErrorReporter
public void processMouseEvent(java.awt.event.MouseEvent evt)
processMouseEvent
in class java.awt.Component
public void processMouseMotionEvent(java.awt.event.MouseEvent evt)
processMouseMotionEvent
in class java.awt.Component
public java.awt.Dimension getPreferredSize()
getPreferredSize
in class java.awt.Component
public void update(java.awt.Graphics g)
update
in class java.awt.Component
public void paint(java.awt.Graphics g)
paint
in class java.awt.Canvas
public void drawTemp(DrawTemp drawItem)
public void drawTemp(DrawTemp drawItem, int coordRectIndex)
drawItem
- The non-null object that is to be drawncoordRectIndex
- The index of the CoordinateRect in which it
is to be drawn, where the index of the fist CoordinateRect
added to the canvas is zero, and so on. If there is
no CoordinateRect with the specified index, an IllegalArgumentException
is thrown.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |