Skip to content

Commit e968fc9

Browse files
committed
-separated out irc lib into independent repository
-major restructuring for compatibility with new mercury-irc structure -slight ui changes -switched from ubuntu mono font to inconsolata
1 parent b76ecb5 commit e968fc9

Some content is hidden

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

48 files changed

+433
-1586
lines changed

.gitignore

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
out/*
2-
*.iml
3-
.idea/*
1+
*.iml
+109-72
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
package com.mercuryirc.client;
22

3-
import com.mercuryirc.client.protocol.model.Channel;
4-
import com.mercuryirc.client.protocol.model.Message;
5-
import com.mercuryirc.client.protocol.model.Mode;
6-
import com.mercuryirc.client.protocol.model.Target;
7-
import com.mercuryirc.client.protocol.model.User;
8-
import com.mercuryirc.client.protocol.network.Connection;
9-
import com.mercuryirc.client.protocol.network.callback.InputCallback;
103
import com.mercuryirc.client.ui.ApplicationPane;
11-
import com.mercuryirc.client.ui.Tab;
124
import com.mercuryirc.client.ui.model.MessageRow;
5+
import com.mercuryirc.model.Channel;
6+
import com.mercuryirc.model.Entity;
7+
import com.mercuryirc.model.Message;
8+
import com.mercuryirc.model.Mode;
9+
import com.mercuryirc.model.User;
10+
import com.mercuryirc.network.Connection;
11+
import com.mercuryirc.network.callback.InputCallback;
1312
import javafx.application.Platform;
1413

1514
import java.util.List;
@@ -24,53 +23,63 @@ public InputCallbackImpl(ApplicationPane appPane) {
2423
}
2524

2625
public void onConnect(final Connection connection) {
27-
connection.joinChannel("#mercury");
26+
connection.join("#mercury");
2827
}
2928

3029
@Override
31-
public void onMessage(final Connection connection, final Message message) {
30+
public void onPrivMsg(final Connection connection, final Message message) {
3231
Platform.runLater(new Runnable() {
32+
@Override
3333
public void run() {
34-
Target target = connection.resolveTarget(message.getTarget());
35-
MessageRow row = new MessageRow(connection, message);
36-
Tab tab;
37-
if (message.getType() == Message.Type.NOTICE) {
38-
tab = appPane.getTabPane().getSelected();
39-
} else {
40-
if (message.getTarget().startsWith("#")) {
41-
tab = appPane.getTabPane().get(target);
42-
} else {
43-
tab = appPane.getTabPane().get(connection.resolveTarget(message.getSource()));
44-
}
45-
}
46-
tab.getContentPane().getMessagePane().addRow(row);
34+
boolean highlight = message.getMessage().toLowerCase().contains(connection.getLocalUser().getName().toLowerCase());
35+
appPane.getTabPane().addTargetedMessage(connection, message, highlight ? MessageRow.Type.HIGHLIGHT : MessageRow.Type.PRIVMSG);
4736
}
4837
});
4938
}
5039

5140
@Override
52-
public void onCTCP(Connection connection, String from, String ctcp) {
53-
String arch = System.getProperty("os.arch");
54-
if(arch.equals("amd64"))
55-
arch = "x64";
56-
57-
String sysInfo = System.getProperty("os.name") + " (" + arch + ", "
58-
+ Runtime.getRuntime().availableProcessors() + " cores)";
41+
public void onNotice(final Connection connection, final Message message) {
42+
Platform.runLater(new Runnable() {
43+
@Override
44+
public void run() {
45+
appPane.getTabPane().addUntargetedMessage(connection, message, MessageRow.Type.NOTICE);
46+
}
47+
});
48+
}
5949

60-
connection.ctcp(from, "VERSION MercuryIRC // " + sysInfo);
50+
@Override
51+
public void onCtcp(final Connection connection, final Message message) {
52+
Platform.runLater(new Runnable() {
53+
@Override
54+
public void run() {
55+
String ctcp = message.getMessage();
56+
if (ctcp.startsWith("ACTION")) {
57+
Message _message = new Message(message.getSource(), message.getTarget(), ctcp.substring(7));
58+
appPane.getTabPane().addTargetedMessage(connection, _message, MessageRow.Type.EVENT);
59+
} else {
60+
Message _message = new Message(message.getSource(), message.getTarget(), ctcp);
61+
appPane.getTabPane().addUntargetedMessage(connection, _message, MessageRow.Type.CTCP);
62+
if (ctcp.equals("VERSION")) {
63+
String arch = System.getProperty("os.arch");
64+
if (arch.equals("amd64")) {
65+
arch = "x64";
66+
}
67+
String sysInfo = System.getProperty("os.name") + " (" + arch + " "
68+
+ Runtime.getRuntime().availableProcessors() + "-core)";
69+
connection.ctcp(message.getSource(), "VERSION MercuryIRC // " + sysInfo);
70+
}
71+
}
72+
}
73+
});
6174
}
6275

6376
@Override
6477
public void onChannelJoin(final Connection connection, final Channel channel, final User user) {
6578
Platform.runLater(new Runnable() {
79+
@Override
6680
public void run() {
67-
MessageRow row = new MessageRow(channel.getName(), user.getName() + " has joined the channel", MessageRow.Type.EVENT);
68-
Tab tab = appPane.getTabPane().get(channel);
69-
tab.getContentPane().getMessagePane().addRow(row);
70-
tab.getContentPane().getTopicPane().setTopic(channel.getTopic());
71-
if (user.equals(connection.getLocalUser())) {
72-
appPane.getTabPane().select(tab);
73-
}
81+
Message message = new Message(user, channel, "has joined the channel");
82+
appPane.getTabPane().addTargetedMessage(connection, message, MessageRow.Type.JOIN);
7483
}
7584
});
7685
}
@@ -80,9 +89,10 @@ public void onChannelPart(final Connection connection, final Channel channel, fi
8089
Platform.runLater(new Runnable() {
8190
@Override
8291
public void run() {
83-
appPane.getTabPane().get(channel).getContentPane().getMessagePane().addRow(new MessageRow(channel.getName(), user.getName() + " has left the channel" + (reason == null ? "" : " (" + reason + ")"), MessageRow.Type.EVENT));
92+
Message message = new Message(user, channel, "has left the channel");
93+
appPane.getTabPane().addTargetedMessage(connection, message, MessageRow.Type.PART);
8494
if (user.equals(connection.getLocalUser())) {
85-
appPane.getTabPane().close(appPane.getTabPane().get(channel));
95+
appPane.getTabPane().close(appPane.getTabPane().get(connection, channel));
8696
}
8797
}
8898
});
@@ -93,31 +103,29 @@ public void onUserQuit(Connection connection, final User user, final String reas
93103
Platform.runLater(new Runnable() {
94104
@Override
95105
public void run() {
96-
for (Tab tab : appPane.getTabPane().getItems()) {
97-
if (tab.getContentPane().getUserPane().getUsers().contains(user)) {
98-
tab.getContentPane().getMessagePane().addRow(new MessageRow(tab.getTarget().getName(), user.getName() + " has quit" + (reason == null ? "" : " (" + reason + ")"), MessageRow.Type.EVENT));
99-
}
100-
}
106+
Message message = new Message(user, null, "has quit (" + reason + ")");
107+
appPane.getTabPane().addUserStatusMessage(user, message, MessageRow.Type.PART);
101108
}
102109
});
103110
}
104111

105112
@Override
106-
public void onChannelNickList(Connection connection, final Channel channel, final Set<String> nicks) {
113+
public void onChannelNickList(final Connection connection, final Channel channel, final Set<User> users) {
107114
Platform.runLater(new Runnable() {
108115
public void run() {
109-
appPane.getTabPane().get(channel).getContentPane().getUserPane().setUsers(nicks);
116+
appPane.getTabPane().get(connection, channel).getContentPane().getUserPane().setUsers(users);
110117
}
111118
});
112119
}
113120

114121
@Override
115-
public void onTopicChange(Connection connection, final Channel channel, final String who, final String topic) {
122+
public void onTopicChange(final Connection connection, final Channel channel, final User source, final String topic) {
116123
Platform.runLater(new Runnable() {
117124
@Override
118125
public void run() {
119-
appPane.getTabPane().get(channel).getContentPane().getMessagePane().addRow(new MessageRow(channel.getName(), who + " has set the topic to: " + topic, MessageRow.Type.EVENT));
120-
appPane.getTabPane().get(channel).getContentPane().getTopicPane().setTopic(topic);
126+
Message message = new Message(source, channel, "has set the topic: " + topic);
127+
appPane.getTabPane().addTargetedMessage(connection, message, MessageRow.Type.EVENT);
128+
appPane.getTabPane().get(connection, channel).getContentPane().getTopicPane().setTopic(topic);
121129
}
122130
});
123131
}
@@ -127,24 +135,11 @@ public void onUserNickChange(final Connection connection, final User user, final
127135
Platform.runLater(new Runnable() {
128136
@Override
129137
public void run() {
130-
for (Tab tab : appPane.getTabPane().getItems()) {
131-
for (String _nick : tab.getContentPane().getUserPane().getUsers()) {
132-
User _user = (User) connection.resolveTarget(_nick);
133-
if (_nick.equals(oldNick) && _user.getServer().equals(user.getServer())) {
134-
tab.getContentPane().getMessagePane().addRow(new MessageRow(tab.getTarget().getName(), oldNick + " has changed their name to " + user.getName(), MessageRow.Type.EVENT));
135-
break;
136-
}
137-
}
138-
139-
/*
140-
topicpane now has more info. can't get CSS right. changed the way InputPane nick is set, since it didn't like the Property being set from the network thread. now works, but nick changing is still messed up because it doesn't update the list of channel users w/the new nick.
141-
*/
142-
143-
if(user.equals(connection.getLocalUser())) {
144-
tab.getContentPane().getMessagePane().getInputPane().setNick(user.getName());
145-
}
138+
Message message = new Message(null, null, oldNick + " is now known as " + user.getName());
139+
appPane.getTabPane().addUserStatusMessage(user, message, MessageRow.Type.EVENT);
140+
if (user.equals(connection.getLocalUser())) {
141+
appPane.getContentPane().getMessagePane().getInputPane().setNick(user.getName());
146142
}
147-
148143
}
149144
});
150145
}
@@ -154,17 +149,59 @@ public void onUserKick(final Connection connection, final Channel channel, final
154149
Platform.runLater(new Runnable() {
155150
@Override
156151
public void run() {
157-
appPane.getTabPane().get(channel).getContentPane().getMessagePane().addRow(new MessageRow(channel.getName(), user.getName() + " has been kicked out of the channel" + (reason == null ? "" : " (" + reason + ")"), MessageRow.Type.EVENT));
158-
if (user.equals(connection.getLocalUser())) {
159-
appPane.getTabPane().close(appPane.getTabPane().get(channel));
160-
}
152+
Message message = new Message(user, channel, "has been kicked from the channel");
153+
appPane.getTabPane().addTargetedMessage(connection, message, MessageRow.Type.PART);
161154
}
162155
});
163156
}
164157

165158
@Override
166159
public void onChannelModeList(Connection connection, Channel channel, Mode.Type type, List<Mode> list) {
167-
//To change body of implemented methods use File | Settings | File Templates.
160+
Message message = new Message(null, null, "Channel " + type.toString() + " list:");
161+
appPane.getTabPane().addTargetedMessage(connection, message, MessageRow.Type.EVENT);
162+
for (Mode mode : list) {
163+
Message message2 = new Message(null, null, ((User) mode.getTarget()).getHost() + " by " + mode.getSource().getHost());
164+
appPane.getTabPane().addTargetedMessage(connection, message2, MessageRow.Type.EVENT);
165+
}
166+
}
167+
168+
@Override
169+
public void onError(final Connection connection, final String error) {
170+
Platform.runLater(new Runnable() {
171+
@Override
172+
public void run() {
173+
Message message = new Message(null, null, error);
174+
appPane.getTabPane().addUntargetedMessage(connection, message, MessageRow.Type.ERROR);
175+
}
176+
});
177+
}
178+
179+
@Override
180+
public void onUnknownCommand(final Connection connection, final String command) {
181+
Platform.runLater(new Runnable() {
182+
@Override
183+
public void run() {
184+
Message message = new Message(null, null, "Unknown command: " + command);
185+
appPane.getTabPane().addUntargetedMessage(connection, message, MessageRow.Type.ERROR);
186+
}
187+
});
188+
}
189+
190+
@Override
191+
public void onModeChange(final Connection connection, final Entity target, final Set<Mode> modes, final boolean add) {
192+
Platform.runLater(new Runnable() {
193+
@Override
194+
public void run() {
195+
for (Mode mode : modes) {
196+
Message message = new Message(mode.getSource(), target, (add ? "" : "un") + "sets " + mode.getType().toString() + " on " + mode.getTarget().getName() + (mode.getTarget().equals(target) ? "" : " in " + target.getName()));
197+
if (target instanceof Channel) {
198+
appPane.getTabPane().addTargetedMessage(connection, message, MessageRow.Type.EVENT);
199+
} else {
200+
appPane.getTabPane().addUntargetedMessage(connection, message, MessageRow.Type.EVENT);
201+
}
202+
}
203+
}
204+
});
168205
}
169206

170207
}

src/com/mercuryirc/client/Mercury.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ public class Mercury extends Application {
1919
public static void main(String[] args) {
2020
Font.loadFont(Mercury.class.getResource("./res/fonts/font_awesome.ttf").toExternalForm(), 12);
2121
Font.loadFont(Mercury.class.getResource("./res/fonts/open_sans.ttf").toExternalForm(), 12);
22-
Font.loadFont(Mercury.class.getResource("./res/fonts/ubuntu_mono.ttf").toExternalForm(), 12);
22+
Font.loadFont(Mercury.class.getResource("./res/fonts/inconsolata.ttf").toExternalForm(), 12);
23+
Font.loadFont(Mercury.class.getResource("./res/fonts/inconsolata_bold.ttf").toExternalForm(), 12);
2324
Settings.init();
2425
Application.launch(args);
2526
}
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
package com.mercuryirc.client;
22

3-
import com.mercuryirc.client.protocol.model.Message;
4-
import com.mercuryirc.client.protocol.network.Connection;
5-
import com.mercuryirc.client.protocol.network.callback.OutputCallback;
63
import com.mercuryirc.client.ui.ApplicationPane;
74
import com.mercuryirc.client.ui.model.MessageRow;
5+
import com.mercuryirc.model.Message;
6+
import com.mercuryirc.model.Server;
7+
import com.mercuryirc.model.User;
8+
import com.mercuryirc.network.Connection;
9+
import com.mercuryirc.network.callback.OutputCallback;
10+
import javafx.application.Platform;
811

912
public class OutputCallbackImpl implements OutputCallback {
1013

@@ -15,8 +18,66 @@ public OutputCallbackImpl(ApplicationPane appPane) {
1518
}
1619

1720
@Override
18-
public void onMessage(Connection connection, Message message) {
19-
appPane.getTabPane().get(appPane.getConnection().resolveTarget(message.getTarget())).getContentPane().getMessagePane().addRow(new MessageRow(appPane.getConnection(), message));
21+
public void onPrivmsg(final Connection connection, final Message message) {
22+
Platform.runLater(new Runnable() {
23+
@Override
24+
public void run() {
25+
appPane.getTabPane().addTargetedMessage(connection, message, MessageRow.Type.SELF);
26+
}
27+
});
28+
}
29+
30+
@Override
31+
public void onNotice(final Connection connection, final Message message) {
32+
Platform.runLater(new Runnable() {
33+
@Override
34+
public void run() {
35+
appPane.getTabPane().addUntargetedMessage(connection, message, MessageRow.Type.NOTICE);
36+
}
37+
});
38+
}
39+
40+
@Override
41+
public void onCtcp(final Connection connection, final Message message) {
42+
Platform.runLater(new Runnable() {
43+
@Override
44+
public void run() {
45+
String ctcp = message.getMessage();
46+
if (ctcp.startsWith("ACTION")) {
47+
Message _message = new Message(connection.getLocalUser(), message.getTarget(), ctcp.substring(7));
48+
appPane.getTabPane().addTargetedMessage(connection, _message, MessageRow.Type.EVENT);
49+
} else {
50+
appPane.getTabPane().addUntargetedMessage(connection, message, MessageRow.Type.CTCP);
51+
}
52+
}
53+
});
54+
}
55+
56+
@Override
57+
public void onQuery(final Connection connection, final User user) {
58+
Platform.runLater(new Runnable() {
59+
@Override
60+
public void run() {
61+
appPane.getTabPane().create(connection, user);
62+
}
63+
});
64+
}
65+
66+
@Override
67+
public void onConnectionRequest(final Connection connection, final String network, final String hostname, final int port, final String nick) {
68+
Platform.runLater(new Runnable() {
69+
@Override
70+
public void run() {
71+
Server server = new Server(network, hostname, port, false);
72+
User user = new User(server, nick);
73+
user.setUserName("mercury");
74+
user.setRealName("Mercury IRC Client");
75+
Connection conn = new Connection(server, user, new InputCallbackImpl(appPane), new OutputCallbackImpl(appPane));
76+
conn.setAcceptAllSSLCerts(true);
77+
conn.connect();
78+
appPane.getTabPane().create(conn, conn.getServer());
79+
}
80+
});
2081
}
2182

2283
}

0 commit comments

Comments
 (0)