2 * Created on Jul 19, 2005
4 * Copyright (c) 2005, the JUNG Project and the Regents of the University
8 * This software is open-source under the BSD license; see either
10 * http://jung.sourceforge.net/license.txt for a description.
12 package edu.uci.ics.jung.algorithms.layout.util;
14 import java.awt.Dimension;
15 import java.awt.geom.Point2D;
16 import java.util.Date;
17 import java.util.Random;
19 import org.apache.commons.collections15.Transformer;
22 * Transforms the input type into a random location within
23 * the bounds of the Dimension property.
24 * This is used as the backing Transformer for the LazyMap
26 * and provides a random location for unmapped vertices
27 * the first time they are accessed.
33 public class RandomLocationTransformer<V> implements Transformer<V,Point2D> {
39 * Creates an instance with the specified size which uses the current time
42 public RandomLocationTransformer(Dimension d) {
43 this(d, new Date().getTime());
47 * Creates an instance with the specified dimension and random seed.
51 public RandomLocationTransformer(final Dimension d, long seed) {
53 this.random = new Random(seed);
56 public Point2D transform(V v) {
57 return new Point2D.Double(random.nextDouble() * d.width, random.nextDouble() * d.height);