Merge branch 'develop' into f/sync
This commit is contained in:
@ -6,6 +6,8 @@ import java.awt.Font;
|
||||
import java.awt.GridBagConstraints;
|
||||
import java.awt.GridBagLayout;
|
||||
import java.awt.Insets;
|
||||
import java.awt.event.KeyAdapter;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
|
||||
@ -39,7 +41,7 @@ import envoy.schema.User;
|
||||
* @author Kai S. K. Engelbart
|
||||
* @author Maximilian Käfer
|
||||
* @author Leon Hofmeister
|
||||
* @since Envoy 0.1
|
||||
* @since Envoy v0.1-alpha
|
||||
*/
|
||||
public class ChatWindow extends JFrame {
|
||||
|
||||
@ -53,6 +55,8 @@ public class ChatWindow extends JFrame {
|
||||
private JList<User> userList = new JList<>();
|
||||
private Chat currentChat;
|
||||
|
||||
private JTextArea messageEnterTextArea;
|
||||
|
||||
public ChatWindow(Client client, LocalDB localDB) {
|
||||
this.client = client;
|
||||
this.localDB = localDB;
|
||||
@ -77,7 +81,7 @@ public class ChatWindow extends JFrame {
|
||||
gbl_contentPane.columnWidths = new int[] { 1, 1, 1 };
|
||||
gbl_contentPane.rowHeights = new int[] { 1, 1, 1 };
|
||||
gbl_contentPane.columnWeights = new double[] { 0.3, 1.0, 0.1 };
|
||||
gbl_contentPane.rowWeights = new double[] { 0.05, 1, 0.07 };
|
||||
gbl_contentPane.rowWeights = new double[] { 0.05, 1.0, 0.07 };
|
||||
contentPane.setLayout(gbl_contentPane);
|
||||
|
||||
JList<Message> messageList = new JList<>();
|
||||
@ -113,23 +117,38 @@ public class ChatWindow extends JFrame {
|
||||
contentPane.add(scrollPane, gbc_scrollPane);
|
||||
|
||||
// Message enter field
|
||||
JTextArea messageEnterTextfield = new JTextArea();
|
||||
messageEnterTextfield.setCaretColor(new Color(255, 255, 255));
|
||||
messageEnterTextfield.setForeground(new Color(255, 255, 255));
|
||||
messageEnterTextfield.setBackground(new Color(51, 51, 51));
|
||||
messageEnterTextfield.setLineWrap(true);
|
||||
messageEnterTextfield.setBorder(null);
|
||||
messageEnterTextfield.setFont(new Font("Arial", Font.PLAIN, 17));
|
||||
messageEnterTextfield.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||
messageEnterTextArea = new JTextArea();
|
||||
messageEnterTextArea.addKeyListener(new KeyAdapter() {
|
||||
|
||||
GridBagConstraints gbc_moveSelectionMessageEnterTextfield = new GridBagConstraints();
|
||||
gbc_moveSelectionMessageEnterTextfield.fill = GridBagConstraints.BOTH;
|
||||
gbc_moveSelectionMessageEnterTextfield.gridx = 1;
|
||||
gbc_moveSelectionMessageEnterTextfield.gridy = 2;
|
||||
@Override
|
||||
public void keyReleased(KeyEvent e) {
|
||||
|
||||
gbc_moveSelectionMessageEnterTextfield.insets = new Insets(10, 10, 10, 10);
|
||||
if (e.getKeyCode() == KeyEvent.VK_ENTER && ((SettingsScreen.enterToSend && e.getModifiersEx() == 0)
|
||||
|| (e.getModifiersEx() == KeyEvent.CTRL_DOWN_MASK))) {
|
||||
postMessage(client, messageList);
|
||||
|
||||
contentPane.add(messageEnterTextfield, gbc_moveSelectionMessageEnterTextfield);
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
// Checks for changed Message
|
||||
messageEnterTextArea.setWrapStyleWord(true);
|
||||
messageEnterTextArea.setCaretColor(new Color(255, 255, 255));
|
||||
messageEnterTextArea.setForeground(new Color(255, 255, 255));
|
||||
messageEnterTextArea.setBackground(new Color(51, 51, 51));
|
||||
messageEnterTextArea.setLineWrap(true);
|
||||
messageEnterTextArea.setBorder(null);
|
||||
messageEnterTextArea.setFont(new Font("Arial", Font.PLAIN, 17));
|
||||
messageEnterTextArea.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||
|
||||
GridBagConstraints gbc_messageEnterTextfield = new GridBagConstraints();
|
||||
gbc_messageEnterTextfield.fill = GridBagConstraints.BOTH;
|
||||
gbc_messageEnterTextfield.gridx = 1;
|
||||
gbc_messageEnterTextfield.gridy = 2;
|
||||
|
||||
gbc_messageEnterTextfield.insets = new Insets(10, 10, 10, 10);
|
||||
|
||||
contentPane.add(messageEnterTextArea, gbc_messageEnterTextfield);
|
||||
|
||||
// Post Button
|
||||
JButton postButton = new JButton("Post");
|
||||
@ -145,6 +164,7 @@ public class ChatWindow extends JFrame {
|
||||
|
||||
gbc_moveSelectionPostButton.insets = new Insets(10, 10, 10, 10);
|
||||
|
||||
|
||||
postButton.addActionListener((evt) -> {
|
||||
if (!client.hasRecipient()) {
|
||||
JOptionPane.showMessageDialog(this,
|
||||
@ -153,27 +173,58 @@ public class ChatWindow extends JFrame {
|
||||
JOptionPane.INFORMATION_MESSAGE);
|
||||
}
|
||||
|
||||
if (!messageEnterTextfield.getText().isEmpty()) try {
|
||||
// Create and send message object
|
||||
final Message message = localDB.createMessage(messageEnterTextArea.getText(),
|
||||
currentChat.getRecipient());
|
||||
localDB.addWaitingMessageToLocalDB(message, currentChat);
|
||||
messageList.setModel(currentChat.getModel());
|
||||
|
||||
// Create and send message object
|
||||
final Message message = localDB.createMessage(messageEnterTextfield.getText(),
|
||||
currentChat.getRecipient());
|
||||
localDB.addWaitingMessageToLocalDB(message, currentChat);
|
||||
messageList.setModel(currentChat.getModel());
|
||||
contentPane.add(postButton, gbc_moveSelectionPostButton);
|
||||
|
||||
// Clear text field
|
||||
messageEnterTextfield.setText("");
|
||||
contentPane.revalidate();
|
||||
if (!messageEnterTextArea.getText().isEmpty()) try {
|
||||
|
||||
// Create and send message object
|
||||
final Message message = localDB.createMessage(messageEnterTextArea.getText(), currentChat.getRecipient());
|
||||
localDB.addWaitingMessageToLocalDB(message, currentChat);
|
||||
messageList.setModel(currentChat.getModel());
|
||||
|
||||
// Clear text field
|
||||
messageEnterTextArea.setText("");
|
||||
contentPane.revalidate();
|
||||
} catch (Exception e) {
|
||||
JOptionPane.showMessageDialog(this,
|
||||
"An exception occured while sending a message. See the log for more details.",
|
||||
"Exception occured",
|
||||
JOptionPane.ERROR_MESSAGE);
|
||||
e.printStackTrace();
|
||||
});
|
||||
|
||||
|
||||
// Settings Button
|
||||
JButton settingsButton = new JButton("Settings");
|
||||
settingsButton.setForeground(new Color(255, 255, 255));
|
||||
settingsButton.setBackground(new Color(102, 51, 153));
|
||||
settingsButton.setBorderPainted(false);
|
||||
|
||||
GridBagConstraints gbc_moveSelectionSettingsButton = new GridBagConstraints();
|
||||
|
||||
|
||||
gbc_moveSelectionSettingsButton.fill = GridBagConstraints.BOTH;
|
||||
gbc_moveSelectionSettingsButton.gridx = 2;
|
||||
gbc_moveSelectionSettingsButton.gridy = 0;
|
||||
|
||||
gbc_moveSelectionSettingsButton.insets = new Insets(10, 10, 10, 10);
|
||||
|
||||
settingsButton.addActionListener((evt) -> {
|
||||
try {
|
||||
SettingsScreen.open(localDB.getUser().getName());
|
||||
} catch (Exception e) {
|
||||
JOptionPane.showMessageDialog(this,
|
||||
"An exception occured while sending a message. See the log for more details.",
|
||||
"Exception occured",
|
||||
JOptionPane.ERROR_MESSAGE);
|
||||
SettingsScreen.open();
|
||||
System.err.println("An error occured while opening the settings screen: " + e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
|
||||
contentPane.add(postButton, gbc_moveSelectionPostButton);
|
||||
contentPane.add(settingsButton, gbc_moveSelectionSettingsButton);
|
||||
|
||||
// Partner name display
|
||||
JTextPane textPane = new JTextPane();
|
||||
@ -183,10 +234,9 @@ public class ChatWindow extends JFrame {
|
||||
textPane.setFont(new Font("Arial", Font.PLAIN, 20));
|
||||
|
||||
GridBagConstraints gbc_partnerName = new GridBagConstraints();
|
||||
gbc_partnerName.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbc_partnerName.gridwidth = 2;
|
||||
gbc_partnerName.gridx = 1;
|
||||
gbc_partnerName.gridy = 0;
|
||||
gbc_partnerName.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbc_partnerName.gridx = 1;
|
||||
gbc_partnerName.gridy = 0;
|
||||
|
||||
gbc_partnerName.insets = new Insets(0, 10, 0, 10);
|
||||
contentPane.add(textPane, gbc_partnerName);
|
||||
@ -241,9 +291,12 @@ public class ChatWindow extends JFrame {
|
||||
contentPane.revalidate();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Initializes the elements of the user list by downloading them from the
|
||||
* server.
|
||||
*
|
||||
* @since Envoy v0.1-alpha
|
||||
*/
|
||||
private void loadUsersAndChats() {
|
||||
new Thread(() -> {
|
||||
|
Reference in New Issue
Block a user