001: /*
002: * @(#)ProgressEntry.java 1.20 06/10/10
003: *
004: * Copyright 1990-2006 Sun Microsystems, Inc. All Rights Reserved.
005: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License version
009: * 2 only, as published by the Free Software Foundation.
010: *
011: * This program is distributed in the hope that it will be useful, but
012: * WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * General Public License version 2 for more details (a copy is
015: * included at /legal/license.txt).
016: *
017: * You should have received a copy of the GNU General Public License
018: * version 2 along with this work; if not, write to the Free Software
019: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA
021: *
022: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
023: * Clara, CA 95054 or visit www.sun.com if you need additional
024: * information or have any questions.
025: *
026: */
027: package sun.net;
028:
029: import java.net.URL;
030:
031: public class ProgressEntry {
032: public static final int HTML = 0;
033: public static final int IMAGE = 1;
034: public static final int CLASS = 2;
035: public static final int AUDIO = 3;
036: public static final int OTHER = 4;
037:
038: /* bytes needed */
039: public int need = 0;
040: /* bytes read */
041: public int read = 0;
042: /* the last thing to happen to this entry */
043: public int what;
044: /* where this entry falls into the array
045: * of all entries we're monitoring
046: */
047: public int index;
048: public boolean connected = false;
049:
050: // Label for this entry.
051: public String label;
052:
053: public int type;
054:
055: public ProgressEntry(String l, String ctype) {
056: label = l;
057: type = OTHER;
058: need = 0;
059: setType(l, ctype);
060: }
061:
062: /*
063: * Usually called when a URL is finally connected after the
064: * content type is known.
065: */
066: public void setType(String l, String ctype) {
067: if (ctype != null) {
068: if (ctype.startsWith("image")) {
069: type = IMAGE;
070: } else if (ctype.startsWith("audio")) {
071: type = AUDIO;
072: } else if (ctype.equals("application/java-vm")) {
073: type = CLASS;
074: } else if (ctype.startsWith("text/html")) {
075: type = HTML;
076: }
077: }
078: if (type == OTHER) {
079: if (l.endsWith(".html") || l.endsWith("/")
080: || l.endsWith(".htm")) {
081: type = HTML;
082: } else if (l.endsWith(".class")) {
083: type = CLASS;
084: } else if (l.endsWith(".gif") || l.endsWith(".xbm")
085: || l.endsWith(".jpeg") || l.endsWith(".jpg")
086: || l.endsWith(".jfif")) {
087: type = IMAGE;
088: } else if (l.endsWith(".au")) {
089: type = AUDIO;
090: }
091: }
092: }
093:
094: public void update(int total_read, int total_need) {
095: if (need == 0) {
096: need = total_need;
097: }
098: read = total_read;
099: }
100:
101: /*
102: this returns the previous value of the connected boolean.
103: typical usage as found in Progressdata is something like
104: if (te.connected() == false) {
105: lastchanged = i;
106: setChanged();
107: notifyObservers();
108: }
109:
110: */
111: public synchronized boolean connected() {
112: if (!connected) {
113: connected = true;
114: return false;
115: }
116: return true;
117: }
118: }
|