diff options
author | Matti Tahvonen <matti.tahvonen@itmill.com> | 2010-06-17 14:49:46 +0000 |
---|---|---|
committer | Matti Tahvonen <matti.tahvonen@itmill.com> | 2010-06-17 14:49:46 +0000 |
commit | 2496e77f36d6205472d44a29582019194550c928 (patch) | |
tree | 963ff9ac8bd2c7a41fc35730528609b31f2def6e /src/com/vaadin/ui/TextField.java | |
parent | 2acb37f3c06c251f28abc13367603c7972f468cc (diff) | |
download | vaadin-framework-2496e77f36d6205472d44a29582019194550c928.tar.gz vaadin-framework-2496e77f36d6205472d44a29582019194550c928.zip |
Text selection methods for TextField. Fixes #5217
svn changeset:13751/svn branch:6.4
Diffstat (limited to 'src/com/vaadin/ui/TextField.java')
-rw-r--r-- | src/com/vaadin/ui/TextField.java | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/src/com/vaadin/ui/TextField.java b/src/com/vaadin/ui/TextField.java index aa4c7c8661..fff0beaf0c 100644 --- a/src/com/vaadin/ui/TextField.java +++ b/src/com/vaadin/ui/TextField.java @@ -90,6 +90,10 @@ public class TextField extends AbstractField implements */ private int maxLength = -1; + private int selectionPosition = -1; + + private int selectionLength; + /* Constructors */ /** @@ -174,6 +178,11 @@ public class TextField extends AbstractField implements if (inputPrompt != null) { target.addAttribute("prompt", inputPrompt); } + if (selectionPosition != -1) { + target.addAttribute("selpos", selectionPosition); + target.addAttribute("sellen", selectionLength); + selectionPosition = -1; + } // Adds the number of column and rows final int columns = getColumns(); @@ -635,4 +644,46 @@ public class TextField extends AbstractField implements removeListener(BlurEvent.EVENT_ID, BlurEvent.class, listener); } + /** + * Selects all text in the field. + * + * @since 6.4 + */ + public void selectAll() { + String text = getValue() == null ? "" : getValue().toString(); + setSelectionRange(0, text.length()); + } + + /** + * Sets the range of text to be selected. + * + * As a side effect the field will become focused. + * + * @since 6.4 + * + * @param pos + * the position of the first character to be selected + * @param length + * the number of characters to be selected + */ + public void setSelectionRange(int pos, int length) { + selectionPosition = pos; + selectionLength = length; + focus(); + requestRepaint(); + } + + /** + * Sets the cursor position in the field. As a side effect the field will + * become focused. + * + * @since 6.4 + * + * @param pos + * the position for the cursor + * */ + public void setCursorPosition(int pos) { + setSelectionRange(pos, 0); + } + } |