1 Clazz.declarePackage ("java.beans");
\r
2 Clazz.load (null, "java.beans.ChangeListenerMap", ["java.util.ArrayList", "$.Collections", "$.EventListenerProxy", "$.HashMap"], function () {
\r
3 c$ = Clazz.decorateAsClass (function () {
\r
5 Clazz.instantialize (this, arguments);
\r
6 }, java.beans, "ChangeListenerMap");
\r
7 Clazz.defineMethod (c$, "add",
\r
8 function (name, listener) {
\r
9 if (this.map == null) {
\r
10 this.map = new java.util.HashMap ();
\r
11 }var array = this.map.get (name);
\r
12 var size = (array != null) ? array.length : 0;
\r
13 var clone = this.newArray (size + 1);
\r
14 clone[size] = listener;
\r
15 if (array != null) {
\r
16 System.arraycopy (array, 0, clone, 0, size);
\r
17 }this.map.put (name, clone);
\r
19 Clazz.defineMethod (c$, "remove",
\r
20 function (name, listener) {
\r
21 if (this.map != null) {
\r
22 var array = this.map.get (name);
\r
23 if (array != null) {
\r
24 for (var i = 0; i < array.length; i++) {
\r
25 if (listener.equals (array[i])) {
\r
26 var size = array.length - 1;
\r
28 var clone = this.newArray (size);
\r
29 System.arraycopy (array, 0, clone, 0, i);
\r
30 System.arraycopy (array, i + 1, clone, i, size - i);
\r
31 this.map.put (name, clone);
\r
33 this.map.remove (name);
\r
34 if (this.map.isEmpty ()) {
\r
39 Clazz.defineMethod (c$, "get",
\r
41 return (this.map != null) ? this.map.get (name) : null;
\r
43 Clazz.defineMethod (c$, "set",
\r
44 function (name, listeners) {
\r
45 if (listeners != null) {
\r
46 if (this.map == null) {
\r
47 this.map = new java.util.HashMap ();
\r
48 }this.map.put (name, listeners);
\r
49 } else if (this.map != null) {
\r
50 this.map.remove (name);
\r
51 if (this.map.isEmpty ()) {
\r
54 Clazz.defineMethod (c$, "getListeners",
\r
56 if (this.map == null) {
\r
57 return this.newArray (0);
\r
58 }var list = new java.util.ArrayList ();
\r
59 var listeners = this.map.get (null);
\r
60 if (listeners != null) {
\r
61 for (var listener, $listener = 0, $$listener = listeners; $listener < $$listener.length && ((listener = $$listener[$listener]) || true); $listener++) {
\r
62 list.add (listener);
\r
64 }for (var entry, $entry = this.map.entrySet ().iterator (); $entry.hasNext () && ((entry = $entry.next ()) || true);) {
\r
65 var name = entry.getKey ();
\r
67 for (var listener, $listener = 0, $$listener = entry.getValue (); $listener < $$listener.length && ((listener = $$listener[$listener]) || true); $listener++) {
\r
68 list.add (this.newProxy (name, listener));
\r
71 return list.toArray (this.newArray (list.size ()));
\r
73 Clazz.defineMethod (c$, "getListeners",
\r
76 var listeners = this.get (name);
\r
77 if (listeners != null) {
\r
78 return listeners.clone ();
\r
79 }}return this.newArray (0);
\r
81 Clazz.defineMethod (c$, "hasListeners",
\r
83 if (this.map == null) {
\r
85 }var array = this.map.get (null);
\r
86 return (array != null) || ((name != null) && (null != this.map.get (name)));
\r
88 Clazz.defineMethod (c$, "getEntries",
\r
90 return (this.map != null) ? this.map.entrySet () : java.util.Collections.emptySet ();
\r
92 Clazz.defineMethod (c$, "extract",
\r
93 function (listener) {
\r
94 while (Clazz.instanceOf (listener, java.util.EventListenerProxy)) {
\r
95 var proxy = listener;
\r
96 listener = proxy.getListener ();
\r