da53c9e840f3a9bd188ebda680a635b70415b1e3
[jalviewjs.git] / site / j2s / javax / swing / AncestorNotifier.js
1 Clazz.declarePackage ("javax.swing");\r
2 Clazz.load (["java.awt.event.ComponentListener", "java.beans.PropertyChangeListener", "javax.swing.event.EventListenerList"], "javax.swing.AncestorNotifier", ["java.awt.Window", "javax.swing.JComponent", "javax.swing.event.AncestorEvent", "$.AncestorListener"], function () {\r
3 c$ = Clazz.decorateAsClass (function () {\r
4 this.firstInvisibleAncestor = null;\r
5 this.listenerList = null;\r
6 this.root = null;\r
7 Clazz.instantialize (this, arguments);\r
8 }, javax.swing, "AncestorNotifier", null, [java.awt.event.ComponentListener, java.beans.PropertyChangeListener]);\r
9 Clazz.prepareFields (c$, function () {\r
10 this.listenerList =  new javax.swing.event.EventListenerList ();\r
11 });\r
12 Clazz.makeConstructor (c$, \r
13 function (root) {\r
14 this.root = root;\r
15 this.addListeners (root, true);\r
16 }, "javax.swing.JComponent");\r
17 Clazz.defineMethod (c$, "addAncestorListener", \r
18 function (l) {\r
19 this.listenerList.add (javax.swing.event.AncestorListener, l);\r
20 }, "javax.swing.event.AncestorListener");\r
21 Clazz.defineMethod (c$, "removeAncestorListener", \r
22 function (l) {\r
23 this.listenerList.remove (javax.swing.event.AncestorListener, l);\r
24 }, "javax.swing.event.AncestorListener");\r
25 Clazz.defineMethod (c$, "getAncestorListeners", \r
26 function () {\r
27 return this.listenerList.getListeners (javax.swing.event.AncestorListener);\r
28 });\r
29 Clazz.defineMethod (c$, "fireAncestorAdded", \r
30 function (source, id, ancestor, ancestorParent) {\r
31 var listeners = this.listenerList.getListenerList ();\r
32 for (var i = listeners.length - 2; i >= 0; i -= 2) {\r
33 if (listeners[i] === javax.swing.event.AncestorListener) {\r
34 var ancestorEvent =  new javax.swing.event.AncestorEvent (source, id, ancestor, ancestorParent);\r
35 (listeners[i + 1]).ancestorAdded (ancestorEvent);\r
36 }}\r
37 }, "javax.swing.JComponent,~N,java.awt.Container,java.awt.Container");\r
38 Clazz.defineMethod (c$, "fireAncestorRemoved", \r
39 function (source, id, ancestor, ancestorParent) {\r
40 var listeners = this.listenerList.getListenerList ();\r
41 for (var i = listeners.length - 2; i >= 0; i -= 2) {\r
42 if (listeners[i] === javax.swing.event.AncestorListener) {\r
43 var ancestorEvent =  new javax.swing.event.AncestorEvent (source, id, ancestor, ancestorParent);\r
44 (listeners[i + 1]).ancestorRemoved (ancestorEvent);\r
45 }}\r
46 }, "javax.swing.JComponent,~N,java.awt.Container,java.awt.Container");\r
47 Clazz.defineMethod (c$, "fireAncestorMoved", \r
48 function (source, id, ancestor, ancestorParent) {\r
49 var listeners = this.listenerList.getListenerList ();\r
50 for (var i = listeners.length - 2; i >= 0; i -= 2) {\r
51 if (listeners[i] === javax.swing.event.AncestorListener) {\r
52 var ancestorEvent =  new javax.swing.event.AncestorEvent (source, id, ancestor, ancestorParent);\r
53 (listeners[i + 1]).ancestorMoved (ancestorEvent);\r
54 }}\r
55 }, "javax.swing.JComponent,~N,java.awt.Container,java.awt.Container");\r
56 Clazz.defineMethod (c$, "removeAllListeners", \r
57 function () {\r
58 this.removeListeners (this.root);\r
59 });\r
60 Clazz.defineMethod (c$, "addListeners", \r
61 function (ancestor, addToFirst) {\r
62 var a;\r
63 this.firstInvisibleAncestor = null;\r
64 for (a = ancestor; this.firstInvisibleAncestor == null; a = a.getParent ()) {\r
65 if (addToFirst || a !== ancestor) {\r
66 a.addComponentListener (this);\r
67 if (Clazz.instanceOf (a, javax.swing.JComponent)) {\r
68 var jAncestor = a;\r
69 jAncestor.addPropertyChangeListener (this);\r
70 }}if (!a.isVisible () || a.getParent () == null || Clazz.instanceOf (a, java.awt.Window)) {\r
71 this.firstInvisibleAncestor = a;\r
72 }}\r
73 if (Clazz.instanceOf (this.firstInvisibleAncestor, java.awt.Window) && this.firstInvisibleAncestor.isVisible ()) {\r
74 this.firstInvisibleAncestor = null;\r
75 }}, "java.awt.Component,~B");\r
76 Clazz.defineMethod (c$, "removeListeners", \r
77 function (ancestor) {\r
78 var a;\r
79 for (a = ancestor; a != null; a = a.getParent ()) {\r
80 a.removeComponentListener (this);\r
81 if (Clazz.instanceOf (a, javax.swing.JComponent)) {\r
82 var jAncestor = a;\r
83 jAncestor.removePropertyChangeListener (this);\r
84 }if (a === this.firstInvisibleAncestor || Clazz.instanceOf (a, java.awt.Window)) {\r
85 break;\r
86 }}\r
87 }, "java.awt.Component");\r
88 Clazz.overrideMethod (c$, "componentResized", \r
89 function (e) {\r
90 }, "java.awt.event.ComponentEvent");\r
91 Clazz.overrideMethod (c$, "componentMoved", \r
92 function (e) {\r
93 var source = e.getComponent ();\r
94 this.fireAncestorMoved (this.root, 3, source, source.getParent ());\r
95 }, "java.awt.event.ComponentEvent");\r
96 Clazz.overrideMethod (c$, "componentShown", \r
97 function (e) {\r
98 var ancestor = e.getComponent ();\r
99 if (ancestor === this.firstInvisibleAncestor) {\r
100 this.addListeners (ancestor, false);\r
101 if (this.firstInvisibleAncestor == null) {\r
102 this.fireAncestorAdded (this.root, 1, ancestor, ancestor.getParent ());\r
103 }}}, "java.awt.event.ComponentEvent");\r
104 Clazz.overrideMethod (c$, "componentHidden", \r
105 function (e) {\r
106 var ancestor = e.getComponent ();\r
107 var needsNotify = this.firstInvisibleAncestor == null;\r
108 if (!(Clazz.instanceOf (ancestor, java.awt.Window))) {\r
109 this.removeListeners (ancestor.getParent ());\r
110 }this.firstInvisibleAncestor = ancestor;\r
111 if (needsNotify) {\r
112 this.fireAncestorRemoved (this.root, 2, ancestor, ancestor.getParent ());\r
113 }}, "java.awt.event.ComponentEvent");\r
114 Clazz.overrideMethod (c$, "propertyChange", \r
115 function (evt) {\r
116 var s = evt.getPropertyName ();\r
117 if (s != null && (s.equals ("parent") || s.equals ("ancestor"))) {\r
118 var component = evt.getSource ();\r
119 if (evt.getNewValue () != null) {\r
120 if (component === this.firstInvisibleAncestor) {\r
121 this.addListeners (component, false);\r
122 if (this.firstInvisibleAncestor == null) {\r
123 this.fireAncestorAdded (this.root, 1, component, component.getParent ());\r
124 }}} else {\r
125 var needsNotify = this.firstInvisibleAncestor == null;\r
126 var oldParent = evt.getOldValue ();\r
127 this.removeListeners (oldParent);\r
128 this.firstInvisibleAncestor = component;\r
129 if (needsNotify) {\r
130 this.fireAncestorRemoved (this.root, 2, component, oldParent);\r
131 }}}}, "java.beans.PropertyChangeEvent");\r
132 });\r