Added "Dictionary information"
authorviric@llimona
Thu, 26 Jul 2007 00:14:35 +0200
changeset 14 8d3d102cc5e3
parent 13 d3255b427c6b
child 15 b3cd84530d9a
Added "Dictionary information"
src/jdict/AskWord.java
src/jdict/DictIndex.java
--- a/src/jdict/AskWord.java	Wed Jul 25 23:49:59 2007 +0200
+++ b/src/jdict/AskWord.java	Thu Jul 26 00:14:35 2007 +0200
@@ -12,6 +12,7 @@
 	private Command cmd_sercxi;
 	private Command cmd_montri;
 	private Command cmd_pri;
+	private Command cmd_vortarinformo;
     private TextField word;
     private ChoiceGroup translit;
     final String translit_neniu = "Neniu";
@@ -71,13 +72,16 @@
 		cmd_sercxi = new Command("Serĉi", Command.OK, 0);
 		myform.addCommand(cmd_sercxi);
 		/* Commands */
-		cmd_montri = new Command("Montri", Command.HELP, 0);
+		cmd_montri = new Command("Montri", Command.HELP, 1);
 		myform.addCommand(cmd_montri);
 		/* Commands */
-		cmd_pri = new Command("Pri ĉi tio", Command.HELP, 0);
+		cmd_pri = new Command("Pri ĉi tio", Command.HELP, 2);
 		myform.addCommand(cmd_pri);
 		/* Commands */
-		cmd_eliri = new Command("Eliri", Command.BACK, 0);
+		cmd_vortarinformo = new Command("Vortarinformo", Command.HELP, 3);
+		myform.addCommand(cmd_vortarinformo);
+		/* Commands */
+		cmd_eliri = new Command("Eliri", Command.BACK, 4);
 		myform.addCommand(cmd_eliri);
 
 		myform.setCommandListener(this);
@@ -136,5 +140,29 @@
                     "http://vicerveza.homeunix.net/~viric/dict/jdict"
                     , myform);
         }
+        else if (c == cmd_vortarinformo)
+        {
+            DictIndex index = new DictIndex(vortaro);
+            Vector results;
+            String text = "";
+
+            /* Already at start */
+            results = index.SearchDefinition("00databaseinfo", 5);
+            if (results.size() > 0)
+                text += "Database Info:\n" + (String) results.elementAt(0)
+                    + "\n";
+
+            results = index.SearchDefinition("00databaseshort", 5);
+            if (results.size() > 0)
+                text += "Database Short:\n" + (String) results.elementAt(0)
+                    + "\n";
+
+            results = index.SearchDefinition("00databaseurl", 5);
+            if (results.size() > 0)
+                text += "Database URL:\n" + (String) results.elementAt(0)
+                    + "\n";
+
+            ShowText textwin = new ShowText(text, myform);
+        }
 	}
 }
--- a/src/jdict/DictIndex.java	Wed Jul 25 23:49:59 2007 +0200
+++ b/src/jdict/DictIndex.java	Thu Jul 26 00:14:35 2007 +0200
@@ -253,13 +253,26 @@
 
     public Vector SearchDefinition(String word)
     {
+        return SearchDefinition(word, -1);
+    }
+
+    /* if max >0, limit the search. */
+    public Vector SearchDefinition(String word, int max)
+    {
         Vector results = new Vector();
+        int count = 0;
+        System.out.println("Searching " + word);
 
         String test;
         do
         {
+            if (max > 0 && count > max)
+            {
+                /* Void results */
+                break;
+            }
+            test = getName();
 
-            test = getName();
             if (test == null)
                 break;
             if (WordMatches(word,test))
@@ -272,12 +285,20 @@
                 String definition = defs.getDefinition(offset, length);
 
                 results.addElement(definition);
+                break; /* Word found */
             } else
             {
                 readUntilNewLine();
             }
+            ++count;
         } while (test != null);
 
+        try {
+            in.seekFromStart(0);
+        } catch (IOException e)
+        {
+            System.out.println("Cannot go back to start in search def.");
+        }
         return results;
     }