author | viric@mandarina |
Sun, 29 Jul 2007 21:42:52 +0200 | |
changeset 23 | 8e2034f0b934 |
parent 22 | 41c03c688d65 |
child 25 | 764c48b54327 |
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; |
0 | 24 |
|
25 |
public AskWord() |
|
26 |
{ |
|
16 | 27 |
translit_neniu = T.t("Neniu"); |
28 |
translit_iksa = T.t("Iksa sistemo"); |
|
29 |
translit_rusa = T.t("ASCII-rusa"); |
|
10 | 30 |
get_vortaro(); |
6 | 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 |
{ |
|
10 | 60 |
myform = new Form(vortaro); |
0 | 61 |
|
16 | 62 |
word = new TextField(T.t("Vorto:"), "", 20, TextField.ANY); |
0 | 63 |
myform.append(word); |
64 |
||
16 | 65 |
translit = new ChoiceGroup(T.t("Transliterigo"), ChoiceGroup.EXCLUSIVE); |
20
2f815ca5cb8c
Added prefix search and 'Transliterigo' saving in record.
viric@mandarina
parents:
19
diff
changeset
|
66 |
|
2f815ca5cb8c
Added prefix search and 'Transliterigo' saving in record.
viric@mandarina
parents:
19
diff
changeset
|
67 |
String tselected = Mem.getVariable("Transliterigo"); |
2f815ca5cb8c
Added prefix search and 'Transliterigo' saving in record.
viric@mandarina
parents:
19
diff
changeset
|
68 |
int index; |
2f815ca5cb8c
Added prefix search and 'Transliterigo' saving in record.
viric@mandarina
parents:
19
diff
changeset
|
69 |
index = translit.append(translit_neniu, null); |
2f815ca5cb8c
Added prefix search and 'Transliterigo' saving in record.
viric@mandarina
parents:
19
diff
changeset
|
70 |
if (tselected != null && tselected.equals(translit_neniu)) |
2f815ca5cb8c
Added prefix search and 'Transliterigo' saving in record.
viric@mandarina
parents:
19
diff
changeset
|
71 |
translit.setSelectedIndex(index, true); |
2f815ca5cb8c
Added prefix search and 'Transliterigo' saving in record.
viric@mandarina
parents:
19
diff
changeset
|
72 |
index = translit.append(translit_iksa, null); |
2f815ca5cb8c
Added prefix search and 'Transliterigo' saving in record.
viric@mandarina
parents:
19
diff
changeset
|
73 |
if (tselected != null && tselected.equals(translit_iksa)) |
2f815ca5cb8c
Added prefix search and 'Transliterigo' saving in record.
viric@mandarina
parents:
19
diff
changeset
|
74 |
translit.setSelectedIndex(index, true); |
9
2507586786aa
Added Transliteration options, added BLOCK size in a file.
viric@llimona
parents:
8
diff
changeset
|
75 |
translit.append(translit_rusa, null); |
20
2f815ca5cb8c
Added prefix search and 'Transliterigo' saving in record.
viric@mandarina
parents:
19
diff
changeset
|
76 |
if (tselected != null && tselected.equals(translit_rusa)) |
2f815ca5cb8c
Added prefix search and 'Transliterigo' saving in record.
viric@mandarina
parents:
19
diff
changeset
|
77 |
translit.setSelectedIndex(index, true); |
2f815ca5cb8c
Added prefix search and 'Transliterigo' saving in record.
viric@mandarina
parents:
19
diff
changeset
|
78 |
if (tselected == null) |
2f815ca5cb8c
Added prefix search and 'Transliterigo' saving in record.
viric@mandarina
parents:
19
diff
changeset
|
79 |
translit.setSelectedIndex(0, true); |
9
2507586786aa
Added Transliteration options, added BLOCK size in a file.
viric@llimona
parents:
8
diff
changeset
|
80 |
myform.append(translit); |
2507586786aa
Added Transliteration options, added BLOCK size in a file.
viric@llimona
parents:
8
diff
changeset
|
81 |
|
2507586786aa
Added Transliteration options, added BLOCK size in a file.
viric@llimona
parents:
8
diff
changeset
|
82 |
/* DEBUG */ |
16 | 83 |
showSearch = new StringItem(T.t("Serĉonte:"), ""); |
9
2507586786aa
Added Transliteration options, added BLOCK size in a file.
viric@llimona
parents:
8
diff
changeset
|
84 |
myform.append(showSearch); |
2507586786aa
Added Transliteration options, added BLOCK size in a file.
viric@llimona
parents:
8
diff
changeset
|
85 |
|
16 | 86 |
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
|
87 |
myform.addCommand(cmd_sercxi); |
2507586786aa
Added Transliteration options, added BLOCK size in a file.
viric@llimona
parents:
8
diff
changeset
|
88 |
/* Commands */ |
16 | 89 |
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
|
90 |
myform.addCommand(cmd_montri); |
0 | 91 |
/* Commands */ |
16 | 92 |
cmd_pri = new Command(T.t("Pri ĉi tio"), Command.HELP, 2); |
13 | 93 |
myform.addCommand(cmd_pri); |
94 |
/* Commands */ |
|
16 | 95 |
cmd_vortarinformo = new Command(T.t("Vortarinformo"), Command.HELP, 3); |
14 | 96 |
myform.addCommand(cmd_vortarinformo); |
97 |
/* Commands */ |
|
16 | 98 |
cmd_agordoj = new Command(T.t("Agordoj"), Command.HELP, 3); |
99 |
myform.addCommand(cmd_agordoj); |
|
100 |
/* Commands */ |
|
101 |
cmd_eliri = new Command(T.t("Eliri"), Command.BACK, 4); |
|
4 | 102 |
myform.addCommand(cmd_eliri); |
0 | 103 |
|
104 |
myform.setCommandListener(this); |
|
105 |
Main.display.setCurrent(myform); |
|
106 |
} |
|
107 |
||
19 | 108 |
private String transliterate(String from) |
109 |
{ |
|
110 |
String out = from; |
|
111 |
if (translit.getString(translit.getSelectedIndex()) |
|
112 |
.equals(translit_iksa)) |
|
113 |
out = Replace.IksojAlCxapeloj(from); |
|
114 |
else if (translit.getString(translit.getSelectedIndex()) |
|
115 |
.equals(translit_rusa)) |
|
116 |
out = Replace.AsciiAlRusa(from); |
|
117 |
||
118 |
return out; |
|
119 |
} |
|
120 |
||
0 | 121 |
public void commandAction(Command c, Displayable d) |
122 |
{ |
|
123 |
if (c == cmd_sercxi) |
|
124 |
{ |
|
10 | 125 |
DictIndex index = new DictIndex(vortaro); |
0 | 126 |
|
9
2507586786aa
Added Transliteration options, added BLOCK size in a file.
viric@llimona
parents:
8
diff
changeset
|
127 |
String toSearch = word.getString(); |
19 | 128 |
toSearch = transliterate(toSearch); |
6 | 129 |
|
9
2507586786aa
Added Transliteration options, added BLOCK size in a file.
viric@llimona
parents:
8
diff
changeset
|
130 |
showSearch.setText(toSearch); |
22 | 131 |
SearchThread t = new SearchThread(toSearch, vortaro, myform); |
11 | 132 |
|
22 | 133 |
SearchScreen s = new SearchScreen(toSearch); |
134 |
t.start(); |
|
0 | 135 |
} |
4 | 136 |
else if (c == cmd_eliri) |
137 |
{ |
|
20
2f815ca5cb8c
Added prefix search and 'Transliterigo' saving in record.
viric@mandarina
parents:
19
diff
changeset
|
138 |
String tselected = translit.getString(translit.getSelectedIndex()); |
2f815ca5cb8c
Added prefix search and 'Transliterigo' saving in record.
viric@mandarina
parents:
19
diff
changeset
|
139 |
Mem.setVariable("Transliterigo", tselected); |
4 | 140 |
Main.main.quit(); |
141 |
} |
|
9
2507586786aa
Added Transliteration options, added BLOCK size in a file.
viric@llimona
parents:
8
diff
changeset
|
142 |
else if (c == cmd_montri) |
2507586786aa
Added Transliteration options, added BLOCK size in a file.
viric@llimona
parents:
8
diff
changeset
|
143 |
{ |
2507586786aa
Added Transliteration options, added BLOCK size in a file.
viric@llimona
parents:
8
diff
changeset
|
144 |
String toSearch = word.getString(); |
19 | 145 |
toSearch = transliterate(toSearch); |
9
2507586786aa
Added Transliteration options, added BLOCK size in a file.
viric@llimona
parents:
8
diff
changeset
|
146 |
|
2507586786aa
Added Transliteration options, added BLOCK size in a file.
viric@llimona
parents:
8
diff
changeset
|
147 |
showSearch.setText(toSearch); |
2507586786aa
Added Transliteration options, added BLOCK size in a file.
viric@llimona
parents:
8
diff
changeset
|
148 |
} |
13 | 149 |
else if (c == cmd_pri) |
150 |
{ |
|
151 |
ShowText text = new ShowText( |
|
23 | 152 |
"JDict v0.2- Vortara programo laŭ stilo dictd " + |
13 | 153 |
"(http://www.dict.org)\n" + |
154 |
"Kopirajto (C) 2007 Lluís Batlle i Rossell\n" + |
|
155 |
"Tiun ĉi programon mi distribuas laŭ permesilo " + |
|
156 |
"GPL versio 2 aŭ posta. Vidu la fontokodon por " + |
|
157 |
"pliaj detaloj.\n" + |
|
158 |
"Plia informo, pluaj elŝutoj: " + |
|
159 |
"http://vicerveza.homeunix.net/~viric/dict/jdict" |
|
160 |
, myform); |
|
161 |
} |
|
14 | 162 |
else if (c == cmd_vortarinformo) |
163 |
{ |
|
164 |
DictIndex index = new DictIndex(vortaro); |
|
165 |
Vector results; |
|
166 |
String text = ""; |
|
167 |
||
168 |
/* Already at start */ |
|
169 |
results = index.SearchDefinition("00databaseinfo", 5); |
|
170 |
if (results.size() > 0) |
|
171 |
text += "Database Info:\n" + (String) results.elementAt(0) |
|
172 |
+ "\n"; |
|
173 |
||
174 |
results = index.SearchDefinition("00databaseshort", 5); |
|
175 |
if (results.size() > 0) |
|
176 |
text += "Database Short:\n" + (String) results.elementAt(0) |
|
177 |
+ "\n"; |
|
178 |
||
179 |
results = index.SearchDefinition("00databaseurl", 5); |
|
180 |
if (results.size() > 0) |
|
181 |
text += "Database URL:\n" + (String) results.elementAt(0) |
|
182 |
+ "\n"; |
|
183 |
||
184 |
ShowText textwin = new ShowText(text, myform); |
|
185 |
} |
|
16 | 186 |
else if (c == cmd_agordoj) |
187 |
{ |
|
188 |
/* This opens a new form */ |
|
189 |
Config config = new Config(this, myform); |
|
190 |
} |
|
0 | 191 |
} |
192 |
} |