1 Clazz.declarePackage ("javax.swing.text");
2 Clazz.load (["javax.swing.text.View"], "javax.swing.text.CompositeView", ["java.lang.IllegalArgumentException", "java.awt.Rectangle", "javax.swing.text.BadLocationException", "$.Position", "$.StyleConstants", "$.Utilities"], function () {
3 c$ = Clazz.decorateAsClass (function () {
10 this.childAlloc = null;
11 Clazz.instantialize (this, arguments);
12 }, javax.swing.text, "CompositeView", javax.swing.text.View);
13 Clazz.makeConstructor (c$,
15 Clazz.superConstructor (this, javax.swing.text.CompositeView, [elem]);
16 this.children = new Array (1);
18 this.childAlloc = new java.awt.Rectangle ();
19 }, "javax.swing.text.Element");
20 Clazz.defineMethod (c$, "loadChildren",
24 }var e = this.getElement ();
25 var n = e.getElementCount ();
27 var added = new Array (n);
28 for (var i = 0; i < n; i++) {
29 added[i] = f.create (e.getElement (i));
31 this.replace (0, 0, added);
32 }}, "javax.swing.text.ViewFactory");
33 Clazz.defineMethod (c$, "setParent",
35 Clazz.superCall (this, javax.swing.text.CompositeView, "setParent", [parent]);
36 if ((parent != null) && (this.nchildren == 0)) {
37 var f = this.getViewFactory ();
38 this.loadChildren (f);
39 }}, "javax.swing.text.View");
40 Clazz.overrideMethod (c$, "getViewCount",
42 return this.nchildren;
44 Clazz.overrideMethod (c$, "getView",
46 return this.children[n];
48 Clazz.overrideMethod (c$, "replace",
49 function (offset, length, views) {
51 views = javax.swing.text.CompositeView.ZERO;
52 }for (var i = offset; i < offset + length; i++) {
53 if (this.children[i].getParent () === this) {
54 this.children[i].setParent (null);
55 }this.children[i] = null;
57 var delta = views.length - length;
58 var src = offset + length;
59 var nmove = this.nchildren - src;
60 var dest = src + delta;
61 if ((this.nchildren + delta) >= this.children.length) {
62 var newLength = Math.max (2 * this.children.length, this.nchildren + delta);
63 var newChildren = new Array (newLength);
64 System.arraycopy (this.children, 0, newChildren, 0, offset);
65 System.arraycopy (views, 0, newChildren, offset, views.length);
66 System.arraycopy (this.children, src, newChildren, dest, nmove);
67 this.children = newChildren;
69 System.arraycopy (this.children, src, this.children, dest, nmove);
70 System.arraycopy (views, 0, this.children, offset, views.length);
71 }this.nchildren = this.nchildren + delta;
72 for (var i = 0; i < views.length; i++) {
73 views[i].setParent (this);
76 Clazz.overrideMethod (c$, "getChildAllocation",
78 var alloc = this.getInsideAllocation (a);
79 this.childAllocation (index, alloc);
81 }, "~N,java.awt.Shape");
82 Clazz.defineMethod (c$, "modelToView",
83 function (pos, a, b) {
84 var isBackward = (b === javax.swing.text.Position.Bias.Backward);
85 var testPos = (isBackward) ? Math.max (0, pos - 1) : pos;
86 if (isBackward && testPos < this.getStartOffset ()) {
88 }var vIndex = this.getViewIndexAtPosition (testPos);
89 if ((vIndex != -1) && (vIndex < this.getViewCount ())) {
90 var v = this.getView (vIndex);
91 if (v != null && testPos >= v.getStartOffset () && testPos < v.getEndOffset ()) {
92 var childShape = this.getChildAllocation (vIndex, a);
93 if (childShape == null) {
95 }var retShape = v.modelToView (pos, childShape, b);
96 if (retShape == null && v.getEndOffset () == pos) {
97 if (++vIndex < this.getViewCount ()) {
98 v = this.getView (vIndex);
99 retShape = v.modelToView (pos, this.getChildAllocation (vIndex, a), b);
101 }}throw new javax.swing.text.BadLocationException ("Position not represented by view", pos);
102 }, "~N,java.awt.Shape,javax.swing.text.Position.Bias");
103 Clazz.defineMethod (c$, "modelToView",
104 function (p0, b0, p1, b1, a) {
105 if (p0 == this.getStartOffset () && p1 == this.getEndOffset ()) {
107 }var alloc = this.getInsideAllocation (a);
108 var r0 = new java.awt.Rectangle (alloc);
109 var v0 = this.getViewAtPosition ((b0 === javax.swing.text.Position.Bias.Backward) ? Math.max (0, p0 - 1) : p0, r0);
110 var r1 = new java.awt.Rectangle (alloc);
111 var v1 = this.getViewAtPosition ((b1 === javax.swing.text.Position.Bias.Backward) ? Math.max (0, p1 - 1) : p1, r1);
115 }return v0.modelToView (p0, b0, p1, b1, r0);
116 }var viewCount = this.getViewCount ();
118 while (counter < viewCount) {
120 if ((v = this.getView (counter)) === v0 || v === v1) {
123 var tempRect = new java.awt.Rectangle ();
125 retRect = v0.modelToView (p0, b0, v0.getEndOffset (), javax.swing.text.Position.Bias.Backward, r0).getBounds ();
128 retRect = v1.modelToView (v1.getStartOffset (), javax.swing.text.Position.Bias.Forward, p1, b1, r1).getBounds ();
130 }while (++counter < viewCount && (v = this.getView (counter)) !== endView) {
131 tempRect.setBounds (alloc);
132 this.childAllocation (counter, tempRect);
133 retRect.add (tempRect);
135 if (endView != null) {
137 if (endView === v1) {
138 endShape = v1.modelToView (v1.getStartOffset (), javax.swing.text.Position.Bias.Forward, p1, b1, r1);
140 endShape = v0.modelToView (p0, b0, v0.getEndOffset (), javax.swing.text.Position.Bias.Backward, r0);
141 }if (Clazz.instanceOf (endShape, java.awt.Rectangle)) {
142 retRect.add (endShape);
144 retRect.add (endShape.getBounds ());
148 throw new javax.swing.text.BadLocationException ("Position not represented by view", p0);
149 }, "~N,javax.swing.text.Position.Bias,~N,javax.swing.text.Position.Bias,java.awt.Shape");
150 Clazz.defineMethod (c$, "viewToModel",
151 function (x, y, a, bias) {
152 var alloc = this.getInsideAllocation (a);
153 if (this.isBefore (Clazz.floatToInt (x), Clazz.floatToInt (y), alloc)) {
156 retValue = this.getNextVisualPositionFrom (-1, javax.swing.text.Position.Bias.Forward, a, 3, bias);
158 if (Clazz.exceptionOf (e$$, javax.swing.text.BadLocationException)) {
162 } else if (Clazz.exceptionOf (e$$, IllegalArgumentException)) {
170 if (retValue == -1) {
171 retValue = this.getStartOffset ();
172 bias[0] = javax.swing.text.Position.Bias.Forward;
174 } else if (this.isAfter (Clazz.floatToInt (x), Clazz.floatToInt (y), alloc)) {
177 retValue = this.getNextVisualPositionFrom (-1, javax.swing.text.Position.Bias.Forward, a, 7, bias);
179 if (Clazz.exceptionOf (e$$, javax.swing.text.BadLocationException)) {
183 } else if (Clazz.exceptionOf (e$$, IllegalArgumentException)) {
191 if (retValue == -1) {
192 retValue = this.getEndOffset () - 1;
193 bias[0] = javax.swing.text.Position.Bias.Forward;
196 var v = this.getViewAtPoint (Clazz.floatToInt (x), Clazz.floatToInt (y), alloc);
198 return v.viewToModel (x, y, alloc, bias);
200 }, "~N,~N,java.awt.Shape,~A");
201 Clazz.overrideMethod (c$, "getNextVisualPositionFrom",
202 function (pos, b, a, direction, biasRet) {
205 return this.getNextNorthSouthVisualPositionFrom (pos, b, a, direction, biasRet);
207 return this.getNextNorthSouthVisualPositionFrom (pos, b, a, direction, biasRet);
209 return this.getNextEastWestVisualPositionFrom (pos, b, a, direction, biasRet);
211 return this.getNextEastWestVisualPositionFrom (pos, b, a, direction, biasRet);
213 throw new IllegalArgumentException ("Bad direction: " + direction);
215 }, "~N,javax.swing.text.Position.Bias,java.awt.Shape,~N,~A");
216 Clazz.defineMethod (c$, "getViewIndex",
218 if (b === javax.swing.text.Position.Bias.Backward) {
220 }if ((pos >= this.getStartOffset ()) && (pos < this.getEndOffset ())) {
221 return this.getViewIndexAtPosition (pos);
223 }, "~N,javax.swing.text.Position.Bias");
224 Clazz.defineMethod (c$, "getViewAtPosition",
226 var index = this.getViewIndexAtPosition (pos);
227 if ((index >= 0) && (index < this.getViewCount ())) {
228 var v = this.getView (index);
230 this.childAllocation (index, a);
233 }, "~N,java.awt.Rectangle");
234 Clazz.defineMethod (c$, "getViewIndexAtPosition",
236 var elem = this.getElement ();
237 return elem.getElementIndex (pos);
239 Clazz.defineMethod (c$, "getInsideAllocation",
243 if (Clazz.instanceOf (a, java.awt.Rectangle)) {
246 alloc = a.getBounds ();
247 }this.childAlloc.setBounds (alloc);
248 this.childAlloc.x += this.getLeftInset ();
249 this.childAlloc.y += this.getTopInset ();
250 this.childAlloc.width -= this.getLeftInset () + this.getRightInset ();
251 this.childAlloc.height -= this.getTopInset () + this.getBottomInset ();
252 return this.childAlloc;
254 }, "java.awt.Shape");
255 Clazz.defineMethod (c$, "setParagraphInsets",
257 this.top = Clazz.floatToShort (javax.swing.text.StyleConstants.getSpaceAbove (attr));
258 this.left = Clazz.floatToShort (javax.swing.text.StyleConstants.getLeftIndent (attr));
259 this.bottom = Clazz.floatToShort (javax.swing.text.StyleConstants.getSpaceBelow (attr));
260 this.right = Clazz.floatToShort (javax.swing.text.StyleConstants.getRightIndent (attr));
261 }, "javax.swing.text.AttributeSet");
262 Clazz.defineMethod (c$, "setInsets",
263 function (top, left, bottom, right) {
267 this.bottom = bottom;
269 Clazz.defineMethod (c$, "getLeftInset",
273 Clazz.defineMethod (c$, "getRightInset",
277 Clazz.defineMethod (c$, "getTopInset",
281 Clazz.defineMethod (c$, "getBottomInset",
285 Clazz.defineMethod (c$, "getNextNorthSouthVisualPositionFrom",
286 function (pos, b, a, direction, biasRet) {
287 return javax.swing.text.Utilities.getNextVisualPositionFrom (this, pos, b, a, direction, biasRet);
288 }, "~N,javax.swing.text.Position.Bias,java.awt.Shape,~N,~A");
289 Clazz.defineMethod (c$, "getNextEastWestVisualPositionFrom",
290 function (pos, b, a, direction, biasRet) {
291 return javax.swing.text.Utilities.getNextVisualPositionFrom (this, pos, b, a, direction, biasRet);
292 }, "~N,javax.swing.text.Position.Bias,java.awt.Shape,~N,~A");
293 Clazz.defineMethod (c$, "flipEastAndWestAtEnds",
294 function (position, bias) {
296 }, "~N,javax.swing.text.Position.Bias");
297 c$.ZERO = c$.prototype.ZERO = new Array (0);