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

📄 actiontextwriter.java

📁 java和flash混合编程
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/****************************************************************
 * 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.writers;

import java.io.IOException;
import java.io.PrintWriter;

import com.anotherbigidea.flash.SWFActionCodes;
import com.anotherbigidea.flash.interfaces.SWFActions;
import com.anotherbigidea.flash.interfaces.SWFActionBlock;

/**
 * A writer that implements the SWFActions interface and writes
 * actions to a text format
 */
public class ActionTextWriter implements SWFActions, SWFActionBlock, SWFActionCodes 
{
    protected PrintWriter printer;
    protected int blockLevel = 0;
    protected String indent = "";
    protected String label = null;
    
    public static final String LABEL_ZONE = "      ";
    
    public ActionTextWriter( PrintWriter printer )
    {
        this.printer = printer;
    }

    public void indent() {
        indent += "    ";
    }
    
    public void unindent() {
        if( indent.length() < 4 ) indent = "";
        else indent = indent.substring( 0, indent.length() - 4 );
    }
    
    protected void print( String mnemonic, String[] args )
    {
        printer.print( "  " );
        if( label != null ) {
            printer.print( label + ":" + ((label.length() < 5) ?  LABEL_ZONE.substring( label.length() + 1 ) : " "));
            label = null;
        } else {
            printer.print( LABEL_ZONE );
        }
        
        printer.print( indent );
    	
    	if( mnemonic.equals( "{" ) ||  mnemonic.equals( "}" ) 
    	        || mnemonic.startsWith( "catch" )
    	        || mnemonic.startsWith( "finally" )) {
    		printer.println( mnemonic );
    		return;
    	}
    	        
        
        writePaddedString( mnemonic + " ", 15 );
        
        if( args != null )
        {
            for( int i = 0; i < args.length; i++ )
            {
                if( i > 0 ) printer.print( ", " );
                printer.print( args[i] );
            }
        }
        
        printer.println();
    }
    
    protected void writePaddedString( String s, int length )
    {
        int pad = length - s.length();
        
        printer.print( s );
        while( pad > 0 )
        {
            printer.print( " " );
            pad--;
        }
    }

    public SWFActionBlock start( int conditions ) throws IOException
    {
        print( "conditions", new String[] { Integer.toBinaryString( conditions ) } );
        printer.flush();
        return this;
    }
    
	public SWFActionBlock start( int conditions, int keycode ) throws IOException
	{
		print( "conditions", new String[] { Integer.toBinaryString( conditions ), "keycode = " + keycode } );
		printer.flush();
		return this;
	}    

	public void done() throws IOException
	{
	    printer.flush();
	}
	
    public void end() throws IOException
    {    	
    	if( blockLevel > 0 ) {
            unindent();
            print( "}", null );
            blockLevel--;
        } else {
            print( "end", null );            
        }
    }
 
    public void blob( byte[] blob ) throws IOException
    {
        print( "(blob)", null );
        printer.println();
    }    
    
    public void unknown( int code, byte[] data ) throws IOException
    {
        print( "unknown code =", new String[] { Integer.toString( code ) } );
    }
    
    public void initArray() throws IOException 
    {
        print( "initArray", null );
    }    
        
    public void jumpLabel( String label ) throws IOException
    {
        if( this.label != null ) print( "", null );
        this.label = label;
    }    
  
    public void gotoFrame( int frameNumber ) throws IOException
    {
        print( "gotoFrame", new String[] { Integer.toString( frameNumber ) } );
    }
    
    public void gotoFrame( String label ) throws IOException
    {
        print( "gotoFrame", new String[] { "\"" + label + "\"" } );
    }
    
    public void getURL( String url, String target ) throws IOException
    {
        print( "getURL", new String[] { "\"" + url + "\"", "\"" + target + "\"" } );
    }
    
    public void nextFrame() throws IOException
    {
        print( "nextFrame", null );
    }
    
    public void prevFrame() throws IOException
    {
        print( "previousFrame", null );
    }
    
    public void play() throws IOException
    {
        print( "play", null );
    }
    
    public void stop() throws IOException
    {
        print( "stop", null );
    }
    
    public void toggleQuality() throws IOException
    {
        print( "toggleQuality", null );
    }
    
    public void stopSounds() throws IOException
    {
        print( "stopSounds", null );
    }
    
    public void setTarget( String target ) throws IOException
    {
        print( "setTarget", new String[] { "\"" + target + "\"" } );
    }
    
    public void jump( String jumpLabel ) throws IOException
    {
        print( "jump", new String[] { "\"" + jumpLabel + "\"" } );
    }
    
    public void ifJump( String jumpLabel ) throws IOException
    {
        print( "ifJump", new String[] { "\"" + jumpLabel + "\"" } );
    }
    
    public void waitForFrame( int frameNumber, String jumpLabel ) throws IOException
    {
        print( "waitForFrame", new String[] { Integer.toString( frameNumber ), 
                                              "\"" + jumpLabel + "\"" } );        
    }
    
    public void waitForFrame( String jumpLabel ) throws IOException
    {
        print( "waitForFrame", new String[] { "\"" + jumpLabel + "\"" } );       
    }
    
    public void pop() throws IOException
    {
        print( "pop", null );
    }
    
    public void push( String value ) throws IOException
    {
        print( "push", new String[] { "\"" + value + "\"" } );
    }
    
    public void push( float  value ) throws IOException
    {
        print( "push", new String[] { "float " + value } );
    }
    
    public void push( double value ) throws IOException
    {
        print( "push", new String[] { "double " + value } );
    }
    
    public void pushNull() throws IOException
    {
        print( "push", new String[] { "null" } );
    }
    
	public void pushUndefined() throws IOException
	{
		print( "push", new String[] { "undefined" } );
	}
	    
    public void pushRegister( int registerNumber ) throws IOException
    {
        print( "push", new String[] { "register( " + registerNumber + " )" } );
    }
    
    public void push( boolean value ) throws IOException
    {
        print( "push", new String[] { value ? "true" : "false" } );
    }
    
    public void push( int value ) throws IOException
    {
        print( "push", new String[] { "" + value } );
    }
    
    public void lookup( int dictionaryIndex ) throws IOException
    {
        print( "push", new String[] { "lookup( " + dictionaryIndex + " )" } );
    }
    
    public void add() throws IOException
    {
        print( "add", null );
    }
    
    public void substract() throws IOException
    {
        print( "substract", null );
    }
    
    public void multiply() throws IOException
    {
        print( "multiply", null );
    }
    
    public void divide() throws IOException
    {
        print( "divide", null );
    }
    
    public void equals() throws IOException
    {
        print( "equals", null );
    }
    
    public void lessThan() throws IOException
    {
        print( "lessThan", null );
    }
    
    public void and() throws IOException
    {
        print( "and", null );
    }
    
    public void or() throws IOException
    {
        print( "or", null );
    }
    
    public void not() throws IOException
    {
        print( "not", null );
    }
    
    public void stringEquals() throws IOException
    {
        print( "stringEquals", null );
    }
    
    public void stringLength() throws IOException
    {
        print( "stringLength", null );
    }
    
    public void concat() throws IOException
    {
        print( "concat", null );
    }
    
    public void substring() throws IOException
    {
        print( "substring", null );
    }
    
    public void stringLessThan() throws IOException
    {
        print( "stringLessThan", null );
    }
    
    public void stringLengthMB() throws IOException
    {
        print( "stringLengthMB", null );
    }
    
    public void substringMB() throws IOException
    {
        print( "substringMB", null );
    }
        
    public void toInteger() throws IOException
    {
        print( "toInteger", null );
    }
        
    public void charToAscii() throws IOException
    {
        print( "charToAscii", null );
    }
        
    public void asciiToChar() throws IOException
    {
        print( "asciiToChar", null );
    }
        
    public void charMBToAscii() throws IOException
    {
        print( "charMBToAscii", null );
    }
        
    public void asciiToCharMB() throws IOException
    {
        print( "asciiToCharMB", null );
    }
        
    public void call() throws IOException
    {
        print( "call", null );
    }
    
    public void getVariable() throws IOException
    {
        print( "getVariable", null );
    }
    
    public void setVariable() throws IOException
    {
        print( "setVariable", null );
    }
    
    public void getURL( int sendVars, int loadMode ) throws IOException
    {        
        String sendVars_ = null;
        switch( sendVars )
        {
            case GET_URL_SEND_VARS_GET:
                sendVars_ = "send vars via GET";
                break;
            
            case GET_URL_SEND_VARS_POST:
                sendVars_ = "send vars via POST";
                break;
            
            case GET_URL_SEND_VARS_NONE:
            default:
                sendVars_ = "no send";
                break;
        }
        

⌨️ 快捷键说明

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