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.select;
005    
006    import graphlab.graph.graph.EdgeModel;
007    import graphlab.graph.graph.SubGraph;
008    import graphlab.graph.graph.VertexModel;
009    import graphlab.platform.core.AbstractAction;
010    import graphlab.platform.core.BlackBoard;
011    import graphlab.plugins.main.core.actions.edge.EdgeSelectData;
012    import graphlab.plugins.main.core.actions.vertex.VertexSelectData;
013    
014    /**
015     * Author: Azin Azadi
016     */
017    public class DeSelect extends AbstractAction {
018    
019        /**
020         * constructor
021         *
022         * @param bb the blackboard of the action
023         */
024        public DeSelect(BlackBoard bb) {
025            super(bb);
026            listen4Event(VertexSelectData.EVENT_KEY);
027            listen4Event(EdgeSelectData.EVENT_KEY);
028            blackboard.setData(Select.EVENT_KEY, new SubGraph());
029        }
030    
031        public void performAction(String eventName, Object value) {
032            if (eventName == VertexSelectData.EVENT_KEY)
033                selectVertex();
034            if (eventName == EdgeSelectData.EVENT_KEY)
035                selectEdge();
036        }
037    
038        public SubGraph getSelection() {
039            return Select.getSelection(blackboard);
040        }
041    
042        private void selectEdge() {
043            EdgeSelectData esd = blackboard.getData(EdgeSelectData.EVENT_KEY);
044            SubGraph sd = getSelection();
045            EdgeModel e = esd.edge;
046            //e.view.isSelected=!e.view.isSelected;
047    
048    //        if (!e.view.isSelected)
049            sd.edges.add(e);
050    //        else
051    //            sd.edges.remove(e);
052            Select.setSelection(blackboard, sd);
053        }
054    
055        private void selectVertex() {
056            VertexSelectData vsd = blackboard.getData(VertexSelectData.EVENT_KEY);
057            SubGraph sd = getSelection();
058            VertexModel v = vsd.v;
059            //v.view.isSelected=!v.view.isSelected;
060    //        if (!v.view.isSelected)
061            sd.vertices.add(v);
062    //        else
063    //            sd.vertices.remove(v);
064            Select.setSelection(blackboard, sd);
065        }
066    }