You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pivot.apache.org by rw...@apache.org on 2020/12/30 21:44:39 UTC
svn commit: r1884960 - in /pivot/trunk/wtk/src/org/apache/pivot/wtk:
TextArea.java TextInput.java TextPane.java
Author: rwhitcomb
Date: Wed Dec 30 21:44:39 2020
New Revision: 1884960
URL: http://svn.apache.org/viewvc?rev=1884960&view=rev
Log:
Added convenience methods for setting text in TextInput, TextArea, and TextPane.
Modified:
pivot/trunk/wtk/src/org/apache/pivot/wtk/TextArea.java
pivot/trunk/wtk/src/org/apache/pivot/wtk/TextInput.java
pivot/trunk/wtk/src/org/apache/pivot/wtk/TextPane.java
Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/TextArea.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/TextArea.java?rev=1884960&r1=1884959&r2=1884960&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/TextArea.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/TextArea.java Wed Dec 30 21:44:39 2020
@@ -17,12 +17,16 @@
package org.apache.pivot.wtk;
import java.awt.Toolkit;
+import java.io.BufferedReader;
+import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.StringReader;
import java.net.URL;
+import java.nio.charset.Charset;
+import java.nio.file.Files;
import java.util.Iterator;
import org.apache.pivot.annotations.UnsupportedOperation;
@@ -493,7 +497,10 @@ public class TextArea extends Component
private boolean expandTabs = false;
- private int maximumLength = 1048575;
+ /** Default maximum length (~1MB) or 2^20 - 1. */
+ private static final int DEFAULT_MAX_LENGTH = 1048575;
+
+ private int maximumLength = DEFAULT_MAX_LENGTH;
private boolean editable = true;
private String textKey = null;
@@ -622,6 +629,18 @@ public class TextArea extends Component
}
}
+ public void setText(File f) throws IOException {
+ try (BufferedReader reader = Files.newBufferedReader(f.toPath())) {
+ setText(reader);
+ }
+ }
+
+ public void setText(File f, Charset cs) throws IOException {
+ try (BufferedReader reader = Files.newBufferedReader(f.toPath(), cs)) {
+ setText(reader);
+ }
+ }
+
public void setText(Reader textReader) throws IOException {
Utils.checkNull(textReader, "Text reader");
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=1884960&r1=1884959&r2=1884960&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/TextInput.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/TextInput.java Wed Dec 30 21:44:39 2020
@@ -74,10 +74,16 @@ public class TextInput extends Component
public Object valueOf(String text);
}
+ /**
+ * Interface for a text operation that can be undone.
+ */
private interface Edit {
public void undo();
}
+ /**
+ * Description of an "insert text" editing operation.
+ */
private class InsertTextEdit implements Edit {
private final int index;
private final int count;
@@ -93,6 +99,9 @@ public class TextInput extends Component
}
}
+ /**
+ * Description of a "remove text" editing operation.
+ */
private class RemoveTextEdit implements Edit {
private final int index;
private final String text;
@@ -172,6 +181,10 @@ public class TextInput extends Component
}
public void setText(final String text) {
+ setText(text);
+ }
+
+ public void setText(final CharSequence text) {
Utils.checkNull(text, "text");
if (text.length() > maximumLength) {
@@ -188,7 +201,7 @@ public class TextInput extends Component
// Update the valid flag
boolean previousTextValid = textValid;
- textValid = (validator == null) ? true : validator.isValid(text);
+ textValid = (validator == null) ? true : validator.isValid(text.toString());
// Clear the edit history
editHistory.clear();
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=1884960&r1=1884959&r2=1884960&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/TextPane.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/TextPane.java Wed Dec 30 21:44:39 2020
@@ -16,12 +16,16 @@
*/
package org.apache.pivot.wtk;
+import java.io.BufferedReader;
+import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.StringReader;
import java.net.URL;
+import java.nio.charset.Charset;
+import java.nio.file.Files;
import org.apache.pivot.beans.DefaultProperty;
import org.apache.pivot.collections.LinkedStack;
@@ -876,6 +880,18 @@ public class TextPane extends Container
}
}
+ public void setText(File f) throws IOException {
+ try (BufferedReader reader = Files.newBufferedReader(f.toPath())) {
+ setText(reader);
+ }
+ }
+
+ public void setText(File f, Charset cs) throws IOException {
+ try (BufferedReader reader = Files.newBufferedReader(f.toPath(), cs)) {
+ setText(reader);
+ }
+ }
+
public void setText(Reader textReader) throws IOException {
Utils.checkNull(textReader, "Reader");