KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > prefuse > action > animate > VisibilityAnimator


1 package prefuse.action.animate;
2
3 import java.util.Iterator JavaDoc;
4
5 import prefuse.action.GroupAction;
6 import prefuse.util.ColorLib;
7 import prefuse.visual.VisualItem;
8 import prefuse.visual.expression.StartVisiblePredicate;
9
10 /**
11  * Animator that interpolates the visibility status of VisualItems. Items
12  * not currently visible but with end visibilty true are faded in, while
13  * items currently visible but with end visibility false are faded out and
14  * finally set to not visible.
15  *
16  * @author <a HREF="http://jheer.org">jeffrey heer</a>
17  */

18 public class VisibilityAnimator extends GroupAction {
19     
20     /**
21      * Create a new VisibilityAnimator that processes all data groups.
22      */

23     public VisibilityAnimator() {
24         super();
25     }
26     
27     /**
28      * Create a new VisibilityAnimator that processes the specified group.
29      * @param group the data group to process.
30      */

31     public VisibilityAnimator(String JavaDoc group) {
32         super(group);
33     }
34     
35     /**
36      * @see prefuse.action.GroupAction#run(double)
37      */

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         // handle fade-in nodes
48
Iterator JavaDoc 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         // handle fade-out nodes
62
items = m_vis.items(m_group, StartVisiblePredicate.TRUE);
63         while ( items.hasNext() ) {
64             VisualItem item = (VisualItem) items.next();
65             if ( !item.isEndVisible() ) {
66                 // fade-out case
67
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         // set faded-out nodes to permanently invisible
80
Iterator JavaDoc 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         // set faded-in nodes to permanently visible
90
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 } // end of class VisibilityAnimator
103
Popular Tags