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.platform.core.AbstractAction;
007    import graphlab.platform.core.BlackBoard;
008    import graphlab.ui.UIUtils;
009    import graphlab.ui.components.GComponentInterface;
010    
011    import javax.swing.*;
012    import java.awt.*;
013    import java.awt.event.ActionEvent;
014    import java.awt.event.ActionListener;
015    
016    /**
017     * with using of this class you can have a message in status bar of the program, by just putting a bar in the XML file as following
018     * <bar      class="graphlab.plugins.main.graph.actions.StatusBarMessage"    id="user message" />
019     *
020     * @author azin azadi
021     */
022    public class StatusBarMessage extends AbstractAction implements GComponentInterface {
023    
024        /**
025         * constructor
026         *
027         * @param bb the blackboard of the action
028         */
029        public StatusBarMessage(BlackBoard bb) {
030            super(bb);
031        }
032    
033        public void performAction(String eventName, Object value) {
034    
035        }
036    
037        static Timer t;
038    
039        /**
040         * shows a message in the status bar of the Frame loaded and assigned to current blackboard
041         * the showing message will be hide after 3 seconds
042         */
043        public static void showQuickMessage(final BlackBoard b, String message) {
044            setLabelMessage(b, message);
045            t = new Timer(3000, new ActionListener() {
046                public void actionPerformed(ActionEvent e) {
047                    t.stop();
048                    setLabelMessage(b, "");
049                }
050            });
051            t.start();
052        }
053    //    private static void setLastMessage(blackboard b, String msg) {
054    //        b.set("Last Status Message", msg);
055    //    }
056    //    private static String getLastMessage(blackboard b, String msg) {
057    //        return b.get("Last Status Message");
058    //    }
059    
060        /**
061         * shows a message in the status bar of the Frame loaded and assigned to current blackboard
062         * note that at each time just 1 message can be shown on that place
063         */
064        public static void setMessage(BlackBoard b, String s) {
065    //        setLastMessage(b, s);
066            setLabelMessage(b, s);
067        }
068    
069        private static void setLabelMessage(BlackBoard b, String msg) {
070            final JLabel l = (JLabel) UIUtils.getComponent(b, "user message");
071            l.setText(msg);
072            new Thread() {
073                public void run() {
074                    l.setBackground(Color.white);
075                    l.setOpaque(true);
076                    try {
077                        Thread.sleep(500);
078                    } catch (InterruptedException e) {
079                        e.printStackTrace();
080                    }
081                    l.repaint();
082                    l.setOpaque(false);
083                }
084            }.start();
085        }
086    
087        public void actionPerformed(ActionEvent e) {
088            //nothing to do :D
089        }
090    
091        JLabel l = new JLabel();
092    
093        public Component getComponent(BlackBoard b) {
094    //        l.setBackground(Color.lightGray.brighter());
095    
096            l.setOpaque(false);
097            return l;
098        }
099    }