Beispiel #1
0
 public synchronized void insertChar(char c) {
   if (c == KeyEvent.CHAR_UNDEFINED) return;
   if (selectionActivated) deleteSelection();
   text.insert(getCaretLocation().toIndex(getLines()), c);
   clearCache();
   setCaretLocation(getCaretLocation().moved(getLines(), 1));
 }
Beispiel #2
0
  public String getSelectedText() {
    if (!hasSelection()) return "";

    int startIndex = getSelectionStart().toIndex(getLines());
    int endIndex = getSelectionEnd().toIndex(getLines());

    return text.substring(startIndex, endIndex);
  }
Beispiel #3
0
  public TextLocation findWordsRightEdge(TextLocation location) {

    for (int i = location.toIndex(getLines()); i <= text.length() - 1; i++) {
      if (i == 0) i = 1;
      if (isAtEndOfWord(i)) return TextLocation.fromIndex(getLines(), i);
    }
    return getEndLocation();
  }
Beispiel #4
0
  public synchronized void setText(String newText) {
    if (newText == null) newText = "";

    if (newText.length() == text.length() && newText.equals(getText())) return;

    text = new StringBuffer(newText);
    clearCache();
    setCaretLocation(getEndLocation());
  }
Beispiel #5
0
 public void deleteEnclosedText(TextLocation start, TextLocation end) {
   ArrayList<TypedLayout> lines = getLines();
   int startIndex = start.toIndex(lines);
   int endIndex = end.toIndex(lines);
   synchronized (this) {
     text.delete(startIndex, endIndex);
     clearCache();
   }
   setCaretLocation(start);
   setSelectionLocation(start);
 }
Beispiel #6
0
 public void pasteClipboard() {
   String clipboard = getClipboardContents();
   if (clipboard != null && clipboard.length() > 0) {
     int caretIndex = caretLocation.toIndex(getLines());
     synchronized (this) {
       text.insert(caretIndex, clipboard);
       clearCache();
     }
     setCaretLocation(TextLocation.fromIndex(getLines(), caretIndex + clipboard.length()));
   }
 }
Beispiel #7
0
 public TextLocation getEndLocation() {
   return TextLocation.fromIndex(getLines(), text.length());
 }
Beispiel #8
0
 protected TextLocation findNextWordSkippingSpacesOrNewLines(TextLocation startLocation) {
   for (int i = startLocation.toIndex(getLines()); i <= text.length() - 1; i++) {
     if (isAtStartOfWord(i)) return TextLocation.fromIndex(getLines(), i);
   }
   return getEndLocation();
 }
Beispiel #9
0
 public String getText() {
   return text.toString();
 }
Beispiel #10
0
 public boolean isAtStartOfWord(int i) {
   if (i < 0 || i > getText().length()) return true;
   return (text.charAt(i - 1) == ' ' || text.charAt(i - 1) == '\n')
       && (text.charAt(i) != ' ' && text.charAt(i) != '\n');
 }
Beispiel #11
0
 public boolean isAtEndOfWord(int i) {
   return text.charAt(i - 1) != ' '
       && text.charAt(i - 1) != '\n'
       && (text.charAt(i) == ' ' || text.charAt(i) == '\n');
 }