Coverage details for edu.uci.ics.jung.visualization.RandomVertexLocationDecorator

LineHitsSource
1 /*
2  * Created on Jul 19, 2005
3  *
4  * Copyright (c) 2005, the JUNG Project and the Regents of the University
5  * of California
6  * All rights reserved.
7  *
8  * This software is open-source under the BSD license; see either
9  * "license.txt" or
10  * http://jung.sourceforge.net/license.txt for a description.
11  */
12 package edu.uci.ics.jung.visualization;
13  
14 import java.awt.Dimension;
15 import java.awt.geom.Point2D;
16 import java.util.Date;
17 import java.util.HashMap;
18 import java.util.Iterator;
19 import java.util.Map;
20  
21 import cern.jet.random.engine.DRand;
22 import cern.jet.random.engine.RandomEngine;
23 import edu.uci.ics.jung.graph.ArchetypeVertex;
24  
25 public class RandomVertexLocationDecorator implements VertexLocationFunction
26 {
27     RandomEngine rand;
2819    Map v_locations = new HashMap();
29     Dimension dim;
30     
31     public RandomVertexLocationDecorator(Dimension d)
3219    {
3319        this.rand = new DRand((int)(new Date().getTime()));
3419        this.dim = d;
3519    }
36     
37     public RandomVertexLocationDecorator(Dimension d, int seed)
380    {
390        this.rand = new DRand(seed);
400        this.dim = d;
410    }
42     
43     /**
44      * Resets all vertex locations returned by <code>getLocation</code>
45      * to new (random) locations.
46      */
47     public void reset()
48     {
490        v_locations.clear();
500    }
51     
52     public Point2D getLocation(ArchetypeVertex v)
53     {
541015        Point2D location = (Point2D)v_locations.get(v);
551015        if (location == null)
56         {
57905            location = new Point2D.Double(rand.nextDouble() * dim.width, rand.nextDouble() * dim.height);
58905            v_locations.put(v, location);
59         }
601015        return location;
61     }
62  
63     public Iterator getVertexIterator()
64     {
650        return v_locations.keySet().iterator();
66     }
67 }

this report was generated by version 1.0.5 of jcoverage.
visit www.jcoverage.com for updates.

copyright © 2003, jcoverage ltd. all rights reserved.
Java is a trademark of Sun Microsystems, Inc. in the United States and other countries.