Added a wizard window to avoid as much as possible using the command line.
This way through clicking on the application through the wizard one can choose to connect to the available on-line dicts, open a local dict or generate a dict database.
This commit is contained in:
parent
4caeafa1b1
commit
cce779bf88
6 changed files with 718 additions and 86 deletions
|
@ -152,11 +152,9 @@ public class BinaryFileGenerator extends SimplifiedLinkedList
|
|||
{
|
||||
private long posHijos;
|
||||
private String sil, def[];
|
||||
private static String delimiter;
|
||||
private static int delimiterType;
|
||||
private final static int delimiterGeneric=0;
|
||||
private final static int delimiterAcip=1;
|
||||
private final static int delimiterDash=2;
|
||||
public final static int delimiterGeneric=0;
|
||||
public final static int delimiterAcip=1;
|
||||
public final static int delimiterDash=2;
|
||||
|
||||
/** Number of dictionary. If 0, partial word (no definition).
|
||||
*/
|
||||
|
@ -168,8 +166,6 @@ public class BinaryFileGenerator extends SimplifiedLinkedList
|
|||
{
|
||||
wordRaf = null;
|
||||
defRaf = null;
|
||||
delimiter = null;
|
||||
delimiterType=delimiterDash;
|
||||
}
|
||||
|
||||
public BinaryFileGenerator()
|
||||
|
@ -181,7 +177,7 @@ public class BinaryFileGenerator extends SimplifiedLinkedList
|
|||
sourceDef = null;
|
||||
}
|
||||
|
||||
public BinaryFileGenerator(String sil, String def, int numDef)
|
||||
private BinaryFileGenerator(String sil, String def, int numDef)
|
||||
{
|
||||
super();
|
||||
int marker = sil.indexOf(" ");
|
||||
|
@ -208,18 +204,18 @@ public class BinaryFileGenerator extends SimplifiedLinkedList
|
|||
return sil;
|
||||
}
|
||||
|
||||
private static String deleteQuotes(String s)
|
||||
private static String deleteQuotes(String s)
|
||||
{
|
||||
int length = s.length();
|
||||
if (length>2)
|
||||
{
|
||||
int length = s.length();
|
||||
if (length>2)
|
||||
{
|
||||
if ((s.charAt(0)=='\"') && (s.charAt(length-1)=='\"'))
|
||||
return s.substring(1,length-2);
|
||||
}
|
||||
return s;
|
||||
if ((s.charAt(0)=='\"') && (s.charAt(length-1)=='\"'))
|
||||
return s.substring(1,length-1);
|
||||
}
|
||||
|
||||
public void addFile(String archivo, int defNum) throws Exception
|
||||
return s;
|
||||
}
|
||||
|
||||
public void addFile(String archivo, int delimiterType, String delimiter, int defNum) throws Exception
|
||||
{
|
||||
final short newDefiniendum=1, halfDefiniendum=2, definition=3;
|
||||
short status=newDefiniendum;
|
||||
|
@ -671,11 +667,30 @@ public class BinaryFileGenerator extends SimplifiedLinkedList
|
|||
System.out.println(" -acip: use this to process dictionaries entered using the ACIP standard");
|
||||
System.out.println(" to mark page numbers, comments, etc. Make sure to convert it to");
|
||||
System.out.println(" THDL's extended Wylie scheme first using the AcipToWylie class.");
|
||||
}
|
||||
|
||||
public void generateDatabase(String name) throws Exception
|
||||
{
|
||||
File wordF = new File(name + ".wrd"), defF = new File(name + ".def");
|
||||
wordF.delete();
|
||||
defF.delete();
|
||||
wordRaf = new RandomAccessFile(wordF,"rw");
|
||||
defRaf = new RandomAccessFile(defF,"rw");
|
||||
print();
|
||||
wordRaf.writeInt((int)posHijos);
|
||||
|
||||
}
|
||||
|
||||
public static void main(String args[]) throws Exception
|
||||
{
|
||||
int i, n=0, a;
|
||||
int delimiterType;
|
||||
String delimiter;
|
||||
|
||||
int i, n=0, a;
|
||||
|
||||
delimiter = null;
|
||||
delimiterType=delimiterDash;
|
||||
|
||||
if (args.length==0)
|
||||
{
|
||||
printSintax();
|
||||
|
@ -701,7 +716,7 @@ public class BinaryFileGenerator extends SimplifiedLinkedList
|
|||
printSintax();
|
||||
return;
|
||||
}
|
||||
sl.addFile(args[1] + ".txt",0);
|
||||
sl.addFile(args[1] + ".txt",delimiterType, delimiter, 0);
|
||||
a=1;
|
||||
}
|
||||
else
|
||||
|
@ -709,7 +724,7 @@ public class BinaryFileGenerator extends SimplifiedLinkedList
|
|||
a=0;
|
||||
if (args.length==1)
|
||||
{
|
||||
sl.addFile(args[0] + ".txt",0);
|
||||
sl.addFile(args[0] + ".txt", delimiterType, delimiter, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -737,17 +752,11 @@ public class BinaryFileGenerator extends SimplifiedLinkedList
|
|||
{
|
||||
delimiterType=delimiterDash;
|
||||
}
|
||||
sl.addFile(args[i] + ".txt", n);
|
||||
sl.addFile(args[i] + ".txt", delimiterType, delimiter, n);
|
||||
n++; i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
File wordF = new File(args[a] + ".wrd"), defF = new File(args[a] + ".def");
|
||||
wordF.delete();
|
||||
defF.delete();
|
||||
wordRaf = new RandomAccessFile(wordF,"rw");
|
||||
defRaf = new RandomAccessFile(defF,"rw");
|
||||
sl.print();
|
||||
wordRaf.writeInt((int)sl.posHijos);
|
||||
sl.generateDatabase(args[a]);
|
||||
}
|
||||
}
|
||||
|
|
259
source/org/thdl/tib/scanner/CreateDatabaseWizard.java
Normal file
259
source/org/thdl/tib/scanner/CreateDatabaseWizard.java
Normal file
|
@ -0,0 +1,259 @@
|
|||
package org.thdl.tib.scanner;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.io.*;
|
||||
import org.thdl.util.*;
|
||||
import org.thdl.tib.scanner.*;
|
||||
import javax.swing.*;
|
||||
|
||||
class CreateDatabaseWizard extends Dialog implements ActionListener, ItemListener
|
||||
{
|
||||
private Label dictNum;
|
||||
private int numDict, delimiterType;
|
||||
private Label fileName;
|
||||
private TextField dicDesc, dicAbb, delimiter;
|
||||
private Choice dicType;
|
||||
private List listDicts;
|
||||
private Button add, ok, cancel, browse;
|
||||
private Frame owner;
|
||||
private SimplifiedLinkedList dicts;
|
||||
private boolean pocketpc;
|
||||
private String response;
|
||||
|
||||
CreateDatabaseWizard(Frame owner, boolean pocketpc)
|
||||
{
|
||||
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);
|
||||
Panel p1, p2, p3;
|
||||
p1 = new Panel(new GridLayout(4, 1));
|
||||
p2 = new Panel(new FlowLayout(FlowLayout.LEFT));
|
||||
p2.add(new Label("Dictionary "));
|
||||
numDict = 1;
|
||||
dictNum = new Label(Integer.toString(numDict));
|
||||
p2.add(dictNum);
|
||||
p2.add(new Label(":"));
|
||||
p1.add(p2);
|
||||
p2 = new Panel(new BorderLayout());
|
||||
p2.add(new Label("File name:"), BorderLayout.WEST);
|
||||
fileName = new Label();
|
||||
p2.add(fileName, BorderLayout.CENTER);
|
||||
browse = new Button("Browse...");
|
||||
browse.addActionListener(this);
|
||||
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);
|
||||
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:"));
|
||||
dicAbb = new TextField(6);
|
||||
p3.add(dicAbb);
|
||||
p2.add(p3, BorderLayout.EAST);
|
||||
p1.add(p2);
|
||||
p2 = new Panel(new BorderLayout());
|
||||
p2.add(new Label("Type:"), BorderLayout.WEST);
|
||||
dicType = new Choice();
|
||||
dicType.add("Dash separated");
|
||||
dicType.add("Tab separated");
|
||||
dicType.add("Transcribed ACIP");
|
||||
dicType.add("Other:");
|
||||
dicType.addItemListener(this);
|
||||
p2.add(dicType, BorderLayout.CENTER);
|
||||
p3 = new Panel(new FlowLayout());
|
||||
delimiter = new TextField(" - ");
|
||||
delimiter.setEnabled(false);
|
||||
p3.add(delimiter);
|
||||
add = new Button("Add");
|
||||
add.setEnabled(false);
|
||||
add.addActionListener(this);
|
||||
p3.add(add);
|
||||
p2.add(p3, BorderLayout.EAST);
|
||||
p1.add(p2);
|
||||
this.add(p1, BorderLayout.NORTH);
|
||||
listDicts = new List();
|
||||
this.add(listDicts, BorderLayout.CENTER);
|
||||
|
||||
p1 = new Panel(new FlowLayout());
|
||||
ok = new Button("Generate database");
|
||||
ok.addActionListener(this);
|
||||
ok.setEnabled(false);
|
||||
p1.add(ok);
|
||||
cancel = new Button("Cancel");
|
||||
cancel.addActionListener(this);
|
||||
p1.add(cancel);
|
||||
this.add(p1, BorderLayout.SOUTH);
|
||||
}
|
||||
|
||||
public void actionPerformed(ActionEvent event)
|
||||
{
|
||||
FileDialog fd;
|
||||
DictionaryRecord dr;
|
||||
Button obj = (Button) event.getSource();
|
||||
String fileName, path="";
|
||||
int pos;
|
||||
|
||||
if (obj == cancel)
|
||||
{
|
||||
this.setVisible(false);
|
||||
}
|
||||
if (obj == browse)
|
||||
{
|
||||
fd = new FileDialog(owner, "Select dictionary to open", FileDialog.LOAD);
|
||||
fd.show();
|
||||
fileName = fd.getFile();
|
||||
if (fileName != null)
|
||||
{
|
||||
path = fd.getDirectory() + fileName;
|
||||
this.fileName.setText(path);
|
||||
// strip extension
|
||||
pos = fileName.lastIndexOf('.');
|
||||
if (pos>0) fileName = fileName.substring(0, pos);
|
||||
this.dicDesc.setText(fileName);
|
||||
if (fileName.length()>4) this.dicAbb.setText(fileName.substring(0,4));
|
||||
else this.dicAbb.setText(fileName);
|
||||
add.setEnabled(true);
|
||||
}
|
||||
}
|
||||
else if (obj == add)
|
||||
{
|
||||
dr = new DictionaryRecord(dicDesc.getText()+ "," + dicAbb.getText(), this.fileName.getText(), delimiterType, delimiter.getText());
|
||||
listDicts.add(dr.header + " - " + dicType.getSelectedItem() + "; " + dr.fileName);
|
||||
ok.setEnabled(true);
|
||||
numDict++;
|
||||
dictNum.setText(Integer.toString(numDict));
|
||||
dicts.addLast(dr);
|
||||
|
||||
dicDesc.setText("");
|
||||
dicAbb.setText("");
|
||||
this.fileName.setText("");
|
||||
|
||||
add.setEnabled(false);
|
||||
}
|
||||
else if (obj == ok)
|
||||
{
|
||||
BinaryFileGenerator bfg = new BinaryFileGenerator();
|
||||
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));
|
||||
|
||||
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;
|
||||
Object dictsArray[] = dicts.toArray();
|
||||
try
|
||||
{
|
||||
pr = new PrintWriter(new FileOutputStream(path + ".dic"));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
}
|
||||
|
||||
for (pos=0; pos<dictsArray.length; pos++)
|
||||
{
|
||||
dr = (DictionaryRecord) dictsArray[pos];
|
||||
if (dr.delimiterType==BinaryFileGenerator.delimiterAcip)
|
||||
{
|
||||
try
|
||||
{
|
||||
a2w = new AcipToWylie(new BufferedReader(new InputStreamReader(new FileInputStream(dr.fileName))), new PrintWriter(new FileOutputStream(dr.fileName + ".temp")));
|
||||
a2w.run();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
}
|
||||
|
||||
dr.fileName = dr.fileName + ".temp";
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
bfg.addFile(dr.fileName, dr.delimiterType, dr.delimiter, pos);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
}
|
||||
|
||||
pr.println(dr.header);
|
||||
}
|
||||
pr.flush();
|
||||
|
||||
try
|
||||
{
|
||||
bfg.generateDatabase(path);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
}
|
||||
response = path;
|
||||
this.setVisible(false);
|
||||
}
|
||||
}
|
||||
|
||||
public void itemStateChanged(ItemEvent e)
|
||||
{
|
||||
Choice ch = (Choice) e.getSource();
|
||||
int sel = ch.getSelectedIndex();
|
||||
|
||||
switch (sel)
|
||||
{
|
||||
case 0: delimiterType = BinaryFileGenerator.delimiterDash;
|
||||
break;
|
||||
case 1: delimiterType = BinaryFileGenerator.delimiterGeneric;
|
||||
delimiter.setText("\t");
|
||||
break;
|
||||
case 2: delimiterType = BinaryFileGenerator.delimiterAcip;
|
||||
break;
|
||||
case 3: delimiterType = BinaryFileGenerator.delimiterGeneric;
|
||||
delimiter.setEnabled(true);
|
||||
}
|
||||
}
|
||||
|
||||
public String getResponse()
|
||||
{
|
||||
return response;
|
||||
}
|
||||
}
|
38
source/org/thdl/tib/scanner/DictionaryFileFilter.java
Normal file
38
source/org/thdl/tib/scanner/DictionaryFileFilter.java
Normal file
|
@ -0,0 +1,38 @@
|
|||
package org.thdl.tib.scanner;
|
||||
|
||||
import java.io.*;
|
||||
import javax.swing.filechooser.*;
|
||||
|
||||
class DictionaryFileFilter extends javax.swing.filechooser.FileFilter
|
||||
{
|
||||
public DictionaryFileFilter()
|
||||
{
|
||||
}
|
||||
|
||||
public boolean accept(File file)
|
||||
{
|
||||
if (file.isDirectory())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
String fName = file.getName();
|
||||
int i = fName.lastIndexOf('.');
|
||||
|
||||
if (i < 0)
|
||||
return false;
|
||||
else
|
||||
{
|
||||
String ext = fName.substring(i+1).toLowerCase();
|
||||
if (ext.equals("wrd"))
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
public String getDescription()
|
||||
{
|
||||
return "Binary tree dictionary (.wrd)";
|
||||
}
|
||||
}
|
18
source/org/thdl/tib/scanner/DictionaryRecord.java
Normal file
18
source/org/thdl/tib/scanner/DictionaryRecord.java
Normal file
|
@ -0,0 +1,18 @@
|
|||
package org.thdl.tib.scanner;
|
||||
|
||||
/** Wrapping class
|
||||
*/
|
||||
class DictionaryRecord
|
||||
{
|
||||
public String header, fileName, delimiter;
|
||||
public int delimiterType;
|
||||
|
||||
public DictionaryRecord(String header, String fileName, int delimiterType, String delimiter)
|
||||
{
|
||||
this.header = header;
|
||||
this.fileName = fileName;
|
||||
this.delimiterType = delimiterType;
|
||||
this.delimiter = delimiter;
|
||||
|
||||
}
|
||||
}
|
218
source/org/thdl/tib/scanner/WhichDictionaryFrame.java
Normal file
218
source/org/thdl/tib/scanner/WhichDictionaryFrame.java
Normal file
|
@ -0,0 +1,218 @@
|
|||
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 WhichDictionaryFrame extends Dialog implements ActionListener, ItemListener
|
||||
{
|
||||
private String response;
|
||||
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[];
|
||||
private Checkbox ckbDefault;
|
||||
private CreateDatabaseWizard cdw;
|
||||
|
||||
public WhichDictionaryFrame(Frame owner, boolean pocketpc)
|
||||
{
|
||||
super(owner, "Welcome to the Tibetan to English Translation Tool", true);
|
||||
this.owner = owner;
|
||||
this.pocketpc = pocketpc;
|
||||
dicFilter = null;
|
||||
response="";
|
||||
Panel p;
|
||||
CheckboxGroup cbg = new CheckboxGroup();
|
||||
|
||||
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:"));
|
||||
|
||||
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);
|
||||
|
||||
// FIXME: values should not be hardwired
|
||||
dictsOnline = new String[2];
|
||||
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";
|
||||
|
||||
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";
|
||||
|
||||
//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);
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** 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);
|
||||
response = dictsOnline[availDictsOnline.getSelectedIndex()];
|
||||
}
|
||||
else if (chx == useOffline)
|
||||
{
|
||||
localDict.setEnabled(true);
|
||||
browse.setEnabled(true);
|
||||
if (availDictsOnline!=null) availDictsOnline.setEnabled(false);
|
||||
ok.setEnabled(!localDict.getText().equals(""));
|
||||
response = localDict.getText();
|
||||
}
|
||||
else if (chx == createNewDictDB)
|
||||
{
|
||||
localDict.setEnabled(false);
|
||||
browse.setEnabled(false);
|
||||
if (availDictsOnline!=null) availDictsOnline.setEnabled(false);
|
||||
ok.setEnabled(true);
|
||||
response="";
|
||||
}
|
||||
}
|
||||
else if (obj instanceof Choice)
|
||||
{
|
||||
Choice ch = (Choice) obj;
|
||||
response = dictsOnline[ch.getSelectedIndex()];
|
||||
}
|
||||
}
|
||||
|
||||
public String getResponse()
|
||||
{
|
||||
return response;
|
||||
}
|
||||
|
||||
public boolean getDefaultOption()
|
||||
{
|
||||
return ckbDefault.getState();
|
||||
}
|
||||
}
|
|
@ -28,6 +28,7 @@ import java.awt.datatransfer.*;
|
|||
import javax.swing.text.JTextComponent;
|
||||
import javax.swing.JOptionPane;
|
||||
import org.thdl.tib.input.DuffPane;
|
||||
import org.thdl.util.*;
|
||||
|
||||
/** Provides a graphical interfase to input Tibetan text (Roman or
|
||||
Tibetan script) and displays the words (Roman or Tibetan script)
|
||||
|
@ -44,35 +45,91 @@ import org.thdl.tib.input.DuffPane;
|
|||
*/
|
||||
public class WindowScannerFilter implements WindowListener, FocusListener, ActionListener, ItemListener
|
||||
{
|
||||
private static String defOpenOption = "thdl.scanner.default.open";
|
||||
|
||||
private ScannerPanel sp;
|
||||
private MenuItem mnuExit, mnuCut, mnuCopy, mnuPaste, mnuDelete, mnuSelectAll, mnuAbout, mnuClear;
|
||||
private MenuItem mnuExit, mnuCut, mnuCopy, mnuPaste, mnuDelete, mnuSelectAll, mnuAbout, mnuClear, mnuOpen;
|
||||
private CheckboxMenuItem tibScript, mnuDicts;
|
||||
private Object objModified;
|
||||
private Frame frame;
|
||||
private Dialog diagAbout;
|
||||
private boolean usingSwing;
|
||||
private AboutDialog diagAbout;
|
||||
private Frame mainWindow;
|
||||
private boolean pocketpc;
|
||||
|
||||
public WindowScannerFilter(boolean pocketpc)
|
||||
{
|
||||
String response;
|
||||
this.pocketpc = pocketpc;
|
||||
|
||||
if (!pocketpc) response = ThdlOptions.getStringOption(defOpenOption);
|
||||
else response=null;
|
||||
if (response==null || response.equals(""))
|
||||
{
|
||||
mainWindow = new Frame("Tibetan Scanner");
|
||||
mainWindow.show();
|
||||
mainWindow.toFront();
|
||||
WhichDictionaryFrame wdf = new WhichDictionaryFrame(mainWindow, pocketpc);
|
||||
|
||||
wdf.show();
|
||||
response = wdf.getResponse();
|
||||
if (response.equals("")) System.exit(0);
|
||||
else
|
||||
{
|
||||
if (!pocketpc && wdf.getDefaultOption())
|
||||
{
|
||||
ThdlOptions.setUserPreference(defOpenOption, response);
|
||||
try
|
||||
{
|
||||
ThdlOptions.saveUserPreferences();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
makeWindow (response);
|
||||
}
|
||||
|
||||
public WindowScannerFilter()
|
||||
{
|
||||
this(false);
|
||||
}
|
||||
|
||||
public WindowScannerFilter(String file)
|
||||
{
|
||||
this (file, false);
|
||||
pocketpc = false;
|
||||
mainWindow = null;
|
||||
makeWindow (file);
|
||||
}
|
||||
|
||||
public WindowScannerFilter(String file, boolean ipaq)
|
||||
|
||||
public WindowScannerFilter(String file, boolean pocketpc)
|
||||
{
|
||||
frame = new Frame("Tibetan Scanner");
|
||||
frame.setLayout(new GridLayout(1,1));
|
||||
frame.setBackground(Color.white);
|
||||
this.pocketpc = pocketpc;
|
||||
mainWindow = null;
|
||||
makeWindow (file);
|
||||
}
|
||||
|
||||
public void makeWindow(String file)
|
||||
{
|
||||
if (mainWindow==null) mainWindow = new Frame("Tibetan Scanner");
|
||||
else mainWindow.setVisible(false);
|
||||
mainWindow.setLayout(new GridLayout(1,1));
|
||||
mainWindow.setBackground(Color.white);
|
||||
|
||||
diagAbout = null;
|
||||
usingSwing=!ipaq;
|
||||
mnuAbout = null;
|
||||
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
|
||||
|
||||
if (usingSwing)
|
||||
if (!pocketpc)
|
||||
sp = new DuffScannerPanel(file);
|
||||
else
|
||||
sp = new SimpleScannerPanel(file, d.width >d.height);
|
||||
|
||||
MenuBar mb = new MenuBar();
|
||||
Menu m = new Menu ("File");
|
||||
Menu m = new Menu ("File");
|
||||
mnuOpen = new MenuItem("Open...");
|
||||
mnuOpen.addActionListener(this);
|
||||
m.add(mnuOpen);
|
||||
mnuExit = new MenuItem("Exit");
|
||||
mnuExit.addActionListener(this);
|
||||
m.add(mnuExit);
|
||||
|
@ -104,7 +161,7 @@ public class WindowScannerFilter implements WindowListener, FocusListener, Actio
|
|||
mnuClear.addActionListener(this);
|
||||
mb.add(m);
|
||||
m = new Menu("View");
|
||||
if (usingSwing)
|
||||
if (!pocketpc)
|
||||
{
|
||||
tibScript = new CheckboxMenuItem("Tibetan Script", true);
|
||||
m.add(tibScript);
|
||||
|
@ -120,47 +177,70 @@ public class WindowScannerFilter implements WindowListener, FocusListener, Actio
|
|||
}
|
||||
mb.add(m);
|
||||
|
||||
m = new Menu("Help");
|
||||
mnuAbout = new MenuItem("About...");
|
||||
m.add(mnuAbout);
|
||||
mnuAbout.addActionListener(this);
|
||||
mb.add(m);
|
||||
if (!pocketpc)
|
||||
{
|
||||
m = new Menu("Help");
|
||||
mnuAbout = new MenuItem("About...");
|
||||
m.add(mnuAbout);
|
||||
mnuAbout.addActionListener(this);
|
||||
mb.add(m);
|
||||
}
|
||||
|
||||
// disable menus
|
||||
focusLost(null);
|
||||
focusLost(null);
|
||||
|
||||
|
||||
sp.addFocusListener(this);
|
||||
|
||||
frame.setMenuBar(mb);
|
||||
frame.add(sp);
|
||||
frame.addWindowListener(this);
|
||||
frame.setSize(d);
|
||||
// frame.setSize(240,320);
|
||||
//else frame.setSize(500,600);
|
||||
frame.show();
|
||||
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 (usingSwing)
|
||||
if (pocketpc || !ThdlOptions.getBooleanOption(AboutDialog.windowAboutOption))
|
||||
{
|
||||
//JOptionPane.showMessageDialog(frame, TibetanScanner.aboutUnicode, "About", JOptionPane.PLAIN_MESSAGE);
|
||||
diagAbout = new AboutDialog(frame, true);
|
||||
diagAbout = new AboutDialog(mainWindow, pocketpc);
|
||||
diagAbout.show();
|
||||
|
||||
if (!pocketpc && diagAbout.omitNextTime())
|
||||
{
|
||||
ThdlOptions.setUserPreference(AboutDialog.windowAboutOption, true);
|
||||
try
|
||||
{
|
||||
ThdlOptions.saveUserPreferences();
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (diagAbout==null)
|
||||
{
|
||||
diagAbout = new AboutDialog(frame, false);
|
||||
}
|
||||
diagAbout.show();
|
||||
}
|
||||
|
||||
|
||||
public static void main(String[] args)
|
||||
{
|
||||
if (args.length!=1 && args.length!=2)
|
||||
switch(args.length)
|
||||
{
|
||||
case 0:
|
||||
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);
|
||||
return;
|
||||
}
|
||||
new WindowScannerFilter(args[args.length-1], args.length == 2);
|
||||
}
|
||||
|
||||
|
||||
|
@ -288,30 +368,44 @@ public class WindowScannerFilter implements WindowListener, FocusListener, Actio
|
|||
/* 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 e)
|
||||
public void actionPerformed(ActionEvent event)
|
||||
{
|
||||
Object clicked = e.getSource();
|
||||
Object clicked = event.getSource();
|
||||
StringSelection ss;
|
||||
String s = null;
|
||||
|
||||
if (clicked == mnuAbout)
|
||||
{
|
||||
if (usingSwing)
|
||||
{
|
||||
//JOptionPane.showMessageDialog(frame, TibetanScanner.aboutUnicode, "About", JOptionPane.PLAIN_MESSAGE);
|
||||
diagAbout = new AboutDialog(frame, true);
|
||||
}
|
||||
else if (diagAbout==null)
|
||||
{
|
||||
diagAbout = new AboutDialog(frame, false);
|
||||
}
|
||||
if (diagAbout==null) diagAbout = new AboutDialog(mainWindow, pocketpc);
|
||||
diagAbout.show();
|
||||
if (!pocketpc)
|
||||
{
|
||||
ThdlOptions.setUserPreference(AboutDialog.windowAboutOption, diagAbout.omitNextTime());
|
||||
try
|
||||
{
|
||||
ThdlOptions.saveUserPreferences();
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (clicked == mnuClear)
|
||||
{
|
||||
sp.clear();
|
||||
}
|
||||
else
|
||||
else if (clicked == mnuOpen)
|
||||
{
|
||||
mainWindow.setVisible(false);
|
||||
mainWindow.dispose();
|
||||
if (!pocketpc) ThdlOptions.setUserPreference(defOpenOption, "");
|
||||
new WindowScannerFilter(pocketpc);
|
||||
}
|
||||
else if (clicked == mnuExit)
|
||||
{
|
||||
System.exit(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (objModified==null) return;
|
||||
|
||||
|
@ -319,11 +413,7 @@ public class WindowScannerFilter implements WindowListener, FocusListener, Actio
|
|||
{
|
||||
TextArea t = (TextArea) objModified;
|
||||
|
||||
if (clicked == mnuExit)
|
||||
{
|
||||
System.exit(0);
|
||||
}
|
||||
else if (clicked == mnuCut)
|
||||
if (clicked == mnuCut)
|
||||
{
|
||||
ss = new StringSelection(t.getSelectedText());
|
||||
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(ss,ss);
|
||||
|
@ -387,7 +477,7 @@ public class WindowScannerFilter implements WindowListener, FocusListener, Actio
|
|||
else if (clicked == mnuSelectAll)
|
||||
{
|
||||
t.selectAll();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue