1 /* 2 * $RCSfile: RasterState.java,v $ 3 * 4 * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 10 * - Redistribution of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 13 * - Redistribution in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in 15 * the documentation and/or other materials provided with the 16 * distribution. 17 * 18 * Neither the name of Sun Microsystems, Inc. or the names of 19 * contributors may be used to endorse or promote products derived 20 * from this software without specific prior written permission. 21 * 22 * This software is provided "AS IS," without a warranty of any 23 * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND 24 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, 25 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY 26 * EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL 27 * NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF 28 * USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS 29 * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR 30 * ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, 31 * CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND 32 * REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF OR 33 * INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE 34 * POSSIBILITY OF SUCH DAMAGES. 35 * 36 * You acknowledge that this software is not designed, licensed or 37 * intended for use in the design, construction, operation or 38 * maintenance of any nuclear facility. 39 * 40 * $Revision: 1.4 $ 41 * $Date: 2007/02/09 17:20:38 $ 42 * $State: Exp $ 43 */ 44 45 package com.sun.j3d.utils.scenegraph.io.state.javax.media.j3d; 46 47 import java.io.IOException; 48 import java.io.DataInput; 49 import java.io.DataOutput; 50 import javax.media.j3d.Raster; 51 import javax.media.j3d.SceneGraphObject; 52 import com.sun.j3d.utils.scenegraph.io.retained.Controller; 53 import com.sun.j3d.utils.scenegraph.io.retained.SymbolTableData; 54 import java.awt.Point; 55 import javax.vecmath.Point3f; 56 import java.awt.Dimension; 57 import javax.media.j3d.ImageComponent2D; 58 import javax.media.j3d.DepthComponent; 59 60 public class RasterState extends GeometryState { 61 62 int image; 63 int depthComponent; 64 RasterState(SymbolTableData symbol,Controller control)65 public RasterState(SymbolTableData symbol,Controller control) { 66 super( symbol, control ); 67 68 // Set up references during save 69 if ( node!=null ) { 70 image = control.getSymbolTable().addReference( ((Raster)node).getImage() ); 71 depthComponent = 72 control.getSymbolTable().addReference( ((Raster)node).getDepthComponent() ); 73 } 74 } 75 writeObject( DataOutput out )76 public void writeObject( DataOutput out ) throws IOException { 77 super.writeObject( out ); 78 79 out.writeInt( image ); 80 out.writeInt( depthComponent ); 81 82 Point3f pos = new Point3f(); 83 ((Raster)node).getPosition( pos ); 84 control.writePoint3f( out, pos ); 85 86 out.writeInt( ((Raster)node).getType() ); 87 out.writeInt( ((Raster)node).getClipMode() ); 88 89 Point offset = new Point(); 90 ((Raster)node).getSrcOffset( offset ); 91 out.writeInt( offset.x ); 92 out.writeInt( offset.y ); 93 94 Dimension size = new Dimension(); 95 ((Raster)node).getSize( size ); 96 out.writeInt( size.width ); 97 out.writeInt( size.height ); 98 99 ((Raster)node).getDstOffset( offset ); 100 out.writeInt( offset.x ); 101 out.writeInt( offset.y ); 102 } 103 readObject( DataInput in )104 public void readObject( DataInput in ) throws IOException { 105 super.readObject( in ); 106 107 image = in.readInt(); 108 depthComponent = in.readInt(); 109 110 ((Raster)node).setPosition( control.readPoint3f( in ) ); 111 ((Raster)node).setType( in.readInt() ); 112 ((Raster)node).setClipMode( in.readInt() ); 113 ((Raster)node).setSrcOffset( new Point( in.readInt(), in.readInt() ) ); 114 ((Raster)node).setSize( new Dimension( in.readInt(), in.readInt() ) ); 115 ((Raster)node).setDstOffset( new Point( in.readInt(), in.readInt() ) ); 116 } 117 118 /** 119 * Called when this component reference count is incremented. 120 * Allows this component to update the reference count of any components 121 * that it references. 122 */ addSubReference()123 public void addSubReference() { 124 control.getSymbolTable().incNodeComponentRefCount( image ); 125 control.getSymbolTable().incNodeComponentRefCount( depthComponent ); 126 } 127 128 // Set up references during load buildGraph()129 public void buildGraph() { 130 ((Raster)node).setImage( (ImageComponent2D)control.getSymbolTable().getJ3dNode( image ) ); 131 ((Raster)node).setDepthComponent( 132 (DepthComponent)control.getSymbolTable().getJ3dNode( depthComponent ) ); 133 super.buildGraph(); // Must be last call in method 134 } 135 createNode()136 protected javax.media.j3d.SceneGraphObject createNode() { 137 return new Raster(); 138 } 139 } 140