Revision: 48589
Updated Code
at July 5, 2011 23:00 by kuril
Updated Code
package { import flash.display.Sprite; import flashx.textLayout.container.ContainerController; import flashx.textLayout.edit.SelectionManager; import flashx.textLayout.elements.TextFlow; import flashx.textLayout.events.CompositionCompleteEvent; import mx.core.IDataRenderer; import mx.core.UIComponent; import spark.utils.TextFlowUtil; /** * Simple TLF based Text ItemRenderer for flex DataGroup * After data set and text composed it ivokes invalidateParentSizeAndDisplayList if * if height of text container changed. */ public class TextItemRenderer extends UIComponent implements IDataRenderer { private var _container:Sprite; private var _controller:ContainerController; private var _textFlow:TextFlow; private var _selectionManager:SelectionManager; private var dataChanged:Boolean; private var _data:String; public function set data(value:Object):void { if (_data != value) { _data = String(value); dataChanged = true; invalidateProperties(); } } public function get data():Object { return _data; } protected override function createChildren():void { _container = new Sprite(); _controller = new ContainerController(_container, NaN, NaN); _selectionManager = new SelectionManager; addChild(_container); } override protected function commitProperties():void { super.commitProperties(); if (dataChanged) { if (_textFlow != null) { _textFlow.flowComposer.removeAllControllers(); _textFlow.removeEventListener(CompositionCompleteEvent.COMPOSITION_COMPLETE, compositionCompleteHandler); } _textFlow = TextFlowUtil.importFromString(_data); _textFlow.addEventListener(CompositionCompleteEvent.COMPOSITION_COMPLETE, compositionCompleteHandler); _textFlow.interactionManager = _selectionManager; _textFlow.flowComposer.addController(_controller); _textFlow.flowComposer.updateToController(); dataChanged = false; } } private function compositionCompleteHandler(event:CompositionCompleteEvent):void { if (measuredHeight != Math.ceil(_controller.getContentBounds().height)) { invalidateSize(); invalidateDisplayList(); invalidateParentSizeAndDisplayList(); } } override protected function measure():void { super.measure(); measuredHeight = Math.ceil(_controller.getContentBounds().height); } override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void { if (unscaledWidth == 0 || unscaledHeight == 0) { return; } if (_textFlow != null) { _controller.setCompositionSize(unscaledWidth, unscaledHeight); _textFlow.flowComposer.updateToController(); } } } }
Revision: 48588
Updated Code
at July 5, 2011 22:56 by kuril
Updated Code
package { import flash.display.Sprite; import flashx.textLayout.container.ContainerController; import flashx.textLayout.edit.SelectionManager; import flashx.textLayout.elements.TextFlow; import flashx.textLayout.events.CompositionCompleteEvent; import mx.core.IDataRenderer; import mx.core.UIComponent; import spark.utils.TextFlowUtil; /** * Simple TLF based Text ItemRenderer for flex DataGroup * */ public class TextItemRenderer extends UIComponent implements IDataRenderer { private var _container:Sprite; private var _controller:ContainerController; private var _textFlow:TextFlow; private var _selectionManager:SelectionManager; private var dataChanged:Boolean; private var _data:String; public function set data(value:Object):void { if (_data != value) { _data = String(value); dataChanged = true; invalidateProperties(); } } public function get data():Object { return _data; } protected override function createChildren():void { _container = new Sprite(); _controller = new ContainerController(_container, NaN, NaN); _selectionManager = new SelectionManager; addChild(_container); } override protected function commitProperties():void { super.commitProperties(); if (dataChanged) { if (_textFlow != null) { _textFlow.flowComposer.removeAllControllers(); _textFlow.removeEventListener(CompositionCompleteEvent.COMPOSITION_COMPLETE, compositionCompleteHandler); } _textFlow = TextFlowUtil.importFromString(_data); _textFlow.addEventListener(CompositionCompleteEvent.COMPOSITION_COMPLETE, compositionCompleteHandler); _textFlow.interactionManager = _selectionManager; _textFlow.flowComposer.addController(_controller); _textFlow.flowComposer.updateToController(); dataChanged = false; } } private function compositionCompleteHandler(event:CompositionCompleteEvent):void { if (measuredHeight != Math.ceil(_controller.getContentBounds().height)) { invalidateSize(); invalidateDisplayList(); invalidateParentSizeAndDisplayList(); } } override protected function measure():void { super.measure(); measuredHeight = Math.ceil(_controller.getContentBounds().height); } override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void { if (unscaledWidth == 0 || unscaledHeight == 0) { return; } if (_textFlow != null) { _controller.setCompositionSize(unscaledWidth, unscaledHeight); _textFlow.flowComposer.updateToController(); } } } }
Revision: 48587
Updated Code
at July 5, 2011 20:32 by kuril
Updated Code
public class TextItemRenderer extends UIComponent implements IDataRenderer { private var _container:Sprite; private var _controller:ContainerController; private var _textFlow:TextFlow; private var _selectionManager:SelectionManager; private var dataChanged:Boolean; private var _data:String; public function set data(value:Object):void { if (_data != value) { _data = String(value); dataChanged = true; invalidateProperties(); } } public function get data():Object { return _data; } protected override function createChildren():void { _container = new Sprite(); _controller = new ContainerController(_container, NaN, NaN); _selectionManager = new SelectionManager; addChild(_container); } override protected function commitProperties():void { super.commitProperties(); if (dataChanged) { if (_textFlow != null) { _textFlow.flowComposer.removeAllControllers(); _textFlow.removeEventListener(CompositionCompleteEvent.COMPOSITION_COMPLETE, compositionCompleteHandler); } _textFlow = TextFlowUtil.importFromString(_data); _textFlow.addEventListener(CompositionCompleteEvent.COMPOSITION_COMPLETE, compositionCompleteHandler); _textFlow.interactionManager = _selectionManager; _textFlow.flowComposer.addController(_controller); _textFlow.flowComposer.updateToController(); dataChanged = false; } } private function compositionCompleteHandler(event:CompositionCompleteEvent):void { if (measuredHeight != Math.ceil(_controller.getContentBounds().height)) { invalidateSize(); invalidateDisplayList(); invalidateParentSizeAndDisplayList(); } } override protected function measure():void { super.measure(); measuredHeight = Math.ceil(_controller.getContentBounds().height); } override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void { if (unscaledWidth == 0 || unscaledHeight == 0) { return; } if (_textFlow != null) { _controller.setCompositionSize(unscaledWidth, unscaledHeight); _textFlow.flowComposer.updateToController(); } } } }
Revision: 48586
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at July 5, 2011 20:29 by kuril
Initial Code
public class TextItemRenderer extends UIComponent implements IDataRenderer { private var _container:Sprite; private var _controller:ContainerController; private var _textFlow:TextFlow; private var _selectionManager:SelectionManager; private var dataChanged:Boolean; private var _data:String; public function set data(value:Object):void { if (_data != value) { _data = String(value); dataChanged = true; invalidateProperties(); } } public function get data():Object { return _data; } protected override function createChildren():void { _container = new Sprite(); _controller = new ContainerController(_container, NaN, NaN); _selectionManager = new SelectionManager; addChild(_container); } override protected function commitProperties():void { super.commitProperties(); if (dataChanged) { if (_textFlow != null) { _textFlow.flowComposer.removeAllControllers(); _textFlow.removeEventListener(CompositionCompleteEvent.COMPOSITION_COMPLETE, compositionCompleteHandler); } _textFlow = TextFlowUtil.importFromString(_data); _textFlow.addEventListener(CompositionCompleteEvent.COMPOSITION_COMPLETE, compositionCompleteHandler); _textFlow.interactionManager = _selectionManager; _textFlow.flowComposer.addController(_controller); _textFlow.flowComposer.updateToController(); dataChanged = false; } } private function compositionCompleteHandler(event:CompositionCompleteEvent):void { if (measuredHeight != Math.ceil(_controller.getContentBounds().height)) { invalidateSize(); invalidateDisplayList(); invalidateParentSizeAndDisplayList(); } } override protected function measure():void { super.measure(); measuredHeight = Math.ceil(_controller.getContentBounds().height); } override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void { if (unscaledWidth == 0 || unscaledHeight == 0) { return; } if (_textFlow != null) { _controller.setCompositionSize(unscaledWidth, unscaledHeight); _textFlow.flowComposer.updateToController(); — Скрыть цитируемый текÑÑ‚ — } } } }
Initial URL
Initial Description
Initial Title
Text ItemRenderer for Flex DataGroup
Initial Tags
Flex
Initial Language
ActionScript 3