1 package prefuse.visual.sort; 2 3 import java.util.Comparator ; 4 5 import prefuse.Visualization; 6 import prefuse.visual.AggregateItem; 7 import prefuse.visual.DecoratorItem; 8 import prefuse.visual.EdgeItem; 9 import prefuse.visual.VisualItem; 10 11 19 public class ItemSorter implements Comparator { 20 21 protected static final int AGGREGATE = 0; 22 protected static final int EDGE = 1; 23 protected static final int ITEM = 2; 24 protected static final int DECORATOR = 3; 25 26 42 public int score(VisualItem item) { 43 int type = ITEM; 44 if ( item instanceof EdgeItem ) { 45 type = EDGE; 46 } else if ( item instanceof AggregateItem ) { 47 type = AGGREGATE; 48 } else if ( item instanceof DecoratorItem ) { 49 type = DECORATOR; 50 } 51 52 int score = (1<<(26+type)); 53 if ( item.isHover() ) { 54 score += (1<<25); 55 } 56 if ( item.isHighlighted() ) { 57 score += (1<<24); 58 } 59 if ( item.isInGroup(Visualization.FOCUS_ITEMS) ) { 60 score += (1<<23); 61 } 62 if ( item.isInGroup(Visualization.SEARCH_ITEMS) ) { 63 score += (1<<22); 64 } 65 66 return score; 67 } 68 69 77 public int compare(VisualItem v1, VisualItem v2) { 78 int score1 = score(v1); 79 int score2 = score(v2); 80 return (score1<score2 ? -1 : (score1==score2 ? 0 : 1)); 81 } 82 83 87 public int compare(Object o1, Object o2) { 88 if ( !(o1 instanceof VisualItem && o2 instanceof VisualItem) ) { 89 throw new IllegalArgumentException (); 90 } 91 return compare((VisualItem)o1, (VisualItem)o2); 92 } 93 94 } | Popular Tags |