/************************************************************************** /* This class provides a message line with a progress indicator. /* /* Copyright (c) 2003-2004 by Bernhard Bablok (mail@bablokb.de) /* /* This library is free software; you can redistribute it and/or modify /* it under the terms of the GNU Lesser General Public License as published /* by the Free Software Foundation; either version 2 of the License or /* (at your option) any later version. /* /* This library is distributed in the hope that it will be useful, but /* WITHOUT ANY WARRANTY; without even the implied warranty of /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /* GNU Lesser General Public License for more details. /* /* You should have received a copy of the GNU Lesser General Public License /* along with this library; see the file COPYING.LESSER. If not, write to /* the Free Software Foundation Inc., 59 Temple Place - Suite 330, /* Boston, MA 02111-1307 USA /**************************************************************************/ package de.bablokb.luala.lib.gui; import java.awt.*; import java.lang.*; import javax.swing.*; /** A message line with a progress indicator. Add this widget to the bottom (BorderLayout.SOUTH) of a JFrame. @see javax.swing.JLabel @see javax.swing.JProgressBar @version $Revision: 1.2 $ @author $Author: bablokb $ */ public class MessageLine extends JPanel { private int iWidth = 300; // Default widget width private JLabel iLabel; private JProgressBar iBar; //////////////////////////////////////////////////////////////////////////// /** Constructor. Create components. */ public MessageLine() { iBar = new JProgressBar(); iLabel = new JLabel(); iLabel.setBackground(Color.lightGray); iLabel.setForeground(Color.red); // Layout setLayout(new GridBagLayout()); GridBagConstraints constraint = new GridBagConstraints(); constraint.insets = new Insets(5,5,5,5); constraint.ipadx = 2; constraint.ipady = 2; constraint.gridx = 0; constraint.gridy = 0; constraint.gridwidth = 1; constraint.gridheight = 1; constraint.weightx = 0.7; constraint.weighty = 0; constraint.fill = GridBagConstraints.HORIZONTAL; constraint.anchor = GridBagConstraints.NORTHWEST; add(iLabel,constraint); constraint.gridx = 1; constraint.gridy = 0; constraint.gridwidth = 1; constraint.gridheight = 1; constraint.weightx = 0.3; constraint.weighty = 0; constraint.fill = GridBagConstraints.HORIZONTAL; constraint.anchor = GridBagConstraints.NORTHEAST; add(iBar,constraint); } //////////////////////////////////////////////////////////////////////////// /** Set message @param text Message */ public void setText(String text) { iLabel.setText(text); } //////////////////////////////////////////////////////////////////////////// /** Set widget width for getMinimumSize(). @param width Width of widget */ public int setWidth(int width) { int old = iWidth; iWidth = width; return old; } //////////////////////////////////////////////////////////////////////////// /** Minimum size. The width is a constant, the height depends on the font. */ public Dimension getMinimumSize() { FontMetrics fm = iLabel.getFontMetrics(getFont()); return new Dimension(iWidth,2*fm.getHeight()); } //////////////////////////////////////////////////////////////////////////// /** Preferred size (just return minimum size). */ public Dimension getPreferredSize() { return getMinimumSize(); } //////////////////////////////////////////////////////////////////////////// /** Start progress-bar. */ public void start() { iBar.setIndeterminate(true); } //////////////////////////////////////////////////////////////////////////// /** Stop progress-bar. */ public void stop() { iBar.setIndeterminate(false); } //////////////////////////////////////////////////////////////////////////// /** Start-status of progress-bar. */ public boolean isStarted() { return iBar.isIndeterminate(); } }