[subversion:2] List display added.
- From: kotharthar@kenai.com
- To: commits@mz-mobile-dictionary.kenai.com
- Subject: [subversion:2] List display added.
- Date: Sat, 21 Mar 2009 13:30:27 +0000 (GMT)
Repository: subversion
Revision: 2
Author: kotharthar
Date: 2009-03-21 13:30:25 UTC
Link:
http://kenai.com/projects/mz-mobile-dictionary/sources/subversion/revis
ion/2
Log Message:
-----------
List display added.
Modified Paths:
--------------
trunk/mz_mobile_dictionary
trunk/mz_mobile_dictionary/src/MZMobileDictionary.java
Diffs:
-----
Index: trunk/mz_mobile_dictionary/src/MZMobileDictionary.java
===================================================================
--- trunk/mz_mobile_dictionary/src/MZMobileDictionary.java
(revision 1)
+++ trunk/mz_mobile_dictionary/src/MZMobileDictionary.java
(revision 2)
@@ -10,10 +10,14 @@
import com.sun.lwuit.events.*;
import com.sun.lwuit.layouts.BorderLayout;
import com.sun.lwuit.layouts.BoxLayout;
+import com.sun.lwuit.layouts.FlowLayout;
import com.sun.lwuit.layouts.GridLayout;
+import com.sun.lwuit.list.DefaultListCellRenderer;
+import com.sun.lwuit.list.DefaultListModel;
import com.sun.lwuit.plaf.Border;
import com.sun.lwuit.plaf.Style;
import java.util.Stack;
+import java.util.Vector;
/**
* @author Thar Htet
@@ -29,11 +33,14 @@
private Form resultForm;
private Resources resourceObject;
private TextField searchField;
- private Stack dictionaryData;
+ private Vector dictionaryData;
+ private Vector wordListData;
private Label welcomeLabel;
private Label siteLabel;
private Label logo;
+ private List resultList;
private ZawgyiComponent resultDisplay;
+ private ZawgyiComponent msgNotFound;
private Label smileLabel;
private final int cluster_prefix_length = 3;
private final String file_suffix = "_mz.txt";
@@ -94,9 +101,10 @@
smileLabel.setAlignment(Label.CENTER);
// Prepare Dictionary Form layout
- dictionaryForm.getContentPane().setLayout(new
BoxLayout(BoxLayout.Y_AXIS));
- dictionaryForm.getContentPane().addComponent(searchField);
- dictionaryForm.getContentPane().addComponent(smileLabel);
+ dictionaryForm.setLayout(new BorderLayout());
+ dictionaryForm.addComponent(BorderLayout.NORTH, searchField);
+ dictionaryForm.addComponent(BorderLayout.CENTER, smileLabel);
+ dictionaryForm.setScrollable(false);
// Add commands and listener
dictionaryForm.addCommand(exitCommand);
@@ -125,8 +133,8 @@
splashForm.show();
splashForm.addCommand(startCommand);
welcomeLabel.setText("Welcome..");
- //dataLoadThread = new Thread(this);
- //dataLoadThread.start();
+ //dataLoadThread = new Thread(this);
+ //dataLoadThread.start();
}
@@ -164,8 +172,7 @@
if (ae.getCommand() == searchCommand) {
if (searchField.getText().trim().length() > 0) {
-
resultDisplay.setText(search(searchField.getText().trim()));
- resultForm.show();
+ searchAndDisplayResult(searchField.getText().trim());
}
}
@@ -282,53 +289,98 @@
surrogatePair[1] = (0xDC00 | (low10));
}
- private String search(String query) {
-
+ private void searchAndDisplayResult(String query) {
+ String result;
//Get the prefix string
//System.out.println("QUERY:" + query);
- String prefix =
query.substring(0,Math.min(cluster_prefix_length,query.trim().length())
);
+ String prefix = query.substring(0,
Math.min(cluster_prefix_length, query.trim().length()));
//System.out.println("PREFIX:" + prefix);
//Detect if the file exist
InputStream is;
- try{
- is = this.getClass().getResourceAsStream("txt/"+
prefix.toLowerCase() + file_suffix);
- //System.out.println("AOK : " + "txt/"+
prefix.toLowerCase() + file_suffix);
- }catch(Exception e){
+ try {
+ is = this.getClass().getResourceAsStream("txt/" +
prefix.toLowerCase() + file_suffix);
+ //System.out.println("AOK : " + "txt/"+ prefix.toLowerCase() +
file_suffix);
+ } catch (Exception e) {
is = this.getClass().getResourceAsStream("txt/exception" +
file_suffix);
- //System.out.println("BOK");
+ //System.out.println("BOK");
}
- //Load into Hash
- extract(read_dict(is));
+ //Load and Search
+ result = extractAndSearch(read_dict(is), query);
- //search
- String result = "";
- while (!dictionaryData.empty()){
- String data = (String) dictionaryData.pop();
- if (data.trim().toLowerCase().indexOf(query.toLowerCase()
+ "|") == 0){
- result += data + "\n\n";
-
+ // if result is empty.
+ //if (result.length() == 0) {
+ //result = query + " " +
"\u104F\u0020\u1021\u1013\u102D\u1015\u1078\u102B\u101A\u1039\u1000\u10
2D\u102F\n" +
+ //
"\u1024\u1021\u1018\u102D\u1013\u102B\u1014\u1039\u1010\u103C\u1004\u10
39\n" +
+ //
"\u1019\u101E\u103C\u1004\u1039\u1038\u101B\u1031\u101E\u1038\u1015\u10
2B\u104B";
+
+ //When there are optional words available
+ if (wordListData.size() > 0) {
+ resultList = new List(wordListData);
+ resultList.setListCellRenderer(new
DefaultListCellRenderer(false));
+ dictionaryForm.removeComponent(smileLabel);
+ dictionaryForm.removeComponent(smileLabel);
+ dictionaryForm.addComponent(BorderLayout.CENTER,
resultList);
+ dictionaryForm.invalidate();
+ dictionaryForm.repaint();
+ } else {
+ //Not even optional words.
+ result = query + " " +
"\u104F\u0020\u1021\u1013\u102D\u1015\u1078\u102B\u101A\u1039\u1000\u10
2D\u102F\n" +
+
"\u1024\u1021\u1018\u102D\u1013\u102B\u1014\u1039\u1010\u103C\u1004\u10
39\n" +
+
"\u1019\u101E\u103C\u1004\u1039\u1038\u101B\u1031\u101E\u1038\u1015\u10
2B\u104B";
+ msgNotFound = new ZawgyiComponent();
+ msgNotFound.setText(result);
+ dictionaryForm.removeComponent(smileLabel);//If smile
is in place
+ if (resultList !=
null)dictionaryForm.removeComponent(resultList);//If result list is in
place
+ dictionaryForm.addComponent(BorderLayout.CENTER,
msgNotFound);
+ dictionaryForm.invalidate();
+ dictionaryForm.repaint();
}
- }
-
- if (result.length() == 0){
- result = query + " " +
"\u104F\u0020\u1021\u1013\u102D\u1015\u1078\u102B\u101A\u1039\u1000\u10
2D\u102F\n" +
-
"\u1024\u1021\u1018\u102D\u1013\u102B\u1014\u1039\u1010\u103C\u1004\u10
39\n" +
-
"\u1019\u101E\u103C\u1004\u1039\u1038\u101B\u1031\u101E\u1038\u1015\u10
2B\u104B";}
- return result;
+ //} else {
+ //When exact match is found.
+ // resultDisplay.setText(result);
+ // resultForm.show();
+ //}
+
+
}
- private void extract(String s) {
- dictionaryData = new Stack();
+ /**
+ * This method iterates the dictionary text file
+ * (whic is loaded based on prefixed index) and
+ * search if the query word is found in the dictionary file.
+ *
+ * If the word is found, instantly break from loop and return
+ * the word definition.
+ *
+ * If the word is NOT found, prepare the word list for display and
+ * prepare the dictionary item list for later display, in case
user
+ * select one from list item.
+ */
+ private String extractAndSearch(String s, String query) {
+ String result = "";
+ dictionaryData = new Vector();
+ wordListData = new Vector();
String item;
int start_index = 0;
while (start_index < s.trim().length()) {
item = s.substring(start_index, s.indexOf("||",
start_index)).trim();
- dictionaryData.push(item);
+
+ //if
(item.trim().toLowerCase().indexOf(query.toLowerCase() + "|") == 0) {
+ //Now found the word, quit from here and show the
result.
+ // result += item + "\n\n";
+ // return result; // in this case dictionaryData will
be ignored.
+ // } else {
+ if (item.length() > 0) {
+ dictionaryData.addElement(item);
+ wordListData.addElement(item.substring(0,
item.indexOf("|")));
+ }
+ //}
start_index += (item.length() + 2);
}
System.out.println(dictionaryData.size());
+ return "";
}
}
Property changes on: trunk/mz_mobile_dictionary
___________________________________________________________________
Name: svn:ignore
+ build
dist
|
[subversion:2] List display added. |
kotharthar | 03/21/2009 |





