MATES 3.0-rc2

org.mates.ui.graphical
Class DefaultTopologyVisualizer

java.lang.Object
  extended byjava.awt.Component
      extended byjava.awt.Container
          extended byjavax.swing.JComponent
              extended byjavax.swing.JPanel
                  extended byorg.mates.ui.graphical.DefaultTopologyVisualizer
All Implemented Interfaces:
javax.accessibility.Accessible, java.util.EventListener, java.awt.image.ImageObserver, java.awt.MenuContainer, javax.swing.event.MouseInputListener, java.awt.event.MouseListener, java.awt.event.MouseMotionListener, java.io.Serializable, TopologyVisualizer

public class DefaultTopologyVisualizer
extends javax.swing.JPanel
implements javax.swing.event.MouseInputListener, TopologyVisualizer

JPanel that is used by default for drawing the topology. This class may be extended to have customized topology drawing. For an example of how to save a screenshot of the visualized topology, see TopologyVisualizer.

Author:
Evan Sultanik
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
protected  java.awt.Font host_font
          The font with which hosts' names are drawn.
protected  java.awt.Color host_highlight_color
          The color in which hosts are highlighted.
protected  java.awt.Color tool_tip_color
          The color in which a non-highlighted host's tooltip is drawn.
protected  int[] xlocation
          Contains the x coordinate of where each host is drawn in the graphics object.
protected  int[] ylocation
          Contains the y coordinate of where each host is drawn in the graphics object.
 
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
DefaultTopologyVisualizer()
          Constructs a new DefaultTopologyVisualizer.
 
Method Summary
 boolean getDrawRadioRanges()
          Returns whether or not radio ranges will be drawn.
 java.awt.Component getGUI()
          Returns the GUI component associated with this visualizer.
 Host getHostAt(int x, int y, int radius)
          Finds the host closest to a point.
 boolean getViewScale()
          Returns whether or not a scale is drawn for the topology.
 void highlightHost(Host host)
          Highlights a host in the topology.
 boolean isPainting()
          Returns true if and only if the topology is currently being painted.
 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 paint(java.awt.Graphics graphics)
          Paints the topology, using double-buffering.
 void paint(java.awt.Graphics graphics, boolean double_buffer)
          Paints the topology, with optional double-buffering.
protected  void paintHighlightToolTip(java.awt.Graphics graphics, java.lang.String text, int x, int y)
          Callback function for drawing a tool tip for a highlighted host.
protected  void paintHosts(java.awt.Graphics graphics, Topology topology, double[][] network)
          Callback function for drawing the hosts.
protected  void paintLinks(java.awt.Graphics graphics, Topology topology, double[][] network)
          Callback function for painting the links (i.e. edges) in the network.
protected  void paintRadioRanges(java.awt.Graphics graphics, Topology topology, double[][] network, Host tool_tip_host, Host highlighted_host)
          Callback function for drawing the radio ranges.
protected  void paintScale(java.awt.Graphics graphics, int width)
          Callback function for painting the "scale" legend on the topology.
protected  void paintToolTip(java.awt.Graphics graphics, java.lang.String text, int x, int y)
          Callback function for drawing a tool tip.
protected  void paintTopology(java.awt.Graphics g, int width, int height)
          Callback function for drawing the topology.
 void setDrawRadioRanges(boolean draw_radio_ranges)
          Sets whether or not radio ranges of hosts are drawn.
 void setSimulator(Simulator simulator)
          Sets the simulator associated with this visualizer.
 void setViewScale(boolean view_scale)
          Sets whether or not a scale is drawn for the topology.
 
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, getPreferredSize, 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, update
 
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

xlocation

protected int[] xlocation
Contains the x coordinate of where each host is drawn in the graphics object. May be null.


ylocation

protected int[] ylocation
Contains the y coordinate of where each host is drawn in the graphics object. May be null.


host_font

protected java.awt.Font host_font
The font with which hosts' names are drawn.


host_highlight_color

protected java.awt.Color host_highlight_color
The color in which hosts are highlighted. This is mainly used to draw hosts' tool tips.


tool_tip_color

protected java.awt.Color tool_tip_color
The color in which a non-highlighted host's tooltip is drawn.

Constructor Detail

DefaultTopologyVisualizer

public DefaultTopologyVisualizer()
Constructs a new DefaultTopologyVisualizer.

Method Detail

paint

public void paint(java.awt.Graphics graphics)
Description copied from interface: TopologyVisualizer
Paints the topology, using double-buffering. This should be equivalent to paint(graphics, true).

Specified by:
paint in interface TopologyVisualizer

paint

public void paint(java.awt.Graphics graphics,
                  boolean double_buffer)
Description copied from interface: TopologyVisualizer
Paints the topology, with optional double-buffering.

Specified by:
paint in interface TopologyVisualizer

mouseMoved

public void mouseMoved(java.awt.event.MouseEvent e)
Specified by:
mouseMoved in interface java.awt.event.MouseMotionListener

setViewScale

public void setViewScale(boolean view_scale)
Description copied from interface: TopologyVisualizer
Sets whether or not a scale is drawn for the topology.

Specified by:
setViewScale in interface TopologyVisualizer

setDrawRadioRanges

public void setDrawRadioRanges(boolean draw_radio_ranges)
Description copied from interface: TopologyVisualizer
Sets whether or not radio ranges of hosts are drawn.

Specified by:
setDrawRadioRanges in interface TopologyVisualizer

getDrawRadioRanges

public boolean getDrawRadioRanges()
Description copied from interface: TopologyVisualizer
Returns whether or not radio ranges will be drawn.

Specified by:
getDrawRadioRanges in interface TopologyVisualizer

getViewScale

public boolean getViewScale()
Description copied from interface: TopologyVisualizer
Returns whether or not a scale is drawn for the topology.

Specified by:
getViewScale in interface TopologyVisualizer

highlightHost

public void highlightHost(Host host)
Description copied from interface: TopologyVisualizer
Highlights a host in the topology. This will usually be called when a host is clicked or selected in the Hosts tab.

Specified by:
highlightHost in interface TopologyVisualizer

mouseDragged

public void mouseDragged(java.awt.event.MouseEvent e)
Specified by:
mouseDragged in interface java.awt.event.MouseMotionListener

mouseEntered

public void mouseEntered(java.awt.event.MouseEvent e)
Specified by:
mouseEntered in interface java.awt.event.MouseListener

mousePressed

public void mousePressed(java.awt.event.MouseEvent e)
Specified by:
mousePressed in interface java.awt.event.MouseListener

mouseReleased

public void mouseReleased(java.awt.event.MouseEvent e)
Specified by:
mouseReleased in interface java.awt.event.MouseListener

mouseClicked

public void mouseClicked(java.awt.event.MouseEvent e)
Specified by:
mouseClicked in interface java.awt.event.MouseListener

mouseExited

public void mouseExited(java.awt.event.MouseEvent e)
Specified by:
mouseExited in interface java.awt.event.MouseListener

isPainting

public boolean isPainting()
Description copied from interface: TopologyVisualizer
Returns true if and only if the topology is currently being painted.

Specified by:
isPainting in interface TopologyVisualizer

setSimulator

public void setSimulator(Simulator simulator)
Description copied from interface: TopologyVisualizer
Sets the simulator associated with this visualizer.

Specified by:
setSimulator in interface TopologyVisualizer

paintRadioRanges

protected void paintRadioRanges(java.awt.Graphics graphics,
                                Topology topology,
                                double[][] network,
                                Host tool_tip_host,
                                Host highlighted_host)
Callback function for drawing the radio ranges. This implementation calls Host.paintRadioRange(java.awt.Graphics, boolean, boolean) for each host in the network.

Parameters:
tool_tip_host - the host for which a tool tip is to be drawn; may be null.
highlighted_host - the currently-highlighted host; may be null.

paintHosts

protected void paintHosts(java.awt.Graphics graphics,
                          Topology topology,
                          double[][] network)
Callback function for drawing the hosts. This implementation calls Host.paint(java.awt.Graphics) for each host in the network.


paintLinks

protected void paintLinks(java.awt.Graphics graphics,
                          Topology topology,
                          double[][] network)
Callback function for painting the links (i.e. edges) in the network. This implementation draws each edge with an alpha value proportional to link strength (i.e. the lower the link strength the more transparent the edge). Edges on which an agent is currently in transit are painted blue.


paintToolTip

protected void paintToolTip(java.awt.Graphics graphics,
                            java.lang.String text,
                            int x,
                            int y)
Callback function for drawing a tool tip.


paintHighlightToolTip

protected void paintHighlightToolTip(java.awt.Graphics graphics,
                                     java.lang.String text,
                                     int x,
                                     int y)
Callback function for drawing a tool tip for a highlighted host.


paintScale

protected void paintScale(java.awt.Graphics graphics,
                          int width)
Callback function for painting the "scale" legend on the topology.

Parameters:
width - the width of the topology being painted.

paintTopology

protected void paintTopology(java.awt.Graphics g,
                             int width,
                             int height)
Callback function for drawing the topology. This function draws the topology by issuing the following callbacks (in order):


getHostAt

public Host getHostAt(int x,
                      int y,
                      int radius)
Finds the host closest to a point. If more than one host is equidistant from the point, only one is returned.

Specified by:
getHostAt in interface TopologyVisualizer
Returns:
the host closest to the point (x, y), within a radius of radius pixels. Returns null if no such host exists.

getGUI

public java.awt.Component getGUI()
Description copied from interface: TopologyVisualizer
Returns the GUI component associated with this visualizer. Usually, this component will be a JFrame.

Specified by:
getGUI in interface TopologyVisualizer

MATES 3.0-rc2

Submit a bug or request a feature
http://mates.sourceforge.net/

Copyright 2004 Evan Sultanik