edu.hawaii.ics.yucheng
Class GraphBox

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JPanel
                  extended by edu.hawaii.ics.yucheng.GraphBox
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, javax.accessibility.Accessible

 class GraphBox
extends javax.swing.JPanel

A component that displays a graph and possibly a solution.


Nested Class Summary
(package private)  class GraphBox.Delegate
          A class that shows information about the loaded graph through a popup window.
private static class GraphBox.Theme
          A collection of colors, fonts, and strokes.
 
Nested classes/interfaces inherited from class javax.swing.JPanel
javax.swing.JPanel.AccessibleJPanel
 
Nested classes/interfaces inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
private static int MAX_DISPLAYED_EDGES
          The maximum number of edges displayed.
private  java.awt.Dimension myCachedSize
           
(package private)  Graph myGraph
          The displayed graph.
private  javax.swing.JLabel myHelpIcon
           
private  float myMaxWeight
           
private  float myMinWeight
           
(package private)  GraphSolution mySolution
          The displayed graph solution.
private  javax.swing.JLabel myStatusLabel
           
private  java.awt.Dimension myVertexSize
           
private  java.util.ArrayList<java.awt.Point> myXY
           
 
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
GraphBox()
          Initializes a new instance of the class.
 
Method Summary
private  void computeVertexLocations()
          Computes the drawing information based on the assigned graph.
private static void drawCentered(java.awt.Component component, java.awt.Graphics g, java.lang.String text)
          Draws text centered in a component.
private static void drawCentered(java.awt.Graphics g, java.lang.String text, int x, int y)
          Draws text centered at a location.
private static java.lang.String formatWeight(float weight)
          Formats the weight value as text.
private  java.awt.Color getScaledColor(float weight)
          Returns a color based on a weight.
private  java.awt.Color getScaledColorByPercent(float percent)
          Returns a color based on a percentage.
 void paint(java.awt.Graphics g)
          Paints the component.
private  void paintBorder(java.awt.Graphics2D g)
          Draws a border around the component.
private  void paintEdges(java.awt.Graphics2D g)
          Draws the edges.
private  void paintNoGraph(java.awt.Graphics2D g)
          Draws the component when no graph is loaded.
private  void paintScale(java.awt.Graphics2D g)
          Draws the scale.
private  void paintVertices(java.awt.Graphics2D g)
          Draws the vertices.
 void reset()
          Resets the graph.
 void setBounds(java.awt.Rectangle r)
          Moves and resizes this component to conform to the new bounding rectangle r.
 void setGraph(Graph g)
          Sets the graph to display.
 void setSolution(GraphSolution solution)
          Sets the solution.
private static java.awt.Graphics2D startAntialiasing(java.awt.Graphics g)
          Updates the graphics object to use antialiasing.
private  void updateInformationArea()
          Sets the information area.
 
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, 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, 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, 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, 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, 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

MAX_DISPLAYED_EDGES

private static final int MAX_DISPLAYED_EDGES
The maximum number of edges displayed.

See Also:
Constant Field Values

myCachedSize

private java.awt.Dimension myCachedSize

myGraph

Graph myGraph
The displayed graph.


myHelpIcon

private final javax.swing.JLabel myHelpIcon

myMaxWeight

private float myMaxWeight

myMinWeight

private float myMinWeight

mySolution

GraphSolution mySolution
The displayed graph solution.


myStatusLabel

private final javax.swing.JLabel myStatusLabel

myVertexSize

private java.awt.Dimension myVertexSize

myXY

private final java.util.ArrayList<java.awt.Point> myXY
Constructor Detail

GraphBox

public GraphBox()
Initializes a new instance of the class.

Method Detail

drawCentered

private static void drawCentered(java.awt.Component component,
                                 java.awt.Graphics g,
                                 java.lang.String text)
Draws text centered in a component.

Parameters:
component - The component.
g - The graphics object.
text - The text.

drawCentered

private static void drawCentered(java.awt.Graphics g,
                                 java.lang.String text,
                                 int x,
                                 int y)
Draws text centered at a location.

Parameters:
g - The graphics object.
text - The text.
x - The horizontal location.
y - The vertical location.

formatWeight

private static java.lang.String formatWeight(float weight)
Formats the weight value as text.

Parameters:
weight - The weight.
Returns:
A String for the weight.

startAntialiasing

private static java.awt.Graphics2D startAntialiasing(java.awt.Graphics g)
Updates the graphics object to use antialiasing.

Parameters:
g - The graphics object.
Returns:
The graphics object casted to a 2D graphics object.

computeVertexLocations

private void computeVertexLocations()
Computes the drawing information based on the assigned graph.


getScaledColor

private java.awt.Color getScaledColor(float weight)
Returns a color based on a weight.

Parameters:
weight - The weight.
Returns:
A color.

getScaledColorByPercent

private java.awt.Color getScaledColorByPercent(float percent)
Returns a color based on a percentage.

Parameters:
percent - The percentage.
Returns:
A color.

paint

public void paint(java.awt.Graphics g)
Paints the component.

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

paintBorder

private void paintBorder(java.awt.Graphics2D g)
Draws a border around the component.

Parameters:
g - The graphics object.

paintEdges

private void paintEdges(java.awt.Graphics2D g)
Draws the edges.

Parameters:
g - The graphics object.

paintNoGraph

private void paintNoGraph(java.awt.Graphics2D g)
Draws the component when no graph is loaded.

Parameters:
g - The graphics object.

paintScale

private void paintScale(java.awt.Graphics2D g)
Draws the scale.

Parameters:
g - The graphics object.

paintVertices

private void paintVertices(java.awt.Graphics2D g)
Draws the vertices.

Parameters:
g - The graphics object.

reset

public void reset()
Resets the graph.


setBounds

public void setBounds(java.awt.Rectangle r)
Moves and resizes this component to conform to the new bounding rectangle r. This component's new position is specified by r.x and r.y, and its new size is specified by r.width and r.height

Overrides:
setBounds in class java.awt.Component
Parameters:
r - the new bounding rectangle for this component

setGraph

public void setGraph(Graph g)
Sets the graph to display.

Parameters:
g - The graph.

setSolution

public void setSolution(GraphSolution solution)
Sets the solution.

Parameters:
solution -

updateInformationArea

private void updateInformationArea()
Sets the information area.