1 Clazz.declarePackage ("javax.swing.text");
\r
2 c$ = Clazz.decorateAsClass (function () {
\r
6 Clazz.instantialize (this, arguments);
\r
7 }, javax.swing.text, "GapVector");
\r
8 Clazz.makeConstructor (c$,
\r
10 this.construct (10);
\r
12 Clazz.makeConstructor (c$,
\r
13 function (initialLength) {
\r
14 this.array = this.allocateArray (initialLength);
\r
16 this.g1 = initialLength;
\r
18 Clazz.defineMethod (c$, "getArray",
\r
22 Clazz.defineMethod (c$, "getGapStart",
\r
26 Clazz.defineMethod (c$, "getGapEnd",
\r
30 Clazz.defineMethod (c$, "replace",
\r
31 function (position, rmSize, addItems, addSize) {
\r
34 this.close (position, rmSize);
\r
36 } else if (rmSize > addSize) {
\r
37 this.close (position + addSize, rmSize - addSize);
\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
43 }System.arraycopy (addItems, addOffset, this.array, position, addSize);
\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
59 this.shiftGapStartDown (position);
\r
60 this.shiftGapEndUp (this.g0 + new_gs);
\r
62 Clazz.defineMethod (c$, "open",
\r
63 function (position, nItems) {
\r
64 var gapSize = this.g1 - this.g0;
\r
66 if (position > this.g0) position += gapSize;
\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
75 Clazz.defineMethod (c$, "resize",
\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
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
93 Clazz.defineMethod (c$, "getNewArraySize",
\r
94 function (reqSize) {
\r
95 return (reqSize + 1) * 2;
\r
97 Clazz.defineMethod (c$, "shiftGap",
\r
98 function (newGapStart) {
\r
99 if (newGapStart == this.g0) {
\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
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
113 Clazz.defineMethod (c$, "shiftGapStartDown",
\r
114 function (newGapStart) {
\r
115 this.g0 = newGapStart;
\r
117 Clazz.defineMethod (c$, "shiftGapEndUp",
\r
118 function (newGapEnd) {
\r
119 this.g1 = newGapEnd;
\r