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;
private final FocusListener focusListener = new FocusAdapter() {
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);
}
}
@ -242,6 +242,8 @@ public class DarkTextFieldUI extends DarkTextFieldUIBridge implements PropertyCh
@Override
protected void installDefaults() {
super.installDefaults();
editor.putClientProperty(KEY_KEEP_SELECTION_ON_FOCUS_LOST,
UIManager.getBoolean("TextField.keepSelectionOnFocusLost"));
arcSize = UIManager.getInt("TextField.arc");
borderSize = UIManager.getInt("TextField.borderThickness");
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
protected void installDefaults() {
super.installDefaults();
editor.putClientProperty(KEY_ROUNDED_SELECTION,
UIManager.getBoolean("TextComponent.roundedSelection"));
editor.putClientProperty(KEY_ROUNDED_SELECTION, UIManager.getBoolean("TextComponent.roundedSelection"));
disabledColor = UIManager.getColor(getPropertyPrefix() + ".disabledBackground");
inactiveColor = UIManager.getColor(getPropertyPrefix() + ".inactiveBackground");
}
@ -237,9 +236,7 @@ public abstract class DarkTextUI extends BasicTextUI implements PropertyChangeLi
protected InputMap getInputMap() {
InputMap map = new InputMapUIResource();
InputMap shared =
(InputMap) DefaultLookup.get(editor, this,
getPropertyPrefix() + ".focusInputMap");
InputMap shared = (InputMap) DefaultLookup.get(editor, this, getPropertyPrefix() + ".focusInputMap");
if (shared != null) {
map.setParent(shared);
}
@ -270,8 +267,7 @@ public abstract class DarkTextUI extends BasicTextUI implements PropertyChangeLi
if (getEditorKit(editor) instanceof DefaultEditorKit) {
if (map != null) {
Object obj = map.get(DefaultEditorKit.insertBreakAction);
if (obj != null
&& obj instanceof DefaultEditorKit.InsertBreakAction) {
if (obj instanceof DefaultEditorKit.InsertBreakAction) {
Action action = new TextActionWrapper((TextAction) obj);
componentMap.put(action.getValue(Action.NAME), action);
}
@ -307,8 +303,7 @@ public abstract class DarkTextUI extends BasicTextUI implements PropertyChangeLi
km.clear();
if (accelerator != '\0') {
km.put(KeyStroke.getKeyStroke(accelerator, getFocusAcceleratorKeyMask()), "requestFocus");
km.put(KeyStroke.getKeyStroke(accelerator,
DarkSwingUtil.setAltGraphMask(getFocusAcceleratorKeyMask())),
km.put(KeyStroke.getKeyStroke(accelerator, DarkSwingUtil.setAltGraphMask(getFocusAcceleratorKeyMask())),
"requestFocus");
}
}
@ -326,12 +321,9 @@ public abstract class DarkTextUI extends BasicTextUI implements PropertyChangeLi
for (Action a : actions) {
map.put(a.getValue(Action.NAME), a);
}
map.put(TransferHandler.getCutAction().getValue(Action.NAME),
TransferHandler.getCutAction());
map.put(TransferHandler.getCopyAction().getValue(Action.NAME),
TransferHandler.getCopyAction());
map.put(TransferHandler.getPasteAction().getValue(Action.NAME),
TransferHandler.getPasteAction());
map.put(TransferHandler.getCutAction().getValue(Action.NAME), TransferHandler.getCutAction());
map.put(TransferHandler.getCopyAction().getValue(Action.NAME), TransferHandler.getCopyAction());
map.put(TransferHandler.getPasteAction().getValue(Action.NAME), TransferHandler.getPasteAction());
return map;
}
@ -357,14 +349,10 @@ public abstract class DarkTextUI extends BasicTextUI implements PropertyChangeLi
*/
EditorKit editorKit = getEditorKit(editor);
if (editorKit instanceof DefaultEditorKit) {
Set<AWTKeyStroke> storedForwardTraversalKeys =
editor.getFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS);
Set<AWTKeyStroke> storedBackwardTraversalKeys =
editor.getFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS);
Set<AWTKeyStroke> forwardTraversalKeys =
new HashSet<>(storedForwardTraversalKeys);
Set<AWTKeyStroke> backwardTraversalKeys =
new HashSet<>(storedBackwardTraversalKeys);
Set<AWTKeyStroke> storedForwardTraversalKeys = editor.getFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS);
Set<AWTKeyStroke> storedBackwardTraversalKeys = editor.getFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS);
Set<AWTKeyStroke> forwardTraversalKeys = new HashSet<>(storedForwardTraversalKeys);
Set<AWTKeyStroke> backwardTraversalKeys = new HashSet<>(storedBackwardTraversalKeys);
if (editor.isEditable()) {
forwardTraversalKeys.remove(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0));
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.selectionBackground = %textSelectionBackground
TextField.selectionForeground = %textSelectionForeground
TextField.keepSelectionOnFocusLost = true
TextField.arc = %arc
TextField.focusArc = %arcFocus

Loading…
Cancel
Save