Class AbstractCanvas
- java.lang.Object
-
- java.awt.Component
-
- java.awt.Container
-
- javax.swing.JComponent
-
- javax.swing.JPanel
-
- com.singularsys.jepexamples.applets.AbstractCanvas
-
- All Implemented Interfaces:
java.awt.event.ComponentListener
,java.awt.event.KeyListener
,java.awt.event.MouseListener
,java.awt.event.MouseMotionListener
,java.awt.event.MouseWheelListener
,java.awt.image.ImageObserver
,java.awt.MenuContainer
,java.io.Serializable
,java.util.EventListener
,javax.accessibility.Accessible
- Direct Known Subclasses:
ComplexCanvas
,FunctionCanvas
,ImplicitCanvas
,ParametrisedCanvas
,PixelCanvas
public abstract class AbstractCanvas extends javax.swing.JPanel implements java.awt.event.MouseListener, java.awt.event.ComponentListener, java.awt.event.MouseWheelListener, java.awt.event.MouseMotionListener, java.awt.event.KeyListener
An abstract base class providing scaling and double buffering support for Canvas components. Scaling is such that the position of the origin on the screen does not change. Has methods for clearing background, painting axis, grid, scales and elapse time.- Author:
- Richard Morris
- See Also:
- Serialized Form
-
-
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
-
-
Field Summary
Fields Modifier and Type Field Description protected java.awt.Color
axisColor
Color for axisprotected java.awt.Color
bgColor
Color for backgroundprotected double
cenX
protected double
cenY
protected int
defaultOffX
protected int
defaultOffY
protected double
defaultScaleX
Default scale values, set in constructor used in resetprotected double
defaultScaleY
Default scale values, set in constructor used in resetprotected java.awt.Dimension
dimensions
Dimensions of the canvasprotected java.awt.Color
gridColor
Color for gridprotected java.awt.Color
labelColor
Color for labelsprotected java.awt.Font
labelFont
protected java.awt.Point
lastpos
protected int
offX
Offset of the graph in absolute coordsprotected int
offY
Offset of the graph in absolute coordsprotected javax.swing.JPopupMenu
popup
A popup menuprotected java.awt.Font
scaleFont
protected double
scaleX
Scaling of the graph in x and y directionsprotected double
scaleY
Scaling of the graph in x and y directionsprotected boolean
showGrid
Whether to show calculation timesprotected boolean
showScale
Whether to show scalesprotected boolean
showTime
Whether to show calculation timesprotected java.awt.image.BufferStrategy
strategy
BufferStratergy to use-
Fields inherited from class javax.swing.JComponent
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
-
-
Constructor Summary
Constructors Constructor Description AbstractCanvas()
Constructor using 1 for scaling and 0 for offset.AbstractCanvas(double sx, double sy, int offx, int offy)
Constructor specifying the default values for scaling and offset.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected void
center()
protected int
clipX(int xAbsolute)
Clip screen X values to lie within screenprotected int
clipY(int yAbsolute)
Clip screen Y values to lie within screenvoid
componentHidden(java.awt.event.ComponentEvent e)
void
componentMoved(java.awt.event.ComponentEvent e)
void
componentResized(java.awt.event.ComponentEvent e)
void
componentShown(java.awt.event.ComponentEvent e)
abstract void
dump()
Dump textual representation to System.outprotected abstract long
getNumPts()
The number of points which are calculatedint
getOffX()
int
getOffY()
javax.swing.JPopupMenu
getPopup()
A pop-up menu which subclasses can add items to.double
getScaleX()
double
getScaleY()
void
keyPressed(java.awt.event.KeyEvent e)
void
keyReleased(java.awt.event.KeyEvent e)
void
keyTyped(java.awt.event.KeyEvent e)
void
mouseClicked(java.awt.event.MouseEvent e)
void
mouseDragged(java.awt.event.MouseEvent e)
void
mouseEntered(java.awt.event.MouseEvent e)
void
mouseExited(java.awt.event.MouseEvent e)
void
mouseMoved(java.awt.event.MouseEvent e)
void
mousePressed(java.awt.event.MouseEvent e)
void
mouseReleased(java.awt.event.MouseEvent e)
void
mouseWheelMoved(java.awt.event.MouseWheelEvent e)
void
paint(java.awt.Graphics g)
Provides double buffering support and calls paintCanvas.protected void
paintAxes(java.awt.Graphics g)
Paints the axes for the graph.protected void
paintCanvas(java.awt.Graphics g)
Paint the canvas.protected abstract void
paintCurve(java.awt.Graphics g)
Paint the curveprotected void
paintGrid(java.awt.Graphics g)
protected void
paintScale(java.awt.Graphics g)
protected void
paintTime(java.awt.Graphics g, long t1, long t2)
Paints the elapse timeprotected void
paintWhite(java.awt.Graphics g)
Fills the background with white.protected void
rescaled()
Called when scale, or offset changed Default action is to call repaintvoid
reset()
void
resetCanvas()
protected void
resized()
Called when canvas sized changes Default action is to call repaintvoid
setOffset(int offX, int offY)
void
setScale(double scX, double scY)
void
shiftCanvas(int xdiff, int ydiff)
void
update(java.awt.Graphics g)
Just calls paint.protected int
xAbsolute(double xRelative)
Translates from scaled coordinates to screen coordinates.protected double
xRelative(int xAbsolute)
Translates from screen coordinates to scaled coordinates.protected int
yAbsolute(double yRelative)
Translates from scaled coordinates to screen coordinates.protected double
yRelative(int yAbsolute)
Translates from screen coordinates to scaled coordinates.void
zoomCanvas(double amount)
Zoom the canvas.-
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, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, 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
-
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, 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, 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, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, 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, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
-
-
-
Field Detail
-
bgColor
protected java.awt.Color bgColor
Color for background
-
labelColor
protected java.awt.Color labelColor
Color for labels
-
axisColor
protected java.awt.Color axisColor
Color for axis
-
gridColor
protected java.awt.Color gridColor
Color for grid
-
scaleFont
protected java.awt.Font scaleFont
-
labelFont
protected java.awt.Font labelFont
-
cenX
protected double cenX
-
cenY
protected double cenY
-
scaleX
protected double scaleX
Scaling of the graph in x and y directions
-
scaleY
protected double scaleY
Scaling of the graph in x and y directions
-
offX
protected int offX
Offset of the graph in absolute coords
-
offY
protected int offY
Offset of the graph in absolute coords
-
defaultScaleX
protected double defaultScaleX
Default scale values, set in constructor used in reset
-
defaultScaleY
protected double defaultScaleY
Default scale values, set in constructor used in reset
-
defaultOffX
protected int defaultOffX
-
defaultOffY
protected int defaultOffY
-
dimensions
protected java.awt.Dimension dimensions
Dimensions of the canvas
-
strategy
protected java.awt.image.BufferStrategy strategy
BufferStratergy to use
-
popup
protected javax.swing.JPopupMenu popup
A popup menu
-
showScale
protected boolean showScale
Whether to show scales
-
showGrid
protected boolean showGrid
Whether to show calculation times
-
showTime
protected boolean showTime
Whether to show calculation times
-
lastpos
protected java.awt.Point lastpos
-
-
Method Detail
-
center
protected void center()
-
dump
public abstract void dump()
Dump textual representation to System.out
-
rescaled
protected void rescaled()
Called when scale, or offset changed Default action is to call repaint
-
resized
protected void resized()
Called when canvas sized changes Default action is to call repaint
-
clipX
protected int clipX(int xAbsolute)
Clip screen X values to lie within screen
-
clipY
protected int clipY(int yAbsolute)
Clip screen Y values to lie within screen
-
xAbsolute
protected int xAbsolute(double xRelative)
Translates from scaled coordinates to screen coordinates.
-
yAbsolute
protected int yAbsolute(double yRelative)
Translates from scaled coordinates to screen coordinates.
-
xRelative
protected double xRelative(int xAbsolute)
Translates from screen coordinates to scaled coordinates.
-
yRelative
protected double yRelative(int yAbsolute)
Translates from screen coordinates to scaled coordinates.
-
getScaleX
public double getScaleX()
-
getScaleY
public double getScaleY()
-
setScale
public void setScale(double scX, double scY)
-
getOffX
public int getOffX()
-
getOffY
public int getOffY()
-
setOffset
public void setOffset(int offX, int offY)
-
reset
public void reset()
-
resetCanvas
public void resetCanvas()
-
zoomCanvas
public void zoomCanvas(double amount)
Zoom the canvas. The x, y scales are multiplied by 1+amount/10.- Parameters:
amount
-
-
shiftCanvas
public void shiftCanvas(int xdiff, int ydiff)
-
getPopup
public javax.swing.JPopupMenu getPopup()
A pop-up menu which subclasses can add items to.- Returns:
- the menu
-
update
public void update(java.awt.Graphics g)
Just calls paint. Eliminates background flicker problems with Canvas.update.- Overrides:
update
in classjavax.swing.JComponent
-
paint
public void paint(java.awt.Graphics g)
Provides double buffering support and calls paintCanvas. Subclasses should not override this method unless they want a different buffering strategy. Instead they should implement paintCanvas.- Overrides:
paint
in classjavax.swing.JComponent
- See Also:
paintCanvas(Graphics)
-
paintCanvas
protected void paintCanvas(java.awt.Graphics g)
Paint the canvas. Calls paintWhite(g); paintAxes(g); paintScale(g); paintGrid(g); paintCurve(g); and paintTime(g,t1,t2);- Parameters:
g
- the graphics object
-
paintCurve
protected abstract void paintCurve(java.awt.Graphics g)
Paint the curve- Parameters:
g
-
-
paintTime
protected void paintTime(java.awt.Graphics g, long t1, long t2)
Paints the elapse time- Parameters:
g
-t1
- start time in nano-secs.t2
- end time in nano-secs.
-
getNumPts
protected abstract long getNumPts()
The number of points which are calculated- Returns:
- the number of points
-
paintWhite
protected void paintWhite(java.awt.Graphics g)
Fills the background with white.
-
paintAxes
protected void paintAxes(java.awt.Graphics g)
Paints the axes for the graph.
-
paintScale
protected void paintScale(java.awt.Graphics g)
-
paintGrid
protected void paintGrid(java.awt.Graphics g)
-
componentHidden
public void componentHidden(java.awt.event.ComponentEvent e)
- Specified by:
componentHidden
in interfacejava.awt.event.ComponentListener
-
componentMoved
public void componentMoved(java.awt.event.ComponentEvent e)
- Specified by:
componentMoved
in interfacejava.awt.event.ComponentListener
-
componentShown
public void componentShown(java.awt.event.ComponentEvent e)
- Specified by:
componentShown
in interfacejava.awt.event.ComponentListener
-
componentResized
public void componentResized(java.awt.event.ComponentEvent e)
- Specified by:
componentResized
in interfacejava.awt.event.ComponentListener
-
mouseWheelMoved
public void mouseWheelMoved(java.awt.event.MouseWheelEvent e)
- Specified by:
mouseWheelMoved
in interfacejava.awt.event.MouseWheelListener
-
mousePressed
public void mousePressed(java.awt.event.MouseEvent e)
- Specified by:
mousePressed
in interfacejava.awt.event.MouseListener
-
mouseReleased
public void mouseReleased(java.awt.event.MouseEvent e)
- Specified by:
mouseReleased
in interfacejava.awt.event.MouseListener
-
mouseDragged
public void mouseDragged(java.awt.event.MouseEvent e)
- Specified by:
mouseDragged
in interfacejava.awt.event.MouseMotionListener
-
mouseMoved
public void mouseMoved(java.awt.event.MouseEvent e)
- Specified by:
mouseMoved
in interfacejava.awt.event.MouseMotionListener
-
mouseClicked
public void mouseClicked(java.awt.event.MouseEvent e)
- Specified by:
mouseClicked
in interfacejava.awt.event.MouseListener
-
mouseEntered
public void mouseEntered(java.awt.event.MouseEvent e)
- Specified by:
mouseEntered
in interfacejava.awt.event.MouseListener
-
mouseExited
public void mouseExited(java.awt.event.MouseEvent e)
- Specified by:
mouseExited
in interfacejava.awt.event.MouseListener
-
keyPressed
public void keyPressed(java.awt.event.KeyEvent e)
- Specified by:
keyPressed
in interfacejava.awt.event.KeyListener
-
keyReleased
public void keyReleased(java.awt.event.KeyEvent e)
- Specified by:
keyReleased
in interfacejava.awt.event.KeyListener
-
keyTyped
public void keyTyped(java.awt.event.KeyEvent e)
- Specified by:
keyTyped
in interfacejava.awt.event.KeyListener
-
-