001: /*
002: * $Id: DepsCollector.java,v 1.3 2002/07/03 23:03:44 skavish Exp $
003: *
004: * ===========================================================================
005: *
006: * The JGenerator Software License, Version 1.0
007: *
008: * Copyright (c) 2000 Dmitry Skavish (skavish@usa.net). All rights reserved.
009: *
010: * Redistribution and use in source and binary forms, with or without
011: * modification, are permitted provided that the following conditions are met:
012: *
013: * 1. Redistributions of source code must retain the above copyright
014: * notice, this list of conditions and the following disclaimer.
015: *
016: * 2. Redistributions in binary form must reproduce the above copyright
017: * notice, this list of conditions and the following disclaimer in
018: * the documentation and/or other materials provided with the
019: * distribution.
020: *
021: * 3. The end-user documentation included with the redistribution, if
022: * any, must include the following acknowlegement:
023: * "This product includes software developed by Dmitry Skavish
024: * (skavish@usa.net, http://www.flashgap.com/)."
025: * Alternately, this acknowlegement may appear in the software itself,
026: * if and wherever such third-party acknowlegements normally appear.
027: *
028: * 4. The name "The JGenerator" must not be used to endorse or promote
029: * products derived from this software without prior written permission.
030: * For written permission, please contact skavish@usa.net.
031: *
032: * 5. Products derived from this software may not be called "The JGenerator"
033: * nor may "The JGenerator" appear in their names without prior written
034: * permission of Dmitry Skavish.
035: *
036: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
037: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
038: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
039: * DISCLAIMED. IN NO EVENT SHALL DMITRY SKAVISH OR THE OTHER
040: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
041: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
042: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
043: * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
044: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
045: * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
046: * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
047: * SUCH DAMAGE.
048: *
049: */
050:
051: package org.openlaszlo.iv.flash.util;
052:
053: import java.util.*;
054: import org.openlaszlo.iv.flash.api.*;
055: import org.openlaszlo.iv.flash.api.text.*;
056:
057: /**
058: * This class serves as storage for collecting an flash object's dependencies.<P>
059: * Some flash objects depends on others. For example Button depends on
060: * shapes and/or sounds. PlaceObject depends on corresponding
061: * flash definition etc. According to flash file format all dependencies
062: * have to be placed in the file before the object itself.
063: * This class helps in accomplishing this task.
064: *
065: * @author Dmitry Skavish
066: * @see FontsCollector
067: */
068: public final class DepsCollector {
069:
070: protected Hashtable allGenerated = new Hashtable();
071: protected IVVector collected = new IVVector(20);
072: //protected IVVector[] collected = new IVVector[20];
073: protected int current = -1;
074: protected IVVector fonts;
075:
076: /**
077: * Creates collector from {@link FontsCollector}.
078: *
079: * @param fc fonts collector
080: */
081: public DepsCollector(FontsCollector fc) {
082: fonts = fc.getFonts();
083: //for( int i=0; i<collected.length; i++ ) collected[i] = new IVVector();
084: }
085:
086: /**
087: * Collects flash item
088: *
089: * @param item item to collect
090: */
091: public void addDep(FlashItem item) {
092: getLevel(current).addElement(item);
093: }
094:
095: /**
096: * Returns true if specified item has been generated
097: *
098: * @param item item to be checked as generated
099: * @return true if specified item has been generated
100: */
101: public boolean isGenerated(FlashItem item) {
102: return allGenerated.containsKey(item);
103: }
104:
105: /**
106: * Adds specified item to the list of generated item
107: *
108: * @param item item to be added as generated
109: */
110: public void addGenerated(FlashItem item) {
111: allGenerated.put(item, item);
112: }
113:
114: /**
115: * Collects specified font.<p>
116: * Check for given {@link Font} if there is corresponding
117: * {@link FontDef} already collected, if not then collect this font as well.
118: *
119: * @param font font to collect
120: */
121: public void addDep(Font font) {
122: for (int i = 0; i < fonts.size(); i++) {
123: FontDef fdef = (FontDef) fonts.elementAt(i);
124: if (fdef.getFont() == font) {
125: addDep(fdef);
126: return;
127: }
128: }
129: }
130:
131: /**
132: * Starts next level of collection.
133: */
134: public void startCollect() {
135: getLevel(++current).reset();
136: //for( int i=0; i<current; i++ ) System.out.print( " " );
137: //System.out.println( "start collect: current="+current );
138: }
139:
140: /**
141: * Stops current collection level.
142: */
143: public void endCollect() {
144: //for( int i=0; i<current; i++ ) System.out.print( " " );
145: --current;
146: //System.out.println( "end collect: current="+current );
147: }
148:
149: /**
150: * Returns collected objects.
151: *
152: * @return vector of all objects collected on current level
153: */
154: public IVVector getCollected() {
155: return getLevel(current);
156: }
157:
158: private IVVector getLevel(int num) {
159: IVVector level;
160: if (num >= collected.size()) {
161: level = new IVVector();
162: collected.setElementAt(level, num);
163: } else {
164: level = (IVVector) collected.elementAt(num);
165: if (level == null) {
166: level = new IVVector();
167: collected.setElementAt(level, num);
168: }
169: }
170: return level;
171: }
172:
173: }
|