org.jbudget.gui.budget
Class BudgetTreeModel

java.lang.Object
  extended by org.jbudget.gui.budget.BudgetTreeModel
All Implemented Interfaces:
javax.swing.tree.TreeModel

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

An implementation of the TreeModel interface that is used to display a Budget class as a jTree.

Author:
petrov

Nested Class Summary
private  class BudgetTreeModel.AllocationsSignaler
          implements the Signaler interface.
private static interface BudgetTreeModel.Signaler
           
private  class BudgetTreeModel.TransactionsSignaler
          implements the Signaler interface.
 
Field Summary
(package private) static java.lang.String accounts
           
(package private)  org.jbudget.Core.Budget budget
           
(package private) static java.lang.String expenseCategories
           
(package private) static java.lang.String incomeSources
           
private  java.util.List<java.lang.Object> list
           
(package private)  java.util.List<javax.swing.event.TreeModelListener> listeners
           
(package private) static java.lang.String root
           
private  boolean showAllocations
           
private  boolean showTransactions
           
private  java.util.List<java.lang.Object> typesList
           
 
Constructor Summary
BudgetTreeModel(org.jbudget.Core.Budget budget)
          Creates a new instance of BudgetTreeModel
 
Method Summary
 void addTreeModelListener(javax.swing.event.TreeModelListener listener)
          Add a listener that will be notified when the model or underlying budget object change.
private  java.util.List<org.jbudget.Core.ExpenseCategory> getCategoryPath(org.jbudget.Core.ExpenseCategory category)
          Returns a path to a given expense category
 java.lang.Object getChild(java.lang.Object parent, int index)
          returns a child object
 int getChildCount(java.lang.Object parent)
          returns number of children of an object
private  java.util.List<java.lang.Object> getChildrenList(java.lang.Object parent)
          get a list of children of a particular object.
 int getIndexOfChild(java.lang.Object parent, java.lang.Object child)
          returns the index of a child
 java.lang.Object[] getPath(java.lang.Object object, boolean bySource)
          Returns a path that identifies a given object in the tree
 java.lang.Object getRoot()
          returns the root of the tree
 boolean getShowAllcations()
          Returns true if allocations are shown
 boolean getShowTransactions()
          Returns true if deductions are shown
 javax.swing.tree.TreePath getTreePath(java.lang.Object object, boolean bySource)
          Returns a TreePath to the given Object
 boolean isLeaf(java.lang.Object node)
          returns true if the object does not have any children
 void removeTreeModelListener(javax.swing.event.TreeModelListener listener)
          Remove a listener.
 void setShowAllocations(boolean showAllocations)
          Shows/hides allocations
 void setShowTransactions(boolean showTransactions)
          Shows/hides automatic transactions
private  void signalDisplayAllocations(java.util.List<java.lang.Object> path, boolean display)
          A helper function that signals the tree model that allocations should be displayed or hidden
private  void signalDisplayTransactions(java.util.List<java.lang.Object> path, boolean display)
          A helper function that signals the tree model that automatic transactions should be displayed or hidden
 void signalNodeChanged(javax.swing.tree.TreePath path, int index)
          signals to all listeners that a node was updated.
 void signalNodeInserted(javax.swing.tree.TreePath path, int index)
          signals to all listeners that a node was inserted.
 void signalNodeRemoved(javax.swing.tree.TreePath path, int index)
          Removes a node.
private  void signalRecursively(java.util.List<java.lang.Object> path, BudgetTreeModel.Signaler signaler)
          Recursively applies a 'signal' function to a given node and to all its leafs
 void signalStructureChanged()
          signals to all listeners that the structure of the whole tree has changed.
 void signalStructureChanged(javax.swing.tree.TreePath path, int index)
          signals to all listeners that the structure of the tree has changed.
 void valueForPathChanged(javax.swing.tree.TreePath path, java.lang.Object newValue)
          called when the object is changed
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

budget

final org.jbudget.Core.Budget budget

listeners

java.util.List<javax.swing.event.TreeModelListener> listeners

root

static final java.lang.String root
See Also:
Constant Field Values

expenseCategories

static final java.lang.String expenseCategories
See Also:
Constant Field Values

accounts

static final java.lang.String accounts
See Also:
Constant Field Values

incomeSources

static final java.lang.String incomeSources
See Also:
Constant Field Values

showAllocations

private boolean showAllocations

showTransactions

private boolean showTransactions

list

private final java.util.List<java.lang.Object> list

typesList

private final java.util.List<java.lang.Object> typesList
Constructor Detail

BudgetTreeModel

public BudgetTreeModel(org.jbudget.Core.Budget budget)
Creates a new instance of BudgetTreeModel

Method Detail

addTreeModelListener

public void addTreeModelListener(javax.swing.event.TreeModelListener listener)
Add a listener that will be notified when the model or underlying budget object change.

Specified by:
addTreeModelListener in interface javax.swing.tree.TreeModel

removeTreeModelListener

public void removeTreeModelListener(javax.swing.event.TreeModelListener listener)
Remove a listener.

Specified by:
removeTreeModelListener in interface javax.swing.tree.TreeModel

getChild

public java.lang.Object getChild(java.lang.Object parent,
                                 int index)
returns a child object

Specified by:
getChild in interface javax.swing.tree.TreeModel

getChildCount

public int getChildCount(java.lang.Object parent)
returns number of children of an object

Specified by:
getChildCount in interface javax.swing.tree.TreeModel

getIndexOfChild

public int getIndexOfChild(java.lang.Object parent,
                           java.lang.Object child)
returns the index of a child

Specified by:
getIndexOfChild in interface javax.swing.tree.TreeModel

getRoot

public java.lang.Object getRoot()
returns the root of the tree

Specified by:
getRoot in interface javax.swing.tree.TreeModel

isLeaf

public boolean isLeaf(java.lang.Object node)
returns true if the object does not have any children

Specified by:
isLeaf in interface javax.swing.tree.TreeModel

valueForPathChanged

public void valueForPathChanged(javax.swing.tree.TreePath path,
                                java.lang.Object newValue)
called when the object is changed

Specified by:
valueForPathChanged in interface javax.swing.tree.TreeModel

getChildrenList

private java.util.List<java.lang.Object> getChildrenList(java.lang.Object parent)
get a list of children of a particular object. Returns empty list for ExpenseAllocations and AutomaticTransactions. Returns a list of subcategories for an ExpenseCategory. If enabled adds ExpenseAllocations and AutomaticTransactions to the list for ExpenseCategories, Accounts, and IncomeSources.


getTreePath

public javax.swing.tree.TreePath getTreePath(java.lang.Object object,
                                             boolean bySource)
Returns a TreePath to the given Object

Parameters:
object - the object the path to will be returned.
bySource - some leaf nodes can appear in two places if they have both source and destination. If this flag is true a path through the source of a transaction will be returned. In the opposite case a path through a destinaiton will be returned.

getPath

public java.lang.Object[] getPath(java.lang.Object object,
                                  boolean bySource)
Returns a path that identifies a given object in the tree

Parameters:
object - the object the path to will be returned.
bySource - Some leaf nodes can appear in two places if they have both source and destination. If this flag is true a path through the source of a transaction will be returned. In the opposite case a path through a destinaiton will be returned.

getCategoryPath

private java.util.List<org.jbudget.Core.ExpenseCategory> getCategoryPath(org.jbudget.Core.ExpenseCategory category)
Returns a path to a given expense category


setShowAllocations

public void setShowAllocations(boolean showAllocations)
Shows/hides allocations


getShowAllcations

public boolean getShowAllcations()
Returns true if allocations are shown


setShowTransactions

public void setShowTransactions(boolean showTransactions)
Shows/hides automatic transactions


getShowTransactions

public boolean getShowTransactions()
Returns true if deductions are shown


signalRecursively

private void signalRecursively(java.util.List<java.lang.Object> path,
                               BudgetTreeModel.Signaler signaler)
Recursively applies a 'signal' function to a given node and to all its leafs


signalDisplayAllocations

private void signalDisplayAllocations(java.util.List<java.lang.Object> path,
                                      boolean display)
A helper function that signals the tree model that allocations should be displayed or hidden


signalDisplayTransactions

private void signalDisplayTransactions(java.util.List<java.lang.Object> path,
                                       boolean display)
A helper function that signals the tree model that automatic transactions should be displayed or hidden


signalNodeRemoved

public void signalNodeRemoved(javax.swing.tree.TreePath path,
                              int index)
Removes a node.

Parameters:
path - the path to the node that will be removed
index - the index of the node that will be removed in the list of all children of the node's parent.

signalNodeInserted

public void signalNodeInserted(javax.swing.tree.TreePath path,
                               int index)
signals to all listeners that a node was inserted.

Parameters:
path - the path to the node that was inserted.
index - the index given by getChildIndex(...).

signalNodeChanged

public void signalNodeChanged(javax.swing.tree.TreePath path,
                              int index)
signals to all listeners that a node was updated.

Parameters:
path - the path to the node that was updated.
index - the index given by getChildIndex(...).

signalStructureChanged

public void signalStructureChanged(javax.swing.tree.TreePath path,
                                   int index)
signals to all listeners that the structure of the tree has changed.

Parameters:
path - the path to the node that is the root of the part of the tree that has changed.
index - the index given by getChildIndex(...).

signalStructureChanged

public void signalStructureChanged()
signals to all listeners that the structure of the whole tree has changed.