| 1 |
// |
|---|
| 2 |
// Licensed under the MIT License |
|---|
| 3 |
// |
|---|
| 4 |
// Copyright (C) 2008 TAKANAWA Tomoaki (http://nutsu.com) and |
|---|
| 5 |
// Spark project (www.libspark.org) |
|---|
| 6 |
// |
|---|
| 7 |
// Permission is hereby granted, free of charge, to any person obtaining a copy |
|---|
| 8 |
// of this software and associated documentation files (the "Software"), to deal |
|---|
| 9 |
// in the Software without restriction, including without limitation the rights |
|---|
| 10 |
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
|---|
| 11 |
// copies of the Software, and to permit persons to whom the Software is |
|---|
| 12 |
// furnished to do so, subject to the following conditions: |
|---|
| 13 |
// |
|---|
| 14 |
// The above copyright notice and this permission notice shall be included in |
|---|
| 15 |
// all copies or substantial portions of the Software. |
|---|
| 16 |
// |
|---|
| 17 |
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|---|
| 18 |
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|---|
| 19 |
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|---|
| 20 |
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|---|
| 21 |
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|---|
| 22 |
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
|---|
| 23 |
// THE SOFTWARE. |
|---|
| 24 |
// |
|---|
| 25 |
|
|---|
| 26 |
package snapfit.events |
|---|
| 27 |
{ |
|---|
| 28 |
import flash.events.IEventDispatcher; |
|---|
| 29 |
use namespace ns_fadapter; |
|---|
| 30 |
|
|---|
| 31 |
/** |
|---|
| 32 |
* Abstract Static Adapter |
|---|
| 33 |
* @author nutsu |
|---|
| 34 |
* @version 0.2 |
|---|
| 35 |
*/ |
|---|
| 36 |
public class FAbstractFixAdapter implements IAdapter |
|---|
| 37 |
{ |
|---|
| 38 |
private var _adapter:FAdapter; |
|---|
| 39 |
|
|---|
| 40 |
public function FAbstractFixAdapter( dispatcher_:IEventDispatcher ) |
|---|
| 41 |
{ |
|---|
| 42 |
_adapter = new FAdapter( dispatcher_ ); |
|---|
| 43 |
} |
|---|
| 44 |
|
|---|
| 45 |
public function get dispatcher():IEventDispatcher { return _adapter.dispatcher; } |
|---|
| 46 |
public function set dispatcher( value:IEventDispatcher ):void |
|---|
| 47 |
{ |
|---|
| 48 |
_adapter.dispatcher = value; |
|---|
| 49 |
} |
|---|
| 50 |
|
|---|
| 51 |
public function get adapter():FAdapter |
|---|
| 52 |
{ |
|---|
| 53 |
return _adapter; |
|---|
| 54 |
} |
|---|
| 55 |
|
|---|
| 56 |
/** |
|---|
| 57 |
* Inject Event Handler |
|---|
| 58 |
* |
|---|
| 59 |
* value:Function |
|---|
| 60 |
* value:makeListenerInfo() |
|---|
| 61 |
* value:null ( remove ) |
|---|
| 62 |
* value:Boolean ( abort, resume ) |
|---|
| 63 |
* |
|---|
| 64 |
* @param eventType |
|---|
| 65 |
* @param value |
|---|
| 66 |
*/ |
|---|
| 67 |
protected function inject( eventType:String, value:* ):void |
|---|
| 68 |
{ |
|---|
| 69 |
if ( value is $listenerInfo ) |
|---|
| 70 |
{ |
|---|
| 71 |
_adapter.addEventListener( eventType, value.handler, value.useCapture, value.priority, value.useWeakReference ); |
|---|
| 72 |
} |
|---|
| 73 |
else |
|---|
| 74 |
{ |
|---|
| 75 |
try |
|---|
| 76 |
{ |
|---|
| 77 |
_adapter[eventType] = value; |
|---|
| 78 |
} |
|---|
| 79 |
catch (e:Error) |
|---|
| 80 |
{ |
|---|
| 81 |
throw new TypeError("FAbstractFixAdapter : Type Error"); |
|---|
| 82 |
} |
|---|
| 83 |
} |
|---|
| 84 |
} |
|---|
| 85 |
|
|---|
| 86 |
protected function getlistener( eventType:String ):* |
|---|
| 87 |
{ |
|---|
| 88 |
return _adapter[eventType]; |
|---|
| 89 |
} |
|---|
| 90 |
|
|---|
| 91 |
public function bind( target:* ):void |
|---|
| 92 |
{ |
|---|
| 93 |
; |
|---|
| 94 |
} |
|---|
| 95 |
|
|---|
| 96 |
protected function bindHandlers( target:*, ...handlerNames ):void |
|---|
| 97 |
{ |
|---|
| 98 |
for each( var handlerName:String in handlerNames ) |
|---|
| 99 |
{ |
|---|
| 100 |
try |
|---|
| 101 |
{ |
|---|
| 102 |
if ( target[handlerName] is Function ) |
|---|
| 103 |
this[handlerName] = target[handlerName]; |
|---|
| 104 |
} |
|---|
| 105 |
catch ( e:Error ) |
|---|
| 106 |
{ |
|---|
| 107 |
try |
|---|
| 108 |
{ |
|---|
| 109 |
if ( target.ns_fadapter::[handlerName] is Function ) |
|---|
| 110 |
this[handlerName] = target.ns_fadapter::[handlerName]; |
|---|
| 111 |
} |
|---|
| 112 |
catch ( e:Error ) |
|---|
| 113 |
{ |
|---|
| 114 |
; |
|---|
| 115 |
} |
|---|
| 116 |
} |
|---|
| 117 |
} |
|---|
| 118 |
} |
|---|
| 119 |
|
|---|
| 120 |
/** |
|---|
| 121 |
* @see FAdapterCheckResult |
|---|
| 122 |
*/ |
|---|
| 123 |
public function check( eventType:String ):int |
|---|
| 124 |
{ |
|---|
| 125 |
return _adapter.check( eventType ); |
|---|
| 126 |
} |
|---|
| 127 |
|
|---|
| 128 |
public function abort( eventType:String=null ):void |
|---|
| 129 |
{ |
|---|
| 130 |
_adapter.abort( eventType ); |
|---|
| 131 |
} |
|---|
| 132 |
|
|---|
| 133 |
public function resume( eventType:String=null ):void |
|---|
| 134 |
{ |
|---|
| 135 |
_adapter.resume( eventType ); |
|---|
| 136 |
} |
|---|
| 137 |
|
|---|
| 138 |
public function removeAll():void |
|---|
| 139 |
{ |
|---|
| 140 |
_adapter.removeAll(); |
|---|
| 141 |
} |
|---|
| 142 |
|
|---|
| 143 |
public function getTypes( active_kind:int=-1 ):Array |
|---|
| 144 |
{ |
|---|
| 145 |
return _adapter.getTypes(); |
|---|
| 146 |
} |
|---|
| 147 |
|
|---|
| 148 |
public function oneTime( lo:* ):Boolean |
|---|
| 149 |
{ |
|---|
| 150 |
return FAdapter.oneTime( lo ); |
|---|
| 151 |
} |
|---|
| 152 |
|
|---|
| 153 |
public function filter( lo:*, filterfunc:Function, remove:Boolean = false ):Boolean |
|---|
| 154 |
{ |
|---|
| 155 |
return FAdapter.filter( lo, filterfunc, remove ); |
|---|
| 156 |
} |
|---|
| 157 |
|
|---|
| 158 |
public function clearFilter( lo:* ):Boolean |
|---|
| 159 |
{ |
|---|
| 160 |
return FAdapter.clearFilter( lo ); |
|---|
| 161 |
} |
|---|
| 162 |
|
|---|
| 163 |
public function makeListenerInfo( handler:Function, useCapture:Boolean=false, priority:int=0, useWeakReference:Boolean=false ):$listenerInfo |
|---|
| 164 |
{ |
|---|
| 165 |
return new $listenerInfo( handler, useCapture, priority, useWeakReference ); |
|---|
| 166 |
} |
|---|
| 167 |
} |
|---|
| 168 |
} |
|---|
| 169 |
|
|---|
| 170 |
class $listenerInfo |
|---|
| 171 |
{ |
|---|
| 172 |
public var handler:Function; |
|---|
| 173 |
public var useCapture:Boolean; |
|---|
| 174 |
public var priority:int; |
|---|
| 175 |
public var useWeakReference:Boolean; |
|---|
| 176 |
|
|---|
| 177 |
public function $listenerInfo( handler_:Function, useCapture_:Boolean, priority_:int, useWeakReference_:Boolean ) |
|---|
| 178 |
{ |
|---|
| 179 |
handler = handler_; |
|---|
| 180 |
useCapture = useCapture_; |
|---|
| 181 |
priority = priority_; |
|---|
| 182 |
useWeakReference = useWeakReference_; |
|---|
| 183 |
} |
|---|
| 184 |
} |
|---|