2
0

Standard label font & fix warnings.

This commit is contained in:
Maarten Billemont 2018-08-14 12:06:04 -04:00
parent f41cdb8742
commit 6b9e1b8cb8
7 changed files with 42 additions and 63 deletions

View File

@ -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();
} );
}
}

View File

@ -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;
}

View File

@ -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<Listener> 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);

View File

@ -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 );
}

View File

@ -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;

View File

@ -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 );
}

View File

@ -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 ) );