diff --git a/source/org/thdl/tib/scanner/AboutDialog.java b/source/org/thdl/tib/scanner/AboutDialog.java index 29c7e08..7e77dc3 100644 --- a/source/org/thdl/tib/scanner/AboutDialog.java +++ b/source/org/thdl/tib/scanner/AboutDialog.java @@ -31,14 +31,16 @@ public class AboutDialog extends Dialog implements ActionListener, WindowListene { public static String windowAboutOption = "thdl.scanner.omit.about.window"; private Checkbox chkOmitNextTime; + private Button close; public AboutDialog(Frame parent, boolean pocketpc) { super(parent, "About...", true); + this.setFont(WindowScannerFilter.getTHDLFont()); Panel p = new Panel(new BorderLayout()); chkOmitNextTime = new Checkbox("Don't show this window at startup", ThdlOptions.getBooleanOption(windowAboutOption)); p.add(chkOmitNextTime, BorderLayout.CENTER); - Button close = new Button("Close this window"); + close = new Button("Close this window"); p.add(close, BorderLayout.EAST); add(p, BorderLayout.NORTH); close.addActionListener(this); @@ -54,6 +56,13 @@ public class AboutDialog extends Dialog implements ActionListener, WindowListene else setSize(480,400); } +/* public void setDefaultFont(Font f) + { + this.setFont(f); + chkOmitNextTime.setFont(f); + close.setFont(f); + }*/ + public boolean omitNextTime() { return chkOmitNextTime.getState(); @@ -64,7 +73,7 @@ public class AboutDialog extends Dialog implements ActionListener, WindowListene user may not see the console! See ThdlActionListener. -DC */ public void actionPerformed(ActionEvent e) { - hide(); + dispose(); } /** @@ -74,7 +83,7 @@ public class AboutDialog extends Dialog implements ActionListener, WindowListene */ public void windowClosing(WindowEvent e) { - hide(); + dispose(); } /** diff --git a/source/org/thdl/tib/scanner/CreateDatabaseWizard.java b/source/org/thdl/tib/scanner/CreateDatabaseWizard.java index 70e27e2..b57c897 100644 --- a/source/org/thdl/tib/scanner/CreateDatabaseWizard.java +++ b/source/org/thdl/tib/scanner/CreateDatabaseWizard.java @@ -18,23 +18,18 @@ class CreateDatabaseWizard extends Dialog implements ActionListener, ItemListene private Button add, ok, cancel, browse; private Frame owner; private SimplifiedLinkedList dicts; - private boolean pocketpc; private String response; - CreateDatabaseWizard(Frame owner, boolean pocketpc) + CreateDatabaseWizard(Frame owner) { super(owner, "Generation of Binary Tree Dictionary", true); - this.pocketpc = pocketpc; this.owner = owner; response = ""; dicts = new SimplifiedLinkedList(); this.setLayout(new BorderLayout()); - if (pocketpc) - { - Dimension d = Toolkit.getDefaultToolkit().getScreenSize(); - this.setSize(d); - } else this.setSize(400,300); + this.setSize(400,300); + Panel p1, p2, p3; p1 = new Panel(new GridLayout(4, 1)); p2 = new Panel(new FlowLayout(FlowLayout.LEFT)); @@ -53,13 +48,11 @@ class CreateDatabaseWizard extends Dialog implements ActionListener, ItemListene p2.add(browse, BorderLayout.EAST); p1.add(p2); p2 = new Panel(new BorderLayout()); - if (pocketpc) p2.add(new Label("Desc:"), BorderLayout.WEST); - else p2.add(new Label("Description:"), BorderLayout.WEST); + p2.add(new Label("Description:"), BorderLayout.WEST); dicDesc = new TextField(20); p2.add(dicDesc, BorderLayout.CENTER); p3 = new Panel(new FlowLayout()); - if (pocketpc) p3.add(new Label("Abv:")); - else p3.add(new Label("Abbreviation:")); + p3.add(new Label("Abbreviation:")); dicAbb = new TextField(6); p3.add(dicAbb); p2.add(p3, BorderLayout.EAST); @@ -149,37 +142,21 @@ class CreateDatabaseWizard extends Dialog implements ActionListener, ItemListene AcipToWylie a2w=null; // getting the database name - if (pocketpc) - { - fd = new FileDialog(owner, "Save database to", FileDialog.SAVE); - fd.show(); - fileName = fd.getFile(); - if (fileName!= null) - { - // dropping the extension - pos = fileName.lastIndexOf('.'); - if (pos>0) fileName = fileName.substring(0, pos); - path = fd.getDirectory() + fileName; - } - } - else - { - DictionaryFileFilter dicFilter = new DictionaryFileFilter(); - JFileChooser fileChooser = new JFileChooser("Save database to"); - fileChooser.addChoosableFileFilter(dicFilter); - /*setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); + DictionaryFileFilter dicFilter = new DictionaryFileFilter(); + JFileChooser fileChooser = new JFileChooser("Save database to"); + fileChooser.addChoosableFileFilter(dicFilter); + /*setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); - if (fileChooser.showOpenDialog(this) != JFileChooser.APPROVE_OPTION) - { - setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); - return; - }*/ - if (fileChooser.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) - { - path = fileChooser.getSelectedFile().getPath(); - pos = path.lastIndexOf('.'); - if (pos>0) path = path.substring(0, pos); - } + if (fileChooser.showOpenDialog(this) != JFileChooser.APPROVE_OPTION) + { + setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); + return; + }*/ + if (fileChooser.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) + { + path = fileChooser.getSelectedFile().getPath(); + pos = path.lastIndexOf('.'); + if (pos>0) path = path.substring(0, pos); } PrintWriter pr=null; diff --git a/source/org/thdl/tib/scanner/DictionaryBreakDown.java b/source/org/thdl/tib/scanner/DictionaryBreakDown.java new file mode 100644 index 0000000..e9525cd --- /dev/null +++ b/source/org/thdl/tib/scanner/DictionaryBreakDown.java @@ -0,0 +1,440 @@ +/* +The contents of this file are subject to the AMP Open Community License +Version 1.0 (the "License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License on the AMP web site +(http://www.tibet.iteso.mx/Guatemala/). + +Software distributed under the License is distributed on an "AS IS" basis, +WITHOUT WARRANTY OF ANY KIND, either express or implied. See the +License for the specific terms governing rights and limitations under the +License. + +The Initial Developer of this software is Andres Montano Pellegrini. Portions +created by Andres Montano Pellegrini are Copyright 2001 Andres Montano +Pellegrini. All Rights Reserved. + +Contributor(s): ______________________________________. +*/ + +package org.thdl.tib.scanner; + +import org.thdl.util.*; +import org.thdl.tib.text.*; +import java.net.*; +import java.io.*; + +public class DictionaryBreakDown +{ + private static final int TOMERAIDER=1; + private static final int HTML=2; + private static final int SIMPLEBREAK=3; + private int mode; + private BufferedReader in; + private int numberOfFields; + private int numberOfMergedFields; + + private static final int UNIQUE=0; + private static final int MERGE_HEAD=1; + private static final int MERGE_FOLLOWER=2; + + public DictionaryBreakDown(BufferedReader in, int mode) + { + this.mode = mode; + this.in = in; + } + + public static void main (String[] args) throws Exception + { + PrintWriter out; + BufferedReader in=null; + int argNum = args.length, currentArg=0, mode = SIMPLEBREAK; + String option, format=null; + + if (argNum<=currentArg) + { + System.out.println("Syntax: DictionaryBreakDown [-format format] [-tomeraider | -html] input-file"); + return; + } + + while (args[currentArg].charAt(0)=='-') + { + option = args[currentArg].substring(1); + currentArg++; + if (option.equals("format")) + { + format=args[currentArg]; + currentArg++; + } else if (option.equals("tomeraider")) + { + mode=TOMERAIDER; + } else if (option.equals("html")) + { + mode=HTML; + } + } + if (argNum<=currentArg) + { + System.out.println("Syntax error. Input file expected."); + return; + } + + in = getBufferedReader(args[currentArg], format); + + new DictionaryBreakDown(in, mode).run(format); + } + + public static BufferedReader getBufferedReader(String s, String format) throws Exception + { + InputStream is; + + if (s.indexOf("http://") >= 0) + is = new BufferedInputStream((new URL(s)).openStream()); + else + is = new FileInputStream(s); + + if (format==null) + return new BufferedReader(new InputStreamReader(is)); + else + return new BufferedReader(new InputStreamReader(is, format)); + + } + + private int[] buildMergeMatrix(String fields[]) + { + int i; + int matrix[] = new int[fields.length]; + boolean sameRoot=false; + String root; + + for (i=0; i1 && s.charAt(0)=='\"' && s.charAt(s.length()-1)=='\"') + return s.substring(1,s.length()-1); + else return s; + } + + private String[] getFields(String linea) + { + int i=0, j, pos; + String fields[] = new String[this.numberOfFields], tokens[]; + + tokens = linea.split("\t"); + for (i=0; i=fields.length) break outAHere; + } + j++; + } + } + return mergedFields; + } + + public void run(String format) throws Exception + { + String linea, fieldNames[], fields[], mergedFieldNames[], mergedFields[], tail; + int i, pos, j; + int mergeMatrix[]; + PrintWriter out[] = null, outOne = null; + SimplifiedLinkedList ll = null, llOdd = null; + SimplifiedListIterator sli; + char ch; + + linea=in.readLine(); + if (linea==null) throw new Exception("File is empty!"); + fieldNames = linea.split("\t"); + numberOfFields = fieldNames.length; + mergeMatrix = buildMergeMatrix(fieldNames); + mergedFieldNames = buildMergedFieldNames(fieldNames, mergeMatrix); + numberOfMergedFields = mergedFieldNames.length; + + switch (mode) + { + case TOMERAIDER: + if (format!=null) outOne = new PrintWriter(new OutputStreamWriter(new FileOutputStream("dict-in-tomeraider-format.txt"), format)); + else outOne = new PrintWriter(new FileOutputStream("dict-in-tomeraider-format.txt")); + ll = new SimplifiedLinkedList(); + llOdd = new SimplifiedLinkedList(); + break; + + case HTML: + if (format != null) outOne = new PrintWriter(new OutputStreamWriter(new FileOutputStream("dict-in-tab-format.txt"), format)); + else outOne = new PrintWriter(new FileOutputStream("dict-in-tab-format.txt")); + break; + + case SIMPLEBREAK: + out = new PrintWriter[mergedFieldNames.length-1]; + for (i=0; i0) linea = linea.substring(0,pos).trim(); + pos = linea.indexOf('+'); + if (pos>0) + { + llOdd.addLast(mergedFields); + continue; + } + try + { + ll.addSorted(new SortingTibetanEntry(linea, mergedFields)); + } + catch (Exception e) + { + llOdd.addLast(mergedFields); + } + + break; + case HTML: + tail = null; + + pos = mergedFields[0].indexOf("..."); + + if (pos==0) mergedFields[0] = mergedFields[0].substring(3).trim(); + else + if (pos>0) + { + tail = mergedFields[0].substring(pos + 3).trim(); + mergedFields[0] = mergedFields[0].substring(0,pos-1).trim(); + } + outOne.print(mergedFields[0] + "\t"); + + for (i=1; i<=2; i++) // tenses & sanskrit + { + if (!mergedFields[i].equals("")) + { + if (tail!=null) outOne.print("... " + tail + ": " + mergedFields[i] + "
"); + else outOne.print(mergedFields[i] + "
"); + } + } + + if (!mergedFields[3].equals("")) // english + { + if (tail!=null) outOne.print("... " + tail + ": " + mergedFields[3] + "
"); + else outOne.print("" + mergedFields[3] + "
"); + } + if (!mergedFields[4].equals("")) // english-others + { + if (tail!=null) outOne.print("... " + tail + ": " + mergedFields[4] + "
"); + else outOne.print("" + mergedFields[4] + "
"); + } + + for (i=5; i<=8; i++) + { + if (!mergedFields[i].equals("")) + { + if (tail!=null) outOne.print("... " + tail + ": " + mergedFields[i] + "
"); + else outOne.print(mergedFields[i] + "
"); + } + } + + if (!mergedFields[9].equals("")) // synonyms-tibetan + { + if (tail!=null) outOne.print("... " + tail + ": Synonyms: " + mergedFields[9] + "
"); + else outOne.print("Synonyms: " + mergedFields[9] + "
"); + } + + for (i=10; i<=13; i++) + { + if (!mergedFields[i].equals("")) + { + if (tail!=null) outOne.print("... " + tail + ": " + mergedFields[i] + "
"); + else outOne.print(mergedFields[i] + "
"); + } + } + outOne.println(); + break; + case SIMPLEBREAK: + tail = null; + + pos = mergedFields[0].indexOf("..."); + + if (pos==0) mergedFields[0] = mergedFields[0].substring(3).trim(); + else + if (pos>0) + { + tail = mergedFields[0].substring(pos + 3).trim(); + mergedFields[0] = mergedFields[0].substring(0,pos-1).trim(); + } + + for (i=1; i\nAbout\n"); + outOne.println(TibetanScanner.aboutTomeraider); + + sli = ll.listIterator(); + while (sli.hasNext()) + { + mergedFields = ((SortingTibetanEntry)sli.next()).get(); + outOne.println("\n\n" + mergedFields[0] + "\n"); + if (!mergedFields[1].equals("")) outOne.println(mergedFields[1] + "
"); // tenses + if (!mergedFields[2].equals("")) outOne.println(mergedFields[2] + "
"); // sanskrit + if (!mergedFields[3].equals("")) outOne.println("" + mergedFields[3] + "
"); // english + if (!mergedFields[4].equals("")) outOne.println("" + mergedFields[4] + "
"); // english-others + for (i=5; i<=8; i++) + { + if (!mergedFields[i].equals("")) outOne.println(mergedFields[i] + "
"); + } + if (!mergedFields[9].equals("")) outOne.println("Synonyms: " + mergedFields[9] + "
"); // synonyms-tibetan + + for (i=10; i<=13; i++) + { + if (!mergedFields[i].equals("")) outOne.println(mergedFields[i] + "
"); + } + } + + sli = llOdd.listIterator(); + if (sli.hasNext()) + { + outOne.println("\n\nUnsorted entries start here.\n"); + outOne.println("Because of errors in the entries with regards to:"); + outOne.println("
    "); + outOne.println("
  1. Invalid tibetan"); + outOne.println("
  2. Conversion from Tibetan script to extended wylie"); + outOne.println("
  3. or the sorting algorithm"); + outOne.println("
"); + outOne.println("the following entries could not be sorted. Hopefully these errors will be corrected in future versions."); + } + while (sli.hasNext()) + { + mergedFields = (String[])sli.next(); + outOne.println("\n\n" + mergedFields[0] + "\n"); + if (!mergedFields[1].equals("")) outOne.println(mergedFields[1] + "
"); // tenses + if (!mergedFields[2].equals("")) outOne.println(mergedFields[2] + "
"); // sanskrit + if (!mergedFields[3].equals("")) outOne.println("" + mergedFields[3] + "
"); // english + if (!mergedFields[4].equals("")) outOne.println("" + mergedFields[4] + "
"); // english-others + for (i=5; i<=8; i++) + { + if (!mergedFields[i].equals("")) outOne.println(mergedFields[i] + "
"); + } + if (!mergedFields[9].equals("")) outOne.println("Synonyms: " + mergedFields[9] + "
"); // synonyms-tibetan + + for (i=10; i<=13; i++) + { + if (!mergedFields[i].equals("")) outOne.println(mergedFields[i] + "
"); + } + } + case HTML: + outOne.flush(); // no break above so that both flush. + break; + + case SIMPLEBREAK: + for (i=0; i= 0) + in = new BufferedReader(new InputStreamReader(new BufferedInputStream((new URL(args[currentArg])).openStream()))); + else + in = new BufferedReader(new InputStreamReader(new FileInputStream(args[currentArg]))); + } + + new FilterHTMLDictionary(in, out).run(); + } + + public void run() throws Exception + { + String lineaLC, term, definition="", modTerm; + int status = GETTING_TERM, start, end, ps, pe; + + currentLine=0; + while ((linea=in.readLine())!=null) + { + currentLine++; + linea = linea.trim(); + lineaLC = linea.toLowerCase(); + + switch (status) + { + case GETTING_TERM: + + if (!lineaLC.startsWith("

")) reportProblem("

expected."); + + end = lineaLC.indexOf(""); + if (end<=0) + { + reportProblem(" expected."); + continue; + } + + term = linea.substring(6, end).trim().toLowerCase(); + ps = term.indexOf('('); + if (ps<0) ps = term.indexOf('['); + if (ps>=0) + { + pe = term.indexOf(')', ps); + if (pe<0) pe = term.indexOf(']', ps); + definition = "

Original entry: " + term + ". "; + if (ps>0) modTerm = term.substring(0, ps); + else modTerm = ""; + if (pe+1"); @@ -380,7 +382,7 @@ public class OnLineScannerFilter extends HttpServlet // else tag = null; /*if (tag!=null) {*/ - pw.println(" "+ words[j].getBookmark(tibetan) +""); + pw.println(" "+ word.getBookmark(tibetan) +""); pw.println(" "+ tag +""); pw.println(" " + defs.def[0] + ""); /*} diff --git a/source/org/thdl/tib/scanner/PocketPreferenceWindow.java b/source/org/thdl/tib/scanner/PocketPreferenceWindow.java new file mode 100644 index 0000000..7f84897 --- /dev/null +++ b/source/org/thdl/tib/scanner/PocketPreferenceWindow.java @@ -0,0 +1,160 @@ +/* +The contents of this file are subject to the AMP Open Community License +Version 1.0 (the "License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License on the AMP web site +(http://www.tibet.iteso.mx/Guatemala/). + +Software distributed under the License is distributed on an "AS IS" basis, +WITHOUT WARRANTY OF ANY KIND, either express or implied. See the +License for the specific terms governing rights and limitations under the +License. + +The Initial Developer of this software is Andres Montano Pellegrini. Portions +created by Andres Montano Pellegrini are Copyright 2001 Andres Montano +Pellegrini. All Rights Reserved. + +Contributor(s): ______________________________________. +*/ + +package org.thdl.tib.scanner; + +import java.awt.*; +import java.awt.event.*; + +class PocketPreferenceWindow extends Dialog implements ActionListener, ItemListener +{ + private Frame owner; + private Choice chFontNames, fontSizes, paneRows, parsePaneCols; + private Button ok, cancel; + private boolean gotStuff, landscape; + + PocketPreferenceWindow(Frame owner, boolean landscape) + { + super(owner, "Preferences", true); + + String s; + this.setFont(WindowScannerFilter.getTHDLFont()); + this.owner = owner; + this.landscape = landscape; + Dimension d = Toolkit.getDefaultToolkit().getScreenSize(); + this.setSize(d); + + this.gotStuff = false; + + GraphicsEnvironment genv = GraphicsEnvironment.getLocalGraphicsEnvironment(); + String[] fontNames = genv.getAvailableFontFamilyNames(); + + Panel p1, p2; + + p1 = new Panel(new BorderLayout()); + p1.add(new Label("Font: "), BorderLayout.WEST); + + chFontNames = new Choice(); + int i; + + chFontNames.add(""); + for (i=0; i0) fileName = fileName.substring(0, pos); + response = fd.getDirectory() + fileName; + localDict.setText(response); + ok.setEnabled(true); + } + } + } + + /*public void setFont(Font f) + { + super.setFont(f); + ok.setFont(f); + cancel.setFont(f); + useOnline.setFont(f); + useOffline.setFont(f); + availDictsOnline.setFont(f); + localDict.setFont(f); + browse.setFont(f); + ckbDefault.setFont(f); + }*/ + + /** Implement the disabling of other guys here + */ + public void itemStateChanged(ItemEvent e) + { + Object obj = e.getSource(); + if (obj instanceof Checkbox) + { + Checkbox chx = (Checkbox) obj; + //System.out.println(obj); + if (chx == useOnline) + { + localDict.setEnabled(false); + browse.setEnabled(false); + availDictsOnline.setEnabled(true); + ok.setEnabled(true); + dictType = availDictsOnline.getSelectedIndex(); + response = dictsOnline[dictType]; + } + else if (chx == useOffline) + { + localDict.setEnabled(true); + browse.setEnabled(true); + if (availDictsOnline!=null) availDictsOnline.setEnabled(false); + ok.setEnabled(!localDict.getText().equals("")); + response = localDict.getText(); + dictType = 2; + } + } + else if (obj instanceof Choice) + { + Choice ch = (Choice) obj; + dictType = ch.getSelectedIndex(); + response = dictsOnline[dictType]; + } + } + + /*class SymMouse extends java.awt.event.MouseAdapter + { + public void mouseEntered(java.awt.event.MouseEvent event) + { + Object object = event.getSource(); + if (object == PocketWhichDictionaryFrame.this) + PocketWhichDictionaryFrame_MouseEntered(event); + } + } + + void PocketWhichDictionaryFrame_MouseEntered(java.awt.event.MouseEvent event) + { + // to do: code goes here. + }*/ +} \ No newline at end of file diff --git a/source/org/thdl/tib/scanner/PocketWindowScannerFilter.java b/source/org/thdl/tib/scanner/PocketWindowScannerFilter.java new file mode 100644 index 0000000..8041a39 --- /dev/null +++ b/source/org/thdl/tib/scanner/PocketWindowScannerFilter.java @@ -0,0 +1,340 @@ +/* +The contents of this file are subject to the AMP Open Community License +Version 1.0 (the "License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License on the AMP web site +(http://www.tibet.iteso.mx/Guatemala/). + +Software distributed under the License is distributed on an "AS IS" basis, +WITHOUT WARRANTY OF ANY KIND, either express or implied. See the +License for the specific terms governing rights and limitations under the +License. + +The Initial Developer of this software is Andres Montano Pellegrini. Portions +created by Andres Montano Pellegrini are Copyright 2001 Andres Montano +Pellegrini. All Rights Reserved. + +Contributor(s): ______________________________________. +*/ + +package org.thdl.tib.scanner; + +import java.awt.*; +import java.util.*; +import java.io.*; +import java.awt.event.*; +import java.applet.Applet; +import java.awt.*; +import java.awt.datatransfer.*; +import org.thdl.util.*; + +/** Provides a graphical interfase to input Tibetan text (in Roman script) + and displays the words (in Roman script) with their definitions. Use + this version for platforms that support awt but not swing; it was + re-designed to fit with the implementation of the J2ME Personal Profile + 1.0 (JSR-62) used by some implementations of Java for Pocket pc's. The + command line to include in the shortcut file (.lnk) in the pocket pc to + run using IBM's WebSphere Everyplace Micro Environment Personal Profile + 1.0 for Windows Mobile 2003 is: +

255#"\Program Files\J9\PPRO10\bin\j9w.exe" "-jcl:ppro10" "-cp"  "\program files\TranslationTool\DictionarySearchHandheld.jar" "org.thdl.tib.scanner.PocketWindowScannerFilter"
+ + Can access dictionaries stored locally or remotely via the command line or + the wizard window. + + @author Andrés Montano Pellegrini + + +*/ +public class PocketWindowScannerFilter extends WindowScannerFilter +{ + protected static String defaultPortraitParseCols = "thdl.scanner.portrait.parse-pane.cols"; + protected static String defaultLandscapeParseCols = "thdl.scanner.landscape.parse-pane.cols"; + + public PocketWindowScannerFilter() + { + super(); + } + + public PocketWindowScannerFilter(String file) + { + super(file); + } + + protected WhichDictionaryFrame getWhichDictionaryFrame() + { + PocketWhichDictionaryFrame wdf = new PocketWhichDictionaryFrame(mainWindow); + wdf.setFont(WindowScannerFilter.getTHDLFont()); + wdf.show(); + return wdf; + } + + protected void makeWindow(String file) + { + if (mainWindow==null) + { + String dictType=null; + dictType = ThdlOptions.getStringOption(dictOpenType); + if (dictType!=null && !dictType.equals("")) + mainWindow = new Frame("Tibetan Translation Tool: Connected to " + dictType + " database"); + else + mainWindow = new Frame("Tibetan Translation Tool"); + mainWindow.setFont(WindowScannerFilter.getTHDLFont()); + } + else mainWindow.setVisible(false); + mainWindow.setLayout(new GridLayout(1,1)); + mainWindow.setBackground(Color.white); + + diagAbout = null; + mnuAbout = null; + Dimension d = Toolkit.getDefaultToolkit().getScreenSize(); + sp = new SimpleScannerPanel(file, d.width >d.height); + + MenuBar mb = new MenuBar(); + Menu m; + m = new Menu ("File"); + mnuOpen = new MenuItem("Open..."); + mnuOpen.addActionListener(this); + m.add(mnuOpen); + mnuExit = new MenuItem("Exit"); + mnuExit.addActionListener(this); + m.add(mnuExit); + mb.add(m); + + m = new Menu ("Edit"); + mnuCut = new MenuItem("Cut"); + //mnuCut.setShortcut(new MenuShortcut(KeyEvent.VK_X)); + m.add(mnuCut); + mnuCut.addActionListener(this); + mnuCopy = new MenuItem("Copy"); + //mnuCopy.setShortcut(new MenuShortcut(KeyEvent.VK_C)); + m.add(mnuCopy); + mnuCopy.addActionListener(this); + mnuPaste = new MenuItem("Paste"); + //mnuPaste.setShortcut(new MenuShortcut(KeyEvent.VK_V)); + m.add(mnuPaste); + mnuPaste.addActionListener(this); + mnuDelete = new MenuItem("Delete"); + m.add(mnuDelete); + mnuDelete.addActionListener(this); + m.add("-"); + mnuSelectAll = new MenuItem("Select all"); + //mnuSelectAll.setShortcut(new MenuShortcut(KeyEvent.VK_A)); + m.add(mnuSelectAll); + mnuSelectAll.addActionListener(this); + mnuClear = new MenuItem("Clear all"); + m.add(mnuClear); + mnuClear.addActionListener(this); + m.add("-"); + mnuPreferences = new MenuItem("Preferences..."); + m.add(mnuPreferences); + mnuPreferences.addActionListener(this); + mnuSavePref = new MenuItem("Save preferences to " + ThdlOptions.getUserPreferencesPath()); + m.add(mnuSavePref); + mnuSavePref.addActionListener(this); + + mb.add(m); + + m = new Menu("View"); + mnuDicts = new CheckboxMenuItem("Dictionaries", false); + m.add(mnuDicts); + mnuDicts.addItemListener(this); + mb.add(m); + + m = new Menu("Help"); + + mnuAbout = new MenuItem("About..."); + m.add(mnuAbout); + mnuAbout.addActionListener(this); + mb.add(m); + + // disable menus + focusLost(null); + + sp.addFocusListener(this); + + mainWindow.setMenuBar(mb); + mainWindow.add(sp); + mainWindow.addWindowListener(this); + mainWindow.setSize(d); + // mainWindow.setSize(240,320); + //else mainWindow.setSize(500,600); + mainWindow.show(); + mainWindow.toFront(); + + if (!ThdlOptions.getBooleanOption(AboutDialog.windowAboutOption)) + { + // hardwiring pocketpc + diagAbout = new AboutDialog(mainWindow, true); + diagAbout.show(); + + if (diagAbout.omitNextTime()) + { + ThdlOptions.setUserPreference(AboutDialog.windowAboutOption, true); + try + { + ThdlOptions.saveUserPreferences(); + } + catch(Exception e) + { + } + } + } + } + + public static void main(String[] args) + { + String os; + switch(args.length) + { + case 0: + new PocketWindowScannerFilter(); + break; + case 1: + if (args[0]==null || args[0].trim().equals("")) new PocketWindowScannerFilter(); + else new PocketWindowScannerFilter(args[0]); + break; + default: + System.out.println("Syntax error!"); + System.out.println("Sintaxis: java PocketWindowScannerFilter arch-dict"); + System.out.println(TibetanScanner.copyrightASCII); + } + } + + /* FIXME: what happens if this throws an exception? We'll just + see it on the console--it won't terminate the program. And the + user may not see the console! See ThdlActionListener. -DC */ + public void actionPerformed(ActionEvent event) + { + Object clicked = event.getSource(); + StringSelection ss; + String s = null; + + if (clicked == mnuAbout) + { + // hardwiring pocketpc + if (diagAbout==null) + { + diagAbout = new AboutDialog(mainWindow, true); + } + diagAbout.setFont(WindowScannerFilter.getTHDLFont()); + diagAbout.show(); + ThdlOptions.setUserPreference(AboutDialog.windowAboutOption, diagAbout.omitNextTime()); + try + { + ThdlOptions.saveUserPreferences(); + } + catch(Exception e) + { + } + } + else if (clicked == mnuClear) + { + sp.clear(); + } + else if (clicked == mnuOpen) + { + mainWindow.setVisible(false); + mainWindow.dispose(); + ThdlOptions.setUserPreference(defOpenOption, ""); + new PocketWindowScannerFilter(); + } + else if (clicked == mnuExit) + { + mainWindow.dispose(); + System.exit(0); + } + else if (clicked == mnuPreferences) + { + sp.setPreferences(mainWindow); + } + else if (clicked == mnuSavePref) + { + try + { + ThdlOptions.saveUserPreferences(); + } + catch (Exception e) + { + } + + } + else + { + if (objModified==null) return; + + if (objModified instanceof TextArea) + { + TextArea t = (TextArea) objModified; + + if (clicked == mnuCut) + { + ss = new StringSelection(t.getSelectedText()); + Toolkit.getDefaultToolkit().getSystemClipboard().setContents(ss,ss); + t.replaceRange("", t.getSelectionStart(), t.getSelectionEnd()); + } + else if (clicked == mnuCopy) + { + ss = new StringSelection(t.getSelectedText()); + Toolkit.getDefaultToolkit().getSystemClipboard().setContents(ss,ss); + } + else if (clicked == mnuPaste) + { + Transferable data = Toolkit.getDefaultToolkit().getSystemClipboard().getContents(this); + try + { + s = (String)(data.getTransferData(DataFlavor.stringFlavor)); + } + catch (Exception ex) + { + s = data.toString(); + } + t.replaceRange(s, t.getSelectionStart(), t.getSelectionEnd()); + //t.insert(s, t.getCaretPosition()); + } + else if (clicked == mnuDelete) + { + t.replaceRange("", t.getSelectionStart(), t.getSelectionEnd()); + } + else if (clicked == mnuSelectAll) + { + t.selectAll(); + } + } + } + } + + public void focusGained(FocusEvent e) + { + objModified = e.getSource(); + boolean isEditable=false; + + if (objModified instanceof TextComponent) + { + TextComponent t = (TextComponent) objModified; + isEditable = t.isEditable(); + } + + mnuCut.setEnabled(isEditable); + if (isEditable) + { + if (Toolkit.getDefaultToolkit().getSystemClipboard().getContents(this)!=null) + mnuPaste.setEnabled(true); + } + else mnuPaste.setEnabled(false); + mnuDelete.setEnabled(isEditable); + mnuCopy.setEnabled(true); + mnuSelectAll.setEnabled(true); + } + + public static int getParsePaneCols(boolean landscape) + { + if (landscape) return ThdlOptions.getIntegerOption(defaultLandscapeParseCols, 47); + else return ThdlOptions.getIntegerOption(defaultPortraitParseCols, 36); + } + + public static void setParsePaneCols(boolean landscape, int cols) + { + + if (landscape) ThdlOptions.setUserPreference(defaultLandscapeParseCols, cols); + else ThdlOptions.setUserPreference(defaultPortraitParseCols, cols); + } +} \ No newline at end of file diff --git a/source/org/thdl/tib/scanner/RemoteScannerFilter.java b/source/org/thdl/tib/scanner/RemoteScannerFilter.java index b5fa9f3..b0116e9 100644 --- a/source/org/thdl/tib/scanner/RemoteScannerFilter.java +++ b/source/org/thdl/tib/scanner/RemoteScannerFilter.java @@ -42,14 +42,23 @@ public class RemoteScannerFilter extends GenericServlet ResourceBundle rb = ResourceBundle.getBundle("dictionary"); scanner = new LocalTibetanScanner(rb.getString("onlinescannerfilter.dict-file-name")); ds = scanner.getDictionarySource(); + + + String fileName = rb.getString("remotescannerfilter.log-file-name"); + Calendar rightNow = Calendar.getInstance(); + + PrintStream pw = new PrintStream(new FileOutputStream(fileName, true)); + pw.println("Testing: " + rightNow.toString()); + pw.flush(); + pw.close(); } public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException { BufferedReader br; res.setContentType ("text/plain"); - Token token[]; - Word word; + Token token[] = null; + Word word = null; PrintWriter out = res.getWriter(); int i; String linea, dicts = req.getParameter("dicts"), dicDescrip[]; @@ -79,22 +88,52 @@ public class RemoteScannerFilter extends GenericServlet } br = new BufferedReader(new InputStreamReader(req.getInputStream())); - while((linea = br.readLine())!= null) - scanner.scanLine(linea); - - br.close(); - - scanner.finishUp(); - token = scanner.getTokenArray(); - - for (i=0; i +
java -jar DictionarySearchStandalone.jar http://iris.lib.virginia.edu/tibetan/servlet/org.thdl.tib.scanner.RemoteScannerFilter
+

If the JRE you installed does not support Swing classes but supports + + AWT (as the JRE for handhelds), run the command:

+
java -jar DictionarySearchHandheld.jar -simple ry-dic99
+ + @author Andrés Montano Pellegrini +*/ +public class SwingWindowScannerFilter extends WindowScannerFilter +{ + + public SwingWindowScannerFilter() + { + super(); + } + + public SwingWindowScannerFilter(String file) + { + super(file); + } + + protected WhichDictionaryFrame getWhichDictionaryFrame() + { + WhichDictionaryFrame wdf = new SwingWhichDictionaryFrame(mainWindow); + wdf.show(); + return wdf; + } + + protected void makeWindow(String file) + { + if (mainWindow==null) + { + String dictType=null; + dictType = ThdlOptions.getStringOption(dictOpenType); + if (dictType!=null && !dictType.equals("")) + mainWindow = new Frame("Tibetan Translation Tool: Connected to " + dictType + " database"); + else + mainWindow = new Frame("Tibetan Translation Tool"); + } + else mainWindow.setVisible(false); + mainWindow.setLayout(new GridLayout(1,1)); + mainWindow.setBackground(Color.white); + + diagAbout = null; + mnuAbout = null; + Dimension d = Toolkit.getDefaultToolkit().getScreenSize(); + + sp = new DuffScannerPanel(file); + + MenuBar mb = new MenuBar(); + Menu m; + m = new Menu ("File"); + mnuOpen = new MenuItem("Open..."); + mnuOpen.addActionListener(this); + m.add(mnuOpen); + mnuExit = new MenuItem("Exit"); + mnuExit.addActionListener(this); + m.add(mnuExit); + mb.add(m); + + m = new Menu ("Edit"); + mnuCut = new MenuItem("Cut"); + //mnuCut.setShortcut(new MenuShortcut(KeyEvent.VK_X)); + m.add(mnuCut); + mnuCut.addActionListener(this); + mnuCopy = new MenuItem("Copy"); + //mnuCopy.setShortcut(new MenuShortcut(KeyEvent.VK_C)); + m.add(mnuCopy); + mnuCopy.addActionListener(this); + mnuPaste = new MenuItem("Paste"); + //mnuPaste.setShortcut(new MenuShortcut(KeyEvent.VK_V)); + m.add(mnuPaste); + mnuPaste.addActionListener(this); + mnuDelete = new MenuItem("Delete"); + m.add(mnuDelete); + mnuDelete.addActionListener(this); + m.add("-"); + mnuSelectAll = new MenuItem("Select all"); + //mnuSelectAll.setShortcut(new MenuShortcut(KeyEvent.VK_A)); + m.add(mnuSelectAll); + mnuSelectAll.addActionListener(this); + mnuClear = new MenuItem("Clear all"); + m.add(mnuClear); + mnuClear.addActionListener(this); + + m.add("-"); + mnuPreferences = new MenuItem("Preferences..."); + m.add(mnuPreferences); + mnuPreferences.addActionListener(this); + mnuSavePref = new MenuItem("Save preferences to " + ThdlOptions.getUserPreferencesPath()); + m.add(mnuSavePref); + mnuSavePref.addActionListener(this); + mnuDicts=null; + + mb.add(m); + + m = new Menu("Help"); + + for (int i = 0; i < DuffScannerPanel.keybdMgr.size(); i++) + { + final JskadKeyboard kbd = DuffScannerPanel.keybdMgr.elementAt(i); + if (kbd.hasQuickRefFile()) + { + MenuItem keybdItem = new MenuItem(kbd.getIdentifyingString()); + keybdItem.addActionListener(new ThdlActionListener() + { + public void theRealActionPerformed(ActionEvent e) + { + new SimpleFrame(kbd.getIdentifyingString(), + kbd.getQuickRefPane()); + /* DLC FIXME -- pressing the "Extended + Wylie" menu item (for example) twice + causes the first pane to become dead. + We should check to see if the first + pane exists and raise it rather than + creating a second pane. */ + } + }); + m.add(keybdItem); + } + } + m.add("-"); + + mnuAbout = new MenuItem("About..."); + m.add(mnuAbout); + mnuAbout.addActionListener(this); + mb.add(m); + + // disable menus + focusLost(null); + + sp.addFocusListener(this); + + mainWindow.setMenuBar(mb); + mainWindow.add(sp); + mainWindow.addWindowListener(this); + mainWindow.setSize(d); + // mainWindow.setSize(240,320); + //else mainWindow.setSize(500,600); + mainWindow.show(); + mainWindow.toFront(); + + if (!ThdlOptions.getBooleanOption(AboutDialog.windowAboutOption)) + { + diagAbout = new AboutDialog(mainWindow, false); + diagAbout.show(); + + if (diagAbout.omitNextTime()) + { + ThdlOptions.setUserPreference(AboutDialog.windowAboutOption, true); + try + { + ThdlOptions.saveUserPreferences(); + } + catch(Exception e) + { + } + } + } + } + + public static void main(String[] args) + { + String os; + switch(args.length) + { + case 0: + new SwingWindowScannerFilter(); + break; + case 1: + new SwingWindowScannerFilter(args[0]); + break; + default: + System.out.println("Syntax error!"); + System.out.println("Sintaxis: java SwingWindowScannerFilter [options] arch-dict"); + System.out.println("Options:"); + System.out.println(" -simple: runs the non-swing version."); + System.out.println(TibetanScanner.copyrightASCII); + } + } + + /* FIXME: what happens if this throws an exception? We'll just + see it on the console--it won't terminate the program. And the + user may not see the console! See ThdlActionListener. -DC */ + public void actionPerformed(ActionEvent event) + { + Object clicked = event.getSource(); + StringSelection ss; + String s = null; + + if (clicked == mnuAbout) + { + if (diagAbout==null) diagAbout = new AboutDialog(mainWindow, false); + diagAbout.show(); + ThdlOptions.setUserPreference(AboutDialog.windowAboutOption, diagAbout.omitNextTime()); + try + { + ThdlOptions.saveUserPreferences(); + } + catch(Exception e) + { + } + } + else if (clicked == mnuClear) + { + sp.clear(); + } + else if (clicked == mnuOpen) + { + mainWindow.setVisible(false); + mainWindow.dispose(); + ThdlOptions.setUserPreference(defOpenOption, ""); + new SwingWindowScannerFilter(); + } + else if (clicked == mnuExit) + { + mainWindow.dispose(); + System.exit(0); + } + else if (clicked == mnuPreferences) + { + sp.setPreferences(null); + } + else if (clicked == mnuSavePref) + { + try + { + if (!ThdlOptions.saveUserPreferences()) { + JOptionPane.showMessageDialog(mainWindow, + "You previously cleared preferences,\nso you cannot now save them.", + "Cannot Save User Preferences", + JOptionPane.PLAIN_MESSAGE); + } + } + catch (IOException ioe) + { + JOptionPane.showMessageDialog(mainWindow, + "Could not save to your preferences file!", + "Error Saving Preferences", + JOptionPane.ERROR_MESSAGE); + } + + } + else + { + if (objModified==null) return; + + if (objModified instanceof TextArea) + { + TextArea t = (TextArea) objModified; + + if (clicked == mnuCut) + { + ss = new StringSelection(t.getSelectedText()); + Toolkit.getDefaultToolkit().getSystemClipboard().setContents(ss,ss); + t.replaceRange("", t.getSelectionStart(), t.getSelectionEnd()); + } + else if (clicked == mnuCopy) + { + ss = new StringSelection(t.getSelectedText()); + Toolkit.getDefaultToolkit().getSystemClipboard().setContents(ss,ss); + } + else if (clicked == mnuPaste) + { + Transferable data = Toolkit.getDefaultToolkit().getSystemClipboard().getContents(this); + try + { + s = (String)(data.getTransferData(DataFlavor.stringFlavor)); + } + catch (Exception ex) + { + s = data.toString(); + } + t.replaceRange(s, t.getSelectionStart(), t.getSelectionEnd()); + //t.insert(s, t.getCaretPosition()); + } + else if (clicked == mnuDelete) + { + t.replaceRange("", t.getSelectionStart(), t.getSelectionEnd()); + } + else if (clicked == mnuSelectAll) + { + t.selectAll(); + } + } + else if (objModified instanceof DuffPane) + { + DuffPane t = (DuffPane) objModified; + + if (clicked == mnuCut) + { + t.cut(); + } + else if (clicked == mnuCopy) + { + t.copy(); + } + else if (clicked == mnuPaste) + { + t.paste(t.getCaret().getDot()); + } + else if (clicked == mnuDelete) + { + try + { + t.getDocument().remove(t.getSelectionStart(), t.getSelectionEnd()); + } + catch (Exception ex) + { + System.out.println(ex); + } + } + else if (clicked == mnuSelectAll) + { + t.selectAll(); + } + } + } + } + + public void focusGained(FocusEvent e) + { + objModified = e.getSource(); + boolean isEditable=false; + + if (objModified instanceof TextComponent) + { + TextComponent t = (TextComponent) objModified; + isEditable = t.isEditable(); + } + else if (objModified instanceof JTextComponent) + { + JTextComponent j = (JTextComponent) objModified; + isEditable = j.isEditable(); + } + + mnuCut.setEnabled(isEditable); + if (isEditable) + { + if (Toolkit.getDefaultToolkit().getSystemClipboard().getContents(this)!=null) + mnuPaste.setEnabled(true); + } + else mnuPaste.setEnabled(false); + mnuDelete.setEnabled(isEditable); + mnuCopy.setEnabled(true); + mnuSelectAll.setEnabled(true); + } +} diff --git a/source/org/thdl/tib/scanner/SwingWord.java b/source/org/thdl/tib/scanner/SwingWord.java new file mode 100644 index 0000000..524c9b9 --- /dev/null +++ b/source/org/thdl/tib/scanner/SwingWord.java @@ -0,0 +1,103 @@ +/* +The contents of this file are subject to the AMP Open Community License +Version 1.0 (the "License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License on the AMP web site +(http://www.tibet.iteso.mx/Guatemala/). + +Software distributed under the License is distributed on an "AS IS" basis, +WITHOUT WARRANTY OF ANY KIND, either express or implied. See the +License for the specific terms governing rights and limitations under the +License. + +The Initial Developer of this software is Andres Montano Pellegrini. Portions +created by Andres Montano Pellegrini are Copyright 2001 Andres Montano +Pellegrini. All Rights Reserved. + +Contributor(s): ______________________________________. +*/ + +/** Used to make up the list of words to be displayed, not + to store the dictionary. */ +package org.thdl.tib.scanner; + +import org.thdl.tib.text.TibetanHTML; + +/** Tibetan word with its corresponding definitions. + + @author Andrés Montano Pellegrini +*/ +public class SwingWord extends Word +{ + public SwingWord(Word word) + { + super(word); + } + + public SwingWord (String word, String wordSinDec, String def) + { + super (word, wordSinDec, def); + } + + public SwingWord (String word, Definitions def) + { + super (word, def); + } + + public SwingWord (String word, String def) + { + super (word, def); + } + + public SwingWord (String word, String wordSinDec, Definitions def) + { + super (word, wordSinDec, def); + } + + public String getBookmark(boolean tibetan) + { + String localWord; + if (tibetan) + { + try + { + localWord = TibetanHTML.getHTML(super.token + " "); + } + catch (Exception e) + { + localWord = "" + super.token + ""; + } + } + else localWord = "" + super.token + ""; + return "" + localWord + ""; + } + + public String getLink() + { + return getLink(false); + } + + public String getLink(boolean tibetan) + { + String localWord, result=null; + // String result; + if (wordSinDec==null) localWord = super.token; + else localWord = wordSinDec; + if (tibetan) + { + try + { + result = TibetanHTML.getHTML(localWord + " "); + } + catch (Exception e) + { + result = localWord; + } + } + else result = localWord; +/* result = "" + localWord; + if (tibetan) result+= ""; + else result+= " "; + return result;*/ + return "" + result + " "; + } +} diff --git a/source/org/thdl/tib/scanner/TibetanScanner.java b/source/org/thdl/tib/scanner/TibetanScanner.java index a75395b..76cfc4f 100644 --- a/source/org/thdl/tib/scanner/TibetanScanner.java +++ b/source/org/thdl/tib/scanner/TibetanScanner.java @@ -25,7 +25,7 @@ import org.thdl.util.*; */ public abstract class TibetanScanner { - public static final String version = "The Tibetan to English Translation Tool, version 3.0.0 compiled on " + ThdlVersion.getTimeOfCompilation() + ". "; + public static final String version = "The Tibetan to English Translation Tool, version 3.1.0 compiled on " + ThdlVersion.getTimeOfCompilation() + ". "; public static final String copyrightUnicode="Copyright " + '\u00A9' + " 2000-2004 by Andr" + '\u00E9' + "s Montano Pellegrini, all rights reserved."; public static final String copyrightASCII="Copyright 2000-2004 by Andres Montano Pellegrini, all rights reserved."; public static final String copyrightHTML="
" + version + "Copyright © 2000-2004 by Andrés Montano Pellegrini.
All rights reserved.
"; diff --git a/source/org/thdl/tib/scanner/WhichDictionaryFrame.java b/source/org/thdl/tib/scanner/WhichDictionaryFrame.java index 84a0ede..eda4416 100644 --- a/source/org/thdl/tib/scanner/WhichDictionaryFrame.java +++ b/source/org/thdl/tib/scanner/WhichDictionaryFrame.java @@ -9,218 +9,70 @@ import javax.swing.*; /** provides a friendly user interface when the command-line is not used for choosing a dictionary or connection to open. */ -class WhichDictionaryFrame extends Dialog implements ActionListener, ItemListener +abstract class WhichDictionaryFrame extends Dialog implements ActionListener, ItemListener { - private String response; - private int dictType; - private Button ok, cancel; - private Checkbox useOnline, useOffline, createNewDictDB; - private Choice availDictsOnline; - private Label localDict; - private Button browse; - private Frame owner; - private boolean pocketpc; - private DictionaryFileFilter dicFilter; - private String dictsOnline[], dictTypes[]; - private Checkbox ckbDefault; - private CreateDatabaseWizard cdw; + protected String response; + protected int dictType; + protected Button ok, cancel; + protected Checkbox useOnline, useOffline; + protected Choice availDictsOnline; + protected Label localDict; + protected Button browse; + protected Frame owner; + protected String dictsOnline[], dictTypes[]; + protected Checkbox ckbDefault; - public WhichDictionaryFrame(Frame owner, boolean pocketpc) + public WhichDictionaryFrame(Frame owner) { super(owner, "Welcome to the Tibetan to English Translation Tool", true); - Panel p; - CheckboxGroup cbg = new CheckboxGroup(); - - this.owner = owner; - this.pocketpc = pocketpc; - dicFilter = null; - response=""; - this.setLayout(new GridLayout(6, 1)); - if (pocketpc) - { - Dimension d = Toolkit.getDefaultToolkit().getScreenSize(); - this.setSize(d); - } else this.setSize(400, 200); - if (pocketpc) this.add(new Label("Would you like open:")); - else this.add(new Label("Would you like to:")); + this.owner = owner; + response=""; // FIXME: values should not be hardwired dictsOnline = new String[2]; - dictTypes = new String[3]; - - availDictsOnline = null; - p = new Panel(new BorderLayout()); - if (pocketpc) useOnline = new Checkbox("An on-line dict", false, cbg); - else useOnline = new Checkbox("Access an on-line dictionary", false, cbg); - useOnline.addItemListener(this); - p.add(useOnline, BorderLayout.WEST); - - availDictsOnline = new Choice(); - - if (pocketpc) availDictsOnline.add("Public"); - else availDictsOnline.add("Public version"); dictsOnline[0] = "http://iris.lib.virginia.edu/tibetan/servlet/org.thdl.tib.scanner.RemoteScannerFilter"; - dictTypes[0] = "public"; - - if (pocketpc) availDictsOnline.add("Private version"); - else availDictsOnline.add("Private version (only within UVa)"); dictsOnline[1] = "http://wyllie.lib.virginia.edu/tibetan/servlet/org.thdl.tib.scanner.RemoteScannerFilter"; - dictTypes[1] = "private"; + dictTypes = new String[3]; + dictTypes[0] = "public"; + dictTypes[1] = "private"; + dictTypes[2] = "local"; + //dictsOnline[2] = "http://localhost:8080/tibetan/servlet/org.thdl.tib.scanner.RemoteScannerFilter"; + + availDictsOnline = new Choice(); //availDictsOnline.add("Local (only on my computer!)"); - //dictsOnline[2] = "http://localhost:8080/tibetan/servlet/org.thdl.tib.scanner.RemoteScannerFilter"; availDictsOnline.addItemListener(this); availDictsOnline.setEnabled(false); - p.add(availDictsOnline, BorderLayout.EAST); - this.add(p); - - p = new Panel(new BorderLayout()); - if (pocketpc) useOffline = new Checkbox("Local dict: ", true, cbg); - else useOffline = new Checkbox("Access a local dictionary: ", true, cbg); - useOffline.addItemListener(this); - p.add(useOffline, BorderLayout.WEST); localDict = new Label(); localDict.setEnabled(true); - p.add(localDict, BorderLayout.CENTER); - dictTypes[2] = "local"; - dictType = 2; + dictType = 2; + browse = new Button("Browse..."); browse.setEnabled(true); browse.addActionListener(this); - p.add(browse, BorderLayout.EAST); - this.add(p); - if (pocketpc) createNewDictDB = new Checkbox("New dict...", false, cbg); - else createNewDictDB = new Checkbox("Create a new dictionary...", false, cbg); - createNewDictDB.addItemListener(this); - this.add(createNewDictDB); - - p = new Panel(new FlowLayout()); + ok = new Button("Ok"); ok.setEnabled(false); ok.addActionListener(this); + cancel = new Button("Cancel"); cancel.addActionListener(this); - p.add(ok); - p.add(cancel); - this.add(p); - p = new Panel(new FlowLayout(FlowLayout.RIGHT)); - if (pocketpc) ckbDefault = new Checkbox("Set as default?", true); - else ckbDefault = new Checkbox("Use these settings as default", true); - p.add(ckbDefault); - this.add(p); + + useOnline=null; + useOffline=null; + ckbDefault=null; } - public void actionPerformed(ActionEvent e) - { - Object obj = e.getSource(); - FileDialog fd; - String fileName; - int pos; - - if (obj == ok) - { - if (response.equals("")) - { - if (cdw==null) cdw = new CreateDatabaseWizard(owner, pocketpc); - cdw.show(); - response = cdw.getResponse(); - } - if (!response.equals("")) this.setVisible(false); - } - else if (obj == cancel) - { - response = ""; - this.setVisible(false); - } - else if (obj == browse) - { - if (pocketpc) - { - fd = new FileDialog(owner, "Select dictionary to open", FileDialog.LOAD); - fd.show(); - fileName = fd.getFile(); - if (fileName!= null) - { - // dropping the extension - pos = fileName.lastIndexOf('.'); - if (pos>0) fileName = fileName.substring(0, pos); - response = fd.getDirectory() + fileName; - localDict.setText(response); - ok.setEnabled(true); - } - } - else - { - if (dicFilter == null) dicFilter = new DictionaryFileFilter(); - JFileChooser fileChooser = new JFileChooser("Select dictionary to open"); - fileChooser.addChoosableFileFilter(dicFilter); - /*setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); - - if (fileChooser.showOpenDialog(this) != JFileChooser.APPROVE_OPTION) - { - setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); - return; - }*/ - if (fileChooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) - { - response = fileChooser.getSelectedFile().getPath(); - response = response.substring(0, response.length()-4); - localDict.setText(response); - ok.setEnabled(true); - } - } - } - } + public abstract void actionPerformed(ActionEvent e); /** Implement the disabling of other guys here */ - public void itemStateChanged(ItemEvent e) - { - Object obj = e.getSource(); - if (obj instanceof Checkbox) - { - Checkbox chx = (Checkbox) obj; - //System.out.println(obj); - if (chx == useOnline) - { - localDict.setEnabled(false); - browse.setEnabled(false); - availDictsOnline.setEnabled(true); - ok.setEnabled(true); - dictType = availDictsOnline.getSelectedIndex(); - response = dictsOnline[dictType]; - } - else if (chx == useOffline) - { - localDict.setEnabled(true); - browse.setEnabled(true); - if (availDictsOnline!=null) availDictsOnline.setEnabled(false); - ok.setEnabled(!localDict.getText().equals("")); - response = localDict.getText(); - dictType = 2; - } - else if (chx == createNewDictDB) - { - localDict.setEnabled(false); - browse.setEnabled(false); - if (availDictsOnline!=null) availDictsOnline.setEnabled(false); - ok.setEnabled(true); - response=""; - dictType = 2; - } - } - else if (obj instanceof Choice) - { - Choice ch = (Choice) obj; - dictType = ch.getSelectedIndex(); - response = dictsOnline[dictType]; - } - } - + public abstract void itemStateChanged(ItemEvent e); + public String getResponse() { return response; diff --git a/source/org/thdl/tib/scanner/WindowScannerFilter.java b/source/org/thdl/tib/scanner/WindowScannerFilter.java index 4a20817..ed58ee8 100644 --- a/source/org/thdl/tib/scanner/WindowScannerFilter.java +++ b/source/org/thdl/tib/scanner/WindowScannerFilter.java @@ -25,41 +25,40 @@ import java.awt.event.*; import java.applet.Applet; import java.awt.*; import java.awt.datatransfer.*; -import javax.swing.text.JTextComponent; -import javax.swing.JOptionPane; -import org.thdl.tib.input.*; import org.thdl.util.*; /** Provides a graphical interfase to input Tibetan text (Roman or Tibetan script) and displays the words (Roman or Tibetan script) with their definitions. Works without Tibetan script in platforms that don't support Swing. Can access dictionaries stored - locally or remotely. For example, to access the public dictionary database run the command:

-
java -jar DictionarySearchStandalone.jar http://iris.lib.virginia.edu/tibetan/servlet/org.thdl.tib.scanner.RemoteScannerFilter
-

If the JRE you installed does not support Swing classes but supports - - AWT (as the JRE for handhelds), run the command:

-
java -jar DictionarySearchHandheld.jar -simple ry-dic99
+ locally or remotely. It is not meant to be run alone, but through one + of the inherited childs. Use SwingWindowScannerFilter for platforms + that support swing. Use PockeWindowScannerFilter for platforms that + support awt but not swing. @author Andrés Montano Pellegrini */ -public class WindowScannerFilter implements WindowListener, FocusListener, ActionListener, ItemListener +public abstract class WindowScannerFilter implements WindowListener, FocusListener, ActionListener, ItemListener { - private static String defOpenOption = "thdl.scanner.default.open"; - private static String dictOpenType = "thdl.scanner.default.type"; + protected static String defOpenOption = "thdl.scanner.default.open"; + protected static String dictOpenType = "thdl.scanner.default.type"; + protected static String defaultFontFace = "thdl.default.roman.font.face"; + protected static String defaultFontSize = "thdl.default.roman.font.size"; + protected static String defaultInputRows = "thdl.scanner.input-pane.rows"; + protected static String defaultOutputRows = "thdl.scanner.output-pane.rows"; - private ScannerPanel sp; - private MenuItem mnuExit, mnuCut, mnuCopy, mnuPaste, mnuDelete, mnuSelectAll, mnuAbout, mnuClear, mnuOpen, mnuPreferences, mnuSavePref; - private CheckboxMenuItem mnuDicts; - private Object objModified; - private AboutDialog diagAbout; - private Frame mainWindow; - private boolean pocketpc; - - public WindowScannerFilter(boolean pocketpc) + protected ScannerPanel sp; + protected MenuItem mnuExit, mnuCut, mnuCopy, mnuPaste, mnuDelete, mnuSelectAll, mnuAbout, mnuClear, mnuOpen, mnuPreferences, mnuSavePref; + protected CheckboxMenuItem mnuDicts; + protected Object objModified; + protected AboutDialog diagAbout; + protected Frame mainWindow; + + /** This class is not meant to be called by itself */ + public WindowScannerFilter() { String response, dictType; - this.pocketpc = pocketpc; + WhichDictionaryFrame wdf; response = ThdlOptions.getStringOption(defOpenOption); @@ -68,11 +67,16 @@ public class WindowScannerFilter implements WindowListener, FocusListener, Actio mainWindow = new Frame("Tibetan Translation Tool"); mainWindow.show(); mainWindow.toFront(); - WhichDictionaryFrame wdf = new WhichDictionaryFrame(mainWindow, pocketpc); - - wdf.show(); - response = wdf.getResponse(); - if (response.equals("")) System.exit(0); + + wdf = getWhichDictionaryFrame(); + response = wdf.getResponse(); + wdf.dispose(); + + if (response.equals("")) + { + mainWindow.dispose(); + System.exit(0); + } else { dictType = wdf.getDictionaryType(); @@ -92,198 +96,17 @@ public class WindowScannerFilter implements WindowListener, FocusListener, Actio } } makeWindow (response); - } + } - public WindowScannerFilter() - { - this(false); - } - public WindowScannerFilter(String file) { - pocketpc = false; mainWindow = null; makeWindow (file); } - public WindowScannerFilter(String file, boolean pocketpc) - { - this.pocketpc = pocketpc; - mainWindow = null; - makeWindow (file); - } - - public void makeWindow(String file) - { - if (mainWindow==null) - { - String dictType=null; - dictType = ThdlOptions.getStringOption(dictOpenType); - if (dictType!=null && !dictType.equals("")) - mainWindow = new Frame("Tibetan Translation Tool: Connected to " + dictType + " database"); - else - mainWindow = new Frame("Tibetan Translation Tool"); - } - else mainWindow.setVisible(false); - mainWindow.setLayout(new GridLayout(1,1)); - mainWindow.setBackground(Color.white); - - diagAbout = null; - mnuAbout = null; - Dimension d = Toolkit.getDefaultToolkit().getScreenSize(); - - if (pocketpc) sp = new SimpleScannerPanel(file, d.width >d.height); - else sp = new DuffScannerPanel(file); - - MenuBar mb = new MenuBar(); - Menu m; - m = new Menu ("File"); - mnuOpen = new MenuItem("Open..."); - mnuOpen.addActionListener(this); - m.add(mnuOpen); - mnuExit = new MenuItem("Exit"); - mnuExit.addActionListener(this); - m.add(mnuExit); - mb.add(m); - - m = new Menu ("Edit"); - mnuCut = new MenuItem("Cut"); - //mnuCut.setShortcut(new MenuShortcut(KeyEvent.VK_X)); - m.add(mnuCut); - mnuCut.addActionListener(this); - mnuCopy = new MenuItem("Copy"); - //mnuCopy.setShortcut(new MenuShortcut(KeyEvent.VK_C)); - m.add(mnuCopy); - mnuCopy.addActionListener(this); - mnuPaste = new MenuItem("Paste"); - //mnuPaste.setShortcut(new MenuShortcut(KeyEvent.VK_V)); - m.add(mnuPaste); - mnuPaste.addActionListener(this); - mnuDelete = new MenuItem("Delete"); - m.add(mnuDelete); - mnuDelete.addActionListener(this); - m.add("-"); - mnuSelectAll = new MenuItem("Select all"); - //mnuSelectAll.setShortcut(new MenuShortcut(KeyEvent.VK_A)); - m.add(mnuSelectAll); - mnuSelectAll.addActionListener(this); - mnuClear = new MenuItem("Clear all"); - m.add(mnuClear); - mnuClear.addActionListener(this); - if (!pocketpc) - { - m.add("-"); - mnuPreferences = new MenuItem("Preferences"); - m.add(mnuPreferences); - mnuPreferences.addActionListener(this); - mnuSavePref = new MenuItem("Save preferences to " + ThdlOptions.getUserPreferencesPath()); - m.add(mnuSavePref); - mnuSavePref.addActionListener(this); - mnuDicts=null; - } - mb.add(m); - - if (pocketpc) - { - m = new Menu("View"); - mnuDicts = new CheckboxMenuItem("Dictionaries", false); - m.add(mnuDicts); - mnuDicts.addItemListener(this); - mb.add(m); - } - - m = new Menu("Help"); - if (!pocketpc) - { - for (int i = 0; i < DuffScannerPanel.keybdMgr.size(); i++) - { - final JskadKeyboard kbd = DuffScannerPanel.keybdMgr.elementAt(i); - if (kbd.hasQuickRefFile()) - { - MenuItem keybdItem = new MenuItem(kbd.getIdentifyingString()); - keybdItem.addActionListener(new ThdlActionListener() - { - public void theRealActionPerformed(ActionEvent e) - { - new SimpleFrame(kbd.getIdentifyingString(), - kbd.getQuickRefPane()); - /* DLC FIXME -- pressing the "Extended - Wylie" menu item (for example) twice - causes the first pane to become dead. - We should check to see if the first - pane exists and raise it rather than - creating a second pane. */ - } - }); - m.add(keybdItem); - } - } - m.add("-"); - } - mnuAbout = new MenuItem("About..."); - m.add(mnuAbout); - mnuAbout.addActionListener(this); - mb.add(m); - - // disable menus - focusLost(null); - - sp.addFocusListener(this); - - mainWindow.setMenuBar(mb); - mainWindow.add(sp); - mainWindow.addWindowListener(this); - mainWindow.setSize(d); - // mainWindow.setSize(240,320); - //else mainWindow.setSize(500,600); - mainWindow.show(); - mainWindow.toFront(); - - if (!ThdlOptions.getBooleanOption(AboutDialog.windowAboutOption)) - { - diagAbout = new AboutDialog(mainWindow, pocketpc); - diagAbout.show(); - - if (diagAbout.omitNextTime()) - { - ThdlOptions.setUserPreference(AboutDialog.windowAboutOption, true); - try - { - ThdlOptions.saveUserPreferences(); - } - catch(Exception e) - { - } - } - } - } + protected abstract WhichDictionaryFrame getWhichDictionaryFrame(); + protected abstract void makeWindow(String file); - public static void main(String[] args) - { - switch(args.length) - { - case 0: - if (System.getProperty("os.name").toLowerCase().equals("windows ce")) - new WindowScannerFilter(true); - else new WindowScannerFilter(); - break; - case 1: - if (args[0].length()>0 && args[0].charAt(0)=='-') new WindowScannerFilter(true); - else new WindowScannerFilter(args[0]); - break; - case 2: - new WindowScannerFilter(args[1], true); - break; - default: - System.out.println("Syntax error!"); - System.out.println("Sintaxis: java WindowScannerFilter [options] arch-dict"); - System.out.println("Options:"); - System.out.println(" -simple: runs the non-swing version."); - System.out.println(TibetanScanner.copyrightASCII); - } - } - - /** * Cierra la ventana. Invocado unicamente cuando el programa corre * como aplicacion, para que el programa pare su ejecucion cuando @@ -292,6 +115,7 @@ public class WindowScannerFilter implements WindowListener, FocusListener, Actio public void windowClosing(WindowEvent e) { sp.closingRemarks(); + mainWindow.dispose(); System.exit(0); } @@ -364,33 +188,7 @@ public class WindowScannerFilter implements WindowListener, FocusListener, Actio /** Added to update the Edit menu in dependence upon which textbox the keyboard focus is at. */ - public void focusGained(FocusEvent e) - { - objModified = e.getSource(); - boolean isEditable=false; - - if (objModified instanceof TextComponent) - { - TextComponent t = (TextComponent) objModified; - isEditable = t.isEditable(); - } - else if (objModified instanceof JTextComponent) - { - JTextComponent j = (JTextComponent) objModified; - isEditable = j.isEditable(); - } - - mnuCut.setEnabled(isEditable); - if (isEditable) - { - if (Toolkit.getDefaultToolkit().getSystemClipboard().getContents(this)!=null) - mnuPaste.setEnabled(true); - } - else mnuPaste.setEnabled(false); - mnuDelete.setEnabled(isEditable); - mnuCopy.setEnabled(true); - mnuSelectAll.setEnabled(true); - } + public abstract void focusGained(FocusEvent e); /** Added to update the Edit menu in dependence upon which textbox the keyboard focus is at. @@ -405,146 +203,59 @@ public class WindowScannerFilter implements WindowListener, FocusListener, Actio mnuSelectAll.setEnabled(false); } - /* FIXME: what happens if this throws an exception? We'll just - see it on the console--it won't terminate the program. And the - user may not see the console! See ThdlActionListener. -DC */ - public void actionPerformed(ActionEvent event) - { - Object clicked = event.getSource(); - StringSelection ss; - String s = null; - - if (clicked == mnuAbout) - { - if (diagAbout==null) diagAbout = new AboutDialog(mainWindow, pocketpc); - diagAbout.show(); - ThdlOptions.setUserPreference(AboutDialog.windowAboutOption, diagAbout.omitNextTime()); - try - { - ThdlOptions.saveUserPreferences(); - } - catch(Exception e) - { - } - } - else if (clicked == mnuClear) - { - sp.clear(); - } - else if (clicked == mnuOpen) - { - mainWindow.setVisible(false); - mainWindow.dispose(); - ThdlOptions.setUserPreference(defOpenOption, ""); - new WindowScannerFilter(pocketpc); - } - else if (clicked == mnuExit) - { - System.exit(0); - } - else if (clicked == mnuPreferences) - { - sp.setPreferences(); - } - else if (clicked == mnuSavePref) - { - try - { - if (!ThdlOptions.saveUserPreferences()) { - JOptionPane.showMessageDialog(mainWindow, - "You previously cleared preferences,\nso you cannot now save them.", - "Cannot Save User Preferences", - JOptionPane.PLAIN_MESSAGE); - } - } - catch (IOException ioe) - { - JOptionPane.showMessageDialog(mainWindow, - "Could not save to your preferences file!", - "Error Saving Preferences", - JOptionPane.ERROR_MESSAGE); - } - - } - else - { - if (objModified==null) return; - - if (objModified instanceof TextArea) - { - TextArea t = (TextArea) objModified; - - if (clicked == mnuCut) - { - ss = new StringSelection(t.getSelectedText()); - Toolkit.getDefaultToolkit().getSystemClipboard().setContents(ss,ss); - t.replaceRange("", t.getSelectionStart(), t.getSelectionEnd()); - } - else if (clicked == mnuCopy) - { - ss = new StringSelection(t.getSelectedText()); - Toolkit.getDefaultToolkit().getSystemClipboard().setContents(ss,ss); - } - else if (clicked == mnuPaste) - { - Transferable data = Toolkit.getDefaultToolkit().getSystemClipboard().getContents(this); - try - { - s = (String)(data.getTransferData(DataFlavor.stringFlavor)); - } - catch (Exception ex) - { - s = data.toString(); - } - t.replaceRange(s, t.getSelectionStart(), t.getSelectionEnd()); - //t.insert(s, t.getCaretPosition()); - } - else if (clicked == mnuDelete) - { - t.replaceRange("", t.getSelectionStart(), t.getSelectionEnd()); - } - else if (clicked == mnuSelectAll) - { - t.selectAll(); - } - } - else if (objModified instanceof DuffPane) - { - DuffPane t = (DuffPane) objModified; - - if (clicked == mnuCut) - { - t.cut(); - } - else if (clicked == mnuCopy) - { - t.copy(); - } - else if (clicked == mnuPaste) - { - t.paste(t.getCaret().getDot()); - } - else if (clicked == mnuDelete) - { - try - { - t.getDocument().remove(t.getSelectionStart(), t.getSelectionEnd()); - } - catch (Exception ex) - { - System.out.println(ex); - } - } - else if (clicked == mnuSelectAll) - { - t.selectAll(); - } - } - } - } + public abstract void actionPerformed(ActionEvent event); public void itemStateChanged(ItemEvent e) { sp.setWylieInput(e.getStateChange()!=ItemEvent.SELECTED); } + + public static String getTHDLFontFamilyName() + { + String response = ThdlOptions.getStringOption(defaultFontFace); + int size; + + if (response!=null && response.equals("")) return null; + return response; + } + + public static void setTHDLFontFamilyName(String font) + { + ThdlOptions.setUserPreference(defaultFontFace, font); + } + + public static int getTHDLFontSize() + { + return ThdlOptions.getIntegerOption(defaultFontSize, 12); + } + + public static void setTHDLFontSize(int font) + { + ThdlOptions.setUserPreference(defaultFontSize, font); + } + + public static int getInputPaneRows() + { + return ThdlOptions.getIntegerOption(defaultInputRows, 4); + } + + public static void setInputPaneRows(int rows) + { + ThdlOptions.setUserPreference(defaultInputRows, rows); + } + + public static int getOutputPaneRows() + { + return ThdlOptions.getIntegerOption(defaultOutputRows, 7); + } + + public static void setOutputPaneRows(int rows) + { + ThdlOptions.setUserPreference(defaultOutputRows, rows); + } + + public static Font getTHDLFont() + { + return new Font(WindowScannerFilter.getTHDLFontFamilyName(), Font.PLAIN, WindowScannerFilter.getTHDLFontSize()); + } } diff --git a/source/org/thdl/tib/scanner/Word.java b/source/org/thdl/tib/scanner/Word.java index c1384d1..4884a3e 100644 --- a/source/org/thdl/tib/scanner/Word.java +++ b/source/org/thdl/tib/scanner/Word.java @@ -20,7 +20,7 @@ Contributor(s): ______________________________________. to store the dictionary. */ package org.thdl.tib.scanner; -import org.thdl.tib.text.TibetanHTML; +//import org.thdl.tib.text.TibetanHTML; /** Tibetan word with its corresponding definitions. @@ -29,8 +29,13 @@ import org.thdl.tib.text.TibetanHTML; public class Word extends Token { /** Used to rebuild the text the user entered. */ - private String wordSinDec; - private Definitions def; + protected String wordSinDec; + protected Definitions def; + + public Word (Word word) + { + this(word.token, word.wordSinDec, word.def); + } public Word (String word, String wordSinDec, String def) { @@ -97,54 +102,6 @@ public class Word extends Token { return super.token + " - " + def; } - - public String getBookmark(boolean tibetan) - { - String localWord; - if (tibetan) - { - try - { - localWord = TibetanHTML.getHTML(super.token + " "); - } - catch (Exception e) - { - localWord = "" + super.token + ""; - } - } - else localWord = "" + super.token + ""; - return "" + localWord + ""; - } - - public String getLink() - { - return getLink(false); - } - - public String getLink(boolean tibetan) - { - String localWord, result=null; - // String result; - if (wordSinDec==null) localWord = super.token; - else localWord = wordSinDec; - if (tibetan) - { - try - { - result = TibetanHTML.getHTML(localWord + " "); - } - catch (Exception e) - { - result = localWord; - } - } - else result = localWord; -/* result = "" + localWord; - if (tibetan) result+= ""; - else result+= " "; - return result;*/ - return "" + result + " "; - } /** Called in order to redisplay the text with links keeping the returns the user entered.