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