1 50 51 package org.openlaszlo.iv.flash.commands; 52 53 import java.io.*; 54 import java.awt.geom.*; 55 56 import org.openlaszlo.iv.flash.parser.*; 57 import org.openlaszlo.iv.flash.api.*; 58 import org.openlaszlo.iv.flash.util.*; 59 import org.openlaszlo.iv.flash.url.*; 60 import org.openlaszlo.iv.flash.context.Context; 61 62 public class InsertMovieFileCommand extends GenericCommand { 63 64 public InsertMovieFileCommand() {} 65 66 public void doCommand( FlashFile file, Context context, Script parent, int frameNum ) throws IVException { 67 String filename = getParameter( context, "filename", "" ); 68 boolean scale = getBoolParameter( context, "scale", false ); 69 boolean expand = getBoolParameter( context, "expand", true ); 70 boolean cache = getBoolParameter( context, "cache", false ); 71 String instancename = getParameter( context, "instancename" ); 72 73 Instance inst = getInstance(); 74 75 FlashFile flashFile = null; 76 try { 77 flashFile = (FlashFile) file.addExternalMedia(filename, cache); 78 } catch( IOException e ) { 79 throw new IVException(Resource.ERRCMDFILEREAD, new Object [] {filename, getCommandName()}, e); 80 } 81 82 Script script; 83 synchronized(flashFile) { 84 script = flashFile.getMainScript(); 85 script.resetMain(); 86 if( flashFile.isTemplate() ) { 87 script.removeFileDepGlobalCommands(); 88 script = script.copyScript(); 89 } 90 } 91 if( flashFile.isTemplate() ) file.processScript(script, context); 92 93 inst.setScript( script ); 94 95 Rectangle2D r = flashFile.getFrameSize(); double width = r.getWidth(); 97 double height = r.getHeight(); 98 99 double scaleX, scaleY, translateX, translateY; 100 if( scale ) { 101 scaleX = 2048.0/width; 102 scaleY = 2048.0/height; 103 } else { 104 scaleX = 1.0; 105 scaleY = 1.0; 106 } 107 translateX = -(scaleX*width)/2; 108 translateY = -(scaleY*height)/2; 109 110 inst.matrix.concatenate( new AffineTransform(scaleX,0,0,scaleY,translateX,translateY) ); 112 113 if( instancename != null ) { 114 inst.name = instancename; 115 } 116 117 if( expand ) { 119 int myTotal = script.getFrameCount(); 121 parent.getFrameAt(frameNum+myTotal-1); 122 } 123 } 124 125 } 126 | Popular Tags |