/* * com.fc.vrml.image.ExternalSFImageObserver * * Copyright (c) 1996-1998 Finlayson Consulting (FC). All Rights Reserved. * * FC grants you ("Licensee") a non-exclusive, royalty free, license to use, * modify and redistribute this software in source and binary code form, * provided that i) this copyright notice and license appear on all copies of * the software; and ii) this software is not reverse engineereed without written * consent. * * This software is provided "AS IS," without a warranty of any kind. ALL * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. FC AND ITS LICENSORS SHALL NOT BE * LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL FC OR ITS * LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF * OR INABILITY TO USE SOFTWARE, EVEN IF FC HAS BEEN ADVISED OF THE * POSSIBILITY OF SUCH DAMAGES. * * This software is not designed or intended for use in on-line control of * aircraft, air traffic, aircraft navigation or aircraft communications; or in * the design, construction, operation or maintenance of any nuclear * facility. Licensee represents and warrants that it will not use or * redistribute the Software for such purposes. * */ package com.fc.vrml.image; import vrml.field.ConstSFImage; import vrml.external.field.EventInSFImage; import java.util.Observer; import java.util.Observable; /** * * This is for use with EAI. * The ExternalSFImageObserver is constructed with an vrml.external.field.EventInSFImage. *
* The ExternalSFImageObserver extends the Observer object. It is registered with an SFImageConverter. *
* When the update method is called the EventInSFImage is set to the values of the SFImage data of the * getExternalSFImage() method of the SFImageConverter cast from Observable if the image status is * ImageConsumer.SINGLEFRAMEDONE or ImageConsumer.STATICIMAGEDONE. *
* * Here is some example code, an Applet that gets a PixelTexture node from a VRML World and sets * it's image to one loaded through the Applet. * *
* #VRML V2.0 utf8
* Group{
* children[
* Shape{
* appearance Appearance{
* texture DEF PIXELTEXTURE PixelTexture{}
* }
* geometry Box{}
* }
* ]
* }
*
* * import vrml.external.*; * import vrml.external.field.*; * import com.fc.vrml.image.*; * import java.applet.Applet; * import java.awt.Image; **
* public class ImageLoaderApplet extends Applet{
*
* private Browser browser;
*
* public void start(){
* browser=Browser.getBrowser(this);
* Node node=browser.getNode("PIXELTEXTURE");
* EventInSFImage sfimage=(EventInSFImage)node.getEventIn("set_image");
* ExternalSFImageObserver observer=new ExternalSFImageObserver(sfimage);
* Image image=getImage(getDocumentBase(), "image.gif");
* SFImageConverter converter=new SFImageConverter(3);
* converter.addObserver(observer);
* converter.loadImage(image);
* }
* }
*
* @see com.fc.vrml.image.SFImageConverter
* @version 0.5
* @author Ross A. Finlayson
* @author FC VRML Group
*/
public class ExternalSFImageObserver implements Observer{
EventInSFImage _sfimage;
/**
* @param sfimage EventInSFImage to be set with image data when notified
*/
public ExternalSFImageObserver(EventInSFImage sfimage){
_sfimage=sfimage;
}
/**
* This method is called by the Observable that has been registered with this upon load notification.
* If the image status is SINGLEFRAMEDONE or STATICIMAGEDONE it sets the value of this ExternalSFImageObserver's
* EventInSFImage to the value of the SFImage data of the result of the getExternalSFImage()
* call to the SFImageConverter cast to Observable.
*/
public void update(Observable o, Object arg){
if ( ((Integer)arg).intValue()==1) return;
if ( ((Integer)arg).intValue()==4) return;
ExternalSFImage sfimagedata=((SFImageConverter)o).getExternalSFImage();
_sfimage.setValue(sfimagedata.getWidth(), sfimagedata.getHeight(), sfimagedata.getComponents(), sfimagedata.getPixels());
}
}