2
0

Button tooltips and improvements.

This commit is contained in:
Maarten Billemont 2018-07-28 18:11:36 -04:00
parent 7455fba55e
commit 38f09021b3
5 changed files with 41 additions and 25 deletions

View File

@ -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 ) { JButton iconButton = button( new AbstractAction( null, icon ) {
@Override @Override
public void actionPerformed(final ActionEvent e) { public void actionPerformed(final ActionEvent e) {
@ -248,6 +248,7 @@ public abstract class Components {
return actionListener != null; return actionListener != null;
} }
} ); } );
iconButton.setToolTipText( toolTip );
iconButton.setFocusable( false ); iconButton.setFocusable( false );
return iconButton; return iconButton;

View File

@ -3,9 +3,7 @@ package com.lyndir.masterpassword.gui.view;
import static com.lyndir.masterpassword.util.Utilities.*; import static com.lyndir.masterpassword.util.Utilities.*;
import com.google.common.collect.ImmutableSortedSet; import com.google.common.collect.ImmutableSortedSet;
import com.lyndir.masterpassword.gui.util.Res; import com.lyndir.masterpassword.gui.util.*;
import com.lyndir.masterpassword.gui.util.CollectionListModel;
import com.lyndir.masterpassword.gui.util.Components;
import com.lyndir.masterpassword.model.MPUser; import com.lyndir.masterpassword.model.MPUser;
import com.lyndir.masterpassword.model.impl.MPFileUser; import com.lyndir.masterpassword.model.impl.MPFileUser;
import com.lyndir.masterpassword.model.impl.MPFileUserManager; import com.lyndir.masterpassword.model.impl.MPFileUserManager;
@ -24,7 +22,8 @@ public class FilesPanel extends JPanel implements MPFileUserManager.Listener {
private final Collection<Listener> listeners = new CopyOnWriteArraySet<>(); private final Collection<Listener> 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<MPUser<?>> usersModel = private final CollectionListModel<MPUser<?>> usersModel =
CollectionListModel.<MPUser<?>>copy( MPFileUserManager.get().getFiles() ).selection( this::setUser ); CollectionListModel.<MPUser<?>>copy( MPFileUserManager.get().getFiles() ).selection( this::setUser );
@ -43,7 +42,6 @@ public class FilesPanel extends JPanel implements MPFileUserManager.Listener {
add( avatarButton ); add( avatarButton );
avatarButton.setHorizontalAlignment( SwingConstants.CENTER ); avatarButton.setHorizontalAlignment( SwingConstants.CENTER );
avatarButton.setMaximumSize( new Dimension( Integer.MAX_VALUE, 0 ) ); avatarButton.setMaximumSize( new Dimension( Integer.MAX_VALUE, 0 ) );
avatarButton.setToolTipText( "The avatar for your user. Click to change it." );
// - // -
add( Components.strut( Components.margin() ) ); add( Components.strut( Components.margin() ) );

View File

@ -35,7 +35,10 @@ public class UserContentPanel extends JPanel implements FilesPanel.Listener, MPU
private static final Random random = new Random(); private static final Random random = new Random();
private static final Logger logger = Logger.get( UserContentPanel.class ); 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 userToolbar = Components.panel( BoxLayout.PAGE_AXIS );
private final JPanel siteToolbar = 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( "<html>Enter your full legal name:</html>" ), "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 final class NoUserPanel extends JPanel {
private NoUserPanel() { private NoUserPanel() {
setLayout( new BoxLayout( this, BoxLayout.PAGE_AXIS ) ); setLayout( new BoxLayout( this, BoxLayout.PAGE_AXIS ) );
userToolbar.add( addButton );
add( Box.createGlue() ); add( Box.createGlue() );
add( Components.heading( "Select a user to proceed." ) ); add( Components.heading( "Select a user to proceed." ) );
add( Box.createGlue() ); add( Box.createGlue() );
@ -125,8 +140,8 @@ public class UserContentPanel extends JPanel implements FilesPanel.Listener, MPU
@Nonnull @Nonnull
private final MPUser<?> user; 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 JPasswordField masterPasswordField = Components.passwordField();
private final JLabel errorLabel = Components.label(); private final JLabel errorLabel = Components.label();
@ -159,16 +174,6 @@ public class UserContentPanel extends JPanel implements FilesPanel.Listener, MPU
add( Box.createGlue() ); add( Box.createGlue() );
} }
private void addUser() {
Object fullName = JOptionPane.showInputDialog(
this, strf( "<html>Enter your full legal name:</html>" ), "Add User",
JOptionPane.QUESTION_MESSAGE, null, null, "Robert Lee Mitchell" );
if (fullName == null)
return;
setUser( MPFileUserManager.get().add( fullName.toString() ) );
}
private void deleteUser() { private void deleteUser() {
MPFileUser fileUser = (user instanceof MPFileUser)? (MPFileUser) user: null; MPFileUser fileUser = (user instanceof MPFileUser)? (MPFileUser) user: null;
if (fileUser == null) if (fileUser == null)
@ -248,11 +253,16 @@ public class UserContentPanel extends JPanel implements FilesPanel.Listener, MPU
public static final int SIZE_RESULT = 48; public static final int SIZE_RESULT = 48;
private final JButton userButton = Components.button( Res.icons().user(), event -> showUserPreferences() ); private final JButton userButton = Components.button( Res.icons().user(), event -> showUserPreferences(),
private final JButton logoutButton = Components.button( Res.icons().lock(), event -> logoutUser() ); "Show user preferences." );
private final JButton settingsButton = Components.button( Res.icons().settings(), event -> showSiteSettings() ); private final JButton logoutButton = Components.button( Res.icons().lock(), event -> logoutUser(),
private final JButton questionsButton = Components.button( Res.icons().question(), null ); "Sign out and lock user." );
private final JButton deleteButton = Components.button( Res.icons().delete(), event -> deleteSite() ); 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 @Nonnull
private final MPUser<?> user; private final MPUser<?> user;
@ -272,6 +282,7 @@ public class UserContentPanel extends JPanel implements FilesPanel.Listener, MPU
this.user = user; this.user = user;
userToolbar.add( addButton );
userToolbar.add( userButton ); userToolbar.add( userButton );
userToolbar.add( logoutButton ); userToolbar.add( logoutButton );
@ -279,6 +290,7 @@ public class UserContentPanel extends JPanel implements FilesPanel.Listener, MPU
siteToolbar.add( questionsButton ); siteToolbar.add( questionsButton );
siteToolbar.add( deleteButton ); siteToolbar.add( deleteButton );
settingsButton.setEnabled( false ); settingsButton.setEnabled( false );
deleteButton.setEnabled( false );
add( Components.heading( user.getFullName(), SwingConstants.CENTER ) ); add( Components.heading( user.getFullName(), SwingConstants.CENTER ) );
@ -366,6 +378,9 @@ public class UserContentPanel extends JPanel implements FilesPanel.Listener, MPU
if (site == null) if (site == null)
return; return;
if (JOptionPane.YES_OPTION == JOptionPane.showConfirmDialog(
this, strf( "<html>Forget the site <strong>%s</strong>?</html>", site.getSiteName() ),
"Delete Site", JOptionPane.YES_NO_OPTION ))
user.deleteSite( site ); user.deleteSite( site );
} }
@ -434,6 +449,7 @@ public class UserContentPanel extends JPanel implements FilesPanel.Listener, MPU
passwordLabel.setText( " " ); passwordLabel.setText( " " );
passwordField.setText( " " ); passwordField.setText( " " );
settingsButton.setEnabled( false ); settingsButton.setEnabled( false );
deleteButton.setEnabled( false );
} ); } );
return; return;
} }
@ -448,6 +464,7 @@ public class UserContentPanel extends JPanel implements FilesPanel.Listener, MPU
passwordLabel.setText( strf( "Your password for %s:", site.getSiteName() ) ); passwordLabel.setText( strf( "Your password for %s:", site.getSiteName() ) );
passwordField.setText( result ); passwordField.setText( result );
settingsButton.setEnabled( true ); settingsButton.setEnabled( true );
deleteButton.setEnabled( true );
} ); } );
} }
catch (final MPKeyUnavailableException | MPAlgorithmException e) { catch (final MPKeyUnavailableException | MPAlgorithmException e) {

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.3 KiB

After

Width:  |  Height:  |  Size: 2.1 KiB