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.algorithmanimator.core.atoms;
005    
006    import graphlab.graph.graph.VertexModel;
007    import graphlab.graph.ui.GTabbedGraphPane;
008    import graphlab.library.event.Event;
009    import graphlab.library.event.VertexRequest;
010    import graphlab.platform.core.AbstractAction;
011    import graphlab.platform.core.BlackBoard;
012    import graphlab.plugins.algorithmanimator.core.AtomAnimator;
013    import graphlab.plugins.main.core.actions.vertex.VertexSelectData;
014    import graphlab.plugins.main.select.SelectPluginMethods;
015    
016    /**
017     * @author Azin Azadi
018     */
019    public class VertexSelect implements AtomAnimator<VertexRequest> {
020        public boolean isAnimatable(Event vertexRequest) {
021            return vertexRequest instanceof VertexRequest;
022        }
023    
024        public VertexRequest animate(final VertexRequest vr, final BlackBoard b) {
025            GTabbedGraphPane.showNotificationMessage(vr.message, b, true);
026            vs vt = new vs(b);
027            vt.start();
028            vr.setVertex(vt.getResult());
029            new SelectPluginMethods(b).clearSelection();
030            GTabbedGraphPane.showNotificationMessage("", b, true);
031            return vr;
032        }
033    
034    }
035    
036    class vs extends aa {
037        public vs(BlackBoard bb) {
038            super(bb);
039            listen4Event(VertexSelectData.EVENT_KEY);
040        }
041    
042        VertexModel a;
043    
044        public void performAction(String key, Object value) {
045            VertexSelectData vsd = blackboard.getData(VertexSelectData.EVENT_KEY);
046            a = vsd.v;
047            super.performAction(key, value);
048        }
049    
050        public VertexModel getResult() {
051            return a;
052        }
053    }
054    
055    abstract class aa extends AbstractAction {
056        /**
057         * constructor
058         *
059         * @param bb the blackboard of the action
060         */
061        public aa(BlackBoard bb) {
062            super(bb);
063    //        disable();
064        }
065    
066        boolean finished = false;
067    
068        public void start() {
069            enable();
070            while (!finished)
071                try {
072                    Thread.sleep(100);
073                } catch (InterruptedException e) {
074                    e.printStackTrace();
075                }
076            disable();
077        }
078    
079        public void performAction(String key, Object value) {
080            finished = true;
081        }
082    }