org.openstreetmap.josm.gui.dialogs.relation
Class RelationTreeModel

java.lang.Object
  extended by org.openstreetmap.josm.gui.dialogs.relation.RelationTreeModel
All Implemented Interfaces:
javax.swing.tree.TreeModel

public class RelationTreeModel
extends java.lang.Object
implements javax.swing.tree.TreeModel

This is a TreeModel which provides the hierarchical structure of Relations to a JTree. The model is initialized with a root relation or with a list of RelationMembers, see populate(Relation) and populate(List) respectively.


Field Summary
private  java.util.concurrent.CopyOnWriteArrayList<javax.swing.event.TreeModelListener> listeners
          the tree model listeners
private  Relation root
          the root relation
 
Constructor Summary
RelationTreeModel()
          constructor
RelationTreeModel(java.util.List<RelationMember> members)
          constructor
RelationTreeModel(Relation root)
          constructor
 
Method Summary
 void addTreeModelListener(javax.swing.event.TreeModelListener l)
           
protected  void fireRefreshNode(javax.swing.tree.TreePath path)
          Notifies tree model listeners about an update of the trees nodes.
protected  void fireRootReplacedEvent()
          Notifies tree model listeners about a replacement of the root.
 java.lang.Object getChild(java.lang.Object parent, int index)
           
 int getChildCount(java.lang.Object parent)
           
protected  int getIndexForRelationChild(Relation parent, Relation child)
          Replies the index of a particular child with respect to its parent.
 int getIndexOfChild(java.lang.Object parent, java.lang.Object child)
           
protected  int getNumRelationChildren(Relation parent)
          Replies the number of children of type relation for a particular relation parent
protected  Relation getRelationChildByIdx(Relation parent, int idx)
          Replies the i-th child of type relation for a particular relation parent.
 java.lang.Object getRoot()
           
 boolean isLeaf(java.lang.Object node)
           
 void populate(java.util.List<RelationMember> members)
          Populates the model with a list of relation members
 void populate(Relation root)
          Populates the model with a root relation
 void refreshNode(javax.swing.tree.TreePath pathToNode)
          Invoke to notify all listeners about an update of a particular node
 void removeTreeModelListener(javax.swing.event.TreeModelListener l)
           
 void valueForPathChanged(javax.swing.tree.TreePath path, java.lang.Object newValue)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

root

private Relation root
the root relation


listeners

private java.util.concurrent.CopyOnWriteArrayList<javax.swing.event.TreeModelListener> listeners
the tree model listeners

Constructor Detail

RelationTreeModel

public RelationTreeModel()
constructor


RelationTreeModel

public RelationTreeModel(Relation root)
constructor

Parameters:
root - the root relation

RelationTreeModel

public RelationTreeModel(java.util.List<RelationMember> members)
constructor

Parameters:
members - a list of members
Method Detail

getNumRelationChildren

protected int getNumRelationChildren(Relation parent)
Replies the number of children of type relation for a particular relation parent

Parameters:
parent - the parent relation
Returns:
the number of children of type relation

getRelationChildByIdx

protected Relation getRelationChildByIdx(Relation parent,
                                         int idx)
Replies the i-th child of type relation for a particular relation parent.

Parameters:
parent - the parent relation
idx - the index
Returns:
the i-th child of type relation for a particular relation parent; null, if no such child exists

getIndexForRelationChild

protected int getIndexForRelationChild(Relation parent,
                                       Relation child)
Replies the index of a particular child with respect to its parent.

Parameters:
parent - the parent relation
child - the child relation
Returns:
the index of a particular child with respect to its parent; -1 if either parent or child are null or if child isn't a child of parent.

populate

public void populate(Relation root)
Populates the model with a root relation

Parameters:
root - the root relation
See Also:
populate(List)

populate

public void populate(java.util.List<RelationMember> members)
Populates the model with a list of relation members

Parameters:
members - the relation members

fireRootReplacedEvent

protected void fireRootReplacedEvent()
Notifies tree model listeners about a replacement of the root.


fireRefreshNode

protected void fireRefreshNode(javax.swing.tree.TreePath path)
Notifies tree model listeners about an update of the trees nodes.

Parameters:
path - the tree path to the node

refreshNode

public void refreshNode(javax.swing.tree.TreePath pathToNode)
Invoke to notify all listeners about an update of a particular node

Parameters:
pathToNode - the tree path to the node

getChild

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

getChildCount

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

getIndexOfChild

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

getRoot

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

isLeaf

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

addTreeModelListener

public void addTreeModelListener(javax.swing.event.TreeModelListener l)
Specified by:
addTreeModelListener in interface javax.swing.tree.TreeModel

removeTreeModelListener

public void removeTreeModelListener(javax.swing.event.TreeModelListener l)
Specified by:
removeTreeModelListener in interface javax.swing.tree.TreeModel

valueForPathChanged

public void valueForPathChanged(javax.swing.tree.TreePath path,
                                java.lang.Object newValue)
Specified by:
valueForPathChanged in interface javax.swing.tree.TreeModel


JOSM