Merge branch 'master' of github.com:Lyndir/MasterPassword
This commit is contained in:
commit
300a04f5c7
1
.idea/encodings.xml
Normal file → Executable file
1
.idea/encodings.xml
Normal file → Executable file
@ -8,3 +8,4 @@
|
||||
<file url="file://$PROJECT_DIR$/MasterPassword/Java/masterpassword-model" charset="UTF-8" />
|
||||
</component>
|
||||
</project>
|
||||
|
||||
|
4
MasterPassword/Java/masterpassword-gui/src/main/java/com/lyndir/masterpassword/gui/IncognitoUser.java
Normal file → Executable file
4
MasterPassword/Java/masterpassword-gui/src/main/java/com/lyndir/masterpassword/gui/IncognitoUser.java
Normal file → Executable file
@ -41,4 +41,8 @@ public class IncognitoUser extends User {
|
||||
@Override
|
||||
public void addSite(final Site site) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteSite(Site site) {
|
||||
}
|
||||
}
|
||||
|
4
MasterPassword/Java/masterpassword-gui/src/main/java/com/lyndir/masterpassword/gui/ModelSite.java
Normal file → Executable file
4
MasterPassword/Java/masterpassword-gui/src/main/java/com/lyndir/masterpassword/gui/ModelSite.java
Normal file → Executable file
@ -16,6 +16,10 @@ public class ModelSite extends Site {
|
||||
this.model = result.getSite();
|
||||
}
|
||||
|
||||
public MPSite getModel() {
|
||||
return model;
|
||||
}
|
||||
|
||||
public String getSiteName() {
|
||||
return model.getSiteName();
|
||||
}
|
||||
|
12
MasterPassword/Java/masterpassword-gui/src/main/java/com/lyndir/masterpassword/gui/ModelUser.java
Normal file → Executable file
12
MasterPassword/Java/masterpassword-gui/src/main/java/com/lyndir/masterpassword/gui/ModelUser.java
Normal file → Executable file
@ -67,8 +67,8 @@ public class ModelUser extends User {
|
||||
return FluentIterable.from( model.findSitesByName( query ) ).transform( new Function<MPSiteResult, Site>() {
|
||||
@Nullable
|
||||
@Override
|
||||
public Site apply(@Nullable final MPSiteResult result) {
|
||||
return new ModelSite( Preconditions.checkNotNull( result ) );
|
||||
public Site apply(@Nullable final MPSiteResult site) {
|
||||
return new ModelSite( Preconditions.checkNotNull( site ) );
|
||||
}
|
||||
} );
|
||||
}
|
||||
@ -80,6 +80,14 @@ public class ModelUser extends User {
|
||||
MPUserFileManager.get().save();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteSite(Site site) {
|
||||
if (site instanceof ModelSite) {
|
||||
model.deleteSite(((ModelSite) site).getModel());
|
||||
MPUserFileManager.get().save();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean keySaved() {
|
||||
// TODO
|
||||
return false;
|
||||
|
58
MasterPassword/Java/masterpassword-gui/src/main/java/com/lyndir/masterpassword/gui/PasswordFrame.java
Normal file → Executable file
58
MasterPassword/Java/masterpassword-gui/src/main/java/com/lyndir/masterpassword/gui/PasswordFrame.java
Normal file → Executable file
@ -1,9 +1,13 @@
|
||||
package com.lyndir.masterpassword.gui;
|
||||
|
||||
import static com.lyndir.lhunath.opal.system.util.ObjectUtils.ifNotNullElse;
|
||||
import static com.lyndir.lhunath.opal.system.util.StringUtils.*;
|
||||
|
||||
import com.google.common.collect.FluentIterable;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.util.concurrent.*;
|
||||
import com.lyndir.lhunath.opal.system.util.NNSupplier;
|
||||
import com.lyndir.lhunath.opal.system.util.PredicateNN;
|
||||
import com.lyndir.masterpassword.*;
|
||||
import com.lyndir.masterpassword.gui.util.Components;
|
||||
import java.awt.*;
|
||||
@ -24,7 +28,7 @@ public class PasswordFrame extends JFrame implements DocumentListener {
|
||||
private final User user;
|
||||
private final Components.GradientPanel root;
|
||||
private final JTextField siteNameField;
|
||||
private final JButton siteAddButton;
|
||||
private final JButton siteActionButton;
|
||||
private final JComboBox<MPSiteType> siteTypeField;
|
||||
private final JComboBox<MasterKey.Version> siteVersionField;
|
||||
private final JSpinner siteCounterField;
|
||||
@ -33,8 +37,10 @@ public class PasswordFrame extends JFrame implements DocumentListener {
|
||||
private final JCheckBox maskPasswordField;
|
||||
private final char passwordEchoChar;
|
||||
private final Font passwordEchoFont;
|
||||
private boolean updatingUI;
|
||||
|
||||
@Nullable
|
||||
private Site currentSite;
|
||||
private boolean updatingUI;
|
||||
|
||||
public PasswordFrame(User user)
|
||||
throws HeadlessException {
|
||||
@ -61,12 +67,12 @@ public class PasswordFrame extends JFrame implements DocumentListener {
|
||||
sitePanel.add(Components.label("Site Name:"));
|
||||
JComponent siteControls = Components.boxLayout( BoxLayout.LINE_AXIS, //
|
||||
siteNameField = Components.textField(), Components.stud(),
|
||||
siteAddButton = Components.button( "Add Site" ) );
|
||||
siteActionButton = Components.button( "Add Site" ) );
|
||||
siteNameField.getDocument().addDocumentListener(this);
|
||||
siteNameField.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent e) {
|
||||
Futures.addCallback( updatePassword(), new FutureCallback<String>() {
|
||||
Futures.addCallback(updatePassword(true), new FutureCallback<String>() {
|
||||
@Override
|
||||
public void onSuccess(@Nullable final String sitePassword) {
|
||||
StringSelection clipboardContents = new StringSelection(sitePassword);
|
||||
@ -89,12 +95,15 @@ public class PasswordFrame extends JFrame implements DocumentListener {
|
||||
});
|
||||
}
|
||||
});
|
||||
siteAddButton.setVisible( false );
|
||||
siteAddButton.addActionListener( new ActionListener() {
|
||||
siteActionButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent e) {
|
||||
if (currentSite instanceof ModelSite)
|
||||
PasswordFrame.this.user.deleteSite(currentSite);
|
||||
else
|
||||
PasswordFrame.this.user.addSite(currentSite);
|
||||
siteAddButton.setVisible( false );
|
||||
|
||||
updatePassword(true);
|
||||
}
|
||||
});
|
||||
sitePanel.add( siteControls );
|
||||
@ -115,7 +124,7 @@ public class PasswordFrame extends JFrame implements DocumentListener {
|
||||
siteTypeField.addItemListener( new ItemListener() {
|
||||
@Override
|
||||
public void itemStateChanged(final ItemEvent e) {
|
||||
updatePassword();
|
||||
updatePassword(true);
|
||||
}
|
||||
} );
|
||||
|
||||
@ -125,7 +134,7 @@ public class PasswordFrame extends JFrame implements DocumentListener {
|
||||
siteVersionField.addItemListener( new ItemListener() {
|
||||
@Override
|
||||
public void itemStateChanged(final ItemEvent e) {
|
||||
updatePassword();
|
||||
updatePassword(true);
|
||||
}
|
||||
} );
|
||||
|
||||
@ -134,7 +143,7 @@ public class PasswordFrame extends JFrame implements DocumentListener {
|
||||
siteCounterField.addChangeListener( new ChangeListener() {
|
||||
@Override
|
||||
public void stateChanged(final ChangeEvent e) {
|
||||
updatePassword();
|
||||
updatePassword(true);
|
||||
}
|
||||
} );
|
||||
|
||||
@ -186,12 +195,13 @@ public class PasswordFrame extends JFrame implements DocumentListener {
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
private ListenableFuture<String> updatePassword() {
|
||||
private ListenableFuture<String> updatePassword(boolean allowNameCompletion) {
|
||||
|
||||
final String siteNameQuery = siteNameField.getText();
|
||||
if (updatingUI)
|
||||
return Futures.immediateCancelledFuture();
|
||||
if (siteNameQuery == null || siteNameQuery.isEmpty() || !user.isKeyAvailable()) {
|
||||
siteActionButton.setVisible(false);
|
||||
tipLabel.setText( null );
|
||||
passwordField.setText( null );
|
||||
return Futures.immediateCancelledFuture();
|
||||
@ -200,11 +210,18 @@ public class PasswordFrame extends JFrame implements DocumentListener {
|
||||
final MPSiteType siteType = siteTypeField.getModel().getElementAt(siteTypeField.getSelectedIndex());
|
||||
final MasterKey.Version siteVersion = siteVersionField.getItemAt(siteVersionField.getSelectedIndex());
|
||||
final int siteCounter = (Integer) siteCounterField.getValue();
|
||||
final Site site = currentSite != null && currentSite.getSiteName().equals( siteNameQuery )? currentSite
|
||||
: Iterables.getFirst( user.findSitesByName( siteNameQuery ),
|
||||
|
||||
Iterable<Site> siteResults = user.findSitesByName(siteNameQuery);
|
||||
if (!allowNameCompletion)
|
||||
siteResults = FluentIterable.from(siteResults).filter(new PredicateNN<Site>() {
|
||||
@Override
|
||||
public boolean apply(Site input) {
|
||||
return siteNameQuery.equals(input.getSiteName());
|
||||
}
|
||||
});
|
||||
final Site site = Iterables.getFirst(siteResults,
|
||||
new IncognitoSite(siteNameQuery, siteType, siteCounter, siteVersion) );
|
||||
assert site != null;
|
||||
if (site == currentSite) {
|
||||
if (currentSite != null && site.getSiteName().equals(currentSite.getSiteName())) {
|
||||
site.setSiteType( siteType );
|
||||
site.setAlgorithmVersion( siteVersion );
|
||||
site.setSiteCounter( siteCounter );
|
||||
@ -226,7 +243,11 @@ public class PasswordFrame extends JFrame implements DocumentListener {
|
||||
public void run() {
|
||||
updatingUI = true;
|
||||
currentSite = site;
|
||||
siteAddButton.setVisible( user instanceof ModelUser && !(currentSite instanceof ModelSite) );
|
||||
siteActionButton.setVisible(user instanceof ModelUser);
|
||||
if (currentSite instanceof ModelSite)
|
||||
siteActionButton.setText("Delete Site");
|
||||
else
|
||||
siteActionButton.setText("Add Site");
|
||||
siteTypeField.setSelectedItem(currentSite.getSiteType());
|
||||
siteVersionField.setSelectedItem( currentSite.getAlgorithmVersion() );
|
||||
siteCounterField.setValue( currentSite.getSiteCounter() );
|
||||
@ -251,15 +272,16 @@ public class PasswordFrame extends JFrame implements DocumentListener {
|
||||
|
||||
@Override
|
||||
public void insertUpdate(final DocumentEvent e) {
|
||||
updatePassword();
|
||||
updatePassword(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeUpdate(final DocumentEvent e) {
|
||||
updatePassword(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void changedUpdate(final DocumentEvent e) {
|
||||
updatePassword();
|
||||
updatePassword(true);
|
||||
}
|
||||
}
|
||||
|
2
MasterPassword/Java/masterpassword-gui/src/main/java/com/lyndir/masterpassword/gui/User.java
Normal file → Executable file
2
MasterPassword/Java/masterpassword-gui/src/main/java/com/lyndir/masterpassword/gui/User.java
Normal file → Executable file
@ -62,6 +62,8 @@ public abstract class User {
|
||||
|
||||
public abstract void addSite(final Site site);
|
||||
|
||||
public abstract void deleteSite(final Site site);
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object obj) {
|
||||
return this == obj || obj instanceof User && Objects.equals( getFullName(), ((User) obj).getFullName() );
|
||||
|
4
MasterPassword/Java/masterpassword-model/src/main/java/com/lyndir/masterpassword/model/MPUser.java
Normal file → Executable file
4
MasterPassword/Java/masterpassword-model/src/main/java/com/lyndir/masterpassword/model/MPUser.java
Normal file → Executable file
@ -59,6 +59,10 @@ public class MPUser implements Comparable<MPUser> {
|
||||
sites.add( site );
|
||||
}
|
||||
|
||||
public void deleteSite(final MPSite site) {
|
||||
sites.remove( site );
|
||||
}
|
||||
|
||||
public String getFullName() {
|
||||
return fullName;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user