1 36 37 package com.sun.demo.scripting.jconsole; 38 39 import javax.swing.text.*; 40 41 45 public class EditableAtEndDocument extends PlainDocument { 46 private int mark; 47 48 public void insertString(int offset, String text, AttributeSet a) 49 throws BadLocationException { 50 int len = getLength(); 51 super.insertString(len, text, a); 52 } 53 54 public void remove(int offs, int len) throws BadLocationException { 55 int start = offs; 56 int end = offs + len; 57 58 int markStart = mark; 59 int markEnd = getLength(); 60 61 if ((end < markStart) || (start > markEnd)) { 62 return; 64 } 65 66 int cutStart = Math.max(start, markStart); 68 int cutEnd = Math.min(end, markEnd); 69 super.remove(cutStart, cutEnd - cutStart); 70 } 71 72 public void setMark() { 73 mark = getLength(); 74 } 75 76 public String getMarkedText() throws BadLocationException { 77 return getText(mark, getLength() - mark); 78 } 79 80 81 public void clear() { 82 try { 83 super.remove(0, getLength()); 84 setMark(); 85 } catch (BadLocationException e) { 86 } 87 } 88 } 89 | Popular Tags |