1 package prefuse.visual.sort; 2 3 import prefuse.Visualization; 4 import prefuse.visual.AggregateItem; 5 import prefuse.visual.DecoratorItem; 6 import prefuse.visual.EdgeItem; 7 import prefuse.visual.NodeItem; 8 import prefuse.visual.VisualItem; 9 10 18 public class TreeDepthItemSorter extends ItemSorter { 19 20 protected static final int AGGREGATE = 0; 21 protected static final int EDGE = 1; 22 protected static final int ITEM = 2; 23 protected static final int NODE = 3; 24 protected static final int DECORATOR = 4; 25 26 private int m_childrenAbove; 27 private int m_hover; 28 private int m_highlight; 29 private int m_depth; 30 31 35 public TreeDepthItemSorter() { 36 this(false); 37 } 38 39 44 public TreeDepthItemSorter(boolean childrenAbove) { 45 if ( childrenAbove ) { 46 m_childrenAbove = 1; 47 m_hover = 13; 48 m_highlight = 12; 49 m_depth = 14; 50 } else { 51 m_childrenAbove = -1; 52 m_hover = 24; 53 m_highlight = 23; 54 m_depth = 12; 55 } 56 } 57 58 63 public int score(VisualItem item) { 64 int type = ITEM; 65 if ( item instanceof EdgeItem ) { 66 type = EDGE; 67 } else if ( item instanceof AggregateItem ) { 68 type = AGGREGATE; 69 } else if ( item instanceof DecoratorItem ) { 70 type = DECORATOR; 71 } 72 73 int score = (1<<(25+type)); 74 if ( item instanceof NodeItem ) { 75 int depth = ((NodeItem)item).getDepth(); 76 score += m_childrenAbove*(depth<<m_depth); 77 } 78 if ( item.isHover() ) { 79 score += (1<<m_hover); 80 } 81 if ( item.isHighlighted() ) { 82 score += (1<<m_highlight); 83 } 84 if ( item.isInGroup(Visualization.FOCUS_ITEMS) ) { 85 score += (1<<11); 86 } 87 if ( item.isInGroup(Visualization.SEARCH_ITEMS) ) { 88 score += (1<<10); 89 } 90 91 return score; 92 } 114 115 } | Popular Tags |