aim4.gui

## Class Canvas

- java.lang.Object
- - java.awt.Component
  - - java.awt.Container
    - - javax.swing.JComponent
      - - javax.swing.JPanel
        - - aim4.gui.Canvas

- All Implemented Interfaces:
    ComponentListener, MouseListener, MouseMotionListener, MouseWheelListener, ImageObserver, MenuContainer, Serializable, EventListener, Accessible

      public class Canvas
      extends JPanel
      implements ComponentListener, MouseListener, MouseWheelListener, MouseMotionListener

  The Canvas is the visual area on which the Layout, IntersectionManagers, Vehicles, and so forth are drawn for the user to see.
  See Also:
    Serialized Form

- - ### Nested Class Summary

    - ### Nested classes/interfaces inherited from class javax.swing.JPanel

      `JPanel.AccessibleJPanel`

    - ### Nested classes/interfaces inherited from class javax.swing.JComponent

      `JComponent.AccessibleJComponent`

    - ### Nested classes/interfaces inherited from class java.awt.Container

      `Container.AccessibleAWTContainer`

    - ### Nested classes/interfaces inherited from class java.awt.Component

      `Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy`

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static Color` | `ASPHALT_COLOR` The color of the asphalt, if the image does not load properly.
    `static Color` | `BACKGROUND_COLOR` The color of the background
    `static Color` | `GRASS_COLOR` The color of the grass, if the image does not load properly.

    - ### 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.image.ImageObserver

      `ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `Canvas(Viewer viewer)` Create a new canvas.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `cleanUp()` Clean up the canvas
    `void` | `componentHidden(ComponentEvent e)`
    `void` | `componentMoved(ComponentEvent e)`
    `void` | `componentResized(ComponentEvent e)`
    `void` | `componentShown(ComponentEvent e)`
    `Point2D` | `getMapPosition(int screenPosX, int screenPosY)` Convert the position on screen to the position on the map.
    `void` | `highlightVehicle(int vin)` Highlight a particular vehicle.
    `void` | `initWithGivenMap(BasicMap basicMap)` Initialize the canvas with a given map.
    `void` | `mouseClicked(MouseEvent e)`
    `void` | `mouseDragged(MouseEvent e)`
    `void` | `mouseEntered(MouseEvent e)`
    `void` | `mouseExited(MouseEvent e)`
    `void` | `mouseMoved(MouseEvent e)`
    `void` | `mousePressed(MouseEvent e)`
    `void` | `mouseReleased(MouseEvent e)`
    `void` | `mouseWheelMoved(MouseWheelEvent e)`
    `void` | `paint(Graphics g)`
    `void` | `saveScreenShot(String outFileName)` Save the screen to a file in PNG format.
    `void` | `setIsShowIMDebugShapes(boolean useIMDebugShapes)` Set whether or not the canvas draws the IM shapes.
    `void` | `setIsShowSimulationTime(boolean b)` Set whether to show the simulation time.
    `void` | `setIsShowVin(boolean b)` Set whether to show the VIN numbers.
    `void` | `update()` Update the canvas to visualize the current state of simulation.

    - ### 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, 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, update`

    - ### 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, 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, transferFocusBackward, transferFocusUpCycle`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Field Detail

    - #### GRASS_COLOR

          public static final Color GRASS_COLOR

      The color of the grass, if the image does not load properly.

    - #### ASPHALT_COLOR

          public static final Color ASPHALT_COLOR

      The color of the asphalt, if the image does not load properly.

    - #### BACKGROUND_COLOR

          public static final Color BACKGROUND_COLOR

      The color of the background

  - ### Constructor Detail

    - #### Canvas

          public Canvas(Viewer viewer)

      Create a new canvas.
      Parameters:
        `viewer` - the viewer object

  - ### Method Detail

    - #### initWithGivenMap

          public void initWithGivenMap(BasicMap basicMap)

      Initialize the canvas with a given map.
      Parameters:
        `basicMap` - the layout the canvas will be visualizing

    - #### cleanUp

          public void cleanUp()

      Clean up the canvas

    - #### update

          public void update()

      Update the canvas to visualize the current state of simulation.

    - #### paint

          public void paint(Graphics g)

      Overrides:
        `paint` in class `JComponent`

    - #### componentHidden

          public void componentHidden(ComponentEvent e)

      Specified by:
        `componentHidden` in interface `ComponentListener`

    - #### componentMoved

          public void componentMoved(ComponentEvent e)

      Specified by:
        `componentMoved` in interface `ComponentListener`

    - #### componentResized

          public void componentResized(ComponentEvent e)

      Specified by:
        `componentResized` in interface `ComponentListener`

    - #### componentShown

          public void componentShown(ComponentEvent e)

      Specified by:
        `componentShown` in interface `ComponentListener`

    - #### mouseClicked

          public void mouseClicked(MouseEvent e)

      Specified by:
        `mouseClicked` in interface `MouseListener`

    - #### mouseEntered

          public void mouseEntered(MouseEvent e)

      Specified by:
        `mouseEntered` in interface `MouseListener`

    - #### mouseExited

          public void mouseExited(MouseEvent e)

      Specified by:
        `mouseExited` in interface `MouseListener`

    - #### mousePressed

          public void mousePressed(MouseEvent e)

      Specified by:
        `mousePressed` in interface `MouseListener`

    - #### mouseReleased

          public void mouseReleased(MouseEvent e)

      Specified by:
        `mouseReleased` in interface `MouseListener`

    - #### mouseWheelMoved

          public void mouseWheelMoved(MouseWheelEvent e)

      Specified by:
        `mouseWheelMoved` in interface `MouseWheelListener`

    - #### mouseDragged

          public void mouseDragged(MouseEvent e)

      Specified by:
        `mouseDragged` in interface `MouseMotionListener`

    - #### mouseMoved

          public void mouseMoved(MouseEvent e)

      Specified by:
        `mouseMoved` in interface `MouseMotionListener`

    - #### setIsShowSimulationTime

          public void setIsShowSimulationTime(boolean b)

      Set whether to show the simulation time.
      Parameters:
        `b` - whether to show the simulation time

    - #### setIsShowVin

          public void setIsShowVin(boolean b)

      Set whether to show the VIN numbers.
      Parameters:
        `b` - whether to show the VIN numbers

    - #### setIsShowIMDebugShapes

          public void setIsShowIMDebugShapes(boolean useIMDebugShapes)

      Set whether or not the canvas draws the IM shapes.
      Parameters:
        `useIMDebugShapes` - whether or not the canvas should draw the shapes

    - #### saveScreenShot

          public void saveScreenShot(String outFileName)

      Save the screen to a file in PNG format.
      Parameters:
        `outFileName` - the output file name

    - #### getMapPosition

          public Point2D getMapPosition(int screenPosX,
                               int screenPosY)

      Convert the position on screen to the position on the map.
      Parameters:
        `screenPosX` - The x-coordinate of the screen position
        `screenPosY` - The y-coordinate of the screen position
      Returns:
        The corresponding position on the map; null if there is no map

    - #### highlightVehicle

          public void highlightVehicle(int vin)

      Highlight a particular vehicle.
      Parameters:
        `vin` - the VIN number of the vehicle

Copyright © 2013. All rights reserved.