Mercurial > 510Connectbot
annotate src/org/tn5250j/framework/tn5250/KeyStrokenizer.java @ 353:20412de44c06
update jsocks to 2011-03-19
author | Carl Byington <carl@five-ten-sg.com> |
---|---|
date | Fri, 01 Aug 2014 11:35:35 -0700 |
parents | 77ac18bc1b2f |
children | e2a56e383bad |
rev | line source |
---|---|
3 | 1 /* |
2 * @(#)KeyStrokenizer.java | |
3 * Copyright: Copyright (c) 2001 | |
4 * | |
5 * This program is free software; you can redistribute it and/or modify | |
6 * it under the terms of the GNU General Public License as published by | |
7 * the Free Software Foundation; either version 2, or (at your option) | |
8 * any later version. | |
9 * | |
10 * This program is distributed in the hope that it will be useful, | |
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 * GNU General Public License for more details. | |
14 * | |
15 * You should have received a copy of the GNU General Public License | |
16 * along with this software; see the file COPYING. If not, write to | |
17 * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, | |
18 * Boston, MA 02111-1307 USA | |
19 * | |
20 */ | |
21 | |
22 package org.tn5250j.framework.tn5250; | |
23 | |
25
5949eb469a79
adding tn5250 files, native android logging
Carl Byington <carl@five-ten-sg.com>
parents:
3
diff
changeset
|
24 import android.util.Log; |
5949eb469a79
adding tn5250 files, native android logging
Carl Byington <carl@five-ten-sg.com>
parents:
3
diff
changeset
|
25 |
3 | 26 |
27 | |
28 public class KeyStrokenizer { | |
27
b29b39f386a4
adding tn5250 files, native android logging
Carl Byington <carl@five-ten-sg.com>
parents:
25
diff
changeset
|
29 private static final String TAG = "KeyStrokenizer"; |
48
1e931ef5f776
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
27
diff
changeset
|
30 private StringBuffer keyStrokes; |
1e931ef5f776
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
27
diff
changeset
|
31 private StringBuffer sb; |
1e931ef5f776
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
27
diff
changeset
|
32 private int index; |
1e931ef5f776
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
27
diff
changeset
|
33 private int length; |
27
b29b39f386a4
adding tn5250 files, native android logging
Carl Byington <carl@five-ten-sg.com>
parents:
25
diff
changeset
|
34 |
25
5949eb469a79
adding tn5250 files, native android logging
Carl Byington <carl@five-ten-sg.com>
parents:
3
diff
changeset
|
35 |
27
b29b39f386a4
adding tn5250 files, native android logging
Carl Byington <carl@five-ten-sg.com>
parents:
25
diff
changeset
|
36 |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
48
diff
changeset
|
37 public KeyStrokenizer() { |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
48
diff
changeset
|
38 sb = new StringBuffer(); |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
48
diff
changeset
|
39 setKeyStrokes(null); |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
48
diff
changeset
|
40 } |
3 | 41 |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
48
diff
changeset
|
42 public void setKeyStrokes(String strokes) { |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
48
diff
changeset
|
43 if (strokes != null) { |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
48
diff
changeset
|
44 keyStrokes.setLength(0); |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
48
diff
changeset
|
45 Log.d(TAG, "set " + keyStrokes); |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
48
diff
changeset
|
46 length = strokes.length(); |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
48
diff
changeset
|
47 } |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
48
diff
changeset
|
48 else { |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
48
diff
changeset
|
49 keyStrokes = new StringBuffer(); |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
48
diff
changeset
|
50 length = 0; |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
48
diff
changeset
|
51 } |
3 | 52 |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
48
diff
changeset
|
53 keyStrokes.append(strokes); |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
48
diff
changeset
|
54 index = 0; |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
48
diff
changeset
|
55 } |
3 | 56 |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
48
diff
changeset
|
57 public boolean hasMoreKeyStrokes() { |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
48
diff
changeset
|
58 return length > index; |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
48
diff
changeset
|
59 } |
3 | 60 |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
48
diff
changeset
|
61 public String nextKeyStroke() { |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
48
diff
changeset
|
62 String s = ""; |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
48
diff
changeset
|
63 boolean gotOne = false; |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
48
diff
changeset
|
64 |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
48
diff
changeset
|
65 if (length > index) { |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
48
diff
changeset
|
66 sb.setLength(0); |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
48
diff
changeset
|
67 char c = keyStrokes.charAt(index); |
3 | 68 |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
48
diff
changeset
|
69 switch (c) { |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
48
diff
changeset
|
70 case '[': |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
48
diff
changeset
|
71 sb.append(c); |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
48
diff
changeset
|
72 index++; |
3 | 73 |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
48
diff
changeset
|
74 // we need to throw an error here |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
48
diff
changeset
|
75 if (index >= length) { |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
48
diff
changeset
|
76 Log.w(TAG, " mnemonic key was incomplete :1 " + |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
48
diff
changeset
|
77 "at position " + index + " len " + length); |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
48
diff
changeset
|
78 } |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
48
diff
changeset
|
79 else { |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
48
diff
changeset
|
80 c = keyStrokes.charAt(index); |
3 | 81 |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
48
diff
changeset
|
82 if (c == '[') |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
48
diff
changeset
|
83 index++; |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
48
diff
changeset
|
84 else { |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
48
diff
changeset
|
85 while (!gotOne) { |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
48
diff
changeset
|
86 if (c == ']') { // did we find an ending |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
48
diff
changeset
|
87 sb.append(c); |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
48
diff
changeset
|
88 index++; |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
48
diff
changeset
|
89 gotOne = true; |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
48
diff
changeset
|
90 } |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
48
diff
changeset
|
91 else { |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
48
diff
changeset
|
92 sb.append(c); |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
48
diff
changeset
|
93 index++; |
3 | 94 |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
48
diff
changeset
|
95 // we need to throw an error here because we did not |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
48
diff
changeset
|
96 // find an ending for the potential mnemonic |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
48
diff
changeset
|
97 if (index >= length) { |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
48
diff
changeset
|
98 Log.w(TAG, |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
48
diff
changeset
|
99 " mnemonic key was incomplete ending not found :2 " + |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
48
diff
changeset
|
100 "at position " + index); |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
48
diff
changeset
|
101 } |
3 | 102 |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
48
diff
changeset
|
103 c = keyStrokes.charAt(index); |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
48
diff
changeset
|
104 } |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
48
diff
changeset
|
105 } |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
48
diff
changeset
|
106 } |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
48
diff
changeset
|
107 } |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
48
diff
changeset
|
108 |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
48
diff
changeset
|
109 break; |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
48
diff
changeset
|
110 |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
48
diff
changeset
|
111 case ']': |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
48
diff
changeset
|
112 index++; |
3 | 113 |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
48
diff
changeset
|
114 if (index >= length) { |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
48
diff
changeset
|
115 Log.w(TAG, |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
48
diff
changeset
|
116 " mnemonic key was incomplete ending not found :3 " + |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
48
diff
changeset
|
117 "at position " + index); |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
48
diff
changeset
|
118 sb.append(c); |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
48
diff
changeset
|
119 index++; |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
48
diff
changeset
|
120 } |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
48
diff
changeset
|
121 else { |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
48
diff
changeset
|
122 c = keyStrokes.charAt(index); |
3 | 123 |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
48
diff
changeset
|
124 if (c == ']') { |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
48
diff
changeset
|
125 sb.append(c); |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
48
diff
changeset
|
126 index++; |
3 | 127 } |
128 else { | |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
48
diff
changeset
|
129 Log.w(TAG, |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
48
diff
changeset
|
130 " mnemonic key was incomplete beginning not found :4 " + |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
48
diff
changeset
|
131 "at position " + index); |
3 | 132 } |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
48
diff
changeset
|
133 } |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
48
diff
changeset
|
134 |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
48
diff
changeset
|
135 break; |
3 | 136 |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
48
diff
changeset
|
137 default: |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
48
diff
changeset
|
138 sb.append(c); |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
48
diff
changeset
|
139 index++; |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
48
diff
changeset
|
140 break; |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
48
diff
changeset
|
141 } |
3 | 142 |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
48
diff
changeset
|
143 if (sb != null) { |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
48
diff
changeset
|
144 s = new String(sb); |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
48
diff
changeset
|
145 } |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
48
diff
changeset
|
146 } |
3 | 147 |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
48
diff
changeset
|
148 Log.d(TAG, "next " + keyStrokes); |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
48
diff
changeset
|
149 return s; |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
48
diff
changeset
|
150 } |
3 | 151 |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
48
diff
changeset
|
152 public String getUnprocessedKeyStroked() { |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
48
diff
changeset
|
153 if (index >= length) { |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
48
diff
changeset
|
154 return null; |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
48
diff
changeset
|
155 } |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
48
diff
changeset
|
156 |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
48
diff
changeset
|
157 return keyStrokes.substring(index); |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
48
diff
changeset
|
158 } |
3 | 159 |
160 } |