ca08df5269f2977b3e63433b1b7906aba67ec472
[jalviewjs.git] / site / swingjs / j2s / javax / swing / text / ComponentView.js
1 Clazz.declarePackage ("javax.swing.text");
2 Clazz.load (["java.awt.Container", "java.beans.PropertyChangeListener", "javax.swing.text.View"], "javax.swing.text.ComponentView", ["java.lang.IllegalArgumentException", "java.awt.Dimension", "$.Rectangle", "javax.swing.SwingUtilities", "javax.swing.text.AbstractDocument", "$.BadLocationException", "$.Position", "$.StyleConstants"], function () {
3 c$ = Clazz.decorateAsClass (function () {
4 this.createdC = null;
5 this.c = null;
6 if (!Clazz.isClassDefined ("javax.swing.text.ComponentView.Invalidator")) {
7 javax.swing.text.ComponentView.$ComponentView$Invalidator$ ();
8 }
9 Clazz.instantialize (this, arguments);
10 }, javax.swing.text, "ComponentView", javax.swing.text.View);
11 Clazz.defineMethod (c$, "createComponent", 
12 function () {
13 var attr = this.getElement ().getAttributes ();
14 var comp = javax.swing.text.StyleConstants.getComponent (attr);
15 return comp;
16 });
17 Clazz.defineMethod (c$, "getComponent", 
18 function () {
19 return this.createdC;
20 });
21 Clazz.overrideMethod (c$, "paint", 
22 function (g, a) {
23 if (this.c != null) {
24 var alloc = (Clazz.instanceOf (a, java.awt.Rectangle)) ? a : a.getBounds ();
25 this.c.setBounds (alloc.x, alloc.y, alloc.width, alloc.height);
26 }}, "java.awt.Graphics,java.awt.Shape");
27 Clazz.overrideMethod (c$, "getPreferredSpan", 
28 function (axis) {
29 if ((axis != 0) && (axis != 1)) {
30 throw  new IllegalArgumentException ("Invalid axis: " + axis);
31 }if (this.c != null) {
32 var size = this.c.getPreferredSize ();
33 if (axis == 0) {
34 return size.width;
35 } else {
36 return size.height;
37 }}return 0;
38 }, "~N");
39 Clazz.overrideMethod (c$, "getMinimumSpan", 
40 function (axis) {
41 if ((axis != 0) && (axis != 1)) {
42 throw  new IllegalArgumentException ("Invalid axis: " + axis);
43 }if (this.c != null) {
44 var size = this.c.getMinimumSize ();
45 if (axis == 0) {
46 return size.width;
47 } else {
48 return size.height;
49 }}return 0;
50 }, "~N");
51 Clazz.overrideMethod (c$, "getMaximumSpan", 
52 function (axis) {
53 if ((axis != 0) && (axis != 1)) {
54 throw  new IllegalArgumentException ("Invalid axis: " + axis);
55 }if (this.c != null) {
56 var size = this.c.getMaximumSize ();
57 if (axis == 0) {
58 return size.width;
59 } else {
60 return size.height;
61 }}return 0;
62 }, "~N");
63 Clazz.defineMethod (c$, "getAlignment", 
64 function (axis) {
65 if (this.c != null) {
66 switch (axis) {
67 case 0:
68 return this.c.getAlignmentX ();
69 case 1:
70 return this.c.getAlignmentY ();
71 }
72 }return Clazz.superCall (this, javax.swing.text.ComponentView, "getAlignment", [axis]);
73 }, "~N");
74 Clazz.defineMethod (c$, "setParent", 
75 function (p) {
76 Clazz.superCall (this, javax.swing.text.ComponentView, "setParent", [p]);
77 if (javax.swing.SwingUtilities.isEventDispatchThread ()) {
78 this.setComponentParent ();
79 } else {
80 var callSetComponentParent = ((Clazz.isClassDefined ("javax.swing.text.ComponentView$1") ? 0 : javax.swing.text.ComponentView.$ComponentView$1$ ()), Clazz.innerTypeInstance (javax.swing.text.ComponentView$1, this, null));
81 javax.swing.SwingUtilities.invokeLater (callSetComponentParent);
82 }}, "javax.swing.text.View");
83 Clazz.defineMethod (c$, "setComponentParent", 
84 function () {
85 var p = this.getParent ();
86 if (p != null) {
87 var parent = this.getContainer ();
88 if (parent != null) {
89 if (this.c == null) {
90 var comp = this.createComponent ();
91 if (comp != null) {
92 this.createdC = comp;
93 this.c = Clazz.innerTypeInstance (javax.swing.text.ComponentView.Invalidator, this, null, comp);
94 }}if (this.c != null) {
95 if (this.c.getParent () == null) {
96 parent.add (this.c, this);
97 parent.addPropertyChangeListener ("enabled", this.c);
98 }}}} else {
99 if (this.c != null) {
100 var parent = this.c.getParent ();
101 if (parent != null) {
102 parent.remove (this.c);
103 parent.removePropertyChangeListener ("enabled", this.c);
104 }}}});
105 Clazz.defineMethod (c$, "modelToView", 
106 function (pos, a, b) {
107 var p0 = this.getStartOffset ();
108 var p1 = this.getEndOffset ();
109 if ((pos >= p0) && (pos <= p1)) {
110 var r = a.getBounds ();
111 if (pos == p1) {
112 r.x += r.width;
113 }r.width = 0;
114 return r;
115 }throw  new javax.swing.text.BadLocationException (pos + " not in range " + p0 + "," + p1, pos);
116 }, "~N,java.awt.Shape,javax.swing.text.Position.Bias");
117 Clazz.defineMethod (c$, "viewToModel", 
118 function (x, y, a, bias) {
119 var alloc = a;
120 if (x < alloc.x + (Clazz.doubleToInt (alloc.width / 2))) {
121 bias[0] = javax.swing.text.Position.Bias.Forward;
122 return this.getStartOffset ();
123 }bias[0] = javax.swing.text.Position.Bias.Backward;
124 return this.getEndOffset ();
125 }, "~N,~N,java.awt.Shape,~A");
126 c$.$ComponentView$Invalidator$ = function () {
127 Clazz.pu$h(self.c$);
128 c$ = Clazz.decorateAsClass (function () {
129 Clazz.prepareCallback (this, arguments);
130 this.min = null;
131 this.pref = null;
132 this.max = null;
133 this.yalign = 0;
134 this.xalign = 0;
135 Clazz.instantialize (this, arguments);
136 }, javax.swing.text.ComponentView, "Invalidator", java.awt.Container, java.beans.PropertyChangeListener);
137 Clazz.makeConstructor (c$, 
138 function (a) {
139 Clazz.superConstructor (this, javax.swing.text.ComponentView.Invalidator, []);
140 this.setLayout (null);
141 this.add (a);
142 this.cacheChildSizes ();
143 }, "java.awt.Component");
144 Clazz.defineMethod (c$, "invalidate", 
145 function () {
146 Clazz.superCall (this, javax.swing.text.ComponentView.Invalidator, "invalidate", []);
147 if (this.getParent () != null) {
148 this.b$["javax.swing.text.ComponentView"].preferenceChanged (null, true, true);
149 }});
150 Clazz.overrideMethod (c$, "doLayout", 
151 function () {
152 this.cacheChildSizes ();
153 });
154 Clazz.defineMethod (c$, "setBounds", 
155 function (a, b, c, d) {
156 Clazz.superCall (this, javax.swing.text.ComponentView.Invalidator, "setBounds", [a, b, c, d]);
157 if (this.getComponentCount () > 0) {
158 this.getComponent (0).setSize (c, d);
159 }this.cacheChildSizes ();
160 }, "~N,~N,~N,~N");
161 Clazz.defineMethod (c$, "validateIfNecessary", 
162 function () {
163 if (!this.isValid ()) {
164 this.validate ();
165 }});
166 Clazz.defineMethod (c$, "cacheChildSizes", 
167  function () {
168 if (this.getComponentCount () > 0) {
169 var a = this.getComponent (0);
170 this.min = a.getMinimumSize ();
171 this.pref = a.getPreferredSize ();
172 this.max = a.getMaximumSize ();
173 this.yalign = a.getAlignmentY ();
174 this.xalign = a.getAlignmentX ();
175 } else {
176 this.min = this.pref = this.max =  new java.awt.Dimension (0, 0);
177 }});
178 Clazz.defineMethod (c$, "setVisible", 
179 function (a) {
180 Clazz.superCall (this, javax.swing.text.ComponentView.Invalidator, "setVisible", [a]);
181 if (this.getComponentCount () > 0) {
182 this.getComponent (0).setVisible (a);
183 }}, "~B");
184 Clazz.overrideMethod (c$, "isShowing", 
185 function () {
186 return true;
187 });
188 Clazz.overrideMethod (c$, "getMinimumSize", 
189 function () {
190 this.validateIfNecessary ();
191 return this.min;
192 });
193 Clazz.overrideMethod (c$, "getPreferredSize", 
194 function () {
195 this.validateIfNecessary ();
196 return this.pref;
197 });
198 Clazz.overrideMethod (c$, "getMaximumSize", 
199 function () {
200 this.validateIfNecessary ();
201 return this.max;
202 });
203 Clazz.overrideMethod (c$, "getAlignmentX", 
204 function () {
205 this.validateIfNecessary ();
206 return this.xalign;
207 });
208 Clazz.overrideMethod (c$, "getAlignmentY", 
209 function () {
210 this.validateIfNecessary ();
211 return this.yalign;
212 });
213 Clazz.overrideMethod (c$, "propertyChange", 
214 function (a) {
215 var b = a.getNewValue ();
216 if (this.getComponentCount () > 0) {
217 this.getComponent (0).setEnabled ((b).booleanValue ());
218 }}, "java.beans.PropertyChangeEvent");
219 c$ = Clazz.p0p ();
220 };
221 c$.$ComponentView$1$ = function () {
222 Clazz.pu$h(self.c$);
223 c$ = Clazz.declareAnonymous (javax.swing.text, "ComponentView$1", null, Runnable);
224 Clazz.overrideMethod (c$, "run", 
225 function () {
226 var doc = this.b$["javax.swing.text.ComponentView"].getDocument ();
227 try {
228 if (Clazz.instanceOf (doc, javax.swing.text.AbstractDocument)) {
229 (doc).readLock ();
230 }this.b$["javax.swing.text.ComponentView"].setComponentParent ();
231 var host = this.b$["javax.swing.text.ComponentView"].getContainer ();
232 if (host != null) {
233 this.b$["javax.swing.text.ComponentView"].preferenceChanged (null, true, true);
234 host.repaint ();
235 }} finally {
236 if (Clazz.instanceOf (doc, javax.swing.text.AbstractDocument)) {
237 (doc).readUnlock ();
238 }}
239 });
240 c$ = Clazz.p0p ();
241 };
242 });