changeset 8218:cdfa2301a291

7150100: [macosx] "0123456789" is selected in the TextField Reviewed-by: anthony, art
author serb
date Tue, 01 Oct 2013 04:29:50 +0400
parents 603cd3cefbb0
children 2d8418d68a3c
files src/macosx/classes/sun/lwawt/LWTextComponentPeer.java src/solaris/classes/sun/awt/X11/XTextAreaPeer.java src/solaris/classes/sun/awt/X11/XTextFieldPeer.java test/java/awt/TextArea/SelectionVisible/SelectionVisible.html test/java/awt/TextArea/SelectionVisible/SelectionVisible.java test/java/awt/TextField/SelectionVisible/SelectionVisible.html test/java/awt/TextField/SelectionVisible/SelectionVisible.java
diffstat 7 files changed, 247 insertions(+), 50 deletions(-) [+]
line wrap: on
line diff
--- a/src/macosx/classes/sun/lwawt/LWTextComponentPeer.java	Mon Sep 30 22:08:45 2013 +0400
+++ b/src/macosx/classes/sun/lwawt/LWTextComponentPeer.java	Tue Oct 01 04:29:50 2013 +0400
@@ -71,13 +71,14 @@
         }
         setEditable(getTarget().isEditable());
         setText(getTarget().getText());
+        setCaretPosition(getTarget().getCaretPosition());
         getTarget().addInputMethodListener(this);
         final int start = getTarget().getSelectionStart();
         final int end = getTarget().getSelectionEnd();
         if (end > start) {
+            // Should be called after setText() and setCaretPosition()
             select(start, end);
         }
-        setCaretPosition(getTarget().getCaretPosition());
         firstChangeSkipped = true;
     }
 
--- a/src/solaris/classes/sun/awt/X11/XTextAreaPeer.java	Mon Sep 30 22:08:45 2013 +0400
+++ b/src/solaris/classes/sun/awt/X11/XTextAreaPeer.java	Tue Oct 01 04:29:50 2013 +0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -64,16 +64,14 @@
 import sun.awt.SunToolkit;
 
 
-class XTextAreaPeer extends XComponentPeer implements TextAreaPeer {
-    boolean editable;
+final class XTextAreaPeer extends XComponentPeer implements TextAreaPeer {
 
-    AWTTextPane textPane;
-    AWTTextArea jtext;
+    private final AWTTextPane textPane;
+    private final AWTTextArea jtext;
+    private final boolean firstChangeSkipped;
 
-    boolean firstChangeSkipped;
-
-    private final JavaMouseEventHandler javaMouseEventHandler
-        = new JavaMouseEventHandler( this );
+    private final JavaMouseEventHandler javaMouseEventHandler =
+            new JavaMouseEventHandler(this);
 
     /* FIXME  */
 
@@ -98,7 +96,7 @@
      * Create a Text area.
      */
     XTextAreaPeer(TextArea target) {
-        super( target  );
+        super(target);
 
         // some initializations require that target be set even
         // though init(target) has not been called
@@ -106,8 +104,7 @@
 
         //ComponentAccessor.enableEvents(target,AWTEvent.MOUSE_WHEEL_EVENT_MASK);
 
-        firstChangeSkipped = false;
-        String text = ((TextArea)target).getText();
+        String text = target.getText();
         jtext = new AWTTextArea(text, this);
         jtext.setWrapStyleWord(true);
         jtext.getDocument().addDocumentListener(jtext);
@@ -143,25 +140,22 @@
 
         setFont(font);
 
+        // set the text of this object to the text of its target
+        setTextImpl(target.getText());  //?? should this be setText
+
         int start = target.getSelectionStart();
         int end = target.getSelectionEnd();
-
-        if (end > start) {
-            select(start, end);
-        }
         // Fix for 5100200
         // Restoring Motif behaviour
         // Since the end position of the selected text can be greater then the length of the text,
         // so we should set caret to max position of the text
-        int caretPosition = Math.min(end, text.length());
-        setCaretPosition(caretPosition);
-
+        setCaretPosition(Math.min(end, text.length()));
+        if (end > start) {
+            // Should be called after setText() and setCaretPosition()
+            select(start, end);
+        }
         setEditable(target.isEditable());
-
         setScrollBarVisibility();
-        // set the text of this object to the text of its target
-        setTextImpl(target.getText());  //?? should this be setText
-
         // After this line we should not change the component's text
         firstChangeSkipped = true;
     }
@@ -408,7 +402,6 @@
      * @see java.awt.peer.TextComponentPeer
      */
     public void setEditable(boolean editable) {
-        this.editable = editable;
         if (jtext != null) jtext.setEditable(editable);
         repaintText();
     }
@@ -461,7 +454,7 @@
         repaintText();
     }
 
-    protected boolean setTextImpl(String txt) {
+    private void setTextImpl(String txt) {
         if (jtext != null) {
             // JTextArea.setText() posts two different events (remove & insert).
             // Since we make no differences between text events,
@@ -474,7 +467,6 @@
             }
             jtext.getDocument().addDocumentListener(jtext);
         }
-        return true;
     }
 
     /**
--- a/src/solaris/classes/sun/awt/X11/XTextFieldPeer.java	Mon Sep 30 22:08:45 2013 +0400
+++ b/src/solaris/classes/sun/awt/X11/XTextFieldPeer.java	Tue Oct 01 04:29:50 2013 +0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2007, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -57,46 +57,41 @@
 import sun.awt.CausedFocusEvent;
 import sun.awt.AWTAccessor;
 
-public class XTextFieldPeer extends XComponentPeer implements TextFieldPeer {
+final class XTextFieldPeer extends XComponentPeer implements TextFieldPeer {
     private static final PlatformLogger log = PlatformLogger.getLogger("sun.awt.X11.XTextField");
 
-    String text;
-    XAWTTextField xtext;
+    private String text;
+    private final XAWTTextField xtext;
+    private final boolean firstChangeSkipped;
 
-    boolean firstChangeSkipped;
-
-    public XTextFieldPeer(TextField target) {
+    XTextFieldPeer(TextField target) {
         super(target);
-        int start, end;
-        firstChangeSkipped = false;
         text = target.getText();
         xtext = new XAWTTextField(text,this, target.getParent());
         xtext.getDocument().addDocumentListener(xtext);
         xtext.setCursor(target.getCursor());
         XToolkit.specialPeerMap.put(xtext,this);
 
-        TextField txt = (TextField) target;
         initTextField();
-        setText(txt.getText());
-        if (txt.echoCharIsSet()) {
-            setEchoChar(txt.getEchoChar());
+        setText(target.getText());
+        if (target.echoCharIsSet()) {
+            setEchoChar(target.getEchoChar());
         }
         else setEchoChar((char)0);
 
-        start = txt.getSelectionStart();
-        end = txt.getSelectionEnd();
-
-        if (end > start) {
-            select(start, end);
-        }
+        int start = target.getSelectionStart();
+        int end = target.getSelectionEnd();
         // Fix for 5100200
         // Restoring Motif behaviour
         // Since the end position of the selected text can be greater then the length of the text,
         // so we should set caret to max position of the text
-        int caretPosition = Math.min(end, text.length());
-        setCaretPosition(caretPosition);
+        setCaretPosition(Math.min(end, text.length()));
+        if (end > start) {
+            // Should be called after setText() and setCaretPosition()
+            select(start, end);
+        }
 
-        setEditable(txt.isEditable());
+        setEditable(target.isEditable());
 
         // After this line we should not change the component's text
         firstChangeSkipped = true;
@@ -219,7 +214,7 @@
         repaint();
     }
 
-    protected boolean setXAWTTextField(String txt) {
+    private boolean setXAWTTextField(String txt) {
         text = txt;
         if (xtext != null)  {
             // JTextField.setText() posts two different events (remove & insert).
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/java/awt/TextArea/SelectionVisible/SelectionVisible.html	Tue Oct 01 04:29:50 2013 +0400
@@ -0,0 +1,42 @@
+<html>
+<!--
+ Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
+ DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+
+ This code is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License version 2 only, as
+ published by the Free Software Foundation.
+
+ This code is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ version 2 for more details (a copy is included in the LICENSE file that
+ accompanied this code).
+
+ You should have received a copy of the GNU General Public License version
+ 2 along with this work; if not, write to the Free Software Foundation,
+ Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+
+ Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ or visit www.oracle.com if you need additional information or have any
+ questions.
+-->
+
+<!--  
+  @test
+  @bug 4082144 7150100
+  @summary  Ensures that TextArea.select() works when called 
+            before setVisible() 
+  @author Eric.Hawkes: area=TextComponent
+  @run applet/manual=yesno SelectionVisible.html
+  -->
+<head>
+<title> SelectionVisible </title>
+</head>
+<body>
+
+<h1> SelectionVisible<br> Bugid: 4082144 </h1>
+
+<APPLET CODE="SelectionVisible.class" WIDTH=400 HEIGHT=160></APPLET>
+</body>
+</html>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/java/awt/TextArea/SelectionVisible/SelectionVisible.java	Tue Oct 01 04:29:50 2013 +0400
@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+
+import java.applet.Applet;
+import java.awt.BorderLayout;
+import java.awt.Dimension;
+import java.awt.FlowLayout;
+import java.awt.Panel;
+import java.awt.TextArea;
+
+public final class SelectionVisible extends Applet {
+
+    TextArea tf;
+
+    @Override
+    public void init() {
+        tf = new TextArea(3, 20);
+        tf.setText("0123456789");
+        tf.select(0, 6);
+
+        final TextArea ta = new TextArea("INSTRUCTIONS:\n"
+                                                 + "The text 012345 should be selected in the TextArea.\n"
+                                                 + "If this is what you observe, then the test passes.\n"
+                                                 + "Otherwise, the test fails.", 40, 5,
+                                         TextArea.SCROLLBARS_NONE);
+        ta.setEditable(false);
+        ta.setPreferredSize(new Dimension(300, 70));
+        final Panel panel = new Panel();
+        panel.setLayout(new FlowLayout());
+        panel.add(tf);
+        setLayout(new BorderLayout());
+        add(ta, BorderLayout.CENTER);
+        add(panel, BorderLayout.PAGE_END);
+    }
+
+    @Override
+    public void start() {
+        setVisible(true);
+        tf.requestFocus();
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/java/awt/TextField/SelectionVisible/SelectionVisible.html	Tue Oct 01 04:29:50 2013 +0400
@@ -0,0 +1,42 @@
+<html>
+<!--
+ Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
+ DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+
+ This code is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License version 2 only, as
+ published by the Free Software Foundation.
+
+ This code is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ version 2 for more details (a copy is included in the LICENSE file that
+ accompanied this code).
+
+ You should have received a copy of the GNU General Public License version
+ 2 along with this work; if not, write to the Free Software Foundation,
+ Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+
+ Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ or visit www.oracle.com if you need additional information or have any
+ questions.
+-->
+
+<!--  
+  @test
+  @bug 4082144 7150100
+  @summary  Ensures that TextField.select() works when called 
+            before setVisible() 
+  @author Eric.Hawkes: area=TextComponent
+  @run applet/manual=yesno SelectionVisible.html
+  -->
+<head>
+<title> SelectionVisible </title>
+</head>
+<body>
+
+<h1> SelectionVisible<br> Bugid: 4082144 </h1>
+
+<APPLET CODE="SelectionVisible.class" WIDTH=400 HEIGHT=160></APPLET>
+</body>
+</html>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/java/awt/TextField/SelectionVisible/SelectionVisible.java	Tue Oct 01 04:29:50 2013 +0400
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+
+import java.applet.Applet;
+import java.awt.BorderLayout;
+import java.awt.Dimension;
+import java.awt.FlowLayout;
+import java.awt.Panel;
+import java.awt.TextArea;
+import java.awt.TextField;
+
+public final class SelectionVisible extends Applet {
+
+    TextField tf;
+
+    @Override
+    public void init() {
+        tf = new TextField(20);
+        tf.setText("0123456789");
+        tf.select(0, 6);
+
+        final TextArea ta = new TextArea("INSTRUCTIONS:\n"
+                                         + "The text 012345 should be selected in the TextField.\n"
+                                         + "If this is what you observe, then the test passes.\n"
+                                         + "Otherwise, the test fails.", 40, 5,
+                                         TextArea.SCROLLBARS_NONE);
+        ta.setEditable(false);
+        ta.setPreferredSize(new Dimension(300, 70));
+        final Panel panel = new Panel();
+        panel.setLayout(new FlowLayout());
+        panel.add(tf);
+        setLayout(new BorderLayout());
+        add(ta, BorderLayout.CENTER);
+        add(panel, BorderLayout.PAGE_END);
+    }
+
+    @Override
+    public void start() {
+        setVisible(true);
+        tf.requestFocus();
+    }
+}