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.event.GraphSelectData;
007    import graphlab.platform.core.Listener;
008    
009    import javax.swing.*;
010    import java.awt.event.ActionEvent;
011    import java.awt.event.ActionListener;
012    
013    /**
014     * @author azin azadi
015     */
016    public class LSFUI extends JPanel implements ActionListener {
017        private static final long serialVersionUID = 3844363865479171073L;
018    
019        private LocalSF target;
020    
021        Listener n = new Listener() {
022            //todo: what does this performJob do (Rouzbeh)?
023            public void performJob(String name) {
024                animatorLSF a = target.getCurrentAnimator();
025                if (a != null)
026                    dynamic.setSelected(a.isDynamic);
027            }
028    
029            public void keyChanged(String name, Object value) {
030                animatorLSF a = target.getCurrentAnimator();
031                if (a != null)
032                    dynamic.setSelected(a.isDynamic);
033            }
034    
035            public boolean isEnable() {
036                return isVisible();
037            }
038        };
039    
040        public void setTaget(LocalSF trg) {
041            this.target = trg;
042            initComponents();
043            trg.getBlackBoard().addListener(GraphSelectData.EVENT_KEY, n);
044        }
045    
046        private void initComponents() {
047            start = new javax.swing.JButton();
048            stop = new javax.swing.JButton();
049            opener = new javax.swing.JButton();
050            closer = new javax.swing.JButton();
051            stress = new javax.swing.JButton();
052            dynamic = new javax.swing.JCheckBox();
053    
054            setLayout(new java.awt.GridLayout(3, 2));
055    
056            start.setText("Start");
057            start.addActionListener(this);
058            add(start);
059    
060            stop.setText("Stop");
061            stop.addActionListener(this);
062            add(stop);
063    
064            opener.setText("+");
065            opener.addActionListener(this);
066    
067            add(opener);
068    
069            closer.setText("-");
070            closer.addActionListener(this);
071            add(closer);
072    
073            stress.setText("Stress");
074            stress.addActionListener(this);
075            add(stress);
076    
077            dynamic.setText("Automatic");
078            dynamic.setSelected(true);
079            dynamic.addActionListener(this);
080            dynamic.setSelected(true);
081            updateButtons();
082            add(dynamic);
083    
084        }
085    
086        // Variables declaration - do not modify
087        private javax.swing.JCheckBox dynamic;
088        private javax.swing.JButton closer;
089        private javax.swing.JButton opener;
090        private javax.swing.JButton start;
091        private javax.swing.JButton stop;
092        private javax.swing.JButton stress;
093        // End of variables declaration
094    
095        public void actionPerformed(ActionEvent e) {
096            if (target != null) {
097                animatorLSF anim = this.target.getCurrentAnimator();
098                if (anim != null) {
099                    if (e.getSource() == closer)
100                        anim.stronger();
101                    if (e.getSource() == opener)
102                        anim.weaker();
103                    if (e.getSource() == stress)
104                        anim.temporaryStress = true;
105                    if (e.getSource() == dynamic){
106                        updateButtons();
107                        anim.setDynamic(dynamic.isSelected());
108                    }
109                }
110                if (e.getSource() == stop) {
111                    target.stop();
112                }
113                if (e.getSource() == start) {
114                    target.start();
115                    anim = this.target.getCurrentAnimator();
116                    anim.setDynamic(dynamic.isSelected());
117                }
118            }
119        }
120    
121        private void updateButtons() {
122            boolean b = !dynamic.isSelected();
123            start.setEnabled(b);
124            closer.setEnabled(b);
125            opener.setEnabled(b);
126    //        stop.setEnabled(b);
127            stress.setEnabled(b);
128        }
129    }