Source code: com/anotherbigidea/flash/movie/Symbol.java
1 /****************************************************************
2 * Copyright (c) 2001, David N. Main, All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or
5 * without modification, are permitted provided that the
6 * following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above
9 * copyright notice, this list of conditions and the following
10 * disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above
13 * copyright notice, this list of conditions and the following
14 * disclaimer in the documentation and/or other materials
15 * provided with the distribution.
16 *
17 * 3. The name of the author may not be used to endorse or
18 * promote products derived from this software without specific
19 * prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY
22 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
23 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
24 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
31 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
32 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 ****************************************************************/
34 package com.anotherbigidea.flash.movie;
35
36 import java.io.*;
37 import java.util.*;
38 import com.anotherbigidea.flash.interfaces.*;
39 import com.anotherbigidea.flash.writers.*;
40 import com.anotherbigidea.flash.readers.*;
41 import com.anotherbigidea.flash.structs.*;
42
43 /**
44 * Base class for all defined symbols
45 */
46 public abstract class Symbol
47 {
48 protected int id = 0;
49
50 protected Symbol() {}
51
52 protected Symbol( int id )
53 {
54 this.id = id;
55 }
56
57 /**
58 * Get the internal SWF id for the symbol. This will always be
59 * zero for a Movie that was not loaded from an existing SWF until
60 * the Movie is written out.
61 */
62 public int getId() { return id; }
63
64 /**
65 * Make sure that the Symbol is fully defined in the given Movie and
66 * return the character id
67 * @param tags a vector into which to place any definition tags required
68 */
69 protected int define( Movie movie,
70 SWFTagTypes timelineWriter,
71 SWFTagTypes definitionWriter )
72 throws IOException
73 {
74 Integer integerId = (Integer)movie.definedSymbols.get( this );
75
76 if( integerId == null )
77 {
78 integerId = new Integer( defineSymbol( movie,
79 timelineWriter,
80 definitionWriter ) );
81 movie.definedSymbols.put( this, integerId );
82 }
83
84 id = integerId.intValue();
85 return id;
86 }
87
88 protected int getNextId( Movie movie )
89 {
90 return movie.maxId++;
91 }
92
93 /**
94 * Override to provide symbol definition
95 * @return the new symbol id
96 */
97 protected abstract int defineSymbol( Movie movie,
98 SWFTagTypes timelineWriter,
99 SWFTagTypes definitionwriter )
100 throws IOException;
101 }