/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* ProgressSource represents the source of progress changes.
*
* @author Stanley Man-Kit Ho
*/
public class ProgressSource
{
// URL
// URL method
// Content type
// bytes read
// last bytes read
//bytes expected
// the last thing to happen with this source
// connect flag
private boolean connected = false;
// threshold for notification
// progress monitor
/**
* Construct progress source object.
*/
}
/**
* Construct progress source object.
*/
this.contentType = "content/unknown";
this.progress = 0;
this.lastProgress = 0;
}
public boolean connected() {
if (!connected) {
connected = true;
return false;
}
return true;
}
/**
* Close progress source.
*/
public void close() {
}
/**
* Return URL of progress source.
*/
return url;
}
/**
* Return method of URL.
*/
return method;
}
/**
* Return content type of URL.
*/
return contentType;
}
// Change content type
contentType = ct;
}
/**
* Return current progress.
*/
public long getProgress() {
return progress;
}
/**
* Return expected maximum progress; -1 if expected is unknown.
*/
public long getExpected() {
return expected;
}
/**
* Return state.
*/
return state;
}
/**
* Begin progress tracking.
*/
public void beginTracking() {
progressMonitor.registerSource(this);
}
/**
* Finish progress tracking.
*/
public void finishTracking() {
progressMonitor.unregisterSource(this);
}
/**
* Update progress.
*/
if (connected() == false)
else
// The threshold effectively divides the progress into
// different set of ranges:
//
// Range 0: 0..threshold-1,
// Range 1: threshold .. 2*threshold-1
// ....
// Range n: n*threshold .. (n+1)*threshold-1
//
// To determine which range the progress belongs to, it
// would be calculated as follow:
//
// range number = progress / threshold
//
// Notification should only be triggered when the current
// progress and the last progress are in different ranges,
// i.e. they have different range numbers.
//
// Using this range scheme, notification will be generated
// only once when the progress reaches each range.
//
progressMonitor.updateProgress(this);
}
// Detect read overrun
if (expected != -1) {
close();
}
}
return super.clone();
}
}
}