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/09/03 00:37:18 UTC
svn commit: r992139 - in /pivot/trunk/wtk/src/org/apache/pivot/wtk:
TextArea2.java TextInput.java skin/TextAreaSkin.java
skin/TextAreaSkin2.java skin/TextAreaSkinTextNodeView.java text/TextNode.java
Author: gbrown
Date: Thu Sep 2 22:37:17 2010
New Revision: 992139
URL: http://svn.apache.org/viewvc?rev=992139&view=rev
Log:
Text updates.
Modified:
pivot/trunk/wtk/src/org/apache/pivot/wtk/TextArea2.java
pivot/trunk/wtk/src/org/apache/pivot/wtk/TextInput.java
pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextAreaSkin.java
pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextAreaSkin2.java
pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextAreaSkinTextNodeView.java
pivot/trunk/wtk/src/org/apache/pivot/wtk/text/TextNode.java
Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/TextArea2.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/TextArea2.java?rev=992139&r1=992138&r2=992139&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/TextArea2.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/TextArea2.java Thu Sep 2 22:37:17 2010
@@ -23,7 +23,6 @@ import java.io.InputStreamReader;
import java.io.Reader;
import java.io.StringReader;
import java.net.URL;
-import java.text.CharacterIterator;
import org.apache.pivot.collections.ArrayList;
import org.apache.pivot.json.JSON;
@@ -43,52 +42,37 @@ public class TextArea2 extends Component
*
* @param x
* @param y
- *
- * @return
- * The insertion point for the given location.
*/
public int getInsertionPoint(int x, int y);
/**
- * Returns the next insertion point given an x coordinate and a character offset.
+ * Returns the next insertion point given an x coordinate and a
+ * character index.
*
* @param x
* @param from
* @param direction
- *
- * @return
- * The next insertion point.
*/
public int getNextInsertionPoint(int x, int from, FocusTraversalDirection direction);
/**
- * Returns the row index of the character at a given offset within the document.
+ * Returns the row index of the character at a given index.
*
- * @param offset
- *
- * @return
- * The row index of the character at the given offset.
+ * @param index
*/
- public int getRowIndex(int offset);
+ public int getRowIndex(int index);
/**
- * Returns the total number of rows in the document.
- *
- * @return
- * The number of rows in the document.
+ * Returns the total number of rows in the text area.
*/
public int getRowCount();
/**
- * Returns the bounds of the character at a given offset within the
- * document.
+ * Returns the bounds of the character at a given index.
*
- * @param offset
- *
- * @return
- * The bounds of the character at the given offset.
+ * @param index
*/
- public Bounds getCharacterBounds(int offset);
+ public Bounds getCharacterBounds(int index);
}
/**
@@ -190,7 +174,7 @@ public class TextArea2 extends Component
}
private ArrayList<StringBuilder> paragraphs = null;
- private int length = 0;
+ private int characterCount = 0;
private int selectionStart = 0;
private int selectionLength = 0;
@@ -207,6 +191,8 @@ public class TextArea2 extends Component
private TextAreaSelectionListenerList textAreaSelectionListeners = new TextAreaSelectionListenerList();
private TextAreaBindingListenerList textAreaBindingListeners = new TextAreaBindingListenerList();
+ private static final int INITIAL_PARAGRAPH_CAPACITY = 256;
+
public TextArea2() {
setText("");
@@ -223,11 +209,6 @@ public class TextArea2 extends Component
super.setSkin(skin);
}
- public CharacterIterator getCharacters() {
- // TODO
- return null;
- }
-
/**
* Returns the text content of the text area.
*
@@ -248,8 +229,49 @@ public class TextArea2 extends Component
* A string containing a copy of the text area's text content.
*/
public String getText(int beginIndex, int endIndex) {
- // TODO
- return null;
+ if (beginIndex > endIndex) {
+ throw new IllegalArgumentException();
+ }
+
+ if (beginIndex < 0
+ || endIndex > characterCount) {
+ throw new IndexOutOfBoundsException();
+ }
+
+ StringBuilder textBuilder = new StringBuilder(endIndex - beginIndex);
+
+ // Determine the start of the range
+ int paragraphIndex = 0;
+ int characterOffset = 0;
+
+ StringBuilder paragraph = paragraphs.get(paragraphIndex);
+ int paragraphLength = paragraph.length();
+
+ while (characterOffset + paragraphLength < beginIndex) {
+ characterOffset += paragraphLength;
+
+ paragraph = paragraphs.get(++paragraphIndex);
+ paragraphLength = paragraph.length();
+ }
+
+ characterOffset = beginIndex - characterOffset;
+
+ // Walk from begin index to end index copying characters into text builder
+ for (int index = beginIndex; index < endIndex; index++) {
+ textBuilder.append(paragraph.charAt(characterOffset++));
+
+ if (characterOffset == paragraphLength) {
+ if (index != endIndex - 1) {
+ textBuilder.append('\n');
+ }
+
+ paragraph = paragraphs.get(++paragraphIndex);
+ paragraphLength = paragraph.length();
+ characterOffset = 0;
+ }
+ }
+
+ return textBuilder.toString();
}
/**
@@ -296,20 +318,20 @@ public class TextArea2 extends Component
// Construct the paragraph list
paragraphs = new ArrayList<StringBuilder>();
- length = 0;
+ characterCount = 0;
- StringBuilder paragraph = new StringBuilder();
+ StringBuilder paragraph = new StringBuilder(INITIAL_PARAGRAPH_CAPACITY);
int c = textReader.read();
while (c != -1) {
if (c == '\n') {
paragraphs.add(paragraph);
- paragraph = new StringBuilder();
+ paragraph = new StringBuilder(INITIAL_PARAGRAPH_CAPACITY);
} else {
paragraph.append(c);
}
- length++;
+ characterCount++;
c = textReader.read();
}
@@ -319,7 +341,7 @@ public class TextArea2 extends Component
// Update selection
int previousSelectionStart = selectionStart;
int previousSelectionLength = selectionLength;
- selectionStart = length;
+ selectionStart = characterCount;
selectionLength = 0;
// Fire change events
@@ -336,13 +358,63 @@ public class TextArea2 extends Component
throw new IllegalArgumentException();
}
- if (length + text.length() > maximumLength) {
+ if (index < 0
+ || index > characterCount) {
+ throw new IndexOutOfBoundsException();
+ }
+
+ if (characterCount + text.length() > maximumLength) {
throw new IllegalArgumentException("Insertion of text would exceed maximum length.");
}
- // Insert the text
if (text.length() > 0) {
- // TODO (don't forget to update length)
+ // Determine the insertion point
+ int paragraphIndex, characterOffset;
+ if (index == characterCount) {
+ paragraphIndex = paragraphs.getLength() - 1;
+ characterOffset = paragraphs.get(paragraphIndex).length();
+ } else {
+ paragraphIndex = 0;
+ characterOffset = 0;
+
+ int paragraphCount = paragraphs.getLength();
+ while (paragraphIndex < paragraphCount) {
+ StringBuilder paragraph = paragraphs.get(paragraphIndex);
+ int paragraphLength = paragraph.length();
+
+ if (characterOffset + paragraphLength > index) {
+ break;
+ } else {
+ characterOffset += paragraphLength;
+ paragraphIndex++;
+ }
+ }
+
+ characterOffset = index - characterOffset;
+ }
+
+ // Insert the text
+ StringBuilder textBuilder = new StringBuilder();
+
+ for (int i = 0, n = text.length(); i < n; i++) {
+ char c = text.charAt(i);
+
+ if (c == '\n') {
+ StringBuilder paragraph = paragraphs.get(paragraphIndex);
+ paragraph.insert(characterOffset, textBuilder);
+
+ characterOffset += textBuilder.length();
+ textBuilder = new StringBuilder(paragraph.substring(characterOffset));
+ paragraphs.insert(textBuilder, ++paragraphIndex);
+ } else {
+ textBuilder.append(c);
+ }
+ }
+
+ StringBuilder paragraph = paragraphs.get(paragraphIndex);
+ paragraph.insert(characterOffset, textBuilder);
+
+ characterCount += text.length();
// Update selection
int previousSelectionStart = selectionStart;
@@ -363,7 +435,12 @@ public class TextArea2 extends Component
public void removeText(int index, int count) {
if (count > 0) {
- // TODO (don't forget to update length)
+ // TODO Identify begin paragraph index/offset
+ // TODO Identify end paragraph index/offset
+ // TODO Remove leading/trailing characters
+ // TODO Removing any intervening paragraphs
+
+ characterCount -= count;
// Update the selection
int previousSelectionStart = selectionStart;
@@ -383,26 +460,27 @@ public class TextArea2 extends Component
}
/**
- * Returns the number of characters in the text area, including line break
- * characters.
+ * Returns a character sequence representing a paragraph's content.
+ *
+ * @param index
*/
- public int getCharacterCount() {
- return length;
+ public CharSequence getParagraph(int index) {
+ return paragraphs.get(index);
}
/**
- * Returns a character iterator over the text area's content.
+ * Returns the number of paragraphs in the text area.
*/
- public CharacterIterator getCharacterIterator() {
- return getCharacterIterator(0, getCharacterCount());
+ public int getParagraphCount() {
+ return paragraphs.getLength();
}
/**
- * Returns a character iterator over a portion the text area's content.
+ * Returns the number of characters in the text area, including line break
+ * characters.
*/
- public CharacterIterator getCharacterIterator(int beginIndex, int endIndex) {
- // TODO
- return null;
+ public int getCharacterCount() {
+ return characterCount;
}
/**
@@ -445,7 +523,7 @@ public class TextArea2 extends Component
}
if (text != null) {
- if ((length + text.length()) > maximumLength) {
+ if ((characterCount + text.length()) > maximumLength) {
Toolkit.getDefaultToolkit().beep();
} else {
insertText(text, selectionStart);
@@ -510,7 +588,7 @@ public class TextArea2 extends Component
}
if (selectionStart < 0
- || selectionStart + selectionLength > length) {
+ || selectionStart + selectionLength > characterCount) {
throw new IndexOutOfBoundsException();
}
@@ -546,7 +624,7 @@ public class TextArea2 extends Component
* Selects all text.
*/
public void selectAll() {
- setSelection(0, length);
+ setSelection(0, characterCount);
}
/**
@@ -590,19 +668,20 @@ public class TextArea2 extends Component
int previousMaximumLength = this.maximumLength;
if (previousMaximumLength != maximumLength) {
- int previousTextLength = length;
-
this.maximumLength = maximumLength;
// Truncate the text, if necessary
- if (previousTextLength > maximumLength) {
- // TODO (don't forget to update length)
+ int previousCharacterCount = characterCount;
+ if (previousCharacterCount > maximumLength) {
+ // TODO
+
+ characterCount = maximumLength;
}
// Fire change events
textAreaListeners.maximumLengthChanged(this, previousMaximumLength);
- if (length != previousTextLength) {
+ if (characterCount != previousCharacterCount) {
textAreaContentListeners.textChanged(this);
}
}
@@ -741,9 +820,9 @@ public class TextArea2 extends Component
return textAreaSkin.getNextInsertionPoint(x, from, direction);
}
- public int getRowIndex(int offset) {
+ public int getRowIndex(int index) {
TextArea.Skin textAreaSkin = (TextArea.Skin)getSkin();
- return textAreaSkin.getRowIndex(offset);
+ return textAreaSkin.getRowIndex(index);
}
public int getRowCount() {
@@ -751,9 +830,9 @@ public class TextArea2 extends Component
return textAreaSkin.getRowCount();
}
- public Bounds getCharacterBounds(int offset) {
+ public Bounds getCharacterBounds(int index) {
TextArea.Skin textAreaSkin = (TextArea.Skin)getSkin();
- return textAreaSkin.getCharacterBounds(offset);
+ return textAreaSkin.getCharacterBounds(index);
}
public ListenerList<TextAreaListener2> getTextAreaListeners() {
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=992139&r1=992138&r2=992139&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/TextInput.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/TextInput.java Thu Sep 2 22:37:17 2010
@@ -18,10 +18,8 @@ package org.apache.pivot.wtk;
import java.awt.Toolkit;
import java.io.IOException;
-import java.text.CharacterIterator;
import org.apache.pivot.json.JSON;
-import org.apache.pivot.text.CharSequenceCharacterIterator;
import org.apache.pivot.util.ListenerList;
import org.apache.pivot.util.Vote;
import org.apache.pivot.wtk.validation.Validator;
@@ -39,22 +37,15 @@ public class TextInput extends Component
* Returns the insertion point for a given location.
*
* @param x
- *
- * @return
- * The insertion point for the given location.
*/
public int getInsertionPoint(int x);
/**
- * Returns the bounds of the character at a given offset within the
- * document.
- *
- * @param offset
+ * Returns the bounds of the character at a given index.
*
- * @return
- * The bounds of the character at the given offset.
+ * @param index
*/
- public Bounds getCharacterBounds(int offset);
+ public Bounds getCharacterBounds(int index);
}
/**
@@ -226,7 +217,7 @@ public class TextInput extends Component
}
}
- private StringBuilder textBuilder = new StringBuilder();
+ private StringBuilder characters = new StringBuilder();
private int selectionStart = 0;
private int selectionLength = 0;
@@ -285,7 +276,7 @@ public class TextInput extends Component
* A string containing a copy of the text area's text content.
*/
public String getText(int beginIndex, int endIndex) {
- return textBuilder.substring(beginIndex, endIndex);
+ return characters.substring(beginIndex, endIndex);
}
public void setText(String text) {
@@ -297,7 +288,7 @@ public class TextInput extends Component
throw new IllegalArgumentException("Text length is greater than maximum length.");
}
- textBuilder = new StringBuilder(text);
+ characters = new StringBuilder(text);
// Update selection
int previousSelectionStart = selectionStart;
@@ -327,7 +318,7 @@ public class TextInput extends Component
throw new IllegalArgumentException();
}
- if (textBuilder.length() + text.length() > maximumLength) {
+ if (characters.length() + text.length() > maximumLength) {
throw new IllegalArgumentException("Insertion of text would exceed maximum length.");
}
@@ -336,7 +327,7 @@ public class TextInput extends Component
if (vote == Vote.APPROVE) {
// Insert the text
- textBuilder.insert(index, text);
+ characters.insert(index, text);
// Update selection
int previousSelectionStart = selectionStart;
@@ -372,7 +363,7 @@ public class TextInput extends Component
if (vote == Vote.APPROVE) {
// Remove the text
- textBuilder.delete(index, index + count);
+ characters.delete(index, index + count);
// Update the selection
int previousSelectionStart = selectionStart;
@@ -403,24 +394,17 @@ public class TextInput extends Component
}
/**
- * Returns the number of characters in the text input.
+ * Returns a character sequence representing the text input's content.
*/
- public int getCharacterCount() {
- return textBuilder.length();
+ public CharSequence getCharacters() {
+ return characters;
}
/**
- * Returns a character iterator over the text input's content.
- */
- public CharacterIterator getCharacterIterator() {
- return getCharacterIterator(0, getCharacterCount());
- }
-
- /**
- * Returns a character iterator over a portion the text input's content.
+ * Returns the number of characters in the text input.
*/
- public CharacterIterator getCharacterIterator(int beginIndex, int endIndex) {
- return new CharSequenceCharacterIterator(textBuilder, beginIndex, endIndex);
+ public int getCharacterCount() {
+ return characters.length();
}
/**
@@ -463,7 +447,7 @@ public class TextInput extends Component
}
if (text != null) {
- if ((textBuilder.length() + text.length()) > maximumLength) {
+ if ((characters.length() + text.length()) > maximumLength) {
Toolkit.getDefaultToolkit().beep();
} else {
insertText(text, selectionStart);
@@ -528,7 +512,7 @@ public class TextInput extends Component
}
if (selectionStart < 0
- || selectionStart + selectionLength > textBuilder.length()) {
+ || selectionStart + selectionLength > characters.length()) {
throw new IndexOutOfBoundsException();
}
@@ -564,7 +548,7 @@ public class TextInput extends Component
* Selects all text.
*/
public void selectAll() {
- setSelection(0, textBuilder.length());
+ setSelection(0, characters.length());
}
/**
@@ -637,19 +621,18 @@ public class TextInput extends Component
int previousMaximumLength = this.maximumLength;
if (previousMaximumLength != maximumLength) {
- int previousTextLength = textBuilder.length();
-
this.maximumLength = maximumLength;
// Truncate the text, if necessary
- if (previousTextLength > maximumLength) {
- textBuilder.delete(maximumLength, previousTextLength);
+ int previousCharacterCount = characters.length();
+ if (previousCharacterCount > maximumLength) {
+ characters.delete(maximumLength, previousCharacterCount);
}
// Fire change events
textInputListeners.maximumLengthChanged(this, previousMaximumLength);
- if (textBuilder.length() != previousTextLength) {
+ if (characters.length() != previousCharacterCount) {
textInputContentListeners.textChanged(this);
}
}
@@ -805,9 +788,9 @@ public class TextInput extends Component
return textInputSkin.getInsertionPoint(x);
}
- public Bounds getCharacterBounds(int offset) {
+ public Bounds getCharacterBounds(int index) {
TextInput.Skin textInputSkin = (TextInput.Skin)getSkin();
- return textInputSkin.getCharacterBounds(offset);
+ return textInputSkin.getCharacterBounds(index);
}
/**
Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextAreaSkin.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextAreaSkin.java?rev=992139&r1=992138&r2=992139&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextAreaSkin.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextAreaSkin.java Thu Sep 2 22:37:17 2010
@@ -399,6 +399,35 @@ public class TextAreaSkin extends Contai
}
}
+ public Font getFont() {
+ return font;
+ }
+
+ public void setFont(Font font) {
+ if (font == null) {
+ throw new IllegalArgumentException("font is null.");
+ }
+
+ this.font = font;
+ invalidateComponent();
+ }
+
+ public final void setFont(String font) {
+ if (font == null) {
+ throw new IllegalArgumentException("font is null.");
+ }
+
+ setFont(decodeFont(font));
+ }
+
+ public final void setFont(Dictionary<String, ?> font) {
+ if (font == null) {
+ throw new IllegalArgumentException("font is null.");
+ }
+
+ setFont(Theme.deriveFont(font));
+ }
+
public Color getColor() {
return color;
}
@@ -441,35 +470,6 @@ public class TextAreaSkin extends Contai
setColor(GraphicsUtilities.decodeColor(inactiveColor));
}
- public Font getFont() {
- return font;
- }
-
- public void setFont(Font font) {
- if (font == null) {
- throw new IllegalArgumentException("font is null.");
- }
-
- this.font = font;
- invalidateComponent();
- }
-
- public final void setFont(String font) {
- if (font == null) {
- throw new IllegalArgumentException("font is null.");
- }
-
- setFont(decodeFont(font));
- }
-
- public final void setFont(Dictionary<String, ?> font) {
- if (font == null) {
- throw new IllegalArgumentException("font is null.");
- }
-
- setFont(Theme.deriveFont(font));
- }
-
public Color getSelectionColor() {
return selectionColor;
}
@@ -608,6 +608,7 @@ public class TextAreaSkin extends Contai
}
}
}
+
@Override
public boolean mouseMove(Component component, int x, int y) {
boolean consumed = super.mouseMove(component, x, y);
Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextAreaSkin2.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextAreaSkin2.java?rev=992139&r1=992138&r2=992139&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextAreaSkin2.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextAreaSkin2.java Thu Sep 2 22:37:17 2010
@@ -16,22 +16,54 @@
*/
package org.apache.pivot.wtk.skin;
+import java.awt.Color;
+import java.awt.Font;
import java.awt.Graphics2D;
+import java.awt.Transparency;
+import org.apache.pivot.collections.Dictionary;
import org.apache.pivot.wtk.Bounds;
import org.apache.pivot.wtk.Component;
import org.apache.pivot.wtk.Dimensions;
import org.apache.pivot.wtk.FocusTraversalDirection;
+import org.apache.pivot.wtk.GraphicsUtilities;
+import org.apache.pivot.wtk.Insets;
import org.apache.pivot.wtk.TextArea2;
import org.apache.pivot.wtk.TextAreaListener2;
import org.apache.pivot.wtk.TextAreaContentListener2;
import org.apache.pivot.wtk.TextAreaSelectionListener2;
+import org.apache.pivot.wtk.Theme;
/**
* Text area skin.
*/
public class TextAreaSkin2 extends ComponentSkin implements TextArea2.Skin,
TextAreaListener2, TextAreaContentListener2, TextAreaSelectionListener2 {
+ private Font font;
+ private Color color;
+ private Color backgroundColor;
+ private Color inactiveColor;
+ private Color selectionColor;
+ private Color selectionBackgroundColor;
+ private Color inactiveSelectionColor;
+ private Color inactiveSelectionBackgroundColor;
+
+ private Insets margin = new Insets(4);
+
+ private boolean wrapText = true;
+
+ public TextAreaSkin2() {
+ Theme theme = Theme.getTheme();
+ font = theme.getFont();
+ color = Color.BLACK;
+ backgroundColor = Color.WHITE;
+ inactiveColor = Color.GRAY;
+ selectionColor = Color.LIGHT_GRAY;
+ selectionBackgroundColor = Color.BLACK;
+ inactiveSelectionColor = Color.LIGHT_GRAY;
+ inactiveSelectionBackgroundColor = Color.BLACK;
+ }
+
@Override
public void install(Component component) {
super.install(component);
@@ -67,6 +99,12 @@ public class TextAreaSkin2 extends Compo
// TODO
}
+ @Override
+ public boolean isOpaque() {
+ return (backgroundColor != null
+ && backgroundColor.getTransparency() == Transparency.OPAQUE);
+ }
+
public int getInsertionPoint(int x, int y) {
// TODO
return -1;
@@ -77,7 +115,7 @@ public class TextAreaSkin2 extends Compo
return -1;
}
- public int getRowIndex(int offset) {
+ public int getRowIndex(int index) {
// TODO
return -1;
}
@@ -87,11 +125,233 @@ public class TextAreaSkin2 extends Compo
return 0;
}
- public Bounds getCharacterBounds(int offset) {
+ public Bounds getCharacterBounds(int index) {
// TODO
return null;
}
+ public Font getFont() {
+ return font;
+ }
+
+ public void setFont(Font font) {
+ if (font == null) {
+ throw new IllegalArgumentException("font is null.");
+ }
+
+ this.font = font;
+ invalidateComponent();
+ }
+
+ public final void setFont(String font) {
+ if (font == null) {
+ throw new IllegalArgumentException("font is null.");
+ }
+
+ setFont(decodeFont(font));
+ }
+
+ public final void setFont(Dictionary<String, ?> font) {
+ if (font == null) {
+ throw new IllegalArgumentException("font is null.");
+ }
+
+ setFont(Theme.deriveFont(font));
+ }
+
+ public Color getColor() {
+ return color;
+ }
+
+ public void setColor(Color color) {
+ if (color == null) {
+ throw new IllegalArgumentException("color is null.");
+ }
+
+ this.color = color;
+ repaintComponent();
+ }
+
+ public final void setColor(String color) {
+ if (color == null) {
+ throw new IllegalArgumentException("color is null.");
+ }
+
+ setColor(GraphicsUtilities.decodeColor(color));
+ }
+
+ public Color getBackgroundColor() {
+ return backgroundColor;
+ }
+
+ public void setBackgroundColor(Color backgroundColor) {
+ this.backgroundColor = backgroundColor;
+ repaintComponent();
+ }
+
+ public final void setBackgroundColor(String backgroundColor) {
+ if (backgroundColor == null) {
+ throw new IllegalArgumentException("backgroundColor is null");
+ }
+
+ setBackgroundColor(GraphicsUtilities.decodeColor(backgroundColor));
+ }
+
+ public Color getInactiveColor() {
+ return inactiveColor;
+ }
+
+ public void setInactiveColor(Color inactiveColor) {
+ if (inactiveColor == null) {
+ throw new IllegalArgumentException("inactiveColor is null.");
+ }
+
+ this.inactiveColor = inactiveColor;
+ repaintComponent();
+ }
+
+ public final void setInactiveColor(String inactiveColor) {
+ if (inactiveColor == null) {
+ throw new IllegalArgumentException("inactiveColor is null.");
+ }
+
+ setColor(GraphicsUtilities.decodeColor(inactiveColor));
+ }
+
+ public Color getSelectionColor() {
+ return selectionColor;
+ }
+
+ public void setSelectionColor(Color selectionColor) {
+ if (selectionColor == null) {
+ throw new IllegalArgumentException("selectionColor is null.");
+ }
+
+ this.selectionColor = selectionColor;
+ repaintComponent();
+ }
+
+ public final void setSelectionColor(String selectionColor) {
+ if (selectionColor == null) {
+ throw new IllegalArgumentException("selectionColor is null.");
+ }
+
+ setSelectionColor(GraphicsUtilities.decodeColor(selectionColor));
+ }
+
+ public Color getSelectionBackgroundColor() {
+ return selectionBackgroundColor;
+ }
+
+ public void setSelectionBackgroundColor(Color selectionBackgroundColor) {
+ if (selectionBackgroundColor == null) {
+ throw new IllegalArgumentException("selectionBackgroundColor is null.");
+ }
+
+ this.selectionBackgroundColor = selectionBackgroundColor;
+ repaintComponent();
+ }
+
+ public final void setSelectionBackgroundColor(String selectionBackgroundColor) {
+ if (selectionBackgroundColor == null) {
+ throw new IllegalArgumentException("selectionBackgroundColor is null.");
+ }
+
+ setSelectionBackgroundColor(GraphicsUtilities.decodeColor(selectionBackgroundColor));
+ }
+
+ public Color getInactiveSelectionColor() {
+ return inactiveSelectionColor;
+ }
+
+ public void setInactiveSelectionColor(Color inactiveSelectionColor) {
+ if (inactiveSelectionColor == null) {
+ throw new IllegalArgumentException("inactiveSelectionColor is null.");
+ }
+
+ this.inactiveSelectionColor = inactiveSelectionColor;
+ repaintComponent();
+ }
+
+ public final void setInactiveSelectionColor(String inactiveSelectionColor) {
+ if (inactiveSelectionColor == null) {
+ throw new IllegalArgumentException("inactiveSelectionColor is null.");
+ }
+
+ setInactiveSelectionColor(GraphicsUtilities.decodeColor(inactiveSelectionColor));
+ }
+
+ public Color getInactiveSelectionBackgroundColor() {
+ return inactiveSelectionBackgroundColor;
+ }
+
+ public void setInactiveSelectionBackgroundColor(Color inactiveSelectionBackgroundColor) {
+ if (inactiveSelectionBackgroundColor == null) {
+ throw new IllegalArgumentException("inactiveSelectionBackgroundColor is null.");
+ }
+
+ this.inactiveSelectionBackgroundColor = inactiveSelectionBackgroundColor;
+ repaintComponent();
+ }
+
+ public final void setInactiveSelectionBackgroundColor(String inactiveSelectionBackgroundColor) {
+ if (inactiveSelectionBackgroundColor == null) {
+ throw new IllegalArgumentException("inactiveSelectionBackgroundColor is null.");
+ }
+
+ setInactiveSelectionBackgroundColor(GraphicsUtilities.decodeColor(inactiveSelectionBackgroundColor));
+ }
+
+ public Insets getMargin() {
+ return margin;
+ }
+
+ public void setMargin(Insets margin) {
+ if (margin == null) {
+ throw new IllegalArgumentException("margin is null.");
+ }
+
+ this.margin = margin;
+ invalidateComponent();
+ }
+
+ public final void setMargin(Dictionary<String, ?> margin) {
+ if (margin == null) {
+ throw new IllegalArgumentException("margin is null.");
+ }
+
+ setMargin(new Insets(margin));
+ }
+
+ public final void setMargin(int margin) {
+ setMargin(new Insets(margin));
+ }
+
+ public final void setMargin(Number margin) {
+ if (margin == null) {
+ throw new IllegalArgumentException("margin is null.");
+ }
+
+ setMargin(margin.intValue());
+ }
+
+ public final void setMargin(String margin) {
+ if (margin == null) {
+ throw new IllegalArgumentException("margin is null.");
+ }
+
+ setMargin(Insets.decode(margin));
+ }
+
+ public boolean getWrapText() {
+ return wrapText;
+ }
+
+ public void setWrapText(boolean wrapText) {
+ this.wrapText = wrapText;
+ invalidateComponent();
+ }
+
@Override
public void maximumLengthChanged(TextArea2 textArea, int previousMaximumLength) {
// TODO
Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextAreaSkinTextNodeView.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextAreaSkinTextNodeView.java?rev=992139&r1=992138&r2=992139&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextAreaSkinTextNodeView.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextAreaSkinTextNodeView.java Thu Sep 2 22:37:17 2010
@@ -28,6 +28,7 @@ import java.awt.geom.Area;
import java.awt.geom.Rectangle2D;
import java.text.CharacterIterator;
+import org.apache.pivot.text.CharSequenceCharacterIterator;
import org.apache.pivot.wtk.Bounds;
import org.apache.pivot.wtk.FocusTraversalDirection;
import org.apache.pivot.wtk.Platform;
@@ -90,7 +91,7 @@ class TextAreaSkinTextNodeView extends T
FontRenderContext fontRenderContext = Platform.getFontRenderContext();
int breakWidth = getBreakWidth();
- CharacterIterator ci = textNode.getCharacterIterator(start, textNode.getCharacterCount());
+ CharSequenceCharacterIterator ci = new CharSequenceCharacterIterator(textNode.getCharacters(), start);
float lineWidth = 0;
int lastWhitespaceIndex = -1;
@@ -133,7 +134,7 @@ class TextAreaSkinTextNodeView extends T
}
glyphVector = getEffectiveFont().createGlyphVector(fontRenderContext,
- textNode.getCharacterIterator(start, end));
+ new CharSequenceCharacterIterator(textNode.getCharacters(), start, end));
if (end < ci.getEndIndex()) {
length = end - start;
Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/text/TextNode.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/text/TextNode.java?rev=992139&r1=992138&r2=992139&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/text/TextNode.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/text/TextNode.java Thu Sep 2 22:37:17 2010
@@ -16,9 +16,6 @@
*/
package org.apache.pivot.wtk.text;
-import java.text.CharacterIterator;
-
-import org.apache.pivot.text.CharSequenceCharacterIterator;
import org.apache.pivot.util.ListenerList;
/**
@@ -42,7 +39,7 @@ public final class TextNode extends Node
}
}
- private StringBuilder textBuilder = new StringBuilder();
+ private StringBuilder characters = new StringBuilder();
private TextNodeListenerList textNodeListeners = new TextNodeListenerList();
public TextNode() {
@@ -58,7 +55,7 @@ public final class TextNode extends Node
throw new IllegalArgumentException("text is null.");
}
- textBuilder = new StringBuilder(text);
+ characters = new StringBuilder(text);
}
public String getText() {
@@ -66,7 +63,7 @@ public final class TextNode extends Node
}
public String getText(int beginIndex, int endIndex) {
- return textBuilder.substring(beginIndex, endIndex);
+ return characters.substring(beginIndex, endIndex);
}
public void setText(String text) {
@@ -88,13 +85,13 @@ public final class TextNode extends Node
}
if (index < 0
- || index > textBuilder.length()) {
+ || index > characters.length()) {
throw new IndexOutOfBoundsException();
}
int characterCount = text.length();
if (characterCount > 0) {
- textBuilder.insert(index, text);
+ characters.insert(index, text);
rangeInserted(index, characterCount);
textNodeListeners.charactersInserted(this, index, characterCount);
}
@@ -102,12 +99,12 @@ public final class TextNode extends Node
public void removeText(int index, int count) {
if (index < 0
- || index + count > textBuilder.length()) {
+ || index + count > characters.length()) {
throw new IndexOutOfBoundsException();
}
if (count > 0) {
- textBuilder.delete(index, index + count);
+ characters.delete(index, index + count);
textNodeListeners.charactersRemoved(this, index, count);
rangeRemoved(index, count);
@@ -115,30 +112,26 @@ public final class TextNode extends Node
}
public String getSubstring(int start, int end) {
- return textBuilder.substring(start, end);
+ return characters.substring(start, end);
+ }
+
+ public CharSequence getCharacters() {
+ return characters;
}
@Override
public char getCharacterAt(int index) {
if (index < 0
- || index >= textBuilder.length()) {
+ || index >= characters.length()) {
throw new IndexOutOfBoundsException();
}
- return textBuilder.charAt(index);
+ return characters.charAt(index);
}
@Override
public int getCharacterCount() {
- return textBuilder.length();
- }
-
- public CharacterIterator getCharacterIterator() {
- return getCharacterIterator(0, getCharacterCount());
- }
-
- public CharacterIterator getCharacterIterator(int beginIndex, int endIndex) {
- return new CharSequenceCharacterIterator(textBuilder, beginIndex, endIndex);
+ return characters.length();
}
@Override
@@ -157,7 +150,7 @@ public final class TextNode extends Node
throw new IllegalArgumentException("characterCount is negative.");
}
- String removed = textBuilder.substring(offset, offset + characterCount);
+ String removed = characters.substring(offset, offset + characterCount);
removeText(offset, characterCount);
TextNode range = new TextNode(removed);
@@ -171,14 +164,14 @@ public final class TextNode extends Node
}
if (offset < 0
- || offset + characterCount > textBuilder.length()) {
+ || offset + characterCount > characters.length()) {
throw new IndexOutOfBoundsException();
}
int start = offset;
int end = offset + characterCount;
- String rangeText = textBuilder.substring(start, end);
+ String rangeText = characters.substring(start, end);
TextNode textNode = new TextNode(rangeText);
return textNode;