Apply 'Lhunath' code inspection fixes and improvements.
This commit is contained in:
@@ -8,7 +8,7 @@ description = 'Master Password GUI'
|
||||
mainClassName = 'com.lyndir.masterpassword.gui.GUI'
|
||||
|
||||
dependencies {
|
||||
compile project(':masterpassword:model')
|
||||
compile project(':masterpassword-model')
|
||||
|
||||
compile group: 'ch.qos.logback', name: 'logback-classic', version:'1.1.2'
|
||||
compile group: 'com.yuvimasory', name: 'orange-extensions', version:'1.3.0'
|
||||
|
@@ -46,8 +46,7 @@ public class GUI implements UnlockFrame.SignInCallback {
|
||||
private final UnlockFrame unlockFrame = new UnlockFrame( this );
|
||||
private PasswordFrame passwordFrame;
|
||||
|
||||
public static void main(final String[] args)
|
||||
throws IOException {
|
||||
public static void main(final String... args) {
|
||||
|
||||
if (Config.get().checkForUpdates())
|
||||
checkUpdate();
|
||||
@@ -76,7 +75,7 @@ public class GUI implements UnlockFrame.SignInCallback {
|
||||
String upstreamRevision = upstream.readFirstLine();
|
||||
logger.inf( "Local Revision: <%s>", manifestRevision );
|
||||
logger.inf( "Upstream Revision: <%s>", upstreamRevision );
|
||||
if (manifestRevision != null && !manifestRevision.equalsIgnoreCase( upstreamRevision )) {
|
||||
if ((manifestRevision != null) && !manifestRevision.equalsIgnoreCase( upstreamRevision )) {
|
||||
logger.wrn( "You are not running the current official version. Please update from:\n"
|
||||
+ "http://masterpasswordapp.com/masterpassword-gui.jar" );
|
||||
JOptionPane.showMessageDialog( null, "A new version of Master Password is available.\n"
|
||||
@@ -85,7 +84,7 @@ public class GUI implements UnlockFrame.SignInCallback {
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (IOException e) {
|
||||
catch (final IOException e) {
|
||||
logger.wrn( e, "Couldn't check for version update." );
|
||||
}
|
||||
}
|
||||
|
@@ -23,14 +23,17 @@ import java.util.concurrent.*;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import javax.swing.*;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
|
||||
|
||||
/**
|
||||
* @author lhunath, 2014-06-11
|
||||
*/
|
||||
@SuppressWarnings("HardcodedFileSeparator")
|
||||
public abstract class Res {
|
||||
|
||||
private static final WeakHashMap<Window, ScheduledExecutorService> executorByWindow = new WeakHashMap<>();
|
||||
private static final int AVATAR_COUNT = 19;
|
||||
private static final Map<Window, ScheduledExecutorService> executorByWindow = new WeakHashMap<>();
|
||||
private static final Logger logger = Logger.get( Res.class );
|
||||
private static final Colors colors = new Colors();
|
||||
|
||||
@@ -45,7 +48,7 @@ public abstract class Res {
|
||||
try {
|
||||
job.run();
|
||||
}
|
||||
catch (Throwable t) {
|
||||
catch (final Throwable t) {
|
||||
logger.err( t, "Unexpected: %s", t.getLocalizedMessage() );
|
||||
}
|
||||
}
|
||||
@@ -65,9 +68,9 @@ public abstract class Res {
|
||||
try {
|
||||
return job.call();
|
||||
}
|
||||
catch (Throwable t) {
|
||||
catch (final Throwable t) {
|
||||
logger.err( t, "Unexpected: %s", t.getLocalizedMessage() );
|
||||
throw t;
|
||||
throw Throwables.propagate( t );
|
||||
}
|
||||
}
|
||||
}, delay, timeUnit ), executor );
|
||||
@@ -109,7 +112,7 @@ public abstract class Res {
|
||||
}
|
||||
|
||||
public static int avatars() {
|
||||
return 19;
|
||||
return AVATAR_COUNT;
|
||||
}
|
||||
|
||||
public static Font emoticonsFont() {
|
||||
@@ -180,10 +183,10 @@ public abstract class Res {
|
||||
return font( "fonts/Arimo-Regular.ttf" );
|
||||
}
|
||||
|
||||
private static Font font(String fontResourceName) {
|
||||
private static Font font(@NonNls final String fontResourceName) {
|
||||
Map<String, SoftReference<Font>> fontsByResourceName = Maps.newHashMap();
|
||||
SoftReference<Font> fontRef = fontsByResourceName.get( fontResourceName );
|
||||
Font font = fontRef == null? null: fontRef.get();
|
||||
Font font = (fontRef == null)? null: fontRef.get();
|
||||
if (font == null)
|
||||
try {
|
||||
fontsByResourceName.put( fontResourceName, new SoftReference<>(
|
||||
@@ -203,17 +206,15 @@ public abstract class Res {
|
||||
private static final class RetinaIcon extends ImageIcon {
|
||||
|
||||
private static final Pattern scalePattern = Pattern.compile( ".*@(\\d+)x.[^.]+$" );
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private final float scale;
|
||||
|
||||
public RetinaIcon(final URL url) {
|
||||
private RetinaIcon(final URL url) {
|
||||
super( url );
|
||||
|
||||
Matcher scaleMatcher = scalePattern.matcher( url.getPath() );
|
||||
if (scaleMatcher.matches())
|
||||
scale = Float.parseFloat( scaleMatcher.group( 1 ) );
|
||||
else
|
||||
scale = 1;
|
||||
scale = scaleMatcher.matches()? Float.parseFloat( scaleMatcher.group( 1 ) ): 1;
|
||||
}
|
||||
|
||||
//private static URL retinaURL(final URL url) {
|
||||
@@ -242,13 +243,14 @@ public abstract class Res {
|
||||
return (int) (super.getIconHeight() / scale);
|
||||
}
|
||||
|
||||
public synchronized void paintIcon(Component c, Graphics g, int x, int y) {
|
||||
@Override
|
||||
public synchronized void paintIcon(final Component c, final Graphics g, final int x, final int y) {
|
||||
ImageObserver observer = ifNotNullElse( getImageObserver(), c );
|
||||
|
||||
Image image = getImage();
|
||||
int width = image.getWidth( observer );
|
||||
int height = image.getHeight( observer );
|
||||
final Graphics2D g2d = (Graphics2D) g.create( x, y, width, height );
|
||||
Graphics2D g2d = (Graphics2D) g.create( x, y, width, height );
|
||||
|
||||
g2d.scale( 1 / scale, 1 / scale );
|
||||
g2d.drawImage( image, 0, 0, observer );
|
||||
@@ -276,7 +278,7 @@ public abstract class Res {
|
||||
return controlBorder;
|
||||
}
|
||||
|
||||
public Color fromIdenticonColor(MPIdenticon.Color identiconColor, BackgroundMode backgroundMode) {
|
||||
public Color fromIdenticonColor(final MPIdenticon.Color identiconColor, final BackgroundMode backgroundMode) {
|
||||
switch (identiconColor) {
|
||||
case RED:
|
||||
switch (backgroundMode) {
|
||||
|
@@ -23,18 +23,22 @@ public class IncognitoSite extends Site {
|
||||
this.algorithmVersion = algorithmVersion;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSiteName() {
|
||||
return siteName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSiteName(final String siteName) {
|
||||
this.siteName = siteName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MPSiteType getSiteType() {
|
||||
return siteType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSiteType(final MPSiteType siteType) {
|
||||
this.siteType = siteType;
|
||||
}
|
||||
@@ -49,10 +53,12 @@ public class IncognitoSite extends Site {
|
||||
this.algorithmVersion = algorithmVersion;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UnsignedInteger getSiteCounter() {
|
||||
return siteCounter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSiteCounter(final UnsignedInteger siteCounter) {
|
||||
this.siteCounter = siteCounter;
|
||||
}
|
||||
|
@@ -11,12 +11,14 @@ import javax.annotation.Nullable;
|
||||
public class IncognitoUser extends User {
|
||||
|
||||
private final String fullName;
|
||||
@Nullable
|
||||
private char[] masterPassword;
|
||||
|
||||
public IncognitoUser(final String fullName) {
|
||||
this.fullName = fullName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFullName() {
|
||||
return fullName;
|
||||
}
|
||||
@@ -30,7 +32,7 @@ public class IncognitoUser extends User {
|
||||
@Override
|
||||
public void authenticate(final char[] masterPassword)
|
||||
throws IncorrectMasterPasswordException {
|
||||
this.masterPassword = masterPassword;
|
||||
this.masterPassword = masterPassword.clone();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -43,6 +45,6 @@ public class IncognitoUser extends User {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteSite(Site site) {
|
||||
public void deleteSite(final Site site) {
|
||||
}
|
||||
}
|
||||
|
@@ -14,13 +14,14 @@ public class ModelSite extends Site {
|
||||
private final MPSite model;
|
||||
|
||||
public ModelSite(final MPSiteResult result) {
|
||||
this.model = result.getSite();
|
||||
model = result.getSite();
|
||||
}
|
||||
|
||||
public MPSite getModel() {
|
||||
return model;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSiteName() {
|
||||
return model.getSiteName();
|
||||
}
|
||||
@@ -31,6 +32,7 @@ public class ModelSite extends Site {
|
||||
MPUserFileManager.get().save();
|
||||
}
|
||||
|
||||
@Override
|
||||
public MPSiteType getSiteType() {
|
||||
return model.getSiteType();
|
||||
}
|
||||
@@ -56,6 +58,7 @@ public class ModelSite extends Site {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public UnsignedInteger getSiteCounter() {
|
||||
return model.getSiteCounter();
|
||||
}
|
||||
|
@@ -19,7 +19,7 @@ public class ModelUser extends User {
|
||||
@Nullable
|
||||
private char[] masterPassword;
|
||||
|
||||
public ModelUser(MPUser model) {
|
||||
public ModelUser(final MPUser model) {
|
||||
this.model = model;
|
||||
}
|
||||
|
||||
@@ -48,10 +48,11 @@ public class ModelUser extends User {
|
||||
MPUserFileManager.get().save();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void authenticate(final char[] masterPassword)
|
||||
throws IncorrectMasterPasswordException {
|
||||
putKey( model.authenticate( masterPassword ) );
|
||||
this.masterPassword = masterPassword;
|
||||
this.masterPassword = masterPassword.clone();
|
||||
MPUserFileManager.get().save();
|
||||
}
|
||||
|
||||
@@ -66,8 +67,8 @@ public class ModelUser extends User {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<Site> findSitesByName(final String query) {
|
||||
return FluentIterable.from( model.findSitesByName( query ) ).transform( new Function<MPSiteResult, Site>() {
|
||||
public Iterable<Site> findSitesByName(final String siteName) {
|
||||
return FluentIterable.from( model.findSitesByName( siteName ) ).transform( new Function<MPSiteResult, Site>() {
|
||||
@Nullable
|
||||
@Override
|
||||
public Site apply(@Nullable final MPSiteResult site) {
|
||||
@@ -84,7 +85,7 @@ public class ModelUser extends User {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteSite(Site site) {
|
||||
public void deleteSite(final Site site) {
|
||||
if (site instanceof ModelSite) {
|
||||
model.deleteSite(((ModelSite) site).getModel());
|
||||
MPUserFileManager.get().save();
|
||||
|
@@ -14,19 +14,19 @@ public abstract class Site {
|
||||
|
||||
public abstract String getSiteName();
|
||||
|
||||
public abstract void setSiteName(final String siteName);
|
||||
public abstract void setSiteName(String siteName);
|
||||
|
||||
public abstract MPSiteType getSiteType();
|
||||
|
||||
public abstract void setSiteType(final MPSiteType siteType);
|
||||
public abstract void setSiteType(MPSiteType siteType);
|
||||
|
||||
public abstract MasterKey.Version getAlgorithmVersion();
|
||||
|
||||
public abstract void setAlgorithmVersion(final MasterKey.Version algorithmVersion);
|
||||
public abstract void setAlgorithmVersion(MasterKey.Version algorithmVersion);
|
||||
|
||||
public abstract UnsignedInteger getSiteCounter();
|
||||
|
||||
public abstract void setSiteCounter(final UnsignedInteger siteCounter);
|
||||
public abstract void setSiteCounter(UnsignedInteger siteCounter);
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
|
@@ -4,8 +4,7 @@ import com.google.common.base.Preconditions;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.lyndir.masterpassword.MasterKey;
|
||||
import com.lyndir.masterpassword.model.IncorrectMasterPasswordException;
|
||||
import java.util.EnumMap;
|
||||
import java.util.Objects;
|
||||
import java.util.*;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
@@ -16,14 +15,15 @@ import javax.annotation.Nullable;
|
||||
public abstract class User {
|
||||
|
||||
@Nonnull
|
||||
private final EnumMap<MasterKey.Version, MasterKey> keyByVersion = Maps.newEnumMap( MasterKey.Version.class );
|
||||
private final Map<MasterKey.Version, MasterKey> keyByVersion = Maps.newEnumMap( MasterKey.Version.class );
|
||||
|
||||
public abstract String getFullName();
|
||||
|
||||
@Nullable
|
||||
protected abstract char[] getMasterPassword();
|
||||
|
||||
public abstract void authenticate(final char[] masterPassword)
|
||||
@SuppressWarnings("MethodCanBeVariableArityMethod")
|
||||
public abstract void authenticate(char[] masterPassword)
|
||||
throws IncorrectMasterPasswordException;
|
||||
|
||||
public int getAvatar() {
|
||||
@@ -35,7 +35,7 @@ public abstract class User {
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public MasterKey getKey(MasterKey.Version algorithmVersion) {
|
||||
public MasterKey getKey(final MasterKey.Version algorithmVersion) {
|
||||
char[] masterPassword = Preconditions.checkNotNull( getMasterPassword(), "User is not authenticated: " + getFullName() );
|
||||
|
||||
MasterKey key = keyByVersion.get( algorithmVersion );
|
||||
@@ -47,26 +47,26 @@ public abstract class User {
|
||||
return key;
|
||||
}
|
||||
|
||||
protected void putKey(MasterKey masterKey) {
|
||||
protected void putKey(final MasterKey masterKey) {
|
||||
MasterKey oldKey = keyByVersion.put( masterKey.getAlgorithmVersion(), masterKey );
|
||||
if (oldKey != null)
|
||||
oldKey.invalidate();
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
for (MasterKey key : keyByVersion.values())
|
||||
for (final MasterKey key : keyByVersion.values())
|
||||
key.invalidate();
|
||||
}
|
||||
|
||||
public abstract Iterable<Site> findSitesByName(final String siteName);
|
||||
public abstract Iterable<Site> findSitesByName(String siteName);
|
||||
|
||||
public abstract void addSite(final Site site);
|
||||
public abstract void addSite(Site site);
|
||||
|
||||
public abstract void deleteSite(final Site site);
|
||||
public abstract void deleteSite(Site site);
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object obj) {
|
||||
return this == obj || obj instanceof User && Objects.equals( getFullName(), ((User) obj).getFullName() );
|
||||
return (this == obj) || ((obj instanceof User) && Objects.equals( getFullName(), ((User) obj).getFullName() ));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -0,0 +1,9 @@
|
||||
/**
|
||||
*
|
||||
* @author lhunath, 15-02-04
|
||||
*/
|
||||
|
||||
@ParametersAreNonnullByDefault
|
||||
package com.lyndir.masterpassword.gui.model;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
@@ -19,17 +19,17 @@ public class AppleGUI extends GUI {
|
||||
application.addAppEventListener( new AppForegroundListener() {
|
||||
|
||||
@Override
|
||||
public void appMovedToBackground(AppEvent.AppForegroundEvent arg0) {
|
||||
public void appMovedToBackground(final AppEvent.AppForegroundEvent arg0) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void appRaisedToForeground(AppEvent.AppForegroundEvent arg0) {
|
||||
public void appRaisedToForeground(final AppEvent.AppForegroundEvent arg0) {
|
||||
open();
|
||||
}
|
||||
} );
|
||||
application.addAppEventListener( new AppReOpenedListener() {
|
||||
@Override
|
||||
public void appReOpened(AppEvent.AppReOpenedEvent arg0) {
|
||||
public void appReOpened(final AppEvent.AppReOpenedEvent arg0) {
|
||||
open();
|
||||
}
|
||||
} );
|
||||
|
@@ -13,11 +13,11 @@ import javax.swing.border.CompoundBorder;
|
||||
*/
|
||||
public abstract class Components {
|
||||
|
||||
public static GradientPanel boxLayout(int axis, Component... components) {
|
||||
public static GradientPanel boxLayout(final int axis, final Component... components) {
|
||||
GradientPanel container = gradientPanel( null, null );
|
||||
// container.setBackground( Color.red );
|
||||
container.setLayout( new BoxLayout( container, axis ) );
|
||||
for (Component component : components)
|
||||
for (final Component component : components)
|
||||
container.add( component );
|
||||
|
||||
return container;
|
||||
@@ -27,7 +27,7 @@ public abstract class Components {
|
||||
return borderPanel( component, border, null );
|
||||
}
|
||||
|
||||
public static GradientPanel borderPanel(final JComponent component, @Nullable final Border border, @Nullable Color background) {
|
||||
public static GradientPanel borderPanel(final JComponent component, @Nullable final Border border, @Nullable final Color background) {
|
||||
GradientPanel box = boxLayout( BoxLayout.LINE_AXIS, component );
|
||||
|
||||
if (border != null)
|
||||
@@ -83,7 +83,7 @@ public abstract class Components {
|
||||
};
|
||||
}
|
||||
|
||||
public static JButton button(String label) {
|
||||
public static JButton button(final String label) {
|
||||
return new JButton( label ) {
|
||||
{
|
||||
setFont( Res.controlFont().deriveFont( 12f ) );
|
||||
@@ -126,18 +126,18 @@ public abstract class Components {
|
||||
};
|
||||
}
|
||||
|
||||
public static JLabel label(@Nullable String label) {
|
||||
public static JLabel label(@Nullable final String label) {
|
||||
return label( label, SwingConstants.LEADING );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param horizontalAlignment One of the following constants
|
||||
* defined in <code>SwingConstants</code>:
|
||||
* <code>LEFT</code>,
|
||||
* <code>CENTER</code>,
|
||||
* <code>RIGHT</code>,
|
||||
* <code>LEADING</code> or
|
||||
* <code>TRAILING</code>.
|
||||
* defined in {@code SwingConstants}:
|
||||
* {@code LEFT},
|
||||
* {@code CENTER},
|
||||
* {@code RIGHT},
|
||||
* {@code LEADING} or
|
||||
* {@code TRAILING}.
|
||||
*/
|
||||
public static JLabel label(@Nullable final String label, final int horizontalAlignment) {
|
||||
return new JLabel( label, horizontalAlignment ) {
|
||||
|
@@ -9,7 +9,6 @@ import java.awt.*;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import javax.swing.*;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
|
||||
/**
|
||||
@@ -20,7 +19,7 @@ public abstract class AuthenticationPanel extends Components.GradientPanel {
|
||||
protected final UnlockFrame unlockFrame;
|
||||
protected final JLabel avatarLabel;
|
||||
|
||||
public AuthenticationPanel(final UnlockFrame unlockFrame) {
|
||||
protected AuthenticationPanel(final UnlockFrame unlockFrame) {
|
||||
super( null, null );
|
||||
this.unlockFrame = unlockFrame;
|
||||
|
||||
@@ -39,7 +38,7 @@ public abstract class AuthenticationPanel extends Components.GradientPanel {
|
||||
avatarLabel.setToolTipText( "The avatar for your user. Click to change it." );
|
||||
}
|
||||
|
||||
protected void updateUser(boolean repack) {
|
||||
protected void updateUser(final boolean repack) {
|
||||
unlockFrame.updateUser( getSelectedUser() );
|
||||
validate();
|
||||
|
||||
@@ -50,7 +49,6 @@ public abstract class AuthenticationPanel extends Components.GradientPanel {
|
||||
@Nullable
|
||||
protected abstract User getSelectedUser();
|
||||
|
||||
@NotNull
|
||||
@Nonnull
|
||||
public abstract char[] getMasterPassword();
|
||||
|
||||
|
@@ -7,10 +7,10 @@ import com.lyndir.masterpassword.gui.util.Components;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.DocumentEvent;
|
||||
import javax.swing.event.DocumentListener;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
|
||||
/**
|
||||
@@ -62,7 +62,7 @@ public class IncognitoAuthenticationPanel extends AuthenticationPanel implements
|
||||
return new IncognitoUser( fullNameField.getText() );
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Nonnull
|
||||
@Override
|
||||
public char[] getMasterPassword() {
|
||||
return masterPasswordField.getPassword();
|
||||
|
@@ -13,12 +13,12 @@ import com.lyndir.masterpassword.model.MPUserFileManager;
|
||||
import com.lyndir.masterpassword.gui.util.Components;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.DocumentEvent;
|
||||
import javax.swing.event.DocumentListener;
|
||||
import javax.swing.plaf.metal.MetalComboBoxEditor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
|
||||
/**
|
||||
@@ -109,7 +109,7 @@ public class ModelAuthenticationPanel extends AuthenticationPanel implements Ite
|
||||
return userField.getModel().getElementAt( selectedIndex );
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Nonnull
|
||||
@Override
|
||||
public char[] getMasterPassword() {
|
||||
return masterPasswordField.getPassword();
|
||||
@@ -175,7 +175,7 @@ public class ModelAuthenticationPanel extends AuthenticationPanel implements Ite
|
||||
masterPasswordField.setText( "" );
|
||||
}
|
||||
|
||||
private ModelUser[] readConfigUsers() {
|
||||
private static ModelUser[] readConfigUsers() {
|
||||
return FluentIterable.from( MPUserFileManager.get().getUsers() ).transform( new Function<MPUser, ModelUser>() {
|
||||
@Nullable
|
||||
@Override
|
||||
|
@@ -28,7 +28,7 @@ import javax.swing.event.*;
|
||||
*/
|
||||
public class PasswordFrame extends JFrame implements DocumentListener {
|
||||
|
||||
private final User user;
|
||||
@SuppressWarnings("FieldCanBeLocal")
|
||||
private final Components.GradientPanel root;
|
||||
private final JTextField siteNameField;
|
||||
private final JButton siteActionButton;
|
||||
@@ -41,13 +41,13 @@ public class PasswordFrame extends JFrame implements DocumentListener {
|
||||
private final JCheckBox maskPasswordField;
|
||||
private final char passwordEchoChar;
|
||||
private final Font passwordEchoFont;
|
||||
private final User user;
|
||||
|
||||
@Nullable
|
||||
private Site currentSite;
|
||||
private boolean updatingUI;
|
||||
|
||||
public PasswordFrame(User user)
|
||||
throws HeadlessException {
|
||||
public PasswordFrame(final User user) {
|
||||
super( "Master Password" );
|
||||
this.user = user;
|
||||
|
||||
@@ -104,7 +104,7 @@ public class PasswordFrame extends JFrame implements DocumentListener {
|
||||
public void actionPerformed(final ActionEvent e) {
|
||||
if (currentSite == null)
|
||||
return;
|
||||
else if (currentSite instanceof ModelSite)
|
||||
if (currentSite instanceof ModelSite)
|
||||
PasswordFrame.this.user.deleteSite( currentSite );
|
||||
else
|
||||
PasswordFrame.this.user.addSite( currentSite );
|
||||
@@ -160,7 +160,7 @@ public class PasswordFrame extends JFrame implements DocumentListener {
|
||||
maskPasswordField.setSelected( true );
|
||||
maskPasswordField.addItemListener( new ItemListener() {
|
||||
@Override
|
||||
public void itemStateChanged(ItemEvent e) {
|
||||
public void itemStateChanged(final ItemEvent e) {
|
||||
updateMask();
|
||||
}
|
||||
} );
|
||||
@@ -203,33 +203,33 @@ public class PasswordFrame extends JFrame implements DocumentListener {
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
private ListenableFuture<String> updatePassword(boolean allowNameCompletion) {
|
||||
private ListenableFuture<String> updatePassword(final boolean allowNameCompletion) {
|
||||
|
||||
final String siteNameQuery = siteNameField.getText();
|
||||
if (updatingUI)
|
||||
return Futures.immediateCancelledFuture();
|
||||
if (siteNameQuery == null || siteNameQuery.isEmpty() || !user.isKeyAvailable()) {
|
||||
if ((siteNameQuery == null) || siteNameQuery.isEmpty() || !user.isKeyAvailable()) {
|
||||
siteActionButton.setVisible( false );
|
||||
tipLabel.setText( null );
|
||||
passwordField.setText( null );
|
||||
return Futures.immediateCancelledFuture();
|
||||
}
|
||||
|
||||
final MPSiteType siteType = siteTypeField.getModel().getElementAt( siteTypeField.getSelectedIndex() );
|
||||
final MasterKey.Version siteVersion = siteVersionField.getItemAt( siteVersionField.getSelectedIndex() );
|
||||
final UnsignedInteger siteCounter = siteCounterModel.getNumber();
|
||||
MPSiteType siteType = siteTypeField.getModel().getElementAt( siteTypeField.getSelectedIndex() );
|
||||
MasterKey.Version siteVersion = siteVersionField.getItemAt( siteVersionField.getSelectedIndex() );
|
||||
UnsignedInteger siteCounter = siteCounterModel.getNumber();
|
||||
|
||||
Iterable<Site> siteResults = user.findSitesByName( siteNameQuery );
|
||||
if (!allowNameCompletion)
|
||||
siteResults = FluentIterable.from( siteResults ).filter( new Predicate<Site>() {
|
||||
@Override
|
||||
public boolean apply(@Nullable Site siteResult) {
|
||||
return siteResult != null && siteNameQuery.equals( siteResult.getSiteName() );
|
||||
public boolean apply(@Nullable final Site siteResult) {
|
||||
return (siteResult != null) && siteNameQuery.equals( siteResult.getSiteName() );
|
||||
}
|
||||
} );
|
||||
final Site site = ifNotNullElse( Iterables.getFirst( siteResults, null ),
|
||||
new IncognitoSite( siteNameQuery, siteType, siteCounter, siteVersion ) );
|
||||
if (currentSite != null && currentSite.getSiteName().equals( site.getSiteName() )) {
|
||||
if ((currentSite != null) && currentSite.getSiteName().equals( site.getSiteName() )) {
|
||||
site.setSiteType( siteType );
|
||||
site.setAlgorithmVersion( siteVersion );
|
||||
site.setSiteCounter( siteCounter );
|
||||
|
@@ -28,22 +28,21 @@ public class UnlockFrame extends JFrame {
|
||||
private AuthenticationPanel authenticationPanel;
|
||||
private Future<?> identiconFuture;
|
||||
private boolean incognito;
|
||||
public User user;
|
||||
private User user;
|
||||
|
||||
public UnlockFrame(final SignInCallback signInCallback)
|
||||
throws HeadlessException {
|
||||
public UnlockFrame(final SignInCallback signInCallback) {
|
||||
super( "Unlock Master Password" );
|
||||
this.signInCallback = signInCallback;
|
||||
|
||||
setDefaultCloseOperation( DISPOSE_ON_CLOSE );
|
||||
addWindowFocusListener( new WindowAdapter() {
|
||||
@Override
|
||||
public void windowGainedFocus(WindowEvent e) {
|
||||
public void windowGainedFocus(final WindowEvent e) {
|
||||
root.setGradientColor( Res.colors().frameBg() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void windowLostFocus(WindowEvent e) {
|
||||
public void windowLostFocus(final WindowEvent e) {
|
||||
root.setGradientColor( Color.RED );
|
||||
}
|
||||
} );
|
||||
@@ -118,7 +117,7 @@ public class UnlockFrame extends JFrame {
|
||||
|
||||
JComponent toolsPanel = Components.boxLayout( BoxLayout.LINE_AXIS, incognitoCheckBox, Box.createGlue() );
|
||||
authenticationContainer.add( toolsPanel );
|
||||
for (JButton button : authenticationPanel.getButtons()) {
|
||||
for (final JButton button : authenticationPanel.getButtons()) {
|
||||
toolsPanel.add( button );
|
||||
button.setBorder( BorderFactory.createEmptyBorder() );
|
||||
button.setMargin( new Insets( 0, 0, 0, 0 ) );
|
||||
@@ -138,7 +137,7 @@ public class UnlockFrame extends JFrame {
|
||||
} );
|
||||
}
|
||||
|
||||
void updateUser(@Nullable User user) {
|
||||
void updateUser(@Nullable final User user) {
|
||||
this.user = user;
|
||||
checkSignIn();
|
||||
}
|
||||
@@ -152,10 +151,10 @@ public class UnlockFrame extends JFrame {
|
||||
SwingUtilities.invokeLater( new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
String fullName = user == null? "": user.getFullName();
|
||||
String fullName = (user == null)? "": user.getFullName();
|
||||
char[] masterPassword = authenticationPanel.getMasterPassword();
|
||||
|
||||
if (fullName.isEmpty() || masterPassword.length == 0) {
|
||||
if (fullName.isEmpty() || (masterPassword.length == 0)) {
|
||||
identiconLabel.setText( " " );
|
||||
return;
|
||||
}
|
||||
@@ -169,9 +168,9 @@ public class UnlockFrame extends JFrame {
|
||||
}
|
||||
}, 300, TimeUnit.MILLISECONDS );
|
||||
|
||||
String fullName = user == null? "": user.getFullName();
|
||||
String fullName = (user == null)? "": user.getFullName();
|
||||
char[] masterPassword = authenticationPanel.getMasterPassword();
|
||||
boolean enabled = !fullName.isEmpty() && masterPassword.length > 0;
|
||||
boolean enabled = !fullName.isEmpty() && (masterPassword.length > 0);
|
||||
signInButton.setEnabled( enabled );
|
||||
|
||||
return enabled;
|
||||
@@ -181,7 +180,7 @@ public class UnlockFrame extends JFrame {
|
||||
if (!checkSignIn())
|
||||
return;
|
||||
|
||||
for (JComponent signInComponent : signInComponents)
|
||||
for (final JComponent signInComponent : signInComponents)
|
||||
signInComponent.setEnabled( false );
|
||||
|
||||
signInButton.setEnabled( false );
|
||||
@@ -208,7 +207,7 @@ public class UnlockFrame extends JFrame {
|
||||
JOptionPane.showMessageDialog( null, e.getLocalizedMessage(), "Sign In Failed", JOptionPane.ERROR_MESSAGE );
|
||||
authenticationPanel.reset();
|
||||
signInButton.setText( "Sign In" );
|
||||
for (JComponent signInComponent : signInComponents)
|
||||
for (final JComponent signInComponent : signInComponents)
|
||||
signInComponent.setEnabled( true );
|
||||
checkSignIn();
|
||||
}
|
||||
|
Reference in New Issue
Block a user