home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 25 / CDROM25.iso / Share / prog / VJ11 / VJTRIAL.EXE / IE30Java.exe / classd.exe / sun / net / ProgressEntry.java < prev    next >
Encoding:
Java Source  |  1997-01-27  |  2.8 KB  |  107 lines

  1. /*
  2.  * @(#)ProgressEntry.java    1.7 95/11/04 Chris Warth
  3.  *
  4.  * Copyright (c) 1994 Sun Microsystems, Inc. All Rights Reserved.
  5.  *
  6.  * Permission to use, copy, modify, and distribute this software
  7.  * and its documentation for NON-COMMERCIAL purposes and without
  8.  * fee is hereby granted provided that this copyright notice
  9.  * appears in all copies. Please refer to the file "copyright.html"
  10.  * for further important copyright and licensing information.
  11.  *
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
  13.  * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
  14.  * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  15.  * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
  16.  * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
  17.  * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
  18.  */
  19. package sun.net;
  20.  
  21. import java.net.URL;
  22.  
  23. public class ProgressEntry {
  24.     public static final int HTML  = 0;
  25.     public static final int IMAGE = 1;
  26.     public static final int CLASS = 2;
  27.     public static final int AUDIO = 3;
  28.     public static final int OTHER = 4;
  29.  
  30.     public int need = 0;
  31.     public int read = 0;
  32.     public boolean connected = false;
  33.  
  34.     // Label for this entry.
  35.     public String label;
  36.  
  37.     public int type;
  38.  
  39.     public Object key;
  40.  
  41.     ProgressEntry(Object o, String l, String ctype) {
  42.     key = o;
  43.     label = l;
  44.     type = IMAGE;
  45.     
  46.     setType(l, ctype);
  47.     }
  48.  
  49.  
  50.     /*
  51.      * Usually called when a URL is finally connected after the
  52.      * content type is known.
  53.      */
  54.     public void setType(String l, String ctype) {
  55.     type = OTHER;
  56.     if (ctype != null) {
  57.         if (ctype.startsWith("image")) {
  58.         type = IMAGE;
  59.         } else if (ctype.startsWith("audio")) {
  60.         type = AUDIO;
  61.         } else if (ctype.equals("application/java-vm")) {
  62.         type = CLASS;
  63.         } else if (ctype.startsWith("text/html")) {
  64.         type = HTML;
  65.         }
  66.     }
  67.     if (type == OTHER) {
  68.         if (l.endsWith(".gif") || l.endsWith(".xbm")
  69.         || l.endsWith(".jpeg") || l.endsWith(".jpg")
  70.         || l.endsWith(".jfif")) {
  71.         type = IMAGE;
  72.         } else if (l.endsWith(".au")) {
  73.         type = AUDIO;
  74.         } else if (l.endsWith(".class")) {
  75.         type = CLASS;
  76.         } else if (l.endsWith(".html") || l.endsWith("/")) {
  77.         type = HTML;        
  78.         }
  79.     }
  80.     }
  81.  
  82.     public void update(int total_read, int total_need) {
  83.     if (need == 0) {
  84.         need = total_need;
  85.     }
  86.     read = total_read;
  87.     }
  88.  
  89. /*
  90.     this returns the previous value of the connected boolean.
  91.     typical usage as found in Progressdata is something like
  92.         if (te.connected() == false) {
  93.             lastchanged = i;
  94.             setChanged();
  95.             notifyObservers();
  96.         }
  97.  
  98. */
  99.     public synchronized boolean connected() {
  100.     if (!connected) {
  101.         connected = true;    
  102.         return false;
  103.     } 
  104.     return true;
  105.     }
  106. }
  107.