OSDN Git Service

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