From 2b5a5fe67a266bd771d746c317e7959fc0a1327d Mon Sep 17 00:00:00 2001 From: amontano Date: Sun, 3 Aug 2003 06:28:22 +0000 Subject: [PATCH] Got rid of redundant code --- source/org/thdl/tib/scanner/AboutDialog.java | 21 +++++- .../thdl/tib/scanner/AppletScannerFilter.java | 42 ++++++++++- .../tib/scanner/DictionaryTableModel.java | 32 +------- .../thdl/tib/scanner/DuffScannerPanel.java | 2 +- .../thdl/tib/scanner/LocalTibetanScanner.java | 24 +----- .../tib/scanner/RemoteTibetanScanner.java | 24 +----- source/org/thdl/tib/scanner/ScannerPanel.java | 2 + .../org/thdl/tib/scanner/TibetanScanner.java | 73 ++++++++++++++++--- 8 files changed, 129 insertions(+), 91 deletions(-) diff --git a/source/org/thdl/tib/scanner/AboutDialog.java b/source/org/thdl/tib/scanner/AboutDialog.java index 617522e..29c7e08 100644 --- a/source/org/thdl/tib/scanner/AboutDialog.java +++ b/source/org/thdl/tib/scanner/AboutDialog.java @@ -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 diff --git a/source/org/thdl/tib/scanner/AppletScannerFilter.java b/source/org/thdl/tib/scanner/AppletScannerFilter.java index ee1d166..a6dff66 100644 --- a/source/org/thdl/tib/scanner/AppletScannerFilter.java +++ b/source/org/thdl/tib/scanner/AppletScannerFilter.java @@ -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() { @@ -65,6 +68,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) { diff --git a/source/org/thdl/tib/scanner/DictionaryTableModel.java b/source/org/thdl/tib/scanner/DictionaryTableModel.java index 6f20fe7..d67375b 100644 --- a/source/org/thdl/tib/scanner/DictionaryTableModel.java +++ b/source/org/thdl/tib/scanner/DictionaryTableModel.java @@ -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; iAndrés Montano Pellegrini
All rights reserved"; + public static final String copyrightHTML="
" + "The Tibetan to English Translation Tool: Version 2.0.0, compiled on " + ThdlVersion.getTimeOfCompilation() + ". Copyright © 2000-2002 by Andrés Montano Pellegrini
All rights reserved
"; 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).

\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(); } \ No newline at end of file