home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD (UK) 2000 March / pcp161a.iso / handson / files / copyjava.exe / com / sun / java / swing / ProgressMonitor.class (.txt) < prev    next >
Encoding:
Java Class File  |  1998-02-26  |  3.4 KB  |  158 lines

  1. package com.sun.java.swing;
  2.  
  3. import java.awt.Component;
  4.  
  5. public class ProgressMonitor {
  6.    private int millisToDecideToPopup;
  7.    private int millisToPopup;
  8.    private int min;
  9.    private int max;
  10.    // $FF: renamed from: v int
  11.    private int field_0;
  12.    private int lastDisp;
  13.    private int reportDelta;
  14.    private ProgressMonitor root;
  15.    private JDialog dialog;
  16.    private JOptionPane pane;
  17.    private JProgressBar myBar;
  18.    private JLabel noteLabel;
  19.    private Component parentComponent;
  20.    private String note;
  21.    private Object message;
  22.    // $FF: renamed from: T0 long
  23.    private long field_1;
  24.  
  25.    public ProgressMonitor(Component var1, Object var2, String var3, int var4, int var5) {
  26.       this(var1, var2, var3, var4, var5, (ProgressMonitor)null);
  27.    }
  28.  
  29.    private ProgressMonitor(Component var1, Object var2, String var3, int var4, int var5, ProgressMonitor var6) {
  30.       this.millisToDecideToPopup = 500;
  31.       this.millisToPopup = 2000;
  32.       this.min = var4;
  33.       this.max = var5;
  34.       this.parentComponent = var1;
  35.       this.reportDelta = (var5 - var4) / 100;
  36.       if (this.reportDelta < 1) {
  37.          this.reportDelta = 1;
  38.       }
  39.  
  40.       this.field_0 = var4;
  41.       this.message = var2;
  42.       this.note = var3;
  43.       if (var6 != null) {
  44.          this.root = var6.root != null ? var6.root : var6;
  45.          this.field_1 = this.root.field_1;
  46.          this.dialog = this.root.dialog;
  47.       } else {
  48.          this.field_1 = System.currentTimeMillis();
  49.       }
  50.    }
  51.  
  52.    public void setProgress(int var1) {
  53.       this.field_0 = var1;
  54.       if (var1 >= this.max) {
  55.          this.close();
  56.       } else {
  57.          if (var1 >= this.lastDisp + this.reportDelta) {
  58.             this.lastDisp = var1;
  59.             if (this.myBar != null) {
  60.                this.myBar.setValue(var1);
  61.                return;
  62.             }
  63.  
  64.             long var2 = System.currentTimeMillis();
  65.             long var4 = (long)((int)(var2 - this.field_1));
  66.             if (var4 >= (long)this.millisToDecideToPopup) {
  67.                int var6;
  68.                if (var1 > this.min) {
  69.                   var6 = (int)(var4 * (long)(this.max - this.min) / (long)(var1 - this.min));
  70.                } else {
  71.                   var6 = this.millisToPopup;
  72.                }
  73.  
  74.                if (var6 >= this.millisToPopup) {
  75.                   this.myBar = new JProgressBar();
  76.                   this.myBar.setMinimum(this.min);
  77.                   this.myBar.setMaximum(this.max);
  78.                   this.myBar.setValue(var1);
  79.                   if (this.note != null) {
  80.                      this.noteLabel = new JLabel(this.note);
  81.                   }
  82.  
  83.                   this.pane = new ProgressOptionPane(new Object[]{this.message, this.noteLabel, this.myBar});
  84.                   this.dialog = this.pane.createDialog(this.parentComponent, "Progress...");
  85.                   this.dialog.setModal(false);
  86.                   this.dialog.show();
  87.                }
  88.             }
  89.          }
  90.  
  91.       }
  92.    }
  93.  
  94.    public void close() {
  95.       if (this.dialog != null) {
  96.          this.dialog.setVisible(false);
  97.          this.dialog.dispose();
  98.          this.dialog = null;
  99.          this.pane = null;
  100.          this.myBar = null;
  101.       }
  102.  
  103.    }
  104.  
  105.    public int getMinimum() {
  106.       return this.min;
  107.    }
  108.  
  109.    public void setMinimum(int var1) {
  110.       this.min = var1;
  111.    }
  112.  
  113.    public int getMaximum() {
  114.       return this.max;
  115.    }
  116.  
  117.    public void setMaximum(int var1) {
  118.       this.max = var1;
  119.    }
  120.  
  121.    public boolean isCanceled() {
  122.       if (this.pane == null) {
  123.          return false;
  124.       } else {
  125.          Object var1 = this.pane.getValue();
  126.          return var1 != null && var1 instanceof Integer && (Integer)var1 == 2;
  127.       }
  128.    }
  129.  
  130.    public void setMillisToDecideToPopup(int var1) {
  131.       this.millisToDecideToPopup = var1;
  132.    }
  133.  
  134.    public int getMillisToDecideToPopup() {
  135.       return this.millisToDecideToPopup;
  136.    }
  137.  
  138.    public void setMillisToPopup(int var1) {
  139.       this.millisToPopup = var1;
  140.    }
  141.  
  142.    public int getMillisToPopup() {
  143.       return this.millisToPopup;
  144.    }
  145.  
  146.    public void setNote(String var1) {
  147.       this.note = var1;
  148.       if (this.noteLabel != null) {
  149.          this.noteLabel.setText(var1);
  150.       }
  151.  
  152.    }
  153.  
  154.    public String getNote() {
  155.       return this.note;
  156.    }
  157. }
  158.