com.miginfocom.calendar.category
Class Category

java.lang.Object
  extended by com.miginfocom.calendar.category.Category
All Implemented Interfaces:
AdjustingPropertyConsumer, PropertyConsumer, PropertyObservable, PropertyProvider, java.lang.Comparable, javax.swing.tree.TreeNode
Direct Known Subclasses:
DemoDataBean

public class Category
extends java.lang.Object
implements java.lang.Comparable, javax.swing.tree.TreeNode, PropertyObservable, AdjustingPropertyConsumer

A category that makes up a category tree. A category is to be viewed as a node in a node tree.

Note that it is also a TreeNode so it can exist in a JTree.
If a tree is formed where one node, or more, have more than one parent the TreeNode might not work correctly depending on how it's used. This is due to the fact that a TreeNode can only have one parent. It seems to work in a normal JTree though.

Note!
From version 5.6 the Category class has changed to not permanently hold references to parent and child nodes. Instead those references are references to the ID of that category. This is to reduce the direct coupling, increase the usability for database storage solutions and be more like ActivityDepository. For instance this means that the list of categories can be persisted simply by reading and writing them from a database table without needing to dereference and re-reference them and load/save. There will for performance resons still be reference arrays to and parents but these will be revalidated for every call to setParentIDs(...) or setSubCategories(...) or similar.
This change is made to not affect how this class works, old code will still work, but there might be performance resons to ask for IDs of parents/children rather than the normal references.

If version 5.6 there has also been added addition checks so that it is impossible to create sub trees that aren't connected to the CategoryDepository. This means that you can not add a category to another one if the first one is not in the depository and thus has at least one parent. This ensures a higer degree of data integrity. If you are encountering IllegalStateExceptions you should check your category creation code so that it adds a newly created Category to the category tree (another node in the CategoryDepository). You should use CategoryDepository#addBrokedXXX() and CategoryDepository#removeBrokedXXX() for adding and removeing Categories to the tree.


Field Summary
static java.lang.String ALL_PROPERTIES_CHANGED_NAME
           
static PropertyKey ICON
          Deprecated. Use PROP_ICON, it will be the exact same but with a more correct name.
static int oo
           
static PropertyKey PROP_ALLOWS_CHILDREN
          Property key that represent if this node can have children.
static PropertyKey PROP_CATEGORY_SORTER
          A sorter (Comparator) that will be used to sort the children of this category.
static PropertyKey PROP_CHILDREN_IDS
          Property key that represent the children id objects for this category.
static PropertyKey PROP_ICON
          Property key that represent the Icon of this category.
static PropertyKey PROP_ID
          Property key that represent the ID object of this category
static PropertyKey PROP_IS_HIDDEN
          Property key that represents if the category is hidden or not.
static PropertyKey PROP_IS_LEAF
          If non-null forces the isLeaf() method to return this value, which is a Boolean.
static PropertyKey PROP_LAST_MODIFIED_MILLIS
          When this was last modified.
static PropertyKey PROP_NAME
          Property key that represent the Name of this category.
static PropertyKey PROP_PARENT_IDS
          Property key that represent the parent id objects for this category.
static PropertyKey PROP_STATUS
          Status of the cativity.
 
Constructor Summary
Category()
          Deprecated. Should no longer be used and will be package protected in the next release
Category(java.util.Map props)
          Constructor that set all properties for this category.
Category(java.lang.Object id, java.lang.String name)
          Constructor.
Category(java.lang.Object id, java.lang.String name, java.lang.Object parentID)
          Constructor.
Category(java.lang.Object id, java.lang.String name, java.lang.Object[] parentIDs)
          Constructor.
 
Method Summary
protected  boolean addParent(Category parent)
          Deprecated. See this class' JavaDoc for details. Basically you should from 5.6 do all add/removes from the CategoryDepository.
 void addPropertyListener(java.beans.PropertyChangeListener l)
          Adds a listener that should be notified of all changes that to the property values of this com.miginfocom.theme.
This is usually just implemented as addPropertyListener(l, false)
 void addPropertyListener(java.beans.PropertyChangeListener l, boolean asWeakRef)
          Adds a listener that should be notified of all changes that to the property values of this com.miginfocom.theme
static void addStaticPropertyChangeListener(java.beans.PropertyChangeListener l, boolean asWeakRef)
          Adds a listener to ALL categories of the type Category and all subclasses.
 void addSubCategory(Category cat)
          Deprecated. See this class' JavaDoc for details. Basically you should from 5.6 do all add/removes from the CategoryDepository.
 Category addSubCategory(java.lang.Object id, java.lang.String name)
          Deprecated. See this class' JavaDoc for details. Basically you should from 5.6 do all add/removes from the CategoryDepository.
 java.util.Enumeration children()
           
 int compareTo(java.lang.Object o)
          Compares the name.
 boolean containsProperty(PropertyKey property)
          Return if the provider contains the property.
protected  Category createSubCategory(java.lang.Object id, java.lang.String name)
          Deprecated. Should not be used from v5.6.
 java.lang.Object endAdjusting(PropertyKey key)
          Ends the adjusting mode for the key and removed any reference to the old value.
 boolean equals(java.lang.Object o)
          Only compares id.
 Category findCategoryByName(java.lang.String name)
          Uses a breadth first algorith to recursively search for a category and return it
protected  void firePropertyChangeEvent(java.lang.String propName, java.lang.Object oldValue, java.lang.Object newValue)
          Notifies listeners of property changes.
static void fireStaticPropertyChangeEvent(java.beans.PropertyChangeEvent e)
          Notifies listeners of property changes.
 boolean getAllowsChildren()
           
 javax.swing.tree.TreeNode getChildAt(int i)
           
 int getChildCount()
           
 Category[] getChildren()
          Returns the live array with the children for thid category/node.
 java.util.Collection getChildrenDeep()
          Recursively get the children (not this) beneath this node.
 java.util.Collection getChildrenDeep(java.util.Collection fillIn)
          Recursively get the children (not this) beneath this node.
 java.lang.Object[] getChildrenIDs()
          Returns the live array with the children id:s for thid category/node.
 Category getDeepDownwards(java.lang.Object id)
          Returns the category that matches id.
 Category getDeepUpwards(java.lang.Object id)
          Returns the category that matches id.
 java.lang.Object getId()
          Returns the id.
 int getIndex(javax.swing.tree.TreeNode node)
           
 long getLastModified()
          Returns the last modified date in milliseconds (UTC).
 int getMaxDepth()
          Returns the maximum depth.
 java.lang.String getName()
          Returns the name
 javax.swing.tree.TreeNode getParent()
          Returns the main parent.
 Category getParentCategory()
          Returns the first parent (normally there is only one) cast to a Category.
 java.lang.Object[] getParentIDs()
          Return the parents id:s that this category has like "linked" parents.
 Category[] getParents()
          Return the parents that this category has like "linked" parents.
 java.lang.Object getProperty(PropertyKey propKey)
          Returns a property for this Category
 java.lang.Object getPropertyDeep(PropertyKey propKey, java.lang.Object defaultIfDifferent)
          Returns a property for this Category and for all sub categories.
 java.lang.Object getPropertyDeep(PropertyKey propKey, java.lang.Object defaultIfDifferent, boolean leavesOnly, boolean lenient)
          Returns a property for this Category and for all sub categories.
 java.util.Map getPropertyMap()
          Returns the property map without cloning it.
static PropertyValidator getPropertyValidator()
          Return the property key validator.
 Category getSubCategoryAt(int index)
          Same as getChildAt(int) but cast to a Category.
 int hashCode()
          Returns hashcode of id.
 boolean isAdjusting(PropertyKey key)
          Returns if the key is currently in "adjustment mode".
 boolean isIgnorePropertyEvents()
          Transfer to ListenerSet.isIgnoreEvents()
 boolean isLeaf()
           
 boolean isRoot()
          Returns true if this is the root node.
 java.lang.Object removeProperty(PropertyKey property, java.lang.Boolean fireChangeEvent)
          Removes the property.
 void removePropertyListener(java.beans.PropertyChangeListener l)
          Removes a listener if it is in the list.
 java.lang.Object removePropertySilent(PropertyKey property, java.lang.Boolean fireChangeEvent)
          Convenience method for PropertyConsumer.removeProperty(com.miginfocom.util.PropertyKey, Boolean) that catches the PropertyVetoException.
static void removeStaticPropertyChangeListener(java.beans.PropertyChangeListener l)
          Removes static the listener.
 void removeSubCategory(Category cat)
          Deprecated. See this class' JavaDoc for details. Basically you should from 5.6 do all add/removes from the CategoryDepository.
 void removeSubCategoryDeep(Category cat)
          Deprecated. See this class' JavaDoc for details. Basically you should from 5.6 do all add/removes from the CategoryDepository.
 java.lang.Object rollbackAdjusting(PropertyKey key)
          Rollbacks the value of the key to the value it has when the AdjustingPropertyConsumer.startAdjusting(com.miginfocom.util.PropertyKey) was called.
 void setId(java.lang.Object id)
          Deprecated. Parent ID should only be set in constructor.
 boolean setIgnorePropertyEvents(boolean b)
          Transfer to ListenerSet.setIgnoreEvents(boolean)
 void setLastModified(long millis)
          Sets the last modified to a specific value.
 void setLeaf(java.lang.Boolean b)
          Forces the isLeaf() to return the set value if != null.
 void setName(java.lang.String name)
           
 void setParentID(java.lang.Object id)
          Deprecated. See this class' JavaDoc for details. Basically you should from 5.6 do all add/removes from the CategoryDepository.
 void setParents(Category[] parents)
          Deprecated. See this class' JavaDoc for details. Basically you should from 5.6 do all add/removes from the CategoryDepository.
 java.lang.Object setProperty(PropertyKey property, java.lang.Object value, java.lang.Boolean fireChangeEvent)
          Sets a property for this Category.
 void setPropertyDeep(PropertyKey propKey, java.lang.Object value, java.lang.Boolean fireChangeEvent)
          Set the property for this and all sub categories.
 void setPropertyDeep(PropertyKey propKey, java.lang.Object value, boolean onlyLeaves, java.lang.Boolean fireChangeEvent)
          Set the property for this and all sub categories.
 void setPropertyMap(java.util.Map props)
          Exhanges the property map.
 java.lang.Object setPropertySilent(PropertyKey property, java.lang.Object prop, java.lang.Boolean fireChangeEvent)
          Convenience method for PropertyConsumer.setProperty(com.miginfocom.util.PropertyKey, Object, Boolean) that catches the PropertyVetoException.
static void setPropertyValidator(PropertyValidator validator)
          Adds a property key validator that can be used to validate any set and remove of any property in any Category.
 void sort()
          Sorts the children of this category according to the child sorter that is installed (PROP_CATEGORY_SORTER).
 void sort(int levelsDown)
          Sorts the children of this category according to the child sorter that is installed (PROP_CATEGORY_SORTER).
 void sortDeep()
          Sorts the children of this category and all sub childred in the whole tree according to the child sorter that is installed (PROP_CATEGORY_SORTER).
 boolean startAdjusting(PropertyKey key)
          Starts a transaction for the key.
 java.lang.String toString()
          Returns name
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

ALL_PROPERTIES_CHANGED_NAME

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

PROP_ID

public static final PropertyKey PROP_ID
Property key that represent the ID object of this category


PROP_NAME

public static final PropertyKey PROP_NAME
Property key that represent the Name of this category. Always String.


PROP_IS_HIDDEN

public static final PropertyKey PROP_IS_HIDDEN
Property key that represents if the category is hidden or not. Always Boolean.


PROP_ICON

public static final PropertyKey PROP_ICON
Property key that represent the Icon of this category. Always Icon.


ICON

public static final PropertyKey ICON
Deprecated. Use PROP_ICON, it will be the exact same but with a more correct name.
Property key that represent the Icon of this category. Always Icon.


PROP_PARENT_IDS

public static final PropertyKey PROP_PARENT_IDS
Property key that represent the parent id objects for this category. Always Object[].


PROP_CHILDREN_IDS

public static final PropertyKey PROP_CHILDREN_IDS
Property key that represent the children id objects for this category. Always Object[].


PROP_ALLOWS_CHILDREN

public static final PropertyKey PROP_ALLOWS_CHILDREN
Property key that represent if this node can have children. Always Boolean or null. null means true for backwards compatibility.

See Also:
getAllowsChildren()

PROP_LAST_MODIFIED_MILLIS

public static final PropertyKey PROP_LAST_MODIFIED_MILLIS
When this was last modified. Not updated automatically. Type is Long.


PROP_STATUS

public static final PropertyKey PROP_STATUS
Status of the cativity. Interpreted by the implementation.


PROP_IS_LEAF

public static final PropertyKey PROP_IS_LEAF
If non-null forces the isLeaf() method to return this value, which is a Boolean.


PROP_CATEGORY_SORTER

public static final PropertyKey PROP_CATEGORY_SORTER
A sorter (Comparator) that will be used to sort the children of this category. If null the sorter from the parent (first parent) will be used. If no parent all the way to the root has no sorter installed the children will be sorted in the insertion order.

The objects sent into the Comparator are Category objects..

You will have to call sort(int) if the sorter is changed.

See Also:
CategorySorter

oo

public static int oo
Constructor Detail

Category

public Category()
Deprecated. Should no longer be used and will be package protected in the next release

Constructor. ID and name has to be set before using this category. Does not set the parent id to null!


Category

public Category(java.util.Map props)
Constructor that set all properties for this category. Must set the name, parent and id.

Parameters:
props - The properties. Not null.

Category

public Category(java.lang.Object id,
                java.lang.String name)
Constructor.

Parameters:
id - The id. Not null.
name - The name. Not null.

Category

public Category(java.lang.Object id,
                java.lang.String name,
                java.lang.Object parentID)
Constructor.

Parameters:
id - The id. Not null.
name - The name. Not null.
parentID - The id of the parent. null means root.

Category

public Category(java.lang.Object id,
                java.lang.String name,
                java.lang.Object[] parentIDs)
Constructor.

Parameters:
id - The id. Not null.
name - The name. Not null.
parentIDs - The ids of the parents. null means root (as element). If null a single parent that is root will be set.
Method Detail

getId

public final java.lang.Object getId()
Returns the id.

Returns:
The id. Not null except for the root node which is always null.

setId

public final void setId(java.lang.Object id)
Deprecated. Parent ID should only be set in constructor.

Sets the id, should normally only be done at creation.

Parameters:
id - The id. Not null.

getName

public final java.lang.String getName()
Returns the name

Returns:
The name. Not null.

setName

public final void setName(java.lang.String name)

startAdjusting

public boolean startAdjusting(PropertyKey key)
Description copied from interface: AdjustingPropertyConsumer
Starts a transaction for the key. The current value is saved and can be reset by a call to AdjustingPropertyConsumer.rollbackAdjusting(com.miginfocom.util.PropertyKey). The adjusting status end when calling either AdjustingPropertyConsumer.endAdjusting(PropertyKey) or AdjustingPropertyConsumer.rollbackAdjusting(com.miginfocom.util.PropertyKey). If the property is already in "adjustment" mode nothing is done since there is no support for hierarchical transactions.

Specified by:
startAdjusting in interface AdjustingPropertyConsumer
Parameters:
key - The key that should be considered "adjusting". Not null.
Returns:
If the adjustment mode for this key got changed. false if it already was adjusting.

isAdjusting

public boolean isAdjusting(PropertyKey key)
Description copied from interface: AdjustingPropertyConsumer
Returns if the key is currently in "adjustment mode".

Specified by:
isAdjusting in interface AdjustingPropertyConsumer
Parameters:
key - The key to check. Not null.
Returns:
If the key is currently in "adjustment mode".

rollbackAdjusting

public java.lang.Object rollbackAdjusting(PropertyKey key)
Description copied from interface: AdjustingPropertyConsumer
Rollbacks the value of the key to the value it has when the AdjustingPropertyConsumer.startAdjusting(com.miginfocom.util.PropertyKey) was called. If the key is not in "adjustment mode" nothing is done.

Specified by:
rollbackAdjusting in interface AdjustingPropertyConsumer
Parameters:
key - The key to rollback. Not null.
Returns:
The old value that was rolled back to. May be null.

endAdjusting

public java.lang.Object endAdjusting(PropertyKey key)
Description copied from interface: AdjustingPropertyConsumer
Ends the adjusting mode for the key and removed any reference to the old value.

Specified by:
endAdjusting in interface AdjustingPropertyConsumer
Parameters:
key - The key to end adjustment for.
Returns:
The old value.

getParentCategory

public Category getParentCategory()
Returns the first parent (normally there is only one) cast to a Category.

Returns:
The first parent (normally there is only one) cast to a Category. null for the root.

getParents

public Category[] getParents()
Return the parents that this category has like "linked" parents. A category always has exactly one real parent, so that it actyall formas a tree, but it can also be mounted under any number of other categories. This make the category tree into sort of a graph, since it can have multiple parents.

The reason why mount parents are different from the one "real" parent (that always exist, except for the root) is so that Category can implement TreeNode.

It is not allowed to have cyclic dependencies trough this mouning. This means that you can't mount a category on a parent that is already a clild of the category. That would form an infinitive loop when parsing upeards through parent.

Returns:
A new array of parents. Never null but can be of length 0.

setParents

public void setParents(Category[] parents)
Deprecated. See this class' JavaDoc for details. Basically you should from 5.6 do all add/removes from the CategoryDepository.

Set the mount parents.

Parameters:
parents - The new mouse parents array. Will be overtaken and not cloned. Can be null and will if so be replaced with an empty array.
See Also:
for an explamation of what it is.

addParent

protected boolean addParent(Category parent)
Deprecated. See this class' JavaDoc for details. Basically you should from 5.6 do all add/removes from the CategoryDepository.

Adds a mount parent to the list of mount parents. If the mount parent already exists nothing is added since there can't be duplicates in the mount parents.

Parameters:
parent - The parent to add. Not null.
Returns:
true if the parent was added. false if it was already connected to this parent and no change was made.

getParentIDs

public java.lang.Object[] getParentIDs()
Return the parents id:s that this category has like "linked" parents. A category always has exactly one real parent (index 0), so that it actually forms a tree, but it can also be mounted under any number of other categories. This make the category tree into sort of a graph, since it can have multiple parents.

The reason why mount parents are different from the one "real" parent (that always exist, except for the root) is so that Category can implement TreeNode.

It is not allowed to have cyclic dependencies trough this mouning. This means that you can't mount a category on a parent that is already a child of the category. That would form an infinitive loop when parsing upwards through parent.

Use setProperty(com.miginfocom.util.PropertyKey, Object, Boolean) or #setPropertySilent(#PROP_PARENT_IDS, Object, Boolean) with key PROP_PARENT_IDS to set the parent.

Returns:
The live array of mount parents.

setParentID

public void setParentID(java.lang.Object id)
Deprecated. See this class' JavaDoc for details. Basically you should from 5.6 do all add/removes from the CategoryDepository.

Convenience method for:
<setPropertySilent(PROP_PARENT_IDS, new Object[] {id}, null);.

Note that null is used as the ID of the category root.

Parameters:
id - The id of the parent.

getChildren

public Category[] getChildren()
Returns the live array with the children for thid category/node.

Returns:
The live array with the children for thid category/node. Never null.

getChildrenIDs

public java.lang.Object[] getChildrenIDs()
Returns the live array with the children id:s for thid category/node.

Returns:
The live array with the children id:s for thid category/node. Can be null.

addSubCategory

public void addSubCategory(Category cat)
Deprecated. See this class' JavaDoc for details. Basically you should from 5.6 do all add/removes from the CategoryDepository.

Adds the category as a sub category to this category and add this as parent to it.

Parameters:
cat - The category to add. Not null. Children of cat will be added recursively.

addSubCategory

public Category addSubCategory(java.lang.Object id,
                               java.lang.String name)
Deprecated. See this class' JavaDoc for details. Basically you should from 5.6 do all add/removes from the CategoryDepository.

Creates a new node and adds it. Calls createSubCategory(Object, String) to create the category.

Parameters:
id - The id to use as for later look-up. If null the id is randomly auto generated. (an Integer with a uniqe random value)
name - The name. Used only for visual apperence.
Returns:
The newly created node.

createSubCategory

protected Category createSubCategory(java.lang.Object id,
                                     java.lang.String name)
Deprecated. Should not be used from v5.6.

Called for creating a new node.

Parameters:
id - The id to use as for later look-up. If null the id is randomly auto generated. (an Integer with a uniqe random value)
name - The name. Used only for visual apperence.
Returns:
The newly created node.

getSubCategoryAt

public Category getSubCategoryAt(int index)
Same as getChildAt(int) but cast to a Category.

Parameters:
index - The index. Must exist.
Returns:
The category at index.

removeSubCategory

public void removeSubCategory(Category cat)
Deprecated. See this class' JavaDoc for details. Basically you should from 5.6 do all add/removes from the CategoryDepository.

Removes a child category from this node. The method is not recursive and throws an IllegalStateException if it cat has sub categories. This is because you can not remove a whole sub tree since that would put the category tree in a illegal state.

Parameters:
cat - The category to remove. Not null.
See Also:
removeSubCategoryDeep(Category).

removeSubCategoryDeep

public void removeSubCategoryDeep(Category cat)
Deprecated. See this class' JavaDoc for details. Basically you should from 5.6 do all add/removes from the CategoryDepository.

Removes a child category from this node and all its children (deep). The method is recursive. The deepest leaves are removed first, one by one. This is slower than just detaching the root but this method leaves not childred haning with a parent that isn't connected to the root.

Parameters:
cat - The category to remove. Not null.

getDeepDownwards

public Category getDeepDownwards(java.lang.Object id)
Returns the category that matches id. Check with all children as well as this.

Parameters:
id - The id to check for.
Returns:
The category that matches id.

getDeepUpwards

public Category getDeepUpwards(java.lang.Object id)
Returns the category that matches id. Check with all parents as well as this.

Parameters:
id - The id to check for.
Returns:
The category that matches id.

getMaxDepth

public int getMaxDepth()
Returns the maximum depth. Always >= 1.

Returns:
The maximum depth. Always >= 1.

getChildrenDeep

public java.util.Collection getChildrenDeep()
Recursively get the children (not this) beneath this node. Depth first.

Returns:
A new collection with the children. Never null but can be of length 0.

getChildrenDeep

public java.util.Collection getChildrenDeep(java.util.Collection fillIn)
Recursively get the children (not this) beneath this node. Depth first.

Parameters:
fillIn - The collection is used to add the children. Not null.
Returns:
fillIn for chaining.

findCategoryByName

public Category findCategoryByName(java.lang.String name)
Uses a breadth first algorith to recursively search for a category and return it

Parameters:
name - The name to search for. Not null.
Returns:
The node if found or null otherwise.

isRoot

public final boolean isRoot()
Returns true if this is the root node.

Returns:
true if this is the root node.

setLeaf

public void setLeaf(java.lang.Boolean b)
Forces the isLeaf() to return the set value if != null. If set to null the value returned for isLeaf is depending on if this category has sub-categories or not.

This is the same as category.setPropertySilent(Category.PROP_IS_LEAF, b, null);

Parameters:
b - The new value. May be null

setProperty

public java.lang.Object setProperty(PropertyKey property,
                                    java.lang.Object value,
                                    java.lang.Boolean fireChangeEvent)
                             throws java.beans.PropertyVetoException
Sets a property for this Category.

Specified by:
setProperty in interface PropertyConsumer
Parameters:
property - The type of property for this Activity.
value - The property for this Category.
fireChangeEvent - If Boolean.TRUE fires a change event. If Boolean.FALSE don't fire and if null the old and new object is checked for equality (with .equals()) and fires a change if they differ.
Returns:
The old object, may be null.
Throws:
java.beans.PropertyVetoException - If the property couldn't be set on this for some reason.

setPropertySilent

public java.lang.Object setPropertySilent(PropertyKey property,
                                          java.lang.Object prop,
                                          java.lang.Boolean fireChangeEvent)
Description copied from interface: PropertyConsumer
Convenience method for PropertyConsumer.setProperty(com.miginfocom.util.PropertyKey, Object, Boolean) that catches the PropertyVetoException.

It is required that this method is implemented in the PropertyConsumer.setProperty(com.miginfocom.util.PropertyKey, Object, Boolean).

Note that if the PropertyKey defines a value class type it should be checked in this setter and an ClassCastException is thrown if prop the wrong class type.

Specified by:
setPropertySilent in interface PropertyConsumer
Parameters:
property - The property key that denotes the property. Not null.
prop - The property to set for this object.
fireChangeEvent - If Boolean.TRUE fires a change event. If Boolean.FALSE don't fire and if null the old and new object is checked for equality (with .equals()) and fires a change if they differ.
Returns:
The old object, may be null.

removeProperty

public java.lang.Object removeProperty(PropertyKey property,
                                       java.lang.Boolean fireChangeEvent)
                                throws java.beans.PropertyVetoException
Description copied from interface: PropertyConsumer
Removes the property.

Specified by:
removeProperty in interface PropertyConsumer
Parameters:
property - The property key that denotes the property. Not null.
fireChangeEvent - If Boolean.TRUE fires a change event. If Boolean.FALSE don't fire and if null fires a change if the key existed before this call.
Returns:
The Old object. null both is null was stored or if the key did not exist in the provider.
Throws:
java.beans.PropertyVetoException - If the property couldn't be set on this for some reason.

removePropertySilent

public java.lang.Object removePropertySilent(PropertyKey property,
                                             java.lang.Boolean fireChangeEvent)
Description copied from interface: PropertyConsumer
Convenience method for PropertyConsumer.removeProperty(com.miginfocom.util.PropertyKey, Boolean) that catches the PropertyVetoException.

It is required that this method is implemented in the PropertyConsumer.setProperty(com.miginfocom.util.PropertyKey, Object, Boolean).

Specified by:
removePropertySilent in interface PropertyConsumer
Parameters:
property - The property key that denotes the property. Not null.
fireChangeEvent - If Boolean.TRUE fires a change event. If Boolean.FALSE don't fire and if null fires a change if the key existed before this call.
Returns:
The Old object. null both is null was stored or if the key did not exist in the provider.

getProperty

public java.lang.Object getProperty(PropertyKey propKey)
Returns a property for this Category

Specified by:
getProperty in interface PropertyProvider
Parameters:
propKey - The type of property to return. E g. PROP_IS_HIDDEN
Returns:
The property. Can be null.

containsProperty

public boolean containsProperty(PropertyKey property)
Description copied from interface: PropertyProvider
Return if the provider contains the property.

Specified by:
containsProperty in interface PropertyProvider
Parameters:
property - The property key. Not null.
Returns:
If the provider contains the property.

setPropertyDeep

public void setPropertyDeep(PropertyKey propKey,
                            java.lang.Object value,
                            java.lang.Boolean fireChangeEvent)
Set the property for this and all sub categories.

Parameters:
propKey - The type of property to set. E g. PROP_IS_HIDDEN
value - The value to set. May be null.
fireChangeEvent - If Boolean.TRUE fires a change event. If Boolean.FALSE don't fire and if null the old and new object is checked for equality (with .equals()) and fires a change if they differ.

setPropertyDeep

public void setPropertyDeep(PropertyKey propKey,
                            java.lang.Object value,
                            boolean onlyLeaves,
                            java.lang.Boolean fireChangeEvent)
Set the property for this and all sub categories.

Parameters:
propKey - The type of property to set. E g. PROP_IS_HIDDEN
value - The value to set. May be null.
onlyLeaves - If true the values will only be set on the leaves and the folders' values will go unchanged. This is good to use if the folders' values are only synthesized from their leaves, such as for a tree-state checkbox tree.
fireChangeEvent - If Boolean.TRUE fires a change event. If Boolean.FALSE don't fire and if null the old and new object is checked for equality (with .equals()) and fires a change if they differ.

getPropertyDeep

public java.lang.Object getPropertyDeep(PropertyKey propKey,
                                        java.lang.Object defaultIfDifferent)
Returns a property for this Category and for all sub categories. Will only return the actual value if ALL categories containes the same value. As soon as a category is found which has another value than the defaultIfDifferent is returned. If this doesn't contain any sub categories this method will return the same value as getProperty(PropertyKey).

Parameters:
propKey - The type of property to return. E g. PROP_IS_HIDDEN
defaultIfDifferent - This object will be returned if not all of the categories contains the same (equals) value for the property.
Returns:
The property. Can be null.

getPropertyDeep

public java.lang.Object getPropertyDeep(PropertyKey propKey,
                                        java.lang.Object defaultIfDifferent,
                                        boolean leavesOnly,
                                        boolean lenient)
Returns a property for this Category and for all sub categories. Will only return the actual value if ALL categories containes the same value. As soon as a category is found which has another value than the defaultIfDifferent is returned. If this doesn't contain any sub categories this method will return the same value as getProperty(PropertyKey).

Parameters:
propKey - The type of property to return. E g. PROP_IS_HIDDEN
defaultIfDifferent - This object will be returned if not all of the categories contains the same (equals) value for the property.
leavesOnly - If true then only leaves will be included in the comparison and the value of the folders ignored. This is good to use if the folders' values are only synthesized from their leaves, such as for a tree-state checkbox tree.
lenient - If true then the MigUtil.equalsLenient(Object, Object) method will be used for comparison.
Returns:
The property. Can be null.

getPropertyMap

public java.util.Map getPropertyMap()
Returns the property map without cloning it. Should not be changed.

Returns:
The property map. Not null.

setPropertyMap

public void setPropertyMap(java.util.Map props)
                    throws java.beans.PropertyVetoException
Exhanges the property map. Shallow clones the map.

Parameters:
props - The new property map. Must have PropertyKey keys. Not null.
Throws:
java.beans.PropertyVetoException

getLastModified

public long getLastModified()
Returns the last modified date in milliseconds (UTC). Updated automatically when a property changes.

Returns:
The last modified date in milliseconds (UTC). not null.

setLastModified

public void setLastModified(long millis)
Sets the last modified to a specific value. This should only be made during the setup process of the activity and is handled automatically whenever a property is changed later on.

Parameters:
millis - The millis as standard.

sort

public void sort()
Sorts the children of this category according to the child sorter that is installed (PROP_CATEGORY_SORTER).

This is done automatically for when a child is added but if the sorting algorithm is more advanced and is using the leafs/folder property it might be necessary to sort the whole tree after it has been fully created.

If no sorter is installed this method does nothing.

Same as Category.sort(0).

Since:
6.0
See Also:
PROP_CATEGORY_SORTER, CategorySorter

sortDeep

public void sortDeep()
Sorts the children of this category and all sub childred in the whole tree according to the child sorter that is installed (PROP_CATEGORY_SORTER).

This is done automatically for when a child is added but if the sorting algorithm is more advanced and is using the leafs/folder property it might be necessary to sort the whole tree after it has been fully created.

If no sorter is installed this method does nothing.

Same as Category.sort(Integer.MAX_VALUE).

Since:
6.0
See Also:
PROP_CATEGORY_SORTER, CategorySorter

sort

public void sort(int levelsDown)
Sorts the children of this category according to the child sorter that is installed (PROP_CATEGORY_SORTER).

This is done automatically for when a child is added but if the sorting algorithm is more advanced and is using the leafs/folder property it might be necessary to sort the whole tree after it has been fully created.

If no sorter is installed this method does nothing (unless a child sorter is installed on a child and levelsDown is set to reach it/them.

Parameters:
levelsDown - If the sort should be propagated to the childred as well and how many levels. 0 means that only the children of this catgory will be sorted.
Since:
6.0
See Also:
PROP_CATEGORY_SORTER, CategorySorter

compareTo

public int compareTo(java.lang.Object o)
Compares the name. This is for sorting in visual list and such.

Specified by:
compareTo in interface java.lang.Comparable
Parameters:
o - Converted to String. Not null.
Returns:
As per specification in Comparable.

equals

public boolean equals(java.lang.Object o)
Only compares id.

Overrides:
equals in class java.lang.Object
Parameters:
o - The other Category object to compare to.
Returns:
If is matches.

hashCode

public int hashCode()
Returns hashcode of id.

Overrides:
hashCode in class java.lang.Object
Returns:
hashcode of id.

toString

public java.lang.String toString()
Returns name

Overrides:
toString in class java.lang.Object
Returns:
The name

setPropertyValidator

public static void setPropertyValidator(PropertyValidator validator)
Adds a property key validator that can be used to validate any set and remove of any property in any Category.

Note that these validator will listen to all categories in the JVM.

Parameters:
validator - The validator to set. May be null which invalidates validation.
Since:
6.0

getPropertyValidator

public static PropertyValidator getPropertyValidator()
Return the property key validator.

Returns:
The validator or null if there are none set.
Since:
6.0

addStaticPropertyChangeListener

public static void addStaticPropertyChangeListener(java.beans.PropertyChangeListener l,
                                                   boolean asWeakRef)
Adds a listener to ALL categories of the type Category and all subclasses.

This is potentialy dangerous, but powerful. Handling in the listeners should be extremely fast since they can get quite a few updates per second. Also, since this method is static and thus will not be garbage collected it is important for all listeners to unregister themselves if they are disposed or a memory leak will be the result. Alternatively set asWeakref to true.

It is important to understand that this listens to ALL categories created in this virtual machine, not only the once in the CategoryDepository but possibly others, unknown, as well. It is problably a good idea to have som sort of filter to know that a "valid" category has been changed.

Parameters:
l - The listener to add.
asWeakRef - If the listener should be added wrapped in a WeakReference. This defers memory leak problems since the garbage collector can collect the listener if it is only referenced from this list.
Note! This (weak reference) can not be used with listeners that doesn't have another real (a.k.a Strong) reference to it, as for instance an annonymous inner class. If one such listener is added it will be removed almost immediately by the garbage collector.

removeStaticPropertyChangeListener

public static void removeStaticPropertyChangeListener(java.beans.PropertyChangeListener l)
Removes static the listener.

Parameters:
l - The listener to remove.

fireStaticPropertyChangeEvent

public static void fireStaticPropertyChangeEvent(java.beans.PropertyChangeEvent e)
Notifies listeners of property changes. Also chains this event to the static method

Parameters:
e - The event to send to the listeners.

addPropertyListener

public void addPropertyListener(java.beans.PropertyChangeListener l)
Description copied from interface: PropertyObservable
Adds a listener that should be notified of all changes that to the property values of this com.miginfocom.theme.
This is usually just implemented as addPropertyListener(l, false)

Specified by:
addPropertyListener in interface PropertyObservable
Parameters:
l - The listener.

addPropertyListener

public void addPropertyListener(java.beans.PropertyChangeListener l,
                                boolean asWeakRef)
Description copied from interface: PropertyObservable
Adds a listener that should be notified of all changes that to the property values of this com.miginfocom.theme

Specified by:
addPropertyListener in interface PropertyObservable
Parameters:
l - The listener
asWeakRef - If the listener should be added wrapped in a WeakReference. This defers memory leak problems since the garbage collector can collect the listener if it is only referenced from this list.
Note! This (weak reference) can not be used with listeners that doesn't have another real (a.k.a Strong) reference to it, as for instance an annonymous inner class. If one such listener is added it will be removed almost immediately by the garbage collector.

removePropertyListener

public void removePropertyListener(java.beans.PropertyChangeListener l)
Description copied from interface: PropertyObservable
Removes a listener if it is in the list.

Specified by:
removePropertyListener in interface PropertyObservable
Parameters:
l - the listener

isIgnorePropertyEvents

public boolean isIgnorePropertyEvents()
Transfer to ListenerSet.isIgnoreEvents()

Specified by:
isIgnorePropertyEvents in interface PropertyObservable
Returns:
If the PropertyObservable is currently ignoring change events

setIgnorePropertyEvents

public boolean setIgnorePropertyEvents(boolean b)
Transfer to ListenerSet.setIgnoreEvents(boolean)

Specified by:
setIgnorePropertyEvents in interface PropertyObservable
Parameters:
b - true or false...
Returns:
The old value.

firePropertyChangeEvent

protected void firePropertyChangeEvent(java.lang.String propName,
                                       java.lang.Object oldValue,
                                       java.lang.Object newValue)
Notifies listeners of property changes.

Parameters:
propName - The property that has been changed
oldValue - The old value if that is known. May be null.
newValue - The new value if known. May be null.

getParent

public javax.swing.tree.TreeNode getParent()
Returns the main parent. Can safely be cast to a Category and is a TreeNode just to be able to implement the TreeNode interface.

Specified by:
getParent in interface javax.swing.tree.TreeNode
Returns:
The parent or null if no parent.

children

public java.util.Enumeration children()
Specified by:
children in interface javax.swing.tree.TreeNode

getAllowsChildren

public boolean getAllowsChildren()
Specified by:
getAllowsChildren in interface javax.swing.tree.TreeNode

getChildAt

public javax.swing.tree.TreeNode getChildAt(int i)
Specified by:
getChildAt in interface javax.swing.tree.TreeNode

getChildCount

public int getChildCount()
Specified by:
getChildCount in interface javax.swing.tree.TreeNode

getIndex

public int getIndex(javax.swing.tree.TreeNode node)
Specified by:
getIndex in interface javax.swing.tree.TreeNode

isLeaf

public boolean isLeaf()
Specified by:
isLeaf in interface javax.swing.tree.TreeNode


Copyright © 2009 MiG InfoCom AB. All Rights Reserved.