Added support for multiple keyboards and ability to set the preferences
for size of tibetan font and type and size of roman font.
This commit is contained in:
parent
8e4b508de8
commit
52cdc17794
8 changed files with 222 additions and 50 deletions
|
@ -507,8 +507,8 @@ public class BinaryFileGenerator extends SimplifiedLinkedList
|
|||
add(s1, s2 , defNum);
|
||||
}
|
||||
}
|
||||
currentLine++;
|
||||
}
|
||||
currentLine++;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -47,7 +47,7 @@ public class DictionaryListSelectionListener implements ListSelectionListener
|
|||
{
|
||||
int selectedRow = lsm.getMinSelectionIndex();
|
||||
//TableModel tm = table.getModel();
|
||||
fullDef.setText(table.getValueAt(selectedRow, 1).toString());
|
||||
fullDef.setText(table.getValueAt(selectedRow, 2).toString());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -102,5 +102,17 @@ public class DictionaryTable extends JTable
|
|||
tc.setCellRenderer(normalRenderer);
|
||||
DictionaryTableModel dtm = (DictionaryTableModel) getModel();
|
||||
dtm.activateTibetan(activate);
|
||||
}
|
||||
}
|
||||
|
||||
public void setTibetanFontSize(int size)
|
||||
{
|
||||
DuffCellRenderer dcr = (DuffCellRenderer) duffRenderer;
|
||||
dcr.setTibetanFontSize(size);
|
||||
}
|
||||
|
||||
public void setRomanFont(Font f)
|
||||
{
|
||||
AlmostDefaultTableCellRenderer tcr = (AlmostDefaultTableCellRenderer) normalRenderer;
|
||||
tcr.setFont(f);
|
||||
}
|
||||
}
|
|
@ -59,15 +59,14 @@ public class DictionaryTableModel extends AbstractTableModel
|
|||
|
||||
public Object getValueAt(int row, int column)
|
||||
{
|
||||
if (column==0)
|
||||
{
|
||||
if (tibetanActivated)
|
||||
return arrayTibetan[row];
|
||||
else
|
||||
return array[row].getWylie();
|
||||
switch(column)
|
||||
{
|
||||
case 0:
|
||||
if (tibetanActivated) return arrayTibetan[row];
|
||||
else return array[row].getWylie();
|
||||
case 1: return array[row].getDef();
|
||||
default: return array[row].toString();
|
||||
}
|
||||
else
|
||||
return array[row].getDef();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -22,7 +22,8 @@ import java.awt.event.*;
|
|||
import javax.swing.*;
|
||||
import javax.swing.event.*;
|
||||
import javax.swing.table.*;
|
||||
import org.thdl.tib.input.DuffPane;
|
||||
import org.thdl.tib.input.*;
|
||||
import org.thdl.util.*;
|
||||
|
||||
/** Graphical interfase to be used by applications and applets
|
||||
to input a Tibetan text (in Roman or Tibetan script) and
|
||||
|
@ -33,7 +34,7 @@ import org.thdl.tib.input.DuffPane;
|
|||
@see WindowScannerFilter
|
||||
@see AppletScannerFilter
|
||||
*/
|
||||
public class DuffScannerPanel extends ScannerPanel
|
||||
public class DuffScannerPanel extends ScannerPanel implements ItemListener
|
||||
{
|
||||
private TextArea fullDef, txtInput;
|
||||
private DuffPane duffInput;
|
||||
|
@ -46,11 +47,31 @@ public class DuffScannerPanel extends ScannerPanel
|
|||
private DictionaryTableModel model;
|
||||
|
||||
boolean showingTibetan;
|
||||
|
||||
private PreferenceWindow prefWindow;
|
||||
private Choice script, keyboard;
|
||||
|
||||
/** the middleman that keeps code regarding Tibetan keyboards
|
||||
* clean */
|
||||
final static JskadKeyboardManager keybdMgr;
|
||||
|
||||
static {
|
||||
try {
|
||||
keybdMgr
|
||||
= new JskadKeyboardManager(JskadKeyboardFactory.getAllAvailableJskadKeyboards());
|
||||
} catch (Exception e) {
|
||||
throw new ThdlLazyException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public DuffScannerPanel(String file)
|
||||
{
|
||||
super(file);
|
||||
Panel panel1, panel2;
|
||||
super(file, true);
|
||||
Panel panel1, panel2, toolBar;
|
||||
int i;
|
||||
|
||||
prefWindow = null;
|
||||
|
||||
panel2 = new Panel(new BorderLayout());
|
||||
panel1 = getDictPanel();
|
||||
if (panel1!=null) panel2.add (panel1, BorderLayout.NORTH);
|
||||
|
@ -83,8 +104,36 @@ public class DuffScannerPanel extends ScannerPanel
|
|||
panel2.add(panel1, BorderLayout.CENTER);
|
||||
add(panel2, BorderLayout.CENTER);
|
||||
showingTibetan = true;
|
||||
|
||||
toolBar = getToolBar();
|
||||
toolBar.setLayout(new FlowLayout());
|
||||
toolBar.add(new Label("Display:"));
|
||||
|
||||
// tibetanFont = new Font("TibetanMachine",Font.PLAIN,36);
|
||||
script = new Choice();
|
||||
script.add("Tibetan script");
|
||||
script.add("Roman script");
|
||||
toolBar.add(script);
|
||||
script.addItemListener(this);
|
||||
|
||||
toolBar.add(new Label("Keyboard:"));
|
||||
|
||||
keyboard = new Choice();
|
||||
String keyboardNames[] = keybdMgr.getIdentifyingStrings();
|
||||
for (i=0; i<keyboardNames.length; i++)
|
||||
keyboard.add(keyboardNames[i]);
|
||||
|
||||
int initialKeyboard
|
||||
= ThdlOptions.getIntegerOption("thdl.default.tibetan.keyboard", 0);
|
||||
try {
|
||||
keyboard.select(initialKeyboard);
|
||||
} catch (IllegalArgumentException e) {
|
||||
initialKeyboard = 0; // good ol' Wylie
|
||||
keyboard.select(initialKeyboard);
|
||||
}
|
||||
keybdMgr.elementAt(initialKeyboard).activate(duffInput);
|
||||
|
||||
keyboard.addItemListener(this);
|
||||
toolBar.add(keyboard);
|
||||
}
|
||||
|
||||
public void addFocusListener(FocusListener fl)
|
||||
|
@ -94,6 +143,29 @@ public class DuffScannerPanel extends ScannerPanel
|
|||
fullDef.addFocusListener(fl);
|
||||
}
|
||||
|
||||
public void itemStateChanged(ItemEvent e)
|
||||
{
|
||||
Object obj = e.getSource();
|
||||
if (obj instanceof Choice)
|
||||
{
|
||||
Choice ch = (Choice) obj;
|
||||
if (ch == script)
|
||||
{
|
||||
boolean useTibetan = (ch.getSelectedIndex()==0);
|
||||
this.setWylieInput(!useTibetan);
|
||||
keyboard.setEnabled(useTibetan);
|
||||
}
|
||||
else if (ch == keyboard)
|
||||
{
|
||||
int ki = ch.getSelectedIndex();
|
||||
keybdMgr.elementAt(ki).activate(duffInput);
|
||||
ThdlOptions.setUserPreference("thdl.default.tibetan.keyboard", ki);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* public void printAllDefs()
|
||||
{
|
||||
|
||||
|
@ -203,5 +275,20 @@ public class DuffScannerPanel extends ScannerPanel
|
|||
showingTibetan = false;
|
||||
}
|
||||
table.repaint();
|
||||
}
|
||||
}
|
||||
|
||||
public void setPreferences()
|
||||
{
|
||||
Font f;
|
||||
if (prefWindow==null) prefWindow = new PreferenceWindow(this, duffInput);
|
||||
prefWindow.show();
|
||||
f = new Font(prefWindow.getRomanFont(), Font.PLAIN, prefWindow.getRomanFontSize());
|
||||
fullDef.setFont(f);
|
||||
txtInput.setFont(f);
|
||||
table.setTibetanFontSize(prefWindow.getTibetanFontSize());
|
||||
table.setRomanFont(f);
|
||||
table.repaint();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -36,23 +36,40 @@ public abstract class ScannerPanel extends Panel implements ActionListener
|
|||
protected Checkbox chkDicts[];
|
||||
Button cmdTranslate;
|
||||
protected TibetanScanner scanner;
|
||||
private Panel toolBar;
|
||||
|
||||
public ScannerPanel(String file)
|
||||
{
|
||||
this(file, false);
|
||||
}
|
||||
|
||||
/** Individual components that are to be shown or
|
||||
hidden through the menu.
|
||||
*/
|
||||
|
||||
public ScannerPanel(String file)
|
||||
public ScannerPanel(String file, boolean includeToolBar)
|
||||
{
|
||||
boolean exito=true;
|
||||
|
||||
setLayout(new BorderLayout());
|
||||
status = new Label();
|
||||
Panel panel1;
|
||||
Panel panel1, panel2;
|
||||
panel1 = new Panel(new BorderLayout());
|
||||
panel1.add(status, BorderLayout.CENTER);
|
||||
cmdTranslate = new Button("Translate");
|
||||
cmdTranslate.addActionListener(this);
|
||||
panel1.add(cmdTranslate, BorderLayout.EAST);
|
||||
if (includeToolBar)
|
||||
{
|
||||
toolBar = new Panel();
|
||||
panel2 = new Panel(new FlowLayout());
|
||||
panel2.add(toolBar);
|
||||
panel2.add(cmdTranslate);
|
||||
panel1.add(panel2, BorderLayout.EAST);
|
||||
}
|
||||
else
|
||||
{
|
||||
toolBar = null;
|
||||
panel1.add(cmdTranslate, BorderLayout.EAST);
|
||||
}
|
||||
chkDicts=null;
|
||||
// Label copyright = new Label(TibetanScanner.copyrightUnicode);
|
||||
|
||||
|
@ -121,8 +138,6 @@ public abstract class ScannerPanel extends Panel implements ActionListener
|
|||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
protected void doingStatus(String s)
|
||||
{
|
||||
status.setText(s);
|
||||
|
@ -162,6 +177,17 @@ public abstract class ScannerPanel extends Panel implements ActionListener
|
|||
{
|
||||
translate();
|
||||
}
|
||||
|
||||
/**Optionally overridden. */
|
||||
public void setPreferences()
|
||||
{
|
||||
}
|
||||
|
||||
public Panel getToolBar()
|
||||
{
|
||||
return toolBar;
|
||||
}
|
||||
|
||||
|
||||
public abstract void translate();
|
||||
public abstract void clear();
|
||||
|
|
|
@ -27,12 +27,12 @@ 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 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 copyrightHTML="<hr><h5>" + "The Tibetan to English Translation Tool: Version 2.1.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 2.0.0\n" +
|
||||
"The Tibetan to English Translation Tool, version 2.1.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 " +
|
||||
|
|
|
@ -27,7 +27,7 @@ import java.awt.*;
|
|||
import java.awt.datatransfer.*;
|
||||
import javax.swing.text.JTextComponent;
|
||||
import javax.swing.JOptionPane;
|
||||
import org.thdl.tib.input.DuffPane;
|
||||
import org.thdl.tib.input.*;
|
||||
import org.thdl.util.*;
|
||||
|
||||
/** Provides a graphical interfase to input Tibetan text (Roman or
|
||||
|
@ -48,13 +48,13 @@ public class WindowScannerFilter implements WindowListener, FocusListener, Actio
|
|||
private static String defOpenOption = "thdl.scanner.default.open";
|
||||
|
||||
private ScannerPanel sp;
|
||||
private MenuItem mnuExit, mnuCut, mnuCopy, mnuPaste, mnuDelete, mnuSelectAll, mnuAbout, mnuClear, mnuOpen;
|
||||
private CheckboxMenuItem tibScript, mnuDicts;
|
||||
private MenuItem mnuExit, mnuCut, mnuCopy, mnuPaste, mnuDelete, mnuSelectAll, mnuAbout, mnuClear, mnuOpen, mnuPreferences, mnuSavePref;
|
||||
private CheckboxMenuItem mnuDicts;
|
||||
private Object objModified;
|
||||
private AboutDialog diagAbout;
|
||||
private Frame mainWindow;
|
||||
private boolean pocketpc;
|
||||
|
||||
|
||||
public WindowScannerFilter(boolean pocketpc)
|
||||
{
|
||||
String response;
|
||||
|
@ -120,13 +120,12 @@ public class WindowScannerFilter implements WindowListener, FocusListener, Actio
|
|||
mnuAbout = null;
|
||||
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
|
||||
|
||||
if (!pocketpc)
|
||||
sp = new DuffScannerPanel(file);
|
||||
else
|
||||
sp = new SimpleScannerPanel(file, d.width >d.height);
|
||||
if (pocketpc) sp = new SimpleScannerPanel(file, d.width >d.height);
|
||||
else sp = new DuffScannerPanel(file);
|
||||
|
||||
MenuBar mb = new MenuBar();
|
||||
Menu m = new Menu ("File");
|
||||
Menu m;
|
||||
m = new Menu ("File");
|
||||
mnuOpen = new MenuItem("Open...");
|
||||
mnuOpen.addActionListener(this);
|
||||
m.add(mnuOpen);
|
||||
|
@ -159,36 +158,61 @@ public class WindowScannerFilter implements WindowListener, FocusListener, Actio
|
|||
mnuClear = new MenuItem("Clear all");
|
||||
m.add(mnuClear);
|
||||
mnuClear.addActionListener(this);
|
||||
mb.add(m);
|
||||
m = new Menu("View");
|
||||
if (!pocketpc)
|
||||
{
|
||||
tibScript = new CheckboxMenuItem("Tibetan Script", true);
|
||||
m.add(tibScript);
|
||||
tibScript.addItemListener(this);
|
||||
mnuDicts=null;
|
||||
}
|
||||
else
|
||||
{
|
||||
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);
|
||||
tibScript=null;
|
||||
}
|
||||
mb.add(m);
|
||||
|
||||
if (!pocketpc)
|
||||
else
|
||||
{
|
||||
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);
|
||||
}
|
||||
mb.add(m);
|
||||
|
||||
// disable menus
|
||||
focusLost(null);
|
||||
|
||||
focusLost(null);
|
||||
|
||||
sp.addFocusListener(this);
|
||||
|
||||
|
@ -405,6 +429,30 @@ public class WindowScannerFilter implements WindowListener, FocusListener, Actio
|
|||
{
|
||||
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;
|
||||
|
|
Loading…
Reference in a new issue