1 16 17 package swingwtx.swing.text; 18 19 import swingwtx.swing.undo.*; 20 21 27 public class StringContent implements AbstractDocument.Content { 28 29 30 private StringBuffer s = null; 31 32 public StringContent() { 33 s = new StringBuffer (); 34 } 35 36 public StringContent(int initialSize) { 37 s = new StringBuffer (initialSize); 38 } 39 40 43 public Position createPosition(final int offset) throws BadLocationException { 44 return new Position() { 45 public int getOffset() { return offset; } 46 }; 47 } 48 49 50 public int length() { return s.length(); } 51 52 57 public UndoableEdit insertString(int where, String str) throws BadLocationException { 58 if (where < 0 || where > s.length()) 59 throw new BadLocationException("Out of bounds", where); 60 s.insert(where, str); 61 return null; 62 } 63 64 69 public UndoableEdit remove(int where, int nitems) throws BadLocationException { 70 if (where < 0 || where > s.length() || where + nitems > s.length()) 71 throw new BadLocationException("Out of bounds", where); 72 s.replace(where, where + nitems, ""); 73 return null; 74 } 75 76 83 public String getString(int where, int len) throws BadLocationException { 84 if (where < 0 || where > s.length() || where + len > s.length()) 85 throw new BadLocationException("Out of bounds", where); 86 return s.toString().substring(where, where + len); 87 } 88 89 95 public void getChars(int where, int len, Segment txt) throws BadLocationException { 96 txt.array = getString(where, len).toCharArray(); 97 } 98 99 } 100 | Popular Tags |