⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 memoryimagesource.java

📁 JAVA基本类源代码,大家可以学习学习!
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
     * data for this image.     * @param ic the specified <code>ImageConsumer</code>     * @see ImageConsumer     */    public synchronized void removeConsumer(ImageConsumer ic) {	theConsumers.removeElement(ic);    }    /**     * Adds an ImageConsumer to the list of consumers interested in     * data for this image and immediately starts delivery of the     * image data through the ImageConsumer interface.     * @param ic the specified <code>ImageConsumer</code>     * image data through the ImageConsumer interface.     * @see ImageConsumer     */    public void startProduction(ImageConsumer ic) {	addConsumer(ic);    }    /**     * Requests that a given ImageConsumer have the image data delivered     * one more time in top-down, left-right order.     * @param ic the specified <code>ImageConsumer</code>     * @see ImageConsumer     */    public void requestTopDownLeftRightResend(ImageConsumer ic) {	// Ignored.  The data is either single frame and already in TDLR	// format or it is multi-frame and TDLR resends aren't critical.    }    /**     * Changes this memory image into a multi-frame animation or a     * single-frame static image depending on the animated parameter.     * <p>This method should be called immediately after the     * MemoryImageSource is constructed and before an image is     * created with it to ensure that all ImageConsumers will     * receive the correct multi-frame data.  If an ImageConsumer     * is added to this ImageProducer before this flag is set then     * that ImageConsumer will see only a snapshot of the pixel     * data that was available when it connected.     * @param animated <code>true</code> if the image is a      *       multi-frame animation     */    public synchronized void setAnimated(boolean animated) {	this.animating = animated;	if (!animating) {	    Enumeration enum = theConsumers.elements();	    while (enum.hasMoreElements()) {	    	ImageConsumer ic = (ImageConsumer) enum.nextElement();		ic.imageComplete(ImageConsumer.STATICIMAGEDONE);		if (isConsumer(ic)) {		    ic.imageComplete(ImageConsumer.IMAGEERROR);		}	    }	    theConsumers.removeAllElements();	}    }    /**     * Specifies whether this animated memory image should always be     * updated by sending the complete buffer of pixels whenever     * there is a change.     * This flag is ignored if the animation flag is not turned on     * through the setAnimated() method.     * <p>This method should be called immediately after the     * MemoryImageSource is constructed and before an image is     * created with it to ensure that all ImageConsumers will     * receive the correct pixel delivery hints.     * @param fullbuffers <code>true</code> if the complete pixel      *             buffer should always     * be sent     * @see #setAnimated     */    public synchronized void setFullBufferUpdates(boolean fullbuffers) {	if (this.fullbuffers == fullbuffers) {	    return;	}	this.fullbuffers = fullbuffers;	if (animating) {	    Enumeration enum = theConsumers.elements();	    while (enum.hasMoreElements()) {	    	ImageConsumer ic = (ImageConsumer) enum.nextElement();		ic.setHints(fullbuffers			    ? (ImageConsumer.TOPDOWNLEFTRIGHT |			       ImageConsumer.COMPLETESCANLINES)			    : ImageConsumer.RANDOMPIXELORDER);	    }	}    }    /**     * Sends a whole new buffer of pixels to any ImageConsumers that     * are currently interested in the data for this image and notify     * them that an animation frame is complete.     * This method only has effect if the animation flag has been     * turned on through the setAnimated() method.     * @see #newPixels(int, int, int, int, boolean)     * @see ImageConsumer     * @see #setAnimated     */    public void newPixels() {	newPixels(0, 0, width, height, true);    }    /**     * Sends a rectangular region of the buffer of pixels to any     * ImageConsumers that are currently interested in the data for     * this image and notify them that an animation frame is complete.     * This method only has effect if the animation flag has been     * turned on through the setAnimated() method.     * If the full buffer update flag was turned on with the     * setFullBufferUpdates() method then the rectangle parameters     * will be ignored and the entire buffer will always be sent.     * @param x the x coordinate of the upper left corner of the rectangle     * of pixels to be sent     * @param y the y coordinate of the upper left corner of the rectangle     * of pixels to be sent     * @param w the width of the rectangle of pixels to be sent     * @param h the height of the rectangle of pixels to be sent     * @see #newPixels(int, int, int, int, boolean)     * @see ImageConsumer     * @see #setAnimated     * @see #setFullBufferUpdates     */    public synchronized void newPixels(int x, int y, int w, int h) {	newPixels(x, y, w, h, true);    }    /**     * Sends a rectangular region of the buffer of pixels to any     * ImageConsumers that are currently interested in the data for     * this image.     * If the framenotify parameter is true then the consumers are     * also notified that an animation frame is complete.     * This method only has effect if the animation flag has been     * turned on through the setAnimated() method.     * If the full buffer update flag was turned on with the     * setFullBufferUpdates() method then the rectangle parameters     * will be ignored and the entire buffer will always be sent.     * @param x the x coordinate of the upper left corner of the rectangle     * of pixels to be sent     * @param y the y coordinate of the upper left corner of the rectangle     * of pixels to be sent     * @param w the width of the rectangle of pixels to be sent     * @param h the height of the rectangle of pixels to be sent     * @param framenotify <code>true</code> if the consumers should be sent a     * {@link ImageConsumer#SINGLEFRAMEDONE SINGLEFRAMEDONE} notification     * @see ImageConsumer     * @see #setAnimated     * @see #setFullBufferUpdates     */    public synchronized void newPixels(int x, int y, int w, int h,				       boolean framenotify) {	if (animating) {	    if (fullbuffers) {		x = y = 0;		w = width;		h = height;	    } else {		if (x < 0) {		    w += x;		    x = 0;		}		if (x + w > width) {		    w = width - x;		}		if (y < 0) {		    h += y;		    y = 0;		}		if (y + h > height) {		    h = height - y;		}	    }	    if ((w <= 0 || h <= 0) && !framenotify) {		return;	    }	    Enumeration enum = theConsumers.elements();	    while (enum.hasMoreElements()) {	    	ImageConsumer ic = (ImageConsumer) enum.nextElement();		if (w > 0 && h > 0) {		    sendPixels(ic, x, y, w, h);		}		if (framenotify && isConsumer(ic)) {		    ic.imageComplete(ImageConsumer.SINGLEFRAMEDONE);		}	    }	}    }    /**     * Changes to a new byte array to hold the pixels for this image.     * If the animation flag has been turned on through the setAnimated()     * method, then the new pixels will be immediately delivered to any     * ImageConsumers that are currently interested in the data for     * this image.     * @param newpix the new pixel array     * @param newmodel the specified <code>ColorModel</code>     * @param offset the offset into the array     * @param scansize the distance from one row of pixels to the next in     * the array     * @see #newPixels(int, int, int, int, boolean)     * @see #setAnimated     */    public synchronized void newPixels(byte[] newpix, ColorModel newmodel,				       int offset, int scansize) {	this.pixels = newpix;	this.model = newmodel;	this.pixeloffset = offset;	this.pixelscan = scansize;	newPixels();    }    /**     * Changes to a new int array to hold the pixels for this image.     * If the animation flag has been turned on through the setAnimated()     * method, then the new pixels will be immediately delivered to any     * ImageConsumers that are currently interested in the data for     * this image.     * @param newpix the new pixel array     * @param newmodel the specified <code>ColorModel</code>     * @param offset the offset into the array     * @param scansize the distance from one row of pixels to the next in     * the array     * @see #newPixels(int, int, int, int, boolean)     * @see #setAnimated     */    public synchronized void newPixels(int[] newpix, ColorModel newmodel,				       int offset, int scansize) {	this.pixels = newpix;	this.model = newmodel;	this.pixeloffset = offset;	this.pixelscan = scansize;	newPixels();    }    private void initConsumer(ImageConsumer ic) {	if (isConsumer(ic)) {	    ic.setDimensions(width, height);	}	if (isConsumer(ic)) {	    ic.setProperties(properties);	}	if (isConsumer(ic)) {	    ic.setColorModel(model);	}	if (isConsumer(ic)) {	    ic.setHints(animating			? (fullbuffers			   ? (ImageConsumer.TOPDOWNLEFTRIGHT |			      ImageConsumer.COMPLETESCANLINES)			   : ImageConsumer.RANDOMPIXELORDER)			: (ImageConsumer.TOPDOWNLEFTRIGHT |			   ImageConsumer.COMPLETESCANLINES |			   ImageConsumer.SINGLEPASS |			   ImageConsumer.SINGLEFRAME));	}    }    private void sendPixels(ImageConsumer ic, int x, int y, int w, int h) {	int off = pixeloffset + pixelscan * y + x;	if (isConsumer(ic)) {	    if (pixels instanceof byte[]) {		ic.setPixels(x, y, w, h, model,			     ((byte[]) pixels), off, pixelscan);	    } else {		ic.setPixels(x, y, w, h, model,			     ((int[]) pixels), off, pixelscan);	    }	}    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -