home *** CD-ROM | disk | FTP | other *** search
/ Computer Shopper 183 / dpcs0503.iso / Components / Microsoft ASP / _SETUP.1 / ASPWizard.jar / asp / wizard / ProgressStatus.class (.txt) < prev    next >
Encoding:
Java Class File  |  1998-11-20  |  2.9 KB  |  89 lines

  1. package asp.wizard;
  2.  
  3. import asp.wizard.util.UiUtil;
  4. import com.sun.java.swing.BorderFactory;
  5. import com.sun.java.swing.JDialog;
  6. import com.sun.java.swing.JLabel;
  7. import com.sun.java.swing.JProgressBar;
  8. import com.sun.java.swing.UIManager;
  9. import java.awt.Component;
  10. import java.awt.Container;
  11. import java.awt.GridBagConstraints;
  12. import java.awt.GridBagLayout;
  13.  
  14. public class ProgressStatus extends JDialog {
  15.    public static final int PROGRESSBAR_MIN = 0;
  16.    public static final int PROGRESSBAR_MAX = 100;
  17.    private static final int WIDTH = 400;
  18.    private static final int HEIGHT = 100;
  19.    private static ProgressStatus _instance;
  20.    private JLabel _txfStatus;
  21.    private JProgressBar _pgbProgress;
  22.  
  23.    public static ProgressStatus getInstance() {
  24.       if (_instance == null) {
  25.          _instance = new ProgressStatus();
  26.       }
  27.  
  28.       return _instance;
  29.    }
  30.  
  31.    private ProgressStatus() {
  32.       this.initComponents();
  33.       this.initLayout();
  34.    }
  35.  
  36.    public void dispose() {
  37.       if (this == _instance) {
  38.          _instance = null;
  39.       }
  40.  
  41.       super.dispose();
  42.    }
  43.  
  44.    private void initComponents() {
  45.       this._txfStatus = new JLabel();
  46.       this._txfStatus.setBorder(BorderFactory.createEmptyBorder());
  47.       this._txfStatus.setBackground(UIManager.getColor("Control"));
  48.       this._pgbProgress = new JProgressBar();
  49.       this._pgbProgress.setMinimum(0);
  50.       this._pgbProgress.setMaximum(100);
  51.       this._pgbProgress.setValue(0);
  52.    }
  53.  
  54.    private void initLayout() {
  55.       Container c = ((JDialog)this).getContentPane();
  56.       GridBagLayout gbl = new GridBagLayout();
  57.       GridBagConstraints gbc = new GridBagConstraints();
  58.       c.setLayout(gbl);
  59.       UiUtil.addComponent(c, this._pgbProgress, gbl, gbc, 0, 0, 1, 1, (double)1.0F, (double)0.0F, 17, 2, 20, 5, 0, 5);
  60.       UiUtil.addComponent(c, this._txfStatus, gbl, gbc, 0, 1, 1, 1, (double)1.0F, (double)1.0F, 18, 2, 10, 5, 10, 5);
  61.       ((Component)this).setSize(400, 100);
  62.       UiUtil.centerComponentInScreen(this);
  63.    }
  64.  
  65.    public void reset() {
  66.       this._txfStatus.setText("");
  67.       this._pgbProgress.setValue(0);
  68.    }
  69.  
  70.    public void setValue(int value) {
  71.       if (value < 0) {
  72.          value = 0;
  73.       } else if (value >= 100) {
  74.          value = 100;
  75.       }
  76.  
  77.       this._pgbProgress.setValue(value);
  78.       Thread.yield();
  79.    }
  80.  
  81.    public void setText(String newText) {
  82.       newText = newText == null ? "" : newText;
  83.       this._txfStatus.setText(newText);
  84.       this._txfStatus.invalidate();
  85.       this._txfStatus.getParent().validate();
  86.       Thread.yield();
  87.    }
  88. }
  89.