Implemented ContactRenderer and built a properScrollPane with list, etc.
This commit is contained in:
@ -17,6 +17,7 @@ import envoy.client.event.MessageCreationEvent;
|
||||
import envoy.client.event.ThemeChangeEvent;
|
||||
import envoy.client.net.Client;
|
||||
import envoy.client.ui.list.ComponentList;
|
||||
import envoy.client.ui.list.ComponentListModel;
|
||||
import envoy.client.ui.settings.SettingsScreen;
|
||||
import envoy.client.util.EnvoyLog;
|
||||
import envoy.data.Message;
|
||||
@ -54,17 +55,18 @@ public class ChatWindow extends JFrame {
|
||||
private PrimaryButton settingsButton = new PrimaryButton("Settings");
|
||||
|
||||
// Contacts Header
|
||||
private JPanel contactsHeader = new JPanel();
|
||||
private JTextPane contactsDisplay = new JTextPane();
|
||||
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 final JPanel searchPane = new JPanel();
|
||||
private final PrimaryButton cancelButton = new PrimaryButton("x");
|
||||
private final PrimaryTextArea searchField = new PrimaryTextArea(space);
|
||||
private final PrimaryScrollPane possibleContacts = new PrimaryScrollPane();
|
||||
private final ContactsSearchRenderer contactRenderer = new ContactsSearchRenderer();
|
||||
private final ComponentListModel<User> contactsSearchModel = new ComponentListModel<>();
|
||||
private final ComponentList<User> contactList = new ComponentList<>(contactRenderer);
|
||||
|
||||
private static final Logger logger = EnvoyLog.getLogger(ChatWindow.class.getSimpleName());
|
||||
|
||||
@ -215,12 +217,12 @@ public class ChatWindow extends JFrame {
|
||||
userList.setBorder(new EmptyBorder(space, space, space, space));
|
||||
|
||||
GridBagConstraints gbc_userList = new GridBagConstraints();
|
||||
gbc_userList.fill = GridBagConstraints.VERTICAL;
|
||||
gbc_userList.gridx = 0;
|
||||
gbc_userList.gridy = 2;
|
||||
gbc_userList.anchor = GridBagConstraints.PAGE_START;
|
||||
gbc_userList.insets = insets;
|
||||
|
||||
gbc_userList.fill = GridBagConstraints.VERTICAL;
|
||||
gbc_userList.gridx = 0;
|
||||
gbc_userList.gridy = 2;
|
||||
gbc_userList.gridheight = 2;
|
||||
gbc_userList.anchor = GridBagConstraints.PAGE_START;
|
||||
gbc_userList.insets = insets;
|
||||
|
||||
contentPane.add(userList, gbc_userList);
|
||||
contentPane.revalidate();
|
||||
@ -247,9 +249,9 @@ public class ChatWindow extends JFrame {
|
||||
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;
|
||||
@ -260,6 +262,8 @@ public class ChatWindow extends JFrame {
|
||||
|
||||
searchPane.add(cancelButton, gbc_cancelButton);
|
||||
|
||||
contactList.setModel(contactsSearchModel);
|
||||
possibleContacts.setBorder(new EmptyBorder(space, space, space, space));
|
||||
possibleContacts.setViewportView(contactList);
|
||||
|
||||
GridBagConstraints gbc_possibleContacts = new GridBagConstraints();
|
||||
@ -269,9 +273,10 @@ public class ChatWindow extends JFrame {
|
||||
gbc_possibleContacts.gridy = 1;
|
||||
|
||||
gbc_possibleContacts.insets = insets;
|
||||
|
||||
|
||||
searchPane.add(possibleContacts, gbc_possibleContacts);
|
||||
|
||||
|
||||
// Contacts Header
|
||||
|
||||
GridBagConstraints gbc_contactsHeader = new GridBagConstraints();
|
||||
@ -305,7 +310,7 @@ public class ChatWindow extends JFrame {
|
||||
gbc_addContact.gridx = 1;
|
||||
gbc_addContact.gridy = 0;
|
||||
gbc_addContact.insets = insets;
|
||||
|
||||
|
||||
addContact.addActionListener((evt) -> { drawContactSearch(gbc_searchPane); });
|
||||
|
||||
contactsHeader.add(addContact, gbc_addContact);
|
||||
@ -320,7 +325,7 @@ public class ChatWindow extends JFrame {
|
||||
|
||||
// Listen to received messages
|
||||
EventBus.getInstance().register(MessageCreationEvent.class, (evt) -> {
|
||||
Message message = ((MessageCreationEvent) evt).get();
|
||||
Message message = ((MessageCreationEvent) evt).get();
|
||||
Chat chat = localDb.getChats().stream().filter(c -> c.getRecipient().getId() == message.getSenderId()).findFirst().get();
|
||||
chat.appendMessage(message);
|
||||
|
||||
@ -355,6 +360,7 @@ public class ChatWindow extends JFrame {
|
||||
});
|
||||
|
||||
revalidate();
|
||||
repaint();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -406,9 +412,8 @@ public class ChatWindow extends JFrame {
|
||||
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());
|
||||
contactList.setForeground(theme.getMessageColorChat());
|
||||
contactList.setBackground(theme.getCellColor());
|
||||
possibleContacts.applyTheme(theme);
|
||||
}
|
||||
|
||||
@ -465,6 +470,9 @@ public class ChatWindow extends JFrame {
|
||||
localDb.getChats().add(new Chat(user));
|
||||
});
|
||||
SwingUtilities.invokeLater(() -> userList.setModel(userListModel));
|
||||
|
||||
revalidate();
|
||||
repaint();
|
||||
}).start();
|
||||
}
|
||||
|
||||
@ -477,15 +485,14 @@ 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);
|
||||
@ -494,6 +501,7 @@ public class ChatWindow extends JFrame {
|
||||
contentPane.remove(scrollPane);
|
||||
contentPane.add(searchPane, gbc_searchPane);
|
||||
contentPane.revalidate();
|
||||
contactRenderer.setScrollPane(possibleContacts);
|
||||
contentPane.repaint();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user