com.borland.primetime.node
Class TextStructure

java.lang.Object
  |
  +--com.borland.primetime.node.TextStructure
All Implemented Interfaces:
java.util.EventListener, java.awt.event.KeyListener, java.awt.event.MouseListener, javax.swing.tree.TreeCellRenderer

public class TextStructure
extends java.lang.Object
implements javax.swing.tree.TreeCellRenderer, java.awt.event.MouseListener, java.awt.event.KeyListener

A TextStructure object provides a tree structure that can be used in the structure pane. Actually the TextStructure object will manage a tree object, handling all user inputs, and showing and updating the tree. There are a handfull of methods that a derived class should override:


Inner Class Summary
protected  class TextStructure.StructureSelectionListener
           
 
Field Summary
protected static javax.swing.tree.DefaultTreeCellRenderer defaultTreeCellRenderer
           
protected  FileNode fileNode
           
protected  javax.swing.JTree tree
           
protected  javax.swing.tree.DefaultTreeModel treeModel
           
 
Constructor Summary
TextStructure()
           
 
Method Summary
protected  java.lang.Object[] findPath(java.lang.Object root, java.lang.String[] stringPath, int index)
          Helper function for setExpandState to find an expansion path by name.
 EditorPane getEditorPane()
          Retrieve the editorPane of the viewer associated with this TextStructure This will work for files displayed in one of the tabbed views of the content pane in the Browser.
 java.util.List getExpandState()
          Look at the tree in the structure pane, find all the expanded nodes, and encode all the expansion path in an array list.
 javax.swing.JPopupMenu getPopup()
          One of the functions that a derived class should override.
 javax.swing.Icon getStructureIcon(java.lang.Object value)
          One of the functions that a derived class should override.
 javax.swing.JTree getTree()
          Return the JTree object that this TextStructure is currently using.
 java.awt.Component getTreeCellRendererComponent(javax.swing.JTree tree, java.lang.Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus)
          Implements the TreeCellRenderer interface by calling the getTreeCellRendererComponent function of the defaultTreeCellRenderer.
 void keyPressed(java.awt.event.KeyEvent e)
          Key listener implementation which basically translates into a call to the nodeActivated function of the currently selected node.
 void keyReleased(java.awt.event.KeyEvent e)
          Key listener implementation which by default does nothing.
 void keyTyped(java.awt.event.KeyEvent e)
          Key listener implementation which by default does nothing.
 void mouseClicked(java.awt.event.MouseEvent e)
          Mouse listener implementation which basically translates into a call to the nodeSelected function of the node under the mouse.
 void mouseEntered(java.awt.event.MouseEvent e)
          Mouse listener implementation which by default does nothing.
 void mouseExited(java.awt.event.MouseEvent e)
          Mouse listener implementation which by default does nothing.
 void mousePressed(java.awt.event.MouseEvent e)
          Mouse listener implementation which by default only checks if the popup menu should be displayed.
 void mouseReleased(java.awt.event.MouseEvent e)
          Mouse listener implementation which by default only checks if the popup menu should be displayed.
 void nodeActivated(javax.swing.tree.DefaultMutableTreeNode node)
          One of the functions that a derived class should override.
 void nodeSelected(javax.swing.tree.DefaultMutableTreeNode node)
          One of the functions that a derived class should override.
 void setCaretOffset(int offset, boolean requestFocus)
          Make the fileNode associated with this TextStructure into the active fileNode, retrieve the text node viewer, and make that viewer the active viewer, retrieve the editor, and set the caret and the focus.
 void setCaretPosition(int offset, boolean requestFocus)
          Get the editor of the fileNode associated with this TextStructure, position the caret at a certain file offset, and optionally request the focus.
 void setCaretPosition(int line, int column, boolean requestFocus)
          Get the editor of the fileNode associated with this TextStructure, position the caret at a certain line and column, and optionally request the focus.
 void setExpandState(java.util.List expansionList)
          Taking an array list with encoded expansion paths, try to apply these expansions to the current tree.
 void setFileNode(FileNode fileNode)
          Remember the file that provides the information displayed in this TextStructure object.
 void setTree(javax.swing.JTree tree)
          Hook a tree up to this TextStructure object so it can be managed correctly.
 void updateStructure(javax.swing.text.Document doc)
          One of the functions that a derived class should override.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

tree

protected javax.swing.JTree tree

fileNode

protected FileNode fileNode

treeModel

protected javax.swing.tree.DefaultTreeModel treeModel

defaultTreeCellRenderer

protected static javax.swing.tree.DefaultTreeCellRenderer defaultTreeCellRenderer
Constructor Detail

TextStructure

public TextStructure()
Method Detail

setFileNode

public void setFileNode(FileNode fileNode)
Remember the file that provides the information displayed in this TextStructure object. This file should normally be the active file in the Browser.
Parameters:
fileNode - the FileNode object describing the active file.

setTree

public void setTree(javax.swing.JTree tree)
Hook a tree up to this TextStructure object so it can be managed correctly.
Parameters:
tree - the tree object that this TextStructure should manage.

getTree

public javax.swing.JTree getTree()
Return the JTree object that this TextStructure is currently using.
Returns:
The tree currently used.

updateStructure

public void updateStructure(javax.swing.text.Document doc)
One of the functions that a derived class should override. By default, this function does nothing.
Parameters:
doc - The document that provides information for the structure pane.

getPopup

public javax.swing.JPopupMenu getPopup()
One of the functions that a derived class should override. By default, this function return null.
Returns:
the local context popup that should be shown.

nodeSelected

public void nodeSelected(javax.swing.tree.DefaultMutableTreeNode node)
One of the functions that a derived class should override. By default, this function does nothing.
Parameters:
node - The node selected, for instance through a single mouse click.

nodeActivated

public void nodeActivated(javax.swing.tree.DefaultMutableTreeNode node)
One of the functions that a derived class should override. By default, this function does nothing
Parameters:
node - The node activated, for instance through a double mouse click.

getStructureIcon

public javax.swing.Icon getStructureIcon(java.lang.Object value)
One of the functions that a derived class should override. Each node in the tree can display an icon, and this function is called for each visible node in the tree. By default, this function return null.
Parameters:
value - The node that wants an icon.
Returns:
the icon that the node wants.

getEditorPane

public EditorPane getEditorPane()
Retrieve the editorPane of the viewer associated with this TextStructure This will work for files displayed in one of the tabbed views of the content pane in the Browser.
Returns:
the editorPane of the viewer associated with this TextStructure, or null if the editor couldn't be found.

setCaretOffset

public void setCaretOffset(int offset,
                           boolean requestFocus)
Make the fileNode associated with this TextStructure into the active fileNode, retrieve the text node viewer, and make that viewer the active viewer, retrieve the editor, and set the caret and the focus.
Parameters:
offset - the desired zero based file offset for the caret
requestFocus - if true, request focus for the editor.

setCaretPosition

public void setCaretPosition(int line,
                             int column,
                             boolean requestFocus)
Get the editor of the fileNode associated with this TextStructure, position the caret at a certain line and column, and optionally request the focus. This will only work if the fileNode is the active fileNode and the text node viewer of that fileNode is the active viewer. Use setCaretOffset if you want to force the fileNode and viewer into active duty.
Parameters:
line - the desired one based line for the caret
column - the desired one based column for the caret
requestFocus - if true, request focus for the editor

setCaretPosition

public void setCaretPosition(int offset,
                             boolean requestFocus)
Get the editor of the fileNode associated with this TextStructure, position the caret at a certain file offset, and optionally request the focus. This will only work if the fileNode is the active fileNode and the text node viewer of that fileNode is the active viewer. Use setCaretOffset if you want to force the fileNode and viewer into active duty.
Parameters:
offset - the desired zero based file offset for the caret

getTreeCellRendererComponent

public java.awt.Component getTreeCellRendererComponent(javax.swing.JTree tree,
                                                       java.lang.Object value,
                                                       boolean selected,
                                                       boolean expanded,
                                                       boolean leaf,
                                                       int row,
                                                       boolean hasFocus)
Implements the TreeCellRenderer interface by calling the getTreeCellRendererComponent function of the defaultTreeCellRenderer. Before the defaultTreeCellRenderer is returned, a call is made to getStructureIcon to set the icon of the incoming node.
Specified by:
getTreeCellRendererComponent in interface javax.swing.tree.TreeCellRenderer
Parameters:
tree - the tree this TextStructure manages.
value - the object representing a node
selected - true if the node is selected
expanded - true if the node is expanded
leaf - true if the node is a leaf
row - the location in the tree
hasFocus - true if the node has focus.
Returns:
the TreeCellRenderer, in this case the defaultTreeCellRenderer.

keyPressed

public void keyPressed(java.awt.event.KeyEvent e)
Key listener implementation which basically translates into a call to the nodeActivated function of the currently selected node.
Specified by:
keyPressed in interface java.awt.event.KeyListener
Parameters:
e - the keyEvent caused by the key press.

keyReleased

public void keyReleased(java.awt.event.KeyEvent e)
Key listener implementation which by default does nothing.
Specified by:
keyReleased in interface java.awt.event.KeyListener
Parameters:
e - the keyEvent caused by the key press.

keyTyped

public void keyTyped(java.awt.event.KeyEvent e)
Key listener implementation which by default does nothing.
Specified by:
keyTyped in interface java.awt.event.KeyListener
Parameters:
e - the keyEvent caused by the key press.

mouseClicked

public void mouseClicked(java.awt.event.MouseEvent e)
Mouse listener implementation which basically translates into a call to the nodeSelected function of the node under the mouse. This function first checks if the popup menu should be displayed.
Specified by:
mouseClicked in interface java.awt.event.MouseListener
Parameters:
e - the mouseEvent caused by the mouse click

mousePressed

public void mousePressed(java.awt.event.MouseEvent e)
Mouse listener implementation which by default only checks if the popup menu should be displayed.
Specified by:
mousePressed in interface java.awt.event.MouseListener
Parameters:
e - the mouseEvent caused by the mouse press.

mouseReleased

public void mouseReleased(java.awt.event.MouseEvent e)
Mouse listener implementation which by default only checks if the popup menu should be displayed.
Specified by:
mouseReleased in interface java.awt.event.MouseListener
Parameters:
e - the mouseEvent caused by the mouse release

mouseEntered

public void mouseEntered(java.awt.event.MouseEvent e)
Mouse listener implementation which by default does nothing.
Specified by:
mouseEntered in interface java.awt.event.MouseListener
Parameters:
e - the mouseEvent caused by the mouse enter.

mouseExited

public void mouseExited(java.awt.event.MouseEvent e)
Mouse listener implementation which by default does nothing.
Specified by:
mouseExited in interface java.awt.event.MouseListener
Parameters:
e - the mouseEvent caused by the mouse exit.

getExpandState

public java.util.List getExpandState()
Look at the tree in the structure pane, find all the expanded nodes, and encode all the expansion path in an array list.

findPath

protected java.lang.Object[] findPath(java.lang.Object root,
                                      java.lang.String[] stringPath,
                                      int index)
Helper function for setExpandState to find an expansion path by name.

setExpandState

public void setExpandState(java.util.List expansionList)
Taking an array list with encoded expansion paths, try to apply these expansions to the current tree.