KickJava   Java API By Example, From Geeks To Geeks.

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


1 package prefuse.action.animate;
2
3 import java.util.logging.Logger JavaDoc;
4
5 import prefuse.action.ItemAction;
6 import prefuse.util.PrefuseLib;
7 import prefuse.visual.VisualItem;
8
9
10 /**
11  * Animator that inerpolates an array of numerical values.
12  *
13  * @author <a HREF="http://jheer.org">jeffrey heer</a>
14  */

15 public class ArrayAnimator extends ItemAction {
16
17     private static final Logger JavaDoc s_logger
18         = Logger.getLogger(ArrayAnimator.class.getName());
19     
20     private String JavaDoc m_field; // the field
21
private String JavaDoc m_start; // the start field
22
private String JavaDoc m_end; // the end field
23

24     /**
25      * Create a new ArrayAnimator that processes the given data group
26      * and interpolates arrays in the given data field.
27      * @param group the data group to process
28      * @param field the data field to interpolate. This should be an
29      * interpolated field (have start and end instances as well as
30      * the field name itself).
31      */

32     public ArrayAnimator(String JavaDoc group, String JavaDoc field) {
33         super(group);
34         m_field = field;
35         m_start = PrefuseLib.getStartField(field);
36         m_end = PrefuseLib.getEndField(field);
37     }
38     
39     /**
40      * @see prefuse.action.ItemAction#process(prefuse.visual.VisualItem, double)
41      */

42     public void process(VisualItem item, double frac) {
43         Object JavaDoc o = item.get(m_field);
44         if ( o instanceof float[] ) {
45             float[] a = (float[])o;
46             float[] s = (float[])item.get(m_start);
47             float[] e = (float[])item.get(m_end);
48             
49             float f = (float)frac;
50             for ( int i=0; i<a.length; ++i ) {
51                 if ( Float.isNaN(a[i]) ) break;
52                 a[i] = s[i] + f*(e[i]-s[i]);
53             }
54             item.setValidated(false);
55         } else if ( o instanceof double[] ) {
56             double[] a = (double[])o;
57             double[] s = (double[])item.get(m_start);
58             double[] e = (double[])item.get(m_end);
59             
60             for ( int i=0; i<a.length; ++i ) {
61                 if ( Double.isNaN(a[i]) ) break;
62                 a[i] = s[i] + frac*(e[i]-s[i]);
63             }
64             item.setValidated(false);
65         } else {
66             s_logger.warning("Encountered non-double/non-float array type: "
67                     + (o==null ? "null" : o.getClass().getName()));
68         }
69     }
70
71 } // end of class ArrayAnimator
72
Popular Tags