密猟オンラインクライアントプログラム JAVAベース
表示するユーザー名やアイテム名などをそれなりに全角判定して表示を調整するようにした
@@ -132,6 +132,12 @@ | ||
132 | 132 | public static final byte MOVE_LEFT = 2; |
133 | 133 | public static final byte MOVE_RIGHT = 3; |
134 | 134 | |
135 | + /* system parameter */ | |
136 | + public static final int WIDTH_VIEW_USERNAME = 16; | |
137 | + public static final int WIDTH_VIEW_WEAPONNAME = 16; | |
138 | + public static final int WIDTH_VIEW_ITEMNAME = 16; | |
139 | + public static final int WIDTH_VIEW_ANIMALNAME = 16; | |
140 | + | |
135 | 141 | /* system variable */ |
136 | 142 | static String HostName; |
137 | 143 | static String UserName; |
@@ -193,6 +199,122 @@ | ||
193 | 199 | p[nidx + 3] = (byte) (n & 0xff); |
194 | 200 | } |
195 | 201 | |
202 | + public static final boolean isSingleByte(int codepoint) { | |
203 | + boolean result = false; | |
204 | + if (Character.charCount(codepoint) == 1) { | |
205 | + if (codepoint >= 0 && codepoint < 0x80) { | |
206 | + result = true; | |
207 | + } | |
208 | + } | |
209 | + return result; | |
210 | + } | |
211 | + | |
212 | + public static final int countStringWidth(String s) { | |
213 | + int i; | |
214 | + int nwidth = 0; | |
215 | + for (i = 0; i < s.length(); i++) { | |
216 | + int c; | |
217 | + c = s.codePointAt(i); | |
218 | + if (Character.charCount(c) == 2) { | |
219 | + i++; | |
220 | + } | |
221 | + if (isSingleByte(c) == false) { | |
222 | + nwidth += 2; | |
223 | + } else { | |
224 | + nwidth++; | |
225 | + } | |
226 | + } | |
227 | + return nwidth; | |
228 | + } | |
229 | + | |
230 | + public static final String rightStringWidth(String s, int nlimit) { | |
231 | + StringBuilder wkname = new StringBuilder(); | |
232 | + int i; | |
233 | + int nwidth = 0; | |
234 | + for (i = 0; i < s.length(); i++) { | |
235 | + int c; | |
236 | + c = s.codePointAt(i); | |
237 | + if (Character.charCount(c) == 2) { | |
238 | + i++; | |
239 | + } | |
240 | + if (isSingleByte(c) == false) { | |
241 | + if (nwidth + 2 > nlimit) { | |
242 | + break; | |
243 | + } | |
244 | + nwidth += 2; | |
245 | + } else { | |
246 | + if (nwidth + 1 > nlimit) { | |
247 | + break; | |
248 | + } | |
249 | + nwidth++; | |
250 | + } | |
251 | + wkname.appendCodePoint(c); | |
252 | + } | |
253 | + if (nwidth < nlimit) { | |
254 | + StringBuilder wkspace = new StringBuilder(); | |
255 | + for (; nwidth < nlimit; nwidth++) { | |
256 | + wkspace.append(" "); | |
257 | + } | |
258 | + wkname.insert(0, wkspace); | |
259 | + } | |
260 | + return wkname.toString(); | |
261 | + } | |
262 | + | |
263 | + public static final String trimStringWidth(String s, int nlimit) { | |
264 | + StringBuilder wkname = new StringBuilder(); | |
265 | + int i; | |
266 | + int nwidth = 0; | |
267 | + for (i = 0; i < s.length(); i++) { | |
268 | + int c; | |
269 | + c = s.codePointAt(i); | |
270 | + if (Character.charCount(c) == 2) { | |
271 | + i++; | |
272 | + } | |
273 | + if (isSingleByte(c) == false) { | |
274 | + if (nwidth + 2 > nlimit) { | |
275 | + break; | |
276 | + } | |
277 | + nwidth += 2; | |
278 | + } else { | |
279 | + if (nwidth + 1 > nlimit) { | |
280 | + break; | |
281 | + } | |
282 | + nwidth++; | |
283 | + } | |
284 | + wkname.appendCodePoint(c); | |
285 | + } | |
286 | + return wkname.toString(); | |
287 | + } | |
288 | + | |
289 | + public static final String formatStringWidth(String s, int nview) { | |
290 | + StringBuilder wkname = new StringBuilder(); | |
291 | + int i; | |
292 | + int nwidth = 0; | |
293 | + for (i = 0; i < s.length(); i++) { | |
294 | + int c; | |
295 | + c = s.codePointAt(i); | |
296 | + if (Character.charCount(c) == 2) { | |
297 | + i++; | |
298 | + } | |
299 | + if (isSingleByte(c) == false) { | |
300 | + if (nwidth + 2 > nview) { | |
301 | + break; | |
302 | + } | |
303 | + nwidth += 2; | |
304 | + } else { | |
305 | + if (nwidth + 1 > nview) { | |
306 | + break; | |
307 | + } | |
308 | + nwidth++; | |
309 | + } | |
310 | + wkname.appendCodePoint(c); | |
311 | + } | |
312 | + for (; nwidth < nview; nwidth++) { | |
313 | + wkname.append(" "); | |
314 | + } | |
315 | + return wkname.toString(); | |
316 | + } | |
317 | + | |
196 | 318 | public static final int getType() { |
197 | 319 | return yourType; |
198 | 320 | } |
@@ -298,6 +420,7 @@ | ||
298 | 420 | } |
299 | 421 | } |
300 | 422 | nowWeapon[n] = new String(p, nidx, i + 1, SYSTEM_CHARSET); |
423 | + nowWeapon[n] = trimStringWidth(nowWeapon[n], WIDTH_VIEW_WEAPONNAME); | |
301 | 424 | } catch (UnsupportedEncodingException e) { |
302 | 425 | nowWeapon[n] = "?"; //NOI18N |
303 | 426 | } |
@@ -312,6 +435,7 @@ | ||
312 | 435 | } |
313 | 436 | } |
314 | 437 | nowItem[n] = new String(p, nidx, i + 1, SYSTEM_CHARSET); |
438 | + nowItem[n] = trimStringWidth(nowItem[n], WIDTH_VIEW_ITEMNAME); | |
315 | 439 | } catch (UnsupportedEncodingException e) { |
316 | 440 | nowItem[n] = "?"; //NOI18N |
317 | 441 | } |
@@ -464,6 +588,7 @@ | ||
464 | 588 | } else { |
465 | 589 | UserName = s; |
466 | 590 | } |
591 | + UserName = trimStringWidth(UserName, WIDTH_VIEW_USERNAME); | |
467 | 592 | } |
468 | 593 | |
469 | 594 | public static void setPassWord(String s) { |
@@ -800,7 +925,7 @@ | ||
800 | 925 | } |
801 | 926 | work = ifile.readLine(); |
802 | 927 | if (work != null) { |
803 | - UserName = work; | |
928 | + UserName = trimStringWidth(work, WIDTH_VIEW_USERNAME); | |
804 | 929 | } |
805 | 930 | mainWndBounds = load_rect(ifile); |
806 | 931 | statusViewBounds = load_rect(ifile); |
@@ -62,7 +62,7 @@ | ||
62 | 62 | add(label); |
63 | 63 | |
64 | 64 | gridbag.gridwidth = GridBagConstraints.REMAINDER; |
65 | - username = new TextField(Hunt.getUserName(), Hunt.USERNAME_LEN); | |
65 | + username = new TextField(Hunt.getUserName(), Hunt.WIDTH_VIEW_USERNAME); | |
66 | 66 | layout.setConstraints(username, gridbag); |
67 | 67 | username.addActionListener(this); |
68 | 68 | add(username); |
@@ -7,18 +7,29 @@ | ||
7 | 7 | |
8 | 8 | static void make_text_labels(Dialog dialog, String s) { |
9 | 9 | String wk; |
10 | + int nwidth; | |
10 | 11 | int ns = 0; |
11 | 12 | int pos = s.indexOf('\n'); |
12 | 13 | Panel panel = new Panel(new GridLayout(0, 1)); |
13 | 14 | while (pos != -1) { |
14 | 15 | wk = s.substring(ns, pos); |
16 | + nwidth = Hunt.countStringWidth(wk); | |
17 | + if (nwidth < 20) { | |
18 | + wk = Hunt.trimStringWidth(s, 20); | |
19 | + } | |
15 | 20 | panel.add(new Label(wk)); |
16 | 21 | ns = pos + 1; |
17 | 22 | pos = s.indexOf('\n', ns); |
18 | 23 | } |
19 | 24 | wk = s.substring(ns); |
25 | + nwidth = Hunt.countStringWidth(wk); | |
26 | + if (nwidth < 20) { | |
27 | + wk = Hunt.formatStringWidth(s, 20); | |
28 | + } | |
20 | 29 | panel.add(new Label(wk)); |
21 | 30 | dialog.add(panel, BorderLayout.CENTER); |
31 | + dialog.add(new Panel(), BorderLayout.WEST); | |
32 | + dialog.add(new Panel(), BorderLayout.EAST); | |
22 | 33 | } |
23 | 34 | |
24 | 35 | public static boolean MessageBox(Frame w, |
@@ -125,10 +125,11 @@ | ||
125 | 125 | } else { |
126 | 126 | work += Hunt.getBundle().getString("WHOLIST_HUNTER"); |
127 | 127 | } |
128 | - work += username; | |
129 | - work += " "; //NOI18N | |
130 | - DecimalFormat form = new DecimalFormat("#########0"); //NOI18N | |
131 | - work += form.format(wk_score); | |
128 | + work += "["; //NOI18N | |
129 | + work += Hunt.trimStringWidth(username, Hunt.WIDTH_VIEW_USERNAME); | |
130 | + work += "]"; //NOI18N | |
131 | + DecimalFormat form = new DecimalFormat("#,##0;-#,##0"); //NOI18N | |
132 | + work += Hunt.rightStringWidth(form.format(wk_score), 11); | |
132 | 133 | work += Hunt.getBundle().getString("LABEL_POINT"); |
133 | 134 | if (buffer[n] != 0) { |
134 | 135 | work += Hunt.getBundle().getString("WHOLIST_ONLINE"); |