From 77bee803b8fd92ce890146af81059006c8511227 Mon Sep 17 00:00:00 2001 From: Maarten Billemont Date: Fri, 10 Mar 2017 11:31:22 -0500 Subject: [PATCH] Fixes #138- delays identicon update to avoid leaking interactive keyboard input. --- README.md | 2 +- core/java/algorithm/build.gradle | 13 +++--- core/java/model/build.gradle | 1 - core/java/tests/build.gradle | 6 ++- .../lyndir/masterpassword/MasterKeyTest.java | 6 +-- gradle/.idea/runConfigurations/Android.xml | 30 +++++++++++++ gradle/.idea/runConfigurations/GUI.xml | 16 +++++++ gradle/.idea/runConfigurations/Tests.xml | 29 +++++++++++++ gradle/build.gradle | 8 ++-- platform-android/build.gradle | 29 +++++++------ .../com/lyndir/masterpassword/gui/GUI.java | 3 ++ .../com/lyndir/masterpassword/gui/Res.java | 34 +++++++++------ .../gui/{ => model}/IncognitoSite.java | 2 +- .../gui/{ => model}/IncognitoUser.java | 2 +- .../gui/{ => model}/ModelSite.java | 2 +- .../gui/{ => model}/ModelUser.java | 5 ++- .../masterpassword/gui/{ => model}/Site.java | 2 +- .../masterpassword/gui/{ => model}/User.java | 2 +- .../gui/platform/mac/AppleGUI.java | 4 +- .../gui/{ => view}/AuthenticationPanel.java | 6 ++- .../IncognitoAuthenticationPanel.java | 5 ++- .../{ => view}/ModelAuthenticationPanel.java | 4 +- .../gui/{ => view}/PasswordFrame.java | 4 +- .../gui/{ => view}/UnlockFrame.java | 43 ++++++++++++++----- 24 files changed, 188 insertions(+), 70 deletions(-) create mode 100644 gradle/.idea/runConfigurations/Android.xml create mode 100644 gradle/.idea/runConfigurations/GUI.xml create mode 100644 gradle/.idea/runConfigurations/Tests.xml rename platform-independent/gui-java/src/main/java/com/lyndir/masterpassword/gui/{ => model}/IncognitoSite.java (97%) rename platform-independent/gui-java/src/main/java/com/lyndir/masterpassword/gui/{ => model}/IncognitoUser.java (95%) rename platform-independent/gui-java/src/main/java/com/lyndir/masterpassword/gui/{ => model}/ModelSite.java (97%) rename platform-independent/gui-java/src/main/java/com/lyndir/masterpassword/gui/{ => model}/ModelUser.java (94%) rename platform-independent/gui-java/src/main/java/com/lyndir/masterpassword/gui/{ => model}/Site.java (95%) rename platform-independent/gui-java/src/main/java/com/lyndir/masterpassword/gui/{ => model}/User.java (98%) rename platform-independent/gui-java/src/main/java/com/lyndir/masterpassword/gui/{ => view}/AuthenticationPanel.java (89%) rename platform-independent/gui-java/src/main/java/com/lyndir/masterpassword/gui/{ => view}/IncognitoAuthenticationPanel.java (92%) rename platform-independent/gui-java/src/main/java/com/lyndir/masterpassword/gui/{ => view}/ModelAuthenticationPanel.java (98%) rename platform-independent/gui-java/src/main/java/com/lyndir/masterpassword/gui/{ => view}/PasswordFrame.java (99%) rename platform-independent/gui-java/src/main/java/com/lyndir/masterpassword/gui/{ => view}/UnlockFrame.java (83%) diff --git a/README.md b/README.md index 0581a1df..3fa5688b 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ To skip the intro and go straight to the information on how to use the code, [cl Master Password is available for [📲 iOS](https://itunes.apple.com/app/id510296984), [🖥 macOS](https://ssl.masterpasswordapp.com/masterpassword-mac.zip), [📲 Android](https://ssl.masterpasswordapp.com/masterpassword-android.apk), [🖥 Desktop](https://ssl.masterpasswordapp.com/masterpassword-gui.jar), and [⌨ Console](https://ssl.masterpasswordapp.com/masterpassword-cli.tar.gz). -Master Password is also available from the following package managers: [mac OS: Homebrew](https://brew.sh/). Get in touch if you are interested in adding Master Password to any other package managers. +Master Password is also available from the following package managers: [macOS: Homebrew](https://brew.sh/). Get in touch if you are interested in adding Master Password to any other package managers. ## What is a password? diff --git a/core/java/algorithm/build.gradle b/core/java/algorithm/build.gradle index 6e5b3f9f..c37d3236 100644 --- a/core/java/algorithm/build.gradle +++ b/core/java/algorithm/build.gradle @@ -1,12 +1,15 @@ -apply plugin: 'java' +plugins { + id 'java' +} description = 'Master Password Algorithm Implementation' dependencies { - compile( 'com.lyndir.lhunath.opal:opal-system:1.6-p10' ) { + compile (group: 'com.lyndir.lhunath.opal', name: 'opal-system', version: '1.6-p10') { exclude( module: 'joda-time' ) } - compile 'com.lambdaworks:scrypt:1.4.0' - compile 'org.jetbrains:annotations:13.0' - compile 'com.google.code.findbugs:jsr305:3.0.1' + + compile group: 'com.lambdaworks', name: 'scrypt', version: '1.4.0' + compile group: 'org.jetbrains', name: 'annotations', version: '13.0' + compile group: 'com.google.code.findbugs', name: 'jsr305', version: '3.0.1' } diff --git a/core/java/model/build.gradle b/core/java/model/build.gradle index 81c42ced..190a6ff0 100644 --- a/core/java/model/build.gradle +++ b/core/java/model/build.gradle @@ -9,7 +9,6 @@ dependencies { compile project(':masterpassword:algorithm') compile group: 'joda-time', name: 'joda-time', version:'2.4' - compileOnly group: 'com.google.auto.value', name: 'auto-value', version: '1.2' apt group: 'com.google.auto.value', name: 'auto-value', version: '1.2' diff --git a/core/java/tests/build.gradle b/core/java/tests/build.gradle index e83ecc3a..317c4824 100644 --- a/core/java/tests/build.gradle +++ b/core/java/tests/build.gradle @@ -1,9 +1,11 @@ -apply plugin: 'java' +plugins { + id 'java' +} description = 'Master Password Test Suite' dependencies { - compile project(':masterpassword:algorithm') + compile project(':masterpassword:algorithm') testCompile group: 'org.testng', name: 'testng', version:'6.8.5' testCompile group: 'ch.qos.logback', name: 'logback-classic', version:'1.1.2' diff --git a/core/java/tests/src/test/java/com/lyndir/masterpassword/MasterKeyTest.java b/core/java/tests/src/test/java/com/lyndir/masterpassword/MasterKeyTest.java index 89b5bea1..1966aefd 100644 --- a/core/java/tests/src/test/java/com/lyndir/masterpassword/MasterKeyTest.java +++ b/core/java/tests/src/test/java/com/lyndir/masterpassword/MasterKeyTest.java @@ -2,14 +2,10 @@ package com.lyndir.masterpassword; import static org.testng.Assert.*; -import com.google.common.io.Resources; import com.lyndir.lhunath.opal.system.CodeUtils; import com.lyndir.lhunath.opal.system.logging.Logger; import com.lyndir.lhunath.opal.system.util.NNFunctionNN; -import com.lyndir.lhunath.opal.system.util.StringUtils; -import java.net.URL; import javax.annotation.Nonnull; -import javax.xml.bind.JAXBContext; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; @@ -88,7 +84,7 @@ public class MasterKeyTest { masterKey.encode( defaultCase.getSiteName(), defaultCase.getSiteType(), defaultCase.getSiteCounter(), defaultCase.getSiteVariant(), defaultCase.getSiteContext() ); - assertTrue( false, "[testInvalidate] Master key should have been invalidated, but was still usable." ); + fail( "[testInvalidate] Master key should have been invalidated, but was still usable." ); } catch (IllegalStateException ignored) { } diff --git a/gradle/.idea/runConfigurations/Android.xml b/gradle/.idea/runConfigurations/Android.xml new file mode 100644 index 00000000..0386e12b --- /dev/null +++ b/gradle/.idea/runConfigurations/Android.xml @@ -0,0 +1,30 @@ + + + + + \ No newline at end of file diff --git a/gradle/.idea/runConfigurations/GUI.xml b/gradle/.idea/runConfigurations/GUI.xml new file mode 100644 index 00000000..aac22091 --- /dev/null +++ b/gradle/.idea/runConfigurations/GUI.xml @@ -0,0 +1,16 @@ + + + + \ No newline at end of file diff --git a/gradle/.idea/runConfigurations/Tests.xml b/gradle/.idea/runConfigurations/Tests.xml new file mode 100644 index 00000000..cf544362 --- /dev/null +++ b/gradle/.idea/runConfigurations/Tests.xml @@ -0,0 +1,29 @@ + + + + + + \ No newline at end of file diff --git a/gradle/build.gradle b/gradle/build.gradle index 611ba02c..4a29c0af 100644 --- a/gradle/build.gradle +++ b/gradle/build.gradle @@ -1,12 +1,12 @@ -allprojects { +allprojects { //apply plugin: 'findbugs' group = 'com.lyndir.masterpassword' version = 'GIT-SNAPSHOT' tasks.withType(JavaCompile) { - sourceCompatibility = "1.7" - targetCompatibility = "1.7" + sourceCompatibility = '1.7' + targetCompatibility = '1.7' } tasks.withType(FindBugs) { reports { @@ -29,6 +29,6 @@ buildscript { subprojects { repositories { mavenCentral() - maven { url "http://maven.lyndir.com" } + maven { url 'http://maven.lyndir.com' } } } diff --git a/platform-android/build.gradle b/platform-android/build.gradle index dea99a76..7fc8bdfd 100644 --- a/platform-android/build.gradle +++ b/platform-android/build.gradle @@ -2,44 +2,45 @@ apply plugin: 'com.android.application' android { compileSdkVersion 25 - buildToolsVersion "25.0.0" + buildToolsVersion '25.0.0' compileOptions { sourceCompatibility JavaVersion.VERSION_1_7 targetCompatibility JavaVersion.VERSION_1_7 } + defaultConfig { - applicationId "com.lyndir.masterpassword" + applicationId 'com.lyndir.masterpassword' minSdkVersion 19 targetSdkVersion 25 versionCode 20401 - versionName "2.4.1" + versionName '2.4.1' } + // release with: STORE_PW=$(mpw masterpassword.keystore) KEY_PW=$(mpw masterpassword-android) gradle assembleRelease signingConfigs { release { - storeFile file('masterpassword.keystore') - storePassword System.getenv('STORE_PW') + storeFile file( 'masterpassword.keystore' ) + storePassword System.getenv( 'STORE_PW' ) keyAlias 'masterpassword-android' - keyPassword System.getenv('KEY_PW') + keyPassword System.getenv( 'KEY_PW' ) } } buildTypes { release { - if (System.getenv('STORE_PW') != null) + if (System.getenv( 'STORE_PW' ) != null) signingConfig signingConfigs.release } } } dependencies { - compile project( ':masterpassword:algorithm' ) - compile project( ':masterpassword:tests' ) + compile project( ':masterpassword:algorithm' ) + compile project( ':masterpassword:tests' ) - // Android dependencies - compile 'org.slf4j:slf4j-android:1.7.13-underscore' - compile 'com.jakewharton:butterknife:8.5.1' - annotationProcessor 'com.jakewharton:butterknife-compiler:8.5.1' - compile files('libs/scrypt-1.4.0-native.jar') + compile group: 'org.slf4j', name: 'slf4j-android', version:'1.7.13-underscore' + compile group: 'com.jakewharton', name: 'butterknife', version:'8.5.1' + annotationProcessor group: 'com.jakewharton', name: 'butterknife-compiler', version:'8.5.1' + compile files( 'libs/scrypt-1.4.0-native.jar' ) } diff --git a/platform-independent/gui-java/src/main/java/com/lyndir/masterpassword/gui/GUI.java b/platform-independent/gui-java/src/main/java/com/lyndir/masterpassword/gui/GUI.java index 2b4a6e10..3f99082d 100644 --- a/platform-independent/gui-java/src/main/java/com/lyndir/masterpassword/gui/GUI.java +++ b/platform-independent/gui-java/src/main/java/com/lyndir/masterpassword/gui/GUI.java @@ -22,6 +22,9 @@ import com.google.common.io.*; import com.lyndir.lhunath.opal.system.logging.Logger; import com.lyndir.lhunath.opal.system.util.TypeUtils; +import com.lyndir.masterpassword.gui.model.User; +import com.lyndir.masterpassword.gui.view.PasswordFrame; +import com.lyndir.masterpassword.gui.view.UnlockFrame; import java.io.*; import java.net.URI; import java.net.URL; diff --git a/platform-independent/gui-java/src/main/java/com/lyndir/masterpassword/gui/Res.java b/platform-independent/gui-java/src/main/java/com/lyndir/masterpassword/gui/Res.java index d0903dd5..cd2f3aa3 100644 --- a/platform-independent/gui-java/src/main/java/com/lyndir/masterpassword/gui/Res.java +++ b/platform-independent/gui-java/src/main/java/com/lyndir/masterpassword/gui/Res.java @@ -30,12 +30,16 @@ import javax.swing.*; */ public abstract class Res { - private static final WeakHashMap executorByWindow = new WeakHashMap<>(); - private static final Logger logger = Logger.get( Res.class ); - private static final Colors colors = new Colors(); + private static final WeakHashMap executorByWindow = new WeakHashMap<>(); + private static final Logger logger = Logger.get( Res.class ); + private static final Colors colors = new Colors(); public static Future execute(final Window host, final Runnable job) { - return getExecutor( host ).submit( new Runnable() { + return schedule( host, job, 0, TimeUnit.MILLISECONDS ); + } + + public static Future schedule(final Window host, final Runnable job, final long delay, final TimeUnit timeUnit) { + return getExecutor( host ).schedule( new Runnable() { @Override public void run() { try { @@ -45,12 +49,16 @@ public abstract class Res { logger.err( t, "Unexpected: %s", t.getLocalizedMessage() ); } } - } ); + }, delay, timeUnit ); } public static ListenableFuture execute(final Window host, final Callable job) { - ExecutorService executor = getExecutor( host ); - return JdkFutureAdapters.listenInPoolThread( executor.submit( new Callable() { + return schedule( host, job, 0, TimeUnit.MILLISECONDS ); + } + + public static ListenableFuture schedule(final Window host, final Callable job, final long delay, final TimeUnit timeUnit) { + ScheduledExecutorService executor = getExecutor( host ); + return JdkFutureAdapters.listenInPoolThread( executor.schedule( new Callable() { @Override public V call() throws Exception { @@ -62,14 +70,14 @@ public abstract class Res { throw t; } } - } ), executor ); + }, delay, timeUnit ), executor ); } - private static ExecutorService getExecutor(final Window host) { - ExecutorService executor = executorByWindow.get( host ); + private static ScheduledExecutorService getExecutor(final Window host) { + ScheduledExecutorService executor = executorByWindow.get( host ); if (executor == null) { - executorByWindow.put( host, executor = Executors.newSingleThreadExecutor() ); + executorByWindow.put( host, executor = Executors.newSingleThreadScheduledExecutor() ); host.addWindowListener( new WindowAdapter() { @Override @@ -252,8 +260,8 @@ public abstract class Res { public static class Colors { - private final Color frameBg = Color.decode( "#5A5D6B" ); - private final Color controlBg = Color.decode( "#ECECEC" ); + private final Color frameBg = Color.decode( "#5A5D6B" ); + private final Color controlBg = Color.decode( "#ECECEC" ); private final Color controlBorder = Color.decode( "#BFBFBF" ); public Color frameBg() { diff --git a/platform-independent/gui-java/src/main/java/com/lyndir/masterpassword/gui/IncognitoSite.java b/platform-independent/gui-java/src/main/java/com/lyndir/masterpassword/gui/model/IncognitoSite.java similarity index 97% rename from platform-independent/gui-java/src/main/java/com/lyndir/masterpassword/gui/IncognitoSite.java rename to platform-independent/gui-java/src/main/java/com/lyndir/masterpassword/gui/model/IncognitoSite.java index 493e6ade..49322203 100644 --- a/platform-independent/gui-java/src/main/java/com/lyndir/masterpassword/gui/IncognitoSite.java +++ b/platform-independent/gui-java/src/main/java/com/lyndir/masterpassword/gui/model/IncognitoSite.java @@ -1,4 +1,4 @@ -package com.lyndir.masterpassword.gui; +package com.lyndir.masterpassword.gui.model; import com.google.common.primitives.UnsignedInteger; import com.lyndir.masterpassword.MPSiteType; diff --git a/platform-independent/gui-java/src/main/java/com/lyndir/masterpassword/gui/IncognitoUser.java b/platform-independent/gui-java/src/main/java/com/lyndir/masterpassword/gui/model/IncognitoUser.java similarity index 95% rename from platform-independent/gui-java/src/main/java/com/lyndir/masterpassword/gui/IncognitoUser.java rename to platform-independent/gui-java/src/main/java/com/lyndir/masterpassword/gui/model/IncognitoUser.java index d4f4c7e4..83318ed1 100755 --- a/platform-independent/gui-java/src/main/java/com/lyndir/masterpassword/gui/IncognitoUser.java +++ b/platform-independent/gui-java/src/main/java/com/lyndir/masterpassword/gui/model/IncognitoUser.java @@ -1,4 +1,4 @@ -package com.lyndir.masterpassword.gui; +package com.lyndir.masterpassword.gui.model; import com.google.common.collect.ImmutableList; import com.lyndir.masterpassword.model.IncorrectMasterPasswordException; diff --git a/platform-independent/gui-java/src/main/java/com/lyndir/masterpassword/gui/ModelSite.java b/platform-independent/gui-java/src/main/java/com/lyndir/masterpassword/gui/model/ModelSite.java similarity index 97% rename from platform-independent/gui-java/src/main/java/com/lyndir/masterpassword/gui/ModelSite.java rename to platform-independent/gui-java/src/main/java/com/lyndir/masterpassword/gui/model/ModelSite.java index 53e1f3ea..488a5f5a 100755 --- a/platform-independent/gui-java/src/main/java/com/lyndir/masterpassword/gui/ModelSite.java +++ b/platform-independent/gui-java/src/main/java/com/lyndir/masterpassword/gui/model/ModelSite.java @@ -1,4 +1,4 @@ -package com.lyndir.masterpassword.gui; +package com.lyndir.masterpassword.gui.model; import com.google.common.primitives.UnsignedInteger; import com.lyndir.masterpassword.MPSiteType; diff --git a/platform-independent/gui-java/src/main/java/com/lyndir/masterpassword/gui/ModelUser.java b/platform-independent/gui-java/src/main/java/com/lyndir/masterpassword/gui/model/ModelUser.java similarity index 94% rename from platform-independent/gui-java/src/main/java/com/lyndir/masterpassword/gui/ModelUser.java rename to platform-independent/gui-java/src/main/java/com/lyndir/masterpassword/gui/model/ModelUser.java index 0d721234..30d555ac 100755 --- a/platform-independent/gui-java/src/main/java/com/lyndir/masterpassword/gui/ModelUser.java +++ b/platform-independent/gui-java/src/main/java/com/lyndir/masterpassword/gui/model/ModelUser.java @@ -1,8 +1,9 @@ -package com.lyndir.masterpassword.gui; +package com.lyndir.masterpassword.gui.model; import com.google.common.base.Function; import com.google.common.base.Preconditions; import com.google.common.collect.FluentIterable; +import com.lyndir.masterpassword.gui.*; import com.lyndir.masterpassword.model.*; import java.util.Arrays; import javax.annotation.Nullable; @@ -43,7 +44,7 @@ public class ModelUser extends User { } public void setAvatar(final int avatar) { - model.setAvatar(avatar % Res.avatars()); + model.setAvatar( avatar % Res.avatars()); MPUserFileManager.get().save(); } diff --git a/platform-independent/gui-java/src/main/java/com/lyndir/masterpassword/gui/Site.java b/platform-independent/gui-java/src/main/java/com/lyndir/masterpassword/gui/model/Site.java similarity index 95% rename from platform-independent/gui-java/src/main/java/com/lyndir/masterpassword/gui/Site.java rename to platform-independent/gui-java/src/main/java/com/lyndir/masterpassword/gui/model/Site.java index b950ab38..cc09851c 100644 --- a/platform-independent/gui-java/src/main/java/com/lyndir/masterpassword/gui/Site.java +++ b/platform-independent/gui-java/src/main/java/com/lyndir/masterpassword/gui/model/Site.java @@ -1,4 +1,4 @@ -package com.lyndir.masterpassword.gui; +package com.lyndir.masterpassword.gui.model; import static com.lyndir.lhunath.opal.system.util.StringUtils.strf; diff --git a/platform-independent/gui-java/src/main/java/com/lyndir/masterpassword/gui/User.java b/platform-independent/gui-java/src/main/java/com/lyndir/masterpassword/gui/model/User.java similarity index 98% rename from platform-independent/gui-java/src/main/java/com/lyndir/masterpassword/gui/User.java rename to platform-independent/gui-java/src/main/java/com/lyndir/masterpassword/gui/model/User.java index e1703876..1355757c 100755 --- a/platform-independent/gui-java/src/main/java/com/lyndir/masterpassword/gui/User.java +++ b/platform-independent/gui-java/src/main/java/com/lyndir/masterpassword/gui/model/User.java @@ -1,4 +1,4 @@ -package com.lyndir.masterpassword.gui; +package com.lyndir.masterpassword.gui.model; import com.google.common.base.Preconditions; import com.google.common.collect.Maps; diff --git a/platform-independent/gui-java/src/main/java/com/lyndir/masterpassword/gui/platform/mac/AppleGUI.java b/platform-independent/gui-java/src/main/java/com/lyndir/masterpassword/gui/platform/mac/AppleGUI.java index 0e6559c6..e5b5c7bd 100644 --- a/platform-independent/gui-java/src/main/java/com/lyndir/masterpassword/gui/platform/mac/AppleGUI.java +++ b/platform-independent/gui-java/src/main/java/com/lyndir/masterpassword/gui/platform/mac/AppleGUI.java @@ -2,8 +2,8 @@ package com.lyndir.masterpassword.gui.platform.mac; import com.apple.eawt.*; import com.lyndir.masterpassword.gui.GUI; -import com.lyndir.masterpassword.gui.PasswordFrame; -import com.lyndir.masterpassword.gui.User; +import com.lyndir.masterpassword.gui.view.PasswordFrame; +import com.lyndir.masterpassword.gui.model.User; import javax.swing.*; diff --git a/platform-independent/gui-java/src/main/java/com/lyndir/masterpassword/gui/AuthenticationPanel.java b/platform-independent/gui-java/src/main/java/com/lyndir/masterpassword/gui/view/AuthenticationPanel.java similarity index 89% rename from platform-independent/gui-java/src/main/java/com/lyndir/masterpassword/gui/AuthenticationPanel.java rename to platform-independent/gui-java/src/main/java/com/lyndir/masterpassword/gui/view/AuthenticationPanel.java index 055cddf1..aceb1274 100644 --- a/platform-independent/gui-java/src/main/java/com/lyndir/masterpassword/gui/AuthenticationPanel.java +++ b/platform-independent/gui-java/src/main/java/com/lyndir/masterpassword/gui/view/AuthenticationPanel.java @@ -1,8 +1,10 @@ -package com.lyndir.masterpassword.gui; +package com.lyndir.masterpassword.gui.view; import com.google.common.collect.ImmutableList; -import com.lyndir.masterpassword.MPIdenticon; +import com.lyndir.masterpassword.gui.Res; +import com.lyndir.masterpassword.gui.model.User; import com.lyndir.masterpassword.gui.util.Components; +import com.lyndir.masterpassword.gui.view.UnlockFrame; import java.awt.*; import javax.annotation.Nonnull; import javax.annotation.Nullable; diff --git a/platform-independent/gui-java/src/main/java/com/lyndir/masterpassword/gui/IncognitoAuthenticationPanel.java b/platform-independent/gui-java/src/main/java/com/lyndir/masterpassword/gui/view/IncognitoAuthenticationPanel.java similarity index 92% rename from platform-independent/gui-java/src/main/java/com/lyndir/masterpassword/gui/IncognitoAuthenticationPanel.java rename to platform-independent/gui-java/src/main/java/com/lyndir/masterpassword/gui/view/IncognitoAuthenticationPanel.java index 8c114bc4..3798f623 100644 --- a/platform-independent/gui-java/src/main/java/com/lyndir/masterpassword/gui/IncognitoAuthenticationPanel.java +++ b/platform-independent/gui-java/src/main/java/com/lyndir/masterpassword/gui/view/IncognitoAuthenticationPanel.java @@ -1,5 +1,8 @@ -package com.lyndir.masterpassword.gui; +package com.lyndir.masterpassword.gui.view; +import com.lyndir.masterpassword.gui.Res; +import com.lyndir.masterpassword.gui.model.IncognitoUser; +import com.lyndir.masterpassword.gui.model.User; import com.lyndir.masterpassword.gui.util.Components; import java.awt.*; import java.awt.event.ActionEvent; diff --git a/platform-independent/gui-java/src/main/java/com/lyndir/masterpassword/gui/ModelAuthenticationPanel.java b/platform-independent/gui-java/src/main/java/com/lyndir/masterpassword/gui/view/ModelAuthenticationPanel.java similarity index 98% rename from platform-independent/gui-java/src/main/java/com/lyndir/masterpassword/gui/ModelAuthenticationPanel.java rename to platform-independent/gui-java/src/main/java/com/lyndir/masterpassword/gui/view/ModelAuthenticationPanel.java index d7bbaf79..61e6b031 100644 --- a/platform-independent/gui-java/src/main/java/com/lyndir/masterpassword/gui/ModelAuthenticationPanel.java +++ b/platform-independent/gui-java/src/main/java/com/lyndir/masterpassword/gui/view/ModelAuthenticationPanel.java @@ -1,4 +1,4 @@ -package com.lyndir.masterpassword.gui; +package com.lyndir.masterpassword.gui.view; import static com.lyndir.lhunath.opal.system.util.StringUtils.strf; @@ -6,6 +6,8 @@ import com.google.common.base.Function; import com.google.common.base.Preconditions; import com.google.common.collect.*; import com.lyndir.lhunath.opal.system.logging.Logger; +import com.lyndir.masterpassword.gui.Res; +import com.lyndir.masterpassword.gui.model.ModelUser; import com.lyndir.masterpassword.model.MPUser; import com.lyndir.masterpassword.model.MPUserFileManager; import com.lyndir.masterpassword.gui.util.Components; diff --git a/platform-independent/gui-java/src/main/java/com/lyndir/masterpassword/gui/PasswordFrame.java b/platform-independent/gui-java/src/main/java/com/lyndir/masterpassword/gui/view/PasswordFrame.java similarity index 99% rename from platform-independent/gui-java/src/main/java/com/lyndir/masterpassword/gui/PasswordFrame.java rename to platform-independent/gui-java/src/main/java/com/lyndir/masterpassword/gui/view/PasswordFrame.java index 6aabcb01..1e6ea749 100755 --- a/platform-independent/gui-java/src/main/java/com/lyndir/masterpassword/gui/PasswordFrame.java +++ b/platform-independent/gui-java/src/main/java/com/lyndir/masterpassword/gui/view/PasswordFrame.java @@ -1,4 +1,4 @@ -package com.lyndir.masterpassword.gui; +package com.lyndir.masterpassword.gui.view; import static com.lyndir.lhunath.opal.system.util.ObjectUtils.ifNotNullElse; import static com.lyndir.lhunath.opal.system.util.StringUtils.*; @@ -9,6 +9,8 @@ import com.google.common.collect.Iterables; import com.google.common.primitives.UnsignedInteger; import com.google.common.util.concurrent.*; import com.lyndir.masterpassword.*; +import com.lyndir.masterpassword.gui.Res; +import com.lyndir.masterpassword.gui.model.*; import com.lyndir.masterpassword.gui.util.Components; import com.lyndir.masterpassword.gui.util.UnsignedIntegerModel; import java.awt.*; diff --git a/platform-independent/gui-java/src/main/java/com/lyndir/masterpassword/gui/UnlockFrame.java b/platform-independent/gui-java/src/main/java/com/lyndir/masterpassword/gui/view/UnlockFrame.java similarity index 83% rename from platform-independent/gui-java/src/main/java/com/lyndir/masterpassword/gui/UnlockFrame.java rename to platform-independent/gui-java/src/main/java/com/lyndir/masterpassword/gui/view/UnlockFrame.java index e936bf7e..84105789 100644 --- a/platform-independent/gui-java/src/main/java/com/lyndir/masterpassword/gui/UnlockFrame.java +++ b/platform-independent/gui-java/src/main/java/com/lyndir/masterpassword/gui/view/UnlockFrame.java @@ -1,12 +1,16 @@ -package com.lyndir.masterpassword.gui; +package com.lyndir.masterpassword.gui.view; import static com.lyndir.lhunath.opal.system.util.ObjectUtils.*; import com.lyndir.masterpassword.MPIdenticon; +import com.lyndir.masterpassword.gui.*; +import com.lyndir.masterpassword.gui.model.User; import com.lyndir.masterpassword.gui.util.Components; import com.lyndir.masterpassword.model.IncorrectMasterPasswordException; import java.awt.*; import java.awt.event.*; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; import javax.annotation.Nullable; import javax.swing.*; @@ -22,6 +26,7 @@ public class UnlockFrame extends JFrame { private final JButton signInButton; private final JPanel authenticationContainer; private AuthenticationPanel authenticationPanel; + private Future identiconFuture; private boolean incognito; public User user; @@ -139,18 +144,34 @@ public class UnlockFrame extends JFrame { } boolean checkSignIn() { + if (identiconFuture != null) + identiconFuture.cancel( false ); + identiconFuture = Res.schedule( this, new Runnable() { + @Override + public void run() { + SwingUtilities.invokeLater( new Runnable() { + @Override + public void run() { + String fullName = user == null? "": user.getFullName(); + char[] masterPassword = authenticationPanel.getMasterPassword(); + + if (fullName.isEmpty() || masterPassword.length == 0) { + identiconLabel.setText( " " ); + return; + } + + MPIdenticon identicon = new MPIdenticon( fullName, masterPassword ); + identiconLabel.setText( identicon.getText() ); + identiconLabel.setForeground( + Res.colors().fromIdenticonColor( identicon.getColor(), Res.Colors.BackgroundMode.DARK ) ); + } + } ); + } + }, 300, TimeUnit.MILLISECONDS ); + String fullName = user == null? "": user.getFullName(); char[] masterPassword = authenticationPanel.getMasterPassword(); boolean enabled = !fullName.isEmpty() && masterPassword.length > 0; - - if (fullName.isEmpty() || masterPassword.length == 0) - identiconLabel.setText( " " ); - else { - MPIdenticon identicon = new MPIdenticon( fullName, masterPassword ); - identiconLabel.setText( identicon.getText() ); - identiconLabel.setForeground( Res.colors().fromIdenticonColor( identicon.getColor(), Res.Colors.BackgroundMode.DARK ) ); - } - signInButton.setEnabled( enabled ); return enabled; @@ -197,7 +218,7 @@ public class UnlockFrame extends JFrame { } ); } - interface SignInCallback { + public interface SignInCallback { void signedIn(User user); }