JAL-1807 Bob's JalviewJS prototype first commit
[jalviewjs.git] / site / swingjs / j2s / javax / swing / text / GapVector.js
1 Clazz.declarePackage ("javax.swing.text");\r
2 c$ = Clazz.decorateAsClass (function () {\r
3 this.array = null;\r
4 this.g0 = 0;\r
5 this.g1 = 0;\r
6 Clazz.instantialize (this, arguments);\r
7 }, javax.swing.text, "GapVector");\r
8 Clazz.makeConstructor (c$, \r
9 function () {\r
10 this.construct (10);\r
11 });\r
12 Clazz.makeConstructor (c$, \r
13 function (initialLength) {\r
14 this.array = this.allocateArray (initialLength);\r
15 this.g0 = 0;\r
16 this.g1 = initialLength;\r
17 }, "~N");\r
18 Clazz.defineMethod (c$, "getArray", \r
19 function () {\r
20 return this.array;\r
21 });\r
22 Clazz.defineMethod (c$, "getGapStart", \r
23 function () {\r
24 return this.g0;\r
25 });\r
26 Clazz.defineMethod (c$, "getGapEnd", \r
27 function () {\r
28 return this.g1;\r
29 });\r
30 Clazz.defineMethod (c$, "replace", \r
31 function (position, rmSize, addItems, addSize) {\r
32 var addOffset = 0;\r
33 if (addSize == 0) {\r
34 this.close (position, rmSize);\r
35 return;\r
36 } else if (rmSize > addSize) {\r
37 this.close (position + addSize, rmSize - addSize);\r
38 } else {\r
39 var endSize = addSize - rmSize;\r
40 var end = this.open (position + rmSize, endSize);\r
41 System.arraycopy (addItems, rmSize, this.array, end, endSize);\r
42 addSize = rmSize;\r
43 }System.arraycopy (addItems, addOffset, this.array, position, addSize);\r
44 }, "~N,~N,~O,~N");\r
45 Clazz.defineMethod (c$, "close", \r
46 function (position, nItems) {\r
47 if (nItems == 0) return;\r
48 var end = position + nItems;\r
49 var new_gs = (this.g1 - this.g0) + nItems;\r
50 if (end <= this.g0) {\r
51 if (this.g0 != end) {\r
52 this.shiftGap (end);\r
53 }this.shiftGapStartDown (this.g0 - nItems);\r
54 } else if (position >= this.g0) {\r
55 if (this.g0 != position) {\r
56 this.shiftGap (position);\r
57 }this.shiftGapEndUp (this.g0 + new_gs);\r
58 } else {\r
59 this.shiftGapStartDown (position);\r
60 this.shiftGapEndUp (this.g0 + new_gs);\r
61 }}, "~N,~N");\r
62 Clazz.defineMethod (c$, "open", \r
63 function (position, nItems) {\r
64 var gapSize = this.g1 - this.g0;\r
65 if (nItems == 0) {\r
66 if (position > this.g0) position += gapSize;\r
67 return position;\r
68 }this.shiftGap (position);\r
69 if (nItems >= gapSize) {\r
70 this.shiftEnd (this.getArrayLength () - gapSize + nItems);\r
71 gapSize = this.g1 - this.g0;\r
72 }this.g0 = this.g0 + nItems;\r
73 return position;\r
74 }, "~N,~N");\r
75 Clazz.defineMethod (c$, "resize", \r
76 function (nsize) {\r
77 var narray = this.allocateArray (nsize);\r
78 System.arraycopy (this.array, 0, narray, 0, Math.min (nsize, this.getArrayLength ()));\r
79 this.array = narray;\r
80 }, "~N");\r
81 Clazz.defineMethod (c$, "shiftEnd", \r
82 function (newSize) {\r
83 var oldSize = this.getArrayLength ();\r
84 var oldGapEnd = this.g1;\r
85 var upperSize = oldSize - oldGapEnd;\r
86 var arrayLength = this.getNewArraySize (newSize);\r
87 var newGapEnd = arrayLength - upperSize;\r
88 this.resize (arrayLength);\r
89 this.g1 = newGapEnd;\r
90 if (upperSize != 0) {\r
91 System.arraycopy (this.array, oldGapEnd, this.array, newGapEnd, upperSize);\r
92 }}, "~N");\r
93 Clazz.defineMethod (c$, "getNewArraySize", \r
94 function (reqSize) {\r
95 return (reqSize + 1) * 2;\r
96 }, "~N");\r
97 Clazz.defineMethod (c$, "shiftGap", \r
98 function (newGapStart) {\r
99 if (newGapStart == this.g0) {\r
100 return;\r
101 }var oldGapStart = this.g0;\r
102 var dg = newGapStart - oldGapStart;\r
103 var oldGapEnd = this.g1;\r
104 var newGapEnd = oldGapEnd + dg;\r
105 var gapSize = oldGapEnd - oldGapStart;\r
106 this.g0 = newGapStart;\r
107 this.g1 = newGapEnd;\r
108 if (dg > 0) {\r
109 System.arraycopy (this.array, oldGapEnd, this.array, oldGapStart, dg);\r
110 } else if (dg < 0) {\r
111 System.arraycopy (this.array, newGapStart, this.array, newGapEnd, -dg);\r
112 }}, "~N");\r
113 Clazz.defineMethod (c$, "shiftGapStartDown", \r
114 function (newGapStart) {\r
115 this.g0 = newGapStart;\r
116 }, "~N");\r
117 Clazz.defineMethod (c$, "shiftGapEndUp", \r
118 function (newGapEnd) {\r
119 this.g1 = newGapEnd;\r
120 }, "~N");\r