File: SWFObject.java

package info (click to toggle)
libming 0.2a.cvs20020110-1
  • links: PTS
  • area: main
  • in suites: woody
  • size: 2,204 kB
  • ctags: 4,173
  • sloc: ansic: 19,467; yacc: 2,149; cpp: 1,518; java: 1,253; ruby: 516; perl: 462; python: 436; makefile: 295; sh: 4
file content (172 lines) | stat: -rw-r--r-- 3,349 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
//
// Description:
//    SWFObject Class
//
// Authors:
//    Jonathan Shore <jshore@e-shuppan.com>
//    Based on php wrapper developed by <dave@opaque.net>
//
// Copyright:
//    Copyright 2001 E-Publishing Group Inc.  Permission is granted to use or
//    modify this code provided that the original copyright notice is included.
//
//    This software is distributed with no warranty of liability, merchantability,
//    or fitness for a specific purpose.
//



import SWFException;
import SWFObjectI;
import SWFMatrix;

import java.util.Hashtable;
import java.util.Vector;




//
//  SWFObject Class
//      base object for all swf-entities
//
//  Notes
//    - keeps underlying SWF entity handle, and adjustments
//
//    - a translation / rotation / skew matrix is kept so that objects can
//	be created with specific offset, rotation, etc
//
//    - eval() is provided so that the object can be adjusted or rendered just
//	prior to being added to a parent container (as in MC.add(object))
//
public class SWFObject implements SWFObjectI {

    public SWFObject ()
	throws SWFException
    {
	initialize();
	this.handle = 0;
	this.matrix = null;
	this.props = null;
	this.preserve = null;
    }

    public SWFObject (int handle)
	throws SWFException
    {
	initialize();
	this.handle = handle;
	this.matrix = null;
	this.props = null;
	this.preserve = null;
    }


    // handle functions

    public int getHandle()
        { return handle; }

    public void	setHandle(int handle)
        { this.handle = handle; }


    // intializer function

    public void eval() throws SWFException
        { }


    // matrix functions

    public void setMatrix (SWFMatrix matrix)
    { 
	this.matrix = matrix; 
    }

    public SWFMatrix getMatrix ()
    {
	if (matrix == null)
	    return SWFMatrix.identity();
	else
	    return matrix;
    }


    // property functions

    public Object getProperty (String name)
	throws SWFException
    {
	if (props == null)
	    throw new SWFException ("SWFObject::getProperty: no properties, trying: " + name);
	else
	    return props.get (name);
    }

    public void setProperty (String name, Object value)
    {
	if (props == null)
	    props = new Hashtable();

	props.put (name, value);
    }

    
    public float getFloatProperty (String name)
	throws SWFException
    {
	Object o = getProperty (name);
	if (o == null)
	    throw new SWFException ("SWFObject::getProperty: unknown property: " + name);
	else
	    return ((Float)o).floatValue();
    }

    
    public void setFloatProperty (String name, float v)
    {
	setProperty (name, new Float (v));
    }
	


    // initializer & GC related

    public static synchronized void initialize ()
	throws SWFException
    {
	if (initialized) 
	    return;
	else
	    initialized = true;

	try
            { System.loadLibrary ("jswf"); }

	catch (UnsatisfiedLinkError e)
	{
	    String msg = e.getMessage();
	    if (msg.indexOf ("already loaded") < 0)
		throw new SWFException ("native loading: " + msg);
	}
    }


    public void preserve (SWFObjectI obj)
    {
	if (preserve == null)
	    preserve = new Vector();
	preserve.add (obj);
    }


    // variables

    protected int		handle;
    protected SWFMatrix		matrix;
    protected Hashtable		props;
    protected Vector		preserve;

    protected static boolean	initialized = false;
};