maslab.vis
Class VisCanvas

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by maslab.vis.VisCanvas
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable

public class VisCanvas
extends javax.swing.JComponent

Draws VisObjects and implements navigational controls

See Also:
Serialized Form

Nested Class Summary
static class VisCanvas.POSITION
          Determine whether to add an object to the top or bottom.
static class VisCanvas.ZOOM
           
 
Nested classes/interfaces inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Field Summary
 java.awt.Color backgroundColor
           
 double cx
           
 double cy
           
static double DEFAULTSCALE
           
static double FASTZOOMSPEED
           
 java.awt.Color gridColor
           
 double gridLineSpacing
           
 double gridLineWidthPx
           
static double MAXZOOM
           
static double MINZOOM
           
static double PANAMOUNT
           
static double PANAMOUNTFAST
           
static double ROTATEAMOUNT
           
 double scale
           
 double theta
           
 
Fields inherited from class javax.swing.JComponent
TOOL_TIP_TEXT_KEY, 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.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
VisCanvas()
          Create a new canvas
 
Method Summary
 void add(VisObject vo)
          Add a new mutable object on top of existing objects.
 void add(VisObject vo, VisCanvas.POSITION pos)
          Add a new mutable object at the specified layer
 void addBuffered(VisObject vo)
          Add an object to the back buffer.
 void addBuffered(VisObject vo, VisCanvas.POSITION pos)
           
 void addEventListener(VisCanvasEventListener el)
          Add a listener to receive notification whenever an unhandled user interface event occurs.
 void addImmutable(VisObject vo)
           
 void addImmutable(VisObject vo, VisCanvas.POSITION pos)
          Add a new immutable object (one which does not have to be redrawn) at the specified layer.
 void addMutable(VisObject vo, VisCanvas.POSITION pos)
          Add a new mutable object at the specified layer
 void addViewChangeListener(VisCanvasViewChangeListener vcvcl)
          Add a listener to receive notification whenever the view of this canvas is changed.
 void clear()
           
 void draw()
          Call this method, rather than repaint(), to schedule a redraw.
 void drawNow()
          Cause a repaint() ASAP, without regard for the maximum frame rate
 void drawSync()
           
 java.awt.Font getFont(java.lang.String family, int type, double heightm)
          Create a font with the appropriate affine transform for the canvas.
 double getScale()
          The current scale of the display, in pixels per unit (meter).
 void goHome()
          Restore the view to the start-up default.
 boolean handleKeyPress(java.awt.event.KeyEvent e)
           
 void paint(java.awt.Graphics gin)
           
 java.awt.image.BufferedImage paintIntoImage(int width, int height)
          Render the display into a new BufferedImage object of the requested width and height.
 java.awt.image.BufferedImage paintIntoImageScale(int width, int height)
          Render the current display into an image of width and height, zooming in as much as possible while displaying an area at least as large as is currently displayed.
 void paintObjects(java.awt.image.BufferedImage bi, java.awt.Graphics2D g, java.util.ArrayList<VisObject> objects)
          Paint objects into a graphics context.
 void pan(double right, double down, boolean fast)
           
 void rotateLeft()
           
 void rotateRight()
           
 void setCenter(double cx, double cy)
          Move the center of the display to the specified coordinates.
 void setGreedyFocus(boolean enable)
          Set whether the canvas should steal the focus whenver the mouse hovers over it.
 void setMaximumFrameRate(double fps)
          Set the maximum redraw rate.
 void showHotKeys()
           
 void switchBuffer()
          Make all objects added via addBuffered since last call to switchBuffer() visible, and discard the objects that were added before.
 void synchronizeView(VisCanvas vc)
          Cause this VisCanvas's view to follow another VisCanvas's view.
 void zoom(VisCanvas.ZOOM dir, boolean fast)
           
 void zoom(VisCanvas.ZOOM dir, int mousex, int mousey, boolean fast)
           
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, getAccessibleContext, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, 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, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paintImmediately, paintImmediately, print, printAll, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, 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, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update, updateUI
 
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, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusBackward, transferFocusDownCycle, validate
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, contains, createImage, createImage, createVolatileImage, createVolatileImage, dispatchEvent, enable, enableInputMethods, 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, 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
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULTSCALE

public static double DEFAULTSCALE

cx

public double cx

cy

public double cy

scale

public double scale

theta

public double theta

gridColor

public java.awt.Color gridColor

backgroundColor

public java.awt.Color backgroundColor

gridLineWidthPx

public double gridLineWidthPx

gridLineSpacing

public double gridLineSpacing

MAXZOOM

public static final double MAXZOOM
See Also:
Constant Field Values

MINZOOM

public static final double MINZOOM
See Also:
Constant Field Values

FASTZOOMSPEED

public static final double FASTZOOMSPEED
See Also:
Constant Field Values

PANAMOUNT

public static final double PANAMOUNT
See Also:
Constant Field Values

PANAMOUNTFAST

public static final double PANAMOUNTFAST
See Also:
Constant Field Values

ROTATEAMOUNT

public static final double ROTATEAMOUNT
See Also:
Constant Field Values
Constructor Detail

VisCanvas

public VisCanvas()
Create a new canvas

Method Detail

addViewChangeListener

public void addViewChangeListener(VisCanvasViewChangeListener vcvcl)
Add a listener to receive notification whenever the view of this canvas is changed.


addEventListener

public void addEventListener(VisCanvasEventListener el)
Add a listener to receive notification whenever an unhandled user interface event occurs.


synchronizeView

public void synchronizeView(VisCanvas vc)
Cause this VisCanvas's view to follow another VisCanvas's view. It is safe to form circular loops.


setGreedyFocus

public void setGreedyFocus(boolean enable)
Set whether the canvas should steal the focus whenver the mouse hovers over it.


addBuffered

public void addBuffered(VisObject vo)
Add an object to the back buffer. Will not become visible until switchBuffer() is called.


addBuffered

public void addBuffered(VisObject vo,
                        VisCanvas.POSITION pos)

switchBuffer

public void switchBuffer()
Make all objects added via addBuffered since last call to switchBuffer() visible, and discard the objects that were added before. i.e., this is used for double buffering an animation.


clear

public void clear()

add

public void add(VisObject vo)
Add a new mutable object on top of existing objects.


draw

public void draw()
Call this method, rather than repaint(), to schedule a redraw. This method enforces a maximum frame rate.


drawNow

public void drawNow()
Cause a repaint() ASAP, without regard for the maximum frame rate


drawSync

public void drawSync()

add

public void add(VisObject vo,
                VisCanvas.POSITION pos)
Add a new mutable object at the specified layer


addMutable

public void addMutable(VisObject vo,
                       VisCanvas.POSITION pos)
Add a new mutable object at the specified layer


addImmutable

public void addImmutable(VisObject vo)

addImmutable

public void addImmutable(VisObject vo,
                         VisCanvas.POSITION pos)
Add a new immutable object (one which does not have to be redrawn) at the specified layer.


setCenter

public void setCenter(double cx,
                      double cy)
Move the center of the display to the specified coordinates.


zoom

public void zoom(VisCanvas.ZOOM dir,
                 boolean fast)

zoom

public void zoom(VisCanvas.ZOOM dir,
                 int mousex,
                 int mousey,
                 boolean fast)

goHome

public void goHome()
Restore the view to the start-up default.


pan

public void pan(double right,
                double down,
                boolean fast)

rotateRight

public void rotateRight()

rotateLeft

public void rotateLeft()

handleKeyPress

public boolean handleKeyPress(java.awt.event.KeyEvent e)

showHotKeys

public void showHotKeys()

paint

public void paint(java.awt.Graphics gin)
Overrides:
paint in class javax.swing.JComponent

paintIntoImageScale

public java.awt.image.BufferedImage paintIntoImageScale(int width,
                                                        int height)
Render the current display into an image of width and height, zooming in as much as possible while displaying an area at least as large as is currently displayed.


paintIntoImage

public java.awt.image.BufferedImage paintIntoImage(int width,
                                                   int height)
Render the display into a new BufferedImage object of the requested width and height. The current cx, cy, theta are used.


paintObjects

public void paintObjects(java.awt.image.BufferedImage bi,
                         java.awt.Graphics2D g,
                         java.util.ArrayList<VisObject> objects)
Paint objects into a graphics context.


getFont

public java.awt.Font getFont(java.lang.String family,
                             int type,
                             double heightm)
Create a font with the appropriate affine transform for the canvas. This is intended to be used by VisObjects that want to draw text.

Parameters:
family - e.g. "Helvetica"
type - e.g. Font.PLAIN
heightm - The height of the font, in meters.
Returns:
A font of the specified family/type with the correct transformation matrix.

setMaximumFrameRate

public void setMaximumFrameRate(double fps)
Set the maximum redraw rate. It is typically limited to ensure that we don't needlessly redraw the screen.

Parameters:
fps - The maximum frame rate.

getScale

public double getScale()
The current scale of the display, in pixels per unit (meter).