Browse Source

Made JTextField.keepSelectionOnFocusLost true by default.

pull/97/head
weisj 5 years ago
parent
commit
4de2b16e17
  1. 4
      core/src/main/java/com/github/weisj/darklaf/ui/text/DarkTextFieldUI.java
  2. 34
      core/src/main/java/com/github/weisj/darklaf/ui/text/DarkTextUI.java
  3. 1
      core/src/main/resources/com/github/weisj/darklaf/properties/ui/text.properties

4
core/src/main/java/com/github/weisj/darklaf/ui/text/DarkTextFieldUI.java

@ -56,7 +56,7 @@ public class DarkTextFieldUI extends DarkTextFieldUIBridge implements PropertyCh
protected static Icon searchWithHistory; protected static Icon searchWithHistory;
private final FocusListener focusListener = new FocusAdapter() { private final FocusListener focusListener = new FocusAdapter() {
public void focusLost(final FocusEvent e) { public void focusLost(final FocusEvent e) {
if (!Boolean.TRUE.equals(getComponent().getClientProperty(KEY_KEEP_SELECTION_ON_FOCUS_LOST))) { if (Boolean.FALSE.equals(getComponent().getClientProperty(KEY_KEEP_SELECTION_ON_FOCUS_LOST))) {
getComponent().select(0, 0); getComponent().select(0, 0);
} }
} }
@ -242,6 +242,8 @@ public class DarkTextFieldUI extends DarkTextFieldUIBridge implements PropertyCh
@Override @Override
protected void installDefaults() { protected void installDefaults() {
super.installDefaults(); super.installDefaults();
editor.putClientProperty(KEY_KEEP_SELECTION_ON_FOCUS_LOST,
UIManager.getBoolean("TextField.keepSelectionOnFocusLost"));
arcSize = UIManager.getInt("TextField.arc"); arcSize = UIManager.getInt("TextField.arc");
borderSize = UIManager.getInt("TextField.borderThickness"); borderSize = UIManager.getInt("TextField.borderThickness");
searchArcSize = UIManager.getInt("TextField.searchArc"); searchArcSize = UIManager.getInt("TextField.searchArc");

34
core/src/main/java/com/github/weisj/darklaf/ui/text/DarkTextUI.java

@ -83,8 +83,7 @@ public abstract class DarkTextUI extends BasicTextUI implements PropertyChangeLi
@Override @Override
protected void installDefaults() { protected void installDefaults() {
super.installDefaults(); super.installDefaults();
editor.putClientProperty(KEY_ROUNDED_SELECTION, editor.putClientProperty(KEY_ROUNDED_SELECTION, UIManager.getBoolean("TextComponent.roundedSelection"));
UIManager.getBoolean("TextComponent.roundedSelection"));
disabledColor = UIManager.getColor(getPropertyPrefix() + ".disabledBackground"); disabledColor = UIManager.getColor(getPropertyPrefix() + ".disabledBackground");
inactiveColor = UIManager.getColor(getPropertyPrefix() + ".inactiveBackground"); inactiveColor = UIManager.getColor(getPropertyPrefix() + ".inactiveBackground");
} }
@ -237,9 +236,7 @@ public abstract class DarkTextUI extends BasicTextUI implements PropertyChangeLi
protected InputMap getInputMap() { protected InputMap getInputMap() {
InputMap map = new InputMapUIResource(); InputMap map = new InputMapUIResource();
InputMap shared = InputMap shared = (InputMap) DefaultLookup.get(editor, this, getPropertyPrefix() + ".focusInputMap");
(InputMap) DefaultLookup.get(editor, this,
getPropertyPrefix() + ".focusInputMap");
if (shared != null) { if (shared != null) {
map.setParent(shared); map.setParent(shared);
} }
@ -270,8 +267,7 @@ public abstract class DarkTextUI extends BasicTextUI implements PropertyChangeLi
if (getEditorKit(editor) instanceof DefaultEditorKit) { if (getEditorKit(editor) instanceof DefaultEditorKit) {
if (map != null) { if (map != null) {
Object obj = map.get(DefaultEditorKit.insertBreakAction); Object obj = map.get(DefaultEditorKit.insertBreakAction);
if (obj != null if (obj instanceof DefaultEditorKit.InsertBreakAction) {
&& obj instanceof DefaultEditorKit.InsertBreakAction) {
Action action = new TextActionWrapper((TextAction) obj); Action action = new TextActionWrapper((TextAction) obj);
componentMap.put(action.getValue(Action.NAME), action); componentMap.put(action.getValue(Action.NAME), action);
} }
@ -307,8 +303,7 @@ public abstract class DarkTextUI extends BasicTextUI implements PropertyChangeLi
km.clear(); km.clear();
if (accelerator != '\0') { if (accelerator != '\0') {
km.put(KeyStroke.getKeyStroke(accelerator, getFocusAcceleratorKeyMask()), "requestFocus"); km.put(KeyStroke.getKeyStroke(accelerator, getFocusAcceleratorKeyMask()), "requestFocus");
km.put(KeyStroke.getKeyStroke(accelerator, km.put(KeyStroke.getKeyStroke(accelerator, DarkSwingUtil.setAltGraphMask(getFocusAcceleratorKeyMask())),
DarkSwingUtil.setAltGraphMask(getFocusAcceleratorKeyMask())),
"requestFocus"); "requestFocus");
} }
} }
@ -326,12 +321,9 @@ public abstract class DarkTextUI extends BasicTextUI implements PropertyChangeLi
for (Action a : actions) { for (Action a : actions) {
map.put(a.getValue(Action.NAME), a); map.put(a.getValue(Action.NAME), a);
} }
map.put(TransferHandler.getCutAction().getValue(Action.NAME), map.put(TransferHandler.getCutAction().getValue(Action.NAME), TransferHandler.getCutAction());
TransferHandler.getCutAction()); map.put(TransferHandler.getCopyAction().getValue(Action.NAME), TransferHandler.getCopyAction());
map.put(TransferHandler.getCopyAction().getValue(Action.NAME), map.put(TransferHandler.getPasteAction().getValue(Action.NAME), TransferHandler.getPasteAction());
TransferHandler.getCopyAction());
map.put(TransferHandler.getPasteAction().getValue(Action.NAME),
TransferHandler.getPasteAction());
return map; return map;
} }
@ -357,14 +349,10 @@ public abstract class DarkTextUI extends BasicTextUI implements PropertyChangeLi
*/ */
EditorKit editorKit = getEditorKit(editor); EditorKit editorKit = getEditorKit(editor);
if (editorKit instanceof DefaultEditorKit) { if (editorKit instanceof DefaultEditorKit) {
Set<AWTKeyStroke> storedForwardTraversalKeys = Set<AWTKeyStroke> storedForwardTraversalKeys = editor.getFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS);
editor.getFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS); Set<AWTKeyStroke> storedBackwardTraversalKeys = editor.getFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS);
Set<AWTKeyStroke> storedBackwardTraversalKeys = Set<AWTKeyStroke> forwardTraversalKeys = new HashSet<>(storedForwardTraversalKeys);
editor.getFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS); Set<AWTKeyStroke> backwardTraversalKeys = new HashSet<>(storedBackwardTraversalKeys);
Set<AWTKeyStroke> forwardTraversalKeys =
new HashSet<>(storedForwardTraversalKeys);
Set<AWTKeyStroke> backwardTraversalKeys =
new HashSet<>(storedBackwardTraversalKeys);
if (editor.isEditable()) { if (editor.isEditable()) {
forwardTraversalKeys.remove(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0)); forwardTraversalKeys.remove(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0));
backwardTraversalKeys.remove(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, InputEvent.SHIFT_MASK)); backwardTraversalKeys.remove(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, InputEvent.SHIFT_MASK));

1
core/src/main/resources/com/github/weisj/darklaf/properties/ui/text.properties

@ -40,6 +40,7 @@ TextField.inactiveBackground = %textBackgroundInactive
TextField.background = %textBackground TextField.background = %textBackground
TextField.selectionBackground = %textSelectionBackground TextField.selectionBackground = %textSelectionBackground
TextField.selectionForeground = %textSelectionForeground TextField.selectionForeground = %textSelectionForeground
TextField.keepSelectionOnFocusLost = true
TextField.arc = %arc TextField.arc = %arc
TextField.focusArc = %arcFocus TextField.focusArc = %arcFocus

Loading…
Cancel
Save