2
0

UI Improvements for Windows and system L&F.

This commit is contained in:
Maarten Billemont 2015-02-16 23:56:58 -05:00
parent 2db601475f
commit c330728ac3
7 changed files with 112 additions and 22 deletions

View File

@ -1,5 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="Encoding" useUTFGuessing="true" native2AsciiForPropertiesFiles="false" /> <component name="Encoding" useUTFGuessing="true" native2AsciiForPropertiesFiles="false">
<file url="file://$PROJECT_DIR$/MasterPassword/Java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/MasterPassword/Java/masterpassword-algorithm" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/MasterPassword/Java/masterpassword-cli" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/MasterPassword/Java/masterpassword-gui" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/MasterPassword/Java/masterpassword-model" charset="UTF-8" />
</component>
</project> </project>

View File

@ -21,6 +21,7 @@ import com.google.common.base.Charsets;
import com.google.common.io.*; import com.google.common.io.*;
import com.lyndir.lhunath.opal.system.logging.Logger; import com.lyndir.lhunath.opal.system.logging.Logger;
import com.lyndir.lhunath.opal.system.util.TypeUtils; import com.lyndir.lhunath.opal.system.util.TypeUtils;
import java.io.*; import java.io.*;
import java.net.URI; import java.net.URI;
import java.net.URL; import java.net.URL;
@ -48,7 +49,13 @@ public class GUI implements UnlockFrame.SignInCallback {
if (Config.get().checkForUpdates()) if (Config.get().checkForUpdates())
checkUpdate(); checkUpdate();
TypeUtils.<GUI>newInstance( AppleGUI.class ).or( new GUI() ).open(); try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
catch (UnsupportedLookAndFeelException | ClassNotFoundException | InstantiationException | IllegalAccessException ignored) {
}
TypeUtils.<GUI>newInstance( "com.lyndir.masterpassword.gui.platform.mac.AppleGUI" ).or( new GUI() ).open();
} }
private static void checkUpdate() { private static void checkUpdate() {
@ -80,7 +87,7 @@ public class GUI implements UnlockFrame.SignInCallback {
} }
} }
void open() { protected void open() {
SwingUtilities.invokeLater( new Runnable() { SwingUtilities.invokeLater( new Runnable() {
@Override @Override
public void run() { public void run() {

View File

@ -13,6 +13,7 @@ import javax.annotation.Nullable;
import javax.swing.*; import javax.swing.*;
import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener; import javax.swing.event.DocumentListener;
import javax.swing.plaf.metal.MetalComboBoxEditor;
/** /**
@ -51,6 +52,15 @@ public class ModelAuthenticationPanel extends AuthenticationPanel implements Ite
userField.setFont( Res.valueFont().deriveFont( 12f ) ); userField.setFont( Res.valueFont().deriveFont( 12f ) );
userField.addItemListener( this ); userField.addItemListener( this );
userField.addActionListener( this ); userField.addActionListener( this );
userField.setEditor(new MetalComboBoxEditor() {
@Override
protected JTextField createEditorComponent() {
JTextField editorComponents = Components.textField();
editorComponents.setForeground(Color.red);
return editorComponents;
}
});
add( userField ); add( userField );
add( Components.stud() ); add( Components.stud() );

View File

@ -149,11 +149,12 @@ public class PasswordFrame extends JFrame implements DocumentListener {
} ); } );
// Password // Password
passwordField = new JPasswordField(); passwordField = Components.passwordField();
passwordField.setAlignmentX( Component.CENTER_ALIGNMENT ); passwordField.setAlignmentX(Component.CENTER_ALIGNMENT);
passwordField.setEditable( false ); passwordField.setHorizontalAlignment(JTextField.CENTER);
passwordField.setHorizontalAlignment( JTextField.CENTER ); passwordField.putClientProperty("JPasswordField.cutCopyAllowed", true);
passwordField.putClientProperty( "JPasswordField.cutCopyAllowed", true ); passwordField.setEditable(false);
passwordField.setBackground(null);
passwordField.setBorder( null ); passwordField.setBorder( null );
passwordEchoChar = passwordField.getEchoChar(); passwordEchoChar = passwordField.getEchoChar();
passwordEchoFont = passwordField.getFont().deriveFont( 40f ); passwordEchoFont = passwordField.getFont().deriveFont( 40f );

View File

@ -27,9 +27,21 @@ public class UnlockFrame extends JFrame {
super( "Unlock Master Password" ); super( "Unlock Master Password" );
this.signInCallback = signInCallback; this.signInCallback = signInCallback;
setDefaultCloseOperation( DISPOSE_ON_CLOSE ); setDefaultCloseOperation(DISPOSE_ON_CLOSE);
setContentPane( root = Components.gradientPanel( new BorderLayout( 20, 20 ), Res.colors().frameBg() ) ); setContentPane(root = Components.gradientPanel(new BorderLayout(20, 20), Res.colors().frameBg()));
root.setBorder( BorderFactory.createEmptyBorder( 20, 20, 20, 20 ) ); root.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
addWindowFocusListener(new WindowAdapter() {
@Override
public void windowGainedFocus(WindowEvent e) {
root.setGradientColor(Res.colors().frameBg());
}
@Override
public void windowLostFocus(WindowEvent e) {
root.setGradientColor(Color.RED);
}
});
authenticationContainer = Components.boxLayout( BoxLayout.PAGE_AXIS ); authenticationContainer = Components.boxLayout( BoxLayout.PAGE_AXIS );
authenticationContainer.setOpaque( true ); authenticationContainer.setOpaque( true );
@ -91,10 +103,10 @@ public class UnlockFrame extends JFrame {
JComponent toolsPanel = Components.boxLayout( BoxLayout.LINE_AXIS, incognitoCheckBox, Box.createGlue() ); JComponent toolsPanel = Components.boxLayout( BoxLayout.LINE_AXIS, incognitoCheckBox, Box.createGlue() );
authenticationContainer.add( toolsPanel ); authenticationContainer.add( toolsPanel );
for (JButton button : authenticationPanel.getButtons()) { for (JButton button : authenticationPanel.getButtons()) {
button.setMargin( new Insets( 0, 0, 0, 0 ) );
button.setAlignmentX( RIGHT_ALIGNMENT );
button.setBorder( null );
toolsPanel.add( button ); toolsPanel.add( button );
button.setMargin( new Insets( 0, 0, 0, 0 ) );
button.setAlignmentX(RIGHT_ALIGNMENT);
button.setContentAreaFilled(false);
} }
checkSignIn(); checkSignIn();

View File

@ -0,0 +1,45 @@
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 javax.swing.*;
/**
* @author lhunath, 2014-06-10
*/
public class AppleGUI extends GUI {
public AppleGUI() {
Application application = Application.getApplication();
application.addAppEventListener( new AppForegroundListener() {
@Override
public void appMovedToBackground(AppEvent.AppForegroundEvent arg0) {
}
@Override
public void appRaisedToForeground(AppEvent.AppForegroundEvent arg0) {
open();
}
} );
application.addAppEventListener( new AppReOpenedListener() {
@Override
public void appReOpened(AppEvent.AppReOpenedEvent arg0) {
open();
}
} );
}
@Override
protected PasswordFrame newPasswordFrame(final User user) {
PasswordFrame frame = super.newPasswordFrame( user );
frame.setDefaultCloseOperation( WindowConstants.HIDE_ON_CLOSE );
return frame;
}
}

View File

@ -70,10 +70,10 @@ public abstract class Components {
public static JPasswordField passwordField() { public static JPasswordField passwordField() {
return new JPasswordField() { return new JPasswordField() {
{ {
setBorder( BorderFactory.createCompoundBorder( BorderFactory.createLineBorder( Res.colors().controlBorder(), 1, true ), setBorder(BorderFactory.createCompoundBorder(BorderFactory.createLineBorder(Res.colors().controlBorder(), 1, true),
BorderFactory.createEmptyBorder( 4, 4, 4, 4 ) ) ); BorderFactory.createEmptyBorder(4, 4, 4, 4)));
setAlignmentX( LEFT_ALIGNMENT ); setAlignmentX(LEFT_ALIGNMENT);
setAlignmentY( BOTTOM_ALIGNMENT ); setAlignmentY(BOTTOM_ALIGNMENT);
} }
@Override @Override
@ -116,6 +116,7 @@ public abstract class Components {
((DefaultEditor) getEditor()).getTextField().setBorder( editorBorder ); ((DefaultEditor) getEditor()).getTextField().setBorder( editorBorder );
setAlignmentX( LEFT_ALIGNMENT ); setAlignmentX( LEFT_ALIGNMENT );
setAlignmentY( BOTTOM_ALIGNMENT ); setAlignmentY( BOTTOM_ALIGNMENT );
setBorder(null);
} }
@Override @Override
@ -147,7 +148,8 @@ public abstract class Components {
public static JCheckBox checkBox(final String label) { public static JCheckBox checkBox(final String label) {
return new JCheckBox( label ) { return new JCheckBox( label ) {
{ {
setFont( Res.controlFont().deriveFont( 12f ) ); setFont(Res.controlFont().deriveFont(12f));
setBackground(null);
setAlignmentX( LEFT_ALIGNMENT ); setAlignmentX( LEFT_ALIGNMENT );
setAlignmentY( BOTTOM_ALIGNMENT ); setAlignmentY( BOTTOM_ALIGNMENT );
} }
@ -162,9 +164,14 @@ public abstract class Components {
public static <M> JComboBox<M> comboBox(final ComboBoxModel<M> model) { public static <M> JComboBox<M> comboBox(final ComboBoxModel<M> model) {
return new JComboBox<M>( model ) { return new JComboBox<M>( model ) {
{ {
// CompoundBorder editorBorder = BorderFactory.createCompoundBorder(
// BorderFactory.createLineBorder( Res.colors().controlBorder(), 1, true ),
// BorderFactory.createEmptyBorder( 4, 4, 4, 4 ) );
// ((JComponent) ((BasicComboBoxEditor) getEditor()).getEditorComponent()).setBorder(editorBorder);
setFont( Res.controlFont().deriveFont( 12f ) ); setFont( Res.controlFont().deriveFont( 12f ) );
setAlignmentX( LEFT_ALIGNMENT ); setAlignmentX( LEFT_ALIGNMENT );
setAlignmentY( BOTTOM_ALIGNMENT ); setAlignmentY( BOTTOM_ALIGNMENT );
// setBorder(null);
} }
@Override @Override
@ -195,14 +202,17 @@ public abstract class Components {
public void setGradientColor(@Nullable final Color gradientColor) { public void setGradientColor(@Nullable final Color gradientColor) {
this.gradientColor = gradientColor; this.gradientColor = gradientColor;
revalidate();
} }
@Override @Override
public void doLayout() { public void doLayout() {
super.doLayout(); super.doLayout();
if (gradientColor != null) if (gradientColor != null) {
paint = new GradientPaint( new Point( 0, 0 ), gradientColor, new Point( getWidth(), getHeight() ), gradientColor.darker() ); paint = new GradientPaint( new Point( 0, 0 ), gradientColor, new Point( getWidth(), getHeight() ), gradientColor.darker() );
repaint();
}
} }
@Override @Override