01: package prefuse.action.layout;
02:
03: import java.awt.geom.Rectangle2D;
04: import java.util.Iterator;
05: import java.util.Random;
06:
07: import prefuse.visual.VisualItem;
08:
09: /**
10: * Performs a random layout of items within the layout bounds.
11: *
12: * @author <a href="http://jheer.org">jeffrey heer</a>
13: */
14: public class RandomLayout extends Layout {
15:
16: private Random r = new Random(12345678L);
17:
18: /**
19: * Create a new RandomLayout that processes all items.
20: */
21: public RandomLayout() {
22: super ();
23: }
24:
25: /**
26: * Create a new RandomLayout.
27: * @param group the data group to layout
28: */
29: public RandomLayout(String group) {
30: super (group);
31: }
32:
33: /**
34: * Set the seed value for the random number generator.
35: * @param seed the random seed value
36: */
37: public void setRandomSeed(long seed) {
38: r.setSeed(seed);
39: }
40:
41: /**
42: * @see prefuse.action.Action#run(double)
43: */
44: public void run(double frac) {
45: Rectangle2D b = getLayoutBounds();
46: double x, y;
47: double w = b.getWidth();
48: double h = b.getHeight();
49: Iterator iter = getVisualization().visibleItems(m_group);
50: while (iter.hasNext()) {
51: VisualItem item = (VisualItem) iter.next();
52: x = (int) (b.getX() + r.nextDouble() * w);
53: y = (int) (b.getY() + r.nextDouble() * h);
54: setX(item, null, x);
55: setY(item, null, y);
56: }
57: }
58:
59: } // end of class RandomLayout
|