2
0

Add tip to copy password & close app + less console verbosity in Java GUI.

This commit is contained in:
Maarten Billemont 2014-08-27 22:08:53 -04:00
parent 65cef6d8ed
commit f47ff67ba9
11 changed files with 94 additions and 10 deletions

View File

@ -41,7 +41,7 @@
<dependency>
<groupId>com.lambdaworks</groupId>
<artifactId>scrypt</artifactId>
<version>1.3.2</version>
<version>1.4.0</version>
</dependency>
</dependencies>

View File

@ -1,6 +1,7 @@
package com.lyndir.masterpassword;
import com.apple.eawt.*;
import javax.swing.*;
/**
@ -29,4 +30,12 @@ public class AppleGUI extends GUI {
}
} );
}
@Override
protected PasswordFrame newPasswordFrame(final User user) {
PasswordFrame frame = super.newPasswordFrame( user );
frame.setDefaultCloseOperation( WindowConstants.DISPOSE_ON_CLOSE );
return frame;
}
}

View File

@ -62,9 +62,16 @@ public class GUI implements UnlockFrame.SignInCallback {
}
user.getKey();
passwordFrame = new PasswordFrame( user );
passwordFrame = newPasswordFrame( user );
open();
return true;
}
protected PasswordFrame newPasswordFrame(final User user) {
PasswordFrame frame = new PasswordFrame( user );
frame.setDefaultCloseOperation( WindowConstants.EXIT_ON_CLOSE );
return frame;
}
}

View File

@ -22,6 +22,7 @@ public class PasswordFrame extends JFrame implements DocumentListener {
private final JComboBox<MPElementType> siteTypeField;
private final JSpinner siteCounterField;
private final JLabel passwordLabel;
private final JLabel tipLabel;
public PasswordFrame(User user)
throws HeadlessException {
@ -30,7 +31,6 @@ public class PasswordFrame extends JFrame implements DocumentListener {
JLabel label;
setDefaultCloseOperation( DISPOSE_ON_CLOSE );
setContentPane( new JPanel( new BorderLayout( 20, 20 ) ) {
{
setBorder( new EmptyBorder( 20, 20, 20, 20 ) );
@ -39,6 +39,7 @@ public class PasswordFrame extends JFrame implements DocumentListener {
// User
add( label = new JLabel( strf( "Generating passwords for: %s", user.getName() ) ), BorderLayout.NORTH );
label.setFont( Res.exoRegular().deriveFont( 12f ) );
label.setAlignmentX( LEFT_ALIGNMENT );
// Site
@ -49,6 +50,7 @@ public class PasswordFrame extends JFrame implements DocumentListener {
// Site Name
sitePanel.add( label = new JLabel( "Site Name:", JLabel.LEADING ) );
label.setFont( Res.exoRegular().deriveFont( 12f ) );
label.setAlignmentX( LEFT_ALIGNMENT );
sitePanel.add( siteNameField = new JTextField() {
@ -57,6 +59,7 @@ public class PasswordFrame extends JFrame implements DocumentListener {
return new Dimension( Integer.MAX_VALUE, getPreferredSize().height );
}
} );
siteNameField.setFont( Res.exoRegular().deriveFont( 12f ) );
siteNameField.setAlignmentX( LEFT_ALIGNMENT );
siteNameField.getDocument().addDocumentListener( this );
siteNameField.addActionListener( new ActionListener() {
@ -71,7 +74,10 @@ public class PasswordFrame extends JFrame implements DocumentListener {
SwingUtilities.invokeLater( new Runnable() {
@Override
public void run() {
dispose();
if (getDefaultCloseOperation() == WindowConstants.EXIT_ON_CLOSE)
System.exit( 0 );
else
dispose();
}
} );
}
@ -92,6 +98,7 @@ public class PasswordFrame extends JFrame implements DocumentListener {
} );
siteSettings.setAlignmentX( LEFT_ALIGNMENT );
sitePanel.add( siteSettings );
siteTypeField.setFont( Res.exoRegular().deriveFont( 12f ) );
siteTypeField.setAlignmentX( LEFT_ALIGNMENT );
siteTypeField.setAlignmentY( CENTER_ALIGNMENT );
siteTypeField.setSelectedItem( MPElementType.GeneratedLong );
@ -102,6 +109,7 @@ public class PasswordFrame extends JFrame implements DocumentListener {
}
} );
siteCounterField.setFont( Res.exoRegular().deriveFont( 12f ) );
siteCounterField.setAlignmentX( RIGHT_ALIGNMENT );
siteCounterField.setAlignmentY( CENTER_ALIGNMENT );
siteCounterField.addChangeListener( new ChangeListener() {
@ -112,9 +120,16 @@ public class PasswordFrame extends JFrame implements DocumentListener {
} );
// Password
add( passwordLabel = new JLabel( " ", JLabel.CENTER ), BorderLayout.SOUTH );
passwordLabel.setAlignmentX( LEFT_ALIGNMENT );
passwordLabel = new JLabel( " ", JLabel.CENTER );
passwordLabel.setFont( Res.sourceCodeProBlack().deriveFont( 40f ) );
passwordLabel.setAlignmentX( Component.CENTER_ALIGNMENT );
// Tip
tipLabel = new JLabel( " ", JLabel.CENTER );
tipLabel.setFont( Res.exoThin().deriveFont( 9f ) );
tipLabel.setAlignmentX( Component.CENTER_ALIGNMENT );
add( Components.boxLayout( BoxLayout.PAGE_AXIS, passwordLabel, tipLabel ), BorderLayout.SOUTH );
pack();
setMinimumSize( getSize() );
@ -132,6 +147,7 @@ public class PasswordFrame extends JFrame implements DocumentListener {
if (siteType.getTypeClass() != MPElementTypeClass.Generated || siteName == null || siteName.isEmpty() || !user.hasKey()) {
passwordLabel.setText( null );
tipLabel.setText( null );
return;
}
@ -139,14 +155,14 @@ public class PasswordFrame extends JFrame implements DocumentListener {
@Override
public void run() {
final String sitePassword = MasterPassword.generateContent( siteType, siteName, user.getKey(), siteCounter );
if (callback != null) {
if (callback != null)
callback.passwordGenerated( siteName, sitePassword );
}
SwingUtilities.invokeLater( new Runnable() {
@Override
public void run() {
passwordLabel.setText( sitePassword );
tipLabel.setText( "Press [Enter] to copy the password." );
}
} );
}

View File

@ -26,6 +26,10 @@ public abstract class Res {
private static final Logger logger = Logger.get( Res.class );
private static Font sourceCodeProBlack;
private static Font exoBold;
private static Font exoExtraBold;
private static Font exoRegular;
private static Font exoThin;
public static void execute(final Runnable job) {
executor.submit( new Runnable() {
@ -61,6 +65,54 @@ public abstract class Res {
}
}
public static Font exoBold() {
try {
URL resource = Resources.getResource( "fonts/Exo2.0-Bold.otf" );
Font font = Font.createFont( Font.TRUETYPE_FONT, resource.openStream() );
return exoBold != null? exoBold: //
(exoBold = font);
}
catch (FontFormatException | IOException e) {
throw Throwables.propagate( e );
}
}
public static Font exoExtraBold() {
try {
URL resource = Resources.getResource( "fonts/Exo2.0-ExtraBold.otf" );
Font font = Font.createFont( Font.TRUETYPE_FONT, resource.openStream() );
return exoExtraBold != null? exoExtraBold: //
(exoExtraBold = font);
}
catch (FontFormatException | IOException e) {
throw Throwables.propagate( e );
}
}
public static Font exoRegular() {
try {
URL resource = Resources.getResource( "fonts/Exo2.0-Regular.otf" );
Font font = Font.createFont( Font.TRUETYPE_FONT, resource.openStream() );
return exoRegular != null? exoRegular: //
(exoRegular = font);
}
catch (FontFormatException | IOException e) {
throw Throwables.propagate( e );
}
}
public static Font exoThin() {
try {
URL resource = Resources.getResource( "fonts/Exo2.0-Thin.otf" );
Font font = Font.createFont( Font.TRUETYPE_FONT, resource.openStream() );
return exoThin != null? exoThin: //
(exoThin = font);
}
catch (FontFormatException | IOException e) {
throw Throwables.propagate( e );
}
}
private static final class RetinaIcon extends ImageIcon {
private static final Pattern scalePattern = Pattern.compile(".*@(\\d+)x.[^.]+$");

View File

@ -9,7 +9,7 @@ import javax.swing.*;
*/
public abstract class Components {
public static JComponent boxLayout(int axis, Component... components) {
public static JPanel boxLayout(int axis, Component... components) {
JPanel container = new JPanel();
container.setLayout( new BoxLayout( container, axis ) );
for (Component component : components)

View File

@ -6,7 +6,7 @@
</layout>
</appender>
<logger name="com.lyndir" level="TRACE" />
<logger name="com.lyndir" level="INFO" />
<root level="INFO">
<appender-ref ref="STDOUT" />