|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--fri.gui.swing.polytreetable.AbstractPolyTreeNode | +--fri.gui.swing.polytreetable.DefaultPolyTreeNode | +--fri.gui.swing.polytreetable.DefaultCachedPolyTreeNode
Implements a cached PolyTreeNode that avoids redundancy of nodes in child and parent lists. This makes it possible that every node holds its parent and child references to other nodes without pointing to objects created by unlimited "new" calls (the target is to substitute the "new" operator, so that there exists exactly one node for one userObject).
If you use a PolyTreeTableUserObject subclass, you do not need to extend this class. Use it like this:
PolyTreeNode startNode = DefaultCachedPolyTreeNode.create(userObject);Else override getChildCount() and getParentCount() to read data for the rendered structure, as they get messaged when a tree expansion takes place.
class FilePolyTreeNode extends DefaultPolyTreeNode { public int getChildCount() { // messaged when enumerating children if (children == null) { children = new Vector(); File file = (File)getUserObject(); File [] files = file.listFiles(); for (int i = 0; files != null && i < files.length; i++) { children.add(createCachedPolyTreeNode(files[i])); // createCachedPolyTreeNode() calls createPolyTreeNode() when // node not cached, and caches it. } } return super.getChildCount(); } protected abstract PolyTreeNode createPolyTreeNode(Object userObject) { // substitutes the "new" operator and creates a specific class of nodes. return new FilePolyTreeNode(userObject); } ... }
DefaultPolyTreeNode
Field Summary |
Fields inherited from class fri.gui.swing.polytreetable.AbstractPolyTreeNode |
allowsChildren, allowsParents, children, EMPTY_ENUMERATION, parents, userObject |
Constructor Summary | |
|
DefaultCachedPolyTreeNode()
No-arg do-nothing constructor just for calling PolyTreeNode startNode = new DefaultCachedPolyTreeNode().createCachedPolyTreeNode(userObject); to get a start node. |
protected |
DefaultCachedPolyTreeNode(java.lang.Object userObject)
Constructor used by factory method createPolyTreeNode(userObject). |
Method Summary | |
protected PolyTreeNode |
cacheInsertNode(PolyTreeNode newNode)
Caches a new node or replaces the new node by a chached one. |
static void |
clearCache(java.lang.Class userObjectClass)
Clears the cache of userObjects -> PolyTreeNode |
static PolyTreeNode |
create(java.lang.Object userObject)
Convenience method that calls new DefaultCachedPolyTreeNode().createCachedPolyTreeNode(userObject) .
|
protected PolyTreeNode |
createCachedPolyTreeNode(java.lang.Object userObject)
Factory method to create and find buffered PolyTreeNodes, identified by their userObject. |
protected PolyTreeNode |
createPolyTreeNode(java.lang.Object userObject)
Factory method to create a typed PolyTreeNodes. |
int |
getChildCount()
Returns the number of children the receiver contains. |
int |
getParentCount()
Returns the number of parents the receiver contains. |
void |
insertChild(PolyTreeNode newNode,
int index)
Insert a new child at passed index. |
void |
insertParent(PolyTreeNode newNode,
int index)
Insert a new parent at passed index. |
boolean |
setColumnObject(int column,
java.lang.Object aValue)
Convenience implementation for column objects in conjunction with DefaultPolyTreeTableModel.setValueAt(). |
Methods inherited from class fri.gui.swing.polytreetable.DefaultPolyTreeNode |
getAllowsChildren, getAllowsParents, getColumnObject, isCellEditable, removeChild, removeParent, setUserObject |
Methods inherited from class fri.gui.swing.polytreetable.AbstractPolyTreeNode |
children, getChildAt, getChildIndex, getElementCount, getParentAt, getParentIndex, getUserObject, isChildLeaf, isNodeChild, isNodeParent, isParentLeaf, parents, setAllowsChildren, setAllowsParents, toString |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface fri.gui.swing.polytreetable.PolyTreeNode |
children, getChildAt, getChildIndex, getParentAt, getParentIndex, getUserObject, isChildLeaf, isParentLeaf, parents |
Constructor Detail |
public DefaultCachedPolyTreeNode()
PolyTreeNode startNode = new DefaultCachedPolyTreeNode().createCachedPolyTreeNode(userObject);to get a start node.
protected DefaultCachedPolyTreeNode(java.lang.Object userObject)
Method Detail |
public int getChildCount()
getChildCount
in interface PolyTreeNode
getChildCount
in class DefaultPolyTreeNode
public int getParentCount()
getParentCount
in interface PolyTreeNode
getParentCount
in class DefaultPolyTreeNode
public boolean setColumnObject(int column, java.lang.Object aValue)
setColumnObject
in class DefaultPolyTreeNode
public static void clearCache(java.lang.Class userObjectClass)
public static PolyTreeNode create(java.lang.Object userObject)
new DefaultCachedPolyTreeNode().createCachedPolyTreeNode(userObject)
.
ATTENTION: This method depends on userObject.hashCode()
to find existing
nodes, this means that one has to implement this if not done by some superclass.
protected PolyTreeNode createCachedPolyTreeNode(java.lang.Object userObject)
createPolyTreeNode()
.
If userObject is not found in cache, a new node is created and put into cache.
The properties allowsChildren and allowsParents are both set to true.
ATTENTION: This method depends on userObject.hashCode()
to find existing
nodes, this means that one has to implement this if not done by some superclass.
protected PolyTreeNode createPolyTreeNode(java.lang.Object userObject)
return new FilePolyTreeNode(userObject);
public void insertParent(PolyTreeNode newNode, int index)
insertParent
in interface MutablePolyTreeNode
insertParent
in class DefaultPolyTreeNode
public void insertChild(PolyTreeNode newNode, int index)
insertChild
in interface MutablePolyTreeNode
insertChild
in class DefaultPolyTreeNode
protected PolyTreeNode cacheInsertNode(PolyTreeNode newNode)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |