/** * Pastes the content of the {@link Clipboard} implementation set on this Textfield to this * TextField. */ void paste() { String content = clipboard.getContents(); if (content != null) { StringBuilder builder = new StringBuilder(); for (int i = 0; i < content.length(); i++) { if (maxLength > 0 && text.length() + builder.length() + 1 > maxLength) { break; } char c = content.charAt(i); if (style.font.containsCharacter(c) && (filter == null || filter.acceptChar(this, c))) builder.append(c); } content = builder.toString(); if (!hasSelection) { text = text.substring(0, cursor) + content + text.substring(cursor, text.length()); updateDisplayText(); cursor += content.length(); } else { int minIndex = Math.min(cursor, selectionStart); int maxIndex = Math.max(cursor, selectionStart); text = (minIndex > 0 ? text.substring(0, minIndex) : "") + (maxIndex < text.length() ? text.substring(maxIndex, text.length()) : ""); cursor = minIndex; text = text.substring(0, cursor) + content + text.substring(cursor, text.length()); updateDisplayText(); cursor = minIndex + content.length(); clearSelection(); } } }
/** * Copies the contents of this TextField to the {@link Clipboard} implementation set on this * TextField. */ public void copy() { if (hasSelection) { int minIndex = Math.min(cursor, selectionStart); int maxIndex = Math.max(cursor, selectionStart); clipboard.setContents(text.substring(minIndex, maxIndex)); } }
/** * Copies the contents of this TextField to the {@link Clipboard} implementation set on this * TextField. */ public void copy() { if (hasSelection && !passwordMode) { clipboard.setContents( text.substring(Math.min(cursor, selectionStart), Math.max(cursor, selectionStart))); } }