1 50 51 package org.openlaszlo.iv.flash.api.text; 52 53 import java.io.*; 54 import java.awt.geom.*; 55 56 import org.openlaszlo.iv.flash.parser.Parser; 57 import org.openlaszlo.iv.flash.util.*; 58 import org.openlaszlo.iv.flash.api.*; 59 import org.openlaszlo.iv.flash.context.Context; 60 61 66 public final class TextField extends FlashDef { 67 68 public static final int HASLAYOUT = 0x2000; 69 public static final int NOSELECT = 0x1000; 70 public static final int BORDER = 0x0800; 71 public static final int HTML = 0x0200; 72 public static final int USEOUTLINES = 0x0100; 73 public static final int HASTEXT = 0x0080; 74 public static final int WORDWRAP = 0x0040; 75 public static final int MULTILINE = 0x0020; 76 public static final int PASSWORD = 0x0010; 77 public static final int READONLY = 0x0008; 78 public static final int HASTEXTCOLOR = 0x0004; 79 public static final int HASMAXLENGTH = 0x0002; 80 public static final int HASFONT = 0x0001; 81 82 private Rectangle2D bounds; private Font font; private int height; private AlphaColor color; private int maxlength; private int align; private int leftmargin; private int rightmargin; private int indent; private int leading; private String varName; private String initText; private int flags; 96 public TextField() {} 97 98 107 public TextField( String initText, String varName, Font font, int height, AlphaColor color ) { 108 this.initText = initText; 109 this.varName = varName; 110 this.font = font; 111 this.height = height; 112 this.color = color; 113 if( font != null ) flags = HASFONT; 114 if( color != null ) flags |= HASTEXTCOLOR; 115 if( initText != null ) flags |= HASTEXT; 116 } 117 118 123 public int getMaxLength() { 124 return maxlength; 125 } 126 127 132 public void setMaxLength( int maxlength ) { 133 this.maxlength = maxlength; 134 if( maxlength >= 0 ) flags |= HASMAXLENGTH; 135 else flags &= ~HASMAXLENGTH; 136 } 137 138 144 public void setFont( Font font, int height ) { 145 this.font = font; 146 this.height = height; 147 if( font != null ) flags |= HASFONT; 148 else flags &= ~HASFONT; 149 } 150 151 156 public Font getFont() { 157 return font; 158 } 159 160 165 public int getHeight() { 166 return height; 167 } 168 169 174 public String getVarName() { 175 return varName; 176 } 177 178 183 public void setVarName( String varName ) { 184 this.varName = varName; 185 } 186 187 192 public String getInitText() { 193 return initText; 194 } 195 196 201 public void setInitText( String initText ) { 202 this.initText = initText; 203 if( initText != null ) flags |= HASTEXT; 204 else flags &= ~HASTEXT; 205 } 206 207 212 public void setFlags( int flags ) { 213 this.flags = flags; 214 } 215 216 221 public int getFlags() { 222 return flags; 223 } 224 225 231 public int addFlags( int flags ) { 232 this.flags |= flags; 233 return flags; 234 } 235 236 242 public int removeFlags( int flags ) { 243 this.flags &= ~flags; 244 return flags; 245 } 246 247 252 public void setBounds( Rectangle2D bounds ) { 253 this.bounds = bounds; 254 } 255 256 261 public Rectangle2D getBounds() { 262 return bounds; 263 } 264 265 274 public void setLayout( int align, int leftmargin, int rightmargin, int indent, int leading ) { 275 this.align = align; 276 this.leftmargin = leftmargin; 277 this.rightmargin = rightmargin; 278 this.indent = indent; 279 this.leading = leading; 280 flags |= HASLAYOUT; 281 } 282 283 public int getAlign() { return align; } 284 public int getLeftMargin() { return leftmargin; } 285 public int getRightMargin() { return rightmargin; } 286 public int getIndent() { return indent; } 287 public int getLeading() { return leading; } 288 289 294 public void setColor( AlphaColor color ) { 295 this.color = color; 296 if( color != null ) flags |= HASTEXTCOLOR; 297 else flags &= ~HASTEXTCOLOR; 298 } 299 300 305 public AlphaColor getColor() { 306 return color; 307 } 308 309 public int getTag() { 310 return Tag.DEFINEEDITTEXT; 311 } 312 313 public static TextField parse( Parser p ) { 314 TextField o = new TextField(); 315 o.setID( p.getUWord() ); 317 o.bounds = p.getRect(); 319 320 int flags = o.flags = p.getUWord(); 322 323 if( (flags&HASFONT) != 0 ) { 324 o.font = ((FontDef) p.getDef( p.getUWord() )).getFont(); 325 o.height = p.getUWord(); 326 } 327 328 if( (flags&HASTEXTCOLOR) != 0 ) { 329 o.color = Color.parseRGBA(p); 330 } 331 332 if( (flags&HASMAXLENGTH) != 0 ) { 333 o.maxlength = p.getUWord(); 334 } 335 336 if( (flags&HASLAYOUT) != 0 ) { 337 o.align = p.getUByte(); 338 o.leftmargin = p.getUWord(); 339 o.rightmargin = p.getUWord(); 340 o.indent = p.getUWord(); 341 o.leading = p.getUWord(); 342 } 343 344 o.varName = p.getString(); 345 346 if( (flags&HASTEXT) != 0 ) { 347 o.initText = p.getString(); 348 } 349 350 return o; 351 } 352 353 public void collectDeps( DepsCollector dc ) { 354 if( (flags&HASFONT) != 0 ) { 355 dc.addDep( font ); 356 } 357 } 358 359 public void collectFonts( FontsCollector fc ) { 360 if( (flags&HASFONT) != 0 ) { 361 FontDef fdef = fc.addFont( font, null ); 362 if( (flags&USEOUTLINES) != 0 ) { 363 if( !PropertyManager.mxLibraryFontID.equalsIgnoreCase(initText) ) { 364 fdef.setWriteLayout(true); 365 fdef.setWriteAllChars(true); } 367 } 368 } 369 } 370 371 public void write( FlashOutput fob ) { 372 if( (flags&USEOUTLINES) != 0 && PropertyManager.mxLibraryFontID.equalsIgnoreCase(initText) ) { 373 int start = fob.getPos(); fob.skip(2); 375 fob.writeDefID(this); 376 fob.write(GeomHelper.newRectangle(0, 0, 1, 1)); 377 fob.writeWord(0); 378 fob.writeStringZ(""); 379 int size = fob.getPos()-start-2; fob.writeShortTagAt(getTag(), size, start); 381 } else { 382 int l = varName.length() + ((flags&HASTEXT)!=0?initText.length():0); 384 int start = fob.getPos(); 386 if( l > 22 ) { 387 fob.skip(6); } else { 389 fob.skip(2); 390 } 391 392 fob.writeDefID(this); 393 fob.write(bounds); 394 fob.writeWord(flags); 395 396 if( (flags&HASFONT) != 0 ) { 397 fob.writeFontID( font ); 398 fob.writeWord(height); 399 } 400 401 if( (flags&HASTEXTCOLOR) != 0 ) { 402 color.write(fob); 403 } 404 405 if( (flags&HASMAXLENGTH) != 0 ) { 406 fob.writeWord(maxlength); 407 } 408 409 if( (flags&HASLAYOUT) != 0 ) { 410 fob.writeByte(align); 411 fob.writeWord(leftmargin); 412 fob.writeWord(rightmargin); 413 fob.writeWord(indent); 414 fob.writeWord(leading); 415 } 416 417 fob.writeStringZ(varName); 418 419 if( (flags&HASTEXT) != 0 ) { 420 fob.writeStringZ(initText); 421 } 422 423 if( l > 22 ) { 424 int size = fob.getPos()-start-6; fob.writeLongTagAt( getTag(), size, start ); 426 } else { 427 int size = fob.getPos()-start-2; fob.writeShortTagAt( getTag(), size, start ); 429 } 430 } 431 } 432 433 public void printContent( PrintStream out, String indent ) { 434 out.println( indent+"TextField: id="+getID()+", flags="+Util.w2h(flags) ); 435 out.println( indent+" "+bounds ); 436 437 if( (flags&HASFONT) != 0 ) { 438 out.println( indent+" font="+font.getFontName()+" height="+height ); 439 } 440 441 if( (flags&HASTEXTCOLOR) != 0 ) { 442 color.printContent(out, indent+" "); 443 } 444 445 if( (flags&HASMAXLENGTH) != 0 ) { 446 out.println( indent+" maxlength="+maxlength ); 447 } 448 449 if( (flags&HASLAYOUT) != 0 ) { 450 out.println( indent+" align="+align ); 451 out.println( indent+" leftmargin="+leftmargin ); 452 out.println( indent+" rightmargin="+rightmargin ); 453 out.println( indent+" indent="+indent ); 454 out.println( indent+" leading="+leading ); 455 } 456 457 out.println( indent+" varName='"+varName+"'" ); 458 459 if( (flags&HASTEXT) != 0 ) { 460 out.println( indent+" initText='"+initText+"'" ); 461 } 462 } 463 464 public void apply( Context context ) { 465 super.apply( context ); 466 varName = context.apply( varName ); 467 initText = context.apply( initText ); 468 } 469 470 protected boolean _isConstant() { 471 return !Util.hasVar(varName) && !Util.hasVar(initText); 472 } 473 474 protected FlashItem copyInto( FlashItem item, ScriptCopier copier ) { 475 super.copyInto( item, copier ); 476 ((TextField)item).bounds = (Rectangle2D) bounds.clone(); 477 ((TextField)item).font = font; 478 ((TextField)item).height = height; 479 ((TextField)item).color = (AlphaColor) color.getCopy(copier); 480 ((TextField)item).maxlength = maxlength; 481 ((TextField)item).align = align; 482 ((TextField)item).leftmargin = leftmargin; 483 ((TextField)item).rightmargin = rightmargin; 484 ((TextField)item).indent = indent; 485 ((TextField)item).leading = leading; 486 ((TextField)item).varName = varName; 487 ((TextField)item).initText = initText; 488 ((TextField)item).flags = flags; 489 return item; 490 } 491 492 public FlashItem getCopy( ScriptCopier copier ) { 493 return copyInto( new TextField(), copier ); 494 } 495 496 } 497 | Popular Tags |