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.AbstractGraphRenderer; 008 import graphlab.graph.graph.FastRenderer; 009 import graphlab.graph.graph.GraphModel; 010 import graphlab.platform.core.AbstractAction; 011 import graphlab.platform.core.BlackBoard; 012 import graphlab.platform.core.Listener; 013 import graphlab.ui.UIUtils; 014 015 import javax.swing.*; 016 import java.awt.*; 017 import java.util.HashMap; 018 019 /** 020 * User: root 021 */ 022 public class LocalSF extends AbstractAction { 023 public static final String EVENT_KEY = UIUtils.getUIEventKey("LocalSF"); 024 025 /** 026 * constructor 027 * 028 * @param bb the blackboard of the action 029 */ 030 public LocalSF(BlackBoard bb) { 031 super(bb); 032 listen4Event(EVENT_KEY); 033 //the variable which the component is in. 034 final String stop = UIUtils.getComponentVariableKeyNameInBlackBoard("stop"); 035 stopbtn = (JButton) UIUtils.getComponent(bb, "stop"); 036 if (stopbtn != null) 037 stopbtn.setVisible(false); 038 blackboard.addListener(stop, new Listener() { 039 public void performJob(String name) { 040 stopbtn = blackboard.getData(stop); 041 stopbtn.setVisible(false); 042 } 043 044 public void keyChanged(String name, Object value) { 045 stopbtn = blackboard.getData(stop); 046 stopbtn.setVisible(false); 047 } 048 049 public boolean isEnable() { 050 return true; 051 } 052 }); 053 } 054 055 JButton stopbtn; 056 animatorLSF a; 057 058 /** 059 * like Action 060 * 061 * @param eventName 062 * @param value 063 */ 064 public void performAction(String eventName, Object value) { 065 LSFUI l = new LSFUI(); 066 l.setTaget(this); 067 Dialog d = new JDialog(); 068 // d.setModal(true); 069 d.add(l); 070 d.setVisible(true); 071 d.setAlwaysOnTop(true); 072 d.pack(); 073 start(); 074 } 075 076 void stop() { 077 animatorLSF currentAnimator = getCurrentAnimator(); 078 if (currentAnimator != null) 079 currentAnimator._stop(); 080 g2a.remove(g); 081 if (gv instanceof FastRenderer) { 082 FastRenderer fgv = (FastRenderer) gv; 083 fgv.forceQuickPaint = false; 084 fgv.repaint(); 085 } 086 087 } 088 089 AbstractGraphRenderer gv; 090 091 void start() { 092 g = blackboard.getData(GraphAttrSet.name); 093 gv = blackboard.getData(AbstractGraphRenderer.EVENT_KEY); 094 if (gv instanceof FastRenderer) { 095 FastRenderer fgv = (FastRenderer) gv; 096 fgv.forceQuickPaint = true; 097 } 098 if (!g2a.containsKey(g)) { 099 a = new animatorLSF(blackboard, g, gv); 100 g2a.put(g, a); 101 a.start(); 102 } 103 } 104 105 animatorLSF getCurrentAnimator() { 106 g = blackboard.getData(GraphAttrSet.name); 107 return g2a.get(g); 108 } 109 110 HashMap<GraphModel, animatorLSF> g2a = new HashMap<GraphModel, animatorLSF>(); 111 GraphModel g; 112 } 113 114