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(); e.printStackTrace();
} }
// Clearing the search field and the searchResultList
searchField.setText("");
contactsModel.clear();
// Update LocalDB // Update LocalDB
userListModel.addElement(contact); userListModel.addElement(contact);
localDb.getUsers().put(contact.getName(), contact); localDb.getUsers().put(contact.getName(), contact);

View File

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