edu.princeton.cs.algs4.growingtree.framework
Class TreeJDesktop

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JLayeredPane
                  extended by javax.swing.JDesktopPane
                      extended by edu.princeton.cs.algs4.growingtree.framework.TreeJDesktop
All Implemented Interfaces:
OptionListener, TreeMessageListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, java.util.EventListener, javax.accessibility.Accessible, javax.swing.event.ChangeListener

public class TreeJDesktop
extends javax.swing.JDesktopPane
implements OptionListener, TreeMessageListener, javax.swing.event.ChangeListener

The JDesktop class intended for a tree structure. Within this class, the panels for the trees are constructed as are the JPanel panes to hold them and the internal frames and tabbed pane.

The desktop listens for OptionEvents specific to a chosen tree, and calls that required command for the selected panel (whether it is tabbed pane or a selected window). Also, the desktop listens for events affecting all trees. The only events that bypass the desktop are those based upon clicking upon the tree.

Version:
1.3 9/01/02
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
 
Fields inherited from class javax.swing.JDesktopPane
LIVE_DRAG_MODE, OUTLINE_DRAG_MODE
 
Fields inherited from class javax.swing.JLayeredPane
DEFAULT_LAYER, DRAG_LAYER, FRAME_CONTENT_LAYER, LAYER_PROPERTY, MODAL_LAYER, PALETTE_LAYER, POPUP_LAYER
 
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
TreeJDesktop()
          Sole Constructor, which constructs all of the tree panels and sets up all of the listening.
 
Method Summary
 void addMouseListener(java.awt.event.MouseListener l)
          Adds the specified mouse listener to receive mouse events from this component.
 void addMouseMotionListener(java.awt.event.MouseMotionListener l)
          Adds the specified mouse motion listener to receive mouse motion events from this component.
 void addOptionListener(OptionListener l)
          Adds an OptionEventListener according to the OptionEventListener interface and the OptionEvent.
<P extends NodeProperties>
void
addTree(java.lang.String name, P p, IInsertOperator<P> inserter, ISearchOperator<P> searcher, IDeleteOperator<P> deleter)
           
<P extends NodeProperties>
void
addTree(java.lang.String name, P p, IInsertOperator<P> inserter, ISearchOperator<P> searcher, IDeleteOperator<P> deleter, boolean allowRotations)
           
<P extends NodeProperties>
void
addTree(java.lang.String name, P p, IInsertOperator<P> inserter, ISearchOperator<P> searcher, IDeleteOperator<P> deleter, IExperimentLogger<P> logger)
           
<P extends NodeProperties>
void
addTree(java.lang.String name, P p, IInsertOperator<P> inserter, ISearchOperator<P> searcher, IDeleteOperator<P> deleter, IExperimentLogger<P> logger, boolean allowRotations)
           
 void addTreeMessageListener(TreeMessageListener l)
          Adds an TreeMessageListener from the TREE, according to the TreeMessageListener interface and the TreeMessageEvent.
 javax.swing.Icon getIcon(java.lang.String imageName)
          Gets the icon from the resource (JAR file).
 javax.swing.JPanel getSelectedPanel()
          Gets the currently selected panel, whether it is the panel selected of the windows or whether it is the selected tabbed pane.
 void init()
           
 void initialize()
          Original intialization.
 boolean isWindows()
          Gets if the desktop is set up in windows format or tabbed pabe format.
 void makeRandomTree(java.lang.String startKey, java.lang.String endKey, int size, boolean duplicates)
          Constructs a random Tree for every tree currently in the desktop.
 void makeTabbedPane()
          Makes a tabbedPane.
 void makeWindows()
          Makes the windows for the Desktop.
 void optionEventPerformed(OptionEvent e)
          Option event listener.
 void removeMouseListener(java.awt.event.MouseListener l)
          Removes the specified mouse listener so that it no longer receives mouse events from this component.
 void removeMouseMotionListener(java.awt.event.MouseMotionListener l)
          Removes the specified mouse motion listener so that it no longer receives mouse motion events from this component.
 void removeOptionListener(TreeMessageListener l)
          Removes an OptionEventListener according to the OptionEventListener interface and the OptionEvent.
 void removeTreeMessageListener(TreeMessageListener l)
          Removes an TreeMessageListener from the TREE, according to the TreeMessageListener interface and the TreeMessageEvent.
 void setSelectedFrame(javax.swing.JInternalFrame f)
          Overides the desktop method, to add functionality, by passing information about the changed frame by tree message.
 void stateChanged(javax.swing.event.ChangeEvent e)
          Implements Change Listener.
 void treeMessageEventPerformed(TreeMessageEvent e)
          Listens to tree message events.
 
Methods inherited from class javax.swing.JDesktopPane
getAccessibleContext, getAllFrames, getAllFramesInLayer, getDesktopManager, getDragMode, getSelectedFrame, getUI, getUIClassID, remove, removeAll, selectFrame, setComponentZOrder, setDesktopManager, setDragMode, setUI, updateUI
 
Methods inherited from class javax.swing.JLayeredPane
getComponentCountInLayer, getComponentsInLayer, getIndexOf, getLayer, getLayer, getLayeredPaneAbove, getPosition, highestLayer, isOptimizedDrawingEnabled, lowestLayer, moveToBack, moveToFront, paint, putLayer, setLayer, setLayer, setPosition
 
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, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, 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, removeContainerListener, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusBackward, transferFocusDownCycle, validate
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, 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, 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
 

Constructor Detail

TreeJDesktop

public TreeJDesktop()
Sole Constructor, which constructs all of the tree panels and sets up all of the listening.

Method Detail

init

public void init()

initialize

public void initialize()
Original intialization. This calls methods that are called everytime a selected panel is changed, and obviously needs to be called initially.


addTree

public <P extends NodeProperties> void addTree(java.lang.String name,
                                               P p,
                                               IInsertOperator<P> inserter,
                                               ISearchOperator<P> searcher,
                                               IDeleteOperator<P> deleter,
                                               boolean allowRotations)

addTree

public <P extends NodeProperties> void addTree(java.lang.String name,
                                               P p,
                                               IInsertOperator<P> inserter,
                                               ISearchOperator<P> searcher,
                                               IDeleteOperator<P> deleter)

addTree

public <P extends NodeProperties> void addTree(java.lang.String name,
                                               P p,
                                               IInsertOperator<P> inserter,
                                               ISearchOperator<P> searcher,
                                               IDeleteOperator<P> deleter,
                                               IExperimentLogger<P> logger,
                                               boolean allowRotations)

addTree

public <P extends NodeProperties> void addTree(java.lang.String name,
                                               P p,
                                               IInsertOperator<P> inserter,
                                               ISearchOperator<P> searcher,
                                               IDeleteOperator<P> deleter,
                                               IExperimentLogger<P> logger)

makeWindows

public void makeWindows()
Makes the windows for the Desktop. The method also removes the JInternalFrames to make new frames or removes the tabbedPane (whichever is currently active).


makeTabbedPane

public void makeTabbedPane()
Makes a tabbedPane. It removes the Internal frames first and then constructs the internal frames.


isWindows

public boolean isWindows()
Gets if the desktop is set up in windows format or tabbed pabe format. If the desktop is as windows, true is returned.

Returns:
true if the desktop is set as windows.

getSelectedPanel

public javax.swing.JPanel getSelectedPanel()
Gets the currently selected panel, whether it is the panel selected of the windows or whether it is the selected tabbed pane.

Returns:
JPanel currently selected whether in the window or Tabbed Pane.

addOptionListener

public void addOptionListener(OptionListener l)
Adds an OptionEventListener according to the OptionEventListener interface and the OptionEvent.

Parameters:
l - the listener added recieves the OptionEvents occuring.

removeOptionListener

public void removeOptionListener(TreeMessageListener l)
Removes an OptionEventListener according to the OptionEventListener interface and the OptionEvent.

Parameters:
l - the listener removed from recieving the OptionEvents occuring.

addTreeMessageListener

public void addTreeMessageListener(TreeMessageListener l)
Adds an TreeMessageListener from the TREE, according to the TreeMessageListener interface and the TreeMessageEvent.

Parameters:
l - the listener added recieves the TreeMessageEvents occuring.

removeTreeMessageListener

public void removeTreeMessageListener(TreeMessageListener l)
Removes an TreeMessageListener from the TREE, according to the TreeMessageListener interface and the TreeMessageEvent.

Parameters:
l - the listener removed from recieving the TreeMessageEvents occuring.

addMouseListener

public void addMouseListener(java.awt.event.MouseListener l)
Adds the specified mouse listener to receive mouse events from this component. If l is null, no exception is thrown and no action is performed.

Overrides:
addMouseListener in class java.awt.Component
Parameters:
l - the mouse listener.

removeMouseListener

public void removeMouseListener(java.awt.event.MouseListener l)
Removes the specified mouse listener so that it no longer receives mouse events from this component. This method performs no function, nor does it throw an exception, if the listener specified by the argument was not previously added to this component. If l is null, no exception is thrown and no action is performed.

Overrides:
removeMouseListener in class java.awt.Component
Parameters:
l - the mouse listener.

addMouseMotionListener

public void addMouseMotionListener(java.awt.event.MouseMotionListener l)
Adds the specified mouse motion listener to receive mouse motion events from this component. If l is null, no exception is thrown and no action is performed.

Overrides:
addMouseMotionListener in class java.awt.Component
Parameters:
l - the mouse motion listener.

removeMouseMotionListener

public void removeMouseMotionListener(java.awt.event.MouseMotionListener l)
Removes the specified mouse motion listener so that it no longer receives mouse motion events from this component. This method performs no function, nor does it throw an exception, if the listener specified by the argument was not previously added to this component. If l is null, no exception is thrown and no action is performed.

Overrides:
removeMouseMotionListener in class java.awt.Component
Parameters:
l - the mouse motion listener.

treeMessageEventPerformed

public void treeMessageEventPerformed(TreeMessageEvent e)
Listens to tree message events.

Specified by:
treeMessageEventPerformed in interface TreeMessageListener
Parameters:
e - TreeMessageEvent that contains information about the tree.

makeRandomTree

public void makeRandomTree(java.lang.String startKey,
                           java.lang.String endKey,
                           int size,
                           boolean duplicates)
Constructs a random Tree for every tree currently in the desktop.

Parameters:
startKey - the starting key for the random tree.
endKey - the ending key for the random tree.
size - the size of the random tree created.
duplicates - true if duplicates are allowed in the list.

getIcon

public javax.swing.Icon getIcon(java.lang.String imageName)
Gets the icon from the resource (JAR file).


optionEventPerformed

public void optionEventPerformed(OptionEvent e)
Option event listener. The result of an optionEvent being performed depends upon the event. Within the desktop, the events are used or passed on to the trees accordingly. Here the separating of the events takes place.

Specified by:
optionEventPerformed in interface OptionListener
Parameters:
e - OptionEvent passed with information about the event.

stateChanged

public void stateChanged(javax.swing.event.ChangeEvent e)
Implements Change Listener. On a state changed, messages are sent out according to the status of the new panel.

Specified by:
stateChanged in interface javax.swing.event.ChangeListener
Parameters:
e - ChangeEvent passed when the state changes.

setSelectedFrame

public void setSelectedFrame(javax.swing.JInternalFrame f)
Overides the desktop method, to add functionality, by passing information about the changed frame by tree message.

Overrides:
setSelectedFrame in class javax.swing.JDesktopPane
Parameters:
f - JInternalFrame that is selected.