001/*
002 * Copyright (c) 2004-2010 The Regents of the University of California.
003 * All rights reserved.
004 *
005 * '$Author: brooks $'
006 * '$Date: 2012-08-07 05:12:26 +0000 (Tue, 07 Aug 2012) $' 
007 * '$Revision: 30363 $'
008 * 
009 * Permission is hereby granted, without written agreement and without
010 * license or royalty fees, to use, copy, modify, and distribute this
011 * software and its documentation for any purpose, provided that the above
012 * copyright notice and the following two paragraphs appear in all copies
013 * of this software.
014 *
015 * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY
016 * FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
017 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
018 * THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
019 * SUCH DAMAGE.
020 *
021 * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
022 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
023 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
024 * PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
025 * CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
026 * ENHANCEMENTS, OR MODIFICATIONS.
027 *
028 */
029
030package org.kepler.gui;
031
032import java.awt.Dimension;
033import java.awt.Frame;
034
035import javax.swing.JFrame;
036import javax.swing.JLabel;
037import javax.swing.JPanel;
038import javax.swing.JProgressBar;
039import javax.swing.SwingWorker;
040
041public class ProgressMonitorSwingWorker extends SwingWorker {
042    Frame parent;
043    JFrame controllingFrame;
044    String message;
045
046    /**
047     * Create a ProgressMonitorSwingWorker.
048     * @param message The message to be displayed by the progress monitor.
049     */
050    public ProgressMonitorSwingWorker(String message) {
051        super();
052        this.parent = parent;
053        this.message = message;
054    }
055
056    /**
057     * Construct the frame.
058     */
059    public Object doInBackground() {
060        ProgressMonitorPanel contentFrame = new ProgressMonitorPanel(message);
061        controllingFrame = new JFrame("Progress");
062        controllingFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
063
064        // Create and set up the content pane.
065        contentFrame.setOpaque(true); // content panes must be opaque
066        controllingFrame.setContentPane(contentFrame);
067
068        // Display the window.
069        controllingFrame.pack();
070        controllingFrame.setLocationRelativeTo(null); // stay in the center
071        controllingFrame.setVisible(true);
072        return null;
073    }
074
075    /**
076     * Remove the frame.
077     */
078    public void done() {
079        controllingFrame.setVisible(false);
080        controllingFrame.dispose();
081    }
082
083    private class ProgressMonitorPanel extends JPanel {
084        JLabel explanationLabel;
085        JProgressBar progBar = new JProgressBar();
086
087        /**
088         * Create a simple Progress monitor panel.
089         */
090        public ProgressMonitorPanel(String message) {
091            super();
092            explanationLabel = new JLabel(message);
093            progBar.setIndeterminate(true);
094            add(explanationLabel);
095            add(progBar);
096            setSize(new Dimension(400, 200));
097        }
098    }
099}