Moved dimension and spacing calculation to MessageListRenderer

This commit is contained in:
Kai S. K. Engelbart 2020-02-02 11:37:46 +01:00
parent 07b5ee841a
commit 82fd57d19c
2 changed files with 12 additions and 17 deletions

View File

@ -1,11 +1,9 @@
package envoy.client.ui;
import java.awt.Dimension;
import java.text.SimpleDateFormat;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.*;
import envoy.client.Settings;
import envoy.client.ui.list.ComponentList;
@ -31,6 +29,7 @@ public class MessageListRenderer implements ComponentListCellRenderer<Message> {
if (isSelected) {
panel.setBackground(Color.DARK_GRAY);
panel.setForeground(Color.RED);
// TODO: Selection
// setBackground(list.getSelectionBackground());
// setForeground(list.getSelectionForeground());
} else {
@ -50,8 +49,6 @@ public class MessageListRenderer implements ComponentListCellRenderer<Message> {
// Getting the DateColor in the Chat of the current theme
String dateColor = Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()).getDateColorChat().toHex();
//JLabel textLabel = new JLabel(text + ": " + state);
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,
@ -59,8 +56,14 @@ public class MessageListRenderer implements ComponentListCellRenderer<Message> {
text,
state)));
// Define some space to the components above and below
panel.setBorder(new EmptyBorder(0, 0, 15, 0));
// 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;
}

View File

@ -1,9 +1,6 @@
package envoy.client.ui.list;
import java.awt.Dimension;
import javax.swing.BoxLayout;
import javax.swing.JComponent;
import javax.swing.JPanel;
/**
@ -77,12 +74,7 @@ public class ComponentList<E> extends JPanel {
* @since Envoy v0.3-alpha
*/
void add(E elem) {
JComponent c = renderer.getListCellComponent(this, elem, false);
Dimension size = new Dimension(getWidth(), 50);
c.setMaximumSize(size);
c.setMinimumSize(size);
c.setPreferredSize(size);
add(c);
add(renderer.getListCellComponent(this, elem, false));
}
/**