Author: rwhitcomb Date: Fri Jan 5 18:25:51 2018 New Revision: 1820340 URL: http://svn.apache.org/viewvc?rev=1820340&view=rev Log: PIVOT-1012: Use Utils methods for more parameter validation in TextPane. Add some Javadoc and reflow some other comments.
Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/TextPane.java Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/TextPane.java URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/TextPane.java?rev=1820340&r1=1820339&r2=1820340&view=diff ============================================================================== --- pivot/trunk/wtk/src/org/apache/pivot/wtk/TextPane.java (original) +++ pivot/trunk/wtk/src/org/apache/pivot/wtk/TextPane.java Fri Jan 5 18:25:51 2018 @@ -593,6 +593,14 @@ public class TextPane extends Container return (document == null) ? 0 : document.getCharacterCount(); } + /** + * Delete the currently selected text (if selection length > 0), + * or the character before or after the current cursor position, + * depending on the <tt>backspace</tt> flag. + * @param backspace {@code true} if the single character delete is + * the character before the current position, or {@code false} for + * the character after (at) the current position. + */ public void delete(boolean backspace) { if (selectionLength > 0) { removeText(selectionStart, selectionLength); @@ -605,6 +613,12 @@ public class TextPane extends Container } } + /** + * Remove the text from the document starting at the given position + * for the given number of characters. + * @param offset Starting location to remove text. + * @param characterCount The number of characters to remove. + */ public void removeText(int offset, int characterCount) { checkDocumentExists(); @@ -638,7 +652,7 @@ public class TextPane extends Container document.add(new Paragraph()); } - // Move the caret to the merge point + // Move the caret to the removal point if (offset >= 0) { setSelection(offset, 0); } @@ -874,16 +888,7 @@ public class TextPane extends Container * {@code null} if there is no document. */ public String getText(int beginIndex, int endIndex) { - if (beginIndex > endIndex) { - throw new IllegalArgumentException("Beginning index " + beginIndex + - " is greater than ending index " + endIndex + "."); - } - - if (beginIndex < 0 || endIndex > getCharacterCount()) { - throw new IndexOutOfBoundsException("Beginning index = " + beginIndex + - ", ending index = " + endIndex + ", document.characterCount = " + - getCharacterCount() + "."); - } + Utils.checkTwoIndexBounds(beginIndex, endIndex, 0, getCharacterCount()); int count = endIndex - beginIndex; if (count == 0) { @@ -1044,10 +1049,7 @@ public class TextPane extends Container public void setSelection(int selectionStart, int selectionLength) { checkDocumentExists(); - if (selectionLength < 0) { - throw new IllegalArgumentException("selectionLength is negative, selectionLength=" - + selectionLength); - } + Utils.checkNonNegative(selectionLength, "selectionLength"); int composedTextLength = composedText != null ? (composedText.getEndIndex() - composedText.getBeginIndex()) : 0; indexBoundsCheck("selectionStart", selectionStart, 0, document.getCharacterCount() - 1 + composedTextLength);