Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/anotherbigidea/flash/movie/Button.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   * A Button Symbol
45   */
46  public class Button extends Symbol
47  {
48      /**
49       * A layer of a button.  The layer defines a symbol (Shape etc.) with
50       * associated Transform and color transform.  There may be many layers
51       * in a button and each layer may take part in one or more of the 4 button
52       * states (up,over,down,hit-test).
53       */
54      public static class Layer
55      {
56          protected Symbol symbol;
57          protected Transform matrix;
58          protected AlphaTransform cxform;
59          protected int depth;
60          protected boolean usedForHitArea, usedForUp, usedForDown, usedForOver;
61                            
62          public Symbol         getSymbol()    { return symbol; }
63          public Transform      getTransform() { return matrix; }
64          public AlphaTransform getColoring()  { return cxform; }
65          public int            getDepth()     { return depth;  }
66          public boolean isUsedForHitArea() { return usedForHitArea; }
67          public boolean isUsedForUp()      { return usedForUp; }
68          public boolean isUsedForDown()    { return usedForDown; }
69          public boolean isUsedForOver()    { return usedForOver; }
70  
71          public void setSymbol     ( Symbol symbol )         { this.symbol = symbol; }
72          public void setTransform  ( Transform matrix )      { this.matrix = matrix; }
73          public void setColoring   ( AlphaTransform cxform ) { this.cxform = cxform; }
74          public void setDepth      ( int depth )             { this.depth  = depth;  }
75          public void usedForHitArea( boolean f ) { usedForHitArea = f; }
76          public void usedForUp     ( boolean f ) { usedForUp      = f; }
77          public void usedForDown   ( boolean f ) { usedForDown    = f; }
78          public void usedForOver   ( boolean f ) { usedForOver    = f; }        
79  
80          /**
81           * @param depth should be >= 1 and there should only be one symbol on any layer
82           */
83          public Layer( Symbol symbol, Transform matrix, AlphaTransform cxform,
84                        int depth, boolean usedForHitArea, boolean usedForUp, 
85                        boolean usedForDown, boolean usedForOver )
86          {
87              if( matrix == null ) matrix = new Transform();
88              if( cxform == null ) cxform = new AlphaTransform();
89              
90              this.symbol         = symbol;        
91              this.matrix         = matrix;       
92              this.cxform         = cxform;        
93              this.depth          = depth;         
94              this.usedForHitArea = usedForHitArea;
95              this.usedForUp      = usedForUp;     
96              this.usedForDown    = usedForDown;   
97              this.usedForOver    = usedForOver;          
98          }
99          
100         protected ButtonRecord2 getRecord( Movie movie, 
101                                            SWFTagTypes timelineWriter,
102                                            SWFTagTypes definitionWriter )
103             throws IOException 
104         {
105             //--Make sure symbol is defined
106             int symId = symbol.define( movie, timelineWriter, definitionWriter );
107             
108             int flags = 0;
109             if( usedForHitArea ) flags |= ButtonRecord.BUTTON_HITTEST;
110             if( usedForUp      ) flags |= ButtonRecord.BUTTON_UP; 
111             if( usedForDown    ) flags |= ButtonRecord.BUTTON_DOWN;
112             if( usedForOver    ) flags |= ButtonRecord.BUTTON_OVER;
113             
114             return new ButtonRecord2( symId, depth, matrix, cxform, flags );
115         }
116     }
117     
118     protected ArrayList actions = new ArrayList();
119     protected ArrayList layers = new ArrayList();    
120     protected boolean trackAsMenu;
121     
122     public Button( boolean trackAsMenu )
123     {
124         this.trackAsMenu = trackAsMenu;
125     }    
126     
127     public boolean isTrackedAsMenu()        { return trackAsMenu; }
128     public void    trackAsMenu( boolean f ) { trackAsMenu = f; }
129     
130     /**
131      * Access the list of Button.Layer objects
132      */
133     public ArrayList getButtonLayers() { return layers; }
134 
135     /**
136      * Access the list of Actions objects
137      */
138     public ArrayList getActions() { return actions; }
139         
140     /**
141      * Add a layer to the button.
142      * @param depth should be >= 1 and there should only be one symbol on any layer
143      */
144     public Button.Layer addLayer( Symbol symbol, Transform matrix, 
145                       AlphaTransform cxform,
146                       int depth, boolean usedForHitArea, boolean usedForUp, 
147                       boolean usedForDown, boolean usedForOver )
148     {
149         Layer layer = new Layer( symbol, matrix, cxform, depth,
150                                  usedForHitArea, usedForUp, usedForDown, usedForOver );
151         
152         layers.add( layer );
153         return layer;
154     }
155     
156     public Actions addActions( int conditionFlags, int flashVersion )
157     {
158         Actions acts = new Actions( conditionFlags, flashVersion );
159         actions.add( acts );
160         return acts;
161     }
162     
163     protected int defineSymbol( Movie movie, 
164                                 SWFTagTypes timelineWriter,
165                                 SWFTagTypes definitionWriter )
166         throws IOException
167     {
168         int id = getNextId( movie );
169         
170         Vector recs = new Vector();
171         for( Iterator it = layers.iterator(); it.hasNext(); )
172         {            
173             Layer layer = (Layer)it.next();
174             recs.addElement( layer.getRecord( movie, timelineWriter, definitionWriter ) );
175         }
176         
177         SWFActions acts = definitionWriter.tagDefineButton2( id, trackAsMenu, recs );
178         
179         for( Iterator it = actions.iterator(); it.hasNext(); )
180         {            
181             Actions actions = (Actions)it.next();
182             
183             acts.start( actions.getConditions());
184             acts.blob ( actions.bytes );
185         }
186         
187         acts.done();
188         
189         return id;
190     }
191 }