1 36 package jline; 37 38 44 public class CursorBuffer 45 { 46 public int cursor = 0; 47 public final StringBuffer buffer = new StringBuffer (); 48 49 50 public int length () 51 { 52 return buffer.length (); 53 } 54 55 56 public char current () 57 { 58 if (cursor <= 0) 59 return 0; 60 61 return buffer.charAt (cursor - 1); 62 } 63 64 65 71 public void insert (final char c) 72 { 73 buffer.insert (cursor++, c); 74 } 75 76 77 83 public void insert (final String str) 84 { 85 if (buffer.length () == 0) 86 buffer.append (str); 87 else 88 buffer.insert (cursor, str); 89 90 cursor += str.length (); 91 } 92 93 94 public String toString () 95 { 96 return buffer.toString (); 97 } 98 } 99 | Popular Tags |