edu.princeton.cs.algs4.growingtree.framework
Class BSTTreeJPanel<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.TreeJPanel<P>
                          extended by edu.princeton.cs.algs4.growingtree.framework.BSTTreeJPanel<P>
All Implemented Interfaces:
OptionListener, TreeMessageListener, 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 BSTTreeJPanel<P extends NodeProperties>
extends TreeJPanel<P>

This class provides the panel for a BSTTree. It keeps the graphics for drawing the tree and the image for redrawing. It also keeps a timer for the animation and all changes to the tree proceed through the panel.

Version:
3.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 java.lang.String CHRISTMAS
          Christmas color scheme.
static java.lang.String DEFAULT
          Default color scheme.
static java.lang.String HALLOWEEN
          Halloween color scheme.
static java.lang.String PRIMARY
          Default color scheme.
static java.lang.String PRINCETON
          Princeton color scheme.
 
Fields inherited from class edu.princeton.cs.algs4.growingtree.framework.TreeJPanel
BACKGROUND, CHARACTER, DEFAULT_DELAY, DELETE, DOUBLE, DRAWING, INSERT, INTEGER, KEY, KEY_ANIMATOR_SETTINGS, KEY_ORIGINAL_SETTINGS, LEFT_PAINT, NODE, NODE_ANIMATOR_SETTINGS, NODE_CHILD_SETTINGS, NODE_DESCENDANT_SETTINGS, NODE_LEFT_SETTINGS, NODE_ORIGINAL_SETTINGS, NODE_RIGHT_SETTINGS, NODE_ROOT_SETTINGS, NOKEY, PAINT, RIGHT_PAINT, ROTATE, SEARCH, SELECT, TRAVERSE, TYPEERR
 
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
BSTTreeJPanel()
          Sole Constructor.
BSTTreeJPanel(P np, IInsertOperator<P> inserter, ISearchOperator<P> searcher, IDeleteOperator<P> deleter, boolean allowRotations)
           
BSTTreeJPanel(P np, IInsertOperator<P> inserter, ISearchOperator<P> searcher, IDeleteOperator<P> deleter, IExperimentLogger<P> logger, boolean allowRotations)
           
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent e)
          Listens to action events.
 void balanceCommand(Tree node)
          Balance command.
 void constructColorOptions(ColorOptionsJPanel colorOptionsPanel)
          Constructs the color options combo box and sets the box for the given colorOptionsPanel.
 void constructPresetColorOptions(ColorOptionsJPanel colorOptionsPanel)
          Constructs the color settings combo box and sets the box for the given colorOptionsPanel.
 void displayChangeCommand()
          Change Display Command.
 void drawAnimatingNode()
          Draws the animating node using the currently selected animating settings.
 void drawDrawingNode()
          Draws the drawing node using the currently selected drawing settings.
 java.lang.String[] getColorSchemeOptions()
          Gets the color scheme aniamtion options for the current tree.
 java.lang.String getColorSchemeSetting(java.lang.String function, java.lang.String setting)
          Gets the Color Scheme setting for the given function and setting.
 java.lang.String[] getColorSchemesList(java.lang.String settings)
          Gets the color scheme settings for each type of settings.
 java.lang.String[] getColorSettings()
          Gets the color settings options for the current tree.
 java.lang.String getColorSettingsString()
          Gets the color settings string of the current panel to the colorSettings param.
 java.lang.String[] getOptionColorSchemeOptions(java.lang.String option)
          Gets the color scheme options for each type of animation.
 java.lang.String getTitle()
          Gets the title for the tree.
 javax.swing.JPopupMenu makeJPopupMenu(java.awt.event.ActionListener actionlistener)
          Constructs a popupmenu, using the actionlistener passed.
 void optionEventPerformed(OptionEvent e)
          Recieved an event from an OptionJPanel with one of the given commands.
 void resetSettingStrings()
          Resets the string settings currently selected.
 void rotateToTopCommand(Tree<P> node)
          RotateToTop command.
 void rotateUpCommand(Tree<P> node)
          RotateUp command.
 void rotateUpDoubleCommand(Tree node)
          RotateUpDouble command.
 void setAnimating(boolean animating)
          Sets whether the tree is animating or not.
 void setColorSchemeSetting(java.lang.String presetScheme)
          Sets the color scheme using the given preset scheme string.
 void setColorSchemeSetting(java.lang.String function, java.lang.String setting, java.lang.String scheme)
          Sets the color scheme using the given function and setting.
 void setColorSettingsString(java.lang.String colorSettings)
          Sets the color settings string of the current panel to the colorSettings param.
 void setComponentShown(boolean componentShown)
          Sets whether the tree is shown or not.
 void setSettings()
          Sets the settings for the panel using the currently selected String options.
 void setSettings(TreeJPanel panel)
          Sets the settings for the panel using the currently selected String options.
 void setSubtreeCountsCommand(boolean visible)
           
 void splayCommand(Tree node)
          Splay command.
 void traverseCommand(int traverseType)
          Traverse command.
 
Methods inherited from class edu.princeton.cs.algs4.growingtree.framework.TreeJPanel
addTreeMessageListener, animatingCommand, animationQualityCommand, animationSpeedCommand, clearAllCommand, clearCommand, deleteCommand, deleteCommand, getInputOptions, getKeyType, getTree, getTreeStatusMessage, inputChangeCommand, insertCommand, isAnimating, isStep, makeColorSchemeOptions, makeColorSettings, paintComponent, partitionCommand, pauseCommand, playCommand, playFastCommand, playStepCommand, removeTreeMessageListener, repaintAttempt, rewindCommand, rewindFastCommand, rewindStepCommand, saveTreeCommand, searchCommand, selectCommand, selectCommand, setDelayRate, setStep, setTree, stopCommand, treeMessageEventPerformed
 
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

public static final java.lang.String DEFAULT
Default color scheme.

See Also:
Constant Field Values

PRIMARY

public static final java.lang.String PRIMARY
Default color scheme.

See Also:
Constant Field Values

PRINCETON

public static final java.lang.String PRINCETON
Princeton color scheme.

See Also:
Constant Field Values

CHRISTMAS

public static final java.lang.String CHRISTMAS
Christmas color scheme.

See Also:
Constant Field Values

HALLOWEEN

public static final java.lang.String HALLOWEEN
Halloween color scheme.

See Also:
Constant Field Values
Constructor Detail

BSTTreeJPanel

public BSTTreeJPanel()
Sole Constructor. Simply sets the correct type of tree and sets it to animating.


BSTTreeJPanel

public BSTTreeJPanel(P np,
                     IInsertOperator<P> inserter,
                     ISearchOperator<P> searcher,
                     IDeleteOperator<P> deleter,
                     boolean allowRotations)

BSTTreeJPanel

public BSTTreeJPanel(P np,
                     IInsertOperator<P> inserter,
                     ISearchOperator<P> searcher,
                     IDeleteOperator<P> deleter,
                     IExperimentLogger<P> logger,
                     boolean allowRotations)
Method Detail

getTitle

public java.lang.String getTitle()
Gets the title for the tree.

Overrides:
getTitle in class TreeJPanel<P extends NodeProperties>
Returns:
String defining the title of the tree.

resetSettingStrings

public void resetSettingStrings()
Resets the string settings currently selected. This bascially calls the tree and gets the settings of the tree and sets all currently selected strings to the settings of the tree.


setSettings

public void setSettings()
Sets the settings for the panel using the currently selected String options.

The Panel used is the current panel.


setSettings

public void setSettings(TreeJPanel panel)
Sets the settings for the panel using the currently selected String options.

The Panel used is the passed panel.

Overrides:
setSettings in class TreeJPanel<P extends NodeProperties>
Parameters:
panel - panel to which the settings are changed according to the currently selected settings.

setColorSettingsString

public void setColorSettingsString(java.lang.String colorSettings)
Sets the color settings string of the current panel to the colorSettings param.

Parameters:
colorSettings - the String defining the colorSettings for the current panel.

getColorSettingsString

public java.lang.String getColorSettingsString()
Gets the color settings string of the current panel to the colorSettings param.

Returns:
String colorSettings String defining the colorSettings for the current panel.

drawDrawingNode

public void drawDrawingNode()
Draws the drawing node using the currently selected drawing settings.


drawAnimatingNode

public void drawAnimatingNode()
Draws the animating node using the currently selected animating settings.


getColorSchemeSetting

public java.lang.String getColorSchemeSetting(java.lang.String function,
                                              java.lang.String setting)
Gets the Color Scheme setting for the given function and setting.

Parameters:
function - String function like DRAWING or BACKGROUND.
setting - String setting choice for which the color setting is requested like NODE.
Returns:
String defining the color scheme setting.

setColorSchemeSetting

public void setColorSchemeSetting(java.lang.String function,
                                  java.lang.String setting,
                                  java.lang.String scheme)
Sets the color scheme using the given function and setting.

Parameters:
function - for which the setting is given.
setting - the setting for which the scheme is set.
scheme - the color setting used for the given function and setting.

setColorSchemeSetting

public void setColorSchemeSetting(java.lang.String presetScheme)
Sets the color scheme using the given preset scheme string.

Parameters:
presetScheme - the preset sceme defined.

getColorSchemeOptions

public java.lang.String[] getColorSchemeOptions()
Gets the color scheme aniamtion options for the current tree.

Returns:
String array of the options for the current tree.

getColorSettings

public java.lang.String[] getColorSettings()
Gets the color settings options for the current tree.

Returns:
String array of the color settings.

getOptionColorSchemeOptions

public java.lang.String[] getOptionColorSchemeOptions(java.lang.String option)
Gets the color scheme options for each type of animation.

Returns:
String array of the options for the current tree.

getColorSchemesList

public java.lang.String[] getColorSchemesList(java.lang.String settings)
Gets the color scheme settings for each type of settings.

Returns:
String array of the options for the current type of settings.

constructColorOptions

public void constructColorOptions(ColorOptionsJPanel colorOptionsPanel)
Constructs the color options combo box and sets the box for the given colorOptionsPanel.

Overrides:
constructColorOptions in class TreeJPanel<P extends NodeProperties>
Parameters:
colorOptionsPanel - the colorToolsJPanel for which the JComboBox is set.

constructPresetColorOptions

public void constructPresetColorOptions(ColorOptionsJPanel colorOptionsPanel)
Constructs the color settings combo box and sets the box for the given colorOptionsPanel.

Overrides:
constructPresetColorOptions in class TreeJPanel<P extends NodeProperties>
Parameters:
colorOptionsPanel - the colorOptionsPanel for which the JComboBox is set.

makeJPopupMenu

public javax.swing.JPopupMenu makeJPopupMenu(java.awt.event.ActionListener actionlistener)
Constructs a popupmenu, using the actionlistener passed. The popupMenu contains all of the options available through the current tree. For this class, no items are added, making it necessary to overide the method.

Overrides:
makeJPopupMenu in class TreeJPanel<P extends NodeProperties>
Parameters:
actionListener - the listener add to the actions of all the items made in the menu.
Returns:
JPopupMenu which is the menu constructed within the panel.

setAnimating

public void setAnimating(boolean animating)
Sets whether the tree is animating or not.

Overrides:
setAnimating in class TreeJPanel<P extends NodeProperties>
Parameters:
animating - boolean flag as to whether the tree is animating.

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.

setSubtreeCountsCommand

public void setSubtreeCountsCommand(boolean visible)
Overrides:
setSubtreeCountsCommand in class TreeJPanel<P extends NodeProperties>

rotateUpCommand

public void rotateUpCommand(Tree<P> node)
RotateUp command.

Overrides:
rotateUpCommand in class TreeJPanel<P extends NodeProperties>
Parameters:
node - Tree to rotateUp.

rotateToTopCommand

public void rotateToTopCommand(Tree<P> node)
RotateToTop command.

Overrides:
rotateToTopCommand in class TreeJPanel<P extends NodeProperties>
Parameters:
node - Tree to rotateToTop.

rotateUpDoubleCommand

public void rotateUpDoubleCommand(Tree node)
RotateUpDouble command.

Overrides:
rotateUpDoubleCommand in class TreeJPanel<P extends NodeProperties>
Parameters:
node - Tree to rotateUpDouble.

splayCommand

public void splayCommand(Tree node)
Splay command.

Overrides:
splayCommand in class TreeJPanel<P extends NodeProperties>
Parameters:
node - Tree to splay.

traverseCommand

public void traverseCommand(int traverseType)
Traverse command.

Overrides:
traverseCommand in class TreeJPanel<P extends NodeProperties>
Parameters:
traverseType - int that defines the traverseType.

balanceCommand

public void balanceCommand(Tree node)
Balance command.

Overrides:
balanceCommand in class TreeJPanel<P extends NodeProperties>
Parameters:
node - Tree to balance.

displayChangeCommand

public void displayChangeCommand()
Change Display Command.


optionEventPerformed

public void optionEventPerformed(OptionEvent e)
Recieved an event from an OptionJPanel with one of the given commands. The Panel responds accordingly. The Methods it calls (for example: insertCommand, rotateCommand...) should be overiden in extending classes to functionable.

Specified by:
optionEventPerformed in interface OptionListener
Overrides:
optionEventPerformed in class TreeJPanel<P extends NodeProperties>
Parameters:
e - OptionEvent recieved from the event performed.

actionPerformed

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

Specified by:
actionPerformed in interface java.awt.event.ActionListener
Overrides:
actionPerformed in class TreeJPanel<P extends NodeProperties>
Parameters:
e - ActionEvent that contains information about the tree.