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