1 // 2 // Description: 3 // SWFObject Class 4 // 5 // Authors: 6 // Jonathan Shore <jshore@e-shuppan.com> 7 // Based on php wrapper developed by <dave@opaque.net> 8 // 9 // Copyright: 10 // Copyright 2001 E-Publishing Group Inc. Permission is granted to use or 11 // modify this code provided that the original copyright notice is included. 12 // 13 // This software is distributed with no warranty of liability, merchantability, 14 // or fitness for a specific purpose. 15 // 16 17 18 19 20 import java.util.Hashtable; 21 import java.util.Vector; 22 23 24 25 26 // 27 // SWFObject Class 28 // base object for all swf-entities 29 // 30 // Notes 31 // - keeps underlying SWF entity handle, and adjustments 32 // 33 // - a translation / rotation / skew matrix is kept so that objects can 34 // be created with specific offset, rotation, etc 35 // 36 // - eval() is provided so that the object can be adjusted or rendered just 37 // prior to being added to a parent container (as in MC.add(object)) 38 // 39 public class SWFObject implements SWFObjectI { 40 SWFObject()41 public SWFObject () 42 throws SWFException 43 { 44 initialize(); 45 this.handle = 0; 46 this.matrix = null; 47 this.props = null; 48 this.preserve = null; 49 } 50 SWFObject(int handle)51 public SWFObject (int handle) 52 throws SWFException 53 { 54 initialize(); 55 this.handle = handle; 56 this.matrix = null; 57 this.props = null; 58 this.preserve = null; 59 } 60 61 62 // handle functions 63 getHandle()64 public int getHandle() 65 { return handle; } 66 setHandle(int handle)67 public void setHandle(int handle) 68 { this.handle = handle; } 69 70 71 // intializer function 72 eval()73 public void eval() throws SWFException 74 { } 75 76 77 // matrix functions 78 setMatrix(SWFMatrix matrix)79 public void setMatrix (SWFMatrix matrix) 80 { 81 this.matrix = matrix; 82 } 83 getMatrix()84 public SWFMatrix getMatrix () 85 { 86 if (matrix == null) 87 return SWFMatrix.identity(); 88 else 89 return matrix; 90 } 91 92 93 // property functions 94 getProperty(String name)95 public Object getProperty (String name) 96 throws SWFException 97 { 98 if (props == null) 99 throw new SWFException ("SWFObject::getProperty: no properties, trying: " + name); 100 else 101 return props.get (name); 102 } 103 setProperty(String name, Object value)104 public void setProperty (String name, Object value) 105 { 106 if (props == null) 107 props = new Hashtable(); 108 109 props.put (name, value); 110 } 111 112 getFloatProperty(String name)113 public float getFloatProperty (String name) 114 throws SWFException 115 { 116 Object o = getProperty (name); 117 if (o == null) 118 throw new SWFException ("SWFObject::getProperty: unknown property: " + name); 119 else 120 return ((Float)o).floatValue(); 121 } 122 123 setFloatProperty(String name, float v)124 public void setFloatProperty (String name, float v) 125 { 126 setProperty (name, new Float (v)); 127 } 128 129 130 131 // initializer & GC related 132 initialize()133 public static synchronized void initialize () 134 throws SWFException 135 { 136 if (initialized) 137 return; 138 else 139 initialized = true; 140 141 try 142 { System.loadLibrary ("jswf"); } 143 144 catch (UnsatisfiedLinkError e) 145 { 146 System.out.println(e.toString()); 147 String msg = e.getMessage(); 148 if (msg.indexOf ("already loaded") < 0) 149 throw new SWFException ("native loading: " + msg); 150 } 151 } 152 153 preserve(SWFObjectI obj)154 public void preserve (SWFObjectI obj) 155 { 156 if (preserve == null) 157 preserve = new Vector(); 158 preserve.add (obj); 159 } 160 161 162 // variables 163 164 protected int handle; 165 protected SWFMatrix matrix; 166 protected Hashtable props; 167 protected Vector preserve; 168 169 protected static boolean initialized = false; 170 }; 171