OSDN Git Service

1.22rのソースからインポート.
[coroid/inqubus.git] / frontend / src / saccubus / conv / Chat.java
1 package saccubus.conv;
2
3 import java.io.*;
4
5 import saccubus.util.Util;
6
7 /**
8  * <p>
9  * \83^\83C\83g\83\8b\82³\82«\82ã\82Î\82·
10  * </p>
11  * 
12  * <p>
13  * \90à\96¾: \83j\83R\83j\83R\93®\89æ\82Ì\93®\89æ\82ð\83R\83\81\83\93\83g\82Â\82«\82Å\95Û\91
14  * </p>
15  * 
16  * <p>
17  * \92\98\8dì\8c : Copyright (c) 2007 PSI
18  * </p>
19  * 
20  * <p>
21  * \89ï\8eÐ\96¼:
22  * </p>
23  * 
24  * @author \96¢\93ü\97Í
25  * @version 1.0
26  */
27 public class Chat {
28         private static final int CMD_LOC_DEF = 0;
29
30         private static final int CMD_LOC_TOP = 1;
31
32         private static final int CMD_LOC_BOTTOM = 2;
33
34         @SuppressWarnings("unused")
35         private static final int CMD_SIZE_MAX = 3;
36
37         private static final int CMD_SIZE_DEF = 0;
38
39         private static final int CMD_SIZE_BIG = 1;
40
41         private static final int CMD_SIZE_SMALL = 2;
42
43         @SuppressWarnings("unused")
44         private static final int COMMENT_FONT_SIZE[] = { 24, // DEF
45                         39, // BIG
46                         15, // SMALL
47         };
48
49         private static final int CMD_COLOR_DEF = 0;
50
51         private static final int CMD_COLOR_RED = 1;
52
53         private static final int CMD_COLOR_ORANGE = 2;
54
55         private static final int CMD_COLOR_YELLOW = 3;
56
57         private static final int CMD_COLOR_PINK = 4;
58
59         private static final int CMD_COLOR_BLUE = 5;
60
61         private static final int CMD_COLOR_PURPLE = 6;
62
63         private static final int CMD_COLOR_CYAN = 7;
64
65         private static final int CMD_COLOR_GREEN = 8;
66
67         private static final int CMD_COLOR_NICOWHITE = 9;
68
69         private static final int CMD_COLOR_MARINEBLUE = 10;
70
71         private static final int CMD_COLOR_MADYELLOW = 11;
72
73         private static final int CMD_COLOR_PASSIONORANGE = 12;
74
75         private static final int CMD_COLOR_NOBLEVIOLET = 13;
76
77         private static final int CMD_COLOR_ELEMENTALGREEN = 14;
78
79         private static final int CMD_COLOR_TRUERED = 15;
80
81         private static final int CMD_COLOR_BLACK = 16;
82
83         // "date"
84         @SuppressWarnings("unused")
85         private int Date = 0;
86
87         // "mail"
88         private int Color = 0;
89
90         private int Size = 0;
91
92         private int Location = 0;
93
94         // "No"
95         private int No = 0;
96
97         // "user_id"
98         @SuppressWarnings("unused")
99         private int UserID = 0;
100
101         // "vpos"
102         private int Vpos = 0;
103
104         private String Comment = "";
105
106         public Chat() {
107         }
108
109         public void setDate(String date_str) {
110                 Date = Integer.parseInt(date_str);
111                 // System.out.println("date:" + date_str);
112         }
113
114         public void setMail(String mail_str) {
115                 // System.out.println("mail:" + mail_str);
116                 Color = CMD_COLOR_DEF;
117                 Size = CMD_SIZE_DEF;
118                 Location = CMD_LOC_DEF;
119                 if (mail_str == null) {
120                         return;
121                 }
122                 String element[] = mail_str.split(" ");
123                 for (int i = 0; i < element.length; i++) {
124                         String str = element[i].toLowerCase();
125                         /* \83\8d\83P\81[\83V\83\87\83\93 */
126                         if (str.equals("ue")) {
127                                 Location = CMD_LOC_TOP;
128                         } else if (str.equals("shita")) {
129                                 Location = CMD_LOC_BOTTOM;
130                         } else if (str.equals("big")) {
131                                 Size = CMD_SIZE_BIG;
132                         } else if (str.equals("small")) {
133                                 Size = CMD_SIZE_SMALL;
134                         } else if (str.equals("red")) {
135                                 Color = CMD_COLOR_RED;
136                         } else if (str.equals("orange")) {
137                                 Color = CMD_COLOR_ORANGE;
138                         } else if (str.equals("yellow")) {
139                                 Color = CMD_COLOR_YELLOW;
140                         } else if (str.equals("pink")) {
141                                 Color = CMD_COLOR_PINK;
142                         } else if (str.equals("blue")) {
143                                 Color = CMD_COLOR_BLUE;
144                         } else if (str.equals("purple")) {
145                                 Color = CMD_COLOR_PURPLE;
146                         } else if (str.equals("cyan")) {
147                                 Color = CMD_COLOR_CYAN;
148                         } else if (str.equals("green")) {
149                                 Color = CMD_COLOR_GREEN;
150                         } else if (str.equals("niconicowhite") || str.equals("white2")) {
151                                 Color = CMD_COLOR_NICOWHITE;
152                         } else if (str.equals("arineblue") || str.equals("blue2")) {
153                                 Color = CMD_COLOR_MARINEBLUE;
154                         } else if (str.equals("madyellow") || str.equals("yellow2")) {
155                                 Color = CMD_COLOR_MADYELLOW;
156                         } else if (str.equals("passionorange") || str.equals("orange2")) {
157                                 Color = CMD_COLOR_PASSIONORANGE;
158                         } else if (str.equals("nobleviolet") || str.equals("purple2")) {
159                                 Color = CMD_COLOR_NOBLEVIOLET;
160                         } else if (str.equals("elementalgreen") || str.equals("green2")) {
161                                 Color = CMD_COLOR_ELEMENTALGREEN;
162                         } else if (str.equals("truered") || str.equals("red2")) {
163                                 Color = CMD_COLOR_TRUERED;
164                         } else if (str.equals("black")) {
165                                 Color = CMD_COLOR_BLACK;
166                         } else {
167                                 // System.out.println("Unknown command:" + str);
168                         }
169                 }
170         }
171
172         public void setNo(String no_str) {
173                 try {
174                         No = Integer.parseInt(no_str);
175                 } catch (Exception e) {
176                         No = -1;
177                 }
178                 // System.out.println("no:" + no_str);
179         }
180
181         public void setUserID(String user_id_str) {
182                 // System.out.println("user_id:" + user_id_str);
183                 try {
184                         UserID = Integer.parseInt(user_id_str);
185                 } catch (Exception e) {
186                         UserID = -1;
187                 }
188         }
189
190         public void setVpos(String vpos_str) {
191                 // System.out.println("vpos:" + vpos_str);
192                 try {
193                         Vpos = Integer.parseInt(vpos_str);
194                 } catch (Exception e) {
195                         Vpos = -1;
196                 }
197
198         }
199
200         public void setComment(String com_str) {
201                 // System.out.println("Comment[" + com_str.length() + "]:" + com_str);
202                 if (Comment.equals("")) {
203                         Comment += com_str;
204                 } else {
205                         Comment += com_str;
206                 }
207         }
208
209         public void write(OutputStream os) throws IOException {
210                 byte[] a = null;
211                 try {
212                         a = (Comment + "\0").getBytes("UnicodeLittleUnmarked");
213                 } catch (UnsupportedEncodingException ex) {
214                         ex.printStackTrace();
215                 }
216                 Util.writeInt(os, No);
217                 Util.writeInt(os, Vpos);
218                 Util.writeInt(os, Location);
219                 Util.writeInt(os, Size);
220                 Util.writeInt(os, Color);
221                 Util.writeInt(os, a.length);
222                 try {
223                         os.write(a);
224                 } catch (IOException ex1) {
225                         ex1.printStackTrace();
226                 }
227         }
228
229 }