This repository has been archived on 2021-12-05. You can view files and clone it, but cannot push or open issues or pull requests.
envoy/src/main/java/envoy/client/ui/MessageListRenderer.java

70 lines
2.3 KiB
Java

package envoy.client.ui;
import java.awt.Dimension;
import java.text.SimpleDateFormat;
import javax.swing.*;
import envoy.client.Settings;
import envoy.client.ui.list.ComponentList;
import envoy.client.ui.list.ComponentListCellRenderer;
import envoy.data.Message;
/**
* Defines how a message is displayed.<br>
* <br>
* Project: <strong>envoy-client</strong><br>
* File: <strong>MessageListRenderer.java</strong><br>
* Created: <strong>19 Oct 2019</strong><br>
*
* @author Kai S. K. Engelbart
* @author Maximilian K&auml;fer
* @since Envoy v0.1-alpha
*/
public class MessageListRenderer implements ComponentListCellRenderer<Message> {
@Override
public JComponent getListCellComponent(ComponentList<? extends Message> list, Message value, boolean isSelected) {
final JPanel panel = new JPanel();
if (isSelected) {
panel.setBackground(Color.DARK_GRAY);
panel.setForeground(Color.RED);
// TODO: Selection
// setBackground(list.getSelectionBackground());
// setForeground(list.getSelectionForeground());
} else {
panel.setBackground(list.getBackground());
panel.setForeground(list.getForeground());
}
// TODO: Handle message attachments
final String text = value.getText();
final String state = value.getStatus().toString();
final String date = new SimpleDateFormat("dd.MM.yyyy HH.mm").format(value.getCreationDate());
// Getting the MessageColor in the Chat of the current theme
String textColor = Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()).getMessageColorChat().toHex();
// Getting the DateColor in the Chat of the current theme
String dateColor = Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()).getDateColorChat().toHex();
panel.add(new JLabel(String.format("<html><p style=\"color:%s\"><b><small>%s</b></small><br><p style=\"color:%s\">%s :%s</html>",
dateColor,
date,
textColor,
text,
state)));
// Define some space to the messages below
panel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(0, 0, 15, 0), BorderFactory.createEtchedBorder()));
// Define a maximum height of 50px
Dimension size = new Dimension(list.getWidth() - 25, 50);
panel.setMaximumSize(size);
panel.setMinimumSize(size);
panel.setPreferredSize(size);
return panel;
}
}