Fixed pocket pc version to be completely swing-less.

This commit is contained in:
amontano 2004-12-23 19:31:26 +00:00
parent 533534eb9f
commit 88ebeaed3b
20 changed files with 2221 additions and 707 deletions

View file

@ -31,14 +31,16 @@ public class AboutDialog extends Dialog implements ActionListener, WindowListene
{ {
public static String windowAboutOption = "thdl.scanner.omit.about.window"; public static String windowAboutOption = "thdl.scanner.omit.about.window";
private Checkbox chkOmitNextTime; private Checkbox chkOmitNextTime;
private Button close;
public AboutDialog(Frame parent, boolean pocketpc) public AboutDialog(Frame parent, boolean pocketpc)
{ {
super(parent, "About...", true); super(parent, "About...", true);
this.setFont(WindowScannerFilter.getTHDLFont());
Panel p = new Panel(new BorderLayout()); Panel p = new Panel(new BorderLayout());
chkOmitNextTime = new Checkbox("Don't show this window at startup", ThdlOptions.getBooleanOption(windowAboutOption)); chkOmitNextTime = new Checkbox("Don't show this window at startup", ThdlOptions.getBooleanOption(windowAboutOption));
p.add(chkOmitNextTime, BorderLayout.CENTER); p.add(chkOmitNextTime, BorderLayout.CENTER);
Button close = new Button("Close this window"); close = new Button("Close this window");
p.add(close, BorderLayout.EAST); p.add(close, BorderLayout.EAST);
add(p, BorderLayout.NORTH); add(p, BorderLayout.NORTH);
close.addActionListener(this); close.addActionListener(this);
@ -54,6 +56,13 @@ public class AboutDialog extends Dialog implements ActionListener, WindowListene
else setSize(480,400); else setSize(480,400);
} }
/* public void setDefaultFont(Font f)
{
this.setFont(f);
chkOmitNextTime.setFont(f);
close.setFont(f);
}*/
public boolean omitNextTime() public boolean omitNextTime()
{ {
return chkOmitNextTime.getState(); return chkOmitNextTime.getState();
@ -64,7 +73,7 @@ public class AboutDialog extends Dialog implements ActionListener, WindowListene
user may not see the console! See ThdlActionListener. -DC */ user may not see the console! See ThdlActionListener. -DC */
public void actionPerformed(ActionEvent e) public void actionPerformed(ActionEvent e)
{ {
hide(); dispose();
} }
/** /**
@ -74,7 +83,7 @@ public class AboutDialog extends Dialog implements ActionListener, WindowListene
*/ */
public void windowClosing(WindowEvent e) public void windowClosing(WindowEvent e)
{ {
hide(); dispose();
} }
/** /**

View file

@ -18,23 +18,18 @@ class CreateDatabaseWizard extends Dialog implements ActionListener, ItemListene
private Button add, ok, cancel, browse; private Button add, ok, cancel, browse;
private Frame owner; private Frame owner;
private SimplifiedLinkedList dicts; private SimplifiedLinkedList dicts;
private boolean pocketpc;
private String response; private String response;
CreateDatabaseWizard(Frame owner, boolean pocketpc) CreateDatabaseWizard(Frame owner)
{ {
super(owner, "Generation of Binary Tree Dictionary", true); super(owner, "Generation of Binary Tree Dictionary", true);
this.pocketpc = pocketpc;
this.owner = owner; this.owner = owner;
response = ""; response = "";
dicts = new SimplifiedLinkedList(); dicts = new SimplifiedLinkedList();
this.setLayout(new BorderLayout()); this.setLayout(new BorderLayout());
if (pocketpc) this.setSize(400,300);
{
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
this.setSize(d);
} else this.setSize(400,300);
Panel p1, p2, p3; Panel p1, p2, p3;
p1 = new Panel(new GridLayout(4, 1)); p1 = new Panel(new GridLayout(4, 1));
p2 = new Panel(new FlowLayout(FlowLayout.LEFT)); p2 = new Panel(new FlowLayout(FlowLayout.LEFT));
@ -53,13 +48,11 @@ class CreateDatabaseWizard extends Dialog implements ActionListener, ItemListene
p2.add(browse, BorderLayout.EAST); p2.add(browse, BorderLayout.EAST);
p1.add(p2); p1.add(p2);
p2 = new Panel(new BorderLayout()); p2 = new Panel(new BorderLayout());
if (pocketpc) p2.add(new Label("Desc:"), BorderLayout.WEST); p2.add(new Label("Description:"), BorderLayout.WEST);
else p2.add(new Label("Description:"), BorderLayout.WEST);
dicDesc = new TextField(20); dicDesc = new TextField(20);
p2.add(dicDesc, BorderLayout.CENTER); p2.add(dicDesc, BorderLayout.CENTER);
p3 = new Panel(new FlowLayout()); p3 = new Panel(new FlowLayout());
if (pocketpc) p3.add(new Label("Abv:")); p3.add(new Label("Abbreviation:"));
else p3.add(new Label("Abbreviation:"));
dicAbb = new TextField(6); dicAbb = new TextField(6);
p3.add(dicAbb); p3.add(dicAbb);
p2.add(p3, BorderLayout.EAST); p2.add(p3, BorderLayout.EAST);
@ -149,37 +142,21 @@ class CreateDatabaseWizard extends Dialog implements ActionListener, ItemListene
AcipToWylie a2w=null; AcipToWylie a2w=null;
// getting the database name // getting the database name
if (pocketpc) DictionaryFileFilter dicFilter = new DictionaryFileFilter();
{ JFileChooser fileChooser = new JFileChooser("Save database to");
fd = new FileDialog(owner, "Save database to", FileDialog.SAVE); fileChooser.addChoosableFileFilter(dicFilter);
fd.show(); /*setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
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));
if (fileChooser.showOpenDialog(this) != JFileChooser.APPROVE_OPTION) if (fileChooser.showOpenDialog(this) != JFileChooser.APPROVE_OPTION)
{ {
setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
return; return;
}*/ }*/
if (fileChooser.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) if (fileChooser.showSaveDialog(this) == JFileChooser.APPROVE_OPTION)
{ {
path = fileChooser.getSelectedFile().getPath(); path = fileChooser.getSelectedFile().getPath();
pos = path.lastIndexOf('.'); pos = path.lastIndexOf('.');
if (pos>0) path = path.substring(0, pos); if (pos>0) path = path.substring(0, pos);
}
} }
PrintWriter pr=null; PrintWriter pr=null;

View file

@ -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; i<matrix.length; i++)
matrix[i] = UNIQUE;
i=0;
while (i<fields.length)
{
if (Character.isDigit(fields[i].charAt(fields[i].length()-1)))
{
matrix[i] = MERGE_HEAD;
root = fields[i].substring(0,fields[i].length()-1);
i++;
while (i<fields.length && (sameRoot = fields[i].substring(0,fields[i].length()-1).equals(root)))
{
matrix[i] = MERGE_FOLLOWER;
i++;
}
if (!sameRoot) i--;
}
i++;
}
return matrix;
}
private static String deleteComas(String s)
{
if (s.length()>1 && 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<tokens.length; i++)
{
fields[i] = deleteComas(tokens[i]);
}
for (j=i; j<fields.length; j++)
fields[j]="";
return fields;
}
private String[] buildMergedFieldNames(String fieldNames[], int mergeMatrix[])
{
int i;
SimplifiedLinkedList ll = new SimplifiedLinkedList();
for (i=0; i<mergeMatrix.length; i++)
{
switch (mergeMatrix[i])
{
case UNIQUE: ll.addLast(fieldNames[i]);
break;
case MERGE_HEAD: ll.addLast(fieldNames[i].substring(0,fieldNames[i].length()-1));
}
}
return ll.toStringArray();
}
public String [] getMergeFields(String fields[], int mergeMatrix[])
{
// I can safely assume that fields contains info and are non null.
int i=0, j=0, fieldNum;
String mergedFields[] = new String[numberOfMergedFields];
outAHere:
while(i<fields.length && j<mergedFields.length)
{
switch(mergeMatrix[i])
{
case UNIQUE:
mergedFields[j] = fields[i];
i++; j++;
break;
case MERGE_HEAD:
fieldNum=1;
if (!fields[i].equals("") && !fields[i+1].equals(""))
mergedFields[j] = fieldNum + ". " + fields[i];
else mergedFields[j]=fields[i];
i++; fieldNum++;
while (mergeMatrix[i]==MERGE_FOLLOWER)
{
if (!fields[i].equals(""))
{
if (!mergedFields[j].equals(""))
mergedFields[j]+="; " + fieldNum + ". " + fields[i];
else mergedFields[j] = fieldNum + ". " + fields[i];
}
i++; fieldNum++;
if (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; i<out.length; i++)
{
if (format!=null) out[i] = new PrintWriter(new OutputStreamWriter(new FileOutputStream(mergedFieldNames[i+1] + ".txt"), format));
else out[i] = new PrintWriter(new FileOutputStream(mergedFieldNames[i+1] + ".txt"));
}
}
while ((linea=in.readLine())!=null)
{
fields = getFields(linea);
mergedFields = getMergeFields(fields, mergeMatrix);
switch (mode)
{
case TOMERAIDER:
linea = fields[0];
forBreak:
for (i=0; i<linea.length(); i++)
{
ch = linea.charAt(i);
if (ch==';' || ch=='/')
{
linea = linea.substring(0, i);
break forBreak;
}
}
pos = linea.indexOf("...");
if (pos>0) 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] + "<br>");
else outOne.print(mergedFields[i] + "<br>");
}
}
if (!mergedFields[3].equals("")) // english
{
if (tail!=null) outOne.print("... " + tail + ": <b>" + mergedFields[3] + "</b><br>");
else outOne.print("<b>" + mergedFields[3] + "</b><br>");
}
if (!mergedFields[4].equals("")) // english-others
{
if (tail!=null) outOne.print("... " + tail + ": <i>" + mergedFields[4] + "</i><br>");
else outOne.print("<i>" + mergedFields[4] + "</i><br>");
}
for (i=5; i<=8; i++)
{
if (!mergedFields[i].equals(""))
{
if (tail!=null) outOne.print("... " + tail + ": " + mergedFields[i] + "<br>");
else outOne.print(mergedFields[i] + "<br>");
}
}
if (!mergedFields[9].equals("")) // synonyms-tibetan
{
if (tail!=null) outOne.print("... " + tail + ": <i>Synonyms: </i>" + mergedFields[9] + "<br>");
else outOne.print("<i>Synonyms: </i>" + mergedFields[9] + "<br>");
}
for (i=10; i<=13; i++)
{
if (!mergedFields[i].equals(""))
{
if (tail!=null) outOne.print("... " + tail + ": " + mergedFields[i] + "<br>");
else outOne.print(mergedFields[i] + "<br>");
}
}
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<mergedFields.length; i++)
{
if (!mergedFields[i].equals(""))
{
if (tail!=null)
out[i-1].println(mergedFields[0] + '\t' + "... " + tail + ": " + mergedFields[i]);
else out[i-1].println(mergedFields[0] + '\t' + mergedFields[i]);
}
}
}
}
switch (mode)
{
case TOMERAIDER:
outOne.println("<new>\nAbout\n");
outOne.println(TibetanScanner.aboutTomeraider);
sli = ll.listIterator();
while (sli.hasNext())
{
mergedFields = ((SortingTibetanEntry)sli.next()).get();
outOne.println("\n<new>\n" + mergedFields[0] + "\n");
if (!mergedFields[1].equals("")) outOne.println(mergedFields[1] + "<br>"); // tenses
if (!mergedFields[2].equals("")) outOne.println(mergedFields[2] + "<br>"); // sanskrit
if (!mergedFields[3].equals("")) outOne.println("<b>" + mergedFields[3] + "</b><br>"); // english
if (!mergedFields[4].equals("")) outOne.println("<i>" + mergedFields[4] + "</i><br>"); // english-others
for (i=5; i<=8; i++)
{
if (!mergedFields[i].equals("")) outOne.println(mergedFields[i] + "<br>");
}
if (!mergedFields[9].equals("")) outOne.println("<i>Synonyms: </i>" + mergedFields[9] + "<br>"); // synonyms-tibetan
for (i=10; i<=13; i++)
{
if (!mergedFields[i].equals("")) outOne.println(mergedFields[i] + "<br>");
}
}
sli = llOdd.listIterator();
if (sli.hasNext())
{
outOne.println("\n<new>\nUnsorted entries start here.\n");
outOne.println("Because of errors in the entries with regards to:");
outOne.println("<ol>");
outOne.println("<li>Invalid tibetan");
outOne.println("<li>Conversion from Tibetan script to extended wylie");
outOne.println("<li>or the sorting algorithm");
outOne.println("</ol>");
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<new>\n" + mergedFields[0] + "\n");
if (!mergedFields[1].equals("")) outOne.println(mergedFields[1] + "<br>"); // tenses
if (!mergedFields[2].equals("")) outOne.println(mergedFields[2] + "<br>"); // sanskrit
if (!mergedFields[3].equals("")) outOne.println("<b>" + mergedFields[3] + "</b><br>"); // english
if (!mergedFields[4].equals("")) outOne.println("<i>" + mergedFields[4] + "</i><br>"); // english-others
for (i=5; i<=8; i++)
{
if (!mergedFields[i].equals("")) outOne.println(mergedFields[i] + "<br>");
}
if (!mergedFields[9].equals("")) outOne.println("<i>Synonyms: </i>" + mergedFields[9] + "<br>"); // synonyms-tibetan
for (i=10; i<=13; i++)
{
if (!mergedFields[i].equals("")) outOne.println(mergedFields[i] + "<br>");
}
}
case HTML:
outOne.flush(); // no break above so that both flush.
break;
case SIMPLEBREAK:
for (i=0; i<out.length; i++)
out[i].flush();
}
}
}

View file

@ -281,7 +281,7 @@ public class DuffScannerPanel extends ScannerPanel implements ItemListener
table.repaint(); table.repaint();
} }
public void setPreferences() public void setPreferences(Frame owner)
{ {
Font f; Font f;
if (prefWindow==null) prefWindow = new PreferenceWindow(this, duffInput); if (prefWindow==null) prefWindow = new PreferenceWindow(this, duffInput);

View file

@ -0,0 +1,149 @@
package org.thdl.tib.scanner;
import java.net.*;
import java.io.*;
class FilterHTMLDictionary
{
private BufferedReader in;
private PrintWriter out[];
private int currentLine;
private String linea;
private static final int GETTING_TERM=1;
private static final int GETTING_DEFINITION=2;
public FilterHTMLDictionary(BufferedReader in, PrintWriter out[])
{
this.in = in;
this.out = out;
}
public static void main (String[] args) throws Exception
{
PrintWriter out[];
BufferedReader in=null;
int argNum = args.length, currentArg=0, i;
String option;
boolean file=false, split=false;
if (argNum<=currentArg)
{
System.out.println("Syntax: FilterHTMLDictionary [-split] [input-file] [output-file1] [output-file2]");
return;
}
if (args[currentArg].charAt(0)=='-')
{
option = args[currentArg].substring(1);
currentArg++;
if (option.equals("split"))
{
split = true;
}
}
switch (args.length-currentArg)
{
case 0: out = new PrintWriter[1];
out[0] = new PrintWriter(System.out);
in = new BufferedReader(new InputStreamReader(System.in));
break;
case 1: out = new PrintWriter[1];
out[0] = new PrintWriter(System.out);
file = true;
break;
default:
if (split)
{
out = new PrintWriter[args.length-currentArg-1];
for (i=0; i<out.length; i++)
out[i] = new PrintWriter(new FileOutputStream(args[currentArg + i + 1]));
}
else
{
out = new PrintWriter[1];
out[0] = new PrintWriter(new FileOutputStream(args[currentArg + 1]));
}
file = true;
}
if (file)
{
if (args[currentArg].indexOf("http://") >= 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("<p><b>")) reportProblem("<p><b> expected.");
end = lineaLC.indexOf("</b>");
if (end<=0)
{
reportProblem("</b> 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 = "<p>Original entry: " + term + ". ";
if (ps>0) modTerm = term.substring(0, ps);
else modTerm = "";
if (pe+1<term.length()) modTerm = modTerm + term.substring(pe+1);
term = modTerm;
}
else definition = "<p>";
if (out.length==1) out[0].print(term + "\t");
else out[0].println(term.trim());
status = GETTING_DEFINITION;
definition = definition + linea.substring(end+4).trim();
continue;
case GETTING_DEFINITION:
if (lineaLC.equals(""))
{
if (out.length==1) out[0].println(definition);
else out[1].println(definition);
status = GETTING_TERM;
}
else definition = definition + " " + linea;
}
}
for (start=0; start<out.length; start++)
out[start].flush();
System.out.flush();
}
private void reportProblem(String error)
{
System.out.println("Error in line " + currentLine + ": " + linea + ". " + error);
}
}

View file

@ -312,7 +312,7 @@ public class OnLineScannerFilter extends HttpServlet
public void printText(PrintWriter pw, boolean tibetan) public void printText(PrintWriter pw, boolean tibetan)
{ {
Token words[] = scanner.getTokenArray(); Token words[] = scanner.getTokenArray();
Word word; SwingWord word;
char pm; char pm;
int i; int i;
@ -324,7 +324,7 @@ public class OnLineScannerFilter extends HttpServlet
if (words[i] instanceof Word) if (words[i] instanceof Word)
{ {
word = (Word) words[i]; word = new SwingWord((Word)words[i]);
if (word.getDefs().getDictionarySource()!=null) if (word.getDefs().getDictionarySource()!=null)
pw.print(word.getLink()); pw.print(word.getLink());
else pw.print(word.getWylie() + " "); else pw.print(word.getWylie() + " ");
@ -360,6 +360,7 @@ public class OnLineScannerFilter extends HttpServlet
{ {
int i, j; int i, j;
Word words[]; Word words[];
SwingWord word;
Definitions defs; Definitions defs;
String tag; String tag;
DictionarySource ds; DictionarySource ds;
@ -372,7 +373,8 @@ public class OnLineScannerFilter extends HttpServlet
for (j=0; j<words.length; j++) for (j=0; j<words.length; j++)
{ {
defs = words[j].getDefs(); word = new SwingWord(words[j]);
defs = word.getDefs();
ds = defs.getDictionarySource(); ds = defs.getDictionarySource();
if (ds==null) continue; if (ds==null) continue;
pw.println(" <tr>"); pw.println(" <tr>");
@ -380,7 +382,7 @@ public class OnLineScannerFilter extends HttpServlet
// else tag = null; // else tag = null;
/*if (tag!=null) /*if (tag!=null)
{*/ {*/
pw.println(" <td width=\"20%\" rowspan=\""+ defs.def.length +"\" valign=\"top\">"+ words[j].getBookmark(tibetan) +"</td>"); pw.println(" <td width=\"20%\" rowspan=\""+ defs.def.length +"\" valign=\"top\">"+ word.getBookmark(tibetan) +"</td>");
pw.println(" <td width=\"12%\">"+ tag +"</td>"); pw.println(" <td width=\"12%\">"+ tag +"</td>");
pw.println(" <td width=\"68%\">" + defs.def[0] + "</td>"); pw.println(" <td width=\"68%\">" + defs.def[0] + "</td>");
/*} /*}

View file

@ -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; i<fontNames.length; i++)
chFontNames.add(fontNames[i]);
s = WindowScannerFilter.getTHDLFontFamilyName();
if (s==null) chFontNames.select(0);
else chFontNames.select(s);
chFontNames.addItemListener(this);
p1.add(chFontNames, BorderLayout.CENTER);
p2 = new Panel(new GridLayout(1,2));
p2.add (p1);
p1 = new Panel(new BorderLayout());
p1.add(new Label("Size: "), BorderLayout.WEST);
fontSizes = new Choice();
for (i=10; i<=19; i++)
fontSizes.add(Integer.toString(i));
fontSizes.select(Integer.toString(WindowScannerFilter.getTHDLFontSize()));
fontSizes.addItemListener(this);
p1.add(fontSizes, BorderLayout.CENTER);
p2.add(p1);
setLayout(new GridLayout(4,1));
add(p2);
p1 = new Panel(new BorderLayout());
paneRows = new Choice();
for (i=1; i<=10; i++)
paneRows.add(Integer.toString(i));
paneRows.addItemListener(this);
if (landscape)
{
p1.add(new Label("Rows in output pane: "), BorderLayout.WEST);
paneRows.select(Integer.toString(WindowScannerFilter.getOutputPaneRows()));
}
else
{
p1.add(new Label("Rows in input pane: "), BorderLayout.WEST);
paneRows.select(Integer.toString(WindowScannerFilter.getInputPaneRows()));
}
p1.add(paneRows, BorderLayout.CENTER);
add(p1);
p1 = new Panel(new BorderLayout());
p1.add(new Label("Cols in parsing pane:"), BorderLayout.WEST);
parsePaneCols = new Choice();
for (i=20; i<=75; i++)
parsePaneCols.add(Integer.toString(i));
parsePaneCols.select(Integer.toString(PocketWindowScannerFilter.getParsePaneCols(landscape)));
parsePaneCols.addItemListener(this);
p1.add(parsePaneCols, BorderLayout.CENTER);
add(p1);
ok = new Button("OK");
ok.setEnabled(false);
ok.addActionListener(this);
cancel = new Button("Cancel");
cancel.addActionListener(this);
p1 = new Panel(new FlowLayout());
p1.add(ok);
p1.add(cancel);
add(p1);
}
public boolean dataInputed()
{
this.show();
return gotStuff;
}
public void actionPerformed(ActionEvent e)
{
Object obj = e.getSource();
if (obj == ok)
{
gotStuff = true;
WindowScannerFilter.setTHDLFontFamilyName(chFontNames.getSelectedItem());
WindowScannerFilter.setTHDLFontSize(Integer.parseInt(fontSizes.getSelectedItem()));
PocketWindowScannerFilter.setParsePaneCols(landscape, Integer.parseInt(parsePaneCols.getSelectedItem()));
if (landscape) WindowScannerFilter.setOutputPaneRows(Integer.parseInt(paneRows.getSelectedItem()));
else PocketWindowScannerFilter.setInputPaneRows(Integer.parseInt(paneRows.getSelectedItem()));
owner.setFont(WindowScannerFilter.getTHDLFont());
owner.repaint();
}
this.setVisible(false);
}
public void itemStateChanged(ItemEvent e)
{
ok.setEnabled(true);
}
}

View file

@ -0,0 +1,161 @@
package org.thdl.tib.scanner;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import java.io.*;
/** provides a friendly user interface when the command-line
is not used for choosing a dictionary or connection to open.
*/
class PocketWhichDictionaryFrame extends WhichDictionaryFrame
{
public PocketWhichDictionaryFrame(Frame owner)
{
super(owner);
Panel p;
CheckboxGroup cbg = new CheckboxGroup();
this.setLayout(new GridLayout(5, 1));
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
this.setSize(d);
this.add(new Label("Would you like open:"));
p = new Panel(new BorderLayout());
useOnline = new Checkbox("An on-line dict", false, cbg);
useOnline.addItemListener(this);
p.add(useOnline, BorderLayout.WEST);
availDictsOnline.add("Public");
availDictsOnline.add("Private");
p.add(availDictsOnline, BorderLayout.EAST);
this.add(p);
p = new Panel(new BorderLayout());
useOffline = new Checkbox("Local dict: ", true, cbg);
useOffline.addItemListener(this);
p.add(useOffline, BorderLayout.WEST);
p.add(localDict, BorderLayout.CENTER);
p.add(browse, BorderLayout.EAST);
this.add(p);
p = new Panel(new FlowLayout());
p.add(ok);
p.add(cancel);
this.add(p);
p = new Panel(new FlowLayout(FlowLayout.RIGHT));
ckbDefault = new Checkbox("Set as default?", true);
p.add(ckbDefault);
this.add(p);
}
public void actionPerformed(ActionEvent e)
{
Object obj = e.getSource();
FileDialog fd;
String fileName;
int pos;
if (obj == ok)
{
if (!response.equals("")) this.setVisible(false);
}
else if (obj == cancel)
{
response = "";
this.setVisible(false);
}
else if (obj == browse)
{
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);
}
}
}
/*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.
}*/
}

View file

@ -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:
<pre>255#"\Program Files\J9\PPRO10\bin\j9w.exe" "-jcl:ppro10" "-cp" "\program files\TranslationTool\DictionarySearchHandheld.jar" "org.thdl.tib.scanner.PocketWindowScannerFilter"</pre>
Can access dictionaries stored locally or remotely via the command line or
the wizard window.
@author Andr&eacute;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);
}
}

View file

@ -42,14 +42,23 @@ public class RemoteScannerFilter extends GenericServlet
ResourceBundle rb = ResourceBundle.getBundle("dictionary"); ResourceBundle rb = ResourceBundle.getBundle("dictionary");
scanner = new LocalTibetanScanner(rb.getString("onlinescannerfilter.dict-file-name")); scanner = new LocalTibetanScanner(rb.getString("onlinescannerfilter.dict-file-name"));
ds = scanner.getDictionarySource(); 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 public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException
{ {
BufferedReader br; BufferedReader br;
res.setContentType ("text/plain"); res.setContentType ("text/plain");
Token token[]; Token token[] = null;
Word word; Word word = null;
PrintWriter out = res.getWriter(); PrintWriter out = res.getWriter();
int i; int i;
String linea, dicts = req.getParameter("dicts"), dicDescrip[]; String linea, dicts = req.getParameter("dicts"), dicDescrip[];
@ -79,22 +88,52 @@ public class RemoteScannerFilter extends GenericServlet
} }
br = new BufferedReader(new InputStreamReader(req.getInputStream())); br = new BufferedReader(new InputStreamReader(req.getInputStream()));
while((linea = br.readLine())!= null) /* FIXME: sometimes getDef returns raises a NullPointerException.
scanner.scanLine(linea); In the meantime, I'll just keep it from crashing
*/
br.close(); try
{
scanner.finishUp(); while((linea = br.readLine())!= null)
token = scanner.getTokenArray(); scanner.scanLine(linea);
for (i=0; i<token.length; i++) br.close();
{
if (!(token[i] instanceof Word)) continue; scanner.finishUp();
word = (Word) token[i]; token = scanner.getTokenArray();
out.println(word.getWylie());
out.println(word.getDef()); for (i=0; i<token.length; i++)
out.println(); {
if (!(token[i] instanceof Word)) continue;
word = (Word) token[i];
out.println(word.getWylie());
out.println(word.getDef());
out.println();
}
} }
catch (Exception e)
{
ResourceBundle rb = ResourceBundle.getBundle("dictionary");
String fileName = rb.getString("remotescannerfilter.log-file-name");
Calendar rightNow = Calendar.getInstance();
PrintStream pw = new PrintStream(new FileOutputStream(fileName, true));
pw.println("Translation tool crashed on: " + rightNow.toString());
e.printStackTrace(pw);
pw.println();
pw.println("Word that crashed: " + word.getWylie());
pw.println();
pw.println("All words:");
for (i=0; i<token.length; i++)
{
if (!(token[i] instanceof Word)) continue;
word = (Word) token[i];
out.println(word.getWylie());
}
pw.println();
pw.flush();
pw.close();
}
scanner.clearTokens(); scanner.clearTokens();
out.close(); out.close();
} }

View file

@ -31,10 +31,10 @@ import java.io.*;
*/ */
public abstract class ScannerPanel extends Panel implements ActionListener public abstract class ScannerPanel extends Panel implements ActionListener
{ {
private static int dictCols=4; private static int dictCols=5;
private Label status; protected Label status;
protected Checkbox chkDicts[]; protected Checkbox chkDicts[];
Button cmdTranslate; protected Button cmdTranslate;
protected TibetanScanner scanner; protected TibetanScanner scanner;
private Panel toolBar; private Panel toolBar;
@ -49,6 +49,7 @@ public abstract class ScannerPanel extends Panel implements ActionListener
public ScannerPanel(String file, boolean includeToolBar) public ScannerPanel(String file, boolean includeToolBar)
{ {
boolean exito=true; boolean exito=true;
setFont(WindowScannerFilter.getTHDLFont());
setLayout(new BorderLayout()); setLayout(new BorderLayout());
status = new Label(); status = new Label();
@ -79,10 +80,13 @@ public abstract class ScannerPanel extends Panel implements ActionListener
{ {
if (file==null || file.equals("")) if (file==null || file.equals(""))
scanner = null; scanner = null;
else if (file.toLowerCase().startsWith("http://")) else
scanner = new RemoteTibetanScanner(file); {
if (file.toLowerCase().startsWith("http://"))
scanner = new RemoteTibetanScanner(file);
else else
scanner = new LocalTibetanScanner(file); scanner = new LocalTibetanScanner(file);
}
} }
catch (Exception e) catch (Exception e)
@ -178,16 +182,27 @@ public abstract class ScannerPanel extends Panel implements ActionListener
translate(); translate();
} }
/**Optionally overridden. */ public abstract void setPreferences(Frame owner);
public void setPreferences()
{
}
public Panel getToolBar() public Panel getToolBar()
{ {
return toolBar; return toolBar;
} }
/*public void setDefaultFont(Font f)
{
int i;
status.setFont(f);
cmdTranslate.setFont(f);
if (chkDicts!=null)
{
for (i=0; i<chkDicts.length; i++)
{
chkDicts[i].setFont(f);
}
}
}*/
public abstract void translate(); public abstract void translate();
public abstract void clear(); public abstract void clear();

View file

@ -37,19 +37,18 @@ public class SimpleScannerPanel extends ScannerPanel implements ItemListener
private List listDefs; private List listDefs;
private Word wordArray[]; private Word wordArray[];
private int lenPreview; private int lenPreview;
private static int WIDTH_PORTRAIT = 36; private boolean landscape;
private static int WIDTH_LANDSCAPE = 48;
public SimpleScannerPanel(String file, boolean landscape) public SimpleScannerPanel(String file, boolean landscape)
{ {
super(file); super(file);
Panel panel1, panel2; Panel panel1, panel2;
Font f; Font defFont;
this.landscape = landscape;
cardPanel = new Panel(new CardLayout()); cardPanel = new Panel(new CardLayout());
// FIXME values shouldn't be hardwired lenPreview = PocketWindowScannerFilter.getParsePaneCols(landscape);
if (landscape) lenPreview = WIDTH_LANDSCAPE;
else lenPreview = WIDTH_PORTRAIT;
wordArray=null; wordArray=null;
// panel1 = new Panel(new GridLayout(3, 1)); // panel1 = new Panel(new GridLayout(3, 1));
@ -59,38 +58,41 @@ public class SimpleScannerPanel extends ScannerPanel implements ItemListener
panel1 = new Panel(new BorderLayout()); panel1 = new Panel(new BorderLayout());
panel2 = new Panel(new GridLayout(2, 1)); panel2 = new Panel(new GridLayout(2, 1));
defFont = WindowScannerFilter.getTHDLFont();
txtInput = new TextArea("", 0, 0, TextArea.SCROLLBARS_VERTICAL_ONLY);
txtInput.setFont(defFont);
listDefs = new List(); listDefs = new List();
if (landscape) txtOutput = new TextArea("", 0, 0, TextArea.SCROLLBARS_VERTICAL_ONLY);
txtOutput.setFont(defFont);
if (landscape)
{ {
txtInput = new TextArea("", 0, 0, TextArea.SCROLLBARS_VERTICAL_ONLY); txtOutput.setRows(WindowScannerFilter.getOutputPaneRows());
txtOutput = new TextArea("", 4, WIDTH_LANDSCAPE,TextArea.SCROLLBARS_VERTICAL_ONLY);
panel2.add(txtInput); panel2.add(txtInput);
panel2.add(listDefs); panel2.add(listDefs);
panel1.add(panel2, BorderLayout.CENTER); panel1.add(panel2, BorderLayout.CENTER);
panel1.add(txtOutput, BorderLayout.SOUTH); panel1.add(txtOutput, BorderLayout.SOUTH);
} }
else else
{ {
txtInput = new TextArea("", 4, WIDTH_PORTRAIT, TextArea.SCROLLBARS_VERTICAL_ONLY); txtInput.setRows(WindowScannerFilter.getInputPaneRows());
txtOutput = new TextArea("",0, 0,TextArea.SCROLLBARS_VERTICAL_ONLY);
panel2.add(txtInput);
panel2.add(listDefs); panel2.add(listDefs);
panel2.add(txtOutput);
panel1.add(panel2, BorderLayout.NORTH);
panel1.add(txtInput, BorderLayout.NORTH); panel1.add(txtOutput, BorderLayout.CENTER);
panel1.add(panel2, BorderLayout.CENTER);
} }
listDefs.setMultipleMode(false); listDefs.setMultipleMode(false);
listDefs.addItemListener(this); listDefs.addItemListener(this);
txtOutput.setEditable(false); txtOutput.setEditable(false);
/*f = new Font(null, Font.PLAIN, 10);
txtOutput.setFont(f);
txtInput.setFont(f);*/
cardPanel.add(panel1, "1"); cardPanel.add(panel1, "1");
@ -164,5 +166,32 @@ public class SimpleScannerPanel extends ScannerPanel implements ItemListener
scanner.clearTokens(); scanner.clearTokens();
returnStatusToNorm(); returnStatusToNorm();
} }
} }
public void setPreferences(Frame owner)
{
PocketPreferenceWindow ppw = new PocketPreferenceWindow(owner, landscape);
Font font;
int i;
if (ppw.dataInputed())
{
lenPreview = PocketWindowScannerFilter.getParsePaneCols(landscape);
font = WindowScannerFilter.getTHDLFont();
if (landscape) txtOutput.setRows(WindowScannerFilter.getOutputPaneRows());
else txtInput.setRows(WindowScannerFilter.getInputPaneRows());
status.setFont(font);
cmdTranslate.setFont(font);
txtInput.setFont(font);
listDefs.setFont(font);
txtOutput.setFont(font);
for (i=0; i<chkDicts.length; i++)
chkDicts[i].setFont(font);
setFont(font);
owner.setFont(font);
validate();
owner.validate();
}
ppw.dispose();
}
} }

View file

@ -0,0 +1,26 @@
package org.thdl.tib.scanner;
import org.thdl.tib.text.*;
class SortingTibetanEntry implements Comparable
{
private String fields[];
private TibetanString header;
public SortingTibetanEntry (String header, String fields[])
{
this.header = new TibetanString(header);
this.fields = fields;
}
public int compareTo(Object o)
{
SortingTibetanEntry ste = (SortingTibetanEntry)o;
return header.compareTo(ste.header);
}
public String[] get()
{
return fields;
}
}

View file

@ -0,0 +1,159 @@
package org.thdl.tib.scanner;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import java.io.*;
import javax.swing.*;
/** provides a friendly user interface when the command-line
is not used for choosing a dictionary or connection to open.
*/
class SwingWhichDictionaryFrame extends WhichDictionaryFrame
{
private CreateDatabaseWizard cdw;
private DictionaryFileFilter dicFilter;
private Checkbox createNewDictDB;
public SwingWhichDictionaryFrame(Frame owner)
{
super(owner);
Panel p;
CheckboxGroup cbg = new CheckboxGroup();
dicFilter = null;
this.setLayout(new GridLayout(6, 1));
this.setSize(400, 200);
this.add(new Label("Would you like to:"));
p = new Panel(new BorderLayout());
useOnline = new Checkbox("Access an on-line dictionary", false, cbg);
useOnline.addItemListener(this);
p.add(useOnline, BorderLayout.WEST);
availDictsOnline.add("Public version");
availDictsOnline.add("Private version (only within UVa)");
p.add(availDictsOnline, BorderLayout.EAST);
this.add(p);
p = new Panel(new BorderLayout());
useOffline = new Checkbox("Access a local dictionary: ", true, cbg);
useOffline.addItemListener(this);
p.add(useOffline, BorderLayout.WEST);
p.add(localDict, BorderLayout.CENTER);
p.add(browse, BorderLayout.EAST);
this.add(p);
createNewDictDB = new Checkbox("Create a new dictionary...", false, cbg);
createNewDictDB.addItemListener(this);
this.add(createNewDictDB);
p = new Panel(new FlowLayout());
p.add(ok);
p.add(cancel);
this.add(p);
p = new Panel(new FlowLayout(FlowLayout.RIGHT));
ckbDefault = new Checkbox("Use these settings as default", true);
p.add(ckbDefault);
this.add(p);
}
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);
cdw.show();
response = cdw.getResponse();
}
if (!response.equals("")) this.setVisible(false);
}
else if (obj == cancel)
{
response = "";
this.setVisible(false);
}
else if (obj == browse)
{
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);
}
}
}
/** 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];
}
}
}

View file

@ -0,0 +1,385 @@
/*
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 javax.swing.text.*;
import javax.swing.*;
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:</p>
<pre>java -jar DictionarySearchStandalone.jar http://iris.lib.virginia.edu/tibetan/servlet/org.thdl.tib.scanner.RemoteScannerFilter</pre>
<p>If the JRE you installed does not support <i> Swing</i> classes but supports
<i>
AWT</i> (as the JRE for handhelds), run the command: </p>
<pre>java -jar DictionarySearchHandheld.jar -simple ry-dic99</pre>
@author Andr&eacute;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);
}
}

View file

@ -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&eacute;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 = "<b>" + super.token + "</b>";
}
}
else localWord = "<b>" + super.token + "</b>";
return "<a name=\"" + super.token + "\">" + localWord + "</a>";
}
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 = "<a href=\"#" + word + "\">" + localWord;
if (tibetan) result+= "</a>";
else result+= "</a> ";
return result;*/
return "<a href=\"#" + super.token + "\">" + result + "</a> ";
}
}

View file

@ -25,7 +25,7 @@ import org.thdl.util.*;
*/ */
public abstract class TibetanScanner 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 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 copyrightASCII="Copyright 2000-2004 by Andres Montano Pellegrini, all rights reserved.";
public static final String copyrightHTML="<hr><small><strong>" + version + "Copyright &copy; 2000-2004 by <a href=\"http://www.people.virginia.edu/~am2zb/\" target=\"_blank\">Andr&eacute;s Montano Pellegrini.</a><br/>All rights reserved.</strong></small>"; public static final String copyrightHTML="<hr><small><strong>" + version + "Copyright &copy; 2000-2004 by <a href=\"http://www.people.virginia.edu/~am2zb/\" target=\"_blank\">Andr&eacute;s Montano Pellegrini.</a><br/>All rights reserved.</strong></small>";

View file

@ -9,218 +9,70 @@ import javax.swing.*;
/** provides a friendly user interface when the command-line /** provides a friendly user interface when the command-line
is not used for choosing a dictionary or connection to open. 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; protected String response;
private int dictType; protected int dictType;
private Button ok, cancel; protected Button ok, cancel;
private Checkbox useOnline, useOffline, createNewDictDB; protected Checkbox useOnline, useOffline;
private Choice availDictsOnline; protected Choice availDictsOnline;
private Label localDict; protected Label localDict;
private Button browse; protected Button browse;
private Frame owner; protected Frame owner;
private boolean pocketpc; protected String dictsOnline[], dictTypes[];
private DictionaryFileFilter dicFilter; protected Checkbox ckbDefault;
private String dictsOnline[], dictTypes[];
private Checkbox ckbDefault;
private CreateDatabaseWizard cdw;
public WhichDictionaryFrame(Frame owner, boolean pocketpc) public WhichDictionaryFrame(Frame owner)
{ {
super(owner, "Welcome to the Tibetan to English Translation Tool", true); 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)); this.owner = owner;
if (pocketpc) response="";
{
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:"));
// FIXME: values should not be hardwired // FIXME: values should not be hardwired
dictsOnline = new String[2]; 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"; 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"; 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!)"); //availDictsOnline.add("Local (only on my computer!)");
//dictsOnline[2] = "http://localhost:8080/tibetan/servlet/org.thdl.tib.scanner.RemoteScannerFilter";
availDictsOnline.addItemListener(this); availDictsOnline.addItemListener(this);
availDictsOnline.setEnabled(false); 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 = new Label();
localDict.setEnabled(true); localDict.setEnabled(true);
p.add(localDict, BorderLayout.CENTER);
dictTypes[2] = "local";
dictType = 2;
dictType = 2;
browse = new Button("Browse..."); browse = new Button("Browse...");
browse.setEnabled(true); browse.setEnabled(true);
browse.addActionListener(this); 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 = new Button("Ok");
ok.setEnabled(false); ok.setEnabled(false);
ok.addActionListener(this); ok.addActionListener(this);
cancel = new Button("Cancel"); cancel = new Button("Cancel");
cancel.addActionListener(this); cancel.addActionListener(this);
p.add(ok);
p.add(cancel); useOnline=null;
this.add(p); useOffline=null;
p = new Panel(new FlowLayout(FlowLayout.RIGHT)); ckbDefault=null;
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);
} }
public void actionPerformed(ActionEvent e) public abstract 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);
}
}
}
}
/** Implement the disabling of other guys here /** Implement the disabling of other guys here
*/ */
public void itemStateChanged(ItemEvent e) public abstract 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 String getResponse() public String getResponse()
{ {
return response; return response;

View file

@ -25,41 +25,40 @@ import java.awt.event.*;
import java.applet.Applet; import java.applet.Applet;
import java.awt.*; import java.awt.*;
import java.awt.datatransfer.*; import java.awt.datatransfer.*;
import javax.swing.text.JTextComponent;
import javax.swing.JOptionPane;
import org.thdl.tib.input.*;
import org.thdl.util.*; import org.thdl.util.*;
/** Provides a graphical interfase to input Tibetan text (Roman or /** Provides a graphical interfase to input Tibetan text (Roman or
Tibetan script) and displays the words (Roman or Tibetan script) Tibetan script) and displays the words (Roman or Tibetan script)
with their definitions. Works without Tibetan script in with their definitions. Works without Tibetan script in
platforms that don't support Swing. Can access dictionaries stored platforms that don't support Swing. Can access dictionaries stored
locally or remotely. For example, to access the public dictionary database run the command:</p> locally or remotely. It is not meant to be run alone, but through one
<pre>java -jar DictionarySearchStandalone.jar http://iris.lib.virginia.edu/tibetan/servlet/org.thdl.tib.scanner.RemoteScannerFilter</pre> of the inherited childs. Use SwingWindowScannerFilter for platforms
<p>If the JRE you installed does not support <i> Swing</i> classes but supports that support swing. Use PockeWindowScannerFilter for platforms that
<i> support awt but not swing.
AWT</i> (as the JRE for handhelds), run the command: </p>
<pre>java -jar DictionarySearchHandheld.jar -simple ry-dic99</pre>
@author Andr&eacute;s Montano Pellegrini @author Andr&eacute;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"; protected static String defOpenOption = "thdl.scanner.default.open";
private static String dictOpenType = "thdl.scanner.default.type"; 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; protected ScannerPanel sp;
private MenuItem mnuExit, mnuCut, mnuCopy, mnuPaste, mnuDelete, mnuSelectAll, mnuAbout, mnuClear, mnuOpen, mnuPreferences, mnuSavePref; protected MenuItem mnuExit, mnuCut, mnuCopy, mnuPaste, mnuDelete, mnuSelectAll, mnuAbout, mnuClear, mnuOpen, mnuPreferences, mnuSavePref;
private CheckboxMenuItem mnuDicts; protected CheckboxMenuItem mnuDicts;
private Object objModified; protected Object objModified;
private AboutDialog diagAbout; protected AboutDialog diagAbout;
private Frame mainWindow; protected Frame mainWindow;
private boolean pocketpc;
/** This class is not meant to be called by itself */
public WindowScannerFilter(boolean pocketpc) public WindowScannerFilter()
{ {
String response, dictType; String response, dictType;
this.pocketpc = pocketpc; WhichDictionaryFrame wdf;
response = ThdlOptions.getStringOption(defOpenOption); response = ThdlOptions.getStringOption(defOpenOption);
@ -68,11 +67,16 @@ public class WindowScannerFilter implements WindowListener, FocusListener, Actio
mainWindow = new Frame("Tibetan Translation Tool"); mainWindow = new Frame("Tibetan Translation Tool");
mainWindow.show(); mainWindow.show();
mainWindow.toFront(); mainWindow.toFront();
WhichDictionaryFrame wdf = new WhichDictionaryFrame(mainWindow, pocketpc);
wdf = getWhichDictionaryFrame();
wdf.show(); response = wdf.getResponse();
response = wdf.getResponse(); wdf.dispose();
if (response.equals("")) System.exit(0);
if (response.equals(""))
{
mainWindow.dispose();
System.exit(0);
}
else else
{ {
dictType = wdf.getDictionaryType(); dictType = wdf.getDictionaryType();
@ -92,198 +96,17 @@ public class WindowScannerFilter implements WindowListener, FocusListener, Actio
} }
} }
makeWindow (response); makeWindow (response);
} }
public WindowScannerFilter()
{
this(false);
}
public WindowScannerFilter(String file) public WindowScannerFilter(String file)
{ {
pocketpc = false;
mainWindow = null; mainWindow = null;
makeWindow (file); makeWindow (file);
} }
public WindowScannerFilter(String file, boolean pocketpc) protected abstract WhichDictionaryFrame getWhichDictionaryFrame();
{ protected abstract void makeWindow(String file);
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)
{
}
}
}
}
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 * Cierra la ventana. Invocado unicamente cuando el programa corre
* como aplicacion, para que el programa pare su ejecucion cuando * 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) public void windowClosing(WindowEvent e)
{ {
sp.closingRemarks(); sp.closingRemarks();
mainWindow.dispose();
System.exit(0); System.exit(0);
} }
@ -364,33 +188,7 @@ public class WindowScannerFilter implements WindowListener, FocusListener, Actio
/** Added to update the Edit menu in dependence upon /** Added to update the Edit menu in dependence upon
which textbox the keyboard focus is at. which textbox the keyboard focus is at.
*/ */
public void focusGained(FocusEvent e) public abstract 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);
}
/** Added to update the Edit menu in dependence upon /** Added to update the Edit menu in dependence upon
which textbox the keyboard focus is at. which textbox the keyboard focus is at.
@ -405,146 +203,59 @@ public class WindowScannerFilter implements WindowListener, FocusListener, Actio
mnuSelectAll.setEnabled(false); mnuSelectAll.setEnabled(false);
} }
/* FIXME: what happens if this throws an exception? We'll just public abstract void actionPerformed(ActionEvent event);
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 void itemStateChanged(ItemEvent e) public void itemStateChanged(ItemEvent e)
{ {
sp.setWylieInput(e.getStateChange()!=ItemEvent.SELECTED); 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());
}
} }

View file

@ -20,7 +20,7 @@ Contributor(s): ______________________________________.
to store the dictionary. */ to store the dictionary. */
package org.thdl.tib.scanner; package org.thdl.tib.scanner;
import org.thdl.tib.text.TibetanHTML; //import org.thdl.tib.text.TibetanHTML;
/** Tibetan word with its corresponding definitions. /** Tibetan word with its corresponding definitions.
@ -29,8 +29,13 @@ import org.thdl.tib.text.TibetanHTML;
public class Word extends Token public class Word extends Token
{ {
/** Used to rebuild the text the user entered. */ /** Used to rebuild the text the user entered. */
private String wordSinDec; protected String wordSinDec;
private Definitions def; protected Definitions def;
public Word (Word word)
{
this(word.token, word.wordSinDec, word.def);
}
public Word (String word, String wordSinDec, String def) public Word (String word, String wordSinDec, String def)
{ {
@ -97,54 +102,6 @@ public class Word extends Token
{ {
return super.token + " - " + def; return super.token + " - " + def;
} }
public String getBookmark(boolean tibetan)
{
String localWord;
if (tibetan)
{
try
{
localWord = TibetanHTML.getHTML(super.token + " ");
}
catch (Exception e)
{
localWord = "<b>" + super.token + "</b>";
}
}
else localWord = "<b>" + super.token + "</b>";
return "<a name=\"" + super.token + "\">" + localWord + "</a>";
}
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 = "<a href=\"#" + word + "\">" + localWord;
if (tibetan) result+= "</a>";
else result+= "</a> ";
return result;*/
return "<a href=\"#" + super.token + "\">" + result + "</a> ";
}
/** Called in order to redisplay the text with links keeping /** Called in order to redisplay the text with links keeping
the returns the user entered. the returns the user entered.