Implemented advanced UI

This commit is contained in:
DieGurke 2020-02-06 22:19:33 +01:00
parent 78e6fea898
commit 5ed8c162bb
3 changed files with 170 additions and 21 deletions

View File

@ -53,6 +53,19 @@ public class ChatWindow extends JFrame {
private PrimaryButton postButton = new PrimaryButton("Post");
private PrimaryButton settingsButton = new PrimaryButton("Settings");
// Contacts Header
private JPanel contactsHeader = new JPanel();
private JTextPane contactsDisplay = new JTextPane();
private PrimaryButton addContact = new PrimaryButton("+");
// Search Contacts
private JPanel searchPane = new JPanel();
private PrimaryButton cancelButton = new PrimaryButton("x");
private PrimaryTextArea searchField = new PrimaryTextArea(space);
private PrimaryScrollPane possibleContacts = new PrimaryScrollPane();
private ComponentList<User> contactList; // TODO Implement data rendering model as already done with the
// messages
private static final Logger logger = EnvoyLog.getLogger(ChatWindow.class.getSimpleName());
// GUI component spacing
@ -78,9 +91,9 @@ public class ChatWindow extends JFrame {
setContentPane(contentPane);
GridBagLayout gbl_contentPane = new GridBagLayout();
gbl_contentPane.columnWidths = new int[] { 1, 1, 1 };
gbl_contentPane.rowHeights = new int[] { 1, 1, 1 };
gbl_contentPane.rowHeights = new int[] { 1, 1, 1, 1 };
gbl_contentPane.columnWeights = new double[] { 0.3, 1.0, 0.1 };
gbl_contentPane.rowWeights = new double[] { 0.05, 1.0, 0.07 };
gbl_contentPane.rowWeights = new double[] { 0.03, 0.001, 1.0, 0.005 };
contentPane.setLayout(gbl_contentPane);
// TODO: messageList.setFocusTraversalKeysEnabled(false);
@ -95,11 +108,13 @@ public class ChatWindow extends JFrame {
GridBagConstraints gbc_scrollPane = new GridBagConstraints();
gbc_scrollPane.fill = GridBagConstraints.BOTH;
gbc_scrollPane.gridwidth = 2;
gbc_scrollPane.gridheight = 2;
gbc_scrollPane.gridx = 1;
gbc_scrollPane.gridy = 1;
gbc_scrollPane.insets = insets;
contentPane.add(scrollPane, gbc_scrollPane);
drawChatBox(gbc_scrollPane);
// Message enter field
messageEnterTextArea.addKeyListener(new KeyAdapter() {
@ -115,7 +130,7 @@ public class ChatWindow extends JFrame {
GridBagConstraints gbc_messageEnterTextfield = new GridBagConstraints();
gbc_messageEnterTextfield.fill = GridBagConstraints.BOTH;
gbc_messageEnterTextfield.gridx = 1;
gbc_messageEnterTextfield.gridy = 2;
gbc_messageEnterTextfield.gridy = 3;
gbc_messageEnterTextfield.insets = insets;
@ -126,7 +141,7 @@ public class ChatWindow extends JFrame {
gbc_moveSelectionPostButton.fill = GridBagConstraints.BOTH;
gbc_moveSelectionPostButton.gridx = 2;
gbc_moveSelectionPostButton.gridy = 2;
gbc_moveSelectionPostButton.gridy = 3;
gbc_moveSelectionPostButton.insets = insets;
@ -172,22 +187,27 @@ public class ChatWindow extends JFrame {
final JList<User> selectedUserList = (JList<User>) listSelectionEvent.getSource();
final User user = selectedUserList.getSelectedValue();
// Select current chat
currentChat = localDb.getChats().stream().filter(chat -> chat.getRecipient().getId() == user.getId()).findFirst().get();
for (int i = 0; i < contentPane.getComponents().length; i++) {
if (contentPane.getComponent(i).equals(searchPane)) { drawChatBox(gbc_scrollPane); }
}
if (user != null) {
// Select current chat
currentChat = localDb.getChats().stream().filter(chat -> chat.getRecipient().getId() == user.getId()).findFirst().get();
// Read current chat
readCurrentChat();
// Read current chat
readCurrentChat();
// Set chat title
textPane.setText(currentChat.getRecipient().getName());
// Set chat title
textPane.setText(currentChat.getRecipient().getName());
// Update model and scroll down
messageList.setModel(currentChat.getModel());
scrollPane.setChatOpened(true);
// Update model and scroll down
messageList.setModel(currentChat.getModel());
scrollPane.setChatOpened(true);
messageList.synchronizeModel();
revalidate();
repaint();
messageList.synchronizeModel();
revalidate();
repaint();
}
}
});
@ -197,15 +217,104 @@ public class ChatWindow extends JFrame {
GridBagConstraints gbc_userList = new GridBagConstraints();
gbc_userList.fill = GridBagConstraints.VERTICAL;
gbc_userList.gridx = 0;
gbc_userList.gridy = 1;
gbc_userList.gridy = 2;
gbc_userList.anchor = GridBagConstraints.PAGE_START;
gbc_userList.insets = insets;
applyTheme(Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()));
contentPane.add(userList, gbc_userList);
contentPane.revalidate();
// Contacts Search
GridBagConstraints gbc_searchPane = new GridBagConstraints();
gbc_searchPane.fill = GridBagConstraints.BOTH;
gbc_searchPane.gridwidth = 2;
gbc_searchPane.gridheight = 2;
gbc_searchPane.gridx = 1;
gbc_searchPane.gridy = 1;
gbc_searchPane.insets = insets;
GridBagLayout gbl_contactsSearch = new GridBagLayout();
gbl_contactsSearch.columnWidths = new int[] { 1, 1 };
gbl_contactsSearch.rowHeights = new int[] { 1, 1 };
gbl_contactsSearch.columnWeights = new double[] { 1, 0.1 };
gbl_contactsSearch.rowWeights = new double[] { 0.001, 1 };
searchPane.setLayout(gbl_contactsSearch);
GridBagConstraints gbc_searchField = new GridBagConstraints();
gbc_searchField.fill = GridBagConstraints.BOTH;
gbc_searchField.gridx = 0;
gbc_searchField.gridy = 0;
gbc_searchField.insets = new Insets(7, 4, 4, 4);
searchPane.add(searchField, gbc_searchField);
GridBagConstraints gbc_cancelButton = new GridBagConstraints();
gbc_cancelButton.fill = GridBagConstraints.BOTH;
gbc_cancelButton.gridx = 1;
gbc_cancelButton.gridy = 0;
gbc_cancelButton.insets = new Insets(7, 4, 4, 4);
cancelButton.addActionListener((evt) -> { drawChatBox(gbc_scrollPane); });
searchPane.add(cancelButton, gbc_cancelButton);
possibleContacts.setViewportView(contactList);
GridBagConstraints gbc_possibleContacts = new GridBagConstraints();
gbc_possibleContacts.fill = GridBagConstraints.BOTH;
gbc_possibleContacts.gridwidth = 2;
gbc_possibleContacts.gridx = 0;
gbc_possibleContacts.gridy = 1;
gbc_possibleContacts.insets = insets;
searchPane.add(possibleContacts, gbc_possibleContacts);
// Contacts Header
GridBagConstraints gbc_contactsHeader = new GridBagConstraints();
gbc_contactsHeader.fill = GridBagConstraints.BOTH;
gbc_contactsHeader.gridx = 0;
gbc_contactsHeader.gridy = 1;
gbc_contactsHeader.insets = insets;
GridBagLayout gbl_contactHeader = new GridBagLayout();
gbl_contactHeader.columnWidths = new int[] { 1, 1 };
gbl_contactHeader.rowHeights = new int[] { 1 };
gbl_contactHeader.columnWeights = new double[] { 1, 1 };
gbl_contactHeader.rowWeights = new double[] { 1 };
contactsHeader.setLayout(gbl_contactHeader);
contactsDisplay.setEditable(false);
contactsDisplay.setFont(new Font("Arial", Font.PLAIN, 12));
contactsDisplay.setText("Contacts");
GridBagConstraints gbc_contactsDisplay = new GridBagConstraints();
gbc_contactsDisplay.fill = GridBagConstraints.BOTH;
gbc_contactsDisplay.gridx = 0;
gbc_contactsDisplay.gridy = 0;
contactsHeader.add(contactsDisplay, gbc_contactsDisplay);
addContact.setFont(new Font("Arial", Font.PLAIN, 15));
GridBagConstraints gbc_addContact = new GridBagConstraints();
gbc_addContact.fill = GridBagConstraints.BOTH;
gbc_addContact.gridx = 1;
gbc_addContact.gridy = 0;
gbc_addContact.insets = insets;
addContact.addActionListener((evt) -> { drawContactSearch(gbc_searchPane); });
contactsHeader.add(addContact, gbc_addContact);
applyTheme(Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()));
contentPane.add(contactsHeader, gbc_contactsHeader);
contentPane.revalidate();
// Listen to theme changes
EventBus.getInstance().register(ThemeChangeEvent.class, (evt) -> applyTheme((Theme) evt.get()));
@ -285,6 +394,22 @@ public class ChatWindow extends JFrame {
userList.setSelectionBackground(theme.getSelectionColor());
userList.setForeground(theme.getUserNameColor());
userList.setBackground(theme.getCellColor());
// contacts header
contactsHeader.setBackground(theme.getCellColor());
contactsDisplay.setBackground(theme.getCellColor());
contactsDisplay.setForeground(theme.getUserNameColor());
addContact.setBackground(theme.getInteractableBackgroundColor());
addContact.setForeground(theme.getInteractableForegroundColor());
// SearchPane
searchPane.setBackground(theme.getCellColor());
searchField.setBackground(theme.getBackgroundColor());
searchField.setForeground(theme.getUserNameColor());
cancelButton.setBackground(theme.getInteractableBackgroundColor());
cancelButton.setForeground(theme.getInteractableForegroundColor());
// TODO: Uncomment if renderer is implemented
// contactList.setForeground(theme.getMessageColorChat());
// contactList.setBackground(theme.getCellColor());
possibleContacts.applyTheme(theme);
}
private void postMessage() {
@ -352,6 +477,25 @@ public class ChatWindow extends JFrame {
logger.log(Level.WARNING, "Couldn't notify server about message status change", e);
}
}
private void drawChatBox(GridBagConstraints gbc_scrollPane) {
contentPane.remove(searchPane);
contentPane.add(scrollPane, gbc_scrollPane);
contentPane.revalidate();
contentPane.repaint();
}
private void drawContactSearch(GridBagConstraints gbc_searchPane) {
currentChat = null;
userList.removeSelectionInterval(0, userList.getModel().getSize() - 1);
messageList.setModel(null);
textPane.setText("");
contentPane.remove(scrollPane);
contentPane.add(searchPane, gbc_searchPane);
contentPane.revalidate();
contentPane.repaint();
}
/**
* Sets the {@link Client} used by this {@link ChatWindow}.

View File

@ -1,6 +1,7 @@
package envoy.client.ui;
import java.awt.Component;
import java.awt.Dimension;
import javax.swing.JLabel;
import javax.swing.JList;
@ -41,6 +42,8 @@ public class UserListRenderer extends JLabel implements ListCellRenderer<User> {
final String name = value.getName();
final UserStatus status = value.getStatus();
this.setPreferredSize(new Dimension(100, 35));
// Getting the UserNameColor of the current theme
String textColor = null;
textColor = Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()).getUserNameColor().toHex();

View File

@ -62,8 +62,10 @@ public class ComponentList<E> extends JPanel {
// Synchronize with new model
this.model = model;
this.model.setComponentList(this);
synchronizeModel();
if (model != null) {
this.model.setComponentList(this);
synchronizeModel();
} else removeAll();
}
/**