提交 55df51a2 编写于 作者: A alexp

7147078: [macosx] Echo char set in TextField doesn't prevent word jumping

Reviewed-by: art
上级 f8674c83
...@@ -142,6 +142,21 @@ public class AquaKeyBindings { ...@@ -142,6 +142,21 @@ public class AquaKeyBindings {
})); }));
} }
LateBoundInputMap getPasswordFieldInputMap() {
return new LateBoundInputMap(new SimpleBinding(getTextFieldInputMap().getBindings()),
// nullify all the bindings that may discover space characters in the text
new SimpleBinding(new String[] {
"alt LEFT", null,
"alt KP_LEFT", null,
"alt RIGHT", null,
"alt KP_RIGHT", null,
"shift alt LEFT", null,
"shift alt KP_LEFT", null,
"shift alt RIGHT", null,
"shift alt KP_RIGHT", null,
}));
}
LateBoundInputMap getMultiLineTextInputMap() { LateBoundInputMap getMultiLineTextInputMap() {
return new LateBoundInputMap(new SimpleBinding(commonTextEditorBindings), new SimpleBinding(new String[] { return new LateBoundInputMap(new SimpleBinding(commonTextEditorBindings), new SimpleBinding(new String[] {
"ENTER", DefaultEditorKit.insertBreakAction, "ENTER", DefaultEditorKit.insertBreakAction,
......
...@@ -697,7 +697,7 @@ public class AquaLookAndFeel extends BasicLookAndFeel { ...@@ -697,7 +697,7 @@ public class AquaLookAndFeel extends BasicLookAndFeel {
"Panel.foreground", black, "Panel.foreground", black,
"Panel.opaque", useOpaqueComponents, "Panel.opaque", useOpaqueComponents,
"PasswordField.focusInputMap", aquaKeyBindings.getTextFieldInputMap(), "PasswordField.focusInputMap", aquaKeyBindings.getPasswordFieldInputMap(),
"PasswordField.font", controlFont, "PasswordField.font", controlFont,
"PasswordField.background", textBackground, "PasswordField.background", textBackground,
"PasswordField.foreground", textForeground, "PasswordField.foreground", textForeground,
......
...@@ -34,7 +34,7 @@ import java.awt.event.ActionListener; ...@@ -34,7 +34,7 @@ import java.awt.event.ActionListener;
import java.awt.event.FocusEvent; import java.awt.event.FocusEvent;
import java.awt.peer.TextFieldPeer; import java.awt.peer.TextFieldPeer;
import javax.swing.JPasswordField; import javax.swing.*;
import javax.swing.text.JTextComponent; import javax.swing.text.JTextComponent;
final class LWTextFieldPeer final class LWTextFieldPeer
...@@ -48,7 +48,7 @@ final class LWTextFieldPeer ...@@ -48,7 +48,7 @@ final class LWTextFieldPeer
@Override @Override
protected JPasswordField createDelegate() { protected JPasswordField createDelegate() {
return new JTextAreaDelegate(); return new JPasswordFieldDelegate();
} }
@Override @Override
...@@ -69,9 +69,18 @@ final class LWTextFieldPeer ...@@ -69,9 +69,18 @@ final class LWTextFieldPeer
public void setEchoChar(final char echoChar) { public void setEchoChar(final char echoChar) {
synchronized (getDelegateLock()) { synchronized (getDelegateLock()) {
getDelegate().setEchoChar(echoChar); getDelegate().setEchoChar(echoChar);
getDelegate().putClientProperty("JPasswordField.cutCopyAllowed", final boolean cutCopyAllowed;
getDelegate().echoCharIsSet() final String focusInputMapKey;
? Boolean.FALSE : Boolean.TRUE); if (echoChar != 0) {
cutCopyAllowed = false;
focusInputMapKey = "PasswordField.focusInputMap";
} else {
cutCopyAllowed = true;
focusInputMapKey = "TextField.focusInputMap";
}
getDelegate().putClientProperty("JPasswordField.cutCopyAllowed", cutCopyAllowed);
InputMap inputMap = (InputMap) UIManager.get(focusInputMapKey);
SwingUtilities.replaceUIInputMap(getDelegate(), JComponent.WHEN_FOCUSED, inputMap);
} }
} }
...@@ -106,11 +115,11 @@ final class LWTextFieldPeer ...@@ -106,11 +115,11 @@ final class LWTextFieldPeer
super.handleJavaFocusEvent(e); super.handleJavaFocusEvent(e);
} }
private final class JTextAreaDelegate extends JPasswordField { private final class JPasswordFieldDelegate extends JPasswordField {
// Empty non private constructor was added because access to this // Empty non private constructor was added because access to this
// class shouldn't be emulated by a synthetic accessor method. // class shouldn't be emulated by a synthetic accessor method.
JTextAreaDelegate() { JPasswordFieldDelegate() {
super(); super();
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册