Small improvements

* Resettings the searchField after adding a contact and clearing the
contactsModel after adding a contact.

* Revised LoginDialoge UI
This commit is contained in:
DieGurke 2020-02-10 23:21:06 +01:00
parent 78d8c08573
commit fa4cc8d6d9
2 changed files with 76 additions and 13 deletions

View File

@ -413,6 +413,10 @@ public class ChatWindow extends JFrame {
e.printStackTrace();
}
// Clearing the search field and the searchResultList
searchField.setText("");
contactsModel.clear();
// Update LocalDB
userListModel.addElement(contact);
localDb.getUsers().put(contact.getName(), contact);

View File

@ -9,6 +9,7 @@ import java.util.Arrays;
import javax.swing.*;
import javax.swing.border.EmptyBorder;
import envoy.client.Settings;
import envoy.data.LoginCredentials;
/**
@ -22,19 +23,27 @@ import envoy.data.LoginCredentials;
*/
public class LoginDialog extends JDialog {
private final JPanel contentPanel = new JPanel();
private static final long serialVersionUID = 352021600833907468L;
private final JPanel contentPanel;
private JTextField textField;
private JPasswordField passwordField;
private JPasswordField repeatPasswordField;
private JLabel lblRepeatPassword;
private JLabel lblUserName;
private JLabel lblPassword;
private JLabel lblRepeatPassword;
private GridBagConstraints gbc_lblRepeatPassword;
private GridBagConstraints gbc_repeatPasswordField;
private JPanel buttonPane;
private JTextPane registerText;
private JCheckBox registerCheckBox;
private PrimaryButton okButton;
private PrimaryButton cancelButton;
private LoginCredentials credentials;
private static final long serialVersionUID = 352021600833907468L;
/**
* Displays a dialog enabling the user to enter their user name and password.
*
@ -44,6 +53,7 @@ public class LoginDialog extends JDialog {
setSize(338, 123);
setLocationRelativeTo(null);
getContentPane().setLayout(new BorderLayout());
contentPanel = new JPanel();
contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
getContentPane().add(contentPanel, BorderLayout.CENTER);
GridBagLayout gbl_contentPanel = new GridBagLayout();
@ -53,7 +63,7 @@ public class LoginDialog extends JDialog {
gbl_contentPanel.rowWeights = new double[] { 0.0, 0.0, Double.MIN_VALUE };
contentPanel.setLayout(gbl_contentPanel);
{
JLabel lblUserName = new JLabel("User name:");
lblUserName = new JLabel("Username:");
GridBagConstraints gbc_lblUserName = new GridBagConstraints();
gbc_lblUserName.anchor = GridBagConstraints.EAST;
gbc_lblUserName.insets = new Insets(0, 0, 5, 5);
@ -63,6 +73,7 @@ public class LoginDialog extends JDialog {
}
{
textField = new JTextField();
textField.setBorder(null);
GridBagConstraints gbc_textField = new GridBagConstraints();
gbc_textField.insets = new Insets(0, 0, 5, 0);
gbc_textField.fill = GridBagConstraints.HORIZONTAL;
@ -72,7 +83,7 @@ public class LoginDialog extends JDialog {
textField.setColumns(10);
}
{
JLabel lblPassword = new JLabel("Password:");
lblPassword = new JLabel("Password:");
GridBagConstraints gbc_lblPassword = new GridBagConstraints();
gbc_lblPassword.anchor = GridBagConstraints.EAST;
gbc_lblPassword.insets = new Insets(0, 0, 0, 5);
@ -82,6 +93,7 @@ public class LoginDialog extends JDialog {
}
{
passwordField = new JPasswordField();
passwordField.setBorder(null);
GridBagConstraints gbc_passwordField = new GridBagConstraints();
gbc_passwordField.fill = GridBagConstraints.HORIZONTAL;
gbc_passwordField.gridx = 1;
@ -98,21 +110,23 @@ public class LoginDialog extends JDialog {
}
{
repeatPasswordField = new JPasswordField();
repeatPasswordField.setBorder(null);
gbc_repeatPasswordField = new GridBagConstraints();
gbc_repeatPasswordField.fill = GridBagConstraints.HORIZONTAL;
gbc_repeatPasswordField.gridx = 1;
gbc_repeatPasswordField.gridy = 2;
}
{
JPanel buttonPane = new JPanel();
buttonPane = new JPanel();
JTextPane registerText = new JTextPane();
registerText = new JTextPane();
registerText.setEditable(false);
registerText.setText("Register?");
registerText.setFont(new Font("Arial", Font.BOLD, 12));
registerText.setAlignmentX(LEFT_ALIGNMENT);
buttonPane.add(registerText);
JCheckBox registerCheckBox = new JCheckBox();
registerCheckBox = new JCheckBox();
registerCheckBox.setAlignmentX(LEFT_ALIGNMENT);
registerCheckBox.addItemListener(new ItemListener() {
@ -122,7 +136,7 @@ public class LoginDialog extends JDialog {
case ItemEvent.SELECTED:
contentPanel.add(lblRepeatPassword, gbc_lblRepeatPassword);
contentPanel.add(repeatPasswordField, gbc_repeatPasswordField);
setSize(338, 160);
setSize(338, 148);
contentPanel.revalidate();
contentPanel.repaint();
break;
@ -144,7 +158,7 @@ public class LoginDialog extends JDialog {
buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
getContentPane().add(buttonPane, BorderLayout.SOUTH);
{
JButton okButton = new JButton("OK");
okButton = new PrimaryButton("OK");
okButton.addActionListener((evt) -> {
try {
if (registerCheckBox.isSelected()) {
@ -169,17 +183,62 @@ public class LoginDialog extends JDialog {
getRootPane().setDefaultButton(okButton);
}
{
JButton cancelButton = new JButton("Cancel");
cancelButton = new PrimaryButton("Cancel");
cancelButton.addActionListener((evt) -> dispose());
cancelButton.setActionCommand("Cancel");
buttonPane.add(cancelButton);
}
}
setTheme();
setModal(true);
setVisible(true);
}
private void setTheme() {
Theme theme = Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme());
// Panels
contentPanel.setBackground(theme.getBackgroundColor());
contentPanel.setForeground(theme.getBackgroundColor());
buttonPane.setBackground(theme.getBackgroundColor());
buttonPane.setForeground(theme.getBackgroundColor());
// Input Fields
textField.setBackground(theme.getCellColor());
textField.setForeground(theme.getUserNameColor());
passwordField.setBackground(theme.getCellColor());
passwordField.setForeground(theme.getUserNameColor());
repeatPasswordField.setBackground(theme.getCellColor());
repeatPasswordField.setForeground(theme.getUserNameColor());
// JLabels
lblUserName.setBackground(theme.getCellColor());
lblUserName.setForeground(theme.getUserNameColor());
lblPassword.setBackground(theme.getCellColor());
lblPassword.setForeground(theme.getUserNameColor());
lblRepeatPassword.setBackground(theme.getCellColor());
lblRepeatPassword.setForeground(theme.getUserNameColor());
// Register
registerText.setBackground(theme.getCellColor());
registerText.setForeground(theme.getUserNameColor());
registerCheckBox.setBackground(theme.getCellColor());
// Buttons
okButton.setBackground(theme.getInteractableBackgroundColor());
okButton.setForeground(theme.getInteractableForegroundColor());
cancelButton.setBackground(theme.getInteractableBackgroundColor());
cancelButton.setForeground(theme.getInteractableForegroundColor());
}
/**
* @return the {@link LoginCredentials} entered by the user, or {@code null} if
* the dialog has been cancelled