7
7
import java .util .ArrayList ;
8
8
import testerEntities .*;
9
9
10
-
11
10
public class AppScreen implements AppScreenPresenter , AppScreenController , ChatName , Refresh {
12
11
13
12
private final JFrame jFrame ;
@@ -17,9 +16,9 @@ public class AppScreen implements AppScreenPresenter, AppScreenController, ChatN
17
16
18
17
19
18
/**
20
- Create an appscreen. AppScreen object
21
- @param chats This is a list of chats given by the user (the list will always come as sorted with the
22
- most recent chats at the end of the list)
19
+ Create an AppScreen object
20
+ @param chats This is a list of chats given by the user (the list will always come as sorted with the
21
+ most recent chats at the end of the list)
23
22
*/
24
23
public AppScreen (String currentUsername , ArrayList <Chat > chats ) {
25
24
this .currentUsername = currentUsername ;
@@ -63,11 +62,10 @@ public void openScreen() {
63
62
}
64
63
65
64
/**
66
- Display a screen containing an ordered list of chats to the user based on latest conversation times
65
+ Display a screen containing an ordered list of chats to the user based on latest conversation times
67
66
*/
68
67
public void displayAppScreen (){
69
68
70
-
71
69
JPanel jPanel = new JPanel ();
72
70
73
71
// getting the names of each chat to display and creating buttons for each chat
@@ -88,7 +86,7 @@ public void displayAppScreen(){
88
86
public void actionPerformed (ActionEvent e ) {
89
87
90
88
/* TODO: call chatView to open the display the window (?) for chat
91
- - not sure if appscreen. AppScreen and ChatView would be combined into one window, or
89
+ - not sure if AppScreen and ChatView would be combined into one window, or
92
90
two separate windows
93
91
*/
94
92
}
@@ -110,8 +108,8 @@ public void actionPerformed(ActionEvent e) {
110
108
}
111
109
112
110
/**
113
- Make the chat list scrollable
114
- @param jPanel The panel containing the chats
111
+ Make the chat list scrollable
112
+ @param jPanel The panel containing the chats
115
113
*/
116
114
private void scrollableChats (JPanel jPanel ) {
117
115
JScrollPane scrollFrame = new JScrollPane (jPanel );
@@ -147,9 +145,26 @@ public void updateChatOrder(Chat chat){
147
145
148
146
}
149
147
148
+ /**
149
+ * Add a new chat to the screen, if the chat already exists (i.e. there exists a chat with the
150
+ * same ID, do nothing.
151
+ * @param chat The new chat to be added
152
+ */
153
+ public void addNewChat (Chat chat ){
154
+
155
+ if (!(this .chats .contains (chat ))){
156
+ updateChatOrder (chat );
157
+ jFrame .remove (this .jScrollPane );
158
+
159
+ // refresh the screen
160
+ displayAppScreen ();
161
+
162
+ }
163
+ }
164
+
150
165
151
166
/**
152
- * Update the screen if the given chat has been updated
167
+ * Update the order of chats that appear on screen if there was a change to conversation history
153
168
* @param chatID The ID of the given chat
154
169
*/
155
170
@ Override
@@ -175,6 +190,11 @@ public boolean hasUpdate(String chatID) {
175
190
return this .chats .get (this .chats .size () - 1 ) != chat ;
176
191
}
177
192
193
+ /**
194
+ * Get the chat object given its chat ID
195
+ * @param chatID The ID of the chat
196
+ * @return The chat with the given ID
197
+ */
178
198
@ Override
179
199
public Chat getChat (String chatID ) {
180
200
for (Chat chat : this .chats ){
0 commit comments