KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > prefuse > action > layout > RandomLayout


1 package prefuse.action.layout;
2
3 import java.awt.geom.Rectangle2D JavaDoc;
4 import java.util.Iterator JavaDoc;
5 import java.util.Random JavaDoc;
6
7 import prefuse.visual.VisualItem;
8
9
10 /**
11  * Performs a random layout of items within the layout bounds.
12  *
13  * @author <a HREF="http://jheer.org">jeffrey heer</a>
14  */

15 public class RandomLayout extends Layout {
16
17     private Random JavaDoc r = new Random JavaDoc(12345678L);
18     
19     /**
20      * Create a new RandomLayout that processes all items.
21      */

22     public RandomLayout() {
23         super();
24     }
25     
26     /**
27      * Create a new RandomLayout.
28      * @param group the data group to layout
29      */

30     public RandomLayout(String JavaDoc group) {
31         super(group);
32     }
33
34     /**
35      * Set the seed value for the random number generator.
36      * @param seed the random seed value
37      */

38     public void setRandomSeed(long seed) {
39         r.setSeed(seed);
40     }
41     
42     /**
43      * @see prefuse.action.Action#run(double)
44      */

45     public void run(double frac) {
46         Rectangle2D JavaDoc b = getLayoutBounds();
47         double x, y;
48         double w = b.getWidth();
49         double h = b.getHeight();
50         Iterator JavaDoc iter = getVisualization().visibleItems(m_group);
51         while ( iter.hasNext() ) {
52             VisualItem item = (VisualItem)iter.next();
53             x = (int)(b.getX() + r.nextDouble()*w);
54             y = (int)(b.getY() + r.nextDouble()*h);
55             setX(item,null,x);
56             setY(item,null,y);
57         }
58     }
59
60 } // end of class RandomLayout
61
Popular Tags