home *** CD-ROM | disk | FTP | other *** search
/ Sky at Night 2007 June / SAN CD 6-2007 CD-ROM 25.iso / pc / Software / AstroGrav_Win / Java / jre1.6.0 / lib / rt.jar / sun / net / ProgressSource.class (.txt) < prev    next >
Encoding:
Java Class File  |  2006-11-29  |  2.5 KB  |  116 lines

  1. package sun.net;
  2.  
  3. import java.net.URL;
  4.  
  5. public class ProgressSource {
  6.    private URL url;
  7.    private String method;
  8.    private String contentType;
  9.    private int progress;
  10.    private int lastProgress;
  11.    private int expected;
  12.    private State state;
  13.    private boolean connected;
  14.    private int threshold;
  15.    private ProgressMonitor progressMonitor;
  16.  
  17.    public ProgressSource(URL var1, String var2) {
  18.       this(var1, var2, -1);
  19.    }
  20.  
  21.    public ProgressSource(URL var1, String var2, int var3) {
  22.       this.progress = 0;
  23.       this.lastProgress = 0;
  24.       this.expected = -1;
  25.       this.connected = false;
  26.       this.threshold = 8192;
  27.       this.url = var1;
  28.       this.method = var2;
  29.       this.contentType = "content/unknown";
  30.       this.progress = 0;
  31.       this.lastProgress = 0;
  32.       this.expected = var3;
  33.       this.state = sun.net.ProgressSource.State.NEW;
  34.       this.progressMonitor = ProgressMonitor.getDefault();
  35.       this.threshold = this.progressMonitor.getProgressUpdateThreshold();
  36.    }
  37.  
  38.    public boolean connected() {
  39.       if (!this.connected) {
  40.          this.connected = true;
  41.          this.state = sun.net.ProgressSource.State.CONNECTED;
  42.          return false;
  43.       } else {
  44.          return true;
  45.       }
  46.    }
  47.  
  48.    public void close() {
  49.       this.state = sun.net.ProgressSource.State.DELETE;
  50.    }
  51.  
  52.    public URL getURL() {
  53.       return this.url;
  54.    }
  55.  
  56.    public String getMethod() {
  57.       return this.method;
  58.    }
  59.  
  60.    public String getContentType() {
  61.       return this.contentType;
  62.    }
  63.  
  64.    public void setContentType(String var1) {
  65.       this.contentType = var1;
  66.    }
  67.  
  68.    public int getProgress() {
  69.       return this.progress;
  70.    }
  71.  
  72.    public int getExpected() {
  73.       return this.expected;
  74.    }
  75.  
  76.    public State getState() {
  77.       return this.state;
  78.    }
  79.  
  80.    public void beginTracking() {
  81.       this.progressMonitor.registerSource(this);
  82.    }
  83.  
  84.    public void finishTracking() {
  85.       this.progressMonitor.unregisterSource(this);
  86.    }
  87.  
  88.    public void updateProgress(int var1, int var2) {
  89.       this.lastProgress = this.progress;
  90.       this.progress = var1;
  91.       this.expected = var2;
  92.       if (!this.connected()) {
  93.          this.state = sun.net.ProgressSource.State.CONNECTED;
  94.       } else {
  95.          this.state = sun.net.ProgressSource.State.UPDATE;
  96.       }
  97.  
  98.       if (this.lastProgress / this.threshold != this.progress / this.threshold) {
  99.          this.progressMonitor.updateProgress(this);
  100.       }
  101.  
  102.       if (this.expected != -1 && this.progress >= this.expected && this.progress != 0) {
  103.          this.close();
  104.       }
  105.  
  106.    }
  107.  
  108.    public Object clone() throws CloneNotSupportedException {
  109.       return super.clone();
  110.    }
  111.  
  112.    public String toString() {
  113.       return this.getClass().getName() + "[url=" + this.url + ", method=" + this.method + ", state=" + this.state + ", content-type=" + this.contentType + ", progress=" + this.progress + ", expected=" + this.expected + "]";
  114.    }
  115. }
  116.