gui
Class ChartComp

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--javax.swing.JComponent
                    |
                    +--javax.swing.JPanel
                          |
                          +--gui.ChartComp
All Implemented Interfaces:
javax.accessibility.Accessible, java.util.EventListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.awt.event.MouseListener, java.awt.event.MouseMotionListener, java.io.Serializable

public class ChartComp
extends javax.swing.JPanel
implements java.awt.event.MouseListener, java.awt.event.MouseMotionListener

This class is an extension of a JPanel. It's backgound is that of scale map corresponding to real world GPS coordinates. Agents are drawn on the JPanel, and can be dragged around the map. also wirelss ranges are drawn on each Agent if requested by the iSIM user.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes inherited from class javax.swing.JPanel
javax.swing.JPanel.AccessibleJPanel
 
Nested classes inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
private  util.ChartData chartdata
          The chart data that contains map display and gps information.
private  boolean clicked
          True if when user clicks to move an agent on map.
private  controller.Controller controller
          The controller of the simulation.
private  java.util.Date doubleclick
          A time for keeping track of double-clicking.
private  java.awt.Image img
          Holds the map image.
private  java.awt.Point pos
          The point of key/center agent for drawing.
private  gui.PropDialog propDialog
          A Dialog Window for display User information.
private  boolean ranges
          True if this JComponent is to display wireless ranges.
private  int x_offset
          Offset position on an agent when mouse-dragging.
private  int y_offset
          Offset position on an agent when mouse-dragging.
 
Fields inherited from class javax.swing.JPanel
 
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.Container
 
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
ChartComp(controller.Controller controller, boolean ranges)
          The constructor sets up mouse listeners and sets up its own variables with the given ones.
 
Method Summary
private  double diff(java.awt.Point p1, java.awt.Point p2)
          This method returns the pixel distance between two points.
(package private)  void draw(java.awt.Graphics g, java.util.Vector users, java.util.Vector points)
           
 util.ChartData getChartData()
          This method returns the chartdata kept inside this object used for turning pixel coordinates into real GPS coordinates.
 java.awt.Dimension getPreferredSize()
          This method returns our preferred size which should be the size of the map image that this object displays.
 void loadChart(java.lang.String name)
          This method loads new chart data, by first reading the given xml file which contains map name and reference point information.
 void mouseClicked(java.awt.event.MouseEvent e)
          This method checks for two kinds of mouse clicks.
 void mouseDragged(java.awt.event.MouseEvent e)
          This method is for moving an Agent around on the map.
 void mouseEntered(java.awt.event.MouseEvent e)
          This method not used.
 void mouseExited(java.awt.event.MouseEvent e)
          This method not used.
 void mouseMoved(java.awt.event.MouseEvent e)
          This method not used.
 void mousePressed(java.awt.event.MouseEvent e)
          This method is used to get the offset position when we click and drag an agent on the map.
 void mouseReleased(java.awt.event.MouseEvent e)
          This method lets the object know that the user has released from a mouse drag.
 void movePoint(int x, int y)
           
 void paint()
           
 void paint(java.awt.Graphics g)
           
 void plottPos(java.awt.Point pos, java.util.Vector users, java.util.Vector points)
           
 void readData(java.lang.String file_name)
          This method loads new chart data, by first reading the given xml file which contains map name and reference point information.
 void setRanges(boolean ranges)
          This method to tell this object whether or not it should paint the wireless range for each agent in the simulation.
 void timeOut()
           
 void update(java.awt.Graphics g)
           
 void updatePos(java.awt.Point pos, java.util.Vector users, java.util.Vector points)
           
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getGraphics, getHeight, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPropertyChangeListeners, getPropertyChangeListeners, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFont, setForeground, 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, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, 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, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, 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, processMouseEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, 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
 

Field Detail

controller

private controller.Controller controller
The controller of the simulation.


chartdata

private util.ChartData chartdata
The chart data that contains map display and gps information.


clicked

private boolean clicked
True if when user clicks to move an agent on map.


ranges

private boolean ranges
True if this JComponent is to display wireless ranges.


img

private java.awt.Image img
Holds the map image.


pos

private java.awt.Point pos
The point of key/center agent for drawing.


x_offset

private int x_offset
Offset position on an agent when mouse-dragging.


y_offset

private int y_offset
Offset position on an agent when mouse-dragging.


doubleclick

private java.util.Date doubleclick
A time for keeping track of double-clicking.


propDialog

private gui.PropDialog propDialog
A Dialog Window for display User information.

Constructor Detail

ChartComp

public ChartComp(controller.Controller controller,
                 boolean ranges)
The constructor sets up mouse listeners and sets up its own variables with the given ones.

Parameters:
controller - The controller of simulation.
ranges - True if displaying wireless ranges.
Method Detail

getPreferredSize

public java.awt.Dimension getPreferredSize()
This method returns our preferred size which should be the size of the map image that this object displays.

Overrides:
getPreferredSize in class javax.swing.JComponent
Returns:
Dimension The size of this JPanel with map image.

draw

void draw(java.awt.Graphics g,
          java.util.Vector users,
          java.util.Vector points)

plottPos

public void plottPos(java.awt.Point pos,
                     java.util.Vector users,
                     java.util.Vector points)

updatePos

public void updatePos(java.awt.Point pos,
                      java.util.Vector users,
                      java.util.Vector points)

movePoint

public void movePoint(int x,
                      int y)

timeOut

public void timeOut()

update

public void update(java.awt.Graphics g)
Overrides:
update in class javax.swing.JComponent

paint

public void paint()

paint

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

mouseClicked

public void mouseClicked(java.awt.event.MouseEvent e)
This method checks for two kinds of mouse clicks. If first checks for a right mouse click which is for rotating a user.(changing user's facing direction) This mehtod also checks for mouse left button double clicks. Based on the location of click and the timing, it will lauch a PropDialog for the User that was double clicked on.

Specified by:
mouseClicked in interface java.awt.event.MouseListener
Parameters:
e - The incoming MouseEvent containing button and point info.

mousePressed

public void mousePressed(java.awt.event.MouseEvent e)
This method is used to get the offset position when we click and drag an agent on the map. Offset is needed for correctly drawing the agent on the map.

Specified by:
mousePressed in interface java.awt.event.MouseListener
Parameters:
e - The incoming MouseEvent containing button and point info.

mouseReleased

public void mouseReleased(java.awt.event.MouseEvent e)
This method lets the object know that the user has released from a mouse drag. It sends a location change event, so that the location of the current user can be sent to the iPAQ application.

Specified by:
mouseReleased in interface java.awt.event.MouseListener
Parameters:
e - The incoming MouseEvent containing button and point info.

mouseDragged

public void mouseDragged(java.awt.event.MouseEvent e)
This method is for moving an Agent around on the map. It determines the closest Agent to the drag point, determines if that point is on an Agent, and then redraws the Agent to the new location based on offsets gotten from mousePressed method.

Specified by:
mouseDragged in interface java.awt.event.MouseMotionListener
Parameters:
e - The incoming MouseEvent containing button and point info.

mouseMoved

public void mouseMoved(java.awt.event.MouseEvent e)
This method not used.

Specified by:
mouseMoved in interface java.awt.event.MouseMotionListener
Parameters:
e -

mouseEntered

public void mouseEntered(java.awt.event.MouseEvent e)
This method not used.

Specified by:
mouseEntered in interface java.awt.event.MouseListener
Parameters:
e -

mouseExited

public void mouseExited(java.awt.event.MouseEvent e)
This method not used.

Specified by:
mouseExited in interface java.awt.event.MouseListener
Parameters:
e -

setRanges

public void setRanges(boolean ranges)
This method to tell this object whether or not it should paint the wireless range for each agent in the simulation.

Parameters:
ranges - True if want to show wireless ranges.

diff

private double diff(java.awt.Point p1,
                    java.awt.Point p2)
This method returns the pixel distance between two points.

Parameters:
p1 - The first point.
p2 - The second point.

getChartData

public util.ChartData getChartData()
This method returns the chartdata kept inside this object used for turning pixel coordinates into real GPS coordinates.

Returns:
ChartData The chart data used in this object to return.

loadChart

public void loadChart(java.lang.String name)
This method loads new chart data, by first reading the given xml file which contains map name and reference point information. Then the new ChartData will give us the map image to use.

Parameters:
name - file name for new data to use.

readData

public void readData(java.lang.String file_name)
This method loads new chart data, by first reading the given xml file which contains map name and reference point information.

Parameters:
file_name - Name of XML file that contains new ChartData info.