JAL-1807 Bob's JalviewJS prototype first commit
[jalviewjs.git] / site / j2s / java / beans / ChangeListenerMap.js
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
4 this.map = null;\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
18 }, "~S,~O");\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
27 if (size > 0) {\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
32 } else {\r
33 this.map.remove (name);\r
34 if (this.map.isEmpty ()) {\r
35 this.map = null;\r
36 }}break;\r
37 }}\r
38 }}}, "~S,~O");\r
39 Clazz.defineMethod (c$, "get", \r
40 function (name) {\r
41 return (this.map != null) ? this.map.get (name) : null;\r
42 }, "~S");\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
52 this.map = null;\r
53 }}}, "~S,~A");\r
54 Clazz.defineMethod (c$, "getListeners", \r
55 function () {\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
63 }\r
64 }for (var entry, $entry = this.map.entrySet ().iterator (); $entry.hasNext () && ((entry = $entry.next ()) || true);) {\r
65 var name = entry.getKey ();\r
66 if (name != null) {\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
69 }\r
70 }}\r
71 return list.toArray (this.newArray (list.size ()));\r
72 });\r
73 Clazz.defineMethod (c$, "getListeners", \r
74 function (name) {\r
75 if (name != null) {\r
76 var listeners = this.get (name);\r
77 if (listeners != null) {\r
78 return listeners.clone ();\r
79 }}return this.newArray (0);\r
80 }, "~S");\r
81 Clazz.defineMethod (c$, "hasListeners", \r
82 function (name) {\r
83 if (this.map == null) {\r
84 return false;\r
85 }var array = this.map.get (null);\r
86 return (array != null) || ((name != null) && (null != this.map.get (name)));\r
87 }, "~S");\r
88 Clazz.defineMethod (c$, "getEntries", \r
89 function () {\r
90 return (this.map != null) ? this.map.entrySet () : java.util.Collections.emptySet ();\r
91 });\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
97 }\r
98 return listener;\r
99 }, "~O");\r
100 });\r