userListModel = new DefaultListModel<>();
+ users.getUser().forEach(user -> userListModel.addElement(user));
+ SwingUtilities.invokeLater(() -> userList.setModel(userListModel));
+ }).start();
}
/**
@@ -140,9 +200,7 @@ public class ChatWindow extends JFrame {
* @param message The message from which to return the text content
* @return The first content of type 'text'
*/
- public String getFirstTextContent(Message message) {
- return message.getContent().get(0).getText();
- }
+ private String getFirstTextContent(Message message) { return message.getContent().get(0).getText(); }
/**
* Appends a message with sender and message content to the message list.
@@ -150,12 +208,13 @@ public class ChatWindow extends JFrame {
* @param message The message to append
*/
private void appendMessageToChat(Message message) {
- listModel.addElement("" + " " + message.getMetaData().getSender()
- + " " + "
" + "
" + getFirstTextContent(message)
- + "");
+ messageListModel.addElement("" + "
"
+ + message.getMetaData().getSender() + " " + "
" + "
"
+ + getFirstTextContent(message) + "");
}
- public static void main(String[] args) {
+ public static void main(String[] args)
+ throws ClientProtocolException, IOException, SAXException, ParserConfigurationException {
EventQueue.invokeLater(() -> {
try {
ChatWindow frame = new ChatWindow();
diff --git a/src/main/java/envoy/client/ui/UserListRenderer.java b/src/main/java/envoy/client/ui/UserListRenderer.java
new file mode 100644
index 0000000..3c62e48
--- /dev/null
+++ b/src/main/java/envoy/client/ui/UserListRenderer.java
@@ -0,0 +1,41 @@
+package envoy.client.ui;
+
+import java.awt.Component;
+
+import javax.swing.JLabel;
+import javax.swing.JList;
+import javax.swing.ListCellRenderer;
+
+import envoy.schema.User;
+
+/**
+ * Project: envoy-client
+ * File: UserListRenderer.java
+ * Created: 12 Oct 2019
+ *
+ * @author Kai S. K. Engelbart
+ */
+public class UserListRenderer extends JLabel implements ListCellRenderer {
+
+ private static final long serialVersionUID = 5164417379767181198L;
+
+ @Override
+ public Component getListCellRendererComponent(JList extends User> list, User value, int index, boolean isSelected,
+ boolean cellHasFocus) {
+ if (isSelected) {
+ setBackground(list.getSelectionBackground());
+ setForeground(list.getSelectionForeground());
+ } else {
+ setBackground(list.getBackground());
+ setForeground(list.getForeground());
+ }
+
+ // Enable background rendering
+ setOpaque(true);
+
+ setText(value.getName());
+ setFont(list.getFont());
+
+ return this;
+ }
+}