Got rid of redundant code

This commit is contained in:
amontano 2003-08-03 06:28:22 +00:00
parent cce779bf88
commit 2b5a5fe67a
8 changed files with 129 additions and 91 deletions

View file

@ -20,6 +20,7 @@ package org.thdl.tib.scanner;
import java.awt.*; import java.awt.*;
import java.awt.event.*; import java.awt.event.*;
import org.thdl.util.*;
/** Window that displays copyright stuff. /** Window that displays copyright stuff.
@ -28,22 +29,34 @@ import java.awt.event.*;
*/ */
public class AboutDialog extends Dialog implements ActionListener, WindowListener 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); 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"); Button close = new Button("Close this window");
add(close, BorderLayout.NORTH); p.add(close, BorderLayout.EAST);
add(p, BorderLayout.NORTH);
close.addActionListener(this); close.addActionListener(this);
TextArea ta = new TextArea(TibetanScanner.aboutUnicode,0,0,TextArea.SCROLLBARS_VERTICAL_ONLY); TextArea ta = new TextArea(TibetanScanner.aboutUnicode,0,0,TextArea.SCROLLBARS_VERTICAL_ONLY);
ta.setEditable(false); ta.setEditable(false);
addWindowListener(this); addWindowListener(this);
add(ta, BorderLayout.CENTER); add(ta, BorderLayout.CENTER);
if (big) setSize(480,400); if (pocketpc)
else
{ {
Dimension d = Toolkit.getDefaultToolkit().getScreenSize(); Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
setSize(d); // the size ipaq's window. 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 /* FIXME: what happens if this throws an exception? We'll just

View file

@ -25,6 +25,7 @@ import javax.swing.text.JTextComponent;
import java.awt.event.*; import java.awt.event.*;
import java.awt.datatransfer.*; import java.awt.datatransfer.*;
import org.thdl.tib.input.DuffPane; import org.thdl.tib.input.DuffPane;
import org.thdl.util.*;
/** Inputs a Tibetan text and displays the words with /** Inputs a Tibetan text and displays the words with
their definitions through through a graphical interfase using a 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 JMenu mnuEdit;
private Object objModified; private Object objModified;
private AboutDialog diagAbout;
ScannerPanel sp; ScannerPanel sp;
private Frame fakeFrame;
public void init() public void init()
{ {
@ -66,6 +69,8 @@ public class AppletScannerFilter extends JApplet implements ActionListener, Focu
url = getCodeBase() + url; url = getCodeBase() + url;
} }
diagAbout = null;
// sp = new SimpleScannerPanel(url); // sp = new SimpleScannerPanel(url);
sp = new DuffScannerPanel(url); sp = new DuffScannerPanel(url);
@ -123,6 +128,25 @@ public class AppletScannerFilter extends JApplet implements ActionListener, Focu
SymComponent aSymComponent = new SymComponent(); SymComponent aSymComponent = new SymComponent();
this.addComponentListener(aSymComponent); 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 /** 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 /* FIXME: what happens if this throws an exception? We'll just
see it on the console--it won't terminate the program. And the see it on the console--it won't terminate the program. And the
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 event)
{ {
Object clicked = e.getSource(); Object clicked = event.getSource();
StringSelection ss; StringSelection ss;
String s = null; String s = null;
if (clicked==aboutItem) 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) else if (clicked == mnuClear)
{ {

View file

@ -76,36 +76,12 @@ public class DictionaryTableModel extends AbstractTableModel
return getValueAt(0, c).getClass(); return getValueAt(0, c).getClass();
} }
public void newSearch(Token[] token) public void newSearch(Word[] array)
{ {
int i, n=0; int i, n=0;
if (token==null)
array = null; this.array = array;
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++;
}
}
}
}
if (array==null) if (array==null)
arrayTibetan = null; arrayTibetan = null;
else else

View file

@ -156,7 +156,7 @@ public class DuffScannerPanel extends ScannerPanel
doingStatus("Translating..."); doingStatus("Translating...");
scanner.scanBody(in); scanner.scanBody(in);
scanner.finishUp(); scanner.finishUp();
model.newSearch(scanner.getTokenArray()); model.newSearch(scanner.getWordArray());
// printAllDefs(); // printAllDefs();
scanner.clearTokens(); scanner.clearTokens();
returnStatusToNorm(); returnStatusToNorm();

View file

@ -29,13 +29,12 @@ import java.util.Enumeration;
@author Andr&eacute;s Montano Pellegrini @author Andr&eacute;s Montano Pellegrini
@see SyllableListTree @see SyllableListTree
*/ */
public class LocalTibetanScanner implements TibetanScanner public class LocalTibetanScanner extends TibetanScanner
{ {
public static String archivo; public static String archivo;
private SyllableListTree raiz, silActual, lastCompSil, silAnterior; private SyllableListTree raiz, silActual, lastCompSil, silAnterior;
private String wordActual, lastCompWord; private String wordActual, lastCompWord;
private Vector floatingSil; private Vector floatingSil;
private SimplifiedLinkedList wordList;
private static String endOfParagraphMarks = "/;|!:[]^@#$%=<>(){}"; private static String endOfParagraphMarks = "/;|!:[]^@#$%=<>(){}";
private static String endOfSyllableMarks = " _\t"; private static String endOfSyllableMarks = " _\t";
@ -44,11 +43,6 @@ public class LocalTibetanScanner implements TibetanScanner
archivo = null; archivo = null;
} }
public void clearTokens()
{
wordList = new SimplifiedLinkedList();
}
public DictionarySource getDictionarySource() public DictionarySource getDictionarySource()
{ {
return raiz.getDictionarySource(); return raiz.getDictionarySource();
@ -57,12 +51,12 @@ public class LocalTibetanScanner implements TibetanScanner
public LocalTibetanScanner(String arch) throws Exception public LocalTibetanScanner(String arch) throws Exception
{ {
super();
archivo = arch; archivo = arch;
// raiz = new MemorySyllableListTree(archivo); // raiz = new MemorySyllableListTree(archivo);
// raiz = new FileSyllableListTree(archivo); // raiz = new FileSyllableListTree(archivo);
raiz = new CachedSyllableListTree(archivo); raiz = new CachedSyllableListTree(archivo);
floatingSil = new Vector(); floatingSil = new Vector();
wordList = new SimplifiedLinkedList();
resetAll(); 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. /** Looks for .dic file, and returns the dictionary descriptions.
Also updates the definitionTags in the Definitions class. Also updates the definitionTags in the Definitions class.

View file

@ -28,17 +28,16 @@ import java.io.*;
@author Andr&eacute;s Montano Pellegrini @author Andr&eacute;s Montano Pellegrini
@see RemoteScannerFilter @see RemoteScannerFilter
*/ */
public class RemoteTibetanScanner implements TibetanScanner public class RemoteTibetanScanner extends TibetanScanner
{ {
private String url; private String url;
private SimplifiedLinkedList wordList;
private DictionarySource defSourcesWanted; private DictionarySource defSourcesWanted;
public RemoteTibetanScanner(String url) throws Exception public RemoteTibetanScanner(String url) throws Exception
{ {
super();
defSourcesWanted = DictionarySource.getAllDictionaries(); defSourcesWanted = DictionarySource.getAllDictionaries();
this.url = url; this.url = url;
wordList = new SimplifiedLinkedList();
} }
/** dont use */ /** 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 */ /** does not do anything */
public void finishUp() public void finishUp()

View file

@ -121,6 +121,8 @@ public abstract class ScannerPanel extends Panel implements ActionListener
return null; return null;
} }
protected void doingStatus(String s) protected void doingStatus(String s)
{ {
status.setText(s); status.setText(s);

View file

@ -23,16 +23,16 @@ import org.thdl.util.*;
@author Andr&eacute;s Montano Pellegrini @author Andr&eacute;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 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 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 &copy; 2000-2002 by <a href=\"http://www.people.virginia.edu/~am2zb/\" target=\"_blank\">Andr&eacute;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 &copy; 2000-2002 by <a href=\"http://www.people.virginia.edu/~am2zb/\" target=\"_blank\">Andr&eacute;s Montano Pellegrini</a><br>All rights reserved</h5>";
public static final String aboutUnicode= public static final String aboutUnicode=
"Warning: Since version 1.3.0. the dictionary database format changed and " + "Warning: Since version 1.3.0. the dictionary database format changed and " +
"is incompatible with previous versions. In order to use the newest version " + "is incompatible with previous versions. In order to use the newest version " +
"you have to re-build the dictionary database.\n\n" + "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" + "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, " + "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 " + "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" + "(Kyoto: Heirakuji-Shoten, 1974).<p>\n" +
"YT: Oral commentary by Yeshi Thupten."; "YT: Oral commentary by Yeshi Thupten.";
public void scanLine(String linea); protected SimplifiedLinkedList wordList;
public void scanBody(String linea);
public void finishUp(); public TibetanScanner()
public SimplifiedLinkedList getTokenLinkedList(); {
public Token[] getTokenArray(); wordList = new SimplifiedLinkedList();
public void clearTokens(); }
public DictionarySource getDictionarySource();
public String[] getDictionaryDescriptions(); 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();
} }