Example usage for java.awt.image ImageObserver ERROR

List of usage examples for java.awt.image ImageObserver ERROR

Introduction

In this page you can find the example usage for java.awt.image ImageObserver ERROR.

Prototype

int ERROR

To view the source code for java.awt.image ImageObserver ERROR.

Click Source Link

Document

This flag in the infoflags argument to imageUpdate indicates that an image which was being tracked asynchronously has encountered an error.

Usage

From source file:Main.java

/**
 * Decodes the bits of a java.awt.image.ImageObserver infoflag into a human
 * readable string./* w w  w . j a va  2 s.  co  m*/
 * 
 * @param infoflag
 *            the flag to decode
 * @return a string describing the flag
 */
public static String imageObserverInfoflagToString(int infoflag) {
    String out = "";
    if ((infoflag & ImageObserver.ABORT) == ImageObserver.ABORT)
        out += "ABORT ";
    if ((infoflag & ImageObserver.ALLBITS) == ImageObserver.ALLBITS)
        out += "ALLBITS ";
    if ((infoflag & ImageObserver.ERROR) == ImageObserver.ERROR)
        out += "ERROR ";
    if ((infoflag & ImageObserver.FRAMEBITS) == ImageObserver.FRAMEBITS)
        out += "FRAMEBITS ";
    if ((infoflag & ImageObserver.HEIGHT) == ImageObserver.HEIGHT)
        out += "HEIGHT ";
    if ((infoflag & ImageObserver.PROPERTIES) == ImageObserver.PROPERTIES)
        out += "PROPERTIES ";
    if ((infoflag & ImageObserver.SOMEBITS) == ImageObserver.SOMEBITS)
        out += "SOMEBITS ";
    if ((infoflag & ImageObserver.WIDTH) == ImageObserver.WIDTH)
        out += "WIDTH ";
    return out;
}

From source file:ImageSize.java

public boolean imageUpdate(Image img, int infoflags, int x, int y, int width, int height) {
    if ((infoflags & ImageObserver.ERROR) != 0) {
        System.out.println("Error loading image!");
        System.exit(-1);// www .j  av  a 2s  . c o  m
    }
    if ((infoflags & ImageObserver.WIDTH) != 0 && (infoflags & ImageObserver.HEIGHT) != 0)
        rightSize();
    if ((infoflags & ImageObserver.SOMEBITS) != 0)
        repaint();
    if ((infoflags & ImageObserver.ALLBITS) != 0) {
        rightSize();
        repaint();
        return false;
    }
    return true;
}

From source file:ImageUtilities.java

/**
 * Starts loading the given image, returns only when it's done loading.
 * Note that it's much more efficient to preload a lot of images at once using
 * the preload(Image []) method instead of this one.
 *
 * @return The result of the image loading, either {@link #COMPLETE},
 * {@link #ERRORED}, {@link #ABORTED} or {@link #INTERRUPTED}.
 *
 * @see #preload(java.awt.Image [], int [])
 *///from  ww w.  ja  v a 2  s .  c o  m

public static int preload(Image image) {
    Toolkit toolkit = Toolkit.getDefaultToolkit();

    // Check if already loaded
    if ((toolkit.checkImage(image, -1, -1, null) & ImageObserver.ALLBITS) != 0)
        return COMPLETE;

    Object lock = new Object();
    synchronized (lock) {
        while (true) {
            ImageLoadObserver observer = new ImageLoadObserver(lock);
            toolkit.prepareImage(image, -1, -1, observer);
            int result = toolkit.checkImage(image, -1, -1, null);
            if ((result & ImageObserver.ALLBITS) != 0)
                return COMPLETE;
            if ((result & ImageObserver.ERROR) != 0)
                return ERRORED;
            if ((result & ImageObserver.ABORT) != 0)
                return ABORTED;

            try {
                lock.wait();
                return observer.getResult();
            } catch (InterruptedException e) {
                return INTERRUPTED;
            }
        }
    }
}

From source file:ImageLoaderApplet.java

/**
 * Verbose version of ImageConsumer's imageUpdate method
 *//* www . j  a  v a2s. co m*/
public boolean imageUpdate(Image img, int flags, int x, int y, int width, int height) {
    System.out.print("Flag(s): ");
    if ((flags & ImageObserver.WIDTH) != 0) {
        System.out.print("WIDTH:(" + width + ") ");
    }

    if ((flags & ImageObserver.HEIGHT) != 0) {
        System.out.print("HEIGHT:(" + height + ") ");
    }

    if ((flags & ImageObserver.PROPERTIES) != 0) {
        System.out.print("PROPERTIES ");
    }

    if ((flags & ImageObserver.SOMEBITS) != 0) {
        System.out.print("SOMEBITS(" + x + "," + y + ")->(");
        System.out.print(width + "," + height + ") ");
        repaint();
    }

    if ((flags & ImageObserver.FRAMEBITS) != 0) {
        System.out.print("FRAMEBITS(" + x + "," + y + ")->(");
        System.out.print(width + "," + height + ") ");
        repaint();
    }

    if ((flags & ImageObserver.ALLBITS) != 0) {
        System.out.print("ALLBITS(" + x + "," + y + ")->(");
        System.out.println(width + "," + height + ") ");
        repaint();
        return false;
    }

    if ((flags & ImageObserver.ABORT) != 0) {
        System.out.println("ABORT \n");
        return false;
    }

    if ((flags & ImageObserver.ERROR) != 0) {
        System.out.println("ERROR ");
        return false;
    }

    System.out.println();
    return true;
}

From source file:ImageUtilities.java

/**
 * Starts loading the given images, returns only when all the images are done
 * loading. If you just need to preload one Image, use the preload(Image) method
 * instead./*from  w ww  .j av a  2  s. c om*/
 *
 * @return An array specifying the loading result of each image. Possible values
 * are {@link #COMPLETE}, {@link #ERRORED} and {@link #ABORTED}.
 *
 * @see #preload(Image)
 */

public static int[] preload(Image[] images, int[] results) {
    Object[] locks = new Object[images.length];
    ImageLoadObserver[] loadObservers = new ImageLoadObserver[images.length];
    if ((results == null) || (results.length < images.length))
        results = new int[images.length];
    Toolkit toolkit = Toolkit.getDefaultToolkit();
    for (int i = 0; i < images.length; i++) {
        locks[i] = new Object();
        loadObservers[i] = new ImageLoadObserver(locks[i]);
        toolkit.prepareImage(images[i], -1, -1, loadObservers[i]);
    }

    for (int i = 0; i < images.length; i++) {
        synchronized (locks[i]) {
            int result = toolkit.checkImage(images[i], -1, -1, null);

            if ((result & ImageObserver.ALLBITS) != 0) {
                results[i] = COMPLETE;
                continue;
            }
            if ((result & ImageObserver.ERROR) != 0) {
                results[i] = ERRORED;
                continue;
            }
            if ((result & ImageObserver.ABORT) != 0) {
                results[i] = ABORTED;
                continue;
            }

            try {
                locks[i].wait();
                results[i] = loadObservers[i].getResult();
            } catch (InterruptedException e) {
                results[i] = INTERRUPTED;
            }
        }
    }

    return results;
}

From source file:WaitingImageObserver.java

/**
 * Callback function used by AWT to inform that more data is available. The
 * observer waits until either all data is loaded or AWT signals that the
 * image cannot be loaded./*from   w ww  .  j a  v  a  2s  .c  om*/
 *
 * @param     img   the image being observed.
 * @param     infoflags   the bitwise inclusive OR of the following
 *               flags:  <code>WIDTH</code>, <code>HEIGHT</code>,
 *               <code>PROPERTIES</code>, <code>SOMEBITS</code>,
 *               <code>FRAMEBITS</code>, <code>ALLBITS</code>,
 *               <code>ERROR</code>, <code>ABORT</code>.
 * @param     x   the <i>x</i> coordinate.
 * @param     y   the <i>y</i> coordinate.
 * @param     width    the width.
 * @param     height   the height.
 *
 * @return    <code>false</code> if the infoflags indicate that the
 *            image is completely loaded; <code>true</code> otherwise.
 */
public synchronized boolean imageUpdate(final Image img, final int infoflags, final int x, final int y,
        final int width, final int height) {
    if ((infoflags & ImageObserver.ALLBITS) == ImageObserver.ALLBITS) {
        this.lock = false;
        this.error = false;
        notifyAll();
        return false;
    } else if ((infoflags & ImageObserver.ABORT) == ImageObserver.ABORT
            || (infoflags & ImageObserver.ERROR) == ImageObserver.ERROR) {
        this.lock = false;
        this.error = true;
        notifyAll();
        return false;
    }
    //notifyAll();
    return true;
}

From source file:ucar.unidata.idv.flythrough.Flythrough.java

/**
 * _more_//from   w  w  w .  ja v a 2  s . c  o m
 *
 * @param img _more_
 * @param flags _more_
 * @param x _more_
 * @param y _more_
 * @param width _more_
 * @param height _more_
 *
 * @return _more_
 */
public boolean imageUpdate(Image img, int flags, int x, int y, int width, int height) {
    if ((flags & ImageObserver.ERROR) != 0) {
        return false;
    }
    updateDashboard();
    if ((flags & ImageObserver.ALLBITS) != 0) {
        return false;
    }
    return true;
}

From source file:org.pentaho.reporting.libraries.base.util.WaitingImageObserver.java

/**
 * Callback function used by AWT to inform that more data is available. The observer waits until either all data is
 * loaded or AWT signals that the image cannot be loaded.
 *
 * @param img       the image being observed.
 * @param infoflags the bitwise inclusive OR of the following flags:  <code>WIDTH</code>, <code>HEIGHT</code>,
 *                  <code>PROPERTIES</code>, <code>SOMEBITS</code>, <code>FRAMEBITS</code>, <code>ALLBITS</code>,
 *                  <code>ERROR</code>, <code>ABORT</code>.
 * @param x         the <i>x</i> coordinate.
 * @param y         the <i>y</i> coordinate.
 * @param width     the width./*from w  ww .j av a 2  s  .c om*/
 * @param height    the height.
 * @return <code>false</code> if the infoflags indicate that the image is completely loaded; <code>true</code>
 * otherwise.
 */
public synchronized boolean imageUpdate(final Image img, final int infoflags, final int x, final int y,
        final int width, final int height) {
    if (img == null) {
        throw new NullPointerException();
    }

    lastUpdate = System.currentTimeMillis();
    if ((infoflags & ImageObserver.ALLBITS) == ImageObserver.ALLBITS) {
        this.lock = false;
        this.error = false;
        notifyAll();
        return false;
    } else if ((infoflags & ImageObserver.FRAMEBITS) == ImageObserver.FRAMEBITS) {
        this.lock = false;
        this.error = false;
        notifyAll();
        return false;
    } else if ((infoflags & ImageObserver.ABORT) == ImageObserver.ABORT
            || (infoflags & ImageObserver.ERROR) == ImageObserver.ERROR) {
        this.lock = false;
        this.error = true;
        notifyAll();
        return false;
    }

    // maybe it is enough already to draw the image ..
    notifyAll();
    return true;
}