Working on message scaling
This commit is contained in:
parent
42feefdbd5
commit
6a2cb38bd2
@ -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);
|
||||
|
||||
|
@ -30,10 +30,12 @@ import envoy.data.Message.MessageStatus;
|
||||
public class MessageListRenderer implements ComponentListCellRenderer<Message> {
|
||||
|
||||
private static EnumMap<MessageStatus, ImageIcon> 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<Message> {
|
||||
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<Message> {
|
||||
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<Message> {
|
||||
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);
|
||||
|
Reference in New Issue
Block a user