1 22 23 27 28 package org.netbeans.lib.terminalemulator; 29 30 class Line { 31 public int glyph_glyph; 32 public int glyph_rendition; private char buf[]; 36 private int attr[]; 37 38 private int capacity; private int length; 42 43 public Line() { 44 reset(); 45 } 46 47 public void reset() { 48 length = 0; 49 capacity = 32; 50 buf = new char[capacity]; 51 Attr = null; 52 glyph_glyph = 0; 53 glyph_rendition = 0; 54 wrapped = false; 55 about_to_wrap = false; 56 } 57 58 59 public int capacity() { 60 return Capacity; 61 } 62 public int length() { 63 return Length; 64 } 65 66 public boolean hasAttributes() { 67 return attr != null; 68 } 69 70 public void setWrapped(boolean wrapped) { 71 this.wrapped = wrapped; 72 } 73 public boolean isWrapped() { 74 return wrapped; 75 } 76 private boolean wrapped; 78 79 80 81 public boolean setAboutToWrap(boolean about_to_wrap) { 82 boolean old_about_to_wrap = about_to_wrap; 83 this.about_to_wrap = about_to_wrap; 84 return old_about_to_wrap; 85 } 86 public boolean isAboutToWrap() { 87 return about_to_wrap; 88 } 89 private boolean about_to_wrap; 91 92 93 97 private boolean haveAttributes(int a) { 98 if (attr == null && a != 0) { 99 attr = new int[capacity]; 100 } 101 return attr != null; 102 } 103 104 105 public Char [] charArray() { 106 return buf; 107 } 108 public int [] attrArray() { 109 return attr; 110 } 111 112 113 public StringBuffer stringBuffer() { 114 StringBuffer sb = new StringBuffer (length); 117 return sb.append(buf, 0, length); 118 } 119 120 123 private void ensureCapacity(int min_capacity) { 124 125 if (min_capacity <= capacity) 126 return; 128 138 139 int new_capacity = (length+1) * 2; 141 if (new_capacity < 0) 142 new_capacity = Integer.MAX_VALUE; 143 else if (min_capacity > new_capacity) 144 new_capacity = min_capacity; 145 146 147 char new_buf[] = new char[new_capacity]; 148 System.arraycopy(buf, 0, new_buf, 0, length); 149 buf = new_buf; 150 151 if (attr != null) { 152 int new_attr[] = new int[new_capacity]; 153 System.arraycopy(attr, 0, new_attr, 0, length); 154 attr = new_attr; 155 } 156 157 capacity = new_capacity; 158 } 159 160 164 public void insertCharAt(char c, int column, int a) { 165 int new_length = length + 1; 166 ensureCapacity(new_length); 167 168 System.arraycopy(buf, column, buf, column + 1, length - column); 169 buf[column] = c; 170 171 if (haveAttributes(a)) { 172 System.arraycopy(attr, column, attr, column + 1, length - column); 173 attr[column] = a; 174 } 175 176 length = new_length; 177 } 178 179 183 public void setCharAt(char c, int column, int a) { 184 if (column >= length) { 185 ensureCapacity(column+1); 186 length = column+1; 187 } 188 buf[column] = c; 189 if (haveAttributes(a)) { 190 attr[column] = a; 191 } 192 } 193 194 public void deleteCharAt(int column) { 195 if (column < 0 || column >= length) 196 return; 197 System.arraycopy(buf, column+1, buf, column, length-column-1); 198 buf[length-1] = 0; 199 if (attr != null) { 200 System.arraycopy(attr, column+1, attr, column, length-column-1); 201 attr[length-1] = 0; 202 } 203 length--; 205 } 206 207 public void clearToEndFrom(int col) { 208 ensureCapacity(col+1); 209 210 for (int cx = col; cx < length; cx++) 212 buf[cx] = 0; 213 if (attr != null) { 214 for (int cx = col; cx < length; cx++) 215 attr[cx] = 0; 216 } 217 length = col; 218 } 219 220 221 225 public String text(int bcol, int ecol) { 226 229 String newline = ""; 230 231 if (length == 0) 233 return ""; 234 235 if (ecol >= length) { 236 ecol = length-1; 238 newline = "\n"; 239 240 if (bcol >= length) 241 bcol = length-1; 242 } 243 return new String (buf, bcol, ecol-bcol+1) + newline; 244 } 245 246 public void setCharacterAttribute(int bcol, int ecol, 247 int value, boolean on) { 248 if (!haveAttributes(value)) 251 return; 252 253 if (on) { 254 for (int c = bcol; c <= ecol; c++) 255 attr[c] = Attr.setAttribute(attr[c], value); 256 } else { 257 for (int c = bcol; c <= ecol; c++) 258 attr[c] = Attr.unsetAttribute(attr[c], value); 259 } 260 } 261 } 262 | Popular Tags |