ubiware.core.visualizer
Class BeliefTreeModel

java.lang.Object
  extended by ubiware.core.visualizer.BeliefTreeModel
All Implemented Interfaces:
javax.swing.tree.TreeModel, SubtreesTreeModel

public class BeliefTreeModel
extends java.lang.Object
implements SubtreesTreeModel

Maps a belief to a tree like structure.

This is a tree structure whose nodes are complete subtrees. For more information, read SubtreesTreeModel.

A belief always has three children, with the following indexes:

 0 : subject
 1 : predicate
 2 : object
 

Subject and Object can be either a string literal or a BeliefContainerTreeModel. A Predicate is always a string literal. A string literal has 0 children.

String literals are now officially always instances of StringLiteralTreeModel or subclasses.

Author:
Nikos Mouchtaris

Constructor Summary
BeliefTreeModel(javax.swing.tree.TreeModel root, ReusableAtomicBehavior rabi, SemanticStatement ss)
           Initialises a new instance of BeliefTreeModel which will represent the semantic statement specified by the given semantic statement.
 
Method Summary
 void addTreeModelListener(javax.swing.event.TreeModelListener l)
           This method has no effect in this implementation.
 java.lang.Object getChild(java.lang.Object parent, int index)
           If parent == this then it returns the semantic statement parts as follows:
 int getChildCount(java.lang.Object parent)
           
 int getIndexOfChild(java.lang.Object parent, java.lang.Object child)
           
 javax.swing.tree.TreeModel getObject()
           Equivalent to getChild(this, 2).
 javax.swing.tree.TreeModel getPredicate()
           Equivalent to getChild(this, 1).
 javax.swing.tree.TreeModel getRoot()
           
 javax.swing.tree.TreeModel getSubject()
           Equivalent to getChild(this, 0).
 boolean isLeaf(java.lang.Object node)
           
 void removeTreeModelListener(javax.swing.event.TreeModelListener l)
           This method has no effect in this implementation.
 java.lang.String toString()
           Returns a simple textual representation of this semantic statement tree model representation which consists of the subject's, predicate's and object's textual representations (toString()), separated by a space character.
 void valueForPathChanged(javax.swing.tree.TreePath path, java.lang.Object newValue)
           This method has no effect in this implementation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

BeliefTreeModel

public BeliefTreeModel(javax.swing.tree.TreeModel root,
                       ReusableAtomicBehavior rabi,
                       SemanticStatement ss)

Initialises a new instance of BeliefTreeModel which will represent the semantic statement specified by the given semantic statement.

The given ReusableAtomicBehavior, rabi, is used in order to acquire all beliefs in the belief contexts found as subject, predicate or object of this semantic statement. rabi is never used again, throughout the whole life cycle of this object. It is not even stored in a field.

This model will create a whole tree-like substructure of the Agent's beliefs (as acquired by rabi). The children of this model will be either BeliefContainerTreeModels or string literals, created according to the actual beliefs found in ss's SemanticStatement.subject and SemanticStatement.object. SemanticStatement.predicate is expected always to be a string literal. The locally re-created structure of beliefs is used whenever queries are made to this model. The Agent's actual belief storage is never re-read.

root is the actual root element of this model. This could be any TreeModel which might cooperate with this one. If root is null then the root of the tree is believed to be this! and this belief is being passed accordingly to the children TreeModels created as the result of this model's initialisation.

Parameters:
root - the actual root of the whole tree (if null then root = this)
rabi - a RAB to be used for accessing the Agent's beliefs
ss - the semantic statement to be represented by this model
Method Detail

getRoot

public javax.swing.tree.TreeModel getRoot()
Specified by:
getRoot in interface javax.swing.tree.TreeModel

getChild

public java.lang.Object getChild(java.lang.Object parent,
                                 int index)

If parent == this then it returns the semantic statement parts as follows:

index == 0
subject
index == 1
predicate
index == 2
object

Otherwise it calls TreeModel.getChild(java.lang.Object, int) for parent, after casting it to a TreeModel.

Specified by:
getChild in interface javax.swing.tree.TreeModel
Parameters:
parent - the parent of the child
index - the index of the child (0, 1, 2)
Returns:
a child according to parent and index

getChildCount

public int getChildCount(java.lang.Object parent)
Specified by:
getChildCount in interface javax.swing.tree.TreeModel

isLeaf

public boolean isLeaf(java.lang.Object node)
Specified by:
isLeaf in interface javax.swing.tree.TreeModel

valueForPathChanged

public void valueForPathChanged(javax.swing.tree.TreePath path,
                                java.lang.Object newValue)

This method has no effect in this implementation.

Specified by:
valueForPathChanged in interface javax.swing.tree.TreeModel
Parameters:
path - ignored
newValue - ignored

getIndexOfChild

public int getIndexOfChild(java.lang.Object parent,
                           java.lang.Object child)
Specified by:
getIndexOfChild in interface javax.swing.tree.TreeModel

addTreeModelListener

public void addTreeModelListener(javax.swing.event.TreeModelListener l)

This method has no effect in this implementation.

Specified by:
addTreeModelListener in interface javax.swing.tree.TreeModel
Parameters:
l - ignored

removeTreeModelListener

public void removeTreeModelListener(javax.swing.event.TreeModelListener l)

This method has no effect in this implementation.

Specified by:
removeTreeModelListener in interface javax.swing.tree.TreeModel
Parameters:
l - ignored

getSubject

public javax.swing.tree.TreeModel getSubject()

Equivalent to getChild(this, 0).

Returns:
the subtree of the subject of this semantic statement.

getPredicate

public javax.swing.tree.TreeModel getPredicate()

Equivalent to getChild(this, 1).

Returns:
the subtree of the predicate of this semantic statement.

getObject

public javax.swing.tree.TreeModel getObject()

Equivalent to getChild(this, 2).

Returns:
the subtree of the object of this semantic statement.

toString

public java.lang.String toString()

Returns a simple textual representation of this semantic statement tree model representation which consists of the subject's, predicate's and object's textual representations (toString()), separated by a space character.

Overrides:
toString in class java.lang.Object
Returns:
"subject predicate object"