PageRenderTime 28ms CodeModel.GetById 14ms app.highlight 6ms RepoModel.GetById 2ms app.codeStats 0ms

/src/cocktail/domElement/as3/TextDOMElement.hx

http://github.com/silexlabs/Cocktail
Haxe | 98 lines | 41 code | 8 blank | 49 comment | 0 complexity | 7e6d384007f91f4f466a089d92bddf99 MD5 | raw file
 1/*
 2This file is part of Silex - see http://projects.silexlabs.org/?/silex
 3
 4Silex is Š 2010-2011 Silex Labs and is released under the GPL License:
 5
 6This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License (GPL) as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. 
 7
 8This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 9
10To read the license please visit http://www.gnu.org/copyleft/gpl.html
11*/
12package cocktail.domElement.as3;
13import cocktail.nativeElement.NativeElement;
14import flash.display.DisplayObjectContainer;
15import flash.display.Sprite;
16import flash.text.TextField;
17import haxe.Log;
18import cocktail.domElement.abstract.AbstractTextDOMElement;
19
20/**
21 * This is the Text DOMElement implementation for Flash.
22 * 
23 * It displays an htmlText in a native flash text field.
24 * It needs to convert the HTML text to Flash pseudo-HTML
25 * format before displaying it
26 * 
27 * @author Yannick DOMINGUEZ
28 */
29class TextDOMElement extends AbstractTextDOMElement
30{
31	/**
32	 * The native Flash text field that will be used to display
33	 * the html text
34	 */
35	private var _nativeTextField:TextField;
36	
37	/**
38	 * class constructor. Instantiate the native text field
39	 * and add it as a child of the native Sprite.
40	 */
41	public function new(nativeElement:NativeElement = null) 
42	{
43		super(nativeElement);
44		
45		_nativeTextField = new TextField();
46		_nativeTextField.wordWrap = true;
47		_nativeTextField.multiline = true;
48		this._nativeElement.addChild(_nativeTextField);
49	}
50	
51	/**
52	 * This method is overriden to set the Flash pseudo-html
53	 * string on the native text field
54	 * @param text the HTML text before conversion
55	 */
56	override public function setText(text:String):String
57	{
58		super.setText(text);
59		_nativeTextField.htmlText = fromHTMLtoFLASHTML(text);
60		return text;
61	}
62	
63	/**
64	 * Convert an HTML string into a Flash pseudo-html string.
65	 * Flash supports only a limited subset of the HTML format
66	 * @param	html the HTML string
67	 * @return the pseudo-html string
68	 */
69	private static function fromHTMLtoFLASHTML(html:String):String
70	{
71		return html;
72	}
73	
74	/**
75	 * override to set only the width of the native text
76	 * field. The container sprite must not be reseized,
77	 * else it scale the text
78	 */ 
79	override public function setWidth(value:Int):Int
80	{
81		this._width = value;
82		_nativeTextField.width = value;
83		return this._width;
84	}
85	
86	/**
87	 * override to set only the height of the native text
88	 * field. The container sprite must not be reseized,
89	 * else it scale the text
90	 */ 
91	override public function setHeight(value:Int):Int
92	{
93		this._height = value;
94		_nativeTextField.height = value;
95		return this._height;
96	}
97	
98}