com.imagero.swing.tree.util
Class DMNodeComparator

java.lang.Object
  extended bycom.imagero.swing.tree.util.DMNodeComparator
All Implemented Interfaces:
java.util.Comparator, TreeNodeComparator
Direct Known Subclasses:
FileNodeComparator, HTTPNodeComparator, URLNodeComparator

public class DMNodeComparator
extends java.lang.Object
implements TreeNodeComparator

since this comparator knows nothing about userObjects in nodes, it makes only simple check for null values and (if needed) directory check. subclasses should call super.compare() and if result is UNDEFINED make further comparison


Field Summary
protected  boolean directoriesFirst
           
static int UNDEFINED
           
 
Constructor Summary
DMNodeComparator()
           
 
Method Summary
protected  int checkDirectory(javax.swing.tree.TreeNode tn1, javax.swing.tree.TreeNode tn2)
          check if some of nodes is directory
protected  int checkNull(javax.swing.tree.TreeNode tn1, javax.swing.tree.TreeNode tn2)
          check null nodes
 int compare(HTreeNode tn1, HTreeNode tn2)
           
 int compare(java.lang.Object o1, java.lang.Object o2)
           
 boolean equals(java.lang.Object o)
           
 boolean isDirectoriesFirst()
           
 void setDirectoriesFirst(boolean b)
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

UNDEFINED

public static final int UNDEFINED
See Also:
Constant Field Values

directoriesFirst

protected boolean directoriesFirst
Constructor Detail

DMNodeComparator

public DMNodeComparator()
Method Detail

isDirectoriesFirst

public boolean isDirectoriesFirst()

setDirectoriesFirst

public void setDirectoriesFirst(boolean b)

equals

public boolean equals(java.lang.Object o)
Specified by:
equals in interface java.util.Comparator

compare

public int compare(java.lang.Object o1,
                   java.lang.Object o2)
Specified by:
compare in interface java.util.Comparator

compare

public int compare(HTreeNode tn1,
                   HTreeNode tn2)
Specified by:
compare in interface TreeNodeComparator
Parameters:
tn1 - first node
tn2 - second node
Returns:
UNDEFINED if compare result is unknown

checkNull

protected int checkNull(javax.swing.tree.TreeNode tn1,
                        javax.swing.tree.TreeNode tn2)
check null nodes

Parameters:
tn1 - first node
tn2 - second node
Returns:
0 if both nodes are null, 1 if first node is not null and second node is null, -1 if fist node is null and second node is not null, -2 id both nodes are not null;

checkDirectory

protected int checkDirectory(javax.swing.tree.TreeNode tn1,
                             javax.swing.tree.TreeNode tn2)
check if some of nodes is directory

Parameters:
tn1 - first node
tn2 - second node
Returns:
-1 if first node is directory and second node is not directory, 1 if first node is not directory and second node node is directory, UNDEFINED if both nodes are directories or not;