Beispiel #1
0
  /** @param str If null, "" is used. */
  public void setText(String str) {
    if (str == null) str = "";
    if (str.equals(text)) return;

    clearSelection();
    String oldText = text;
    text = "";
    paste(str, false);
    if (programmaticChangeEvents) changeText(oldText, text);
    cursor = 0;
  }
Beispiel #2
0
 int delete(boolean fireChangeEvent) {
   int from = selectionStart;
   int to = cursor;
   int minIndex = Math.min(from, to);
   int maxIndex = Math.max(from, to);
   String newText =
       (minIndex > 0 ? text.substring(0, minIndex) : "")
           + (maxIndex < text.length() ? text.substring(maxIndex, text.length()) : "");
   if (fireChangeEvent) changeText(text, newText);
   else text = newText;
   clearSelection();
   return minIndex;
 }
Beispiel #3
0
  void paste(String content, boolean fireChangeEvent) {
    if (content == null) return;
    StringBuilder buffer = new StringBuilder();
    int textLength = text.length();
    if (hasSelection) textLength -= Math.abs(cursor - selectionStart);
    BitmapFontData data = style.font.getData();
    for (int i = 0, n = content.length(); i < n; i++) {
      if (!withinMaxLength(textLength + buffer.length())) break;
      char c = content.charAt(i);
      if (!(writeEnters && (c == ENTER_ANDROID || c == ENTER_DESKTOP))) {
        if (c == '\r' || c == '\n') continue;
        if (onlyFontChars && !data.hasGlyph(c)) continue;
        if (filter != null && !filter.acceptChar(this, c)) continue;
      }
      buffer.append(c);
    }
    content = buffer.toString();

    if (hasSelection) cursor = delete(fireChangeEvent);
    if (fireChangeEvent) changeText(text, insert(cursor, content, text));
    else text = insert(cursor, content, text);
    updateDisplayText();
    cursor += content.length();
  }