001/* A status bar to put at the bottom of application windows.
002
003 Copyright (c) 1998-2014 The Regents of the University of California.
004 All rights reserved.
005 Permission is hereby granted, without written agreement and without
006 license or royalty fees, to use, copy, modify, and distribute this
007 software and its documentation for any purpose, provided that the above
008 copyright notice and the following two paragraphs appear in all copies
009 of this software.
010
011 IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY
012 FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
013 ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
014 THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
015 SUCH DAMAGE.
016
017 THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
018 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
019 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
020 PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
021 CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
022 ENHANCEMENTS, OR MODIFICATIONS.
023
024 PT_COPYRIGHT_VERSION_2
025 COPYRIGHTENDKEY
026 */
027package ptolemy.gui;
028
029// Java imports.
030import java.awt.Color;
031import java.awt.Dimension;
032
033import javax.swing.BoxLayout;
034import javax.swing.JPanel;
035import javax.swing.JProgressBar;
036import javax.swing.JTextField;
037import javax.swing.border.EmptyBorder;
038
039///////////////////////////////////////////////////////////////////
040//// StatusBar
041
042/**
043 A status bar with a message and a progress bar, for putting at the
044 bottom of application windows.
045
046 <p>NOTE: This class is borrowed from Diva and modified.
047
048 @author John Reekie and Edward A. Lee
049 @version $Id$
050 @since Ptolemy II 0.4
051 @Pt.ProposedRating Yellow (eal)
052 @Pt.AcceptedRating Red (eal)
053 */
054@SuppressWarnings("serial")
055public class StatusBar extends JPanel {
056    /** Create a new status bar with an empty label and progress at zero.
057     */
058    public StatusBar() {
059        setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
060        // Set the maximum size so that resizing the Vergil welcome window
061        // does not result in a large, ugly status bar.
062        setMaximumSize(new Dimension(Short.MAX_VALUE, 25));
063        _message = new JTextField(20);
064        _message.setEditable(false);
065        _message.setAlignmentX(LEFT_ALIGNMENT);
066        add(_message);
067
068        _progressPanel = new JPanel();
069        _progressPanel.setBorder(new EmptyBorder(0, 3, 0, 3));
070        _progressPanel.setAlignmentX(RIGHT_ALIGNMENT);
071        add(_progressPanel);
072
073        _progress = new JProgressBar();
074        _progress.setMinimum(0);
075        _progress.setMaximum(100);
076        _progress.setValue(0);
077        _progressPanel.add(_progress);
078    }
079
080    ///////////////////////////////////////////////////////////////////
081    ////                         public methods                    ////
082
083    /** Return the progress bar associated with this status bar.
084     *  To adjust the displayed value, call setValue() with a number
085     *  between zero and 100.
086     *  @return The progress bar.
087     */
088    public JProgressBar progressBar() {
089        return _progress;
090    }
091
092    /** Set the background color.
093     *  @param color The background color.
094     */
095    @Override
096    public void setBackground(Color color) {
097        super.setBackground(color);
098
099        // For some incomprehensible reason, it is possible for this
100        // to be null, even though it is set to non-null in the constructor.
101        if (_progress != null) {
102            _progressPanel.setBackground(color);
103        }
104    }
105
106    /** Set the message displayed in the status bar. If the argument
107     *  is null, then clear the message.
108     *  @param message The message to display.
109     */
110    public void setMessage(String message) {
111        _message.setText(message);
112        // Force an immediate repaint, since this message might be a
113        // status update about actions in progress.
114        _message.paintImmediately(_message.getBounds());
115    }
116
117    ///////////////////////////////////////////////////////////////////
118    ////                         private variables                 ////
119    // The progress bar associated with this status bar.
120    private JProgressBar _progress;
121
122    // A panel for the progress bar.
123    private JPanel _progressPanel;
124
125    // The label that displays the status message.
126    // Use JTextField instead of JLabel because there appears to be no
127    // way to control the width of a label except by writing text to it.
128    private JTextField _message;
129}