001 // GraphLab Project: http://graphlab.sharif.edu 002 // Copyright (C) 2008 Mathematical Science Department of Sharif University of Technology 003 // Distributed under the terms of the GNU General Public License (GPL): http://www.gnu.org/licenses/ 004 package graphlab.plugins.visualization.localsfvis; 005 006 import graphlab.graph.atributeset.GraphAttrSet; 007 import graphlab.graph.graph.GraphModel; 008 import graphlab.graph.graph.GraphPoint; 009 import graphlab.graph.graph.VertexModel; 010 import graphlab.platform.core.AbstractAction; 011 import graphlab.platform.core.BlackBoard; 012 import graphlab.plugins.graphgenerator.core.PositionGenerators; 013 import graphlab.ui.UIUtils; 014 015 import java.awt.*; 016 import java.awt.geom.Rectangle2D; 017 018 public class circular extends AbstractAction { 019 GraphModel g; 020 String event = UIUtils.getUIEventKey("circular"); 021 private int n; 022 VertexModel[] v; 023 024 /** 025 * constructor 026 * 027 * @param bb the blackboard of the action 028 */ 029 public circular(BlackBoard bb) { 030 super(bb); 031 listen4Event(event); 032 033 } 034 035 /** 036 * like Action 037 * 038 * @param eventName 039 * @param value 040 */ 041 public void performAction(String eventName, Object value) { 042 g = blackboard.getData(GraphAttrSet.name); 043 n = g.getVerticesCount(); 044 v = new VertexModel[n]; 045 v = getVertices(); 046 Rectangle2D.Double b = g.getAbsBounds(); 047 int w = (int) b.width; 048 int h = (int) b.height; 049 if (w < 5) 050 w = 150; 051 if (h < 5) 052 h = 150; 053 Point[] p = PositionGenerators.circle(25, 25, w + 25, h + 25, n); 054 for (int i = 0; i < n; i++) { 055 v[i].setLocation(new GraphPoint(p[i].x, p[i].y)); 056 } 057 058 } 059 060 private VertexModel[] getVertices() { 061 VertexModel[] ret = new VertexModel[n]; 062 int i = 0; 063 for (VertexModel vm : g) 064 ret[i++] = vm; 065 return ret; 066 } 067 }