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

View File

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