2
0

Java Client: Switch to keybinding for login display

This commit is contained in:
Michael Ziminsky (Z) 2018-12-25 12:01:40 -07:00
parent ee02a54257
commit 08df7a6c0c

View File

@ -508,7 +508,7 @@ public class UserContentPanel extends JPanel implements MasterPassword.Listener,
}
private final class AuthenticatedUserPanel extends JPanel implements KeyListener, MPUser.Listener, KeyEventDispatcher {
private final class AuthenticatedUserPanel extends JPanel implements KeyListener, MPUser.Listener {
private final JButton userButton = Components.button( Res.icons().user(), event -> showUserPreferences(),
"Show user preferences." );
@ -528,6 +528,7 @@ public class UserContentPanel extends JPanel implements MasterPassword.Listener,
private static final String USE_SITE_ACTION = "useSite";
private static final String CLEAR_SITE_ACTION = "clearSite";
private static final String DELETE_SITE_ACTION = "deleteSite";
private static final String SHOW_LOGIN_ACTION = "showLogin";
@Nonnull
private final MPUser<?> user;
@ -595,17 +596,6 @@ public class UserContentPanel extends JPanel implements MasterPassword.Listener,
sitesModel = new CollectionListModel<MPQuery.Result<? extends MPSite<?>>>().selection( this::showSiteItem ),
this::getSiteDescription ) ) );
final InputMap panelInputMap = getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
panelInputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), USE_SITE_ACTION);
panelInputMap.put(copyLoginKeyStroke, USE_SITE_ACTION);
getActionMap().put(USE_SITE_ACTION, new SimpleAction(this::useSite));
panelInputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), CLEAR_SITE_ACTION);
getActionMap().put(CLEAR_SITE_ACTION, new SimpleAction(e -> queryField.setText("")));
sitesList.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0), DELETE_SITE_ACTION);
sitesList.getActionMap().put(DELETE_SITE_ACTION, deleteButton.getAction());
add( Components.strut() );
add( Components.label( strf(
@ -614,17 +604,26 @@ public class UserContentPanel extends JPanel implements MasterPassword.Listener,
InputEvent.getModifiersExText( copyLoginKeyStroke.getModifiers() ),
KeyEvent.getKeyText( copyLoginKeyStroke.getKeyCode() ) ) ) );
addHierarchyListener( e -> {
if (HierarchyEvent.DISPLAYABILITY_CHANGED == (e.getChangeFlags() & HierarchyEvent.DISPLAYABILITY_CHANGED)) {
if (null != SwingUtilities.windowForComponent( this )) {
KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher( this );
user.addListener( this );
} else {
KeyboardFocusManager.getCurrentKeyboardFocusManager().removeKeyEventDispatcher( this );
user.removeListener( this );
}
}
} );
final InputMap panelInputMap = getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
final ActionMap panelActionMap = getActionMap();
// Copy login/password
panelInputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), USE_SITE_ACTION);
panelInputMap.put(copyLoginKeyStroke, USE_SITE_ACTION);
panelActionMap.put(USE_SITE_ACTION, new SimpleAction(this::useSite));
// Clear Site
panelInputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), CLEAR_SITE_ACTION);
panelActionMap.put(CLEAR_SITE_ACTION, new SimpleAction(e -> queryField.setText("")));
// Show Login
panelInputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_SHIFT, InputEvent.SHIFT_DOWN_MASK), SHOW_LOGIN_ACTION); // Press
panelInputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_SHIFT, 0, true), SHOW_LOGIN_ACTION); // Release
panelActionMap.put(SHOW_LOGIN_ACTION, new SimpleAction(e -> setShowLogin((e.getModifiers() & ActionEvent.SHIFT_MASK) != 0)));
// Delete Site
sitesList.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0), DELETE_SITE_ACTION);
sitesList.getActionMap().put(DELETE_SITE_ACTION, deleteButton.getAction());
}
public void showUserPreferences() {
@ -1114,13 +1113,5 @@ public class UserContentPanel extends JPanel implements MasterPassword.Listener,
@Override
public void onUserInvalidated(final MPUser<?> user) {
}
@Override
public boolean dispatchKeyEvent(final KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_SHIFT)
setShowLogin( e.isShiftDown() );
return false;
}
}
}