• R/O
  • SSH
  • HTTPS

Commit

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

密猟オンラインクライアントプログラム JAVAベース


Commit MetaInfo

Revisão20 (tree)
Hora2016-12-24 02:30:37
Autormanjihq

Mensagem de Log

入力ボックスに履歴機能を追加
それに伴い、送信作業後に入力ボックスの内容を消去するようにした
入力ボックスでESCを推すと入力を初期化してメインビューへフォーカスを移動するようにした

Mudança Sumário

Diff

--- trunk/src/hunton/HuntMessageView.java (revision 19)
+++ trunk/src/hunton/HuntMessageView.java (revision 20)
@@ -2,15 +2,21 @@
22
33 import java.awt.*;
44 import java.awt.event.*;
5+import java.util.*;
56
67 public class HuntMessageView extends Frame implements ActionListener {
78
9+ static public final int HISTORY_MAX = 100;
810 TextArea messageList;
911 TextField editWnd;
12+ ArrayList<String> historyText;
13+ int historyPos;
1014
1115 @SuppressWarnings("LeakingThisInConstructor")
1216 HuntMessageView() {
1317 super(Hunt.getBundle().getString("TITLE_MESSAGE"));
18+ historyText = new ArrayList<>();
19+ historyPos = -1;
1420 messageList = new TextArea(10, 80);
1521 messageList.setEditable(false);
1622 messageList.setFont(new Font(Font.MONOSPACED, Font.PLAIN, 14));
@@ -19,6 +25,7 @@
1925 editWnd.setFont(new Font(Font.MONOSPACED, Font.PLAIN, 14));
2026 add(editWnd, BorderLayout.SOUTH);
2127 editWnd.addActionListener(this);
28+ editWnd.addKeyListener(new HuntMessageViewKeyEvent(this));
2229 setResizable(true);
2330 pack();
2431 }
@@ -45,6 +52,34 @@
4552 editWnd.setText(s);
4653 }
4754
55+ public String getNextHistory() {
56+ String wkstr;
57+ if (historyText.isEmpty()) {
58+ wkstr = "";
59+ } else {
60+ historyPos++;
61+ if (historyPos == historyText.size()) {
62+ historyPos = 0;
63+ }
64+ wkstr = historyText.get(historyPos);
65+ }
66+ return wkstr;
67+ }
68+
69+ public String getPrevHistory() {
70+ String wkstr;
71+ if (historyText.isEmpty()) {
72+ wkstr = "";
73+ } else {
74+ historyPos--;
75+ if (historyPos < 0) {
76+ historyPos = historyText.size() - 1;
77+ }
78+ wkstr = historyText.get(historyPos);
79+ }
80+ return wkstr;
81+ }
82+
4883 @Override
4984 public void actionPerformed(ActionEvent e) {
5085 /* send message or command */
@@ -52,7 +87,47 @@
5287 String mesg = hedit.getText();
5388 hedit.selectAll();
5489 Hunt.send_message(mesg);
90+ if (historyText.size() >= HuntMessageView.HISTORY_MAX) {
91+ //need to clear most old string
92+ historyText.remove(0);
93+ }
94+ historyText.add(mesg);
95+ historyPos = -1;
5596 }
5697 }
5798
99+class HuntMessageViewKeyEvent extends KeyAdapter {
100+
101+ HuntMessageView hview;
102+
103+ public HuntMessageViewKeyEvent(HuntMessageView v) {
104+ hview = v;
105+ }
106+
107+ @Override
108+ public void keyPressed(KeyEvent e) {
109+ String wkstr;
110+ switch (e.getKeyCode()) {
111+ case KeyEvent.VK_UP:
112+ case KeyEvent.VK_PAGE_UP:
113+ wkstr = hview.getPrevHistory();
114+ hview.setEditText(wkstr);
115+ break;
116+ case KeyEvent.VK_DOWN:
117+ case KeyEvent.VK_PAGE_DOWN:
118+ wkstr = hview.getNextHistory();
119+ hview.setEditText(wkstr);
120+ break;
121+ case KeyEvent.VK_ESCAPE:
122+ hview.setEditText("");
123+ Hunt.getMainWnd().toFront();
124+ break;
125+ default:
126+ super.keyPressed(e);
127+ break;
128+ }
129+ }
130+
131+}
132+
58133 /* EOF */
--- trunk/src/hunton/SendTask.java (revision 19)
+++ trunk/src/hunton/SendTask.java (revision 20)
@@ -245,6 +245,7 @@
245245 case 'S':
246246 /* just say */
247247
248+ bneed_clearedit = true;
248249 sayCommand(s);
249250 break;
250251
@@ -252,6 +253,7 @@
252253 case 'B':
253254 /* broadcast */
254255
256+ bneed_clearedit = true;
255257 broadcastCommand(s);
256258 break;
257259
@@ -259,6 +261,7 @@
259261 case 'T':
260262 /* tell anyone */
261263
264+ bneed_clearedit = true;
262265 tellCommand(s);
263266 break;
264267
@@ -268,6 +271,7 @@
268271 default:
269272 /* perhaps say... */
270273
274+ bneed_clearedit = true;
271275 doSendMessage(s);
272276 break;
273277 }