⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 moviebuilder.java

📁 java版本的flash文件(swf)播放器
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/****************************************************************
 * Copyright (c) 2001, David N. Main, All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or
 * without modification, are permitted provided that the 
 * following conditions are met:
 *
 * 1. Redistributions of source code must retain the above 
 * copyright notice, this list of conditions and the following 
 * disclaimer. 
 * 
 * 2. Redistributions in binary form must reproduce the above 
 * copyright notice, this list of conditions and the following 
 * disclaimer in the documentation and/or other materials 
 * provided with the distribution.
 * 
 * 3. The name of the author may not be used to endorse or 
 * promote products derived from this software without specific 
 * prior written permission. 
 * 
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY 
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 
 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
 * AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 
 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 ****************************************************************/
package com.anotherbigidea.flash.readers;

import java.util.*;
import java.io.*;
import com.anotherbigidea.flash.*;
import com.anotherbigidea.flash.interfaces.*;
import com.anotherbigidea.flash.writers.*;
import com.anotherbigidea.flash.structs.*;
import com.anotherbigidea.flash.movie.*;

/**
 * An implementation of the SWFTagTypes interface that builds a Movie object
 */
public class MovieBuilder implements SWFTagTypes 
{
    protected Movie   movie;
    protected MovieClip clip;
    protected boolean newMovie = false;
    protected Frame   frame;
    protected Map     symbols = new HashMap();
    protected TimeLine timeline;
    protected Map     instances = new HashMap();
    
    /**
     * Build a new Movie
     */
    public MovieBuilder()
    {
        movie = new Movie();
        newMovie = true;
        timeline = movie;
    }
    
    /**
     * Append to an existing movie (do not change size,rate,color,version etc)
     */
    public MovieBuilder( Movie movie )
    {
        this.movie = movie;
        newMovie = false;
        timeline = movie;
    }
    
    /**
     * Build the timeline of a MovieClip
     */
    protected MovieBuilder( MovieBuilder parent, MovieClip clip )
    {
        this.movie     = parent.movie;
        this.symbols   = parent.symbols;
        this.clip      = clip;
        newMovie       = false;
        timeline       = clip;
    }    
    
    public Movie getMovie() { return movie; }
    
    /**
     * Get the defined symbols - keyed by Integer( symbolId )
     */
    public Map getDefinedSymbols() { return symbols; }
    
    protected Symbol getSymbol( int id )
    {
        return (Symbol)symbols.get( new Integer( id ) );        
    }
    
    protected void saveSymbol( int id, Symbol s )
    {
        symbols.put( new Integer(id), s );
    }

    protected Instance getInstance( int depth )
    {
        return (Instance)instances.get( new Integer( depth ) );        
    }
    
    protected void saveInstance( int depth, Instance inst )
    {
        if( inst == null )
        {
            try{ throw new Exception();  }
            catch( Exception ex ) { ex.printStackTrace(); }
        }
        instances.put( new Integer(depth), inst );
    }    
    
    /**
     * SWFTags interface
     */    
    public void tag( int tagType, boolean longTag, byte[] contents ) 
        throws IOException
    {
        //ignore unknown tags
    }

    /**
     * SWFHeader interface.
     */
    public void header( int version, long length,
                        int twipsWidth, int twipsHeight,
                        int frameRate, int frameCount ) throws IOException
    {
        if( newMovie )
        {
            movie.setVersion( version );
            movie.setWidth( twipsWidth / SWFConstants.TWIPS );
            movie.setHeight( twipsHeight / SWFConstants.TWIPS );
            movie.setFrameRate( frameRate );
        }
    }
    
    /**
     * SWFTagTypes interface
     */
    public void tagEnd() throws IOException
    {
        //nothing to do
    }

    /**
     * SWFTagTypes interface
     */
    public void tagShowFrame() throws IOException
    {
        //--complete the current frame
        if( frame == null ) timeline.appendFrame();
        else frame = null;
    }
    
    protected Frame currentFrame()
    {
        if( frame == null ) frame = timeline.appendFrame();            
        return frame;
    }
    
    //--Tags yet to be implemented...
    public void tagDefineSound( int id, int format, int frequency,
                                boolean bits16, boolean stereo,
                                int sampleCount, byte[] soundData ) 
        throws IOException {}
    public void tagDefineButtonSound( int buttonId,
                    int rollOverSoundId, SoundInfo rollOverSoundInfo,
                    int rollOutSoundId,  SoundInfo rollOutSoundInfo,
                    int pressSoundId,    SoundInfo pressSoundInfo,
                    int releaseSoundId,  SoundInfo releaseSoundInfo )
        throws IOException {}
    public void tagStartSound( int soundId, SoundInfo info ) throws IOException {}
    public void tagSoundStreamHead( 
        int playbackFrequency, boolean playback16bit, boolean playbackStereo,
        int streamFormat, int streamFrequency, boolean stream16bit, boolean streamStereo,
        int averageSampleCount ) throws IOException {}
    public void tagSoundStreamHead2( 
        int playbackFrequency, boolean playback16bit, boolean playbackStereo,
        int streamFormat, int streamFrequency, boolean stream16bit, boolean streamStereo,
        int averageSampleCount ) throws IOException {}
    public void tagSoundStreamBlock( byte[] soundData ) throws IOException {}
    public void tagSerialNumber( String serialNumber ) throws IOException {}
    public void tagGenerator( byte[] data ) throws IOException {}
    public void tagGeneratorText( byte[] data ) throws IOException {}
    public void tagGeneratorCommand( byte[] data ) throws IOException {}
    public void tagGeneratorFont( byte[] data ) throws IOException {}
    public void tagNameCharacter( byte[] data ) throws IOException {}
    public void tagDefineBits( int id, byte[] imageData ) throws IOException {}
    public void tagJPEGTables( byte[] jpegEncodingData ) throws IOException {}
    public void tagDefineBitsJPEG3( int id, byte[] imageData, byte[] alphaData ) throws IOException {}
	public SWFActions tagDoInitAction( int spriteId ) throws IOException { return null; }
    
    
    /**
     * SWFTagTypes interface
     */
    public SWFActions tagDoAction() throws IOException
    {
        Actions acts = currentFrame().actions( movie.getVersion() );
        
        return acts;
    }
    
    /**
     * SWFTagTypes interface
     */
    public SWFShape tagDefineShape( int id, Rect outline ) throws IOException
    {
        Shape s = new Shape();
        s.setBoundingRectangle( ((double)outline.getMinX()) / SWFConstants.TWIPS,
                                ((double)outline.getMinY()) / SWFConstants.TWIPS,
                                ((double)outline.getMaxX()) / SWFConstants.TWIPS,
                                ((double)outline.getMaxY()) / SWFConstants.TWIPS );
        
        saveSymbol( id, s );
        
        return new ShapeBuilder( s );
    }
    
    /**
     * SWFTagTypes interface
     */
    public SWFShape tagDefineShape2( int id, Rect outline ) throws IOException
    {
        Shape s = new Shape();
        s.setBoundingRectangle( ((double)outline.getMinX()) / SWFConstants.TWIPS,
                                ((double)outline.getMinY()) / SWFConstants.TWIPS,
                                ((double)outline.getMaxX()) / SWFConstants.TWIPS,
                                ((double)outline.getMaxY()) / SWFConstants.TWIPS );
        
        saveSymbol( id, s );
        
        return new ShapeBuilder( s );
    }
    
    /**
     * SWFTagTypes interface
     */
    public SWFShape tagDefineShape3( int id, Rect outline ) throws IOException
    {
        Shape s = new Shape();
        s.setBoundingRectangle( ((double)outline.getMinX()) / SWFConstants.TWIPS,
                                ((double)outline.getMinY()) / SWFConstants.TWIPS,
                                ((double)outline.getMaxX()) / SWFConstants.TWIPS,
                                ((double)outline.getMaxY()) / SWFConstants.TWIPS );
        
        saveSymbol( id, s );
        
        return new ShapeBuilder( s );
    }    
    
    /**
     * SWFTagTypes interface
     */    
    public void tagFreeCharacter( int charId ) throws IOException 
    {
        //nothing
    }
    
    /**
     * SWFTagTypes interface
     */    
    public void tagPlaceObject( int charId, int depth, 
                                Matrix matrix, AlphaTransform cxform ) 
        throws IOException
    {
        Symbol s = getSymbol( charId );
        if( s == null ) return;
                
        timeline.setAvailableDepth( depth );
        Instance inst = currentFrame().placeSymbol( s, ( matrix != null ) ? new Transform(matrix): null, cxform );
        saveInstance( depth, inst );
    }
    
    /**
     * SWFTagTypes interface
     */    
    public SWFActions tagPlaceObject2( boolean isMove,
                                       int clipDepth,
                                       int depth,
                                       int charId,
                                       Matrix matrix,
                                       AlphaTransform cxform,
                                       int ratio,
                                       String name,
                                       int clipActionFlags )  
        throws IOException    
    {
        Instance inst = null;
            
        if( depth == 59 )                 
        {
            //System.out.println( "Place2: " + charId + " isMove=" + isMove + " depth=" + depth + " frame=" + currentFrame().getFrameNumber() );
        }
        
        if( isMove && charId <= 0 )
        {
            inst = getInstance( depth );
            if( inst == null )
            {                
                System.out.println( "Failed to find Instance at depth " + depth );
                return null;
            }
            
            currentFrame().alter( inst, ( matrix != null ) ? new Transform(matrix): null, cxform, ratio );
        }
        else
        {
            Symbol s = getSymbol( charId );

            if( depth == 59 )                 
            {
                //System.out.println( ">>> " + s );
            }
                       
            if( s == null )
            {
                System.out.println( "Failed to find Symbol with id " + charId );
                return null;
            }
                
            if( name != null )
            {                
                Frame frame = currentFrame();
                
                if( isMove )
                {
                    inst = frame.replaceMovieClip( s, depth, ( matrix != null ) ? new Transform(matrix): null, 
                                                   cxform, name, null );
                }
                else
                {
                    timeline.setAvailableDepth( depth );

                    inst = frame.placeMovieClip( s, ( matrix != null ) ? new Transform(matrix): null, 
                                                   cxform, name, null );
                }
                
                saveInstance( depth, inst );                
            }
            else if( clipActionFlags != 0 )
            {
                return new ClipActionBuilder( s, matrix, cxform, depth, name, 
                                              movie.getVersion(), isMove );
            }
            else
            {
                Frame frame = currentFrame();
                
                if( isMove )
                {
                    inst = frame.replaceSymbol( s, depth, ( matrix != null ) ? new Transform(matrix): null, 
                                                   cxform, ratio, clipDepth );
                }
                else
                {
                    timeline.setAvailableDepth( depth );

                    inst = frame.placeSymbol( s, ( matrix != null ) ? new Transform(matrix): null, 
                                                   cxform, ratio, clipDepth );
                }

                saveInstance( depth, inst );
            }
        }        
        
        return null;
    }
        
    /**
     * SWFTagTypes interface
     */ 
    public void tagRemoveObject( int charId, int depth ) throws IOException
    {     
        Instance inst = getInstance( depth );
        if( inst == null ) return;
        
        currentFrame().remove( inst );
    }
        
    /**
     * SWFTagTypes interface
     */ 
    public void tagRemoveObject2( int depth ) throws IOException
    {        
        Instance inst = getInstance( depth );
        if( inst == null ) return;
        
        currentFrame().remove( inst );
    }

    /**
     * SWFTagTypes interface
     */ 
    public void tagSetBackgroundColor( Color color ) throws IOException
    {
        if( newMovie ) movie.setBackColor( color );      
    }

    /**
     * SWFTagTypes interface
     */ 
    public void tagFrameLabel( String label ) throws IOException
    {
		tagFrameLabel( label, false );
    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -