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.graph.EdgeModel;
007    import graphlab.graph.graph.VertexModel;
008    import graphlab.platform.core.BlackBoard;
009    import graphlab.plugins.main.core.actions.edge.EdgeSelectData;
010    import graphlab.plugins.main.core.actions.vertex.VertexSelectData;
011    import graphlab.ui.components.GComponentInterface;
012    import graphlab.ui.components.gpropertyeditor.utils.ObjectViewer;
013    
014    import javax.swing.*;
015    import java.awt.*;
016    import java.awt.event.MouseAdapter;
017    import java.awt.event.MouseEvent;
018    
019    /**
020     * Author: azin azadi
021     */
022    public class LastSelectedStatusAction extends graphlab.platform.core.AbstractAction implements
023            GComponentInterface {
024        /**
025         * @param bb the blackboard of the action
026         */
027        public LastSelectedStatusAction(BlackBoard bb) {
028            super(bb);
029            listen4Event(VertexSelectData.EVENT_KEY);
030            listen4Event(EdgeSelectData.EVENT_KEY);
031        }
032    
033        JLabel l;
034    
035        boolean labelHandled = false;
036    
037        private void handleMouseListener() {
038            if (l == null)
039                return;
040            if (!labelHandled) {
041                l.addMouseListener(new MouseAdapter() {
042                    public void mouseClicked(MouseEvent e) {
043                        ObjectViewer.showObject(last);
044                    }
045                });
046                labelHandled = true;
047            }
048    
049        }
050    
051        Object last;
052    
053        /**
054         * like Action
055         *
056         * @param eventName
057         * @param value
058         */
059        public void performAction(String eventName, Object value) {
060            l = label();
061            handleMouseListener();
062            if (eventName == VertexSelectData.EVENT_KEY) {
063                VertexSelectData last = blackboard.getData(VertexSelectData.EVENT_KEY);
064                VertexModel v = last.v;
065                l.setText("Vertex :: " + (v.getLabel()));
066                this.last = v;
067            }
068            if (eventName == EdgeSelectData.EVENT_KEY) {
069                EdgeModel e = ((EdgeSelectData) blackboard.getData(EdgeSelectData.EVENT_KEY)).edge;
070                l.setText("Edge :: " + (e.source.getLabel()) + "-->"
071                        + (e.target.getLabel()));
072                last = e;
073            }
074        }
075    
076        private JLabel label() {
077            return lab;
078        }
079    
080        JLabel lab = new JLabel("last select");
081    
082        public Component getComponent(BlackBoard b) {
083            return lab;
084        }
085    }