/* * com.fc.vrml.image.SFImageObserver * * 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.SFImage; import vrml.field.ConstSFImage; import java.util.Observer; import java.util.Observable; /** * * This is for use in VRML 2.0 Script node. It conforms to VRML97 Annex B. The SFImageObserver is constructed with a vrml.field.SFImage. *
* The SFImageObserver extends the Observer object. It is registered with an SFImageConverter. *
* When the update method is called the SFImage 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 an example script and VRML code. An SFImageConverter loads the image, and when it is loaded sets the PixelTexture. *
* #VRML V2.0 utf8
*
* DEF S Script{
* eventOut SFImage image_changed
* url "ImageLoaderScript.class"
* }
*
* Shape{
* appearance Appearance{
* texture DEF T PixelTexture{}
* }
* geometry Box{}
* }
*
* ROUTE S.image_changed TO T.set_image
*
*
* * * import vrml.*; * import vrml.field.*; * import com.fc.vrml.image.*; * import java.net.*; * import java.awt.*; * **
*
* public class ImageLoaderScript extends Script{
* public void initialize(){
* SFImage sfimage=(SFImage)getEventOut("image_changed");
* try{
* URL url=new URL("http://www.foo.org/graphic.gif");
* Image image=Toolkit.getDefaultToolkit().getImage(url);
* SFImageConverter converter=new SFImageConverter();
* SFImageObserver observer=new SFImageObserver(sfimage);
* converter.addObserver(observer);
* image.getSource().startProduction(converter);
* } catch (MalformedURLException mue){}
* }
* }
*
* @see com.fc.vrml.image.SFImageConverter
* @version 0.5
* @author Ross A. Finlayson
* @author FC VRML Group
*/
public class SFImageObserver implements Observer{
private SFImage _sfimage;
public SFImageObserver(SFImage sfimage){
_sfimage=sfimage;
}
/**
* This method is called by the Observable that has been registered with this upon load notification.
* It sets the value of this SFImageObserver's SFImage 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());
}
}