source: EDIS/trunk/java/tracking-ui-core/src/main/flex/gov/va/med/edp/widget/ColorSelector.mxml@ 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: 5.6 KB
Line 
1<?xml version="1.0" encoding="utf-8"?>
2<!-- ColorSelector.mxml assumes a listcontrol passes in a "color" property -->
3
4<mx:HBox
5 xmlns:mx="http://www.adobe.com/2006/mxml"
6 horizontalScrollPolicy="off" verticalScrollPolicy="off"
7 horizontalGap="3" creationComplete="setCorrectState()" xmlns:accessibility="flash.accessibility.*">
8 <mx:Metadata>
9 [Event(name="colorChange", type="gov.va.med.edp.control.config.ColorChangedEvent")]
10 </mx:Metadata>
11 <mx:Script>
12 <![CDATA[
13 import gov.va.med.edp.util.AccessibilityTools;
14 import gov.va.med.edp.control.config.ColorChangedEvent;
15 import gov.va.med.edp.control.config.ConfigurationEvent;
16 import mx.controls.dataGridClasses.DataGridListData;
17 import gov.va.med.edp.vo.ColorSelectionVO;
18
19 private var _data: Object;
20
21 private var _color:ColorSelectionVO = new ColorSelectionVO();
22
23 [Bindable]
24 private var _baseTabIndex:int;
25
26 [Bindable]
27 public function get color():ColorSelectionVO {
28 return _color;
29 }
30
31 public function set color(c:ColorSelectionVO):void {
32 initColor(c);
33 }
34
35 [Bindable]
36 public override function get tabIndex():int {
37 return super.tabIndex;
38 }
39
40 public override function set tabIndex(index:int):void {
41 super.tabIndex = index;
42 _baseTabIndex = index;
43 }
44
45 override public function set data(value:Object):void
46 {
47 if (value == null) return;
48 _data = value;
49 var curColor: ColorSelectionVO = value["color"] as ColorSelectionVO;
50 initColor(curColor);
51 }
52
53 private function initColor(c:ColorSelectionVO):void {
54 if (c == null) {
55 _color.ignore = true;
56 _color.text = 0;
57 _color.back = 0xffffff;
58 } else {
59 _color.ignore = c.ignore;
60 _color.text = c.text;
61 _color.back = c.back;
62 }
63
64 useColor.selected = !_color.ignore;
65 if (_color.ignore) {
66 _color.back = 0xFFFFFF;
67 _color.text = 0;
68 }
69 textColor.selectedColor = _color.text;
70 backColor.selectedColor = _color.back;
71 textColorTxt.text = rgbToHex(_color.text);
72 backColorTxt.text = rgbToHex(_color.back);
73 }
74
75 override public function get data(): Object
76 {
77 return _data;
78
79 }
80
81 private function changeIgnore(): void
82 {
83 _color.ignore = !useColor.selected;
84 _color.back = 0xFFFFFF;
85 _color.text = 0;
86
87 backColorTxt.visible = useColor.selected;
88 textColorTxt.visible = useColor.selected;
89 dispatchEvent(new ColorChangedEvent(_color));
90 }
91
92 private function changeColor(): void
93 {
94 if (AccessibilityTools.isAccessibilityActive()){
95 if (textColorTxt.text.length == 6){
96 _color.text = uint("0x" + textColorTxt.text);
97 _color.back = uint("0x" + backColorTxt.text);
98 dispatchEvent(new ColorChangedEvent(_color));
99 } else {
100 return;
101 }
102 } else {
103 _color.text = textColor.selectedColor;
104 _color.back = backColor.selectedColor;
105 dispatchEvent(new ColorChangedEvent(_color));
106 }
107
108 }
109
110 private function setCorrectState(): void
111 {
112 if (AccessibilityTools.isAccessibilityActive()) currentState = 'accessible'
113 else currentState = '';
114 }
115
116 private function rgbToHex(color:uint):String
117 {
118 // Find hex number in the RGB offset
119 var colorInHex:String = color.toString(16);
120 var c:String = "00000" + colorInHex;
121 var e:int = c.length;
122 c = c.substring(e - 6, e);
123 return c.toUpperCase();
124 }
125
126 ]]>
127 </mx:Script>
128
129 <mx:CheckBox id="useColor" accessibilityProperties="{useColorProps}" label="Use Color" selected="false" paddingTop="2" change="changeIgnore()" tabIndex="{_baseTabIndex + 1}"/>
130 <mx:Label id="textLbl" text="Text" paddingTop="2" visible="{useColor.selected}" />
131 <mx:ColorPicker id="textColor" change="changeColor()" editable="false" showTextField="false" visible="{useColor.selected}" tabIndex="{_baseTabIndex + 2}"/>
132 <mx:Label id="backLbl" text="Back" paddingTop="2" visible="{useColor.selected}" />
133 <mx:ColorPicker id="backColor" change="changeColor()" editable="false" showTextField="false" visible="{useColor.selected}" tabIndex="{_baseTabIndex + 3}"/>
134
135 <accessibility:AccessibilityProperties id="useColorProps" name="use color" />
136 <accessibility:AccessibilityProperties id="backColorProps" name="enter background color in 6 digit hex string format" />
137 <accessibility:AccessibilityProperties id="textColorProps" name="enter text color in 6 digit hex string format" />
138
139 <mx:states>
140 <mx:State name="accessible">
141 <mx:RemoveChild target="{textColor}"/>
142 <mx:AddChild relativeTo="{textLbl}" position="after">
143 <mx:target>
144 <mx:TextInput maxChars="6" id="textColorTxt" accessibilityProperties="{textColorProps}" change="changeColor()" width="55" restrict="#xabcdefABCDEF0123456789" visible="{useColor.selected}" tabIndex="{_baseTabIndex + 2}"/>
145 </mx:target>
146 </mx:AddChild>
147 <mx:SetProperty target="{textColorTxt}" name="text" value="{rgbToHex(color.text)}"/>
148 <mx:RemoveChild target="{backColor}"/>
149 <mx:AddChild relativeTo="{backLbl}" position="after">
150 <mx:target>
151 <mx:TextInput id="backColorTxt" maxChars="6" change="changeColor()" accessibilityProperties="{backColorProps}" width="55" restrict="#xXabcdefABCDEF0123456789" visible="{useColor.selected}" tabIndex="{_baseTabIndex + 3}"/>
152 </mx:target>
153 </mx:AddChild>
154 <mx:SetProperty target="{backColorTxt}" name="text" value="{rgbToHex(color.back)}"/>
155 </mx:State>
156 </mx:states>
157
158</mx:HBox>
Note: See TracBrowser for help on using the repository browser.