-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWindowManager.java
More file actions
65 lines (60 loc) · 1.79 KB
/
WindowManager.java
File metadata and controls
65 lines (60 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/*
* Manages all of a user's windows:
* client
* settings window
* chat windows
*
*/
import java.util.*;
public class WindowManager {
//possibly merge with server
Server host;
Set<ChatWindow> chatWindowSet = new HashSet<>(); //need to remove when window is closed
WindowManager(Server h) {
host=h;
}
public void openAdminWindow() {
AdminWindow a = new AdminWindow(host);
}
public void openChatWindow(Chat c, User initiator) {
ChatWindow cw = new ChatWindow(generateChatWindowTitle(c),c,host,initiator);
}
public void redrawWindowsInvolvingUser(User u) {
//look through all chats
//find chats with participant groups including the user
//update all chats associated with those participant groups
for(ChatWindow cw : chatWindowSet) {
if(cw.chat.participants.hasUser(u)) {
cw.updateChatFeed();
}
}
}
public void CloseUserWindows(User u) {
// should do this on delete
}
public String generateChatWindowTitle(Chat c) {
ParticipantGroup p = c.participants;
String[] participantNames = p.getParticipantNames();
String chatWindowTitle = "";
if(participantNames.length==1) {
chatWindowTitle+= participantNames[0];
}
else if(participantNames.length==2) {
chatWindowTitle += participantNames[0] + " and " + participantNames[1];
}
else {
for (int i = 0; i < participantNames.length; i++) {
String s = participantNames[i];
if(i==participantNames.length-1 ) {
chatWindowTitle += ", and ";
}
else if (i>0){
chatWindowTitle += ", ";
}
chatWindowTitle += s;
}
}
chatWindowTitle = "Chat with " + chatWindowTitle;
return chatWindowTitle;
}
}