arcgissamples\scenario\map\ImagePainter.java—ArcObjects 10.4 Help for Java | ArcGIS for Desktop
GIS Client
arcgissamples\scenario\map\ImagePainter.java
/* Copyright 2015 ESRI
* 
* All rights reserved under the copyright laws of the United States
* and applicable international laws, treaties, and conventions.
* 
* You may freely redistribute and use this sample code, with or
* without modification, provided you include the original copyright
* notice and use restrictions.
* 
* See the use restrictions at <your ArcGIS install location>/DeveloperKit10.4/userestrictions.txt.
* 
*/
package arcgissamples.scenario.map;

/**This class imlements an ImageObserver interface to receive
 * notification about the image that is being rendered
 */

public class ImagePainter implements java.awt.image.ImageObserver {

    private java.awt.Image _image;
    private java.awt.Graphics _g;
    private int _dx1;
    private int _dy1;
    private int _wd;
    private int _ht;
    private boolean _dispose;


    /**Starts the image rendering
     * @param image
     * @param g
     * @param dx1
     * @param dy1
     * @param wd
     * @param ht
     * @param dispose
     */

    public void start(java.awt.Image image, java.awt.Graphics g, int dx1, int dy1, int wd, int ht, boolean dispose) {
        _image = image;
        _g = g;
        _wd = wd;
        _ht = ht;
        _dispose = dispose;
        paint(_image);
    }

    /**Draws image on the graphics object
     * @param image
     */


    private void paint(java.awt.Image image) {
       _g.drawImage (image, _dx1, _dy1, _wd, _ht, 0,0,_wd,_ht, this);
    }

    /**Flushes image that is being used.
     * @param image
     */

    private void dispose(java.awt.Image image) {
        _g.dispose();
        image.flush();
    }

    /**Method to get the notification about the image
     * @see java.awt.image.ImageObserver#imageUpdate
     * @param img
     * @param infoflags
     * @param x
     * @param y
     * @param width
     * @param height
     * @return
     */

    public boolean imageUpdate(java.awt.Image img, int infoflags, int x, int y, int width, int height) {
        boolean done = true;  // preset to indicate no need to track this image anymore
        if (((infoflags & java.awt.image.ImageObserver.ERROR) > 0) || ((infoflags & java.awt.image.ImageObserver.ABORT) > 0)) {
             new Exception("Unable to render image");
            if (_dispose) dispose(img);
        } else if ((infoflags & java.awt.image.ImageObserver.ALLBITS) > 0) {
            paint(img);
            if (_dispose) dispose(img);
        } else if ((infoflags & java.awt.image.ImageObserver.SOMEBITS) > 0) {
            paint(img);
            done = false;
        } else {
            done = false;
        }
        return !done;
    }
}