提交 3cb008ff 编写于 作者: S serb

7150100: [macosx] "0123456789" is selected in the TextField

Reviewed-by: anthony, art
上级 d33e790f
......@@ -71,13 +71,14 @@ abstract class LWTextComponentPeer<T extends TextComponent, D extends JComponent
}
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;
}
......
/*
* 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.AWTAccessor;
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 @@ class XTextAreaPeer extends XComponentPeer implements TextAreaPeer {
* 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 @@ class XTextAreaPeer extends XComponentPeer implements TextAreaPeer {
//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 @@ class XTextAreaPeer extends XComponentPeer implements TextAreaPeer {
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 @@ class XTextAreaPeer extends XComponentPeer implements TextAreaPeer {
* @see java.awt.peer.TextComponentPeer
*/
public void setEditable(boolean editable) {
this.editable = editable;
if (jtext != null) jtext.setEditable(editable);
repaintText();
}
......@@ -461,7 +454,7 @@ class XTextAreaPeer extends XComponentPeer implements TextAreaPeer {
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 @@ class XTextAreaPeer extends XComponentPeer implements TextAreaPeer {
}
jtext.getDocument().addDocumentListener(jtext);
}
return true;
}
/**
......
/*
* 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.util.logging.PlatformLogger;
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 @@ public class XTextFieldPeer extends XComponentPeer implements TextFieldPeer {
repaint();
}
protected boolean setXAWTTextField(String txt) {
private boolean setXAWTTextField(String txt) {
text = txt;
if (xtext != null) {
// JTextField.setText() posts two different events (remove & insert).
......
<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>
/*
* 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();
}
}
<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>
/*
* 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();
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册