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