Skip to content

Commit 56086ff

Browse files
author
Bin.W
committed
.
1 parent d0bc75a commit 56086ff

Some content is hidden

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

114 files changed

+962
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package main.java.emoji_manager.model;
2+
3+
/**
4+
* EmoInfo
5+
*/
6+
public class EmoInfo {
7+
/* Emo Info*/
8+
int pos;
9+
String val;
10+
11+
public EmoInfo(int pos, String val) {
12+
this.pos = pos;
13+
this.val = val;
14+
}
15+
16+
public int getPos() {
17+
return pos;
18+
}
19+
20+
public String getVal() {
21+
return val;
22+
}
23+
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
package main.java.emoji_manager.model;
2+
3+
import javax.swing.text.SimpleAttributeSet;
4+
import javax.swing.text.StyleConstants;
5+
import java.awt.*;
6+
7+
/**
8+
* Font
9+
*/
10+
public class FontAndText {
11+
private String msg = "", name = "Song"; //
12+
13+
private int size = 0; // Font
14+
15+
private Color color = new Color(225, 225, 225); // Font color
16+
17+
/**
18+
* Free Construction(for newline)
19+
*/
20+
21+
public FontAndText() {
22+
}
23+
24+
public FontAndText(String msg, String fontName, int fontSize, Color color) {
25+
this.msg = msg;
26+
this.name = fontName;
27+
this.size = fontSize;
28+
this.color = color;
29+
}
30+
31+
/**
32+
* return Attribute set
33+
*
34+
*/
35+
public SimpleAttributeSet getAttrSet() {
36+
// Attribute Set
37+
SimpleAttributeSet attrSet = new SimpleAttributeSet();
38+
if (name != null) {
39+
StyleConstants.setFontFamily(attrSet, name);
40+
}
41+
StyleConstants.setBold(attrSet, false);
42+
StyleConstants.setItalic(attrSet, false);
43+
StyleConstants.setFontSize(attrSet, size);
44+
if (color != null)
45+
StyleConstants.setForeground(attrSet, color);
46+
return attrSet;
47+
}
48+
49+
public String toString() {
50+
//divide message to 4 parts
51+
return name + "|"
52+
+ size + "|"
53+
+ color.getRed() + "-" + color.getGreen() + "-" + color.getBlue() + "|"
54+
+ msg;
55+
}
56+
57+
public String getText() {
58+
return msg;
59+
}
60+
61+
public void setText(String text) {
62+
this.msg = text;
63+
}
64+
65+
66+
public void setColor(Color color) {
67+
this.color = color;
68+
}
69+
70+
public void setName(String name) {
71+
this.name = name;
72+
}
73+
74+
public void setSize(int size) {
75+
this.size = size;
76+
}
77+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package main.java.emoji_manager.msg;
2+
public final class MsgType {
3+
public final static int CHAT = 0; // Chat
4+
public final static int SHAKE = 3; // Shake
5+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package main.java.emoji_manager.msg;
2+
3+
import java.net.DatagramPacket;
4+
import java.net.DatagramSocket;
5+
import java.net.InetAddress;
6+
import java.nio.charset.StandardCharsets;
7+
8+
public class Sender {
9+
/* local ip */
10+
public static String localIP = "127.0.0.1";
11+
/* wrong message */
12+
public static String err_msg = "";
13+
/* default send port */
14+
public static int SendPort = 5555;
15+
/* default chat port */
16+
public static int chatPort = 6666;
17+
18+
public Sender() {
19+
}
20+
21+
/**
22+
* @param msgType message Type
23+
* @return send success or not
24+
*/
25+
public static boolean sendUDPMsg(int msgType, String uname, String friendIP, int friendPort, String message) {
26+
try {
27+
/* From Common line get to send context, convert to string by UTF-8 */
28+
byte[] msg = (msgType + "*" + uname + "*" + message).getBytes(StandardCharsets.UTF_8);
29+
/* get the host internet Address */
30+
InetAddress address = InetAddress.getByName(friendIP);
31+
32+
/* Initializes a datagram packet (packet) with data and address*/
33+
DatagramPacket packet = new DatagramPacket(msg, msg.length, address,
34+
friendPort);
35+
36+
/* Create a default socket and send packets through this socket */
37+
DatagramSocket dSocket = new DatagramSocket();
38+
dSocket.send(packet);
39+
40+
/* Close the socket after sending */
41+
dSocket.close();
42+
} catch (Exception e) {
43+
e.printStackTrace();
44+
err_msg = "System error!";
45+
return false;
46+
}
47+
return true;
48+
}
49+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package main.java.use_cases.emoji_manager;
2+
3+
import javax.swing.*;
4+
import java.net.URL;
5+
6+
public class ChatEmo extends ImageIcon {
7+
/**
8+
* the description of emoji
9+
*/
10+
private static final long serialVersionUID = 1L;
11+
int im;// the code of emo
12+
13+
public ChatEmo(URL url, int im) {
14+
super(url);
15+
this.im = im;
16+
}
17+
18+
public int getIm() {
19+
return im;
20+
}
21+
}

0 commit comments

Comments
 (0)