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