密猟オンラインクライアントプログラム JAVAベース
システムメッセージでリスト表示が必要そうなものをリスト表示ウィンドウへ表示するようにした
@@ -148,10 +148,12 @@ | ||
148 | 148 | static Component mainView; |
149 | 149 | static Component statusView; |
150 | 150 | static Component messageView; |
151 | + static HuntListView listViewWnd; | |
151 | 152 | |
152 | 153 | static Rectangle mainWndBounds; |
153 | 154 | static Rectangle statusViewBounds; |
154 | 155 | static Rectangle messageViewBounds; |
156 | + static Rectangle listViewBounds; | |
155 | 157 | |
156 | 158 | static pktio session; |
157 | 159 | static RecvTask rtask; |
@@ -606,6 +608,19 @@ | ||
606 | 608 | } |
607 | 609 | } |
608 | 610 | |
611 | + public static void kick_listview(String s) { | |
612 | + if (listViewWnd == null) { | |
613 | + listViewWnd = new HuntListView(); | |
614 | + if (listViewBounds == null) { | |
615 | + listViewWnd.setBounds(0, 0, 400, 300); | |
616 | + } else { | |
617 | + listViewWnd.setBounds(listViewBounds); | |
618 | + } | |
619 | + listViewWnd.setVisible(true); | |
620 | + } | |
621 | + listViewWnd.add_message(s); | |
622 | + } | |
623 | + | |
609 | 624 | public static void set_effect(int n, long nspan) { |
610 | 625 | if (messageView != null) { |
611 | 626 | HuntMainView hview = (HuntMainView) mainView; |
@@ -796,6 +811,7 @@ | ||
796 | 811 | messageView.setVisible(true); |
797 | 812 | |
798 | 813 | mainWnd.setVisible(true); |
814 | + mainWnd.toFront(); | |
799 | 815 | } |
800 | 816 | |
801 | 817 | /* try to login server */ |
@@ -860,6 +876,7 @@ | ||
860 | 876 | save_rect(ofile, mainWndBounds); |
861 | 877 | save_rect(ofile, statusViewBounds); |
862 | 878 | save_rect(ofile, messageViewBounds); |
879 | + save_rect(ofile, listViewBounds); | |
863 | 880 | } |
864 | 881 | } catch (IOException e) { |
865 | 882 | System.out.println("fail to save setup-file!"); //NOI18N |
@@ -911,6 +928,7 @@ | ||
911 | 928 | mainWndBounds = null; |
912 | 929 | statusViewBounds = null; |
913 | 930 | messageViewBounds = null; |
931 | + listViewBounds = null; | |
914 | 932 | try { |
915 | 933 | try (BufferedReader ifile |
916 | 934 | = new BufferedReader(new FileReader("hunt_setup.def"))) { //NOI18N |
@@ -930,6 +948,7 @@ | ||
930 | 948 | mainWndBounds = load_rect(ifile); |
931 | 949 | statusViewBounds = load_rect(ifile); |
932 | 950 | messageViewBounds = load_rect(ifile); |
951 | + listViewBounds = load_rect(ifile); | |
933 | 952 | } |
934 | 953 | } catch (IOException e) { |
935 | 954 | } |
@@ -948,6 +967,10 @@ | ||
948 | 967 | statusViewBounds = wnd.getBounds(); |
949 | 968 | wnd.dispose(); |
950 | 969 | } |
970 | + if (listViewWnd != null) { | |
971 | + listViewBounds = listViewWnd.getBounds(); | |
972 | + listViewWnd.dispose(); | |
973 | + } | |
951 | 974 | if (mainWnd != null) { |
952 | 975 | mainWndBounds = mainWnd.getBounds(); |
953 | 976 | mainWnd.dispose(); |
@@ -0,0 +1,86 @@ | ||
1 | +package hunton; | |
2 | + | |
3 | +import java.awt.*; | |
4 | +import java.awt.event.*; | |
5 | +import java.util.ArrayList; | |
6 | + | |
7 | +/** | |
8 | + * List view window | |
9 | + * | |
10 | + * @author terry | |
11 | + */ | |
12 | +public class HuntListView extends Frame { | |
13 | + | |
14 | + List plist; | |
15 | + ArrayList<String> mesg; | |
16 | + ArrayList<Integer> fieldWidth; | |
17 | + | |
18 | + HuntListView() { | |
19 | + super(); | |
20 | + mesg = new ArrayList<>(); | |
21 | + fieldWidth = new ArrayList<>(); | |
22 | + ScrollPane scpane = new ScrollPane(); | |
23 | + plist = new List(); | |
24 | + plist.setFont(new Font(Font.MONOSPACED, Font.PLAIN, 12)); | |
25 | + scpane.add(plist); | |
26 | + add(scpane); | |
27 | + addWindowListener(new HuntListViewEvent()); | |
28 | + pack(); | |
29 | + } | |
30 | + | |
31 | + int add_mesg_fields(String s) { | |
32 | + String fields[] = s.split(":"); | |
33 | + int i; | |
34 | + for (i = 0; i < fields.length; i++) { | |
35 | + int n = Hunt.countStringWidth(fields[i]); | |
36 | + if (i < fieldWidth.size()) { | |
37 | + if (n > fieldWidth.get(i)) { | |
38 | + fieldWidth.set(i, n); | |
39 | + } | |
40 | + } else { | |
41 | + fieldWidth.add(n); | |
42 | + } | |
43 | + } | |
44 | + mesg.add(s); | |
45 | + return i; | |
46 | + } | |
47 | + | |
48 | + String format_message_line(String s) { | |
49 | + int i; | |
50 | + StringBuilder wk = new StringBuilder(); | |
51 | + String fields[] = s.split(":"); | |
52 | + for (i = 0; i < fields.length; i++) { | |
53 | + wk.append(Hunt.formatStringWidth(fields[i], fieldWidth.get(i))); | |
54 | + wk.append(":"); | |
55 | + } | |
56 | + if (i > 0) { | |
57 | + //remove last separator | |
58 | + wk.deleteCharAt(wk.length() - 1); | |
59 | + } | |
60 | + return wk.toString(); | |
61 | + } | |
62 | + | |
63 | + public void add_message(String s) { | |
64 | + if (add_mesg_fields(s) == 1) { | |
65 | + //found last message mark | |
66 | + //update list view | |
67 | + int i; | |
68 | + plist.removeAll(); | |
69 | + for (i = 0; i < mesg.size(); i++) { | |
70 | + plist.add(format_message_line(mesg.get(i))); | |
71 | + } | |
72 | + mesg.clear(); | |
73 | + } | |
74 | + } | |
75 | + | |
76 | +} | |
77 | + | |
78 | +class HuntListViewEvent extends WindowAdapter { | |
79 | + | |
80 | + @Override | |
81 | + public void windowClosing(WindowEvent e) { | |
82 | + } | |
83 | + | |
84 | +} | |
85 | + | |
86 | +/* EOF */ |
@@ -100,7 +100,11 @@ | ||
100 | 100 | } catch (UnsupportedEncodingException e) { |
101 | 101 | message = "?"; //NOI18N |
102 | 102 | } |
103 | - Hunt.display_message(message); | |
103 | + if (message.length() > 1 && message.charAt(0) == '<') { | |
104 | + Hunt.kick_listview(message); | |
105 | + } else { | |
106 | + Hunt.display_message(message); | |
107 | + } | |
104 | 108 | } |
105 | 109 | } |
106 | 110 |