Working on line wrapping and message height (borders currently broken)
This commit is contained in:
parent
561f16f261
commit
42feefdbd5
@ -53,7 +53,6 @@ public class ComponentList<E> extends JPanel {
|
||||
*/
|
||||
public ComponentList(ComponentListModel<E> model, ComponentListCellRenderer<E> renderer) {
|
||||
this(renderer);
|
||||
this.model = model;
|
||||
setModel(model);
|
||||
}
|
||||
|
||||
|
@ -10,7 +10,6 @@ import javax.swing.*;
|
||||
import envoy.client.data.Settings;
|
||||
import envoy.client.ui.Color;
|
||||
import envoy.client.ui.IconUtil;
|
||||
import envoy.client.ui.Theme;
|
||||
import envoy.client.ui.list.ComponentList;
|
||||
import envoy.client.ui.list.ComponentListCellRenderer;
|
||||
import envoy.data.Message;
|
||||
@ -40,13 +39,14 @@ public class MessageListRenderer implements ComponentListCellRenderer<Message> {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Handle message attachments
|
||||
|
||||
@Override
|
||||
public JPanel getListCellComponent(ComponentList<? extends Message> list, Message message, boolean isSelected) {
|
||||
final Theme theme = Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme());
|
||||
final var theme = Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme());
|
||||
|
||||
// panel
|
||||
final JPanel panel = new JPanel();
|
||||
// Panel
|
||||
final var panel = new JPanel();
|
||||
|
||||
GridBagLayout gbl_panel = new GridBagLayout();
|
||||
gbl_panel.columnWidths = new int[] { 1, 1 };
|
||||
@ -57,30 +57,21 @@ public class MessageListRenderer implements ComponentListCellRenderer<Message> {
|
||||
panel.setLayout(gbl_panel);
|
||||
panel.setBackground(isSelected ? theme.getSelectionColor() : theme.getCellColor());
|
||||
|
||||
// TODO: Handle message attachments
|
||||
|
||||
// content variables
|
||||
final String status = message.getStatus().toString();
|
||||
final String date = new SimpleDateFormat("dd.MM.yyyy HH:mm").format(message.getCreationDate());
|
||||
final String text = message.getText();
|
||||
|
||||
// date Label - The Label that displays the creation date of a message
|
||||
JLabel dateLabel = new JLabel();
|
||||
dateLabel.setText(date);
|
||||
// Date Label - The Label that displays the creation date of a message
|
||||
var dateLabel = new JLabel(new SimpleDateFormat("dd.MM.yyyy HH:mm").format(message.getCreationDate()));
|
||||
dateLabel.setForeground(theme.getDateColor());
|
||||
dateLabel.setAlignmentX(1f);
|
||||
dateLabel.setFont(new Font("Arial", Font.PLAIN, 12));
|
||||
dateLabel.setPreferredSize(dateLabel.getPreferredSize());
|
||||
|
||||
GridBagConstraints gbc_dateLabel = new GridBagConstraints();
|
||||
var gbc_dateLabel = new GridBagConstraints();
|
||||
gbc_dateLabel.fill = GridBagConstraints.BOTH;
|
||||
gbc_dateLabel.gridx = 0;
|
||||
gbc_dateLabel.gridy = 0;
|
||||
panel.add(dateLabel, gbc_dateLabel);
|
||||
|
||||
|
||||
// Message area - The JTextArea that displays the text content of a message.
|
||||
var messageTextArea = new JTextArea(text);
|
||||
var messageTextArea = new JTextArea(message.getText());
|
||||
messageTextArea.setLineWrap(true);
|
||||
messageTextArea.setWrapStyleWord(true);
|
||||
messageTextArea.setForeground(theme.getMessageTextColor());
|
||||
@ -88,51 +79,49 @@ public class MessageListRenderer implements ComponentListCellRenderer<Message> {
|
||||
messageTextArea.setBackground(Color.red);
|
||||
messageTextArea.setEditable(false);
|
||||
messageTextArea.setFont(new Font("Arial", Font.PLAIN, 14));
|
||||
// messageTextArea.setPreferredSize(messageTextArea.getPreferredSize());
|
||||
messageTextArea.setSize(list.getWidth() - 1, 200);
|
||||
|
||||
GridBagConstraints gbc_messageTextArea = new GridBagConstraints();
|
||||
var gbc_messageTextArea = new GridBagConstraints();
|
||||
gbc_messageTextArea.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbc_messageTextArea.gridx = 0;
|
||||
gbc_messageTextArea.gridy = 1;
|
||||
panel.add(messageTextArea, gbc_messageTextArea);
|
||||
|
||||
// Status Label - displays the status of the message
|
||||
var statusLabel = new JLabel(statusIcons.get(message.getStatus()));
|
||||
|
||||
// status Label - displays the status of the message
|
||||
JLabel statusLabel = new JLabel(statusIcons.get(message.getStatus()));
|
||||
|
||||
GridBagConstraints gbc_statusLabel = new GridBagConstraints();
|
||||
var gbc_statusLabel = new GridBagConstraints();
|
||||
gbc_statusLabel.fill = GridBagConstraints.BOTH;
|
||||
gbc_statusLabel.gridx = 1;
|
||||
gbc_statusLabel.gridy = 1;
|
||||
panel.add(statusLabel, gbc_statusLabel);
|
||||
|
||||
// Forwarding
|
||||
if (message.isForwarded()) try {
|
||||
var forwardLabel = new JLabel("Forwarded", new ImageIcon(ClassLoader.getSystemResourceAsStream(null).readAllBytes()),
|
||||
SwingConstants.CENTER);
|
||||
if (message.isForwarded()) {
|
||||
// TODO: icon
|
||||
var forwardLabel = new JLabel("Forwarded", null, SwingConstants.CENTER);
|
||||
forwardLabel.setBackground(panel.getBackground());
|
||||
forwardLabel.setForeground(Color.lightGray);
|
||||
|
||||
GridBagConstraints gbc_forwardLabel = new GridBagConstraints();
|
||||
|
||||
var gbc_forwardLabel = new GridBagConstraints();
|
||||
gbc_forwardLabel.fill = GridBagConstraints.BOTH;
|
||||
gbc_forwardLabel.gridx = 1;
|
||||
gbc_forwardLabel.gridy = 0;
|
||||
panel.add(forwardLabel, gbc_forwardLabel);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
int padding = (int) (list.getWidth() * 0.35);
|
||||
|
||||
// Define some space to the messages below
|
||||
panel.setBorder(BorderFactory.createCompoundBorder(
|
||||
BorderFactory.createEmptyBorder(0, 0, 0, padding),
|
||||
panel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(0, 0, 0, padding),
|
||||
BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(), BorderFactory.createEtchedBorder())));
|
||||
|
||||
var size = new Dimension(list.getWidth(), (int) panel.getPreferredSize().getHeight());
|
||||
var size = new Dimension(list.getWidth() - 50, panel.getPreferredSize().height);
|
||||
|
||||
// panel.setPreferredSize(panel.getPreferredSize());
|
||||
panel.setPreferredSize(size);
|
||||
panel.setMinimumSize(size);
|
||||
panel.setMaximumSize(size);
|
||||
// System.out.println(panel.getMaximumSize());
|
||||
|
||||
return panel;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user