author | viric@mandarina |
Mon, 21 Jul 2008 00:05:50 +0200 | |
changeset 42 | df0d043aac70 |
parent 38 | 45c0a27c902f |
child 48 | f3660feedd64 |
permissions | -rw-r--r-- |
0 | 1 |
package jdict; |
2 |
||
3 |
import javax.microedition.lcdui.*; |
|
4 |
import java.util.Vector; |
|
10 | 5 |
import java.io.*; |
0 | 6 |
|
7 |
public class AskWord |
|
8 |
implements CommandListener |
|
9 |
{ |
|
10 |
private Form myform; |
|
4 | 11 |
private Command cmd_eliri; |
0 | 12 |
private Command cmd_sercxi; |
9
2507586786aa
Added Transliteration options, added BLOCK size in a file.
viric@llimona
parents:
8
diff
changeset
|
13 |
private Command cmd_montri; |
13 | 14 |
private Command cmd_pri; |
14 | 15 |
private Command cmd_vortarinformo; |
16 | 16 |
private Command cmd_agordoj; |
0 | 17 |
private TextField word; |
9
2507586786aa
Added Transliteration options, added BLOCK size in a file.
viric@llimona
parents:
8
diff
changeset
|
18 |
private ChoiceGroup translit; |
16 | 19 |
private String translit_neniu; |
20 |
private String translit_iksa; |
|
21 |
private String translit_rusa; |
|
42 | 22 |
private String translit_hungara; |
9
2507586786aa
Added Transliteration options, added BLOCK size in a file.
viric@llimona
parents:
8
diff
changeset
|
23 |
private StringItem showSearch; |
10 | 24 |
private String vortaro; |
38 | 25 |
private DictIndex index; |
0 | 26 |
|
27 |
public AskWord() |
|
28 |
{ |
|
10 | 29 |
get_vortaro(); |
6 | 30 |
|
38 | 31 |
index = new DictIndex(vortaro); |
32 |
||
0 | 33 |
show(); |
34 |
} |
|
35 |
||
10 | 36 |
public void get_vortaro() |
37 |
{ |
|
38 |
InputStream vfile = getClass().getResourceAsStream("/dicts/VORTARO"); |
|
12 | 39 |
if (vfile == null) |
40 |
{ |
|
41 |
vortaro = "ERROR"; |
|
42 |
return; |
|
43 |
} |
|
10 | 44 |
/* 50 bytes maximum for vortaro nomo */ |
45 |
byte array[] = new byte[50]; |
|
46 |
int total; |
|
47 |
try { |
|
48 |
total = vfile.read(array, 0, 50); |
|
49 |
} catch (IOException e) |
|
50 |
{ |
|
51 |
System.out.println("Cannot open VORTARO file. Going to ERROR B."); |
|
52 |
vortaro = "ERROR"; |
|
53 |
return; |
|
54 |
} |
|
55 |
/* This will have '\n' */ |
|
56 |
vortaro = new String(array, 0, total - 1 /* - \n */); |
|
57 |
} |
|
58 |
||
0 | 59 |
public void show() |
60 |
{ |
|
25 | 61 |
translit_neniu = T.t("Neniu"); |
62 |
translit_iksa = T.t("Iksa sistemo"); |
|
63 |
translit_rusa = T.t("ASCII-rusa"); |
|
42 | 64 |
translit_hungara = T.t("ASCII-hungara"); |
25 | 65 |
|
10 | 66 |
myform = new Form(vortaro); |
0 | 67 |
|
16 | 68 |
word = new TextField(T.t("Vorto:"), "", 20, TextField.ANY); |
0 | 69 |
myform.append(word); |
70 |
||
16 | 71 |
translit = new ChoiceGroup(T.t("Transliterigo"), ChoiceGroup.EXCLUSIVE); |
20
2f815ca5cb8c
Added prefix search and 'Transliterigo' saving in record.
viric@mandarina
parents:
19
diff
changeset
|
72 |
|
2f815ca5cb8c
Added prefix search and 'Transliterigo' saving in record.
viric@mandarina
parents:
19
diff
changeset
|
73 |
String tselected = Mem.getVariable("Transliterigo"); |
38 | 74 |
int lindex; |
75 |
lindex = translit.append(translit_neniu, null); |
|
20
2f815ca5cb8c
Added prefix search and 'Transliterigo' saving in record.
viric@mandarina
parents:
19
diff
changeset
|
76 |
if (tselected != null && tselected.equals(translit_neniu)) |
38 | 77 |
translit.setSelectedIndex(lindex, true); |
78 |
lindex = translit.append(translit_iksa, null); |
|
20
2f815ca5cb8c
Added prefix search and 'Transliterigo' saving in record.
viric@mandarina
parents:
19
diff
changeset
|
79 |
if (tselected != null && tselected.equals(translit_iksa)) |
38 | 80 |
translit.setSelectedIndex(lindex, true); |
9
2507586786aa
Added Transliteration options, added BLOCK size in a file.
viric@llimona
parents:
8
diff
changeset
|
81 |
translit.append(translit_rusa, null); |
20
2f815ca5cb8c
Added prefix search and 'Transliterigo' saving in record.
viric@mandarina
parents:
19
diff
changeset
|
82 |
if (tselected != null && tselected.equals(translit_rusa)) |
38 | 83 |
translit.setSelectedIndex(lindex, true); |
42 | 84 |
translit.append(translit_hungara, null); |
85 |
if (tselected != null && tselected.equals(translit_hungara)) |
|
86 |
translit.setSelectedIndex(lindex, true); |
|
20
2f815ca5cb8c
Added prefix search and 'Transliterigo' saving in record.
viric@mandarina
parents:
19
diff
changeset
|
87 |
if (tselected == null) |
2f815ca5cb8c
Added prefix search and 'Transliterigo' saving in record.
viric@mandarina
parents:
19
diff
changeset
|
88 |
translit.setSelectedIndex(0, true); |
9
2507586786aa
Added Transliteration options, added BLOCK size in a file.
viric@llimona
parents:
8
diff
changeset
|
89 |
myform.append(translit); |
2507586786aa
Added Transliteration options, added BLOCK size in a file.
viric@llimona
parents:
8
diff
changeset
|
90 |
|
2507586786aa
Added Transliteration options, added BLOCK size in a file.
viric@llimona
parents:
8
diff
changeset
|
91 |
/* DEBUG */ |
16 | 92 |
showSearch = new StringItem(T.t("Serĉonte:"), ""); |
9
2507586786aa
Added Transliteration options, added BLOCK size in a file.
viric@llimona
parents:
8
diff
changeset
|
93 |
myform.append(showSearch); |
2507586786aa
Added Transliteration options, added BLOCK size in a file.
viric@llimona
parents:
8
diff
changeset
|
94 |
|
16 | 95 |
cmd_sercxi = new Command(T.t("Serĉi"), Command.OK, 0); |
9
2507586786aa
Added Transliteration options, added BLOCK size in a file.
viric@llimona
parents:
8
diff
changeset
|
96 |
myform.addCommand(cmd_sercxi); |
2507586786aa
Added Transliteration options, added BLOCK size in a file.
viric@llimona
parents:
8
diff
changeset
|
97 |
/* Commands */ |
16 | 98 |
cmd_montri = new Command(T.t("Montri"), Command.HELP, 1); |
9
2507586786aa
Added Transliteration options, added BLOCK size in a file.
viric@llimona
parents:
8
diff
changeset
|
99 |
myform.addCommand(cmd_montri); |
0 | 100 |
/* Commands */ |
16 | 101 |
cmd_pri = new Command(T.t("Pri ĉi tio"), Command.HELP, 2); |
13 | 102 |
myform.addCommand(cmd_pri); |
103 |
/* Commands */ |
|
16 | 104 |
cmd_vortarinformo = new Command(T.t("Vortarinformo"), Command.HELP, 3); |
14 | 105 |
myform.addCommand(cmd_vortarinformo); |
106 |
/* Commands */ |
|
16 | 107 |
cmd_agordoj = new Command(T.t("Agordoj"), Command.HELP, 3); |
108 |
myform.addCommand(cmd_agordoj); |
|
109 |
/* Commands */ |
|
110 |
cmd_eliri = new Command(T.t("Eliri"), Command.BACK, 4); |
|
4 | 111 |
myform.addCommand(cmd_eliri); |
0 | 112 |
|
113 |
myform.setCommandListener(this); |
|
114 |
Main.display.setCurrent(myform); |
|
115 |
} |
|
116 |
||
19 | 117 |
private String transliterate(String from) |
118 |
{ |
|
119 |
String out = from; |
|
120 |
if (translit.getString(translit.getSelectedIndex()) |
|
121 |
.equals(translit_iksa)) |
|
122 |
out = Replace.IksojAlCxapeloj(from); |
|
123 |
else if (translit.getString(translit.getSelectedIndex()) |
|
124 |
.equals(translit_rusa)) |
|
125 |
out = Replace.AsciiAlRusa(from); |
|
42 | 126 |
else if (translit.getString(translit.getSelectedIndex()) |
127 |
.equals(translit_hungara)) |
|
128 |
out = Replace.AsciiAlHungara(from); |
|
19 | 129 |
|
130 |
return out; |
|
131 |
} |
|
132 |
||
0 | 133 |
public void commandAction(Command c, Displayable d) |
134 |
{ |
|
135 |
if (c == cmd_sercxi) |
|
136 |
{ |
|
9
2507586786aa
Added Transliteration options, added BLOCK size in a file.
viric@llimona
parents:
8
diff
changeset
|
137 |
String toSearch = word.getString(); |
19 | 138 |
toSearch = transliterate(toSearch); |
6 | 139 |
|
9
2507586786aa
Added Transliteration options, added BLOCK size in a file.
viric@llimona
parents:
8
diff
changeset
|
140 |
showSearch.setText(toSearch); |
38 | 141 |
SearchThread t = new SearchThread(toSearch, vortaro, index, myform); |
11 | 142 |
|
22 | 143 |
SearchScreen s = new SearchScreen(toSearch); |
144 |
t.start(); |
|
0 | 145 |
} |
4 | 146 |
else if (c == cmd_eliri) |
147 |
{ |
|
20
2f815ca5cb8c
Added prefix search and 'Transliterigo' saving in record.
viric@mandarina
parents:
19
diff
changeset
|
148 |
String tselected = translit.getString(translit.getSelectedIndex()); |
2f815ca5cb8c
Added prefix search and 'Transliterigo' saving in record.
viric@mandarina
parents:
19
diff
changeset
|
149 |
Mem.setVariable("Transliterigo", tselected); |
4 | 150 |
Main.main.quit(); |
151 |
} |
|
9
2507586786aa
Added Transliteration options, added BLOCK size in a file.
viric@llimona
parents:
8
diff
changeset
|
152 |
else if (c == cmd_montri) |
2507586786aa
Added Transliteration options, added BLOCK size in a file.
viric@llimona
parents:
8
diff
changeset
|
153 |
{ |
2507586786aa
Added Transliteration options, added BLOCK size in a file.
viric@llimona
parents:
8
diff
changeset
|
154 |
String toSearch = word.getString(); |
19 | 155 |
toSearch = transliterate(toSearch); |
9
2507586786aa
Added Transliteration options, added BLOCK size in a file.
viric@llimona
parents:
8
diff
changeset
|
156 |
|
2507586786aa
Added Transliteration options, added BLOCK size in a file.
viric@llimona
parents:
8
diff
changeset
|
157 |
showSearch.setText(toSearch); |
2507586786aa
Added Transliteration options, added BLOCK size in a file.
viric@llimona
parents:
8
diff
changeset
|
158 |
} |
13 | 159 |
else if (c == cmd_pri) |
160 |
{ |
|
161 |
ShowText text = new ShowText( |
|
33 | 162 |
/* Versio */ |
38 | 163 |
"JDict v0.3 - Vortara programo laŭ stilo dictd " + |
13 | 164 |
"(http://www.dict.org)\n" + |
165 |
"Kopirajto (C) 2007 Lluís Batlle i Rossell\n" + |
|
166 |
"Tiun ĉi programon mi distribuas laŭ permesilo " + |
|
167 |
"GPL versio 2 aŭ posta. Vidu la fontokodon por " + |
|
168 |
"pliaj detaloj.\n" + |
|
169 |
"Plia informo, pluaj elŝutoj: " + |
|
170 |
"http://vicerveza.homeunix.net/~viric/dict/jdict" |
|
171 |
, myform); |
|
172 |
} |
|
14 | 173 |
else if (c == cmd_vortarinformo) |
174 |
{ |
|
175 |
Vector results; |
|
176 |
String text = ""; |
|
177 |
||
178 |
/* Already at start */ |
|
179 |
results = index.SearchDefinition("00databaseinfo", 5); |
|
180 |
if (results.size() > 0) |
|
181 |
text += "Database Info:\n" + (String) results.elementAt(0) |
|
182 |
+ "\n"; |
|
183 |
||
184 |
results = index.SearchDefinition("00databaseshort", 5); |
|
185 |
if (results.size() > 0) |
|
186 |
text += "Database Short:\n" + (String) results.elementAt(0) |
|
187 |
+ "\n"; |
|
188 |
||
189 |
results = index.SearchDefinition("00databaseurl", 5); |
|
190 |
if (results.size() > 0) |
|
191 |
text += "Database URL:\n" + (String) results.elementAt(0) |
|
192 |
+ "\n"; |
|
193 |
||
194 |
ShowText textwin = new ShowText(text, myform); |
|
195 |
} |
|
16 | 196 |
else if (c == cmd_agordoj) |
197 |
{ |
|
198 |
/* This opens a new form */ |
|
199 |
Config config = new Config(this, myform); |
|
200 |
} |
|
0 | 201 |
} |
202 |
} |