1 50 51 package org.openlaszlo.iv.flash.api; 52 53 import org.openlaszlo.iv.flash.util.*; 54 import org.openlaszlo.iv.flash.commands.*; 55 56 import org.openlaszlo.iv.flash.api.shape.*; 57 import org.openlaszlo.iv.flash.api.text.*; 58 import org.openlaszlo.iv.flash.api.action.*; 59 import org.openlaszlo.iv.flash.context.Context; 60 61 import java.awt.geom.AffineTransform ; 62 import java.awt.geom.Rectangle2D ; 63 import java.io.*; 64 import java.util.*; 65 66 75 public final class Frame extends IVVector { 76 77 private String name; 78 private boolean is_anchor; 80 83 public Frame() {} 84 85 90 public Frame( int capacity ) { 91 super( capacity ); 92 } 93 94 102 public Frame( IVVector data ) { 103 super( data ); 104 } 105 106 111 public String getName() { 112 return name; 113 } 114 115 120 public void setName( String name ) { 121 this.name = name; 122 } 123 124 131 public void setAnchor( boolean is_anchor ) { 132 this.is_anchor = is_anchor; 133 } 134 135 142 public boolean isAnchor() { 143 return is_anchor; 144 } 145 146 159 public Instance addInstance( FlashDef def, int depth, AffineTransform matrix, CXForm cxform ) { 160 return addInstance(def, depth, matrix, cxform, null); 161 } 162 163 177 public Instance addInstance( FlashDef def, int depth, AffineTransform matrix, CXForm cxform, String name ) { 178 Instance inst = new Instance(); 179 inst.def = def; 180 inst.depth = depth; 181 inst.matrix = matrix; 182 inst.cxform = cxform; 183 inst.name = name; 184 addFlashObject( inst ); 185 return inst; 186 } 187 188 198 public Instance addInstance( int depth, AffineTransform matrix ) { 199 return addInstance(depth, matrix, null); 200 } 201 202 213 public Instance addInstance( int depth, AffineTransform matrix, CXForm cxform ) { 214 Instance inst = new Instance(); 215 inst.depth = depth; 216 inst.matrix = matrix; 217 inst.cxform = cxform; 218 inst.isMove = true; 219 addFlashObject( inst ); 220 return inst; 221 } 222 223 230 public Instance addInstance( Instance inst, int depth ) { 231 inst.depth = depth; 232 addFlashObject( inst ); 233 return inst; 234 } 235 236 245 public RemoveObject removeInstance( int depth ) { 246 RemoveObject ro = new RemoveObject(); 247 ro.depth = depth; 248 addFlashObject( ro ); 249 return ro; 250 } 251 252 257 public void addFlashObject( FlashObject o ) { 258 addElement( o ); 259 } 260 261 267 public void setFlashObjectAt( FlashObject o, int index ) { 268 setElementAt( o, index ); 269 } 270 271 277 public FlashObject getFlashObjectAt( int index ) { 278 return (FlashObject) elementAt( index ); 279 } 280 281 287 public FlashObject removeFlashObjectAt( int index ) { 288 return (FlashObject) removeElementAt( index ); 289 } 290 291 296 public void remove( FlashObject o ) { 297 removeElement( o ); 298 } 299 300 307 public void write( FlashOutput fob ) { 308 if( name != null ) writeFrameLabel(fob); 309 super.write( fob ); 310 Tag.SHOWFRAME_TAG.write( fob ); 311 } 312 313 321 public void generate( FlashOutput fob, DepsCollector dc ) { 322 if( name != null ) writeFrameLabel(fob); 323 for( int i=0; i<top; i++ ) { 324 FlashObject fo = (FlashObject) objects[i]; 325 fo.generate( fob, dc ); 326 } 327 Tag.SHOWFRAME_TAG.write( fob ); 328 } 329 330 335 public void collectDeps( DepsCollector dc ) { 336 for( int i=0; i<top; i++ ) { 337 FlashObject fo = (FlashObject) objects[i]; 338 fo.collectDeps(dc); 339 } 340 } 341 342 349 public void process( FlashFile file, Context context ) throws IVException { 350 name = context.apply( name ); 351 for( int i=0; i<top; i++ ) { 352 FlashObject fo = (FlashObject) objects[i]; 353 file.processObject(fo, context); 354 } 355 } 356 357 362 public void apply( Context context ) { 363 name = context.apply(name); 364 for( int i=0; i<top; i++ ) { 365 FlashObject fo = (FlashObject) objects[i]; 366 fo.apply(context); 367 } 368 } 369 370 379 public void doCommand( FlashFile file, Context context, Script parent, int frame ) throws IVException { 380 for( int i=0; i<top; i++ ) { 381 FlashObject fo = (FlashObject) objects[i]; 382 if( !(fo instanceof Instance) ) continue; 383 Instance instance = (Instance) fo; 384 GenericCommand cmd = instance.command; 385 386 if( cmd != null ) { 387 try { 388 cmd.doCommand( file, context, parent, frame ); 389 } catch( Throwable t ) { 390 Log.logRB( Resource.ERRDOCMD, new Object [] { 391 file.getFullName(), parent.getName(), 392 String.valueOf(frame+1), cmd.getCommandName() }, t ); 393 394 if( PropertyManager.showErrorsInline ) { 395 Script script = new Script(1); 397 Frame fr = script.newFrame(); 398 Shape shape = new Shape(); 399 shape.setLineStyle( new LineStyle(20, AlphaColor.black) ); 400 shape.setFillStyle0( FillStyle.newSolid( new AlphaColor( 150, 150, 150, 150 ) ) ); 401 Rectangle2D r = GeomHelper.newRectangle(-1024, -1024, 2048, 2048); 402 shape.drawRectangle(r); 403 shape.setBounds(r); 404 fr.addInstance(shape, 1, null, null); 405 406 FlashFile defFile = file.getDefaultSymbolFile(); 407 if( defFile != null ) { 408 Font font = defFile.getFont( "Arial" ); 409 if( font != null ) { 410 String msg = cmd.getCommandName()+" : "+t.getMessage(); 411 Text text = Text.newText(); 412 TextItem item = new TextItem( msg, font, 8*20, AlphaColor.black ); 413 text.addTextItem( item ); 414 text.setBounds( (Rectangle2D ) r.clone() ); 415 AffineTransform m = AffineTransform.getTranslateInstance(-1024, -1024); 416 fr.addInstance(text, 2, m, null); 417 } 418 } 419 instance.def = script; 420 instance.command = null; 421 } else { 422 instance.def = Shape.newEmptyShape1(); 424 instance.command = null; 425 } 426 } 427 } 428 } 429 } 430 431 436 public void addBounds( Rectangle2D rect ) { 437 for( int i=0; i<top; i++ ) { 438 FlashObject fo = (FlashObject) objects[i]; 439 GeomHelper.add( rect, fo.getBounds() ); 440 } 441 } 442 443 448 public void append( Frame f ) { 449 for( int i=0; i<f.size(); i++ ) { 450 addFlashObject( f.getFlashObjectAt(i) ); 451 } 452 } 453 454 461 public boolean isConstant() { 462 if( Util.hasVar(name) ) return false; 463 for( int i=0; i<top; i++ ) { 464 FlashObject fo = (FlashObject) objects[i]; 465 if( !fo.isConstant() ) return false; 466 } 467 return true; 468 } 469 470 478 public IVVector getCopy( ScriptCopier copier ) { 479 Frame c = new Frame( size() ); 480 for( int i=0; i<top; i++ ) { 481 FlashObject fo = (FlashObject) objects[i]; 482 c.setElementAt( fo.getCopy(copier), i ); 483 } 484 c.setName( name ); 485 return c; 486 } 487 488 492 public void addStopAction() { 493 DoAction action = new DoAction(); 494 495 action.program = new Program(); 496 action.program.stop(); 497 498 addFlashObject( action ); 499 } 500 501 private void writeFrameLabel( FlashOutput fob ) { 502 fob.writeTag( Tag.FRAMELABEL, name.length()+(is_anchor?2:1) ); 503 fob.writeStringZ( name ); 504 if( is_anchor ) fob.writeByte(1); 505 } 506 507 } 508 509 | Popular Tags |