viceroy.GUI
Class GraphPanel

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--javax.swing.JComponent
                    |
                    +--javax.swing.JPanel
                          |
                          +--viceroy.GUI.GraphPanel
All Implemented Interfaces:
javax.accessibility.Accessible, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable

public class GraphPanel
extends javax.swing.JPanel

This class actually displays the graph. Each node is assigned a virtual position starting from 0,0 and continuing down. The actual paint() function iterates through all the nodes and draws them.

Since:
1.45
Author:
Anat Talmy
, Oren Dobzinski
See Also:
Serialized Form

Nested Class Summary
 class GraphPanel.MouseHandler
          handles the mouse events sent on the panel
(package private)  class GraphPanel.PoolObject
          a pool object
 
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 static int ARROWHEAD_SIZE
          size (in pixels of the arrow head size)
static int BFS_BUILDMODE
           
private  int buildMode
          BFS/DFS/RING/LINE
private  int curMode
          Current mode we are using
static int DEFAULT_LINE_LENGTH
          defualt line length
private  int depthLevel
          The depth we will enter in the recursion for displaying child nodes.
static int DFS_BUILDMODE
           
private  boolean doingLookup
          If we are on a lookup request
static int LINE_BUILDMODE
          Modes for the building the graph
static java.awt.Color[] LINE_COLOR_MAP
          colors
private  int lineLength
          line length
private  java.util.List listeners
          A vector of listener classes implementing the GraphElementListener interface
private static org.apache.log4j.Logger logger
           
private  MessagePath lookupPath
          The path that a lookup message has gone through
private  java.lang.String lookupVal
          The value to lookup
private  int maxHeight
          Used to determine the max.
private  int maxWidth
          Used to determine the max.
private  java.util.Map nextInRow
           
private  java.util.Map nodes
          Hashtable of all the nodes traveresed.
private  int numberOfNodes
          How many nodes to add
static double PEER_RADIUS
          Peer radios
static int RING_BUILDMODE
           
static int RING_CENTER_X
          ring center x
static int RING_CENTER_Y
          ring center y
static int RING_RADIUS
          the radius of the ring
private  int ringRadius
          ring radius
private  ViewController root
          Root node to display
private  boolean showConnections
          if true, will always display the edges between nodes
private static int SIZE
          size (in pixels) of a single node
private  boolean stickyDisplay
          After clicking a node, its exit lines will be colored in light-gray, its input in gray.
private  ViewController stickyNode
          Will hold the node that was last clicked
private static int X_MARGIN
          margin to keep from sides of window
private static int Y_MARGIN
           
private  double zoomRatio
          display zoomRatio
 
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
GraphPanel()
          constructs the panel
 
Method Summary
 void addListener(GraphElementListener listener)
          Adds a listener
private  void addNodeToTableLine(ViewController node)
          Add node and all his children to the ring table
private  void addNodeToTableRing(ViewController node)
          Add node and all his children to the ring table
(package private)  void addToTableBFS(ViewController node, int y)
          Adds noses as in BFS form: the level defines the node's row
(package private)  void addToTableDFS(ViewController node, int y)
          Adds a node to the hashtable
 void buildGraph(ViewController root)
          Will re-build the graph for the specified root
 java.awt.Dimension calculateNodePosOnLine(ViewController node)
          Calculates a node position on the ring sorted by its id
 java.awt.Dimension calculateNodePosOnRing(ViewController node)
          Calculates a node position on the ring sorted by its id
(package private)  void drawArrowLine(java.awt.Graphics g, int x0, int y0, int x1, int y1)
          Draws a line from (x0,y0) to (x1, y1) and adds an arrow head to the line's end.
 void drawLinesFrom(java.awt.Graphics g, java.lang.Object node, java.awt.Color lineColor)
          Draws all the edges leaving a certain node
 void drawLinesTo(java.awt.Graphics g, java.lang.Object baseNode, java.awt.Color lineColor)
          Draws all the edges entering a certain node
 void drawNode(java.awt.Graphics g, java.lang.Object node, int x, int y, int w, int h)
          Draws the node in the specified place
(package private)  void drawStickyNodeFrame(java.awt.Graphics g, java.lang.Object stickyNode, java.awt.Color c)
          Handles sticky
(package private)  void fireClicked(java.lang.Object node)
          Triggers the GraphElementClicked event on all listeners
(package private)  void fireDoubleClicked(java.lang.Object node)
          Triggers the GraphElementDoubleClicked event on all listeners
(package private)  void fireReleased()
          Triggers the GraphElementReleased event on all listeners
(package private)  int getArrowHeadSize()
          Return the size of the arrow head
 int getBuildMode()
          Gets the build mode
private static java.awt.Color getColorByType(LookupState state)
          Gets a color by a node's type
 int getDepthLevel()
          Gets the depth level
(package private)  int getElementSize()
          Returns the number of pixels each element takes in the current display ratio
 java.lang.String getLookupVal()
          Gets the lookup value
 int getMode()
          Gets the mode
(package private)  int getNextInRow(int y)
          Get next available col in a given row, and updates the lastInRow vector
(package private)  ViewController getNodeFromPoint(int x, int y)
          Returns the node at a givel (pixel) coordinate
 int getNumberOfNodes()
          Gets the number of nodes
 java.lang.Object getRoot()
          gets the root
 boolean getShowConnections()
          Gets the connections
 boolean getStickyDisplay()
          Gets the sticky display
 java.lang.Object getStickyNode()
          Gets the sticky node
 double getZoomRatio()
          Gets the zoom ratio
 void paint(java.awt.Graphics g)
          Paint
 void refresh()
          Refresh
 void removeNode(ViewController node)
          Removes a node from the list of nodes
 void setBuildMode(int buildMode)
          Sets the build mode
 void setDepthLevel(int depthLevel)
          Sets the depth level
 void setDoingLookup(boolean lookup)
          Sets the lookup field
 void setLookupPath(MessagePath path)
          Sets the lookup path
 void setLookupVal(java.lang.String val)
          Sets the lookup value
 void setMode(int mode)
          Sets the mode
 void setNumberOfNodes(int num)
          Sets the number of nodes
 void setRingRadius(int radius)
          Sets the ring radius
 void setShowConnections(boolean showConnections)
          Sets the connections
 void setStickyDisplay(boolean stickyDisplay)
           
 void setZoomRatio(double ratio)
          Sets the zoom ratio
(package private)  int xPos(int x)
          Returns the pixel x-position of the input coordinate
(package private)  int yPos(int y)
          Returns the pixel x-position of the input coordinate
 
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

logger

private static final org.apache.log4j.Logger logger

SIZE

private static final int SIZE
size (in pixels) of a single node

See Also:
Constant Field Values

ARROWHEAD_SIZE

private static final int ARROWHEAD_SIZE
size (in pixels of the arrow head size)

See Also:
Constant Field Values

X_MARGIN

private static final int X_MARGIN
margin to keep from sides of window

See Also:
Constant Field Values

Y_MARGIN

private static final int Y_MARGIN
See Also:
Constant Field Values

RING_RADIUS

public static final int RING_RADIUS
the radius of the ring

See Also:
Constant Field Values

PEER_RADIUS

public static final double PEER_RADIUS
Peer radios

See Also:
Constant Field Values

RING_CENTER_X

public static final int RING_CENTER_X
ring center x

See Also:
Constant Field Values

RING_CENTER_Y

public static final int RING_CENTER_Y
ring center y

See Also:
Constant Field Values

DEFAULT_LINE_LENGTH

public static final int DEFAULT_LINE_LENGTH
defualt line length

See Also:
Constant Field Values

ringRadius

private int ringRadius
ring radius


lineLength

private int lineLength
line length


zoomRatio

private double zoomRatio
display zoomRatio


nodes

private java.util.Map nodes
Hashtable of all the nodes traveresed. Data contains a Dimension Object which contains the actual position of the node (col/row)


root

private ViewController root
Root node to display


showConnections

private boolean showConnections
if true, will always display the edges between nodes


stickyDisplay

private boolean stickyDisplay
After clicking a node, its exit lines will be colored in light-gray, its input in gray. if stickyDisplay is true releasing the mouse button will not turn off this coloring


stickyNode

private ViewController stickyNode
Will hold the node that was last clicked


listeners

private java.util.List listeners
A vector of listener classes implementing the GraphElementListener interface


maxWidth

private int maxWidth
Used to determine the max. size needed by the graph viewer to display all the nodes


maxHeight

private int maxHeight
Used to determine the max. size needed by the graph viewer to display all the nodes


depthLevel

private int depthLevel
The depth we will enter in the recursion for displaying child nodes. 0 means infinity. Note will not enter an infinit loop if the graph has loops


curMode

private int curMode
Current mode we are using


buildMode

private int buildMode
BFS/DFS/RING/LINE


numberOfNodes

private int numberOfNodes
How many nodes to add


lookupVal

private java.lang.String lookupVal
The value to lookup


lookupPath

private MessagePath lookupPath
The path that a lookup message has gone through


doingLookup

private boolean doingLookup
If we are on a lookup request


LINE_BUILDMODE

public static final int LINE_BUILDMODE
Modes for the building the graph

See Also:
Constant Field Values

RING_BUILDMODE

public static final int RING_BUILDMODE
See Also:
Constant Field Values

BFS_BUILDMODE

public static final int BFS_BUILDMODE
See Also:
Constant Field Values

DFS_BUILDMODE

public static final int DFS_BUILDMODE
See Also:
Constant Field Values

LINE_COLOR_MAP

public static final java.awt.Color[] LINE_COLOR_MAP
colors


nextInRow

private java.util.Map nextInRow
Constructor Detail

GraphPanel

public GraphPanel()
constructs the panel

Method Detail

setNumberOfNodes

public void setNumberOfNodes(int num)
Sets the number of nodes

Parameters:
num -

setDoingLookup

public void setDoingLookup(boolean lookup)
Sets the lookup field

Parameters:
lookup -

setLookupPath

public void setLookupPath(MessagePath path)
Sets the lookup path

Parameters:
path -

getNumberOfNodes

public int getNumberOfNodes()
Gets the number of nodes

Returns:

setLookupVal

public void setLookupVal(java.lang.String val)
Sets the lookup value

Parameters:
val -

getLookupVal

public java.lang.String getLookupVal()
Gets the lookup value


xPos

int xPos(int x)
Returns the pixel x-position of the input coordinate

Parameters:
x - the x coordinate
Returns:

yPos

int yPos(int y)
Returns the pixel x-position of the input coordinate

Parameters:
y - the x coordinate
Returns:

getElementSize

int getElementSize()
Returns the number of pixels each element takes in the current display ratio

Returns:

getArrowHeadSize

int getArrowHeadSize()
Return the size of the arrow head

Returns:

getNodeFromPoint

ViewController getNodeFromPoint(int x,
                                int y)
Returns the node at a givel (pixel) coordinate

Parameters:
x -
y -
Returns:

getNextInRow

int getNextInRow(int y)
Get next available col in a given row, and updates the lastInRow vector

Parameters:
y - row to check on
Returns:

addToTableBFS

void addToTableBFS(ViewController node,
                   int y)
Adds noses as in BFS form: the level defines the node's row

Parameters:
node -
y -

addNodeToTableRing

private void addNodeToTableRing(ViewController node)
Add node and all his children to the ring table

Parameters:
node -

addNodeToTableLine

private void addNodeToTableLine(ViewController node)
Add node and all his children to the ring table

Parameters:
node -

addToTableDFS

void addToTableDFS(ViewController node,
                   int y)
Adds a node to the hashtable

Parameters:
node -
y -

drawStickyNodeFrame

void drawStickyNodeFrame(java.awt.Graphics g,
                         java.lang.Object stickyNode,
                         java.awt.Color c)
Handles sticky

Parameters:
g -
stickyNode -
c -

drawArrowLine

void drawArrowLine(java.awt.Graphics g,
                   int x0,
                   int y0,
                   int x1,
                   int y1)
Draws a line from (x0,y0) to (x1, y1) and adds an arrow head to the line's end.

Parameters:
g -
x0 -
y0 -
x1 -
y1 -

drawLinesFrom

public void drawLinesFrom(java.awt.Graphics g,
                          java.lang.Object node,
                          java.awt.Color lineColor)
Draws all the edges leaving a certain node

Parameters:
g -
node -

getColorByType

private static java.awt.Color getColorByType(LookupState state)
Gets a color by a node's type

Parameters:
state -
Returns:

drawLinesTo

public void drawLinesTo(java.awt.Graphics g,
                        java.lang.Object baseNode,
                        java.awt.Color lineColor)
Draws all the edges entering a certain node

Parameters:
g -

drawNode

public void drawNode(java.awt.Graphics g,
                     java.lang.Object node,
                     int x,
                     int y,
                     int w,
                     int h)
Draws the node in the specified place

Parameters:
g -
node -
x -
y -
w -
h -

paint

public void paint(java.awt.Graphics g)
Paint

Overrides:
paint in class javax.swing.JComponent
Parameters:
g -

fireClicked

void fireClicked(java.lang.Object node)
Triggers the GraphElementClicked event on all listeners

Parameters:
node -

fireReleased

void fireReleased()
Triggers the GraphElementReleased event on all listeners


fireDoubleClicked

void fireDoubleClicked(java.lang.Object node)
Triggers the GraphElementDoubleClicked event on all listeners

Parameters:
node -

addListener

public void addListener(GraphElementListener listener)
Adds a listener

Parameters:
listener -

buildGraph

public void buildGraph(ViewController root)
Will re-build the graph for the specified root

Parameters:
root - element to set as root

refresh

public void refresh()
Refresh


setShowConnections

public void setShowConnections(boolean showConnections)
Sets the connections

Parameters:
showConnections -

getShowConnections

public boolean getShowConnections()
Gets the connections

Returns:

setStickyDisplay

public void setStickyDisplay(boolean stickyDisplay)

getStickyDisplay

public boolean getStickyDisplay()
Gets the sticky display

Returns:

setDepthLevel

public void setDepthLevel(int depthLevel)
Sets the depth level

Parameters:
depthLevel -

getDepthLevel

public int getDepthLevel()
Gets the depth level


getRoot

public java.lang.Object getRoot()
gets the root


setMode

public void setMode(int mode)
Sets the mode

Parameters:
mode -

getMode

public int getMode()
Gets the mode


getZoomRatio

public double getZoomRatio()
Gets the zoom ratio

Returns:

setZoomRatio

public void setZoomRatio(double ratio)
Sets the zoom ratio

Returns:

setRingRadius

public void setRingRadius(int radius)
Sets the ring radius

Parameters:
radius -

setBuildMode

public void setBuildMode(int buildMode)
Sets the build mode

Parameters:
buildMode -

getBuildMode

public int getBuildMode()
Gets the build mode

Returns:

getStickyNode

public java.lang.Object getStickyNode()
Gets the sticky node

Returns:

removeNode

public void removeNode(ViewController node)
Removes a node from the list of nodes

Parameters:
node - the node to be removes

calculateNodePosOnRing

public java.awt.Dimension calculateNodePosOnRing(ViewController node)
Calculates a node position on the ring sorted by its id

Returns:

calculateNodePosOnLine

public java.awt.Dimension calculateNodePosOnLine(ViewController node)
Calculates a node position on the ring sorted by its id

Returns: