Mercurial > 510Connectbot
annotate src/org/tn5250j/framework/tn5250/KeyStrokenizer.java @ 100:9204fe526e65
finish setField()
author | Carl Byington <carl@five-ten-sg.com> |
---|---|
date | Tue, 17 Jun 2014 15:57:18 -0700 |
parents | 1e931ef5f776 |
children | 77ac18bc1b2f |
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 |
3 | 37 public KeyStrokenizer() { |
38 | |
39 sb = new StringBuffer(); | |
40 setKeyStrokes(null); | |
41 } | |
42 | |
43 public void setKeyStrokes (String strokes) { | |
44 | |
45 if (strokes != null) { | |
46 keyStrokes.setLength(0); | |
25
5949eb469a79
adding tn5250 files, native android logging
Carl Byington <carl@five-ten-sg.com>
parents:
3
diff
changeset
|
47 Log.d(TAG,"set "+ keyStrokes); |
3 | 48 length = strokes.length(); |
49 } | |
50 else { | |
51 | |
52 keyStrokes = new StringBuffer(); | |
53 length = 0; | |
54 | |
55 } | |
56 keyStrokes.append(strokes); | |
57 index = 0; | |
58 | |
59 } | |
60 | |
61 public boolean hasMoreKeyStrokes() { | |
62 return length > index; | |
63 } | |
64 | |
65 public String nextKeyStroke() { | |
66 | |
67 String s = ""; | |
68 boolean gotOne = false; | |
69 if(length > index) { | |
70 sb.setLength(0); | |
71 | |
72 char c = keyStrokes.charAt(index); | |
73 switch(c) { | |
74 case '[': | |
75 sb.append(c); | |
76 index++; | |
77 | |
78 // we need to throw an error here | |
79 if(index >= length) { | |
25
5949eb469a79
adding tn5250 files, native android logging
Carl Byington <carl@five-ten-sg.com>
parents:
3
diff
changeset
|
80 Log.w(TAG," mnemonic key was incomplete :1 " + |
3 | 81 "at position " + index + " len " + length ); |
82 } | |
83 else { | |
84 c = keyStrokes.charAt(index); | |
85 | |
86 if(c == '[') | |
87 index++; | |
88 else { | |
89 while(!gotOne) { | |
90 | |
91 if(c == ']') { // did we find an ending | |
92 sb.append(c); | |
93 index++; | |
94 gotOne = true; | |
95 } | |
96 else { | |
97 sb.append(c); | |
98 index++; | |
99 // we need to throw an error here because we did not | |
100 // find an ending for the potential mnemonic | |
101 if(index >= length) { | |
25
5949eb469a79
adding tn5250 files, native android logging
Carl Byington <carl@five-ten-sg.com>
parents:
3
diff
changeset
|
102 Log.w(TAG, |
3 | 103 " mnemonic key was incomplete ending not found :2 " + |
104 "at position " + index); | |
105 } | |
106 c = keyStrokes.charAt(index); | |
107 } | |
108 } | |
109 } | |
110 } | |
111 break; | |
112 | |
113 case ']': | |
114 index++; | |
115 if(index >= length) { | |
25
5949eb469a79
adding tn5250 files, native android logging
Carl Byington <carl@five-ten-sg.com>
parents:
3
diff
changeset
|
116 Log.w(TAG, |
3 | 117 " mnemonic key was incomplete ending not found :3 " + |
118 "at position " + index); | |
119 sb.append(c); | |
120 index++; | |
121 | |
122 } | |
123 else { | |
124 c = keyStrokes.charAt(index); | |
125 if(c == ']') { | |
126 sb.append(c); | |
127 index++; | |
128 } | |
129 else { | |
25
5949eb469a79
adding tn5250 files, native android logging
Carl Byington <carl@five-ten-sg.com>
parents:
3
diff
changeset
|
130 Log.w(TAG, |
3 | 131 " mnemonic key was incomplete beginning not found :4 " + |
132 "at position " + index); | |
133 } | |
134 } | |
135 break; | |
136 default: | |
137 sb.append(c); | |
138 index++; | |
139 break; | |
140 } | |
141 if(sb != null) { | |
142 s = new String(sb); | |
143 } | |
144 | |
145 } | |
25
5949eb469a79
adding tn5250 files, native android logging
Carl Byington <carl@five-ten-sg.com>
parents:
3
diff
changeset
|
146 Log.d(TAG,"next "+ keyStrokes); |
3 | 147 |
148 return s; | |
149 } | |
150 | |
151 public String getUnprocessedKeyStroked() { | |
152 if(index >= length) { | |
153 return null; | |
154 } | |
155 return keyStrokes.substring(index); | |
156 } | |
157 | |
158 } |