edu.mit.ai.psg.ui.outliner
Class OutlineMakerDefault

java.lang.Object
  |
  +--edu.mit.ai.psg.ui.outliner.OutlineMakerDefault
Direct Known Subclasses:
Jexa.JexaOutlineMaker

public class OutlineMakerDefault
extends Object
implements OutlineMaker

OutlineMakerDefault provides a default implementation of OutlineMaker.

An object's most specific interface is found through depth first search; see getMostSpecificInterfaceWithRenderers(java.lang.Object).

null is treated as the class of null.

Adds popup menu items to expand/collapse node, view a nested node as a top level node in its own window frame, or rerender a node with a choice of applicable renderers.


Field Summary
 Rectangle initialBounds
          initials bounds for new window frames
 OutlineRenderer myNoteRenderer
          renderer called to make text notes for messages, errors, etc.
protected  Map myRenderers
          Map of stacks of OutlineRenderers keyed on interface or class to which each applies.
static Font noteFont
          Default font for noteRenderer, italic system font:
 
Constructor Summary
OutlineMakerDefault()
           
 
Method Summary
 void addPopupMenuItems(PopupMenu menu, OutlineNode outlineNode, TreePath treePath, JTree jTree)
          addOutlinerPopUpMenuItems first adds menu items for "Collapse" or "Expand", then "Regenerate outline in own frame".
 void addRenderer(Class forInterface, OutlineRenderer renderer)
          Add an outline renderer for objects with this interface into this outliner's table.
 void addTreeListeners(JTree jTree)
          Add mouse event listeners to JTree.
 List getAllInterfacesWithRenderers(Object obj)
          Search class and its interfaces and superclasses for each class/interface which has a renderer, and return all classes/interfaces found.
 List getAllRenderers(Object obj)
          Search class and its interfaces and superclasses for each class/interface which has a renderer, and return all renderers found.
 OutlineRenderer getExactRenderer(Class anInterface)
          Get one renderer for exactly this interface or class (not super-interfaces or super-classes).
 List getExactRenderers(Class anInterface)
          return a java.util.List of renderers for exactly this interface or class.
 JTree getFrameJTree(JFrame frame)
          get JTree from JFrame returned by makeFrame
 Class getMostSpecificInterfaceWithRenderers(Object obj)
          Search for outline renderers for object for the most specific class or interface of obj.
 OutlineRenderer getMostSpecificRenderer(Object obj)
          Return outline renderer for most specific class or interface of obj.
 OutlineRenderer getNoteRenderer()
          get renderer used for notes in an outline, such as section separators, error messages, etc.
 JTree getPaneJTree(Container pane)
          get JTree from Container initialized with initializePane
 void initializePane(Container contentPane, OutlineNode displayRoot)
          initializes contentPane with a JScrollPane displaying the JTree from makeOutlineJTree(edu.mit.ai.psg.ui.outliner.OutlineNode).
 JFrame makeFrame(Object obj)
          Convenience method, calls
this.makeFrame (this.makeFrameTitle(obj), this.makeNode(obj));
 JFrame makeFrame(String frameLabel, OutlineNode displayRoot)
          creates a JFrame with frameLabel, initializes its contentPane via initializePane(java.awt.Container, edu.mit.ai.psg.ui.outliner.OutlineNode), and displays it.
 String makeFrameTitle(Object obj)
          overiddable method called by makeFrame(Object)
 JTree makeOutlineJTree(OutlineNode displayRoot)
          creates and initializes a JTree for displaying outline tree.
 OutlineModel makeOutlineModel(OutlineNode displayRoot)
          returns a new OutlineModel with hidden root of tree (overrideable method called by makeOutlineJTree(edu.mit.ai.psg.ui.outliner.OutlineNode))
 OutlineNode makeOutlineNode(Object obj)
           
 OutlineNode makeOutlineNode(Object label, Object obj)
          (overrideable implementation method)
 JFrame outline(Object obj)
          convenience method calls calls frame.show() before returning frame
 boolean removeRenderer(Class forInterface, OutlineRenderer renderer)
          Remove renderer from the renderers for this interface or class (not super-interfaces or super-classes).
 void setFrameJTree(JFrame frame, JTree jTree)
          set JTree in JFrame returned by makeFrame
 void setPaneJTree(Container pane, JTree jTree)
          set JTree in Container initialized with initializePane
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

myRenderers

protected Map myRenderers
Map of stacks of OutlineRenderers keyed on interface or class to which each applies. Top of stack is default chosen for that interface or class.
See Also:
addRenderer(Class, OutlineRenderer), getExactRenderer(Class)

myNoteRenderer

public OutlineRenderer myNoteRenderer
renderer called to make text notes for messages, errors, etc. for outline. By default it is a OutlineRendererDefault with font set to noteFont.

initialBounds

public Rectangle initialBounds
initials bounds for new window frames

noteFont

public static Font noteFont
Default font for noteRenderer, italic system font:
java.util.Map attributes = new java.util.HashMap(1);
attributes.put(TextAttribute.POSTURE, TextAttribute.POSTURE_OBLIQUE);
defaultFont = java.awt.Font.getFont(attributes);
(Initialization specifies only posture, since system default size will vary with locale, e.g., for Aisan languages.)
See Also:
Font.getFont(Map)
Constructor Detail

OutlineMakerDefault

public OutlineMakerDefault()
Method Detail

outline

public JFrame outline(Object obj)
convenience method calls calls frame.show() before returning frame
Specified by:
outline in interface OutlineMaker
See Also:
makeFrame(Object)

makeFrame

public JFrame makeFrame(Object obj)
Convenience method, calls
this.makeFrame (this.makeFrameTitle(obj), this.makeNode(obj));
Specified by:
makeFrame in interface OutlineMaker
Tags copied from interface: OutlineMaker
See Also:
OutlineMaker.makeFrameTitle(java.lang.Object)

makeFrame

public JFrame makeFrame(String frameLabel,
                        OutlineNode displayRoot)
creates a JFrame with frameLabel, initializes its contentPane via initializePane(java.awt.Container, edu.mit.ai.psg.ui.outliner.OutlineNode), and displays it.
Specified by:
makeFrame in interface OutlineMaker
Tags copied from interface: OutlineMaker
Parameters:
frameLabel - title of window frame
newRoot - root node of outline
See Also:
OutlineMaker.makeOutlineNode(Object)

makeFrameTitle

public String makeFrameTitle(Object obj)
overiddable method called by makeFrame(Object)
Specified by:
makeFrameTitle in interface OutlineMaker
Tags copied from interface: OutlineMaker
See Also:
OutlineMaker.makeFrame(Object)

getFrameJTree

public JTree getFrameJTree(JFrame frame)
get JTree from JFrame returned by makeFrame
Specified by:
getFrameJTree in interface OutlineMaker

setFrameJTree

public void setFrameJTree(JFrame frame,
                          JTree jTree)
set JTree in JFrame returned by makeFrame
Specified by:
setFrameJTree in interface OutlineMaker

getPaneJTree

public JTree getPaneJTree(Container pane)
get JTree from Container initialized with initializePane
Specified by:
getPaneJTree in interface OutlineMaker

setPaneJTree

public void setPaneJTree(Container pane,
                         JTree jTree)
set JTree in Container initialized with initializePane
Specified by:
setPaneJTree in interface OutlineMaker

initializePane

public void initializePane(Container contentPane,
                           OutlineNode displayRoot)
initializes contentPane with a JScrollPane displaying the JTree from makeOutlineJTree(edu.mit.ai.psg.ui.outliner.OutlineNode).
Specified by:
initializePane in interface OutlineMaker

makeOutlineJTree

public JTree makeOutlineJTree(OutlineNode displayRoot)
creates and initializes a JTree for displaying outline tree. Adds a hidden root node so every displayed node has a parent node in which it can be replaced by a new renderer. Calls makeOutlineModel(edu.mit.ai.psg.ui.outliner.OutlineNode)(hiddenRoot)
Specified by:
makeOutlineJTree in interface OutlineMaker
Tags copied from interface: OutlineMaker
See Also:
JTree.setRootVisible(boolean)

makeOutlineModel

public OutlineModel makeOutlineModel(OutlineNode displayRoot)
returns a new OutlineModel with hidden root of tree (overrideable method called by makeOutlineJTree(edu.mit.ai.psg.ui.outliner.OutlineNode))
Specified by:
makeOutlineModel in interface OutlineMaker

makeOutlineNode

public OutlineNode makeOutlineNode(Object obj)
Specified by:
makeOutlineNode in interface OutlineMaker
Tags copied from interface: OutlineMaker
See Also:
OutlineMaker.makeOutlineNode(Object, Object)

makeOutlineNode

public OutlineNode makeOutlineNode(Object label,
                                   Object obj)
(overrideable implementation method)
Specified by:
makeOutlineNode in interface OutlineMaker
Tags copied from interface: OutlineMaker
See Also:
OutlineMaker.getMostSpecificRenderer(java.lang.Object)

addTreeListeners

public void addTreeListeners(JTree jTree)
Add mouse event listeners to JTree. Called by makeOutlineFrame; may be extended/overridden to add other listeners if needed

getMostSpecificRenderer

public OutlineRenderer getMostSpecificRenderer(Object obj)
Return outline renderer for most specific class or interface of obj.
Specified by:
getMostSpecificRenderer in interface OutlineMaker
Throws:
NoSuchElementException - if none found (e.g., renderer for Object.class has been removed)
See Also:
getMostSpecificInterfaceWithRenderers(java.lang.Object), getExactRenderer(java.lang.Class)

getMostSpecificInterfaceWithRenderers

public Class getMostSpecificInterfaceWithRenderers(Object obj)
Search for outline renderers for object for the most specific class or interface of obj. Subclasses or interfaces declared in subclasses take precedence over superclasses or interfaces declared in superclasses. Leftmost interface within a class takes precedence. A declaration of an interface that extends other interfaces is taken to be shorthand for also declaring all the interfaces it extends.

I.e.:

.       for (c = obj.getClass(); c != null; c = c.getSuperclass()) {
.         if (null != getExactRenderer(c)) return c;
.         interfacesStack = new Stack(c.getInterfaces());
.         while(! interfacesStack.isEmpty()) {
.           i = interfacesStack.pop();
.           if (null != getExactRenderer(i)) return i;
.           interfacesStack.addAll(0, i.getInterfaces());
.         }           
.       }
Specified by:
getMostSpecificInterfaceWithRenderers in interface OutlineMaker
Throws:
NoSuchElementException - if none found (e.g., renderer for Object.class has been removed)

getAllRenderers

public List getAllRenderers(Object obj)
Search class and its interfaces and superclasses for each class/interface which has a renderer, and return all renderers found.
Specified by:
getAllRenderers in interface OutlineMaker

getAllInterfacesWithRenderers

public List getAllInterfacesWithRenderers(Object obj)
Search class and its interfaces and superclasses for each class/interface which has a renderer, and return all classes/interfaces found.
Specified by:
getAllInterfacesWithRenderers in interface OutlineMaker

getExactRenderer

public OutlineRenderer getExactRenderer(Class anInterface)
Get one renderer for exactly this interface or class (not super-interfaces or super-classes). Returns null if no renderers; otherwise chooses most recently used or added renderer.
Specified by:
getExactRenderer in interface OutlineMaker

getExactRenderers

public List getExactRenderers(Class anInterface)
return a java.util.List of renderers for exactly this interface or class. (not super-interfaces or super-classes). List is ordered so most recently added renderer is first. null is treated as the class of null.
Specified by:
getExactRenderers in interface OutlineMaker

addRenderer

public void addRenderer(Class forInterface,
                        OutlineRenderer renderer)
Add an outline renderer for objects with this interface into this outliner's table. Most recently added renderer is default for an interface, so adding a renderer it already has makes it the default.
Specified by:
addRenderer in interface OutlineMaker
Parameters:
forInterface - Objects with this interface or class will be outlined with this function (unless a more specific one applies). If forInterface is null, then it will be used to render null.
renderer - must be a non-null OutlineRenderer

removeRenderer

public boolean removeRenderer(Class forInterface,
                              OutlineRenderer renderer)
Description copied from interface: OutlineMaker
Remove renderer from the renderers for this interface or class (not super-interfaces or super-classes). Returns true if found.
Specified by:
removeRenderer in interface OutlineMaker

getNoteRenderer

public OutlineRenderer getNoteRenderer()
Description copied from interface: OutlineMaker
get renderer used for notes in an outline, such as section separators, error messages, etc.
Specified by:
getNoteRenderer in interface OutlineMaker

addPopupMenuItems

public void addPopupMenuItems(PopupMenu menu,
                              OutlineNode outlineNode,
                              TreePath treePath,
                              JTree jTree)
addOutlinerPopUpMenuItems first adds menu items for "Collapse" or "Expand", then "Regenerate outline in own frame". Finally, for each applicable outline renderer it adds a menu item to regenerate outline with that renderer.
Specified by:
addPopupMenuItems in interface OutlineMaker
See Also:
OutlineCommand

Copyright (c) 1996-1999
Massachusetts Institute of Technology

Feedback: jeva-feedback@ai.mit.edu