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"?>
<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>

View File

@ -21,6 +21,7 @@ import com.google.common.base.Charsets;
import com.google.common.io.*;
import com.lyndir.lhunath.opal.system.logging.Logger;
import com.lyndir.lhunath.opal.system.util.TypeUtils;
import java.io.*;
import java.net.URI;
import java.net.URL;
@ -48,7 +49,13 @@ public class GUI implements UnlockFrame.SignInCallback {
if (Config.get().checkForUpdates())
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() {
@ -80,7 +87,7 @@ public class GUI implements UnlockFrame.SignInCallback {
}
}
void open() {
protected void open() {
SwingUtilities.invokeLater( new Runnable() {
@Override
public void run() {

View File

@ -13,6 +13,7 @@ import javax.annotation.Nullable;
import javax.swing.*;
import javax.swing.event.DocumentEvent;
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.addItemListener( 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( Components.stud() );

View File

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

View File

@ -31,6 +31,18 @@ public class UnlockFrame extends JFrame {
setContentPane(root = Components.gradientPanel(new BorderLayout(20, 20), Res.colors().frameBg()));
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.setOpaque( true );
authenticationContainer.setBackground( Res.colors().controlBg() );
@ -91,10 +103,10 @@ public class UnlockFrame extends JFrame {
JComponent toolsPanel = Components.boxLayout( BoxLayout.LINE_AXIS, incognitoCheckBox, Box.createGlue() );
authenticationContainer.add( toolsPanel );
for (JButton button : authenticationPanel.getButtons()) {
toolsPanel.add( button );
button.setMargin( new Insets( 0, 0, 0, 0 ) );
button.setAlignmentX(RIGHT_ALIGNMENT);
button.setBorder( null );
toolsPanel.add( button );
button.setContentAreaFilled(false);
}
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

@ -116,6 +116,7 @@ public abstract class Components {
((DefaultEditor) getEditor()).getTextField().setBorder( editorBorder );
setAlignmentX( LEFT_ALIGNMENT );
setAlignmentY( BOTTOM_ALIGNMENT );
setBorder(null);
}
@Override
@ -148,6 +149,7 @@ public abstract class Components {
return new JCheckBox( label ) {
{
setFont(Res.controlFont().deriveFont(12f));
setBackground(null);
setAlignmentX( LEFT_ALIGNMENT );
setAlignmentY( BOTTOM_ALIGNMENT );
}
@ -162,9 +164,14 @@ public abstract class Components {
public static <M> JComboBox<M> comboBox(final ComboBoxModel<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 ) );
setAlignmentX( LEFT_ALIGNMENT );
setAlignmentY( BOTTOM_ALIGNMENT );
// setBorder(null);
}
@Override
@ -195,14 +202,17 @@ public abstract class Components {
public void setGradientColor(@Nullable final Color gradientColor) {
this.gradientColor = gradientColor;
revalidate();
}
@Override
public void doLayout() {
super.doLayout();
if (gradientColor != null)
if (gradientColor != null) {
paint = new GradientPaint( new Point( 0, 0 ), gradientColor, new Point( getWidth(), getHeight() ), gradientColor.darker() );
repaint();
}
}
@Override