Added user list download
This commit is contained in:
@ -7,6 +7,9 @@ import java.awt.Font;
|
||||
import java.awt.GridBagConstraints;
|
||||
import java.awt.GridBagLayout;
|
||||
import java.awt.Insets;
|
||||
import java.awt.List;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import javax.swing.DefaultListModel;
|
||||
import javax.swing.JButton;
|
||||
@ -17,9 +20,14 @@ import javax.swing.JPanel;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JTextArea;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
|
||||
import org.apache.http.client.ClientProtocolException;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
import envoy.client.EnvoyClient;
|
||||
import envoy.schema.Message;
|
||||
import envoy.schema.User;
|
||||
|
||||
/**
|
||||
* Project: <strong>envoy-client</strong><br>
|
||||
@ -31,11 +39,13 @@ public class ChatWindow extends JFrame {
|
||||
|
||||
private static final long serialVersionUID = 6865098428255463649L;
|
||||
|
||||
private JPanel contentPane = new JPanel();
|
||||
private EnvoyClient envoyClient = new EnvoyClient();
|
||||
private JPanel contentPane = new JPanel();
|
||||
private static EnvoyClient envoyClient = new EnvoyClient();
|
||||
|
||||
public DefaultListModel<String> listModel = new DefaultListModel<>();
|
||||
|
||||
public ArrayList<User> userList = new ArrayList<User>();
|
||||
|
||||
public ChatWindow() {
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
setBounds(100, 100, 600, 800);
|
||||
@ -47,10 +57,10 @@ public class ChatWindow extends JFrame {
|
||||
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||
setContentPane(contentPane);
|
||||
GridBagLayout gbl_contentPane = new GridBagLayout();
|
||||
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.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 };
|
||||
contentPane.setLayout(gbl_contentPane);
|
||||
|
||||
JList<String> elementList = new JList<>();
|
||||
@ -74,10 +84,10 @@ public class ChatWindow extends JFrame {
|
||||
scrollPane.setBorder(null);
|
||||
|
||||
GridBagConstraints gbc_scrollPane = new GridBagConstraints();
|
||||
gbc_scrollPane.fill = GridBagConstraints.BOTH;
|
||||
gbc_scrollPane.gridwidth = 2;
|
||||
gbc_scrollPane.gridx = 1;
|
||||
gbc_scrollPane.gridy = 1;
|
||||
gbc_scrollPane.fill = GridBagConstraints.BOTH;
|
||||
gbc_scrollPane.gridwidth = 2;
|
||||
gbc_scrollPane.gridx = 1;
|
||||
gbc_scrollPane.gridy = 1;
|
||||
|
||||
gbc_scrollPane.insets = new Insets(10, 10, 10, 10);
|
||||
|
||||
@ -94,9 +104,9 @@ public class ChatWindow extends JFrame {
|
||||
messageEnterTextfield.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||
|
||||
GridBagConstraints gbc_moveSelectionMessageEnterTextfield = new GridBagConstraints();
|
||||
gbc_moveSelectionMessageEnterTextfield.fill = GridBagConstraints.BOTH;
|
||||
gbc_moveSelectionMessageEnterTextfield.gridx = 1;
|
||||
gbc_moveSelectionMessageEnterTextfield.gridy = 2;
|
||||
gbc_moveSelectionMessageEnterTextfield.fill = GridBagConstraints.BOTH;
|
||||
gbc_moveSelectionMessageEnterTextfield.gridx = 1;
|
||||
gbc_moveSelectionMessageEnterTextfield.gridy = 2;
|
||||
|
||||
gbc_moveSelectionMessageEnterTextfield.insets = new Insets(10, 10, 10, 10);
|
||||
|
||||
@ -110,28 +120,50 @@ public class ChatWindow extends JFrame {
|
||||
|
||||
GridBagConstraints gbc_moveSelectionPostButton = new GridBagConstraints();
|
||||
|
||||
gbc_moveSelectionPostButton.fill = GridBagConstraints.BOTH;
|
||||
gbc_moveSelectionPostButton.gridx = 2;
|
||||
gbc_moveSelectionPostButton.gridy = 2;
|
||||
gbc_moveSelectionPostButton.fill = GridBagConstraints.BOTH;
|
||||
gbc_moveSelectionPostButton.gridx = 2;
|
||||
gbc_moveSelectionPostButton.gridy = 2;
|
||||
|
||||
gbc_moveSelectionPostButton.insets = new Insets(10, 10, 10, 10);
|
||||
|
||||
contentPane.add(postButton, gbc_moveSelectionPostButton);
|
||||
|
||||
postButton.addActionListener((evt) -> {
|
||||
if (!messageEnterTextfield.getText().isEmpty()) try {
|
||||
final Message message = envoyClient.createMessage("Kai", "Maxi", messageEnterTextfield.getText());
|
||||
envoyClient.sendMessage(message);
|
||||
appendMessageToChat(message);
|
||||
messageEnterTextfield.setText("");
|
||||
} 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();
|
||||
}
|
||||
if (!messageEnterTextfield.getText().isEmpty())
|
||||
try {
|
||||
final Message message = envoyClient.createMessage("Kai", "Maxi", messageEnterTextfield.getText());
|
||||
envoyClient.sendMessage(message);
|
||||
appendMessageToChat(message);
|
||||
messageEnterTextfield.setText("");
|
||||
} 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();
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
public void loadUserJList() {
|
||||
// User List
|
||||
JList<User> userJList = new JList<>();
|
||||
DefaultListModel<User> userJListModel = new DefaultListModel<>();
|
||||
for (int i = 0; i < userList.size(); i++) {
|
||||
userJListModel.addElement(userList.get(i));
|
||||
}
|
||||
userJList.setModel(userJListModel);
|
||||
|
||||
GridBagConstraints gbc_userList = new GridBagConstraints();
|
||||
gbc_userList.fill = GridBagConstraints.BOTH;
|
||||
gbc_userList.gridx = 0;
|
||||
gbc_userList.gridy = 1;
|
||||
|
||||
// gbc_userList.insets = new Insets(10, 10, 10, 10);
|
||||
System.out.println(userJListModel.getSize());
|
||||
System.out.println("test");
|
||||
|
||||
contentPane.add(userJList, gbc_userList);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -155,7 +187,20 @@ public class ChatWindow extends JFrame {
|
||||
+ "</span></html>");
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
public void addUserToList(User user) {
|
||||
userList.add(user);
|
||||
|
||||
}
|
||||
|
||||
public void printUserListElements() {
|
||||
for (int i = 0; i < userList.size(); i++) {
|
||||
System.out.println(userList.get(i).getName());
|
||||
System.out.println(userList.get(i).getID());
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args)
|
||||
throws ClientProtocolException, IOException, SAXException, ParserConfigurationException {
|
||||
EventQueue.invokeLater(() -> {
|
||||
try {
|
||||
ChatWindow frame = new ChatWindow();
|
||||
@ -164,5 +209,7 @@ public class ChatWindow extends JFrame {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
envoyClient.getUsersListXml();
|
||||
System.out.println("asd");
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user