Revised code according to reviews by @delvh and @CyB3RC0nN0R
This commit is contained in:
parent
3c8a4c445f
commit
507e249512
@ -54,15 +54,15 @@ public class ChatWindow extends JFrame {
|
|||||||
private LocalDB localDB;
|
private LocalDB localDB;
|
||||||
// GUI components
|
// GUI components
|
||||||
private JPanel contentPane = new JPanel();
|
private JPanel contentPane = new JPanel();
|
||||||
private PrimaryTextArea messageEnterTextArea;
|
private PrimaryTextArea messageEnterTextArea = new PrimaryTextArea(space);
|
||||||
private JList<User> userList = new JList<>();
|
private JList<User> userList = new JList<>();
|
||||||
private Chat currentChat;
|
private Chat currentChat;
|
||||||
private JList<Message> messageList = new JList<>();
|
private JList<Message> messageList = new JList<>();
|
||||||
private JScrollPane scrollPane = new JScrollPane();
|
private JScrollPane scrollPane = new JScrollPane();
|
||||||
private JTextPane textPane = new JTextPane();
|
private JTextPane textPane = new JTextPane();
|
||||||
// private JCheckBox jCbChangeMode;
|
// private JCheckBox jCbChangeMode;
|
||||||
private PrimaryButton postButton;
|
private PrimaryButton postButton = new PrimaryButton("Post");
|
||||||
private PrimaryButton settingsButton;
|
private PrimaryButton settingsButton = new PrimaryButton("Settings");
|
||||||
|
|
||||||
private static int space = 4;
|
private static int space = 4;
|
||||||
|
|
||||||
@ -76,7 +76,8 @@ public class ChatWindow extends JFrame {
|
|||||||
setBounds(100, 100, 600, 800);
|
setBounds(100, 100, 600, 800);
|
||||||
setTitle("Envoy");
|
setTitle("Envoy");
|
||||||
setLocationRelativeTo(null);
|
setLocationRelativeTo(null);
|
||||||
setIconImage(Toolkit.getDefaultToolkit().createImage(getClass().getClassLoader().getResource("envoy_logo.png")));
|
setIconImage(
|
||||||
|
Toolkit.getDefaultToolkit().createImage(getClass().getClassLoader().getResource("envoy_logo.png")));
|
||||||
|
|
||||||
// Save chats when window closes
|
// Save chats when window closes
|
||||||
addWindowListener(new WindowAdapter() {
|
addWindowListener(new WindowAdapter() {
|
||||||
@ -124,9 +125,6 @@ public class ChatWindow extends JFrame {
|
|||||||
gbc_scrollPane.insets = new Insets(space, space, space, space);
|
gbc_scrollPane.insets = new Insets(space, space, space, space);
|
||||||
contentPane.add(scrollPane, gbc_scrollPane);
|
contentPane.add(scrollPane, gbc_scrollPane);
|
||||||
|
|
||||||
// Checks for changed Message
|
|
||||||
messageEnterTextArea = new PrimaryTextArea(space);
|
|
||||||
|
|
||||||
// Message enter field
|
// Message enter field
|
||||||
messageEnterTextArea.addKeyListener(new KeyAdapter() {
|
messageEnterTextArea.addKeyListener(new KeyAdapter() {
|
||||||
|
|
||||||
@ -140,7 +138,6 @@ public class ChatWindow extends JFrame {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
GridBagConstraints gbc_messageEnterTextfield = new GridBagConstraints();
|
GridBagConstraints gbc_messageEnterTextfield = new GridBagConstraints();
|
||||||
gbc_messageEnterTextfield.fill = GridBagConstraints.BOTH;
|
gbc_messageEnterTextfield.fill = GridBagConstraints.BOTH;
|
||||||
gbc_messageEnterTextfield.gridx = 1;
|
gbc_messageEnterTextfield.gridx = 1;
|
||||||
@ -151,7 +148,6 @@ public class ChatWindow extends JFrame {
|
|||||||
contentPane.add(messageEnterTextArea, gbc_messageEnterTextfield);
|
contentPane.add(messageEnterTextArea, gbc_messageEnterTextfield);
|
||||||
|
|
||||||
// Post Button
|
// Post Button
|
||||||
postButton = new PrimaryButton("Post");
|
|
||||||
GridBagConstraints gbc_moveSelectionPostButton = new GridBagConstraints();
|
GridBagConstraints gbc_moveSelectionPostButton = new GridBagConstraints();
|
||||||
|
|
||||||
gbc_moveSelectionPostButton.fill = GridBagConstraints.BOTH;
|
gbc_moveSelectionPostButton.fill = GridBagConstraints.BOTH;
|
||||||
@ -164,8 +160,6 @@ public class ChatWindow extends JFrame {
|
|||||||
contentPane.add(postButton, gbc_moveSelectionPostButton);
|
contentPane.add(postButton, gbc_moveSelectionPostButton);
|
||||||
|
|
||||||
// Settings Button
|
// Settings Button
|
||||||
settingsButton = new PrimaryButton("Settings");
|
|
||||||
|
|
||||||
GridBagConstraints gbc_moveSelectionSettingsButton = new GridBagConstraints();
|
GridBagConstraints gbc_moveSelectionSettingsButton = new GridBagConstraints();
|
||||||
|
|
||||||
gbc_moveSelectionSettingsButton.fill = GridBagConstraints.BOTH;
|
gbc_moveSelectionSettingsButton.fill = GridBagConstraints.BOTH;
|
||||||
@ -207,7 +201,11 @@ public class ChatWindow extends JFrame {
|
|||||||
final User user = selectedUserList.getSelectedValue();
|
final User user = selectedUserList.getSelectedValue();
|
||||||
client.setRecipient(user);
|
client.setRecipient(user);
|
||||||
|
|
||||||
currentChat = localDB.getChats().stream().filter(chat -> chat.getRecipient().getID() == user.getID()).findFirst().get();
|
currentChat = localDB.getChats()
|
||||||
|
.stream()
|
||||||
|
.filter(chat -> chat.getRecipient().getID() == user.getID())
|
||||||
|
.findFirst()
|
||||||
|
.get();
|
||||||
|
|
||||||
// Set all unread messages in the chat to read
|
// Set all unread messages in the chat to read
|
||||||
readCurrentChat();
|
readCurrentChat();
|
||||||
@ -241,7 +239,6 @@ public class ChatWindow extends JFrame {
|
|||||||
contentPane.revalidate();
|
contentPane.revalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used to immediately reload the ChatWindow when settings were changed.
|
* Used to immediately reload the ChatWindow when settings were changed.
|
||||||
*
|
*
|
||||||
@ -373,4 +370,3 @@ public class ChatWindow extends JFrame {
|
|||||||
*/
|
*/
|
||||||
private void readCurrentChat() { if (currentChat != null) { localDB.setMessagesToRead(currentChat); } }
|
private void readCurrentChat() { if (currentChat != null) { localDB.setMessagesToRead(currentChat); } }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,6 +11,7 @@ import javax.swing.JButton;
|
|||||||
*
|
*
|
||||||
* @author Kai S. K. Engelbart
|
* @author Kai S. K. Engelbart
|
||||||
* @author Maximilian Käfer
|
* @author Maximilian Käfer
|
||||||
|
* @since Envoy v0.2-alpha
|
||||||
*/
|
*/
|
||||||
public class PrimaryButton extends JButton {
|
public class PrimaryButton extends JButton {
|
||||||
|
|
||||||
@ -35,8 +36,6 @@ public class PrimaryButton extends JButton {
|
|||||||
*/
|
*/
|
||||||
public PrimaryButton(String title, int arcSize) {
|
public PrimaryButton(String title, int arcSize) {
|
||||||
super(title);
|
super(title);
|
||||||
// setForeground(new Color(255, 255, 255));
|
|
||||||
// setBackground(new Color(102, 51, 153));
|
|
||||||
setBorderPainted(false);
|
setBorderPainted(false);
|
||||||
setFocusPainted(false);
|
setFocusPainted(false);
|
||||||
setContentAreaFilled(false);
|
setContentAreaFilled(false);
|
||||||
|
@ -12,6 +12,7 @@ import javax.swing.border.EmptyBorder;
|
|||||||
* Created: <strong>07.12.2019</strong><br>
|
* Created: <strong>07.12.2019</strong><br>
|
||||||
*
|
*
|
||||||
* @author Maximilian Käfer
|
* @author Maximilian Käfer
|
||||||
|
* @since Envoy v0.2-alpha
|
||||||
*/
|
*/
|
||||||
public class PrimaryTextArea extends JTextArea {
|
public class PrimaryTextArea extends JTextArea {
|
||||||
|
|
||||||
@ -20,7 +21,7 @@ public class PrimaryTextArea extends JTextArea {
|
|||||||
private int arcSize;
|
private int arcSize;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates TextArea
|
* Creates the text area
|
||||||
*
|
*
|
||||||
* @param borderSpace
|
* @param borderSpace
|
||||||
* @since Envoy 0.2-alpha
|
* @since Envoy 0.2-alpha
|
||||||
@ -28,10 +29,10 @@ public class PrimaryTextArea extends JTextArea {
|
|||||||
public PrimaryTextArea(int borderSpace) { this(6, borderSpace); }
|
public PrimaryTextArea(int borderSpace) { this(6, borderSpace); }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates TextArea
|
* Creates the text area
|
||||||
*
|
*
|
||||||
* @param arcSize
|
* @param arcSize
|
||||||
* @param borderSpace
|
* @param borderSpace - the insets of the border on all four sides
|
||||||
* @since Envoy 0.2-alpha
|
* @since Envoy 0.2-alpha
|
||||||
*/
|
*/
|
||||||
public PrimaryTextArea(int arcSize, int borderSpace) {
|
public PrimaryTextArea(int arcSize, int borderSpace) {
|
||||||
@ -54,7 +55,7 @@ public class PrimaryTextArea extends JTextArea {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the arcSize
|
* @return the arcSize - the diameter of the arc at the four corners.
|
||||||
* @since Envoy 0.2-alpha
|
* @since Envoy 0.2-alpha
|
||||||
*/
|
*/
|
||||||
public int getArcSize() { return arcSize; }
|
public int getArcSize() { return arcSize; }
|
||||||
|
Reference in New Issue
Block a user