Got rid of redundant code
This commit is contained in:
parent
cce779bf88
commit
2b5a5fe67a
8 changed files with 129 additions and 91 deletions
|
@ -20,6 +20,7 @@ package org.thdl.tib.scanner;
|
|||
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import org.thdl.util.*;
|
||||
|
||||
/** Window that displays copyright stuff.
|
||||
|
||||
|
@ -28,22 +29,34 @@ import java.awt.event.*;
|
|||
*/
|
||||
public class AboutDialog extends Dialog implements ActionListener, WindowListener
|
||||
{
|
||||
public AboutDialog(Frame parent, boolean big)
|
||||
public static String windowAboutOption = "thdl.scanner.omit.about.window";
|
||||
private Checkbox chkOmitNextTime;
|
||||
|
||||
public AboutDialog(Frame parent, boolean pocketpc)
|
||||
{
|
||||
super(parent, "About...", true);
|
||||
Panel p = new Panel(new BorderLayout());
|
||||
chkOmitNextTime = new Checkbox("Don't show this window at startup", ThdlOptions.getBooleanOption(windowAboutOption));
|
||||
p.add(chkOmitNextTime, BorderLayout.CENTER);
|
||||
Button close = new Button("Close this window");
|
||||
add(close, BorderLayout.NORTH);
|
||||
p.add(close, BorderLayout.EAST);
|
||||
add(p, BorderLayout.NORTH);
|
||||
close.addActionListener(this);
|
||||
TextArea ta = new TextArea(TibetanScanner.aboutUnicode,0,0,TextArea.SCROLLBARS_VERTICAL_ONLY);
|
||||
ta.setEditable(false);
|
||||
addWindowListener(this);
|
||||
add(ta, BorderLayout.CENTER);
|
||||
if (big) setSize(480,400);
|
||||
else
|
||||
if (pocketpc)
|
||||
{
|
||||
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
|
||||
setSize(d); // the size ipaq's window.
|
||||
}
|
||||
else setSize(480,400);
|
||||
}
|
||||
|
||||
public boolean omitNextTime()
|
||||
{
|
||||
return chkOmitNextTime.getState();
|
||||
}
|
||||
|
||||
/* FIXME: what happens if this throws an exception? We'll just
|
||||
|
|
|
@ -25,6 +25,7 @@ import javax.swing.text.JTextComponent;
|
|||
import java.awt.event.*;
|
||||
import java.awt.datatransfer.*;
|
||||
import org.thdl.tib.input.DuffPane;
|
||||
import org.thdl.util.*;
|
||||
|
||||
/** Inputs a Tibetan text and displays the words with
|
||||
their definitions through through a graphical interfase using a
|
||||
|
@ -50,7 +51,9 @@ public class AppletScannerFilter extends JApplet implements ActionListener, Focu
|
|||
|
||||
private JMenu mnuEdit;
|
||||
private Object objModified;
|
||||
private AboutDialog diagAbout;
|
||||
ScannerPanel sp;
|
||||
private Frame fakeFrame;
|
||||
|
||||
public void init()
|
||||
{
|
||||
|
@ -66,6 +69,8 @@ public class AppletScannerFilter extends JApplet implements ActionListener, Focu
|
|||
url = getCodeBase() + url;
|
||||
}
|
||||
|
||||
diagAbout = null;
|
||||
|
||||
// sp = new SimpleScannerPanel(url);
|
||||
sp = new DuffScannerPanel(url);
|
||||
|
||||
|
@ -123,6 +128,25 @@ public class AppletScannerFilter extends JApplet implements ActionListener, Focu
|
|||
SymComponent aSymComponent = new SymComponent();
|
||||
this.addComponentListener(aSymComponent);
|
||||
//}}
|
||||
|
||||
fakeFrame = new Frame();
|
||||
if (!ThdlOptions.getBooleanOption(AboutDialog.windowAboutOption))
|
||||
{
|
||||
diagAbout = new AboutDialog(fakeFrame, true);
|
||||
|
||||
diagAbout.show();
|
||||
if (diagAbout.omitNextTime())
|
||||
{
|
||||
ThdlOptions.setUserPreference(AboutDialog.windowAboutOption, true);
|
||||
try
|
||||
{
|
||||
ThdlOptions.saveUserPreferences();
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Added to update the Edit menu in dependence upon
|
||||
|
@ -172,15 +196,27 @@ public class AppletScannerFilter extends JApplet implements ActionListener, Focu
|
|||
/* 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==aboutItem)
|
||||
{
|
||||
JOptionPane.showMessageDialog(AppletScannerFilter.this, TibetanScanner.aboutUnicode, "About", JOptionPane.PLAIN_MESSAGE);
|
||||
if (diagAbout==null)
|
||||
{
|
||||
diagAbout = new AboutDialog(fakeFrame, true);
|
||||
}
|
||||
diagAbout.show();
|
||||
ThdlOptions.setUserPreference(AboutDialog.windowAboutOption, diagAbout.omitNextTime());
|
||||
try
|
||||
{
|
||||
ThdlOptions.saveUserPreferences();
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
}
|
||||
}
|
||||
else if (clicked == mnuClear)
|
||||
{
|
||||
|
|
|
@ -76,36 +76,12 @@ public class DictionaryTableModel extends AbstractTableModel
|
|||
return getValueAt(0, c).getClass();
|
||||
}
|
||||
|
||||
public void newSearch(Token[] token)
|
||||
public void newSearch(Word[] array)
|
||||
{
|
||||
int i, n=0;
|
||||
if (token==null)
|
||||
array = null;
|
||||
else
|
||||
{
|
||||
for (i=0; i<token.length; i++)
|
||||
{
|
||||
if (token[i] instanceof Word)
|
||||
n++;
|
||||
}
|
||||
if (n==0)
|
||||
{
|
||||
array=null;
|
||||
}
|
||||
else
|
||||
{
|
||||
array = new Word[n];
|
||||
n=0;
|
||||
for (i=0; i<token.length; i++)
|
||||
{
|
||||
if (token[i] instanceof Word)
|
||||
{
|
||||
array[n] = (Word) token[i];
|
||||
n++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.array = array;
|
||||
|
||||
if (array==null)
|
||||
arrayTibetan = null;
|
||||
else
|
||||
|
|
|
@ -156,7 +156,7 @@ public class DuffScannerPanel extends ScannerPanel
|
|||
doingStatus("Translating...");
|
||||
scanner.scanBody(in);
|
||||
scanner.finishUp();
|
||||
model.newSearch(scanner.getTokenArray());
|
||||
model.newSearch(scanner.getWordArray());
|
||||
// printAllDefs();
|
||||
scanner.clearTokens();
|
||||
returnStatusToNorm();
|
||||
|
|
|
@ -29,13 +29,12 @@ import java.util.Enumeration;
|
|||
@author Andrés Montano Pellegrini
|
||||
@see SyllableListTree
|
||||
*/
|
||||
public class LocalTibetanScanner implements TibetanScanner
|
||||
public class LocalTibetanScanner extends TibetanScanner
|
||||
{
|
||||
public static String archivo;
|
||||
private SyllableListTree raiz, silActual, lastCompSil, silAnterior;
|
||||
private String wordActual, lastCompWord;
|
||||
private Vector floatingSil;
|
||||
private SimplifiedLinkedList wordList;
|
||||
private static String endOfParagraphMarks = "/;|!:[]^@#$%=<>(){}";
|
||||
private static String endOfSyllableMarks = " _\t";
|
||||
|
||||
|
@ -44,11 +43,6 @@ public class LocalTibetanScanner implements TibetanScanner
|
|||
archivo = null;
|
||||
}
|
||||
|
||||
public void clearTokens()
|
||||
{
|
||||
wordList = new SimplifiedLinkedList();
|
||||
}
|
||||
|
||||
public DictionarySource getDictionarySource()
|
||||
{
|
||||
return raiz.getDictionarySource();
|
||||
|
@ -57,12 +51,12 @@ public class LocalTibetanScanner implements TibetanScanner
|
|||
|
||||
public LocalTibetanScanner(String arch) throws Exception
|
||||
{
|
||||
super();
|
||||
archivo = arch;
|
||||
// raiz = new MemorySyllableListTree(archivo);
|
||||
// raiz = new FileSyllableListTree(archivo);
|
||||
raiz = new CachedSyllableListTree(archivo);
|
||||
floatingSil = new Vector();
|
||||
wordList = new SimplifiedLinkedList();
|
||||
resetAll();
|
||||
}
|
||||
|
||||
|
@ -377,20 +371,6 @@ outAHere:
|
|||
}
|
||||
}
|
||||
|
||||
public SimplifiedLinkedList getTokenLinkedList()
|
||||
{
|
||||
return wordList;
|
||||
}
|
||||
|
||||
public Token[] getTokenArray()
|
||||
{
|
||||
int i=wordList.size();
|
||||
Token token[] = new Token[i];
|
||||
SimplifiedListIterator li = wordList.listIterator();
|
||||
while(li.hasNext())
|
||||
token[--i] = (Token)li.next();
|
||||
return token;
|
||||
}
|
||||
|
||||
/** Looks for .dic file, and returns the dictionary descriptions.
|
||||
Also updates the definitionTags in the Definitions class.
|
||||
|
|
|
@ -28,17 +28,16 @@ import java.io.*;
|
|||
@author Andrés Montano Pellegrini
|
||||
@see RemoteScannerFilter
|
||||
*/
|
||||
public class RemoteTibetanScanner implements TibetanScanner
|
||||
public class RemoteTibetanScanner extends TibetanScanner
|
||||
{
|
||||
private String url;
|
||||
private SimplifiedLinkedList wordList;
|
||||
private DictionarySource defSourcesWanted;
|
||||
|
||||
public RemoteTibetanScanner(String url) throws Exception
|
||||
{
|
||||
super();
|
||||
defSourcesWanted = DictionarySource.getAllDictionaries();
|
||||
this.url = url;
|
||||
wordList = new SimplifiedLinkedList();
|
||||
}
|
||||
|
||||
/** dont use */
|
||||
|
@ -90,25 +89,6 @@ public class RemoteTibetanScanner implements TibetanScanner
|
|||
}
|
||||
}
|
||||
|
||||
public SimplifiedLinkedList getTokenLinkedList()
|
||||
{
|
||||
return wordList;
|
||||
}
|
||||
|
||||
public void clearTokens()
|
||||
{
|
||||
wordList = new SimplifiedLinkedList();
|
||||
}
|
||||
|
||||
public Token[] getTokenArray()
|
||||
{
|
||||
int i=0;
|
||||
Token token[] = new Token[wordList.size()];
|
||||
SimplifiedListIterator li = wordList.listIterator();
|
||||
while(li.hasNext())
|
||||
token[i++] = (Token)li.next();
|
||||
return token;
|
||||
}
|
||||
|
||||
/** does not do anything */
|
||||
public void finishUp()
|
||||
|
|
|
@ -121,6 +121,8 @@ public abstract class ScannerPanel extends Panel implements ActionListener
|
|||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
protected void doingStatus(String s)
|
||||
{
|
||||
status.setText(s);
|
||||
|
|
|
@ -23,16 +23,16 @@ import org.thdl.util.*;
|
|||
|
||||
@author Andrés Montano Pellegrini
|
||||
*/
|
||||
public interface TibetanScanner
|
||||
public abstract class TibetanScanner
|
||||
{
|
||||
public static final String copyrightUnicode="Copyright " + '\u00A9' + " 2000-2003 by Andr" + '\u00E9' + "s Montano Pellegrini, all rights reserved.";
|
||||
public static final String copyrightASCII="Copyright 2000-2003 by Andres Montano Pellegrini, all rights reserved.";
|
||||
public static final String copyrightHTML="<hr><h5>" + "The Tibetan to English Translation Tool: Version 1.3.0, compiled on " + ThdlVersion.getTimeOfCompilation() + ". Copyright © 2000-2002 by <a href=\"http://www.people.virginia.edu/~am2zb/\" target=\"_blank\">Andrés Montano Pellegrini</a><br>All rights reserved</h5>";
|
||||
public static final String copyrightHTML="<hr><h5>" + "The Tibetan to English Translation Tool: Version 2.0.0, compiled on " + ThdlVersion.getTimeOfCompilation() + ". Copyright © 2000-2002 by <a href=\"http://www.people.virginia.edu/~am2zb/\" target=\"_blank\">Andrés Montano Pellegrini</a><br>All rights reserved</h5>";
|
||||
public static final String aboutUnicode=
|
||||
"Warning: Since version 1.3.0. the dictionary database format changed and " +
|
||||
"is incompatible with previous versions. In order to use the newest version " +
|
||||
"you have to re-build the dictionary database.\n\n" +
|
||||
"The Tibetan to English Translation Tool, version 1.3.0\n" +
|
||||
"The Tibetan to English Translation Tool, version 2.0.0\n" +
|
||||
"Copyright " + '\u00A9' + " 2000-2002 by Andr" + '\u00E9' + "s Montano Pellegrini, all rights reserved.\n\n" +
|
||||
"This software is protected by the terms of the AMP Open Community License, " +
|
||||
"Version 1.0 (available at www.tibet.iteso.mx/Guatemala/). The Tibetan script " +
|
||||
|
@ -262,12 +262,63 @@ public interface TibetanScanner
|
|||
"(Kyoto: Heirakuji-Shoten, 1974).<p>\n" +
|
||||
"YT: Oral commentary by Yeshi Thupten.";
|
||||
|
||||
public void scanLine(String linea);
|
||||
public void scanBody(String linea);
|
||||
public void finishUp();
|
||||
public SimplifiedLinkedList getTokenLinkedList();
|
||||
public Token[] getTokenArray();
|
||||
public void clearTokens();
|
||||
public DictionarySource getDictionarySource();
|
||||
public String[] getDictionaryDescriptions();
|
||||
protected SimplifiedLinkedList wordList;
|
||||
|
||||
public TibetanScanner()
|
||||
{
|
||||
wordList = new SimplifiedLinkedList();
|
||||
}
|
||||
|
||||
public void clearTokens()
|
||||
{
|
||||
wordList = new SimplifiedLinkedList();
|
||||
}
|
||||
|
||||
public Token[] getTokenArray()
|
||||
{
|
||||
int i=0;
|
||||
Token token[] = new Token[wordList.size()];
|
||||
SimplifiedListIterator li = wordList.listIterator();
|
||||
while(li.hasNext())
|
||||
token[i++] = (Token)li.next();
|
||||
return token;
|
||||
}
|
||||
|
||||
public SimplifiedLinkedList getTokenLinkedList()
|
||||
{
|
||||
return wordList;
|
||||
}
|
||||
|
||||
public Word[] getWordArray()
|
||||
{
|
||||
Token token;
|
||||
Word array[];
|
||||
int n=0;
|
||||
SimplifiedListIterator li = wordList.listIterator();
|
||||
while(li.hasNext())
|
||||
if (li.next() instanceof Word) n++;
|
||||
|
||||
if (n==0) return null;
|
||||
|
||||
array = new Word[n];
|
||||
n--;
|
||||
li = wordList.listIterator();
|
||||
while(li.hasNext())
|
||||
{
|
||||
token = (Token) li.next();
|
||||
if (token instanceof Word)
|
||||
{
|
||||
array[n] = (Word) token;
|
||||
n--;
|
||||
}
|
||||
}
|
||||
|
||||
return array;
|
||||
}
|
||||
|
||||
public abstract void scanLine(String linea);
|
||||
public abstract void scanBody(String linea);
|
||||
public abstract void finishUp();
|
||||
public abstract DictionarySource getDictionarySource();
|
||||
public abstract String[] getDictionaryDescriptions();
|
||||
}
|
Loading…
Reference in a new issue