source: EDIS/trunk/java/tracking-ui-core/src/main/flex/gov/va/med/edp/widget/CenteredEmbedImage.as@ 1227

Last change on this file since 1227 was 1227, checked in by George Lilly, 13 years ago

initial load of EDIS 1.0

File size: 3.7 KB
Line 
1package gov.va.med.edp.widget
2{
3 import flash.display.DisplayObject;
4import mx.events.FlexEvent;
5import mx.core.UIComponent;
6import mx.controls.listClasses.BaseListData;
7import mx.controls.listClasses.IListItemRenderer;
8import mx.controls.listClasses.IDropInListItemRenderer;
9
10/**
11 * assumes the image is embedded and not a .swf
12 */
13public class CenteredEmbedImage extends UIComponent implements IListItemRenderer, IDropInListItemRenderer
14{
15
16 public function CenteredEmbedImage()
17 {
18 super();
19 }
20
21 //----------------------------------
22 // data
23 //----------------------------------
24
25 /**
26 * @private
27 * Storage for the data property.
28 */
29 private var _data:Object;
30
31 [Bindable("dataChange")]
32 [Inspectable(environment="none")]
33
34 /**
35 * Lets you pass a value to the component
36 * when you use it in an item renderer or item editor.
37 * You typically use data binding to bind a field of the <code>data</code>
38 * property to a property of this component.
39 *
40 * <p>When you use the control as a drop-in item renderer or drop-in
41 * item editor, Flex automatically writes the current value of the item
42 * to the <code>text</code> property of this control.</p>
43 *
44 * <p>You do not set this property in MXML.</p>
45 *
46 * @default null
47 * @see mx.core.IDataRenderer
48 */
49 public function get data():Object
50 {
51 return _data;
52 }
53
54 /**
55 * @private
56 */
57 public function set data(value:Object):void
58 {
59 var newText:*;
60
61 _data = value;
62
63 invalidateProperties();
64
65 dispatchEvent(new FlexEvent(FlexEvent.DATA_CHANGE));
66 }
67
68 //----------------------------------
69 // listData
70 //----------------------------------
71
72 /**
73 * @private
74 * Storage for the listData property.
75 */
76 private var _listData:BaseListData;
77
78 [Bindable("dataChange")]
79 [Inspectable(environment="none")]
80
81 /**
82 * When a component is used as a drop-in item renderer or drop-in
83 * item editor, Flex initializes the <code>listData</code> property
84 * of the component with the appropriate data from the List control.
85 * The component can then use the <code>listData</code> property
86 * to initialize the <code>data</code> property of the drop-in
87 * item renderer or drop-in item editor.
88 *
89 * <p>You do not set this property in MXML or ActionScript;
90 * Flex sets it when the component is used as a drop-in item renderer
91 * or drop-in item editor.</p>
92 *
93 * @default null
94 * @see mx.controls.listClasses.IDropInListItemRenderer
95 */
96 public function get listData():BaseListData
97 {
98 return _listData;
99 }
100
101 /**
102 * @private
103 */
104 public function set listData(value:BaseListData):void
105 {
106 _listData = value;
107 }
108
109 private var img:DisplayObject;
110
111 /**
112 * create the image instance now that we know what it is
113 */
114 override protected function commitProperties():void
115 {
116 super.commitProperties();
117
118 if (listData)
119 {
120 // remove the old child if we have one
121 if (img)
122 removeChild(img);
123
124 var c:Class = UIComponent(owner).document[listData.label];
125 img = new c();
126 addChild(img);
127 }
128 }
129
130 /**
131 * create the image instance now that we know what it is
132 */
133 override protected function measure():void
134 {
135 super.measure();
136
137 if (img)
138 {
139 measuredHeight = img.height;
140 measuredWidth = img.width;
141 }
142 }
143
144 /**
145 * center the contentHolder
146 */
147 override protected function updateDisplayList(w:Number, h:Number):void
148 {
149 super.updateDisplayList(w, h);
150
151 if (img)
152 {
153 img.x = (w - img.width) / 2;
154 }
155 }
156
157}
158
159}
Note: See TracBrowser for help on using the repository browser.