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.main.core.actions; 005 006 import graphlab.graph.atributeset.GraphAttrSet; 007 import graphlab.graph.graph.EdgeModel; 008 import graphlab.graph.graph.GraphModel; 009 import graphlab.graph.graph.VertexModel; 010 import graphlab.platform.core.AbstractAction; 011 import graphlab.platform.core.BlackBoard; 012 import graphlab.ui.UIUtils; 013 014 import java.util.Iterator; 015 016 /** 017 * @author azin azadi 018 019 */ 020 public class ResetGraph extends AbstractAction { 021 /** 022 * constructor 023 * 024 * @param bb the blackboard of the action 025 */ 026 public ResetGraph(BlackBoard bb) { 027 super(bb); 028 listen4Event(UIUtils.getUIEventKey("reset")); 029 } 030 031 public void performAction(String eventName, Object value) { 032 GraphModel g = blackboard.getData(GraphAttrSet.name); 033 resetGraph(g); 034 } 035 036 /** 037 * resets the state of current graph 038 * this means to set the properties of vertices and edges to default values, 039 * mark=false, model color=0, view color= default color * @param g 040 */ 041 public static void resetGraph(GraphModel g) { 042 boolean b = g.isShowChangesOnView(); 043 g.setShowChangesOnView(true); 044 for (VertexModel v : g) { 045 v.setMark(false); 046 v.setColor(0); 047 } 048 Iterator<EdgeModel> ie = g.edgeIterator(); 049 while (ie.hasNext()) { 050 EdgeModel e = ie.next(); 051 e.setMark(false); 052 // e.model.setWeight(0); 053 e.setColor(0); 054 } 055 g.setShowChangesOnView(b); 056 } 057 }