[1240] | 1 | package gov.va.med.edp.widget.accessibility
|
---|
| 2 | {
|
---|
| 3 | import gov.va.med.edp.widget.AutoComplete;
|
---|
| 4 |
|
---|
| 5 | import flash.accessibility.Accessibility;
|
---|
| 6 | import flash.events.Event;
|
---|
| 7 |
|
---|
| 8 | import mx.accessibility.ComboBoxAccImpl;
|
---|
| 9 | import mx.core.UIComponent;
|
---|
| 10 | import mx.core.mx_internal;
|
---|
| 11 |
|
---|
| 12 | use namespace mx_internal;
|
---|
| 13 |
|
---|
| 14 | /**
|
---|
| 15 | * The AutoCompleteAccImpl class is the accessibility class for
|
---|
| 16 | * Autocomplete component.
|
---|
| 17 | *
|
---|
| 18 | * @tiptext This is the AutoCompleteAccImpl Accessibility Class.
|
---|
| 19 | * @created by jtorreno 6.2.2008
|
---|
| 20 | */
|
---|
| 21 | public class AutoCompleteAccImpl extends ComboBoxAccImpl
|
---|
| 22 | {
|
---|
| 23 | /**
|
---|
| 24 | * @private
|
---|
| 25 | */
|
---|
| 26 | private var lastItemName:String = "No item selected";
|
---|
| 27 |
|
---|
| 28 |
|
---|
| 29 | /**
|
---|
| 30 | * @private
|
---|
| 31 | * Default Role of Autocomplete component.
|
---|
| 32 | */
|
---|
| 33 | private const ROLE_SYSTEM_TEXT:uint = 0x0000002A;
|
---|
| 34 |
|
---|
| 35 | /**
|
---|
| 36 | * @private
|
---|
| 37 | * Default state for all the components.
|
---|
| 38 | */
|
---|
| 39 | private static const STATE_SYSTEM_NORMAL:uint = 0x00000000;
|
---|
| 40 |
|
---|
| 41 | /**
|
---|
| 42 | * @private
|
---|
| 43 | */
|
---|
| 44 | private static const STATE_SYSTEM_FOCUSED:uint = 0x00000004;
|
---|
| 45 |
|
---|
| 46 | /**
|
---|
| 47 | * @private
|
---|
| 48 | */
|
---|
| 49 | private static const EVENT_OBJECT_FOCUS:uint = 0x8005;
|
---|
| 50 |
|
---|
| 51 | /**
|
---|
| 52 | * @private
|
---|
| 53 | */
|
---|
| 54 | private static const EVENT_OBJECT_VALUECHANGE:uint = 0x0000800e;
|
---|
| 55 |
|
---|
| 56 | /**
|
---|
| 57 | * @private
|
---|
| 58 | * Event emitted if 1 item is selected.
|
---|
| 59 | */
|
---|
| 60 | private static const EVENT_OBJECT_SELECTION:uint = 0x8006;
|
---|
| 61 |
|
---|
| 62 | /**
|
---|
| 63 | * Accessibility hookup
|
---|
| 64 | * @private
|
---|
| 65 | */
|
---|
| 66 | private static var accessibilityHooked:Boolean = hookAccessibility();
|
---|
| 67 |
|
---|
| 68 | /**
|
---|
| 69 | * Constructor
|
---|
| 70 | */
|
---|
| 71 | public function AutoCompleteAccImpl(master:UIComponent)
|
---|
| 72 | {
|
---|
| 73 | super(master);
|
---|
| 74 | }
|
---|
| 75 |
|
---|
| 76 | /**
|
---|
| 77 | * @private
|
---|
| 78 | * Method for creating the Accessibility class.
|
---|
| 79 | * This method is called from UIComponent.
|
---|
| 80 | * @review
|
---|
| 81 | */
|
---|
| 82 | mx_internal static function createAccessibilityImplementation(
|
---|
| 83 | component:UIComponent):void
|
---|
| 84 | {
|
---|
| 85 | component.accessibilityImplementation =
|
---|
| 86 | new AutoCompleteAccImpl(component);
|
---|
| 87 | }
|
---|
| 88 |
|
---|
| 89 | /**
|
---|
| 90 | * @private
|
---|
| 91 | * Static variable triggering the hookAccessibility() method.
|
---|
| 92 | * This is used for initializing AutoCompleteAccImpl class to hook its
|
---|
| 93 | * createAccessibilityImplementation() method to AutoComplete class
|
---|
| 94 | * before it gets called from UIComponent.
|
---|
| 95 | */
|
---|
| 96 | private static function hookAccessibility():Boolean
|
---|
| 97 | {
|
---|
| 98 | AutoComplete.createAccessibilityImplementation =
|
---|
| 99 | createAccessibilityImplementation;
|
---|
| 100 |
|
---|
| 101 | return true;
|
---|
| 102 | }
|
---|
| 103 |
|
---|
| 104 | /**
|
---|
| 105 | * Method call for enabling accessibility for a component.
|
---|
| 106 | * this method is required for the compiler to activate
|
---|
| 107 | * the accessibility classes for a component.
|
---|
| 108 | */
|
---|
| 109 | public static function enableAccessibility():void
|
---|
| 110 | {
|
---|
| 111 |
|
---|
| 112 | }
|
---|
| 113 |
|
---|
| 114 | /**
|
---|
| 115 | * @private
|
---|
| 116 | * method for returning the name of the Autocomplete
|
---|
| 117 | *
|
---|
| 118 | * @param childID uint
|
---|
| 119 | *
|
---|
| 120 | * @return Name String
|
---|
| 121 | * @review
|
---|
| 122 | */
|
---|
| 123 | override protected function getName(childID:uint):String
|
---|
| 124 | {
|
---|
| 125 | super.getName(childID);
|
---|
| 126 | var name:String = "";
|
---|
| 127 |
|
---|
| 128 | if (AutoComplete(master).selectedIndex == -1) {
|
---|
| 129 | name = AutoComplete(master).name ;
|
---|
| 130 | } else {
|
---|
| 131 | var lastSelectedIndx:int = AutoComplete(master).selectedIndex + 1;
|
---|
| 132 | name = "Item " + lastSelectedIndx +
|
---|
| 133 | " of " + AutoComplete(master).dataProvider.length;
|
---|
| 134 | }
|
---|
| 135 |
|
---|
| 136 | return name;
|
---|
| 137 | }
|
---|
| 138 |
|
---|
| 139 | /**
|
---|
| 140 | * @private
|
---|
| 141 | * Method for returning the value of the Autocomplete component
|
---|
| 142 | *
|
---|
| 143 | * @param childID uint
|
---|
| 144 | *
|
---|
| 145 | * @return Value String
|
---|
| 146 | * @review
|
---|
| 147 | */
|
---|
| 148 | override public function get_accValue(childID:uint):String
|
---|
| 149 | {
|
---|
| 150 | super.get_accValue(childID);
|
---|
| 151 | var accValue:String = "";
|
---|
| 152 | accValue = AutoComplete(master).value.toString();
|
---|
| 153 | return accValue;
|
---|
| 154 | }
|
---|
| 155 |
|
---|
| 156 | /**
|
---|
| 157 | * @private
|
---|
| 158 | * Method for returning the state of the Autocomplete component
|
---|
| 159 | *
|
---|
| 160 | * @param childID uint
|
---|
| 161 | *
|
---|
| 162 | * @return State uint
|
---|
| 163 | */
|
---|
| 164 | override public function get_accState(childID:uint):uint
|
---|
| 165 | {
|
---|
| 166 | var accState:uint = STATE_SYSTEM_NORMAL;
|
---|
| 167 |
|
---|
| 168 | if (AutoComplete(master).getFocus())
|
---|
| 169 | {
|
---|
| 170 | accState |= STATE_SYSTEM_FOCUSED;
|
---|
| 171 | }
|
---|
| 172 |
|
---|
| 173 | return accState;
|
---|
| 174 | }
|
---|
| 175 |
|
---|
| 176 | /**
|
---|
| 177 | * @private
|
---|
| 178 | * Gets the role for the component.
|
---|
| 179 | *
|
---|
| 180 | * @param childID uint.
|
---|
| 181 | */
|
---|
| 182 | override public function get_accRole(childID:uint):uint
|
---|
| 183 | {
|
---|
| 184 | return ROLE_SYSTEM_TEXT ;
|
---|
| 185 | }
|
---|
| 186 |
|
---|
| 187 | /**
|
---|
| 188 | * @private
|
---|
| 189 | * Array of events that we should listen for from the master component.
|
---|
| 190 | */
|
---|
| 191 | override protected function get eventsToHandle():Array
|
---|
| 192 | {
|
---|
| 193 | return super.eventsToHandle.concat(["valueCommit","change","enter","onFocus"]);
|
---|
| 194 | }
|
---|
| 195 |
|
---|
| 196 | /**
|
---|
| 197 | * @private
|
---|
| 198 | * Override the generic event handler.
|
---|
| 199 | * All AccImpl must implement this to listen for events
|
---|
| 200 | * from its master component.
|
---|
| 201 | */
|
---|
| 202 | override protected function eventHandler(event:Event):void
|
---|
| 203 | {
|
---|
| 204 | switch (event.type)
|
---|
| 205 | {
|
---|
| 206 | case "valueCommit":
|
---|
| 207 | {
|
---|
| 208 | Accessibility.sendEvent(master, 0, EVENT_OBJECT_FOCUS);
|
---|
| 209 | Accessibility.sendEvent(master, 0,EVENT_OBJECT_SELECTION);
|
---|
| 210 | //Accessibility.sendEvent(master, 0, EVENT_OBJECT_VALUECHANGE);
|
---|
| 211 | Accessibility.updateProperties();
|
---|
| 212 | break;
|
---|
| 213 | }
|
---|
| 214 | case "enter":
|
---|
| 215 | {
|
---|
| 216 | Accessibility.sendEvent(master, 0,EVENT_OBJECT_SELECTION);
|
---|
| 217 | Accessibility.updateProperties();
|
---|
| 218 | break;
|
---|
| 219 | }
|
---|
| 220 | case "change":
|
---|
| 221 | {
|
---|
| 222 | Accessibility.sendEvent(master, 0, EVENT_OBJECT_FOCUS);
|
---|
| 223 | Accessibility.sendEvent(master, 0, EVENT_OBJECT_VALUECHANGE);
|
---|
| 224 | Accessibility.updateProperties();
|
---|
| 225 | break;
|
---|
| 226 | }
|
---|
| 227 | case "onFocus":
|
---|
| 228 | {
|
---|
| 229 | Accessibility.sendEvent(master, 0, EVENT_OBJECT_FOCUS);
|
---|
| 230 | Accessibility.updateProperties();
|
---|
| 231 | break;
|
---|
| 232 | }
|
---|
| 233 |
|
---|
| 234 | }
|
---|
| 235 | }
|
---|
| 236 |
|
---|
| 237 | }
|
---|
| 238 | }
|
---|