JAL-1807 Bob's JalviewJS prototype first commit
[jalviewjs.git] / site / j2s / jssun / awt / AppContext.js
1 Clazz.declarePackage ("jssun.awt");\r
2 Clazz.load (["java.lang.StringBuffer", "java.util.Collections", "$.HashMap", "$.IdentityHashMap"], ["jssun.awt.AppContext", "$.MostRecentThreadAppContext", "$.MostRecentKeyValue"], ["java.lang.Thread", "java.util.HashSet", "java.beans.PropertyChangeSupport"], function () {\r
3 c$ = Clazz.decorateAsClass (function () {\r
4 this.table = null;\r
5 this.threadGroup = null;\r
6 this.changeSupport = null;\r
7 this.$isDisposed = false;\r
8 this.mostRecentKeyValue = null;\r
9 this.shadowMostRecentKeyValue = null;\r
10 Clazz.instantialize (this, arguments);\r
11 }, jssun.awt, "AppContext");\r
12 Clazz.prepareFields (c$, function () {\r
13 this.table =  new java.util.HashMap ();\r
14 });\r
15 c$.getAppContexts = Clazz.defineMethod (c$, "getAppContexts", \r
16 function () {\r
17 return  new java.util.HashSet (jssun.awt.AppContext.threadGroup2appContext.values ());\r
18 });\r
19 Clazz.defineMethod (c$, "isDisposed", \r
20 function () {\r
21 return this.$isDisposed;\r
22 });\r
23 Clazz.makeConstructor (c$, \r
24 function (threadGroup) {\r
25 jssun.awt.AppContext.numAppContexts++;\r
26 this.threadGroup = threadGroup;\r
27 jssun.awt.AppContext.threadGroup2appContext.put (threadGroup, this);\r
28 }, "ThreadGroup");\r
29 c$.getAppContext = Clazz.defineMethod (c$, "getAppContext", \r
30 function () {\r
31 var currentThread = Thread.currentThread ();\r
32 var appContext = null;\r
33 var recent = jssun.awt.AppContext.mostRecentThreadAppContext;\r
34 if ((recent != null) && (recent.thread === currentThread)) {\r
35 appContext = recent.appContext;\r
36 } else {\r
37 var currentThreadGroup = currentThread.getThreadGroup ();\r
38 var threadGroup = currentThreadGroup;\r
39 appContext = jssun.awt.AppContext.threadGroup2appContext.get (threadGroup);\r
40 while (appContext == null) {\r
41 threadGroup = threadGroup.getParent ();\r
42 if (threadGroup == null) {\r
43 return null;\r
44 }appContext = jssun.awt.AppContext.threadGroup2appContext.get (threadGroup);\r
45 }\r
46 for (var tg = currentThreadGroup; tg !== threadGroup; tg = tg.getParent ()) {\r
47 jssun.awt.AppContext.threadGroup2appContext.put (tg, appContext);\r
48 }\r
49 jssun.awt.AppContext.mostRecentThreadAppContext =  new jssun.awt.MostRecentThreadAppContext (currentThread, appContext);\r
50 }return appContext;\r
51 });\r
52 c$.isMainContext = Clazz.defineMethod (c$, "isMainContext", \r
53 function (ctx) {\r
54 return false;\r
55 }, "jssun.awt.AppContext");\r
56 Clazz.defineMethod (c$, "dispose", \r
57 function () {\r
58 });\r
59 Clazz.defineMethod (c$, "get", \r
60 function (key) {\r
61 {\r
62 var recent = this.mostRecentKeyValue;\r
63 if ((recent != null) && (recent.key === key)) {\r
64 return recent.value;\r
65 }var value = this.table.get (key);\r
66 if (this.mostRecentKeyValue == null) {\r
67 this.mostRecentKeyValue =  new jssun.awt.MostRecentKeyValue (key, value);\r
68 this.shadowMostRecentKeyValue =  new jssun.awt.MostRecentKeyValue (key, value);\r
69 } else {\r
70 var auxKeyValue = this.mostRecentKeyValue;\r
71 this.shadowMostRecentKeyValue.setPair (key, value);\r
72 this.mostRecentKeyValue = this.shadowMostRecentKeyValue;\r
73 this.shadowMostRecentKeyValue = auxKeyValue;\r
74 }return value;\r
75 }}, "~O");\r
76 Clazz.defineMethod (c$, "put", \r
77 function (key, value) {\r
78 {\r
79 var recent = this.mostRecentKeyValue;\r
80 if ((recent != null) && (recent.key === key)) recent.value = value;\r
81 return this.table.put (key, value);\r
82 }}, "~O,~O");\r
83 Clazz.defineMethod (c$, "remove", \r
84 function (key) {\r
85 {\r
86 var recent = this.mostRecentKeyValue;\r
87 if ((recent != null) && (recent.key === key)) recent.value = null;\r
88 return this.table.remove (key);\r
89 }}, "~O");\r
90 Clazz.defineMethod (c$, "getThreadGroup", \r
91 function () {\r
92 return this.threadGroup;\r
93 });\r
94 Clazz.overrideMethod (c$, "toString", \r
95 function () {\r
96 return this.getClass ().getName () + "[threadGroup=" + this.threadGroup.getName () + "]";\r
97 });\r
98 Clazz.defineMethod (c$, "getPropertyChangeListeners", \r
99 function () {\r
100 if (this.changeSupport == null) {\r
101 return  new Array (0);\r
102 }return this.changeSupport.getPropertyChangeListeners ();\r
103 });\r
104 Clazz.defineMethod (c$, "addPropertyChangeListener", \r
105 function (propertyName, listener) {\r
106 if (listener == null) {\r
107 return;\r
108 }if (this.changeSupport == null) {\r
109 this.changeSupport =  new java.beans.PropertyChangeSupport (this);\r
110 }this.changeSupport.addPropertyChangeListener (propertyName, listener);\r
111 }, "~S,java.beans.PropertyChangeListener");\r
112 Clazz.defineMethod (c$, "removePropertyChangeListener", \r
113 function (propertyName, listener) {\r
114 if (listener == null || this.changeSupport == null) {\r
115 return;\r
116 }this.changeSupport.removePropertyChangeListener (propertyName, listener);\r
117 }, "~S,java.beans.PropertyChangeListener");\r
118 Clazz.defineMethod (c$, "getPropertyChangeListeners", \r
119 function (propertyName) {\r
120 if (this.changeSupport == null) {\r
121 return  new Array (0);\r
122 }return this.changeSupport.getPropertyChangeListeners (propertyName);\r
123 }, "~S");\r
124 c$.EVENT_QUEUE_KEY = c$.prototype.EVENT_QUEUE_KEY =  new StringBuffer ("EventQueue");\r
125 c$.threadGroup2appContext = c$.prototype.threadGroup2appContext = java.util.Collections.synchronizedMap ( new java.util.IdentityHashMap ());\r
126 Clazz.defineStatics (c$,\r
127 "DISPOSED_PROPERTY_NAME", "disposed",\r
128 "GUI_DISPOSED", "guidisposed",\r
129 "numAppContexts", 0,\r
130 "mostRecentThreadAppContext", null);\r
131 c$ = Clazz.decorateAsClass (function () {\r
132 this.thread = null;\r
133 this.appContext = null;\r
134 Clazz.instantialize (this, arguments);\r
135 }, jssun.awt, "MostRecentThreadAppContext");\r
136 Clazz.makeConstructor (c$, \r
137 function (key, value) {\r
138 this.thread = key;\r
139 this.appContext = value;\r
140 }, "Thread,jssun.awt.AppContext");\r
141 c$ = Clazz.decorateAsClass (function () {\r
142 this.key = null;\r
143 this.value = null;\r
144 Clazz.instantialize (this, arguments);\r
145 }, jssun.awt, "MostRecentKeyValue");\r
146 Clazz.makeConstructor (c$, \r
147 function (k, v) {\r
148 this.key = k;\r
149 this.value = v;\r
150 }, "~O,~O");\r
151 Clazz.defineMethod (c$, "setPair", \r
152 function (k, v) {\r
153 this.key = k;\r
154 this.value = v;\r
155 }, "~O,~O");\r
156 });\r