| 1 |
/** |
|---|
| 2 |
* The CheckBox Renderer Class for AIR Application |
|---|
| 3 |
* |
|---|
| 4 |
* @author Copyright (c) 2008 daoki2 |
|---|
| 5 |
* @version 1.0.1 |
|---|
| 6 |
* @link http://snippets.libspark.org/ |
|---|
| 7 |
* @link http://homepage.mac.com/daoki2/ |
|---|
| 8 |
* |
|---|
| 9 |
* Copyright (c) 2008 daoki2 |
|---|
| 10 |
* |
|---|
| 11 |
* Permission is hereby granted, free of charge, to any person obtaining a copy |
|---|
| 12 |
* of this software and associated documentation files (the "Software"), to deal |
|---|
| 13 |
* in the Software without restriction, including without limitation the rights |
|---|
| 14 |
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
|---|
| 15 |
* copies of the Software, and to permit persons to whom the Software is |
|---|
| 16 |
* furnished to do so, subject to the following conditions: |
|---|
| 17 |
* |
|---|
| 18 |
* The above copyright notice and this permission notice shall be included in |
|---|
| 19 |
* all copies or substantial portions of the Software. |
|---|
| 20 |
* |
|---|
| 21 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|---|
| 22 |
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|---|
| 23 |
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|---|
| 24 |
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|---|
| 25 |
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|---|
| 26 |
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
|---|
| 27 |
* THE SOFTWARE. |
|---|
| 28 |
*/ |
|---|
| 29 |
|
|---|
| 30 |
package org.libspark.snippets.controls.SQLControlsClasses { |
|---|
| 31 |
import flash.events.Event; |
|---|
| 32 |
import flash.events.MouseEvent; |
|---|
| 33 |
import mx.containers.VBox; |
|---|
| 34 |
import mx.controls.CheckBox; |
|---|
| 35 |
import mx.events.FlexEvent; |
|---|
| 36 |
import mx.binding.utils.ChangeWatcher; |
|---|
| 37 |
|
|---|
| 38 |
public class checkBoxRenderer extends VBox { |
|---|
| 39 |
[Bindable] |
|---|
| 40 |
public var checkBoxSelected:Boolean; |
|---|
| 41 |
public var checkBoxEnabled:Boolean = false; |
|---|
| 42 |
public var dataField:String; |
|---|
| 43 |
private var cb:CheckBox = new CheckBox(); |
|---|
| 44 |
private var dataProvider:Object; |
|---|
| 45 |
public function checkBoxRenderer() { |
|---|
| 46 |
super(); |
|---|
| 47 |
setStyle("horizontalAlign", "center"); |
|---|
| 48 |
ChangeWatcher.watch(this, "checkBoxSelected", onChanged); |
|---|
| 49 |
cb.addEventListener(MouseEvent.CLICK, onClick); |
|---|
| 50 |
addChild(cb); |
|---|
| 51 |
} |
|---|
| 52 |
|
|---|
| 53 |
override public function set data(value:Object):void { |
|---|
| 54 |
cb.enabled = checkBoxEnabled; |
|---|
| 55 |
checkBoxSelected = value[dataField]; |
|---|
| 56 |
dataProvider = value; |
|---|
| 57 |
} |
|---|
| 58 |
|
|---|
| 59 |
private function onChanged(event:Event):void { |
|---|
| 60 |
cb.selected = checkBoxSelected; |
|---|
| 61 |
} |
|---|
| 62 |
|
|---|
| 63 |
private function onClick(event:MouseEvent):void { |
|---|
| 64 |
checkBoxSelected = cb.selected; |
|---|
| 65 |
if (dataProvider != null) |
|---|
| 66 |
dataProvider[dataField] = cb.selected; |
|---|
| 67 |
} |
|---|
| 68 |
} |
|---|
| 69 |
} |
|---|