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.reports.extension;
005    
006    import graphlab.platform.core.BlackBoard;
007    import graphlab.plugins.main.GraphData;
008    import graphlab.ui.AbstractExtensionAction;
009    import graphlab.ui.UIUtils;
010    import graphlab.ui.components.gpropertyeditor.GCellRenderer;
011    import graphlab.ui.components.utils.GFrameLocationProvider;
012    
013    import javax.swing.*;
014    import java.awt.*;
015    
016    /**
017     * @author azin azadi
018    
019     */
020    public class GraphReportExtensionAction extends AbstractExtensionAction {
021        protected GraphReportExtension mr;
022    
023        public GraphReportExtensionAction(BlackBoard bb, GraphReportExtension gg) {
024            super(bb, gg);
025            this.mr = gg;
026        }
027    
028        public String getParentMenuName() {
029            return "Graph.Reports";
030        }
031    
032        public Object performExtensionInCommandLine() {
033            return mr.calculate(new GraphData(blackboard));
034        }
035    
036    
037        public void performExtension() {
038    //        if (testAndSetParameters(gr)) {
039            new Thread() {
040    
041                public void run() {
042                    JDialog jd = new JDialog(UIUtils.getGFrame(blackboard));
043                    jd.setVisible(true);
044                    jd.setTitle(mr.getName());
045                    jd.setLayout(new BorderLayout(3, 3));
046                    jd.add(new JLabel(mr.getDescription()), BorderLayout.NORTH);
047                    Object result = mr.calculate(new GraphData(blackboard));
048                    Component rendererComponent = GCellRenderer.getRendererFor(result);
049                    rendererComponent.setEnabled(true);
050                    jd.add(rendererComponent, BorderLayout.CENTER);
051                    jd.setLocation(GFrameLocationProvider.getPopUpLocation());
052                    jd.pack();
053    
054                }
055            }.start();
056        }
057    
058    }