Added PrimaryScrollPane class with default scroll pane UI settings
This commit is contained in:
@ -1,6 +1,5 @@
|
||||
package envoy.client.ui;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.ComponentOrientation;
|
||||
import java.awt.Font;
|
||||
import java.awt.GridBagConstraints;
|
||||
@ -20,7 +19,6 @@ import javax.swing.JFrame;
|
||||
import javax.swing.JList;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JTextPane;
|
||||
import javax.swing.ListSelectionModel;
|
||||
import javax.swing.SwingUtilities;
|
||||
@ -54,17 +52,15 @@ public class ChatWindow extends JFrame {
|
||||
private LocalDB localDB;
|
||||
|
||||
// GUI components
|
||||
private JPanel contentPane = new JPanel();
|
||||
private PrimaryTextArea messageEnterTextArea = new PrimaryTextArea(space);
|
||||
private JList<User> userList = new JList<>();
|
||||
private Chat currentChat;
|
||||
private JList<Message> messageList = new JList<>();
|
||||
private JScrollPane scrollPane = new JScrollPane();
|
||||
private int verticalScrollBarMaximumValue = scrollPane.getVerticalScrollBar().getMaximum();
|
||||
private boolean chatOpened = false;
|
||||
private JTextPane textPane = new JTextPane();
|
||||
private PrimaryButton postButton = new PrimaryButton("Post");
|
||||
private PrimaryButton settingsButton = new PrimaryButton("Settings");
|
||||
private JPanel contentPane = new JPanel();
|
||||
private PrimaryTextArea messageEnterTextArea = new PrimaryTextArea(space);
|
||||
private JList<User> userList = new JList<>();
|
||||
private Chat currentChat;
|
||||
private JList<Message> messageList = new JList<>();
|
||||
private PrimaryScrollPane scrollPane = new PrimaryScrollPane();
|
||||
private JTextPane textPane = new JTextPane();
|
||||
private PrimaryButton postButton = new PrimaryButton("Post");
|
||||
private PrimaryButton settingsButton = new PrimaryButton("Settings");
|
||||
|
||||
private static int space = 4;
|
||||
|
||||
@ -115,7 +111,6 @@ public class ChatWindow extends JFrame {
|
||||
messageList.setBorder(new EmptyBorder(space, space, space, space));
|
||||
|
||||
scrollPane.setViewportView(messageList);
|
||||
scrollPane.setBorder(null);
|
||||
|
||||
GridBagConstraints gbc_scrollPane = new GridBagConstraints();
|
||||
gbc_scrollPane.fill = GridBagConstraints.BOTH;
|
||||
@ -210,7 +205,7 @@ public class ChatWindow extends JFrame {
|
||||
textPane.setText(currentChat.getRecipient().getName());
|
||||
|
||||
messageList.setModel(currentChat.getModel());
|
||||
chatOpened = true;
|
||||
scrollPane.setChatOpened(true);
|
||||
contentPane.revalidate();
|
||||
}
|
||||
});
|
||||
@ -254,35 +249,7 @@ public class ChatWindow extends JFrame {
|
||||
messageList.setForeground(theme.getMessageColorChat());
|
||||
messageList.setBackground(theme.getCellColor());
|
||||
// scrollPane
|
||||
scrollPane.setForeground(theme.getBackgroundColor());
|
||||
scrollPane.setBackground(theme.getCellColor());
|
||||
|
||||
// Scroll Bar Styling
|
||||
scrollPane.getVerticalScrollBar().setBackground(theme.getCellColor());
|
||||
scrollPane.getVerticalScrollBar()
|
||||
.setUI(new PrimaryScrollBar(5, theme.getInteractableBackgroundColor(), new Color(theme.getInteractableBackgroundColor().getRGB() - 50),
|
||||
new Color(theme.getInteractableBackgroundColor().getRGB() + 170), true));
|
||||
scrollPane.getHorizontalScrollBar().setBackground(theme.getCellColor());
|
||||
scrollPane.getHorizontalScrollBar()
|
||||
.setUI(new PrimaryScrollBar(5, theme.getInteractableBackgroundColor(), new Color(theme.getInteractableBackgroundColor().getRGB() - 50),
|
||||
new Color(theme.getInteractableBackgroundColor().getRGB() + 170), false));
|
||||
|
||||
// Autoscroll
|
||||
scrollPane.getVerticalScrollBar().addAdjustmentListener(e -> {
|
||||
if ((verticalScrollBarMaximumValue - e.getAdjustable().getMaximum()) == 0) { return; }
|
||||
|
||||
if (chatOpened == true) {
|
||||
e.getAdjustable().setValue(e.getAdjustable().getMaximum());
|
||||
verticalScrollBarMaximumValue = scrollPane.getVerticalScrollBar().getMaximum();
|
||||
chatOpened = false;
|
||||
return;
|
||||
}
|
||||
if (scrollPane.getVerticalScrollBar().getValue() + scrollPane.getVerticalScrollBar().getVisibleAmount()
|
||||
+ 100 >= scrollPane.getVerticalScrollBar().getMaximum()) {
|
||||
e.getAdjustable().setValue(e.getAdjustable().getMaximum());
|
||||
verticalScrollBarMaximumValue = scrollPane.getVerticalScrollBar().getMaximum();
|
||||
}
|
||||
});
|
||||
scrollPane.applyTheme(theme);
|
||||
|
||||
// messageEnterTextArea
|
||||
messageEnterTextArea.setCaretColor(theme.getTypingMessageColor());
|
||||
|
Reference in New Issue
Block a user