diff --git a/platform-independent/java/gui/src/main/java/com/lyndir/masterpassword/gui/util/Components.java b/platform-independent/java/gui/src/main/java/com/lyndir/masterpassword/gui/util/Components.java index 1eb68e5a..8bc68a9f 100644 --- a/platform-independent/java/gui/src/main/java/com/lyndir/masterpassword/gui/util/Components.java +++ b/platform-independent/java/gui/src/main/java/com/lyndir/masterpassword/gui/util/Components.java @@ -235,7 +235,7 @@ public abstract class Components { } ); } - public static JButton button(final Icon icon, @Nullable final ActionListener actionListener) { + public static JButton button(final Icon icon, @Nullable final ActionListener actionListener, @Nullable String toolTip) { JButton iconButton = button( new AbstractAction( null, icon ) { @Override public void actionPerformed(final ActionEvent e) { @@ -248,6 +248,7 @@ public abstract class Components { return actionListener != null; } } ); + iconButton.setToolTipText( toolTip ); iconButton.setFocusable( false ); return iconButton; diff --git a/platform-independent/java/gui/src/main/java/com/lyndir/masterpassword/gui/view/FilesPanel.java b/platform-independent/java/gui/src/main/java/com/lyndir/masterpassword/gui/view/FilesPanel.java index 18937afc..8aa0778c 100644 --- a/platform-independent/java/gui/src/main/java/com/lyndir/masterpassword/gui/view/FilesPanel.java +++ b/platform-independent/java/gui/src/main/java/com/lyndir/masterpassword/gui/view/FilesPanel.java @@ -3,9 +3,7 @@ package com.lyndir.masterpassword.gui.view; import static com.lyndir.masterpassword.util.Utilities.*; import com.google.common.collect.ImmutableSortedSet; -import com.lyndir.masterpassword.gui.util.Res; -import com.lyndir.masterpassword.gui.util.CollectionListModel; -import com.lyndir.masterpassword.gui.util.Components; +import com.lyndir.masterpassword.gui.util.*; import com.lyndir.masterpassword.model.MPUser; import com.lyndir.masterpassword.model.impl.MPFileUser; import com.lyndir.masterpassword.model.impl.MPFileUserManager; @@ -24,7 +22,8 @@ public class FilesPanel extends JPanel implements MPFileUserManager.Listener { private final Collection listeners = new CopyOnWriteArraySet<>(); - private final JButton avatarButton = Components.button( Res.icons().avatar( 0 ), event -> setAvatar() ); + private final JButton avatarButton = Components.button( Res.icons().avatar( 0 ), event -> setAvatar(), + "Click to change the user's avatar." ); private final CollectionListModel> usersModel = CollectionListModel.>copy( MPFileUserManager.get().getFiles() ).selection( this::setUser ); @@ -43,7 +42,6 @@ public class FilesPanel extends JPanel implements MPFileUserManager.Listener { add( avatarButton ); avatarButton.setHorizontalAlignment( SwingConstants.CENTER ); avatarButton.setMaximumSize( new Dimension( Integer.MAX_VALUE, 0 ) ); - avatarButton.setToolTipText( "The avatar for your user. Click to change it." ); // - add( Components.strut( Components.margin() ) ); diff --git a/platform-independent/java/gui/src/main/java/com/lyndir/masterpassword/gui/view/UserContentPanel.java b/platform-independent/java/gui/src/main/java/com/lyndir/masterpassword/gui/view/UserContentPanel.java index 8734f5b6..5fecd091 100644 --- a/platform-independent/java/gui/src/main/java/com/lyndir/masterpassword/gui/view/UserContentPanel.java +++ b/platform-independent/java/gui/src/main/java/com/lyndir/masterpassword/gui/view/UserContentPanel.java @@ -35,7 +35,10 @@ public class UserContentPanel extends JPanel implements FilesPanel.Listener, MPU private static final Random random = new Random(); private static final Logger logger = Logger.get( UserContentPanel.class ); - private static final JButton iconButton = Components.button( Res.icons().user(), null ); + private static final JButton iconButton = Components.button( Res.icons().user(), null, null ); + + private final JButton addButton = Components.button( Res.icons().add(), event -> addUser(), + "Add a new user to Master Password." ); private final JPanel userToolbar = Components.panel( BoxLayout.PAGE_AXIS ); private final JPanel siteToolbar = Components.panel( BoxLayout.PAGE_AXIS ); @@ -108,11 +111,23 @@ public class UserContentPanel extends JPanel implements FilesPanel.Listener, MPU } ); } + private void addUser() { + Object fullName = JOptionPane.showInputDialog( + this, strf( "Enter your full legal name:" ), "Add User", + JOptionPane.QUESTION_MESSAGE, null, null, "Robert Lee Mitchell" ); + if (fullName == null) + return; + + setUser( MPFileUserManager.get().add( fullName.toString() ) ); + } + private final class NoUserPanel extends JPanel { private NoUserPanel() { setLayout( new BoxLayout( this, BoxLayout.PAGE_AXIS ) ); + userToolbar.add( addButton ); + add( Box.createGlue() ); add( Components.heading( "Select a user to proceed." ) ); add( Box.createGlue() ); @@ -125,8 +140,8 @@ public class UserContentPanel extends JPanel implements FilesPanel.Listener, MPU @Nonnull private final MPUser user; - private final JButton addButton = Components.button( Res.icons().add(), event -> addUser() ); - private final JButton deleteButton = Components.button( Res.icons().delete(), event -> deleteUser() ); + private final JButton deleteButton = Components.button( Res.icons().delete(), event -> deleteUser(), + "Delete this user from Master Password." ); private final JPasswordField masterPasswordField = Components.passwordField(); private final JLabel errorLabel = Components.label(); @@ -159,16 +174,6 @@ public class UserContentPanel extends JPanel implements FilesPanel.Listener, MPU add( Box.createGlue() ); } - private void addUser() { - Object fullName = JOptionPane.showInputDialog( - this, strf( "Enter your full legal name:" ), "Add User", - JOptionPane.QUESTION_MESSAGE, null, null, "Robert Lee Mitchell" ); - if (fullName == null) - return; - - setUser( MPFileUserManager.get().add( fullName.toString() ) ); - } - private void deleteUser() { MPFileUser fileUser = (user instanceof MPFileUser)? (MPFileUser) user: null; if (fileUser == null) @@ -248,11 +253,16 @@ public class UserContentPanel extends JPanel implements FilesPanel.Listener, MPU public static final int SIZE_RESULT = 48; - private final JButton userButton = Components.button( Res.icons().user(), event -> showUserPreferences() ); - private final JButton logoutButton = Components.button( Res.icons().lock(), event -> logoutUser() ); - private final JButton settingsButton = Components.button( Res.icons().settings(), event -> showSiteSettings() ); - private final JButton questionsButton = Components.button( Res.icons().question(), null ); - private final JButton deleteButton = Components.button( Res.icons().delete(), event -> deleteSite() ); + private final JButton userButton = Components.button( Res.icons().user(), event -> showUserPreferences(), + "Show user preferences." ); + private final JButton logoutButton = Components.button( Res.icons().lock(), event -> logoutUser(), + "Sign out and lock user." ); + private final JButton settingsButton = Components.button( Res.icons().settings(), event -> showSiteSettings(), + "Show site settings." ); + private final JButton questionsButton = Components.button( Res.icons().question(), null, + "Show site recovery questions." ); + private final JButton deleteButton = Components.button( Res.icons().delete(), event -> deleteSite(), + "Delete the site from the user." ); @Nonnull private final MPUser user; @@ -272,6 +282,7 @@ public class UserContentPanel extends JPanel implements FilesPanel.Listener, MPU this.user = user; + userToolbar.add( addButton ); userToolbar.add( userButton ); userToolbar.add( logoutButton ); @@ -279,6 +290,7 @@ public class UserContentPanel extends JPanel implements FilesPanel.Listener, MPU siteToolbar.add( questionsButton ); siteToolbar.add( deleteButton ); settingsButton.setEnabled( false ); + deleteButton.setEnabled( false ); add( Components.heading( user.getFullName(), SwingConstants.CENTER ) ); @@ -366,7 +378,10 @@ public class UserContentPanel extends JPanel implements FilesPanel.Listener, MPU if (site == null) return; - user.deleteSite( site ); + if (JOptionPane.YES_OPTION == JOptionPane.showConfirmDialog( + this, strf( "Forget the site %s?", site.getSiteName() ), + "Delete Site", JOptionPane.YES_NO_OPTION )) + user.deleteSite( site ); } private String getSiteDescription(@Nonnull final MPSite site) { @@ -434,6 +449,7 @@ public class UserContentPanel extends JPanel implements FilesPanel.Listener, MPU passwordLabel.setText( " " ); passwordField.setText( " " ); settingsButton.setEnabled( false ); + deleteButton.setEnabled( false ); } ); return; } @@ -448,6 +464,7 @@ public class UserContentPanel extends JPanel implements FilesPanel.Listener, MPU passwordLabel.setText( strf( "Your password for %s:", site.getSiteName() ) ); passwordField.setText( result ); settingsButton.setEnabled( true ); + deleteButton.setEnabled( true ); } ); } catch (final MPKeyUnavailableException | MPAlgorithmException e) { diff --git a/platform-independent/java/gui/src/main/resources/media/icon_delete.png b/platform-independent/java/gui/src/main/resources/media/icon_delete.png index 801d2c55..5a82d20d 100644 Binary files a/platform-independent/java/gui/src/main/resources/media/icon_delete.png and b/platform-independent/java/gui/src/main/resources/media/icon_delete.png differ diff --git a/platform-independent/java/gui/src/main/resources/media/icon_delete@2x.png b/platform-independent/java/gui/src/main/resources/media/icon_delete@2x.png index fe1f717e..3f034c80 100644 Binary files a/platform-independent/java/gui/src/main/resources/media/icon_delete@2x.png and b/platform-independent/java/gui/src/main/resources/media/icon_delete@2x.png differ