Started ComponentList integration for message list

This commit is contained in:
2020-01-26 22:10:15 +01:00
parent 8d41a2230a
commit 43851d9893
6 changed files with 56 additions and 36 deletions

View File

@ -11,6 +11,8 @@ import javax.swing.border.EmptyBorder;
import envoy.client.*;
import envoy.client.event.ThemeChangeEvent;
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;
@ -41,7 +43,7 @@ public class ChatWindow extends JFrame {
private PrimaryTextArea messageEnterTextArea = new PrimaryTextArea(space);
private JList<User> userList = new JList<>();
private Chat currentChat;
private JList<Message> messageList = new JList<>();
private ComponentList<Message> messageList;
private PrimaryScrollPane scrollPane = new PrimaryScrollPane();
private JTextPane textPane = new JTextPane();
private PrimaryButton postButton = new PrimaryButton("Post");
@ -73,14 +75,12 @@ public class ChatWindow extends JFrame {
gbl_contentPane.rowWeights = new double[] { 0.05, 1.0, 0.07 };
contentPane.setLayout(gbl_contentPane);
messageList.setCellRenderer(new MessageListRenderer());
messageList.setFocusTraversalKeysEnabled(false);
messageList.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
messageList = new ComponentList<>(new ComponentListModel<>(), new MessageListRenderer());
// TODO: messageList.setFocusTraversalKeysEnabled(false);
// messageList.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
DefaultListModel<Message> messageListModel = new DefaultListModel<>();
messageList.setModel(messageListModel);
messageList.setFont(new Font("Arial", Font.PLAIN, 17));
messageList.setFixedCellHeight(60);
// messageList.setFont(new Font("Arial", Font.PLAIN, 17));
// messageList.setFixedCellHeight(60);
messageList.setBorder(new EmptyBorder(space, space, space, space));
scrollPane.setViewportView(messageList);
@ -101,7 +101,7 @@ public class ChatWindow extends JFrame {
public void keyReleased(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_ENTER
&& ((Settings.getInstance().isEnterToSend() && e.getModifiersEx() == 0) || (e.getModifiersEx() == KeyEvent.CTRL_DOWN_MASK)))
postMessage(messageList);
postMessage();
}
});
@ -123,7 +123,7 @@ public class ChatWindow extends JFrame {
gbc_moveSelectionPostButton.insets = new Insets(space, space, space, space);
postButton.addActionListener((evt) -> { postMessage(messageList); });
postButton.addActionListener((evt) -> { postMessage(); });
contentPane.add(postButton, gbc_moveSelectionPostButton);
// Settings Button
@ -210,8 +210,8 @@ public class ChatWindow extends JFrame {
contentPane.setBackground(theme.getBackgroundColor());
contentPane.setForeground(theme.getUserNameColor());
// messageList
messageList.setSelectionForeground(theme.getUserNameColor());
messageList.setSelectionBackground(theme.getSelectionColor());
// messageList.setSelectionForeground(theme.getUserNameColor());
// messageList.setSelectionBackground(theme.getSelectionColor());
messageList.setForeground(theme.getMessageColorChat());
messageList.setBackground(theme.getCellColor());
// scrollPane
@ -238,7 +238,7 @@ public class ChatWindow extends JFrame {
userList.setBackground(theme.getCellColor());
}
private void postMessage(JList<Message> messageList) {
private void postMessage() {
if (!client.hasRecipient()) {
JOptionPane.showMessageDialog(this, "Please select a recipient!", "Cannot send message", JOptionPane.INFORMATION_MESSAGE);
return;