implemented UserComponentListRenderer

This commit is contained in:
delvh 2020-03-15 19:11:02 +01:00
parent 432a58330b
commit 1fb4ddaa47
2 changed files with 79 additions and 0 deletions

View File

@ -70,6 +70,7 @@ public class ChatWindow extends JFrame {
private JTextPane textPane = new JTextPane(); private JTextPane textPane = new JTextPane();
private PrimaryButton postButton = new PrimaryButton("Post"); private PrimaryButton postButton = new PrimaryButton("Post");
private PrimaryButton settingsButton = new PrimaryButton("Settings"); private PrimaryButton settingsButton = new PrimaryButton("Settings");
private JPopupMenu contextMenu;
// Contacts Header // Contacts Header
private JPanel contactsHeader = new JPanel(); private JPanel contactsHeader = new JPanel();

View File

@ -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: <strong>envoy-client</strong><br>
* File: <strong>UserComponentListRenderer.java</strong><br>
* Created: <strong>15 Mar 2020</strong><br>
*
* @author Leon Hofmeister
* @since Envoy v0.1-beta
*/
public class UserComponentListRenderer implements ComponentListCellRenderer<User>, Serializable {
private static final long serialVersionUID = -2379244319112111284L;
/**
* @since Envoy v0.1-beta
*/
public UserComponentListRenderer() {}
@Override
public JComponent getListCellComponent(ComponentList<? extends User> 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;
}
}