From 1fb4ddaa479e29b3b5391806b9e876fe73ab1fcb Mon Sep 17 00:00:00 2001 From: delvh Date: Sun, 15 Mar 2020 19:11:02 +0100 Subject: [PATCH] implemented UserComponentListRenderer --- src/main/java/envoy/client/ui/ChatWindow.java | 1 + .../renderer/UserComponentListRenderer.java | 78 +++++++++++++++++++ 2 files changed, 79 insertions(+) create mode 100644 src/main/java/envoy/client/ui/renderer/UserComponentListRenderer.java diff --git a/src/main/java/envoy/client/ui/ChatWindow.java b/src/main/java/envoy/client/ui/ChatWindow.java index e95de1c..8e7dc55 100644 --- a/src/main/java/envoy/client/ui/ChatWindow.java +++ b/src/main/java/envoy/client/ui/ChatWindow.java @@ -70,6 +70,7 @@ public class ChatWindow extends JFrame { private JTextPane textPane = new JTextPane(); private PrimaryButton postButton = new PrimaryButton("Post"); private PrimaryButton settingsButton = new PrimaryButton("Settings"); + private JPopupMenu contextMenu; // Contacts Header private JPanel contactsHeader = new JPanel(); diff --git a/src/main/java/envoy/client/ui/renderer/UserComponentListRenderer.java b/src/main/java/envoy/client/ui/renderer/UserComponentListRenderer.java new file mode 100644 index 0000000..f762eab --- /dev/null +++ b/src/main/java/envoy/client/ui/renderer/UserComponentListRenderer.java @@ -0,0 +1,78 @@ +package envoy.client.ui.renderer; + +import java.awt.BorderLayout; +import java.awt.Dimension; +import java.io.Serializable; + +import javax.swing.JComponent; +import javax.swing.JLabel; +import javax.swing.JPanel; + +import envoy.client.data.Settings; +import envoy.client.ui.Theme; +import envoy.client.ui.list.ComponentList; +import envoy.client.ui.list.ComponentListCellRenderer; +import envoy.data.User; +import envoy.data.User.UserStatus; + +/** + * Project: envoy-client
+ * File: UserComponentListRenderer.java
+ * Created: 15 Mar 2020
+ * + * @author Leon Hofmeister + * @since Envoy v0.1-beta + */ +public class UserComponentListRenderer implements ComponentListCellRenderer, Serializable { + + private static final long serialVersionUID = -2379244319112111284L; + + /** + * @since Envoy v0.1-beta + */ + public UserComponentListRenderer() {} + + @Override + public JComponent getListCellComponent(ComponentList list, User value, boolean isSelected) { + final JPanel panel = new JPanel(); + panel.setLayout(new BorderLayout()); + final Theme theme = Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()); + + // Panel background + panel.setBackground(isSelected ? theme.getSelectionColor() : theme.getCellColor()); + panel.setOpaque(true); + + panel.setPreferredSize(new Dimension(100, 35)); + + // TODO add profile picture support in BorderLayout.West + + JLabel username = new JLabel(value.getName()); + username.setForeground(theme.getUserNameColor()); + panel.add(username, BorderLayout.CENTER); + + final UserStatus status = value.getStatus(); + JLabel statusLabel = new JLabel(status.toString()); + java.awt.Color foreground; + switch (status) { + case OFFLINE: + foreground = java.awt.Color.LIGHT_GRAY; + break; + case AWAY: + foreground = java.awt.Color.YELLOW; + break; + case BUSY: + foreground = java.awt.Color.BLUE; + break; + case ONLINE: + foreground = java.awt.Color.GREEN; + break; + default: + foreground = java.awt.Color.LIGHT_GRAY; + break; + } + statusLabel.setForeground(foreground); + panel.add(statusLabel, BorderLayout.NORTH); + return panel; + } + +}