From 6a2cb38bd2f11ad83426fbd0f99f8162d695a43d Mon Sep 17 00:00:00 2001 From: CyB3RC0nN0R Date: Tue, 17 Mar 2020 09:37:19 +0100 Subject: [PATCH] Working on message scaling --- src/main/java/envoy/client/ui/ChatWindow.java | 8 ++++++- .../ui/renderer/MessageListRenderer.java | 24 +++++++++++-------- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/src/main/java/envoy/client/ui/ChatWindow.java b/src/main/java/envoy/client/ui/ChatWindow.java index 8e7dc55..5e87a00 100644 --- a/src/main/java/envoy/client/ui/ChatWindow.java +++ b/src/main/java/envoy/client/ui/ChatWindow.java @@ -131,7 +131,13 @@ public class ChatWindow extends JFrame { // updates list elements when list is resized @Override - public void componentResized(ComponentEvent e) { messageList.synchronizeModel(); } + public void componentResized(ComponentEvent e) { + messageList.synchronizeModel(); + var prefSize = e.getComponent().getPreferredSize(); + messageList.setMinimumSize(new Dimension(prefSize.width, 0)); + messageList.setMaximumSize(new Dimension(prefSize.width, Integer.MAX_VALUE)); + messageList.setPreferredSize(new Dimension(prefSize.width, messageList.getPreferredSize().height)); + } }); scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); diff --git a/src/main/java/envoy/client/ui/renderer/MessageListRenderer.java b/src/main/java/envoy/client/ui/renderer/MessageListRenderer.java index 911a419..f6b6596 100644 --- a/src/main/java/envoy/client/ui/renderer/MessageListRenderer.java +++ b/src/main/java/envoy/client/ui/renderer/MessageListRenderer.java @@ -30,10 +30,12 @@ import envoy.data.Message.MessageStatus; public class MessageListRenderer implements ComponentListCellRenderer { private static EnumMap statusIcons; + private static ImageIcon forwardIcon; static { try { statusIcons = IconUtil.loadByEnum(MessageStatus.class, 16); + // forwardIcon = IconUtil.load("icons/forward.png", 16); } catch (IOException e) { e.printStackTrace(); } @@ -46,7 +48,8 @@ public class MessageListRenderer implements ComponentListCellRenderer { final var theme = Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()); // Panel - final var panel = new JPanel(); + final var panel = new JPanel(); + final int padding = (int) (list.getWidth() * 0.35); GridBagLayout gbl_panel = new GridBagLayout(); gbl_panel.columnWidths = new int[] { 1, 1 }; @@ -76,10 +79,14 @@ public class MessageListRenderer implements ComponentListCellRenderer { messageTextArea.setWrapStyleWord(true); messageTextArea.setForeground(theme.getMessageTextColor()); messageTextArea.setAlignmentX(0.5f); - messageTextArea.setBackground(Color.red); + messageTextArea.setBackground(theme.getCellColor()); messageTextArea.setEditable(false); - messageTextArea.setFont(new Font("Arial", Font.PLAIN, 14)); - messageTextArea.setSize(list.getWidth() - 1, 200); + var font = new Font("Arial", Font.PLAIN, 14); + messageTextArea.setFont(font); + // var frc = new FontRenderContext(new AffineTransform(), true, true); + // messageTextArea.setSize(Math.min(list.getWidth() - padding, (int) + // font.getStringBounds(message.getText(), frc).getWidth()), 10); + messageTextArea.setSize(list.getWidth() - padding, 10); var gbc_messageTextArea = new GridBagConstraints(); gbc_messageTextArea.fill = GridBagConstraints.HORIZONTAL; @@ -110,13 +117,10 @@ public class MessageListRenderer implements ComponentListCellRenderer { panel.add(forwardLabel, gbc_forwardLabel); } - int padding = (int) (list.getWidth() * 0.35); + // Define an etched border and some space to the messages below + panel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(0, 0, 20, padding), BorderFactory.createEtchedBorder())); - // Define some space to the messages below - panel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(0, 0, 0, padding), - BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(), BorderFactory.createEtchedBorder()))); - - var size = new Dimension(list.getWidth() - 50, panel.getPreferredSize().height); + var size = new Dimension(list.getWidth(), panel.getPreferredSize().height); panel.setPreferredSize(size); panel.setMinimumSize(size);