edu.princeton.cs.algs4.growingtree.framework
Class NodeAndLinkAnimatingJPanel<P extends NodeProperties>

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.princeton.cs.algs4.growingtree.framework.DrawingJPanel
                      extended by edu.princeton.cs.algs4.growingtree.framework.NodeAndLinkAnimatingJPanel<P>
All Implemented Interfaces:
java.awt.event.ActionListener, java.awt.event.ComponentListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, java.util.EventListener, javax.accessibility.Accessible

public class NodeAndLinkAnimatingJPanel<P extends NodeProperties>
extends DrawingJPanel
implements java.awt.event.ActionListener

Version:
1.4 9/15/01
Author:
Corey Sanders
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.BaselineResizeBehavior
 
Field Summary
static int DEFAULT_DELAY
          The default delay for animation (90).
 
Fields inherited from class javax.swing.JComponent
TOOL_TIP_TEXT_KEY, 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
NodeAndLinkAnimatingJPanel()
          Sole Constructor for the JPanel that paints the node using the AnimatingTree drawNode method.
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent e)
          Listens to action events.
 void drawLines(java.awt.Graphics2D g2)
          Draws the lines in the given panel using the Graphics2D.
 DrawingTree<P> getAnimatingNode()
          Gets the head of the tree currently drawn in the Panel.
 java.awt.Paint getLeftLinePaint()
          Gets the paint for the left line drawing.
 java.awt.Paint getRightLinePaint()
          Gets the paint for the right line drawing.
 boolean isDrawingLines()
          Gets whether the animation is drawing lines or a node.
 void paintComponent(java.awt.Graphics g)
          Overides paintComponenet and is called whenever the Panel needs to be painted.
 void setAnimatingNode(DrawingTree<P> animatingNode)
          Set the node for drawing.
 void setComponentShown(boolean componentShown)
          Sets whether the tree is shown or not.
 void setDelayRate(int t)
          Sets the delay rate for the timer for the animation.
 void setDrawingLines(boolean drawingLines)
          Sets whether the animation is drawing lines or a node.
 void setLeftLinePaint(java.awt.Paint leftLinePaint)
          Sets the paint for the left line drawing.
 void setRightLinePaint(java.awt.Paint rightLinePaint)
          Sets the paint for the right line drawing.
 
Methods inherited from class edu.princeton.cs.algs4.growingtree.framework.DrawingJPanel
componentHidden, componentMoved, componentResized, componentShown, getDrawingArea, getDrawTreeGraphics, getDrawTreeImage, isComponentShown, isDrawTree, setDrawTree
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, setUI, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, 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, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintImmediately, paintImmediately, print, printAll, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, 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, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, 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, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusBackward, transferFocusDownCycle, validate
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, contains, createImage, createImage, createVolatileImage, createVolatileImage, dispatchEvent, enable, enableInputMethods, 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, 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, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT_DELAY

public static final int DEFAULT_DELAY
The default delay for animation (90).

See Also:
Constant Field Values
Constructor Detail

NodeAndLinkAnimatingJPanel

public NodeAndLinkAnimatingJPanel()
Sole Constructor for the JPanel that paints the node using the AnimatingTree drawNode method. The JPanel only makes a new image on a resize and otherwise, double-buffers the graphics by leaving the image unmodified.

Method Detail

isDrawingLines

public boolean isDrawingLines()
Gets whether the animation is drawing lines or a node. If the panel is drawing lines, returns true.

Returns:
true if the panel is drawing lines.

getAnimatingNode

public DrawingTree<P> getAnimatingNode()
Gets the head of the tree currently drawn in the Panel.

Returns:
TreeHead the tree head.

getRightLinePaint

public java.awt.Paint getRightLinePaint()
Gets the paint for the right line drawing.

Returns:
Paint right Line Paint.

getLeftLinePaint

public java.awt.Paint getLeftLinePaint()
Gets the paint for the left line drawing.

Returns:
Paint left Line Paint.

setDrawingLines

public void setDrawingLines(boolean drawingLines)
Sets whether the animation is drawing lines or a node. If the panel is drawing lines, sets true.

Parameters:
drawingLines - true if the panel is drawing lines.

setRightLinePaint

public void setRightLinePaint(java.awt.Paint rightLinePaint)
Sets the paint for the right line drawing.

Parameters:
rightLinePaint - right Line Paint.

setLeftLinePaint

public void setLeftLinePaint(java.awt.Paint leftLinePaint)
Sets the paint for the left line drawing.

Parameters:
leftLinePaint - left Line Paint.

setDelayRate

public void setDelayRate(int t)
Sets the delay rate for the timer for the animation. param t int delay rate.


setAnimatingNode

public void setAnimatingNode(DrawingTree<P> animatingNode)
Set the node for drawing. This method should be called for each change in node.

Parameters:
node - node used for drawing within the panel.

setComponentShown

public void setComponentShown(boolean componentShown)
Sets whether the tree is shown or not.

Overrides:
setComponentShown in class DrawingJPanel
Parameters:
componentShown - boolean flag as to whether the tree is shown.

drawLines

public void drawLines(java.awt.Graphics2D g2)
Draws the lines in the given panel using the Graphics2D.

Parameters:
g2 - Graphics2D to draw the lines within.

paintComponent

public void paintComponent(java.awt.Graphics g)
Overides paintComponenet and is called whenever the Panel needs to be painted. The painting includes painting the image and then painting the animation (if any).

Overrides:
paintComponent in class DrawingJPanel
Parameters:
g - Graphics to which the component is drawn.

actionPerformed

public void actionPerformed(java.awt.event.ActionEvent e)
Listens to action events.

Specified by:
actionPerformed in interface java.awt.event.ActionListener
Parameters:
e - ActionEvent that contains information about the tree.