|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.awt.Component java.awt.Container javax.swing.JComponent javax.swing.JPanel net.sourceforge.webcompmath.draw.DisplayCanvas
public class 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.
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 |
---|
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.print.Printable |
---|
NO_SUCH_PAGE, PAGE_EXISTS |
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. |
void |
addImpl(java.awt.Component c,
java.lang.Object constraints,
int index)
This method overrides Container.addImpl so that Eclipse VE will display Drawables properly. |
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 |
isCTRLRequired()
Get whether CTRL key is required for mouse zooms. |
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 |
paintComponent(java.awt.Graphics g)
Draw the contents of the DisplayCanvas. |
int |
print(java.awt.Graphics g,
java.awt.print.PageFormat pageFormat,
int pageIndex)
Print 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 |
setCTRLRequired(boolean CTRLRequired)
Set whether the CTRL key is required for mouse zooms. |
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. |
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, 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, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, 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, 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 |
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 setHandleMouseZooms(boolean handle)
handle
- true or falsepublic boolean getHandleMouseZooms()
public void add(Drawable d)
d
- the item to addpublic 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)
hmin
- 0 to 1hmax
- 0 to 1vmin
- 0 to 1vmax
- 0 to 1
public int addNewCoordinateRect(double hmin, double hmax, double vmin, double vmax, java.awt.Color background)
hmin
- 0 to 1hmax
- 0 to 1vmin
- 0 to 1vmax
- 0 to 1background
- background color
public CoordinateRect getCoordinateRect()
public CoordinateRect getCoordinateRect(int i)
i
- index of desired CoordinateRect
public CoordinateRect findCoordinateRectAt(int pixelX, int pixelY)
pixelX
- pixel horizontal locationpixelY
- pixel vertical location
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
c
- controller to notifypublic java.awt.Color getErrorBackground()
public void setErrorBackground(java.awt.Color c)
c
- error background colorpublic java.awt.Color getErrorForeground()
public void setErrorForeground(java.awt.Color c)
c
- error foreground colorpublic 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 javax.swing.JComponent
evt
- the event created when user presses or releases the mouse
buttonpublic void processMouseMotionEvent(java.awt.event.MouseEvent evt)
processMouseMotionEvent
in class javax.swing.JComponent
evt
- event created when user drags the mousepublic java.awt.Dimension getPreferredSize()
getPreferredSize
in class javax.swing.JComponent
public void paintComponent(java.awt.Graphics g)
paintComponent
in class javax.swing.JComponent
g
- graphics contextpublic void drawTemp(DrawTemp drawItem)
drawItem
- item to drawpublic 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.public void addImpl(java.awt.Component c, java.lang.Object constraints, int index)
addImpl
in class java.awt.Container
c
- constraints
- index
- public boolean isCTRLRequired()
public void setCTRLRequired(boolean CTRLRequired)
CTRLRequired
- true for required.public int print(java.awt.Graphics g, java.awt.print.PageFormat pageFormat, int pageIndex) throws java.awt.print.PrinterException
print
in interface java.awt.print.Printable
java.awt.print.PrinterException
Printable.print(java.awt.Graphics,
java.awt.print.PageFormat, int)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |