001/*
002 *                    BioJava development code
003 *
004 * This code may be freely distributed and modified under the
005 * terms of the GNU Lesser General Public Licence.  This should
006 * be distributed with the code.  If you do not have a copy,
007 * see:
008 *
009 *      http://www.gnu.org/copyleft/lesser.html
010 *
011 * Copyright for this code is held jointly by the individual
012 * authors.  These should be listed in @author doc comments.
013 *
014 * For more information on the BioJava project and its aims,
015 * or to join the biojava-l mailing list, visit the home page
016 * at:
017 *
018 *      http://www.biojava.org/
019 *
020 */
021package org.biojava.nbio.structure.align.gui;
022
023import org.biojava.nbio.structure.align.FarmJob;
024import org.biojava.nbio.structure.align.client.FarmJobParameters;
025
026import javax.swing.*;
027import java.awt.*;
028
029public class GUIFarmJobRunnable implements Runnable{
030        FarmJobParameters params;
031        GUIAlignmentProgressListener progressListener ;
032        public GUIFarmJobRunnable(FarmJobParameters params){
033                this.params = params;
034
035
036        }
037
038        /**
039         * Create the GUI and show it. As with all GUI code, this must run
040         * on the event-dispatching thread.
041         */
042        private static void createAndShowGUI(GUIAlignmentProgressListener progressListener) {
043                //Create and set up the window.
044                JFrame frame = new JFrame("Monitor alignment process");
045                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
046
047                //Create and set up the content pane.
048                JComponent newContentPane = progressListener;
049                newContentPane.setOpaque(true); //content panes must be opaque
050                newContentPane.setSize(new Dimension(400,400));
051                frame.setContentPane(newContentPane);
052
053                //Display the window.
054                frame.pack();
055                frame.setVisible(true);
056        }
057
058        @Override
059        public void run() {
060
061                progressListener = new GUIAlignmentProgressListener();
062                progressListener.logStatus(params.toString());
063
064                //createAndShowGUI(progressListener);
065
066                FarmJob job = new FarmJob();
067
068                progressListener.setFarmJob(job);
069
070                job.addAlignmentProgressListener(progressListener);
071                job.setParams(params);
072
073                Thread t = new Thread(job);
074                t.start();
075
076
077                javax.swing.SwingUtilities.invokeLater(new Runnable() {
078                @Override
079                        public void run() {
080                    createAndShowGUI(progressListener);
081                }
082                });
083
084        }
085
086}