2
0

Java Client: "Stay Resident" option improvements

- Reworded "Stay Resident" option to be more clear about what it does
- Added new option to keep user logged in when closing/hiding window
- Made it possible to force exit by holding down ALT key while closing
This commit is contained in:
Michael Ziminsky (Z) 2018-10-25 23:03:00 -07:00
parent 2794ea08e4
commit 8aaf3aec3c
4 changed files with 45 additions and 17 deletions

View File

@ -35,6 +35,7 @@ public class MPGuiConfig extends MPConfig {
Boolean checkForUpdates;
Boolean stayResident;
Boolean logoutOnClose;
public boolean checkForUpdates() {
return (checkForUpdates != null)? checkForUpdates:
@ -55,4 +56,13 @@ public class MPGuiConfig extends MPConfig {
this.stayResident = stayResident;
setChanged();
}
public boolean logoutOnClose() {
return (logoutOnClose != null)? logoutOnClose: true;
}
public void setLogoutOnClose(final boolean logoutOnClose) {
this.logoutOnClose = logoutOnClose;
setChanged();
}
}

View File

@ -11,4 +11,6 @@ import javax.swing.*;
public final class MPGuiConstants {
public static final KeyStroke ui_hotkey = KeyStroke.getKeyStroke( KeyEvent.VK_P, InputEvent.CTRL_DOWN_MASK | InputEvent.META_DOWN_MASK );
public static final int FORCE_CLOSE_KEY = KeyEvent.VK_ALT;
}

View File

@ -2,6 +2,7 @@ package com.lyndir.masterpassword.gui.view;
import com.lyndir.lhunath.opal.system.logging.Logger;
import com.lyndir.masterpassword.gui.MPGuiConfig;
import com.lyndir.masterpassword.gui.MPGuiConstants;
import com.lyndir.masterpassword.gui.util.Components;
import com.lyndir.masterpassword.gui.util.Res;
import com.lyndir.masterpassword.model.impl.MPFileUserManager;
@ -19,8 +20,6 @@ public class MasterPasswordFrame extends JFrame {
private static final Logger logger = Logger.get( MasterPasswordFrame.class );
private final UserContentPanel userContent;
@SuppressWarnings("MagicNumber")
public MasterPasswordFrame() {
super( "Master Password" );
@ -32,14 +31,16 @@ public class MasterPasswordFrame extends JFrame {
root.add( Components.strut() );
root.add( userPanel = Components.panel( new BorderLayout( 0, 0 ) ) );
final UserContentPanel userContent = new UserContentPanel();
userPanel.add( Components.borderPanel(
BorderFactory.createBevelBorder( BevelBorder.RAISED, Res.colors().controlBorder(), Res.colors().frameBg() ),
Res.colors().controlBg(), BoxLayout.PAGE_AXIS, userContent = new UserContentPanel() ), BorderLayout.CENTER );
Res.colors().controlBg(), BoxLayout.PAGE_AXIS, userContent), BorderLayout.CENTER );
userPanel.add( userContent.getUserToolbar(), BorderLayout.LINE_START );
userPanel.add( userContent.getSiteToolbar(), BorderLayout.LINE_END );
addComponentListener( new ComponentHandler() );
addWindowListener( new WindowHandler() );
final WindowHandler windowHandler = new WindowHandler();
addWindowListener(windowHandler);
KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(windowHandler);
setPreferredSize( new Dimension( 800, 560 ) );
setDefaultCloseOperation( DISPOSE_ON_CLOSE );
pack();
@ -48,22 +49,30 @@ public class MasterPasswordFrame extends JFrame {
setLocationByPlatform( true );
}
private class ComponentHandler extends ComponentAdapter {
@Override
public void componentShown(final ComponentEvent e) {
MPFileUserManager.get().reload();
userContent.transferFocus();
}
}
private static class WindowHandler extends WindowAdapter implements KeyEventDispatcher {
private static class WindowHandler extends WindowAdapter {
private boolean forceClose = false;
@Override
public void windowClosed(final WindowEvent e) {
if (!MPGuiConfig.get().stayResident())
if (!MPGuiConfig.get().stayResident() || forceClose) {
System.exit( 0 );
}
else if (MPGuiConfig.get().logoutOnClose()) {
MPFileUserManager.get().reload();
}
}
@Override
public boolean dispatchKeyEvent(KeyEvent e) {
if (e.getKeyCode() == MPGuiConstants.FORCE_CLOSE_KEY)
forceClose = (e.getID() == KeyEvent.KEY_PRESSED);
return false;
}
}
}

View File

@ -253,12 +253,19 @@ public class UserContentPanel extends JPanel implements MasterPassword.Listener,
private void showAppPreferences() {
Component checkForUpdates = Components.checkBox("Check For Updates", MPGuiConfig.get().checkForUpdates(), MPGuiConfig.get()::setCheckForUpdates);
Component stayResident = Components.checkBox(strf("<html>Stay Resident (reactivate with <strong><code>%s+%s</code></strong>)",
JCheckBox stayResident = Components.checkBox(strf("<html>Stay running in background when closed (reactivate with <strong><code>%s+%s</code></strong>)",
InputEvent.getModifiersExText(MPGuiConstants.ui_hotkey.getModifiers()),
KeyEvent.getKeyText(MPGuiConstants.ui_hotkey.getKeyCode())),
MPGuiConfig.get().stayResident(), MPGuiConfig.get()::setStayResident);
stayResident.setToolTipText(strf("<html>Hold <strong><code>%s</code></strong> while closing to force exit</html>", KeyEvent.getKeyText(MPGuiConstants.FORCE_CLOSE_KEY)));
Components.showDialog(this, "Application Preferences", new JOptionPane(Components.panel(BoxLayout.PAGE_AXIS, checkForUpdates, stayResident)));
Component logoutOnClose = Components.checkBox("Logout current user on close", MPGuiConfig.get().logoutOnClose(), MPGuiConfig.get()::setLogoutOnClose);
stayResident.addItemListener(e -> logoutOnClose.setEnabled(e.getStateChange() == ItemEvent.SELECTED));
logoutOnClose.setEnabled(stayResident.isSelected());
Components.showDialog(this, "Application Preferences",
new JOptionPane(Components.panel(BoxLayout.PAGE_AXIS, checkForUpdates, stayResident, logoutOnClose)));
}
private enum ContentMode {