diff --git a/platform-independent/java/gui/src/main/java/com/lyndir/masterpassword/gui/GUI.java b/platform-independent/java/gui/src/main/java/com/lyndir/masterpassword/gui/GUI.java deleted file mode 100644 index 347de69c..00000000 --- a/platform-independent/java/gui/src/main/java/com/lyndir/masterpassword/gui/GUI.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.lyndir.masterpassword.gui; - -import com.lyndir.lhunath.opal.system.logging.Logger; -import com.lyndir.masterpassword.gui.util.Platform; -import com.lyndir.masterpassword.gui.util.Res; -import com.lyndir.masterpassword.gui.view.MasterPasswordFrame; -import com.tulskiy.keymaster.common.Provider; -import java.awt.*; - - -/** - * @author lhunath, 2018-07-28 - */ -public class GUI { - - private static final Logger logger = Logger.get( GUI.class ); - - private final MasterPasswordFrame frame = new MasterPasswordFrame(); - - public GUI() { - Platform.get().installAppForegroundHandler( this::open ); - Platform.get().installAppReopenHandler( this::open ); - - Provider.getCurrentProvider( true ).register( MPGuiConstants.ui_hotkey, hotKey -> open() ); - } - - public void open() { - Res.ui( () -> { - frame.setAlwaysOnTop( true ); - frame.setVisible( true ); - frame.setExtendedState( Frame.NORMAL ); - frame.setAlwaysOnTop( false ); - Platform.get().requestForeground(); - } ); - } -} diff --git a/platform-independent/java/gui/src/main/java/com/lyndir/masterpassword/gui/Config.java b/platform-independent/java/gui/src/main/java/com/lyndir/masterpassword/gui/MPConfig.java similarity index 91% rename from platform-independent/java/gui/src/main/java/com/lyndir/masterpassword/gui/Config.java rename to platform-independent/java/gui/src/main/java/com/lyndir/masterpassword/gui/MPConfig.java index d412d36c..ca1daa7d 100644 --- a/platform-independent/java/gui/src/main/java/com/lyndir/masterpassword/gui/Config.java +++ b/platform-independent/java/gui/src/main/java/com/lyndir/masterpassword/gui/MPConfig.java @@ -26,11 +26,11 @@ import com.lyndir.masterpassword.model.MPModelConstants; * @author lhunath, 2014-08-31 */ @SuppressWarnings("CallToSystemGetenv") -public class Config { +public class MPConfig { - private static final Config instance = new Config(); + private static final MPConfig instance = new MPConfig(); - public static Config get() { + public static MPConfig get() { return instance; } diff --git a/platform-independent/java/gui/src/main/java/com/lyndir/masterpassword/gui/MasterPassword.java b/platform-independent/java/gui/src/main/java/com/lyndir/masterpassword/gui/MasterPassword.java index 2d803f46..bd1d6751 100644 --- a/platform-independent/java/gui/src/main/java/com/lyndir/masterpassword/gui/MasterPassword.java +++ b/platform-independent/java/gui/src/main/java/com/lyndir/masterpassword/gui/MasterPassword.java @@ -24,8 +24,11 @@ import com.google.common.base.Charsets; import com.google.common.io.ByteSource; import com.lyndir.lhunath.opal.system.logging.Logger; import com.lyndir.lhunath.opal.system.util.ObjectUtils; -import com.lyndir.masterpassword.gui.util.Components; +import com.lyndir.masterpassword.gui.util.*; +import com.lyndir.masterpassword.gui.view.MasterPasswordFrame; import com.lyndir.masterpassword.model.MPUser; +import com.tulskiy.keymaster.common.Provider; +import java.awt.*; import java.io.IOException; import java.io.InputStream; import java.net.*; @@ -48,6 +51,7 @@ public final class MasterPassword { private static final MasterPassword instance = new MasterPassword(); private final Collection listeners = new CopyOnWriteArraySet<>(); + private final MasterPasswordFrame frame = new MasterPasswordFrame(); @Nullable private MPUser activeUser; @@ -78,6 +82,16 @@ public final class MasterPassword { return MasterPassword.class.getPackage().getImplementationVersion(); } + public void open() { + Res.ui( () -> { + frame.setAlwaysOnTop( true ); + frame.setVisible( true ); + frame.setExtendedState( Frame.NORMAL ); + Platform.get().requestForeground(); + frame.setAlwaysOnTop( false ); + } ); + } + public void checkUpdate() { try { String implementationVersion = version(); @@ -115,18 +129,22 @@ public final class MasterPassword { // Try and set the system look & feel, if available. try { UIManager.setLookAndFeel( UIManager.getSystemLookAndFeelClassName() ); + Platform.get().installAppForegroundHandler( get()::open ); + Platform.get().installAppReopenHandler( get()::open ); + Provider.getCurrentProvider( true ).register( MPGuiConstants.ui_hotkey, hotKey -> get().open() ); } catch (final UnsupportedLookAndFeelException | ClassNotFoundException | InstantiationException | IllegalAccessException ignored) { } // Create a platform-specific GUI and open it. - new GUI().open(); + get().open(); // Check online to see if this version has been superseded. - if (Config.get().checkForUpdates()) + if (MPConfig.get().checkForUpdates()) get().checkUpdate(); } + @SuppressWarnings("InterfaceMayBeAnnotatedFunctional") public interface Listener { void onUserSelected(@Nullable MPUser user); diff --git a/platform-independent/java/gui/src/main/java/com/lyndir/masterpassword/gui/util/Components.java b/platform-independent/java/gui/src/main/java/com/lyndir/masterpassword/gui/util/Components.java index 0723b626..ba7847e5 100644 --- a/platform-independent/java/gui/src/main/java/com/lyndir/masterpassword/gui/util/Components.java +++ b/platform-independent/java/gui/src/main/java/com/lyndir/masterpassword/gui/util/Components.java @@ -306,7 +306,6 @@ public abstract class Components { public static JButton button(final Action action) { return new JButton( action ) { { - setFont( Res.fonts().controlFont( TEXT_SIZE_CONTROL ) ); setAlignmentX( LEFT_ALIGNMENT ); if (getText() == null) { @@ -383,7 +382,7 @@ public abstract class Components { public static JLabel heading(@Nullable final String heading, final int horizontalAlignment) { return new JLabel( heading, horizontalAlignment ) { { - setFont( Res.fonts().controlFont( TEXT_SIZE_HEADING ).deriveFont( Font.BOLD ) ); + setFont( getFont().deriveFont( Font.BOLD, TEXT_SIZE_HEADING ) ); setAlignmentX( LEFT_ALIGNMENT ); } @@ -418,7 +417,6 @@ public abstract class Components { public static JLabel label(@Nullable final String label, final int horizontalAlignment) { return new JLabel( label, horizontalAlignment ) { { - //setFont( Res.fonts().controlFont( TEXT_SIZE_CONTROL ) ); setAlignmentX( LEFT_ALIGNMENT ); } @@ -432,7 +430,6 @@ public abstract class Components { public static JCheckBox checkBox(final String label) { return new JCheckBox( label ) { { - setFont( Res.fonts().controlFont( TEXT_SIZE_CONTROL ) ); setBackground( null ); setAlignmentX( LEFT_ALIGNMENT ); } diff --git a/platform-independent/java/gui/src/main/java/com/lyndir/masterpassword/gui/util/Res.java b/platform-independent/java/gui/src/main/java/com/lyndir/masterpassword/gui/util/Res.java index 77844657..837b7ab2 100644 --- a/platform-independent/java/gui/src/main/java/com/lyndir/masterpassword/gui/util/Res.java +++ b/platform-independent/java/gui/src/main/java/com/lyndir/masterpassword/gui/util/Res.java @@ -25,7 +25,6 @@ import com.google.common.io.Resources; import com.google.common.util.concurrent.*; import com.lyndir.lhunath.opal.system.logging.Logger; import com.lyndir.masterpassword.MPIdenticon; -import com.lyndir.masterpassword.gui.SwingExecutorService; import java.awt.*; import java.io.IOException; import java.lang.ref.SoftReference; diff --git a/platform-independent/java/gui/src/main/java/com/lyndir/masterpassword/gui/SwingExecutorService.java b/platform-independent/java/gui/src/main/java/com/lyndir/masterpassword/gui/util/SwingExecutorService.java similarity index 90% rename from platform-independent/java/gui/src/main/java/com/lyndir/masterpassword/gui/SwingExecutorService.java rename to platform-independent/java/gui/src/main/java/com/lyndir/masterpassword/gui/util/SwingExecutorService.java index e4241d0f..91116558 100644 --- a/platform-independent/java/gui/src/main/java/com/lyndir/masterpassword/gui/SwingExecutorService.java +++ b/platform-independent/java/gui/src/main/java/com/lyndir/masterpassword/gui/util/SwingExecutorService.java @@ -1,4 +1,4 @@ -package com.lyndir.masterpassword.gui; +package com.lyndir.masterpassword.gui.util; import static com.lyndir.lhunath.opal.system.util.ObjectUtils.*; @@ -29,9 +29,9 @@ public class SwingExecutorService extends AbstractExecutorService { @Override public void shutdown() { - shutdown = true; - synchronized (pendingCommands) { + shutdown = true; + if (pendingCommands.isEmpty()) terminated.add( true ); } @@ -49,7 +49,9 @@ public class SwingExecutorService extends AbstractExecutorService { @Override public boolean isShutdown() { - return shutdown; + synchronized (pendingCommands) { + return shutdown; + } } @Override @@ -65,10 +67,10 @@ public class SwingExecutorService extends AbstractExecutorService { @Override public void execute(@NotNull final Runnable command) { - if (shutdown) - throw new RejectedExecutionException( "Executor is shut down." ); - synchronized (pendingCommands) { + if (shutdown) + throw new RejectedExecutionException( "Executor is shut down." ); + pendingCommands.add( command ); } diff --git a/platform-independent/java/gui/src/main/java/com/lyndir/masterpassword/gui/view/MasterPasswordFrame.java b/platform-independent/java/gui/src/main/java/com/lyndir/masterpassword/gui/view/MasterPasswordFrame.java index a48e06e4..05e2bf1e 100644 --- a/platform-independent/java/gui/src/main/java/com/lyndir/masterpassword/gui/view/MasterPasswordFrame.java +++ b/platform-independent/java/gui/src/main/java/com/lyndir/masterpassword/gui/view/MasterPasswordFrame.java @@ -19,25 +19,24 @@ public class MasterPasswordFrame extends JFrame { private static final Logger logger = Logger.get( MasterPasswordFrame.class ); - @SuppressWarnings("FieldCanBeLocal") - private final Components.GradientPanel root = Components.borderPanel( Res.colors().frameBg(), BoxLayout.PAGE_AXIS ); - private final UserContentPanel userContent = new UserContentPanel(); + private final UserContentPanel userContent; @SuppressWarnings("MagicNumber") public MasterPasswordFrame() { super( "Master Password" ); - setContentPane( root ); + JPanel root, userPanel; + setContentPane( root = Components.borderPanel( Res.colors().frameBg(), BoxLayout.PAGE_AXIS ) ); + root.add( new FilesPanel() ); root.add( Components.strut() ); + root.add( userPanel = Components.panel( new BorderLayout( 0, 0 ) ) ); - JPanel userPanel = Components.panel( new BorderLayout( 0, 0 ) ); - userPanel.add( userContent.getUserToolbar(), BorderLayout.LINE_START ); - userPanel.add( userContent.getSiteToolbar(), BorderLayout.LINE_END ); userPanel.add( Components.borderPanel( BorderFactory.createBevelBorder( BevelBorder.RAISED, Res.colors().controlBorder(), Res.colors().frameBg() ), - Res.colors().controlBg(), BoxLayout.PAGE_AXIS, userContent ), BorderLayout.CENTER ); - root.add( userPanel ); + Res.colors().controlBg(), BoxLayout.PAGE_AXIS, userContent = new UserContentPanel() ), BorderLayout.CENTER ); + userPanel.add( userContent.getUserToolbar(), BorderLayout.LINE_START ); + userPanel.add( userContent.getSiteToolbar(), BorderLayout.LINE_END ); addComponentListener( new ComponentHandler() ); setPreferredSize( new Dimension( 800, 560 ) );