63 lines
1.8 KiB
Java
63 lines
1.8 KiB
Java
package envoy.client.ui.renderer;
|
|
|
|
import java.awt.Component;
|
|
import java.awt.Dimension;
|
|
|
|
import javax.swing.JLabel;
|
|
import javax.swing.JList;
|
|
import javax.swing.ListCellRenderer;
|
|
|
|
import envoy.client.data.Settings;
|
|
import envoy.data.User;
|
|
import envoy.data.User.UserStatus;
|
|
|
|
/**
|
|
* Defines how the {@code UserList} is displayed.<br>
|
|
* <br>
|
|
* Project: <strong>envoy-client</strong><br>
|
|
* File: <strong>UserListRenderer.java</strong><br>
|
|
* Created: <strong>12 Oct 2019</strong><br>
|
|
*
|
|
* @author Kai S. K. Engelbart
|
|
* @author Maximilian Käfer
|
|
* @since Envoy v0.1-alpha
|
|
*/
|
|
public class UserListRenderer extends JLabel implements ListCellRenderer<User> {
|
|
|
|
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);
|
|
|
|
final String name = value.getName();
|
|
final UserStatus status = value.getStatus();
|
|
|
|
this.setPreferredSize(new Dimension(100, 35));
|
|
|
|
// Getting the UserNameColor of the current theme
|
|
String textColor = null;
|
|
textColor = Settings.getInstance().getCurrentTheme().getUserNameColor().toHex();
|
|
switch (status) {
|
|
case ONLINE:
|
|
setText(String
|
|
.format("<html><p style=\"color:#03fc20\"><b><small>%s</b></small><br><p style=\"color:%s\">%s</html>", status, textColor, name));
|
|
break;
|
|
case OFFLINE:
|
|
setText(String
|
|
.format("<html><p style=\"color:#fc0303\"><b><small>%s</b></small><br><p style=\"color:%s\">%s</html>", status, textColor, name));
|
|
break;
|
|
}
|
|
return this;
|
|
}
|
|
}
|