@ -54,14 +54,9 @@ public class ChatWindow extends JFrame {
|
||||
* Initializes a {@link JFrame} with UI elements used to send and read messages
|
||||
* to different users.
|
||||
*
|
||||
* @param client the {@link Client} used to send and receive messages
|
||||
* @param localDB the {@link LocalDB} used to manage stored messages and users
|
||||
* @since Envoy v0.1-alpha
|
||||
*/
|
||||
public ChatWindow(Client client, LocalDB localDB) {
|
||||
this.client = client;
|
||||
this.localDB = localDB;
|
||||
|
||||
public ChatWindow() {
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
setBounds(100, 100, 600, 800);
|
||||
setTitle("Envoy");
|
||||
@ -164,7 +159,7 @@ public class ChatWindow extends JFrame {
|
||||
userList.setCellRenderer(new UserListRenderer());
|
||||
userList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
||||
userList.addListSelectionListener((listSelectionEvent) -> {
|
||||
if (!listSelectionEvent.getValueIsAdjusting()) {
|
||||
if (client != null && localDB != null && !listSelectionEvent.getValueIsAdjusting()) {
|
||||
@SuppressWarnings("unchecked")
|
||||
final JList<User> selectedUserList = (JList<User>) listSelectionEvent.getSource();
|
||||
final User user = selectedUserList.getSelectedValue();
|
||||
@ -193,16 +188,12 @@ public class ChatWindow extends JFrame {
|
||||
gbc_userList.anchor = GridBagConstraints.PAGE_START;
|
||||
gbc_userList.insets = new Insets(space, space, space, space);
|
||||
|
||||
changeChatWindowColors(Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()));
|
||||
applyTheme(Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()));
|
||||
|
||||
contentPane.add(userList, gbc_userList);
|
||||
contentPane.revalidate();
|
||||
|
||||
EventBus.getInstance().register(ThemeChangeEvent.class, (evt) -> changeChatWindowColors((Theme) evt.get()));
|
||||
|
||||
loadUsersAndChats();
|
||||
|
||||
if (client.isOnline()) startSyncThread(Config.getInstance().getSyncTimeout());
|
||||
EventBus.getInstance().register(ThemeChangeEvent.class, (evt) -> applyTheme((Theme) evt.get()));
|
||||
|
||||
contentPane.revalidate();
|
||||
}
|
||||
@ -211,9 +202,9 @@ public class ChatWindow extends JFrame {
|
||||
* Used to immediately reload the ChatWindow when settings were changed.
|
||||
*
|
||||
* @param theme the theme to change colors into
|
||||
* @since Envoy v0.1-alpha
|
||||
* @since Envoy v0.2-alpha
|
||||
*/
|
||||
private void changeChatWindowColors(Theme theme) {
|
||||
private void applyTheme(Theme theme) {
|
||||
// contentPane
|
||||
contentPane.setBackground(theme.getBackgroundColor());
|
||||
contentPane.setForeground(theme.getUserNameColor());
|
||||
@ -334,4 +325,27 @@ public class ChatWindow extends JFrame {
|
||||
* Marks messages in the current chat as {@code READ}.
|
||||
*/
|
||||
private void readCurrentChat() { if (currentChat != null) { localDB.setMessagesToRead(currentChat); } }
|
||||
|
||||
/**
|
||||
* Sets the {@link Client} used by this {@link ChatWindow}. If the client is
|
||||
* online, the sync thread is started.
|
||||
*
|
||||
* @param client the {@link Client} used to send and receive messages
|
||||
*/
|
||||
public void setClient(Client client) {
|
||||
this.client = client;
|
||||
if (client.isOnline() && localDB != null) startSyncThread(Config.getInstance().getSyncTimeout());
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the {@link LocalDB} used by this {@link ChatWindow}. After invoking this
|
||||
* method, users and chats will be loaded from the database into the GUI.
|
||||
*
|
||||
* @param localDB the {@link LocalDB} used to manage stored messages and users
|
||||
*/
|
||||
public void setLocalDB(LocalDB localDB) {
|
||||
this.localDB = localDB;
|
||||
loadUsersAndChats();
|
||||
if (client != null && client.isOnline()) startSyncThread(Config.getInstance().getSyncTimeout());
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user