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