Skip to content

Commit 5029bdb

Browse files
committed
Merge pull request #37 from coddo/develop
Merge develop into master
2 parents db40029 + e99a992 commit 5029bdb

43 files changed

Lines changed: 1953 additions & 313 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,6 @@ Jobs/
1010
DUMP/
1111
*.lin
1212
*.xml
13+
*.out
14+
*.in
15+

resources/staff/offline.ico

2.04 KB
Binary file not shown.

resources/staff/online.ico

2.04 KB
Binary file not shown.

src/com/coddotech/teamsubb/appmanage/gui/ApplicationInformation.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ protected void updateGUI(Observable obs, Object obj) {
5959
}
6060

6161
@Override
62-
protected void performInitializations() {
62+
public void performInitializations() {
6363
font = new Font(Display.getDefault(), "Calibri", 15, SWT.BOLD);
6464

6565
applicationName = new Label(this.getShell(), SWT.None);
@@ -71,7 +71,7 @@ protected void performInitializations() {
7171
}
7272

7373
@Override
74-
protected void createObjectProperties() {
74+
public void createObjectProperties() {
7575
applicationName.setFont(font);
7676
applicationName.setLocation(100, 10);
7777
applicationName.setText("TeamSubb");
@@ -99,15 +99,15 @@ protected void createObjectProperties() {
9999
}
100100

101101
@Override
102-
protected void createShellProperties() {
102+
public void createShellProperties() {
103103
this.getShell().setText("About");
104104
this.getShell().setSize(300, 200);
105105
this.placeToCenter();
106106

107107
}
108108

109109
@Override
110-
protected void createListeners() {
110+
public void createListeners() {
111111
this.getShell().addListener(SWT.Close, new Listener() {
112112

113113
@Override

src/com/coddotech/teamsubb/appmanage/model/AppManager.java

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,16 @@
66
import org.eclipse.swt.widgets.Display;
77
import org.eclipse.swt.widgets.Shell;
88

9+
import com.coddotech.teamsubb.chat.gui.StaffItem;
10+
import com.coddotech.teamsubb.chat.model.Messaging;
911
import com.coddotech.teamsubb.connection.gui.LoginWindow;
1012
import com.coddotech.teamsubb.connection.model.Login;
1113
import com.coddotech.teamsubb.gadget.gui.GadgetWindow;
1214
import com.coddotech.teamsubb.jobs.model.JobManager;
13-
import com.coddotech.teamsubb.jobs.model.JobSearchTimer;
1415
import com.coddotech.teamsubb.main.CustomWindow;
1516
import com.coddotech.teamsubb.notifications.gui.PopUpMessages;
1617
import com.coddotech.teamsubb.settings.model.Settings;
18+
import com.coddotech.teamsubb.timers.JobSearchTimer;
1719

1820
public class AppManager {
1921

@@ -28,9 +30,6 @@ public static void startApp() {
2830

2931
if (AppManager.createAppInstanceLock()) {
3032

31-
// read the settings for the first time
32-
Settings.getInstance().readSettings();
33-
3433
AppManager.performUserLogin(); // locks the main thread
3534

3635
AppManager.startMainComponents(); // locks the main thread
@@ -41,10 +40,11 @@ public static void startApp() {
4140
// display a message telling the user that the app is already running
4241
else {
4342
PopUpMessages.getInstance().areadyRunning();
44-
43+
4544
}
4645

4746
}
47+
4848
catch (Exception ex) {
4949
ActivityLogger.logActivity("Main", "App runtime", "FATAL ERROR !!!");
5050

@@ -55,8 +55,10 @@ public static void startApp() {
5555
AppManager.deleteAppInstanceLock();
5656

5757
}
58+
5859
finally {
5960
AppManager.performExitOperations();
61+
6062
}
6163
}
6264

@@ -85,12 +87,19 @@ private static void startMainComponents() {
8587

8688
timer.startTimer();
8789

88-
final GadgetWindow gadget = new GadgetWindow();
90+
// start the chat modules
91+
Messaging.getInstance();
92+
93+
// open the gadget
94+
GadgetWindow gadget = new GadgetWindow();
8995
gadget.open();
9096
}
9197
}
9298

9399
private static void performUserLogin() {
100+
// read the settings for the first time
101+
Settings.getInstance().readSettings();
102+
94103
boolean displayLoginWindow = false;
95104

96105
if (AppManager.isAutoLogin()) {
@@ -103,9 +112,11 @@ private static void performUserLogin() {
103112

104113
else {
105114
new Login().doLogin(data[0], data[1], false);
115+
106116
}
107117

108118
}
119+
109120
else {
110121
displayLoginWindow = true;
111122
}
@@ -136,15 +147,23 @@ private static void disposeGlobalResources() {
136147
JobSearchTimer.getInstance().dispose();
137148
JobManager.getInstance().dispose();
138149
Settings.getInstance().dispose();
150+
Messaging.getInstance().dispose();
139151

140152
// resources
141153
CustomWindow.APP_ICON.dispose();
142154
CustomWindow.BOLD_FONT.dispose();
143155
CustomWindow.DEFAULT_FONT.dispose();
144156

157+
StaffItem.OFFLINE.dispose();
158+
StaffItem.ONLINE.dispose();
159+
StaffItem.FONT_RANK.dispose();
160+
StaffItem.FONT_USER.dispose();
161+
145162
try {
146163
Display.getDefault().dispose();
164+
147165
}
166+
148167
catch (Exception ex) {
149168

150169
}
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
package com.coddotech.teamsubb.chat.gui;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
6+
import org.eclipse.swt.SWT;
7+
import org.eclipse.swt.custom.CTabFolder;
8+
import org.eclipse.swt.layout.GridLayout;
9+
import org.eclipse.swt.widgets.Composite;
10+
11+
import com.coddotech.teamsubb.chat.model.LoggedUser;
12+
import com.coddotech.teamsubb.chat.model.Message;
13+
import com.coddotech.teamsubb.chat.model.StaffMember;
14+
15+
public class ChatContainer extends CTabFolder {
16+
17+
private ChatItem irc = null;
18+
19+
private List<ChatItem> chats = new ArrayList<ChatItem>();
20+
21+
public ChatContainer(Composite arg0, int arg1) {
22+
super(arg0, arg1);
23+
24+
irc = new ChatItem(this, SWT.None, null);
25+
26+
this.createShellProperties();
27+
}
28+
29+
public void dispose() {
30+
irc.dispose();
31+
32+
for (int i = 0; i < chats.size(); i++)
33+
chats.get(i).dispose();
34+
35+
super.dispose();
36+
37+
}
38+
39+
public void openIRCMessages(Message[] msg) {
40+
irc.appendMessages(msg);
41+
}
42+
43+
public void openPrivateMessages(Message[] msg) {
44+
for (int i = 0; i < msg.length; i++) {
45+
ChatItem item;
46+
47+
item = (msg[i].staff.getId() == LoggedUser.getInstance().getId()) ? openPrivateChat(msg[i].dest)
48+
: openPrivateChat(msg[i].staff);
49+
50+
item.appendMessage(msg[i]);
51+
}
52+
}
53+
54+
public ChatItem openPrivateChat(StaffMember staff) {
55+
for (ChatItem item : chats) {
56+
57+
if (item.getStaff().equals(staff)) {
58+
this.setSelection(item);
59+
60+
return item;
61+
}
62+
63+
}
64+
65+
ChatItem item = new ChatItem(this, SWT.BORDER | SWT.CLOSE, staff);
66+
this.setSelection(item);
67+
68+
chats.add(item);
69+
70+
return item;
71+
}
72+
73+
public void closePrivateChats() {
74+
for (int i = 0; i < chats.size(); i++)
75+
if (chats.get(i).isDisposed())
76+
chats.remove(i);
77+
}
78+
79+
private void createShellProperties() {
80+
GridLayout layout = new GridLayout();
81+
82+
layout.numColumns = 1;
83+
layout.makeColumnsEqualWidth = true;
84+
85+
this.setLayout(layout);
86+
87+
}
88+
89+
}
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
package com.coddotech.teamsubb.chat.gui;
2+
3+
import org.eclipse.swt.SWT;
4+
import org.eclipse.swt.custom.CTabFolder;
5+
import org.eclipse.swt.custom.CTabItem;
6+
import org.eclipse.swt.custom.StyleRange;
7+
import org.eclipse.swt.events.DisposeEvent;
8+
import org.eclipse.swt.events.DisposeListener;
9+
import org.eclipse.swt.graphics.Color;
10+
import org.eclipse.swt.widgets.Display;
11+
12+
import com.coddotech.teamsubb.chat.model.Message;
13+
import com.coddotech.teamsubb.chat.model.StaffMember;
14+
import com.coddotech.teamsubb.main.CustomWindow;
15+
16+
public class ChatItem extends CTabItem {
17+
18+
private static final Color SYSTEM = Display.getDefault().getSystemColor(SWT.COLOR_DARK_RED);
19+
20+
private static final String USER_SYSTEM = "[SYSTEM MESSSAGE]";
21+
private static final String IRCTEXT = "Public chat";
22+
23+
private ChatContainer parent;
24+
25+
private StaffMember staff;
26+
27+
private TextFields text = null;
28+
29+
private ChatItem(CTabFolder arg0, int arg1) {
30+
super(arg0, arg1);
31+
32+
this.parent = (ChatContainer) arg0;
33+
34+
createListeners();
35+
}
36+
37+
public ChatItem(CTabFolder arg0, int arg1, StaffMember staff) {
38+
this(arg0, arg1);
39+
40+
this.staff = staff;
41+
42+
this.setText((staff == null) ? IRCTEXT : staff.getName());
43+
44+
text = new TextFields(arg0, SWT.BORDER, staff);
45+
text.setFont(CustomWindow.DEFAULT_FONT);
46+
47+
this.setControl(text);
48+
}
49+
50+
public StaffMember getStaff() {
51+
return this.staff;
52+
}
53+
54+
public void dispose() {
55+
text.dispose();
56+
57+
super.dispose();
58+
59+
parent.closePrivateChats();
60+
}
61+
62+
public void appendMessages(Message[] messages) {
63+
for (Message message : messages)
64+
this.appendMessage(message);
65+
}
66+
67+
public void appendMessage(Message message) {
68+
this.appendSystemData(message.date + " ");
69+
70+
this.appendUser(message.staff);
71+
72+
this.appendMessage(message.message);
73+
}
74+
75+
private void appendSystemData(String data) {
76+
int start = getStyleStartPoint();
77+
78+
text.append(data + " ");
79+
80+
text.setStyleRange(this.getSystemStyle(start, data.length()));
81+
}
82+
83+
private void appendUser(StaffMember user) {
84+
int start = getStyleStartPoint();
85+
86+
int length = USER_SYSTEM.length() + 1;
87+
String name = null;
88+
89+
if (user != null) {
90+
name = user.getName();
91+
length = name.length() + 1;
92+
}
93+
94+
text.append(name + ": ");
95+
96+
text.setStyleRange(this.getUserStyle(user, start, length));
97+
}
98+
99+
private void appendMessage(String msg) {
100+
text.append(msg + "\n");
101+
}
102+
103+
private StyleRange getSystemStyle(int start, int length) {
104+
return this.getStyle(start, length, ChatItem.SYSTEM);
105+
}
106+
107+
private StyleRange getUserStyle(StaffMember staff, int start, int length) {
108+
StyleRange style = this.getStyle(start, length, StaffMember.getRankColor(staff));
109+
style.fontStyle = SWT.BOLD;
110+
111+
return style;
112+
}
113+
114+
private StyleRange getStyle(int start, int length, Color foreground) {
115+
StyleRange style = new StyleRange();
116+
117+
style.start = start;
118+
style.length = length;
119+
style.foreground = foreground;
120+
121+
return style;
122+
}
123+
124+
private int getStyleStartPoint() {
125+
return text.getText().length();
126+
}
127+
128+
private void createListeners() {
129+
this.addDisposeListener(new DisposeListener() {
130+
131+
@Override
132+
public void widgetDisposed(DisposeEvent arg0) {
133+
dispose();
134+
135+
}
136+
});
137+
}
138+
}

0 commit comments

Comments
 (0)