Initial opendaylight infrastructure commit!!
[controller.git] / third-party / net.sf.jung2 / src / main / java / edu / uci / ics / jung / algorithms / layout / util / RandomLocationTransformer.java
diff --git a/third-party/net.sf.jung2/src/main/java/edu/uci/ics/jung/algorithms/layout/util/RandomLocationTransformer.java b/third-party/net.sf.jung2/src/main/java/edu/uci/ics/jung/algorithms/layout/util/RandomLocationTransformer.java
new file mode 100644 (file)
index 0000000..34428b1
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+ * Created on Jul 19, 2005
+ *
+ * Copyright (c) 2005, the JUNG Project and the Regents of the University 
+ * of California
+ * All rights reserved.
+ *
+ * This software is open-source under the BSD license; see either
+ * "license.txt" or
+ * http://jung.sourceforge.net/license.txt for a description.
+ */
+package edu.uci.ics.jung.algorithms.layout.util;
+
+import java.awt.Dimension;
+import java.awt.geom.Point2D;
+import java.util.Date;
+import java.util.Random;
+
+import org.apache.commons.collections15.Transformer;
+
+/**
+ * Transforms the input type into a random location within
+ * the bounds of the Dimension property.
+ * This is used as the backing Transformer for the LazyMap
+ * for many Layouts,
+ * and provides a random location for unmapped vertices
+ * the first time they are accessed.
+ * 
+ * @author Tom Nelson
+ *
+ * @param <V>
+ */
+public class RandomLocationTransformer<V> implements Transformer<V,Point2D> {
+
+       Dimension d;
+       Random random;
+    
+    /**
+     * Creates an instance with the specified size which uses the current time 
+     * as the random seed.
+     */
+    public RandomLocationTransformer(Dimension d) {
+       this(d, new Date().getTime());
+    }
+    
+    /**
+     * Creates an instance with the specified dimension and random seed.
+     * @param d
+     * @param seed
+     */
+    public RandomLocationTransformer(final Dimension d, long seed) {
+       this.d = d;
+       this.random = new Random(seed);
+    }
+    
+    public Point2D transform(V v) {
+        return new Point2D.Double(random.nextDouble() * d.width, random.nextDouble() * d.height);
+    }
+}