You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pivot.apache.org by gb...@apache.org on 2010/06/29 00:38:51 UTC
svn commit: r958770 - in /pivot/trunk:
demos/src/org/apache/pivot/demos/roweditor/
tutorials/src/org/apache/pivot/tutorials/webqueries/
wtk-terra/src/org/apache/pivot/wtk/skin/terra/ wtk/src/org/apache/pivot/wtk/
Author: gbrown
Date: Mon Jun 28 22:38:51 2010
New Revision: 958770
URL: http://svn.apache.org/viewvc?rev=958770&view=rev
Log:
Remove TextInput dependency on org.apache.pivot.wtk.text. Temporarily disable validation events - this will be re-incorporated in a later checkin.
Modified:
pivot/trunk/demos/src/org/apache/pivot/demos/roweditor/row_editor_demo.bxml
pivot/trunk/tutorials/src/org/apache/pivot/tutorials/webqueries/expense_sheet.bxml
pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraTextInputSkin.java
pivot/trunk/wtk/src/org/apache/pivot/wtk/TextInput.java
pivot/trunk/wtk/src/org/apache/pivot/wtk/TextInputListener.java
Modified: pivot/trunk/demos/src/org/apache/pivot/demos/roweditor/row_editor_demo.bxml
URL: http://svn.apache.org/viewvc/pivot/trunk/demos/src/org/apache/pivot/demos/roweditor/row_editor_demo.bxml?rev=958770&r1=958769&r2=958770&view=diff
==============================================================================
--- pivot/trunk/demos/src/org/apache/pivot/demos/roweditor/row_editor_demo.bxml (original)
+++ pivot/trunk/demos/src/org/apache/pivot/demos/roweditor/row_editor_demo.bxml Mon Jun 28 22:38:51 2010
@@ -29,7 +29,7 @@ limitations under the License.
<ListButton bxml:id="typeListButton" listData="['Hotel', 'Miscellaneous', 'Meals', 'Parking', 'Travel']"
selectedItemKey="type"/>
- <TextInput bxml:id="amountTextInput" strictValidation="true" textKey="amount">
+ <TextInput bxml:id="amountTextInput" textKey="amount" styles="{strictValidation:true}">
<validator>
<demo:CurrencyValidator/>
</validator>
Modified: pivot/trunk/tutorials/src/org/apache/pivot/tutorials/webqueries/expense_sheet.bxml
URL: http://svn.apache.org/viewvc/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/webqueries/expense_sheet.bxml?rev=958770&r1=958769&r2=958770&view=diff
==============================================================================
--- pivot/trunk/tutorials/src/org/apache/pivot/tutorials/webqueries/expense_sheet.bxml (original)
+++ pivot/trunk/tutorials/src/org/apache/pivot/tutorials/webqueries/expense_sheet.bxml Mon Jun 28 22:38:51 2010
@@ -56,8 +56,8 @@ limitations under the License.
<ListButton bxml:id="typeListButton" Form.label="%type" listData="@types.json"
selectedItemKey="type"/>
- <TextInput bxml:id="amountTextInput" Form.label="%amount" strictValidation="true"
- textKey="amount">
+ <TextInput bxml:id="amountTextInput" Form.label="%amount" textKey="amount"
+ styles="{strictValidation:true}">
<validator>
<webqueries:AmountValidator/>
</validator>
Modified: pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraTextInputSkin.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraTextInputSkin.java?rev=958770&r1=958769&r2=958770&view=diff
==============================================================================
--- pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraTextInputSkin.java (original)
+++ pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraTextInputSkin.java Mon Jun 28 22:38:51 2010
@@ -52,7 +52,6 @@ import org.apache.pivot.wtk.TextInputTex
import org.apache.pivot.wtk.Theme;
import org.apache.pivot.wtk.Window;
import org.apache.pivot.wtk.skin.ComponentSkin;
-import org.apache.pivot.wtk.text.TextNode;
import org.apache.pivot.wtk.validation.Validator;
/**
@@ -82,8 +81,7 @@ public class TerraTextInputSkin extends
switch (scrollDirection) {
case FORWARD: {
- TextNode textNode = textInput.getTextNode();
- if (selectionEnd < textNode.getCharacterCount() - 1) {
+ if (selectionEnd < textInput.getTextLength() - 1) {
selectionEnd++;
textInput.setSelection(selectionStart, selectionEnd - selectionStart + 1);
scrollCharacterToVisible(selectionEnd);
@@ -137,8 +135,6 @@ public class TerraTextInputSkin extends
private Color invalidBackgroundColor;
private Color borderColor;
private Color disabledBorderColor;
- private Insets padding;
-
private Color selectionColor;
private Color selectionBackgroundColor;
private Color inactiveSelectionColor;
@@ -148,6 +144,10 @@ public class TerraTextInputSkin extends
private Color disabledBevelColor;
private Color invalidBevelColor;
+ private Insets padding;
+
+ private boolean strictValidation = false;
+
private Dimensions averageCharacterSize;
private static final int SCROLL_RATE = 50;
@@ -189,10 +189,7 @@ public class TerraTextInputSkin extends
textInput.setCursor(Cursor.TEXT);
- TextNode textNode = textInput.getTextNode();
- if (textNode != null) {
- updateSelection();
- }
+ updateSelection();
}
@Override
@@ -228,50 +225,44 @@ public class TerraTextInputSkin extends
@Override
public void layout() {
TextInput textInput = (TextInput)getComponent();
- TextNode textNode = textInput.getTextNode();
glyphVector = null;
- if (textNode != null) {
- int n = textNode.getCharacterCount();
+ int n = textInput.getTextLength();
+ if (n > 0) {
+ String text;
+ if (textInput.isPassword()) {
+ StringBuilder buf = new StringBuilder(n);
+ for (int i = 0; i < n; i++) {
+ buf.append(BULLET);
+ }
- if (n > 0) {
- CharacterIterator ci = null;
- if (textInput.isPassword()) {
- StringBuilder buf = new StringBuilder(n);
- for (int i = 0; i < n; i++) {
- buf.append(BULLET);
- }
+ text = buf.toString();
+ } else {
+ text = textInput.getText();
+ }
- ci = new StringCharacterIterator(buf.toString());
- } else {
- ci= textNode.getCharacterIterator();
- }
+ CharacterIterator ci = new StringCharacterIterator(text);
- FontRenderContext fontRenderContext = Platform.getFontRenderContext();
- glyphVector = font.createGlyphVector(fontRenderContext, ci);
+ FontRenderContext fontRenderContext = Platform.getFontRenderContext();
+ glyphVector = font.createGlyphVector(fontRenderContext, ci);
- Rectangle2D textBounds = glyphVector.getLogicalBounds();
- int textWidth = (int)textBounds.getWidth();
- int width = getWidth();
+ Rectangle2D textBounds = glyphVector.getLogicalBounds();
+ int textWidth = (int)textBounds.getWidth();
+ int width = getWidth();
- if (textWidth - scrollLeft + padding.left + 1 < width - padding.right - 1) {
- // The right edge of the text is less than the right inset; align
- // the text's right edge with the inset
- scrollLeft = Math.max(textWidth + (padding.left + padding.right + 2) - width, 0);
- } else {
- // Scroll lead selection to visible
- int selectionStart = textInput.getSelectionStart();
- if (selectionStart < n
- && textInput.isFocused()) {
- scrollCharacterToVisible(selectionStart);
- }
+ if (textWidth - scrollLeft + padding.left + 1 < width - padding.right - 1) {
+ // The right edge of the text is less than the right inset; align
+ // the text's right edge with the inset
+ scrollLeft = Math.max(textWidth + (padding.left + padding.right + 2) - width, 0);
+ } else {
+ // Scroll lead selection to visible
+ int selectionStart = textInput.getSelectionStart();
+ if (selectionStart < n
+ && textInput.isFocused()) {
+ scrollCharacterToVisible(selectionStart);
}
}
- } else {
- // Set scrollLeft to 0
- scrollLeft = 0;
- updateSelection();
}
updateSelection();
@@ -914,6 +905,14 @@ public class TerraTextInputSkin extends
setPadding(Insets.decode(padding));
}
+ public boolean isStrictValidation() {
+ return strictValidation;
+ }
+
+ public void setStrictValidation(boolean strictValidation) {
+ this.strictValidation = strictValidation;
+ }
+
@Override
public boolean mouseMove(Component component, int x, int y) {
boolean consumed = super.mouseMove(component, x, y);
@@ -1024,11 +1023,7 @@ public class TerraTextInputSkin extends
if (button == Mouse.Button.LEFT
&& count > 1) {
TextInput textInput = (TextInput)getComponent();
- TextNode textNode = textInput.getTextNode();
-
- if (textNode != null) {
- textInput.setSelection(0, textNode.getCharacterCount());
- }
+ textInput.setSelection(0, textInput.getTextLength());
}
return super.mouseClick(component, button, x, y, count);
@@ -1044,30 +1039,27 @@ public class TerraTextInputSkin extends
&& character != 0x7F
&& !Keyboard.isPressed(Keyboard.Modifier.META)) {
TextInput textInput = (TextInput)getComponent();
- TextNode textNode = textInput.getTextNode();
- if (textNode != null) {
- if (textInput.getSelectionLength() == 0
- && textNode.getCharacterCount() == textInput.getMaximumLength()) {
- Toolkit.getDefaultToolkit().beep();
- } else {
- Validator validator = textInput.getValidator();
- boolean strictValidation = textInput.isStrictValidation();
+ if (textInput.getSelectionLength() == 0
+ && textInput.getTextLength() == textInput.getMaximumLength()) {
+ Toolkit.getDefaultToolkit().beep();
+ } else {
+ Validator validator = textInput.getValidator();
+ boolean strictValidation = isStrictValidation();
- if (validator != null
- && strictValidation) {
- StringBuilder buf = new StringBuilder(textNode.getText());
- int selectionStart = textInput.getSelectionStart();
- buf.insert(selectionStart, character);
-
- if (validator.isValid(buf.toString())) {
- textInput.insert(character);
- } else {
- Toolkit.getDefaultToolkit().beep();
- }
- } else {
+ if (validator != null
+ && strictValidation) {
+ StringBuilder buf = new StringBuilder(textInput.getText());
+ int selectionStart = textInput.getSelectionStart();
+ buf.insert(selectionStart, character);
+
+ if (validator.isValid(buf.toString())) {
textInput.insert(character);
+ } else {
+ Toolkit.getDefaultToolkit().beep();
}
+ } else {
+ textInput.insert(character);
}
}
}
@@ -1080,183 +1072,180 @@ public class TerraTextInputSkin extends
boolean consumed = super.keyPressed(component, keyCode, keyLocation);
TextInput textInput = (TextInput)getComponent();
- TextNode textNode = textInput.getTextNode();
-
- if (textNode != null) {
- Keyboard.Modifier commandModifier = Platform.getCommandModifier();
- if (keyCode == Keyboard.KeyCode.DELETE
- || keyCode == Keyboard.KeyCode.BACKSPACE) {
- boolean backspace = (keyCode == Keyboard.KeyCode.DELETE ? false : true);
- Validator validator = textInput.getValidator();
- boolean strictValidation = textInput.isStrictValidation();
+ Keyboard.Modifier commandModifier = Platform.getCommandModifier();
+ if (keyCode == Keyboard.KeyCode.DELETE
+ || keyCode == Keyboard.KeyCode.BACKSPACE) {
+ boolean backspace = (keyCode == Keyboard.KeyCode.DELETE ? false : true);
+
+ Validator validator = textInput.getValidator();
+ boolean strictValidation = isStrictValidation();
+
+ if (validator != null
+ && strictValidation) {
+ StringBuilder buf = new StringBuilder(textInput.getText());
+ int index = textInput.getSelectionStart();
+ int count = textInput.getSelectionLength();
- if (validator != null
- && strictValidation) {
- StringBuilder buf = new StringBuilder(textNode.getText());
- int index = textInput.getSelectionStart();
- int count = textInput.getSelectionLength();
-
- if (count > 0) {
- buf.delete(index, index + count);
- } else {
- if (backspace) {
- index--;
- }
-
- if (index >= 0
- && index < textNode.getCharacterCount()) {
- buf.deleteCharAt(index);
- }
+ if (count > 0) {
+ buf.delete(index, index + count);
+ } else {
+ if (backspace) {
+ index--;
}
- if (validator.isValid(buf.toString())) {
- textInput.delete(backspace);
- } else {
- Toolkit.getDefaultToolkit().beep();
+ if (index >= 0
+ && index < textInput.getTextLength()) {
+ buf.deleteCharAt(index);
}
- } else {
- textInput.delete(backspace);
}
- consumed = true;
- } else if (keyCode == Keyboard.KeyCode.LEFT) {
- int selectionStart = textInput.getSelectionStart();
- int selectionLength = textInput.getSelectionLength();
-
- if (Keyboard.isPressed(Keyboard.Modifier.SHIFT)
- && Keyboard.isPressed(Keyboard.Modifier.CTRL)) {
- // Add all preceding text to the selection
- selectionLength = selectionStart + selectionLength;
- selectionStart = 0;
- consumed = true;
- } else if (Keyboard.isPressed(Keyboard.Modifier.SHIFT)) {
- // Add the previous character to the selection
- if (selectionStart > 0) {
- selectionStart--;
- selectionLength++;
- }
-
- consumed = true;
- } else if (Keyboard.isPressed(Keyboard.Modifier.CTRL)) {
- // Clear the selection and move the caret to the beginning of
- // the text
- selectionStart = 0;
- selectionLength = 0;
- consumed = true;
+ if (validator.isValid(buf.toString())) {
+ textInput.delete(backspace);
} else {
- // Clear the selection and move the caret back by one
- // character
- if (selectionLength == 0
- && selectionStart > 0) {
- selectionStart--;
- consumed = true;
- }
-
- selectionLength = 0;
+ Toolkit.getDefaultToolkit().beep();
}
+ } else {
+ textInput.delete(backspace);
+ }
- textInput.setSelection(selectionStart, selectionLength);
+ consumed = true;
+ } else if (keyCode == Keyboard.KeyCode.LEFT) {
+ int selectionStart = textInput.getSelectionStart();
+ int selectionLength = textInput.getSelectionLength();
- if (textNode.getCharacterCount() > 0) {
- scrollCharacterToVisible(selectionStart);
- } else {
- setScrollLeft(0);
+ if (Keyboard.isPressed(Keyboard.Modifier.SHIFT)
+ && Keyboard.isPressed(Keyboard.Modifier.CTRL)) {
+ // Add all preceding text to the selection
+ selectionLength = selectionStart + selectionLength;
+ selectionStart = 0;
+ consumed = true;
+ } else if (Keyboard.isPressed(Keyboard.Modifier.SHIFT)) {
+ // Add the previous character to the selection
+ if (selectionStart > 0) {
+ selectionStart--;
+ selectionLength++;
}
- } else if (keyCode == Keyboard.KeyCode.RIGHT) {
- int selectionStart = textInput.getSelectionStart();
- int selectionLength = textInput.getSelectionLength();
-
- if (Keyboard.isPressed(Keyboard.Modifier.SHIFT)
- && Keyboard.isPressed(Keyboard.Modifier.CTRL)) {
- // Add all subsequent text to the selection
- selectionLength = textNode.getCharacterCount() - selectionStart;
- consumed = true;
- } else if (Keyboard.isPressed(Keyboard.Modifier.SHIFT)) {
- // Add the next character to the selection
- if (selectionStart + selectionLength < textNode.getCharacterCount()) {
- selectionLength++;
- }
+ consumed = true;
+ } else if (Keyboard.isPressed(Keyboard.Modifier.CTRL)) {
+ // Clear the selection and move the caret to the beginning of
+ // the text
+ selectionStart = 0;
+ selectionLength = 0;
+ consumed = true;
+ } else {
+ // Clear the selection and move the caret back by one
+ // character
+ if (selectionLength == 0
+ && selectionStart > 0) {
+ selectionStart--;
consumed = true;
- } else if (Keyboard.isPressed(Keyboard.Modifier.CTRL)) {
- // Clear the selection and move the caret to the end of
- // the text
- selectionStart = textNode.getCharacterCount();
- selectionLength = 0;
- consumed = true;
- } else {
- // Clear the selection and move the caret forward by one
- // character
- selectionStart += selectionLength;
-
- if (selectionLength == 0
- && selectionStart < textNode.getCharacterCount()) {
- selectionStart++;
- consumed = true;
- }
-
- selectionLength = 0;
}
- textInput.setSelection(selectionStart, selectionLength);
+ selectionLength = 0;
+ }
- if (textNode.getCharacterCount() > 0) {
- scrollCharacterToVisible(selectionStart + selectionLength - 1);
- } else {
- scrollLeft = 0;
- updateSelection();
- }
- } else if (keyCode == Keyboard.KeyCode.HOME) {
- // Move the caret to the beginning of the text
- if (Keyboard.isPressed(Keyboard.Modifier.SHIFT)) {
- textInput.setSelection(0, textInput.getSelectionStart());
- } else {
- textInput.setSelection(0, 0);
- }
+ textInput.setSelection(selectionStart, selectionLength);
+ if (textInput.getTextLength() > 0) {
+ scrollCharacterToVisible(selectionStart);
+ } else {
+ setScrollLeft(0);
+ }
+ } else if (keyCode == Keyboard.KeyCode.RIGHT) {
+ int selectionStart = textInput.getSelectionStart();
+ int selectionLength = textInput.getSelectionLength();
+
+ if (Keyboard.isPressed(Keyboard.Modifier.SHIFT)
+ && Keyboard.isPressed(Keyboard.Modifier.CTRL)) {
+ // Add all subsequent text to the selection
+ selectionLength = textInput.getTextLength() - selectionStart;
consumed = true;
- } else if (keyCode == Keyboard.KeyCode.END) {
- // Move the caret to the end of the text
- if (Keyboard.isPressed(Keyboard.Modifier.SHIFT)) {
- int selectionStart = textInput.getSelectionStart();
- textInput.setSelection(selectionStart, textNode.getCharacterCount()
- - selectionStart);
- } else {
- textInput.setSelection(textNode.getCharacterCount(), 0);
+ } else if (Keyboard.isPressed(Keyboard.Modifier.SHIFT)) {
+ // Add the next character to the selection
+ if (selectionStart + selectionLength < textInput.getTextLength()) {
+ selectionLength++;
}
consumed = true;
- } else if (keyCode == Keyboard.KeyCode.A
- && Keyboard.isPressed(commandModifier)) {
- // Select all
- textInput.setSelection(0, textNode.getCharacterCount());
+ } else if (Keyboard.isPressed(Keyboard.Modifier.CTRL)) {
+ // Clear the selection and move the caret to the end of
+ // the text
+ selectionStart = textInput.getTextLength();
+ selectionLength = 0;
consumed = true;
- } else if (keyCode == Keyboard.KeyCode.X
- && Keyboard.isPressed(commandModifier)) {
- if (textInput.isPassword()) {
- Toolkit.getDefaultToolkit().beep();
- } else {
- textInput.cut();
+ } else {
+ // Clear the selection and move the caret forward by one
+ // character
+ selectionStart += selectionLength;
+
+ if (selectionLength == 0
+ && selectionStart < textInput.getTextLength()) {
+ selectionStart++;
+ consumed = true;
}
- consumed = true;
- } else if (keyCode == Keyboard.KeyCode.C
- && Keyboard.isPressed(commandModifier)) {
- if (textInput.isPassword()) {
- Toolkit.getDefaultToolkit().beep();
- } else {
- textInput.copy();
- }
+ selectionLength = 0;
+ }
- consumed = true;
- } else if (keyCode == Keyboard.KeyCode.V
- && Keyboard.isPressed(commandModifier)) {
- textInput.paste();
- consumed = true;
+ textInput.setSelection(selectionStart, selectionLength);
+
+ if (textInput.getTextLength() > 0) {
+ scrollCharacterToVisible(selectionStart + selectionLength - 1);
+ } else {
+ scrollLeft = 0;
+ updateSelection();
+ }
+ } else if (keyCode == Keyboard.KeyCode.HOME) {
+ // Move the caret to the beginning of the text
+ if (Keyboard.isPressed(Keyboard.Modifier.SHIFT)) {
+ textInput.setSelection(0, textInput.getSelectionStart());
+ } else {
+ textInput.setSelection(0, 0);
+ }
+
+ consumed = true;
+ } else if (keyCode == Keyboard.KeyCode.END) {
+ // Move the caret to the end of the text
+ if (Keyboard.isPressed(Keyboard.Modifier.SHIFT)) {
+ int selectionStart = textInput.getSelectionStart();
+ textInput.setSelection(selectionStart, textInput.getTextLength()
+ - selectionStart);
} else {
- consumed = super.keyPressed(component, keyCode, keyLocation);
+ textInput.setSelection(textInput.getTextLength(), 0);
}
+
+ consumed = true;
+ } else if (keyCode == Keyboard.KeyCode.A
+ && Keyboard.isPressed(commandModifier)) {
+ // Select all
+ textInput.setSelection(0, textInput.getTextLength());
+ consumed = true;
+ } else if (keyCode == Keyboard.KeyCode.X
+ && Keyboard.isPressed(commandModifier)) {
+ if (textInput.isPassword()) {
+ Toolkit.getDefaultToolkit().beep();
+ } else {
+ textInput.cut();
+ }
+
+ consumed = true;
+ } else if (keyCode == Keyboard.KeyCode.C
+ && Keyboard.isPressed(commandModifier)) {
+ if (textInput.isPassword()) {
+ Toolkit.getDefaultToolkit().beep();
+ } else {
+ textInput.copy();
+ }
+
+ consumed = true;
+ } else if (keyCode == Keyboard.KeyCode.V
+ && Keyboard.isPressed(commandModifier)) {
+ textInput.paste();
+ consumed = true;
+ } else {
+ consumed = super.keyPressed(component, keyCode, keyLocation);
}
return consumed;
@@ -1288,9 +1277,8 @@ public class TerraTextInputSkin extends
}
if (textInput.getSelectionLength() == 0) {
- TextNode textNode = textInput.getTextNode();
int selectionStart = textInput.getSelectionStart();
- if (selectionStart < textNode.getCharacterCount()) {
+ if (selectionStart < textInput.getTextLength()) {
scrollCharacterToVisible(selectionStart);
}
@@ -1314,12 +1302,6 @@ public class TerraTextInputSkin extends
// Text input events
@Override
- public void textNodeChanged(TextInput textInput, TextNode previousTextNode) {
- layout();
- repaintComponent();
- }
-
- @Override
public void textSizeChanged(TextInput textInput, int previousTextSize) {
invalidateComponent();
}
@@ -1346,11 +1328,6 @@ public class TerraTextInputSkin extends
}
@Override
- public void strictValidationChanged(TextInput textInput) {
- // No-op
- }
-
- @Override
public void textValidChanged(TextInput textInput) {
repaintComponent();
}
@@ -1411,8 +1388,7 @@ public class TerraTextInputSkin extends
int selectionStart = textInput.getSelectionStart();
int selectionLength = textInput.getSelectionLength();
- TextNode textNode = textInput.getTextNode();
- int n = (textNode == null) ? 0 : textNode.getCharacterCount();
+ int n = textInput.getTextLength();
Bounds leadingSelectionBounds;
if (selectionStart < n) {
Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/TextInput.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/TextInput.java?rev=958770&r1=958769&r2=958770&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/TextInput.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/TextInput.java Mon Jun 28 22:38:51 2010
@@ -21,9 +21,6 @@ import java.io.IOException;
import org.apache.pivot.json.JSON;
import org.apache.pivot.util.ListenerList;
-import org.apache.pivot.wtk.text.Node;
-import org.apache.pivot.wtk.text.NodeListener;
-import org.apache.pivot.wtk.text.TextNode;
import org.apache.pivot.wtk.validation.Validator;
/**
@@ -81,13 +78,6 @@ public class TextInput extends Component
private static class TextInputListenerList extends ListenerList<TextInputListener>
implements TextInputListener {
@Override
- public void textNodeChanged(TextInput textInput, TextNode previousTextNode) {
- for (TextInputListener listener : this) {
- listener.textNodeChanged(textInput, previousTextNode);
- }
- }
-
- @Override
public void textSizeChanged(TextInput textInput, int previousTextSize) {
for (TextInputListener listener : this) {
listener.textSizeChanged(textInput, previousTextSize);
@@ -122,12 +112,6 @@ public class TextInput extends Component
}
}
- public void strictValidationChanged(TextInput textInput) {
- for (TextInputListener listener : this) {
- listener.strictValidationChanged(textInput);
- }
- }
-
@Override
public void textValidChanged(TextInput textInput) {
for (TextInputListener listener : this) {
@@ -196,15 +180,13 @@ public class TextInput extends Component
}
}
- // TODO Don't allow null values, only empty strings
- private TextNode textNode;
+ private String text = "";
private int selectionStart = 0;
private int selectionLength = 0;
private int textSize = DEFAULT_TEXT_SIZE;
private int maximumLength = Integer.MAX_VALUE;
-
private boolean password = false;
private String prompt = null;
@@ -213,44 +195,8 @@ public class TextInput extends Component
private TextBindMapping textBindMapping = null;
private Validator validator = null;
- private boolean strictValidation = false;
-
private boolean textValid = true;
- private NodeListener textNodeListener = new NodeListener.Adapter() {
- @Override
- public void rangeInserted(Node node, int offset, int characterCount) {
- // TODO If selected range changes, also fire selection change event?
- if (selectionStart + selectionLength > offset) {
- if (selectionStart > offset) {
- selectionStart += characterCount;
- } else {
- selectionLength += characterCount;
- }
- }
-
- textInputTextListeners.charactersInserted(TextInput.this, offset, characterCount);
- textInputTextListeners.textChanged(TextInput.this, null);
- validateText();
- }
-
- @Override
- public void rangeRemoved(Node node, int offset, int characterCount) {
- // TODO If selected range changes, also fire selection change event?
- if (selectionStart + selectionLength > offset) {
- if (selectionStart > offset) {
- selectionStart -= characterCount;
- } else {
- selectionLength -= characterCount;
- }
- }
-
- textInputTextListeners.charactersRemoved(TextInput.this, offset, characterCount);
- textInputTextListeners.textChanged(TextInput.this, null);
- validateText();
- }
- };
-
private TextInputListenerList textInputListeners = new TextInputListenerList();
private TextInputTextListenerList textInputTextListeners = new TextInputTextListenerList();
private TextInputSelectionListenerList textInputSelectionListeners = new TextInputSelectionListenerList();
@@ -260,7 +206,6 @@ public class TextInput extends Component
public TextInput() {
installThemeSkin(TextInput.class);
- setText("");
}
@Override
@@ -273,60 +218,36 @@ public class TextInput extends Component
super.setSkin(skin);
}
- /**
- * Returns the text node that backs the text input's content.
- */
- public TextNode getTextNode() {
- return textNode;
+ public String getText() {
+ return text;
}
- /**
- * Sets the text node that backs the text input's content.
- *
- * @param textNode
- */
- public void setTextNode(TextNode textNode) {
- if (textNode != null
- && textNode.getCharacterCount() > maximumLength) {
- throw new IllegalArgumentException("Text length is greater than maximum length.");
+ public void setText(String text) {
+ if (text == null) {
+ throw new IllegalArgumentException();
}
- TextNode previousTextNode = this.textNode;
-
- if (previousTextNode != textNode) {
- if (previousTextNode != null) {
- previousTextNode.getNodeListeners().remove(textNodeListener);
- }
+ if (text.length() > maximumLength) {
+ throw new IllegalArgumentException("Text length is greater than maximum length.");
+ }
- this.textNode = textNode;
+ // TODO Store previous selection start, length; previous text valid flag
- if (textNode == null) {
- selectionStart = 0;
- } else {
- selectionStart = textNode.getCharacterCount();
- textNode.getNodeListeners().add(textNodeListener);
- }
+ String previousText = this.text;
+ if (previousText != text) {
+ this.text = text;
+ selectionStart = text.length();
selectionLength = 0;
- textInputListeners.textNodeChanged(this, previousTextNode);
- textInputTextListeners.textChanged(this,
- (previousTextNode == null) ? null : previousTextNode.getText());
+ // TODO Update textValid flag
- // TODO If selected range changes, also fire selection change event
+ textInputTextListeners.textChanged(this, previousText);
- validateText();
+ // TODO Fire additional events as needed
}
}
- public String getText() {
- return (textNode == null) ? null : textNode.getText();
- }
-
- public void setText(String text) {
- setTextNode((text == null) ? null : new TextNode(text));
- }
-
/**
* Inserts a single character into the text input's content. The character
* replaces the current selection.
@@ -346,12 +267,8 @@ public class TextInput extends Component
* The text to insert.
*/
public void insert(String text) {
- if (textNode == null) {
- throw new IllegalStateException();
- }
-
if (text == null) {
- throw new IllegalArgumentException("text is null.");
+ throw new IllegalArgumentException();
}
if (selectionLength > 0) {
@@ -359,19 +276,26 @@ public class TextInput extends Component
}
// Insert the text
- if (textNode.getCharacterCount() + text.length() > maximumLength) {
+ if (this.text.length() + text.length() > maximumLength) {
throw new IllegalArgumentException("Insertion of text would exceed maximum length.");
}
- int length = textNode.getCharacterCount();
- textNode.insertText(text, selectionStart);
+ // TODO Store previous selection start, length; previous text valid flag
- // TODO Update the selection only if a listener did not modify the text?
- if (length + text.length() == textNode.getCharacterCount()) {
- setSelection(selectionStart + text.length(), 0);
- }
+ StringBuilder textBuilder = new StringBuilder(this.text.substring(0, selectionStart));
+ textBuilder.append(text);
+ textBuilder.append(this.text.substring(selectionStart));
+ this.text = textBuilder.toString();
+
+ selectionStart += text.length();
+ selectionLength = 0;
- // TODO Move the text node event logic here
+ // TODO Update textValid flag
+
+ textInputTextListeners.charactersInserted(TextInput.this, selectionStart, text.length());
+ textInputTextListeners.textChanged(TextInput.this, null);
+
+ // TODO Fire additional events as needed
}
/**
@@ -381,59 +305,50 @@ public class TextInput extends Component
* The text node's length, or <tt>0</tt> if the text node is <tt>null</tt>.
*/
public int getTextLength() {
- return (textNode == null) ? 0 : textNode.getCharacterCount();
+ return text.length();
}
public void delete(boolean backspace) {
- if (textNode == null) {
- throw new IllegalStateException();
- }
+ if (text.length() > 0) {
+ // TODO Store previous selection start, length; previous text valid flag
- if (selectionLength > 0) {
- // TODO Make this part of the undoable action (for all such
- // actions)
- textNode.removeRange(selectionStart, selectionLength);
-
- // TODO Move the text node event logic here
- } else {
- int offset = selectionStart;
+ int count;
+ if (selectionLength > 0) {
+ count = selectionLength;
+ selectionLength = 0;
+ } else {
+ if (backspace) {
+ selectionStart--;
+ }
- if (backspace) {
- offset--;
+ count = 1;
}
- if (offset >= 0
- && offset < textNode.getCharacterCount()) {
- textNode.removeRange(offset, 1);
+ if (selectionStart < text.length()) {
+ StringBuilder textBuilder = new StringBuilder(text.substring(0, selectionStart));
+ textBuilder.append(text.substring(selectionStart + count));
+ text = textBuilder.toString();
}
- }
- }
- public void cut() {
- if (textNode == null) {
- throw new IllegalStateException();
- }
+ // TODO Update textValid flag
- // Delete any selected text and put it on the clipboard
- if (selectionLength > 0) {
- TextNode removedRange =
- (TextNode)textNode.removeRange(selectionStart, selectionLength);
+ textInputTextListeners.charactersRemoved(TextInput.this, selectionStart, count);
+ textInputTextListeners.textChanged(TextInput.this, null);
- LocalManifest clipboardContent = new LocalManifest();
- clipboardContent.putText(removedRange.getText());
- Clipboard.setContent(clipboardContent);
+ // TODO Fire additional events as needed
}
}
- public void copy() {
- if (textNode == null) {
- throw new IllegalStateException();
- }
+ public void cut() {
+ copy();
+ delete(false);
+ }
+ public void copy() {
// Copy selection to clipboard
String selectedText = getSelectedText();
- if (selectedText != null) {
+ if (selectedText.length() > 0) {
LocalManifest clipboardContent = new LocalManifest();
clipboardContent.putText(selectedText);
Clipboard.setContent(clipboardContent);
@@ -441,10 +356,6 @@ public class TextInput extends Component
}
public void paste() {
- if (textNode == null) {
- throw new IllegalStateException();
- }
-
Manifest clipboardContent = Clipboard.getContent();
if (clipboardContent != null
@@ -458,17 +369,9 @@ public class TextInput extends Component
}
if (text != null) {
- if ((text.length() + textNode.getCharacterCount()) > maximumLength) {
+ if ((this.text.length() + text.length()) > maximumLength) {
Toolkit.getDefaultToolkit().beep();
} else {
- // Remove any existing selection
- if (selectionLength > 0) {
- // TODO Make this part of the undoable action (for all such
- // actions)
- textNode.removeRange(selectionStart, selectionLength);
- }
-
- // Insert the clipboard contents
insert(text);
}
}
@@ -526,16 +429,12 @@ public class TextInput extends Component
* The length of the selection.
*/
public void setSelection(int selectionStart, int selectionLength) {
- if (textNode == null) {
- throw new IllegalStateException();
- }
-
if (selectionLength < 0) {
throw new IllegalArgumentException("selectionLength is negative.");
}
if (selectionStart < 0
- || selectionStart + selectionLength > textNode.getCharacterCount()) {
+ || selectionStart + selectionLength > text.length()) {
throw new IndexOutOfBoundsException();
}
@@ -571,11 +470,7 @@ public class TextInput extends Component
* Selects all text.
*/
public void selectAll() {
- if (textNode == null) {
- throw new IllegalStateException();
- }
-
- setSelection(0, textNode.getCharacterCount());
+ setSelection(0, text.length());
}
/**
@@ -589,19 +484,10 @@ public class TextInput extends Component
* Returns the currently selected text.
*
* @return
- * A new string containing a copy of the text in the selected range, or
- * <tt>null</tt> if nothing is selected.
+ * A new string containing a copy of the text in the selected range.
*/
public String getSelectedText() {
- String selectedText = null;
-
- if (selectionLength > 0) {
- TextNode selectedRange = (TextNode)textNode.getRange(selectionStart,
- selectionStart + selectionLength);
- selectedText = selectedRange.getText();
- }
-
- return selectedText;
+ return text.substring(selectionStart, selectionStart + selectionLength);
}
/**
@@ -658,11 +544,9 @@ public class TextInput extends Component
if (previousMaximumLength != maximumLength) {
// Truncate the text, if necessary
- if (textNode != null) {
- int characterCount = textNode.getCharacterCount();
- if (characterCount > maximumLength) {
- textNode.removeText(maximumLength, characterCount - maximumLength);
- }
+ int characterCount = text.length();
+ if (characterCount > maximumLength) {
+ text = text.substring(0, maximumLength);
}
this.maximumLength = maximumLength;
@@ -849,26 +733,6 @@ public class TextInput extends Component
}
/**
- * Returns the text input's strict validation flag.
- */
- public boolean isStrictValidation() {
- return strictValidation;
- }
-
- /**
- * Sets the text input's strict validation flag. When enabled, only valid text will be
- * accepted by the text input.
- *
- * @param strictValidation
- */
- public void setStrictValidation(boolean strictValidation) {
- if (this.strictValidation != strictValidation) {
- this.strictValidation = strictValidation;
- textInputListeners.strictValidationChanged(this);
- }
- }
-
- /**
* Tells whether or not this text input's text is currently valid as
* defined by its validator. If there is no validator associated with this
* text input, the text is assumed to always be valid.
@@ -881,6 +745,8 @@ public class TextInput extends Component
* Updates the valid state after the text or the validator has changed.
*/
private void validateText() {
+ // TODO VERY IMPORTANT Eliminate this method
+
String text = getText();
boolean textValid = (validator == null || text == null) ? true : validator.isValid(text);
Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/TextInputListener.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/TextInputListener.java?rev=958770&r1=958769&r2=958770&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/TextInputListener.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/TextInputListener.java Mon Jun 28 22:38:51 2010
@@ -16,7 +16,6 @@
*/
package org.apache.pivot.wtk;
-import org.apache.pivot.wtk.text.TextNode;
import org.apache.pivot.wtk.validation.Validator;
/**
@@ -28,10 +27,6 @@ public interface TextInputListener {
*/
public static class Adapter implements TextInputListener {
@Override
- public void textNodeChanged(TextInput textInput, TextNode previousTextNode) {
- }
-
- @Override
public void textSizeChanged(TextInput textInput, int previousTextSize) {
}
@@ -52,23 +47,11 @@ public interface TextInputListener {
}
@Override
- public void strictValidationChanged(TextInput textInput) {
- }
-
- @Override
public void textValidChanged(TextInput textInput) {
}
}
/**
- * Called when a text input's text node has changed.
- *
- * @param textInput
- * @param previousTextNode
- */
- public void textNodeChanged(TextInput textInput, TextNode previousTextNode);
-
- /**
* Called when a text input's text size has changed.
*
* @param textInput
@@ -108,13 +91,6 @@ public interface TextInputListener {
public void textValidatorChanged(TextInput textInput, Validator previousValidator);
/**
- * Called when a text input's strict validation flag has changed.
- *
- * @param textInput
- */
- public void strictValidationChanged(TextInput textInput);
-
- /**
* Called when the text changes validity.
*
* @param textInput