|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--edu.umd.cs.fuzzyTree.FuzzyTreeModel
TreeModel used by FuzzyTree to display a partial tree of an XML document. Each node
in the tree is assigned a score which is a relative measure of how valuable the
node is to be displayed. Expanding and collapsing subtrees are accomplished by adjusting
the scores of nodes to add/remove them. Scores are assigned by the ScoreProcessor
class. The class has a variety of parameters which are used in the score increase/decrease
algorithms, and which can be modified to produce different behavior.
Inner Class Summary | |
private static class |
FuzzyTreeModel.UserAction
Simple data structure, consists of affected node and an associated score change. |
Field Summary | |
private java.io.PrintWriter |
_actionsOutput
Debug output; output to System.out, unless the enviroment variable actionsFilename is specified. |
private DataNode |
_activeNode
Node that was last clicked on, which is highlighted. |
private java.io.PrintWriter |
_debugOutput
Debug output; output to System.out, unless the environment variable debugFilename is specified |
(package private) javax.swing.event.EventListenerList |
_listeners
Listeners of TreeModel events. |
private int |
_numDisplayedNodes
Number of nodes currently being displayed in addition to the root. |
(package private) java.util.Comparator |
_preorderIndexComparator
For sorting in ascending order of preorder index. |
private ScoreGenerator |
_scoreGenerator
For creating initial sorted list from the DataGraph. |
private java.util.ArrayList |
_sortedNodeList
A sorted list of all of the DataNode s in the DataGraph. |
private java.util.ArrayList |
_temporaryUserActionList
List of temporary actions. |
private DisplayNode |
_treeRoot
Root of the displayed tree. |
private java.util.ArrayList |
_userActions
List of user actions. |
private int |
_userHistorySize
Number of user history entries to maintain. |
(package private) static DataGraph |
dataGraph
Reference to the XML data graph. |
static int |
debugLevel
Debug levels (each level includes actions of lower levels). |
private static float |
decreaseReductionFactor
Factor by which to reduce score decreases when moving down a subtree. |
private static float |
decreaseThresholdValue
Threshold value at which score decreases are no longer applied. |
private static float |
increaseReductionFactor
Factor by which to reduce score increases when moving down a subtree. |
private static float |
increaseThresholdValue
Threshold value at which score increases are no longer applied. |
private static int |
INSERT_NODE_AFTER
Policy for nodes with the same score value |
private static int |
INSERT_NODE_BEFORE
Policy for nodes with the same score value |
private static float |
maxCollapseFactor
Maximum factor of score to decrease score when collasping. |
private static float |
maxExpandFactor
Maximum factor of score to increase score when expanding. |
private static int |
minChildrenToCollapse
Minimum number of children that should be removed when user collapses a subtree. |
private static int |
minChildrenToExpand
Minimum number of children that should be displayed when user expands a subtree. |
private static float |
minCollapseFactor
Maximum factor of score to decrease score when collasping. |
private static float |
minExpandFactor
Minimum factor of score to increase score when expanding. |
static int |
NODE_CLOSED
Node is closed (none of its children are displayed |
static int |
NODE_FULLY_OPEN
Node is fully open (all of its children are displayed). |
static int |
NODE_PARTIALLY_OPEN
Node is partially open (some of its children are displayed). |
Constructor Summary | |
FuzzyTreeModel(java.lang.String xmlFilename)
Create FuzzyTreeModel from the XML file passed in. |
Method Summary | |
private void |
addDisplayNode(DataNode node)
Adds node to the display tree. |
private void |
addDisplayNodeRange(int currentNumNodes)
Adds _numDisplayedNodes - currentNumNodes nodes to the display tree. |
void |
addTreeModelListener(javax.swing.event.TreeModelListener l)
|
private boolean |
addUserAction(java.util.ArrayList actionList)
Adds a new set of user actions to the user history. |
private java.io.PrintWriter |
createDebugOutput(java.lang.String filenameProperty,
boolean autoFlush)
Creates a PrintWriter from a file with name specified by the environment variable filenameProperty . |
private void |
debugFlush(int messageLevel)
|
private void |
debugPrint(int messageLevel,
java.lang.String message)
Prints the debug string message if messageLevel <= debugLevel |
private void |
debugPrintln(int messageLevel,
java.lang.String message)
Println the debug string message if messageLevel <= debugLevel |
private int |
decreaseNodeScore(DataNode dataNode,
float decreaseFactor,
java.util.ArrayList actionList)
Reduces the score of dataNode by decreaseFactor . |
private int |
decreaseSubtreeScore(DataNode dataNode,
float decreaseFactor,
java.util.ArrayList actionList)
Decreases the scores in the subtree of which dataNode is the root, by decreaseFactor . |
private void |
doSanityCheck()
For debugging purposes--executes only if debugLevel >= 3 . |
protected void |
finalize()
|
protected void |
fireTreeStructureChanged()
|
java.lang.Object |
getChild(java.lang.Object parent,
int index)
|
int |
getChildCount(java.lang.Object parent)
|
int |
getIndexOfChild(java.lang.Object parent,
java.lang.Object child)
|
static int |
getNodeState(java.lang.Object node)
Returns the open/close state of node . |
int |
getNumDisplayedNodes()
Returns number of nodes that are displayed |
FuzzyTreeParameters |
getParameters()
Get parameters used in score adjusting algorithms |
java.lang.Object |
getRoot()
|
int |
getTotalNodes()
Returns total number of nodes in the tree. |
private int |
increaseNodeScore(DataNode dataNode,
float increaseFactor,
java.util.ArrayList actionList)
Increases the score of dataNode by increaseFactor . |
private int |
increaseSubtreeScore(DataNode dataNode,
float increaseFactor,
java.util.ArrayList actionList)
Increases the scores in the subtree of which dataNode is the root, by increaseFactor . |
private boolean |
inflateNodeScore(DataNode sourceNode,
FuzzyTreeModel.UserAction temporaryUserAction)
Inflates the score of sourceNode such that it will be the highest-scoring
node in the tree. |
boolean |
isActiveNode(java.lang.Object node)
Returns true if node should be highlighted. |
boolean |
isLeaf(java.lang.Object node)
|
static boolean |
isOrphan(java.lang.Object node)
Returns true if node is not a child of its parent,
but rather a child of an ancestor. |
private static float |
loadPercentProperty(java.lang.String propertyName,
int defaultValue)
Loads a property value that is a percentage, returns the value divided by 100. |
private void |
moveSubtree(DataNode child,
DisplayNode displayParent)
Moves child under displayParent ,
if it is in the displayed tree; otherwise, any displayed descendants of child
are moved to under displayParent . |
private void |
printDisplayedNodes(java.io.PrintWriter out)
For debugging, executes only if debugLevel < 5 . |
private void |
printDisplayedNodes(java.io.PrintWriter out,
int numNodesToPrint)
For debugging, executes only if debugLevel < 5 . |
private void |
removeDisplayNode(DataNode node)
Removes node from the display tree. |
private void |
removeDisplayNodeRange(int currentDisplayedNodes)
Removes currentDisplayedNodes - _numDisplayedNodes nodes from
the displayTree. |
void |
removeTreeModelListener(javax.swing.event.TreeModelListener l)
|
private int |
repositionNodeInSortedList(DataNode node,
int insertPolicy)
Moves node from its current position in _sortedNodeList
to a new location based on its current score. |
void |
setNumDisplayedNodes(int newValue)
Set new value for number of displayed nodes |
void |
setParameters(FuzzyTreeParameters newParameters)
Set parameters for score adjusting algorithms |
private void |
undoAction(java.util.ArrayList actions)
Iterates through list of user actions and reverses the score change associated with each one. |
private void |
undoTemporaryAction()
Undoes the score change associated with the last temporary action. |
void |
userCollapseSubtree(java.lang.Object node,
boolean fullyCollapse)
Tries to collapse the subtree that node is the root of. |
void |
userExpandSubtree(java.lang.Object node,
boolean fullyExpand)
Tries to expand the subtree that node is the root of. |
void |
valueForPathChanged(javax.swing.tree.TreePath path,
java.lang.Object newValue)
TreeModel method. |
Methods inherited from class java.lang.Object |
|
Field Detail |
private static float minExpandFactor
Default is 5% (.05) Default can be changed with the
environment variable minExpandPercent
.
private static float maxCollapseFactor
Default is -5% (-.05) Default can be changed with the
environment variable maxCollapsePercent
.
private static float maxExpandFactor
Default is 50% (.5) Default can be changed with the
environment variable maxExpandPercent
.
private static float minCollapseFactor
Default is -50% (-.50) Default can be changed with the
environment variable minCollapsePercent
.
private static int minChildrenToExpand
maxExpandFactor
.
Default value is 3.
Default can be changed with the environment variable childrenToExpand
.
private static int minChildrenToCollapse
minCollapseFactor
.
Default value is 3.
Default can be changed with the environment variable childrenToCollapse
.
private static float increaseReductionFactor
parentIncrease * increaseReductionPercent
,
and so on.
Default value is 40%. Default can be changed with the environment variable increaseReductionPercent
.
private static float decreaseReductionFactor
parentDecrease * decreaseReductionPercent
,
and so on.
Default value is 40%. Default can be changed with the environment variable decreaseReductionPercent
.
private static float increaseThresholdValue
Default value is 4%.
Default can be changed with the environment variable increaseThresholdPercent
.
private static float decreaseThresholdValue
Default value is -4%.
Default can be changed with the environment variable decreaseThresholdPercent
.
private int _userHistorySize
userHistorySize
._userActions
static DataGraph dataGraph
private ScoreGenerator _scoreGenerator
private java.util.ArrayList _sortedNodeList
DataNode
s in the DataGraph.
Nodes are sorted based on the DataNode's score field.private java.util.ArrayList _userActions
_userHistorySize
ArrayList
of ArrayList
of UserAction
private java.util.ArrayList _temporaryUserActionList
ArrayList
of UserAction
.
private int _numDisplayedNodes
_numDisplayNodes + 1
nodes are always displayed)
Setter and getter methods do the +/- 1 adjustment.
Nodes from index 0 to _numDisplayedNodes - 1
of
_sortedNodeList
will be displayedprivate DisplayNode _treeRoot
_sortedNodeList
.private DataNode _activeNode
private java.io.PrintWriter _debugOutput
private java.io.PrintWriter _actionsOutput
public static int debugLevel
numDisplayedNodes - 1
of _sortedNodeList
are displayedjavax.swing.event.EventListenerList _listeners
java.util.Comparator _preorderIndexComparator
public static final int NODE_FULLY_OPEN
public static final int NODE_CLOSED
public static final int NODE_PARTIALLY_OPEN
private static final int INSERT_NODE_BEFORE
repositionNodeInSortedList(edu.umd.cs.fuzzyTree.DataNode, int)
private static final int INSERT_NODE_AFTER
repositionNodeInSortedList(edu.umd.cs.fuzzyTree.DataNode, int)
Constructor Detail |
public FuzzyTreeModel(java.lang.String xmlFilename) throws DataGraph.DataGraphException
xmlFilename
- XML file to open and create tree from. File must be a tree (not a graph)DataGraph.DataGraphException
- if there was an error opening/parsing the fileMethod Detail |
public java.lang.Object getRoot()
getRoot
in interface javax.swing.tree.TreeModel
public java.lang.Object getChild(java.lang.Object parent, int index)
getChild
in interface javax.swing.tree.TreeModel
public int getChildCount(java.lang.Object parent)
getChildCount
in interface javax.swing.tree.TreeModel
public boolean isLeaf(java.lang.Object node)
isLeaf
in interface javax.swing.tree.TreeModel
public void valueForPathChanged(javax.swing.tree.TreePath path, java.lang.Object newValue)
valueForPathChanged
in interface javax.swing.tree.TreeModel
public int getIndexOfChild(java.lang.Object parent, java.lang.Object child)
getIndexOfChild
in interface javax.swing.tree.TreeModel
public void addTreeModelListener(javax.swing.event.TreeModelListener l)
addTreeModelListener
in interface javax.swing.tree.TreeModel
public void removeTreeModelListener(javax.swing.event.TreeModelListener l)
removeTreeModelListener
in interface javax.swing.tree.TreeModel
public boolean isActiveNode(java.lang.Object node)
node
should be highlighted._activeNode
public int getTotalNodes()
public FuzzyTreeParameters getParameters()
public void setParameters(FuzzyTreeParameters newParameters)
newParameters
- new parameter valuespublic int getNumDisplayedNodes()
public void setNumDisplayedNodes(int newValue)
newValue
- new number of nodes to displaypublic static boolean isOrphan(java.lang.Object node)
node
is not a child of its parent,
but rather a child of an ancestor.DisplayNode.isOrphan()
public static int getNodeState(java.lang.Object node)
node
.NODE_FULLY_OPEN, NODE_CLOSED, NODE_PARTIALLY_OPEN
public void userExpandSubtree(java.lang.Object node, boolean fullyExpand)
node
is the root of. Expansion is done through
score changes and amount of score increase is constrained by
minExpandFactor
and maxExpandFactor
.
Score change to display childrenToExpand
nodes is applied if fullyExpand
is false, otherwise, score change to display all children is applied.
Applies score changes to descendants further down the tree, but the score
increase is reduced at each level by increaseReductionFactor
.
Score change is not applied if it is less than increaseThresholdValue
.
public void userCollapseSubtree(java.lang.Object node, boolean fullyCollapse)
node
is the root of.
Collapsing is done through score changes and amount of score decrease is constrained by
minCollapseFactor
and maxCollapseFactor
.
Applies score change to remove childrenToCollapse
nodes if
fullyExpand
is false,
otherwise, applies score change to remove all children.
Applies score changes to descendants further down the tree, but the score
decrease will is reduced at each level by decreaseReductionFactor
.
Score change is not applied if it is less than decreaseThresholdValue
.
protected void fireTreeStructureChanged()
private int increaseNodeScore(DataNode dataNode, float increaseFactor, java.util.ArrayList actionList)
dataNode
by increaseFactor
.
Adds action of updating the score to actionList
.dataNode
- the node to which to apply the score changeincreaseFactor
- factor score increaseactionList
- list to add the action of score increase toprivate int increaseSubtreeScore(DataNode dataNode, float increaseFactor, java.util.ArrayList actionList)
dataNode
is the root, by increaseFactor
.
Reduces the amount by which scores are increased at each level by
increaseReductionFactor
.
Adds the action of updating the score to actionList
.
Method is called recursively.
dataNode
- the node to which to apply the score changeincreaseFactor
- factor score increaseactionList
- list to add the action of score increase toprivate int decreaseNodeScore(DataNode dataNode, float decreaseFactor, java.util.ArrayList actionList)
dataNode
by decreaseFactor
.
Adds action of updating the score to actionList
.dataNode
- the node to which to apply the score changedecreaseFactor
- factor score decreaseactionList
- list to add the action of score decrease toprivate int decreaseSubtreeScore(DataNode dataNode, float decreaseFactor, java.util.ArrayList actionList)
dataNode
is the root, by decreaseFactor
.
Reduces the amount by which scores are decreased at each level by
decreaseReductionFactor
.
Adds the action of updating the score to actionList
.
Does not apply score change to nodes that are in the display tree.
Method is called recursively.
dataNode
- the node to which to apply the score changedecreaseFactor
- factor score decreaseactionList
- list to add the action of score decrease toprivate boolean inflateNodeScore(DataNode sourceNode, FuzzyTreeModel.UserAction temporaryUserAction)
sourceNode
such that it will be the highest-scoring
node in the tree. Sets the score change amount in temporaryUserAction
.sourceNode
- node to which to apply the score changetemporaryUserAction
- user action to record the score change.
actionNode
field should already be settrue
if node was added to the tree as a result of score inflation;
false
otherwiseprivate void undoTemporaryAction()
_temporaryUserActionList
private boolean addUserAction(java.util.ArrayList actionList)
private void undoAction(java.util.ArrayList actions)
actions
- list of UserAction
s to undoprivate void addDisplayNodeRange(int currentNumNodes)
_numDisplayedNodes - currentNumNodes
nodes to the display tree.currentNumNodes
- the number of nodes already displayedprivate void addDisplayNode(DataNode node)
node
to the display tree. It is positioned under any parent already
in the tree. If its parent is not in the tree, it is positioned under its closest ancestor,
and it will be an orphan.
Any descendants the node has that are in the display tree are positioned under it.node
- node to add to the display treeprivate void removeDisplayNodeRange(int currentDisplayedNodes)
currentDisplayedNodes - _numDisplayedNodes
nodes from
the displayTree.currentNumNodes
- the number of nodes currently displayedprivate void removeDisplayNode(DataNode node)
node
from the display tree. Children become the children of
node
's parent.node
- node to remove from the display treeprivate void moveSubtree(DataNode child, DisplayNode displayParent)
child
under displayParent
,
if it is in the displayed tree; otherwise, any displayed descendants of child
are moved to under displayParent
.
Method is called recursively.
private int repositionNodeInSortedList(DataNode node, int insertPolicy)
node
from its current position in _sortedNodeList
to a new location based on its current score.
If insertPolicy
is INSERT_NODE_BEFORE
, the node is
inserted before all other nodes with the same score; if it is INSERT_NODE_AFTER
node is inserted after all other nodes with the same score.
node
- node to be repositioned in _sortedNodeList
insertPolicy
- one of INSERT_NODE_BEFORE, INSERT_NODE_AFTER
node
protected void finalize()
finalize
in class java.lang.Object
private void doSanityCheck()
debugLevel >= 3
.
Checks to ensure that only numDisplayedNodes - 1
of
_sortedNodeList
are displayed.
Otherwise, prints a message to System.out
.private static float loadPercentProperty(java.lang.String propertyName, int defaultValue)
private void debugPrintln(int messageLevel, java.lang.String message)
message
if messageLevel <= debugLevel
private void debugPrint(int messageLevel, java.lang.String message)
message
if messageLevel <= debugLevel
private void debugFlush(int messageLevel)
private java.io.PrintWriter createDebugOutput(java.lang.String filenameProperty, boolean autoFlush)
filenameProperty
.
If file cannot be created, System.out
is returned.private void printDisplayedNodes(java.io.PrintWriter out, int numNodesToPrint)
debugLevel < 5
.private void printDisplayedNodes(java.io.PrintWriter out)
debugLevel < 5
.
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |