Read avatar from user export and allow user to modify it by clicking the picture.
This commit is contained in:
parent
0fdf894bf0
commit
1bd76dbb61
@ -11,6 +11,7 @@ import javax.swing.*;
|
|||||||
public abstract class AuthenticationPanel extends JPanel {
|
public abstract class AuthenticationPanel extends JPanel {
|
||||||
|
|
||||||
protected final UnlockFrame unlockFrame;
|
protected final UnlockFrame unlockFrame;
|
||||||
|
protected final JLabel avatarLabel;
|
||||||
|
|
||||||
public AuthenticationPanel(final UnlockFrame unlockFrame) {
|
public AuthenticationPanel(final UnlockFrame unlockFrame) {
|
||||||
this.unlockFrame = unlockFrame;
|
this.unlockFrame = unlockFrame;
|
||||||
@ -19,7 +20,7 @@ public abstract class AuthenticationPanel extends JPanel {
|
|||||||
|
|
||||||
// Avatar
|
// Avatar
|
||||||
add( Box.createVerticalGlue() );
|
add( Box.createVerticalGlue() );
|
||||||
add( new JLabel( Res.avatar(0) ) {
|
add( avatarLabel = new JLabel( Res.avatar( 0 ) ) {
|
||||||
@Override
|
@Override
|
||||||
public Dimension getMaximumSize() {
|
public Dimension getMaximumSize() {
|
||||||
return new Dimension( Integer.MAX_VALUE, Integer.MAX_VALUE );
|
return new Dimension( Integer.MAX_VALUE, Integer.MAX_VALUE );
|
||||||
@ -29,14 +30,14 @@ public abstract class AuthenticationPanel extends JPanel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void updateUser(boolean repack) {
|
protected void updateUser(boolean repack) {
|
||||||
unlockFrame.setUser( getUser() );
|
unlockFrame.setUser( getSelectedUser() );
|
||||||
validate();
|
validate();
|
||||||
|
|
||||||
if (repack)
|
if (repack)
|
||||||
unlockFrame.repack();
|
unlockFrame.repack();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract User getUser();
|
protected abstract User getSelectedUser();
|
||||||
|
|
||||||
public Component getFocusComponent() {
|
public Component getFocusComponent() {
|
||||||
return null;
|
return null;
|
||||||
|
@ -62,7 +62,7 @@ public class IncognitoAuthenticationPanel extends AuthenticationPanel implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected User getUser() {
|
protected User getSelectedUser() {
|
||||||
return new IncognitoUser( fullNameField.getText(), new String( masterPasswordField.getPassword() ) );
|
return new IncognitoUser( fullNameField.getText(), new String( masterPasswordField.getPassword() ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,9 +22,21 @@ public class ModelAuthenticationPanel extends AuthenticationPanel implements Ite
|
|||||||
private final JPasswordField masterPasswordField;
|
private final JPasswordField masterPasswordField;
|
||||||
|
|
||||||
public ModelAuthenticationPanel(final UnlockFrame unlockFrame) {
|
public ModelAuthenticationPanel(final UnlockFrame unlockFrame) {
|
||||||
|
super( unlockFrame );
|
||||||
|
|
||||||
|
// Avatar
|
||||||
|
avatarLabel.addMouseListener( new MouseAdapter() {
|
||||||
|
@Override
|
||||||
|
public void mouseClicked(final MouseEvent e) {
|
||||||
|
ModelUser selectedUser = getSelectedUser();
|
||||||
|
if (selectedUser != null) {
|
||||||
|
selectedUser.setAvatar( selectedUser.getAvatar() + 1 );
|
||||||
|
updateUser( false );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} );
|
||||||
|
|
||||||
// User
|
// User
|
||||||
super( unlockFrame );
|
|
||||||
JLabel userLabel = new JLabel( "User:" );
|
JLabel userLabel = new JLabel( "User:" );
|
||||||
userLabel.setAlignmentX( LEFT_ALIGNMENT );
|
userLabel.setAlignmentX( LEFT_ALIGNMENT );
|
||||||
userLabel.setHorizontalAlignment( SwingConstants.CENTER );
|
userLabel.setHorizontalAlignment( SwingConstants.CENTER );
|
||||||
@ -68,9 +80,9 @@ public class ModelAuthenticationPanel extends AuthenticationPanel implements Ite
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void updateUser(boolean repack) {
|
protected void updateUser(boolean repack) {
|
||||||
int selectedIndex = userField.getSelectedIndex();
|
ModelUser selectedUser = getSelectedUser();
|
||||||
if (selectedIndex >= 0) {
|
if (selectedUser != null) {
|
||||||
ModelUser selectedUser = userField.getModel().getElementAt( selectedIndex );
|
avatarLabel.setIcon( Res.avatar( selectedUser.getAvatar() ) );
|
||||||
boolean showPasswordField = !selectedUser.keySaved();
|
boolean showPasswordField = !selectedUser.keySaved();
|
||||||
if (masterPasswordField.isVisible() != showPasswordField) {
|
if (masterPasswordField.isVisible() != showPasswordField) {
|
||||||
masterPasswordLabel.setVisible( showPasswordField );
|
masterPasswordLabel.setVisible( showPasswordField );
|
||||||
@ -83,7 +95,7 @@ public class ModelAuthenticationPanel extends AuthenticationPanel implements Ite
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected User getUser() {
|
protected ModelUser getSelectedUser() {
|
||||||
int selectedIndex = userField.getSelectedIndex();
|
int selectedIndex = userField.getSelectedIndex();
|
||||||
if (selectedIndex < 0)
|
if (selectedIndex < 0)
|
||||||
return null;
|
return null;
|
||||||
|
@ -29,6 +29,16 @@ public class ModelUser extends User {
|
|||||||
return masterPassword;
|
return masterPassword;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getAvatar() {
|
||||||
|
return user.getAvatar();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAvatar(final int avatar) {
|
||||||
|
user.setAvatar( avatar % Res.avatars() );
|
||||||
|
MPUserFileManager.get().save();
|
||||||
|
}
|
||||||
|
|
||||||
public void setMasterPassword(final String masterPassword) {
|
public void setMasterPassword(final String masterPassword) {
|
||||||
this.masterPassword = masterPassword;
|
this.masterPassword = masterPassword;
|
||||||
}
|
}
|
||||||
@ -39,8 +49,7 @@ public class ModelUser extends User {
|
|||||||
if (!user.hasKeyID()) {
|
if (!user.hasKeyID()) {
|
||||||
user.setKeyID( key.getKeyID() );
|
user.setKeyID( key.getKeyID() );
|
||||||
MPUserFileManager.get().save();
|
MPUserFileManager.get().save();
|
||||||
}
|
} else if (!user.hasKeyID( key.getKeyID() ))
|
||||||
else if (!user.hasKeyID( key.getKeyID() ))
|
|
||||||
throw new IllegalStateException( strf( "Incorrect master password for user: %s", getFullName() ) );
|
throw new IllegalStateException( strf( "Incorrect master password for user: %s", getFullName() ) );
|
||||||
|
|
||||||
return key;
|
return key;
|
||||||
|
@ -54,7 +54,11 @@ public abstract class Res {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Icon avatar(final int index) {
|
public static Icon avatar(final int index) {
|
||||||
return new RetinaIcon( Resources.getResource( strf( "media/avatar-%d@2x.png", index ) ) );
|
return new RetinaIcon( Resources.getResource( strf( "media/avatar-%d@2x.png", index % avatars() ) ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int avatars() {
|
||||||
|
return 19;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Font sourceCodeProBlack() {
|
public static Font sourceCodeProBlack() {
|
||||||
@ -119,7 +123,7 @@ public abstract class Res {
|
|||||||
|
|
||||||
private static final class RetinaIcon extends ImageIcon {
|
private static final class RetinaIcon extends ImageIcon {
|
||||||
|
|
||||||
private static final Pattern scalePattern = Pattern.compile(".*@(\\d+)x.[^.]+$");
|
private static final Pattern scalePattern = Pattern.compile( ".*@(\\d+)x.[^.]+$" );
|
||||||
|
|
||||||
private final float scale;
|
private final float scale;
|
||||||
|
|
||||||
|
@ -17,6 +17,10 @@ public abstract class User {
|
|||||||
|
|
||||||
protected abstract String getMasterPassword();
|
protected abstract String getMasterPassword();
|
||||||
|
|
||||||
|
public int getAvatar() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean hasKey() {
|
public boolean hasKey() {
|
||||||
String masterPassword = getMasterPassword();
|
String masterPassword = getMasterPassword();
|
||||||
return key != null || (masterPassword != null && !masterPassword.isEmpty());
|
return key != null || (masterPassword != null && !masterPassword.isEmpty());
|
||||||
|
Loading…
Reference in New Issue
Block a user