Class TrackCanvas

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Canvas
              |
              +--TrackCanvas

public class TrackCanvas
extends java.awt.Canvas
implements java.awt.event.MouseListener, java.awt.event.MouseMotionListener

See Also:
Serialized Form

Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Constructor Summary
TrackCanvas(java.awt.Frame parent, Track t, java.util.Observer observer)
          Initialize a new track canvas.
 
Method Summary
 java.awt.Point getMouseCoordinates()
          Returns the current mouse coordinates.
static int mapFieldCoords(float fx, float rangef, int rangex, float minf)
          Convert field coordinates to mouse coordinates.
 void mouseClicked(java.awt.event.MouseEvent e)
          Empty mouse clicked handler
 void mouseDragged(java.awt.event.MouseEvent e)
          Empty mouse dragged handler
 void mouseEntered(java.awt.event.MouseEvent e)
          Changes the cursor to a crosshair when the mouse enters the canvas.
 void mouseExited(java.awt.event.MouseEvent e)
          Changes the cursor back to the default cursor when the mouse exits the canvas.
 void mouseMoved(java.awt.event.MouseEvent e)
          Updates the current mouse position and the canvas's observer.
 void mousePressed(java.awt.event.MouseEvent e)
          Empty mouse pressed handler
 void mouseReleased(java.awt.event.MouseEvent e)
          Empty mouse released handler
 void paint(java.awt.Graphics g)
          Paint the image to the canvas
 void setTrack(Track t)
          Set the current track.
static float unmapMouseCoords(int mx, int rangex, float rangef, float minf)
          Convert mouse coordinates to field coordinates.
 void update(java.awt.Graphics g)
          Update the underlying image object
 
Methods inherited from class java.awt.Canvas
addNotify
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, 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, getHeight, getInputContext, getInputMethodRequests, getLocale, getLocation, getLocation, getLocationOnScreen, getMaximumSize, getMinimumSize, getName, getParent, getPeer, getPreferredSize, 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, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, remove, removeComponentListener, removeFocusListener, 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

TrackCanvas

public TrackCanvas(java.awt.Frame parent,
                   Track t,
                   java.util.Observer observer)
Initialize a new track canvas.
Parameters:
frame - the canvas's parent
t - the track object to render
observer - the object to notify for position updates
Method Detail

setTrack

public void setTrack(Track t)
Set the current track.
Parameters:
t - the track object to render

update

public void update(java.awt.Graphics g)
Update the underlying image object
Parameters:
g - the graphics object to update
Overrides:
update in class java.awt.Component

paint

public void paint(java.awt.Graphics g)
Paint the image to the canvas
Overrides:
paint in class java.awt.Canvas

unmapMouseCoords

public static float unmapMouseCoords(int mx,
                                     int rangex,
                                     float rangef,
                                     float minf)
Convert mouse coordinates to field coordinates.
Parameters:
mx - the mouse's x coordinate
rangex - the range of the mouse coordinates
rangef - the range of the field coordinates
minf - the minimum x field coordinates

mapFieldCoords

public static int mapFieldCoords(float fx,
                                 float rangef,
                                 int rangex,
                                 float minf)
Convert field coordinates to mouse coordinates.
Parameters:
fx - the field's x coordinate
rangef - the range of the field coordinates
rangex - the range of the mouse coordinates
minf - the minimum x field coordinates

getMouseCoordinates

public java.awt.Point getMouseCoordinates()
Returns the current mouse coordinates.

mouseMoved

public void mouseMoved(java.awt.event.MouseEvent e)
Updates the current mouse position and the canvas's observer.
Specified by:
mouseMoved in interface java.awt.event.MouseMotionListener
Parameters:
e - the event to process

mouseEntered

public void mouseEntered(java.awt.event.MouseEvent e)
Changes the cursor to a crosshair when the mouse enters the canvas.
Specified by:
mouseEntered in interface java.awt.event.MouseListener
Parameters:
e - the mouse entered event

mouseExited

public void mouseExited(java.awt.event.MouseEvent e)
Changes the cursor back to the default cursor when the mouse exits the canvas.
Specified by:
mouseExited in interface java.awt.event.MouseListener
Parameters:
e - the mouse exited event

mouseClicked

public void mouseClicked(java.awt.event.MouseEvent e)
Empty mouse clicked handler
Specified by:
mouseClicked in interface java.awt.event.MouseListener
Parameters:
e - the mouse clicked event

mouseDragged

public void mouseDragged(java.awt.event.MouseEvent e)
Empty mouse dragged handler
Specified by:
mouseDragged in interface java.awt.event.MouseMotionListener
Parameters:
e - the mouse dragged event

mouseReleased

public void mouseReleased(java.awt.event.MouseEvent e)
Empty mouse released handler
Specified by:
mouseReleased in interface java.awt.event.MouseListener
Parameters:
e - the mouse released event

mousePressed

public void mousePressed(java.awt.event.MouseEvent e)
Empty mouse pressed handler
Specified by:
mousePressed in interface java.awt.event.MouseListener
Parameters:
e - the mouse pressed event