-
Bug
-
Resolution: Incomplete
-
P4
-
7
-
generic
-
generic
JTextComponent: there is some inconsistency between following methods. In particular, second one checks for null whereas first do not.
Moreover, I'd reuse the code like this:
public void selectAll() {
if (doc != null) {
select(0, getDocument().getLength());
}
}
---------
public void select(int selectionStart, int selectionEnd) {
// argument adjustment done by java.awt.TextComponent
int docLength = getDocument().getLength();
[...some bounds math...]
setCaretPosition(selectionStart);
moveCaretPosition(selectionEnd);
}
/**
* Selects all the text in the <code>TextComponent</code>.
* Does nothing on a <code>null</code> or empty document.
*/
public void selectAll() {
Document doc = getDocument();
if (doc != null) {
setCaretPosition(0);
moveCaretPosition(doc.getLength());
}
}
Moreover, I'd reuse the code like this:
public void selectAll() {
if (doc != null) {
select(0, getDocument().getLength());
}
}
---------
public void select(int selectionStart, int selectionEnd) {
// argument adjustment done by java.awt.TextComponent
int docLength = getDocument().getLength();
[...some bounds math...]
setCaretPosition(selectionStart);
moveCaretPosition(selectionEnd);
}
/**
* Selects all the text in the <code>TextComponent</code>.
* Does nothing on a <code>null</code> or empty document.
*/
public void selectAll() {
Document doc = getDocument();
if (doc != null) {
setCaretPosition(0);
moveCaretPosition(doc.getLength());
}
}