9b1b0b55d52604c074a872fe45f2f77e2dd89d36
[jalviewjs.git] / site / j2s / javax / swing / text / View.js
1 Clazz.declarePackage ("javax.swing.text");
2 Clazz.load (["javax.swing.SwingConstants"], "javax.swing.text.View", ["java.lang.IllegalArgumentException", "java.awt.Rectangle", "javax.swing.event.DocumentEvent", "javax.swing.text.Position", "$.Utilities"], function () {
3 c$ = Clazz.decorateAsClass (function () {
4 this.parent = null;
5 this.elem = null;
6 Clazz.instantialize (this, arguments);
7 }, javax.swing.text, "View", null, javax.swing.SwingConstants);
8 Clazz.makeConstructor (c$, 
9 function (elem) {
10 this.elem = elem;
11 }, "javax.swing.text.Element");
12 Clazz.defineMethod (c$, "getParent", 
13 function () {
14 return this.parent;
15 });
16 Clazz.defineMethod (c$, "isVisible", 
17 function () {
18 return true;
19 });
20 Clazz.defineMethod (c$, "getMinimumSpan", 
21 function (axis) {
22 var w = this.getResizeWeight (axis);
23 if (w == 0) {
24 return this.getPreferredSpan (axis);
25 }return 0;
26 }, "~N");
27 Clazz.defineMethod (c$, "getMaximumSpan", 
28 function (axis) {
29 var w = this.getResizeWeight (axis);
30 if (w == 0) {
31 return this.getPreferredSpan (axis);
32 }return 2147483647;
33 }, "~N");
34 Clazz.defineMethod (c$, "preferenceChanged", 
35 function (child, width, height) {
36 var parent = this.getParent ();
37 if (parent != null) {
38 parent.preferenceChanged (this, width, height);
39 }}, "javax.swing.text.View,~B,~B");
40 Clazz.defineMethod (c$, "getAlignment", 
41 function (axis) {
42 return 0.5;
43 }, "~N");
44 Clazz.defineMethod (c$, "setParent", 
45 function (parent) {
46 if (parent == null) {
47 for (var i = 0; i < this.getViewCount (); i++) {
48 if (this.getView (i).getParent () === this) {
49 this.getView (i).setParent (null);
50 }}
51 }this.parent = parent;
52 }, "javax.swing.text.View");
53 Clazz.defineMethod (c$, "getViewCount", 
54 function () {
55 return 0;
56 });
57 Clazz.defineMethod (c$, "getView", 
58 function (n) {
59 return null;
60 }, "~N");
61 Clazz.defineMethod (c$, "removeAll", 
62 function () {
63 this.replace (0, this.getViewCount (), null);
64 });
65 Clazz.defineMethod (c$, "remove", 
66 function (i) {
67 this.replace (i, 1, null);
68 }, "~N");
69 Clazz.defineMethod (c$, "insert", 
70 function (offs, v) {
71 var one =  new Array (1);
72 one[0] = v;
73 this.replace (offs, 0, one);
74 }, "~N,javax.swing.text.View");
75 Clazz.defineMethod (c$, "append", 
76 function (v) {
77 var one =  new Array (1);
78 one[0] = v;
79 this.replace (this.getViewCount (), 0, one);
80 }, "javax.swing.text.View");
81 Clazz.defineMethod (c$, "replace", 
82 function (offset, length, views) {
83 }, "~N,~N,~A");
84 Clazz.defineMethod (c$, "getViewIndex", 
85 function (pos, b) {
86 return -1;
87 }, "~N,javax.swing.text.Position.Bias");
88 Clazz.defineMethod (c$, "getChildAllocation", 
89 function (index, a) {
90 return null;
91 }, "~N,java.awt.Shape");
92 Clazz.defineMethod (c$, "getNextVisualPositionFrom", 
93 function (pos, b, a, direction, biasRet) {
94 biasRet[0] = javax.swing.text.Position.Bias.Forward;
95 switch (direction) {
96 case 1:
97 case 5:
98 {
99 if (pos == -1) {
100 pos = (direction == 1) ? Math.max (0, this.getEndOffset () - 1) : this.getStartOffset ();
101 break;
102 }var target = this.getContainer ();
103 var c = (target != null) ? target.getCaret () : null;
104 var mcp;
105 if (c != null) {
106 mcp = c.getMagicCaretPosition ();
107 } else {
108 mcp = null;
109 }var x;
110 if (mcp == null) {
111 var loc = target.modelToView (pos);
112 x = (loc == null) ? 0 : loc.x;
113 } else {
114 x = mcp.x;
115 }if (direction == 1) {
116 pos = javax.swing.text.Utilities.getPositionAbove (target, pos, x);
117 } else {
118 pos = javax.swing.text.Utilities.getPositionBelow (target, pos, x);
119 }}break;
120 case 7:
121 if (pos == -1) {
122 pos = Math.max (0, this.getEndOffset () - 1);
123 } else {
124 pos = Math.max (0, pos - 1);
125 }break;
126 case 3:
127 if (pos == -1) {
128 pos = this.getStartOffset ();
129 } else {
130 pos = Math.min (pos + 1, this.getDocument ().getLength ());
131 }break;
132 default:
133 throw  new IllegalArgumentException ("Bad direction: " + direction);
134 }
135 return pos;
136 }, "~N,javax.swing.text.Position.Bias,java.awt.Shape,~N,~A");
137 Clazz.defineMethod (c$, "modelToView", 
138 function (p0, b0, p1, b1, a) {
139 var s0 = this.modelToView (p0, a, b0);
140 var s1;
141 if (p1 == this.getEndOffset ()) {
142 try {
143 s1 = this.modelToView (p1, a, b1);
144 } catch (ble) {
145 if (Clazz.exceptionOf (ble, javax.swing.text.BadLocationException)) {
146 s1 = null;
147 } else {
148 throw ble;
149 }
150 }
151 if (s1 == null) {
152 var alloc = (Clazz.instanceOf (a, java.awt.Rectangle)) ? a : a.getBounds ();
153 s1 =  new java.awt.Rectangle (alloc.x + alloc.width - 1, alloc.y, 1, alloc.height);
154 }} else {
155 s1 = this.modelToView (p1, a, b1);
156 }var r0 = s0.getBounds ();
157 var r1 = (Clazz.instanceOf (s1, java.awt.Rectangle)) ? s1 : s1.getBounds ();
158 if (r0.y != r1.y) {
159 var alloc = (Clazz.instanceOf (a, java.awt.Rectangle)) ? a : a.getBounds ();
160 r0.x = alloc.x;
161 r0.width = alloc.width;
162 }r0.add (r1);
163 return r0;
164 }, "~N,javax.swing.text.Position.Bias,~N,javax.swing.text.Position.Bias,java.awt.Shape");
165 Clazz.defineMethod (c$, "insertUpdate", 
166 function (e, a, f) {
167 if (this.getViewCount () > 0) {
168 var elem = this.getElement ();
169 var ec = e.getChange (elem);
170 if (ec != null) {
171 if (!this.updateChildren (ec, e, f)) {
172 ec = null;
173 }}this.forwardUpdate (ec, e, a, f);
174 this.updateLayout (ec, e, a);
175 }}, "javax.swing.event.DocumentEvent,java.awt.Shape,javax.swing.text.ViewFactory");
176 Clazz.defineMethod (c$, "removeUpdate", 
177 function (e, a, f) {
178 if (this.getViewCount () > 0) {
179 var elem = this.getElement ();
180 var ec = e.getChange (elem);
181 if (ec != null) {
182 if (!this.updateChildren (ec, e, f)) {
183 ec = null;
184 }}this.forwardUpdate (ec, e, a, f);
185 this.updateLayout (ec, e, a);
186 }}, "javax.swing.event.DocumentEvent,java.awt.Shape,javax.swing.text.ViewFactory");
187 Clazz.defineMethod (c$, "changedUpdate", 
188 function (e, a, f) {
189 if (this.getViewCount () > 0) {
190 var elem = this.getElement ();
191 var ec = e.getChange (elem);
192 if (ec != null) {
193 if (!this.updateChildren (ec, e, f)) {
194 ec = null;
195 }}this.forwardUpdate (ec, e, a, f);
196 this.updateLayout (ec, e, a);
197 }}, "javax.swing.event.DocumentEvent,java.awt.Shape,javax.swing.text.ViewFactory");
198 Clazz.defineMethod (c$, "getDocument", 
199 function () {
200 return this.elem.getDocument ();
201 });
202 Clazz.defineMethod (c$, "getStartOffset", 
203 function () {
204 return this.elem.getStartOffset ();
205 });
206 Clazz.defineMethod (c$, "getEndOffset", 
207 function () {
208 return this.elem.getEndOffset ();
209 });
210 Clazz.defineMethod (c$, "getElement", 
211 function () {
212 return this.elem;
213 });
214 Clazz.defineMethod (c$, "getGraphics", 
215 function () {
216 var c = this.getContainer ();
217 return c.getGraphics ();
218 });
219 Clazz.defineMethod (c$, "getAttributes", 
220 function () {
221 return this.elem.getAttributes ();
222 });
223 Clazz.defineMethod (c$, "breakView", 
224 function (axis, offset, pos, len) {
225 return this;
226 }, "~N,~N,~N,~N");
227 Clazz.defineMethod (c$, "createFragment", 
228 function (p0, p1) {
229 return this;
230 }, "~N,~N");
231 Clazz.defineMethod (c$, "getBreakWeight", 
232 function (axis, pos, len) {
233 if (len > this.getPreferredSpan (axis)) {
234 return 1000;
235 }return 0;
236 }, "~N,~N,~N");
237 Clazz.defineMethod (c$, "getResizeWeight", 
238 function (axis) {
239 return 0;
240 }, "~N");
241 Clazz.defineMethod (c$, "setSize", 
242 function (width, height) {
243 }, "~N,~N");
244 Clazz.defineMethod (c$, "getContainer", 
245 function () {
246 var v = this.getParent ();
247 return (v != null) ? v.getContainer () : null;
248 });
249 Clazz.defineMethod (c$, "getViewFactory", 
250 function () {
251 var v = this.getParent ();
252 return (v != null) ? v.getViewFactory () : null;
253 });
254 Clazz.defineMethod (c$, "getToolTipText", 
255 function (x, y, allocation) {
256 var viewIndex = this.getViewIndex (x, y, allocation);
257 if (viewIndex >= 0) {
258 allocation = this.getChildAllocation (viewIndex, allocation);
259 var rect = (Clazz.instanceOf (allocation, java.awt.Rectangle)) ? allocation : allocation.getBounds ();
260 if (rect.contains (x, y)) {
261 return this.getView (viewIndex).getToolTipText (x, y, allocation);
262 }}return null;
263 }, "~N,~N,java.awt.Shape");
264 Clazz.defineMethod (c$, "getViewIndex", 
265 function (x, y, allocation) {
266 for (var counter = this.getViewCount () - 1; counter >= 0; counter--) {
267 var childAllocation = this.getChildAllocation (counter, allocation);
268 if (childAllocation != null) {
269 var rect = (Clazz.instanceOf (childAllocation, java.awt.Rectangle)) ? childAllocation : childAllocation.getBounds ();
270 if (rect.contains (x, y)) {
271 return counter;
272 }}}
273 return -1;
274 }, "~N,~N,java.awt.Shape");
275 Clazz.defineMethod (c$, "updateChildren", 
276 function (ec, e, f) {
277 var removedElems = ec.getChildrenRemoved ();
278 var addedElems = ec.getChildrenAdded ();
279 var added = null;
280 if (addedElems != null) {
281 added =  new Array (addedElems.length);
282 for (var i = 0; i < addedElems.length; i++) {
283 added[i] = f.create (addedElems[i]);
284 }
285 }var nremoved = 0;
286 var index = ec.getIndex ();
287 if (removedElems != null) {
288 nremoved = removedElems.length;
289 }this.replace (index, nremoved, added);
290 return true;
291 }, "javax.swing.event.DocumentEvent.ElementChange,javax.swing.event.DocumentEvent,javax.swing.text.ViewFactory");
292 Clazz.defineMethod (c$, "forwardUpdate", 
293 function (ec, e, a, f) {
294 var elem = this.getElement ();
295 var pos = e.getOffset ();
296 var index0 = this.getViewIndex (pos, javax.swing.text.Position.Bias.Forward);
297 if (index0 == -1 && e.getType () === javax.swing.event.DocumentEvent.EventType.REMOVE && pos >= this.getEndOffset ()) {
298 index0 = this.getViewCount () - 1;
299 }var index1 = index0;
300 var v = (index0 >= 0) ? this.getView (index0) : null;
301 if (v != null) {
302 if ((v.getStartOffset () == pos) && (pos > 0)) {
303 index0 = Math.max (index0 - 1, 0);
304 }}if (e.getType () !== javax.swing.event.DocumentEvent.EventType.REMOVE) {
305 index1 = this.getViewIndex (pos + e.getLength (), javax.swing.text.Position.Bias.Forward);
306 if (index1 < 0) {
307 index1 = this.getViewCount () - 1;
308 }}var hole0 = index1 + 1;
309 var hole1 = hole0;
310 var addedElems = (ec != null) ? ec.getChildrenAdded () : null;
311 if ((addedElems != null) && (addedElems.length > 0)) {
312 hole0 = ec.getIndex ();
313 hole1 = hole0 + addedElems.length - 1;
314 }index0 = Math.max (index0, 0);
315 for (var i = index0; i <= index1; i++) {
316 if (!((i >= hole0) && (i <= hole1))) {
317 v = this.getView (i);
318 if (v != null) {
319 var childAlloc = this.getChildAllocation (i, a);
320 this.forwardUpdateToView (v, e, childAlloc, f);
321 }}}
322 }, "javax.swing.event.DocumentEvent.ElementChange,javax.swing.event.DocumentEvent,java.awt.Shape,javax.swing.text.ViewFactory");
323 Clazz.defineMethod (c$, "forwardUpdateToView", 
324 function (v, e, a, f) {
325 var type = e.getType ();
326 if (type === javax.swing.event.DocumentEvent.EventType.INSERT) {
327 v.insertUpdate (e, a, f);
328 } else if (type === javax.swing.event.DocumentEvent.EventType.REMOVE) {
329 v.removeUpdate (e, a, f);
330 } else {
331 v.changedUpdate (e, a, f);
332 }}, "javax.swing.text.View,javax.swing.event.DocumentEvent,java.awt.Shape,javax.swing.text.ViewFactory");
333 Clazz.defineMethod (c$, "updateLayout", 
334 function (ec, e, a) {
335 if ((ec != null) && (a != null)) {
336 this.preferenceChanged (null, true, true);
337 var host = this.getContainer ();
338 if (host != null) {
339 host.repaint ();
340 }}}, "javax.swing.event.DocumentEvent.ElementChange,javax.swing.event.DocumentEvent,java.awt.Shape");
341 Clazz.defineMethod (c$, "modelToView", 
342 function (pos, a) {
343 return this.modelToView (pos, a, javax.swing.text.Position.Bias.Forward);
344 }, "~N,java.awt.Shape");
345 Clazz.defineMethod (c$, "viewToModel", 
346 function (x, y, a) {
347 javax.swing.text.View.sharedBiasReturn[0] = javax.swing.text.Position.Bias.Forward;
348 return this.viewToModel (x, y, a, javax.swing.text.View.sharedBiasReturn);
349 }, "~N,~N,java.awt.Shape");
350 Clazz.defineStatics (c$,
351 "BadBreakWeight", 0,
352 "GoodBreakWeight", 1000,
353 "ExcellentBreakWeight", 2000,
354 "ForcedBreakWeight", 3000,
355 "X_AXIS", 0,
356 "Y_AXIS", 1);
357 c$.sharedBiasReturn = c$.prototype.sharedBiasReturn =  new Array (1);
358 });