1 package prefuse.action.animate; 2 3 import java.util.Iterator ; 4 5 import prefuse.action.GroupAction; 6 import prefuse.util.ColorLib; 7 import prefuse.visual.VisualItem; 8 import prefuse.visual.expression.StartVisiblePredicate; 9 10 18 public class VisibilityAnimator extends GroupAction { 19 20 23 public VisibilityAnimator() { 24 super(); 25 } 26 27 31 public VisibilityAnimator(String group) { 32 super(group); 33 } 34 35 38 public void run(double frac) { 39 if ( frac == 0.0 ) { 40 setup(); 41 } else if ( frac == 1.0 ) { 42 finish(); 43 } 44 } 45 46 private void setup() { 47 Iterator items = m_vis.visibleItems(m_group); 49 while ( items.hasNext() ) { 50 VisualItem item = (VisualItem) items.next(); 51 if ( !item.isStartVisible() ) { 52 item.setStartFillColor( 53 ColorLib.setAlpha(item.getEndFillColor(),0)); 54 item.setStartStrokeColor( 55 ColorLib.setAlpha(item.getEndStrokeColor(),0)); 56 item.setStartTextColor( 57 ColorLib.setAlpha(item.getEndTextColor(),0)); 58 } 59 } 60 61 items = m_vis.items(m_group, StartVisiblePredicate.TRUE); 63 while ( items.hasNext() ) { 64 VisualItem item = (VisualItem) items.next(); 65 if ( !item.isEndVisible() ) { 66 item.setVisible(true); 68 item.setEndFillColor( 69 ColorLib.setAlpha(item.getStartFillColor(),0)); 70 item.setEndStrokeColor( 71 ColorLib.setAlpha(item.getStartStrokeColor(),0)); 72 item.setEndTextColor( 73 ColorLib.setAlpha(item.getStartTextColor(),0)); 74 } 75 } 76 } 77 78 private void finish() { 79 Iterator items = m_vis.items(m_group, StartVisiblePredicate.TRUE); 81 while ( items.hasNext() ) { 82 VisualItem item = (VisualItem) items.next(); 83 if ( !item.isEndVisible() ) { 84 item.setVisible(false); 85 item.setStartVisible(false); 86 } 87 } 88 89 items = m_vis.visibleItems(m_group); 91 while ( items.hasNext() ) { 92 VisualItem item = (VisualItem) items.next(); 93 if ( !item.isStartVisible() ) { 94 item.setStartVisible(true); 95 item.setStartFillColor(item.getEndFillColor()); 96 item.setStartTextColor(item.getEndTextColor()); 97 item.setStartStrokeColor(item.getEndStrokeColor()); 98 } 99 } 100 } 101 102 } | Popular Tags |