--- old/src/java.desktop/share/classes/java/awt/TextComponent.java 2015-10-14 19:00:23.225987043 +0530
+++ new/src/java.desktop/share/classes/java/awt/TextComponent.java 2015-10-14 19:00:22.993987043 +0530
@@ -81,6 +81,15 @@
boolean editable = true;
/**
+ * A boolean indicating whether EOL characters present in the input
+ * text should be replaced by a space character.
+ * This variable is set to true
for TextField
.
+ * If set to true
EOL will be replaced with space.
+ * If set to false
text remains unchanged.
+ */
+ boolean replaceEOL;
+
+ /**
* The selection refers to the selected text, and the
* selectionStart
is the start position
* of the selected text.
@@ -136,6 +145,45 @@
setCursor(Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR));
}
+ /**
+ * Constructs a new text component. Replaces EOL character from the input
+ * text with space character if the flag replaceEOL is true
+ * and also sets the value of the cursor to Cursor.TEXT_CURSOR
.
+ * @param text the text to be displayed; if
+ * text
is null
, the empty
+ * string ""
will be displayed
+ * @param replaceEOL boolean flag to decide whether to replace
+ * EOL or not.
+ * @exception HeadlessException if
+ * GraphicsEnvironment.isHeadless
+ * returns true
+ * @see java.awt.GraphicsEnvironment#isHeadless
+ * @see java.awt.Cursor
+ */
+ TextComponent(String text, boolean replaceEOL) throws HeadlessException {
+ GraphicsEnvironment.checkHeadless();
+ this.text = (text != null) ? text : "";
+ if (replaceEOL) {
+ this.replaceEOL = replaceEOL;
+ if (this.text != "") {
+ replaceEOL();
+ }
+ }
+ setCursor(Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR));
+ }
+
+ /**
+ * Replaces EOL characters from the text variable with a space character.
+ */
+ private void replaceEOL() {
+ String[] strEOLs = {System.getProperty("line.separator"), "\n"};
+ for (String eol : strEOLs) {
+ if (text.contains(eol)) {
+ text = text.replace(eol, " ");
+ }
+ }
+ }
+
private void enableInputMethodsIfNecessary() {
if (checkForEnableIM) {
checkForEnableIM = false;
@@ -232,6 +280,9 @@
boolean skipTextEvent = (text == null || text.isEmpty())
&& (t == null || t.isEmpty());
text = (t != null) ? t : "";
+ if (replaceEOL && text != "") {
+ replaceEOL();
+ }
TextComponentPeer peer = (TextComponentPeer)this.peer;
// Please note that we do not want to post an event
// if TextArea.setText() or TextField.setText() replaces an empty text