1 package prefuse.controls; 2 3 import java.awt.event.MouseEvent ; 4 import java.util.Iterator ; 5 6 import prefuse.visual.EdgeItem; 7 import prefuse.visual.NodeItem; 8 import prefuse.visual.VisualItem; 9 10 11 22 public class NeighborHighlightControl extends ControlAdapter { 23 24 private String activity = null; 25 private boolean highlightWithInvisibleEdge = false; 26 27 30 public NeighborHighlightControl() { 31 this(null); 32 } 33 34 39 public NeighborHighlightControl(String activity) { 40 this.activity = activity; 41 } 42 43 46 public void itemEntered(VisualItem item, MouseEvent e) { 47 if ( item instanceof NodeItem ) 48 setNeighborHighlight((NodeItem)item, true); 49 } 50 51 54 public void itemExited(VisualItem item, MouseEvent e) { 55 if ( item instanceof NodeItem ) 56 setNeighborHighlight((NodeItem)item, false); 57 } 58 59 64 protected void setNeighborHighlight(NodeItem n, boolean state) { 65 Iterator iter = n.edges(); 66 while ( iter.hasNext() ) { 67 EdgeItem eitem = (EdgeItem)iter.next(); 68 NodeItem nitem = eitem.getAdjacentItem(n); 69 if (eitem.isVisible() || highlightWithInvisibleEdge) { 70 eitem.setHighlighted(state); 71 nitem.setHighlighted(state); 72 } 73 } 74 if ( activity != null ) 75 n.getVisualization().run(activity); 76 } 77 78 84 public boolean isHighlightWithInvisibleEdge() { 85 return highlightWithInvisibleEdge; 86 } 87 88 94 public void setHighlightWithInvisibleEdge(boolean highlightWithInvisibleEdge) { 95 this.highlightWithInvisibleEdge = highlightWithInvisibleEdge; 96 } 97 98 } | Popular Tags |