Methods Summary |
---|
private void | abortAllConsumers(java.util.List consumersList)This method stops sending data to the list of consumers.
for (ImageConsumer imageConsumer : consumersList) {
abortConsumer(imageConsumer);
}
|
private void | abortConsumer(java.awt.image.ImageConsumer ic)This method stops sending data to the given consumer
ic.imageComplete(ImageConsumer.IMAGEERROR);
consumers.remove(ic);
|
public synchronized void | addConsumer(java.awt.image.ImageConsumer ic)
if (!checkConnection()) { // No permission for this consumer
ic.imageComplete(ImageConsumer.IMAGEERROR);
return;
}
ImageConsumer cons = findConsumer(consumers, ic);
if (cons == null) { // Try to look in the decoders
ImageDecoder d = null;
// Check for all existing decoders
for (Iterator<ImageDecoder> i = decoders.iterator(); i.hasNext();) {
d = i.next();
cons = findConsumer(d.consumers, ic);
if (cons != null) {
break;
}
}
}
if (cons == null) { // Not found, add this consumer
consumers.add(ic);
}
|
protected abstract boolean | checkConnection()
|
private ImageDecoder | createDecoder()Tries to find an appropriate decoder for the input stream and adds it
to the list of decoders
InputStream is = getInputStream();
ImageDecoder decoder;
if (is == null) {
decoder = null;
} else {
decoder = ImageDecoder.createDecoder(this, is);
}
if (decoder != null) {
synchronized (this) {
decoders.add(decoder);
this.decoder = decoder;
loading = false;
consumers = new ArrayList<ImageConsumer>(5); // Reset queue
}
return decoder;
}
// We were not able to find appropriate decoder
List<ImageConsumer> cs;
synchronized (this) {
cs = consumers;
consumers = new ArrayList<ImageConsumer>(5);
loading = false;
}
abortAllConsumers(cs);
return null;
|
private static java.awt.image.ImageConsumer | findConsumer(java.util.List consumersList, java.awt.image.ImageConsumer ic)Checks if the consumer is in the list and returns it it is there
ImageConsumer res = null;
for (Iterator<ImageConsumer> i = consumersList.iterator(); i.hasNext();) {
res = i.next();
if (res.equals(ic)) {
return res;
}
}
return null;
|
protected abstract java.io.InputStream | getInputStream()
|
public synchronized boolean | isConsumer(java.awt.image.ImageConsumer ic)
ImageDecoder d = null;
// Check for all existing decoders
for (Iterator<ImageDecoder> i = decoders.iterator(); i.hasNext();) {
d = i.next();
if (findConsumer(d.consumers, ic) != null) {
return true;
}
}
// Check current queue of consumers
return findConsumer(consumers, ic) != null;
|
public void | load()This method serves as an entry point.
It starts the decoder and loads the image data.
synchronized (this) {
if (consumers.size() == 0) {
loading = false;
return;
}
}
ImageDecoder d = createDecoder();
if (d != null) {
try {
decoder.decodeImage();
} catch (IOException e) {
e.printStackTrace();
} finally {
removeDecoder(d);
abortAllConsumers(d.consumers);
}
}
|
synchronized void | lockDecoder(ImageDecoder d)Use this method to finish decoding or lock the list of consumers
for a particular decoder
if (d == decoder) {
decoder = null;
startProduction(null);
}
|
public synchronized void | removeConsumer(java.awt.image.ImageConsumer ic)
ImageDecoder d = null;
// Remove in all existing decoders
for (Iterator<ImageDecoder> i = decoders.iterator(); i.hasNext();) {
d = i.next();
removeConsumer(d.consumers, ic);
if (d.consumers.size() <= 0) {
d.terminate();
}
}
// Remove in the current queue of consumers
removeConsumer(consumers, ic);
|
private static void | removeConsumer(java.util.List consumersList, java.awt.image.ImageConsumer ic)Static implementation of removeConsumer method
ImageConsumer cons = null;
for (Iterator<ImageConsumer> i = consumersList.iterator(); i.hasNext();) {
cons = i.next();
if (cons.equals(ic)) {
i.remove();
}
}
|
private synchronized void | removeDecoder(ImageDecoder dr)Stop the given decoder and remove it from the list
lockDecoder(dr);
decoders.remove(dr);
|
public void | requestTopDownLeftRightResend(java.awt.image.ImageConsumer consumer)
// Do nothing
|
public synchronized void | startProduction(java.awt.image.ImageConsumer ic)
if (ic != null) {
addConsumer(ic);
}
if (!loading && consumers.size() > 0) {
ImageLoader.addImageSource(this);
loading = true;
}
|