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:
amontano 2003-08-09 08:00:58 +00:00
parent 8e4b508de8
commit 52cdc17794
8 changed files with 222 additions and 50 deletions

View file

@ -507,8 +507,8 @@ public class BinaryFileGenerator extends SimplifiedLinkedList
add(s1, s2 , defNum); add(s1, s2 , defNum);
} }
} }
currentLine++;
} }
currentLine++;
} }
} }

View file

@ -47,7 +47,7 @@ public class DictionaryListSelectionListener implements ListSelectionListener
{ {
int selectedRow = lsm.getMinSelectionIndex(); int selectedRow = lsm.getMinSelectionIndex();
//TableModel tm = table.getModel(); //TableModel tm = table.getModel();
fullDef.setText(table.getValueAt(selectedRow, 1).toString()); fullDef.setText(table.getValueAt(selectedRow, 2).toString());
} }
} }
} }

View file

@ -102,5 +102,17 @@ public class DictionaryTable extends JTable
tc.setCellRenderer(normalRenderer); tc.setCellRenderer(normalRenderer);
DictionaryTableModel dtm = (DictionaryTableModel) getModel(); DictionaryTableModel dtm = (DictionaryTableModel) getModel();
dtm.activateTibetan(activate); 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);
}
} }

View file

@ -59,15 +59,14 @@ public class DictionaryTableModel extends AbstractTableModel
public Object getValueAt(int row, int column) public Object getValueAt(int row, int column)
{ {
if (column==0) switch(column)
{ {
if (tibetanActivated) case 0:
return arrayTibetan[row]; if (tibetanActivated) return arrayTibetan[row];
else else return array[row].getWylie();
return array[row].getWylie(); case 1: return array[row].getDef();
default: return array[row].toString();
} }
else
return array[row].getDef();
} }

View file

@ -22,7 +22,8 @@ import java.awt.event.*;
import javax.swing.*; import javax.swing.*;
import javax.swing.event.*; import javax.swing.event.*;
import javax.swing.table.*; 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 /** Graphical interfase to be used by applications and applets
to input a Tibetan text (in Roman or Tibetan script) and to input a Tibetan text (in Roman or Tibetan script) and
@ -33,7 +34,7 @@ import org.thdl.tib.input.DuffPane;
@see WindowScannerFilter @see WindowScannerFilter
@see AppletScannerFilter @see AppletScannerFilter
*/ */
public class DuffScannerPanel extends ScannerPanel public class DuffScannerPanel extends ScannerPanel implements ItemListener
{ {
private TextArea fullDef, txtInput; private TextArea fullDef, txtInput;
private DuffPane duffInput; private DuffPane duffInput;
@ -46,11 +47,31 @@ public class DuffScannerPanel extends ScannerPanel
private DictionaryTableModel model; private DictionaryTableModel model;
boolean showingTibetan; 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) public DuffScannerPanel(String file)
{ {
super(file); super(file, true);
Panel panel1, panel2; Panel panel1, panel2, toolBar;
int i;
prefWindow = null;
panel2 = new Panel(new BorderLayout()); panel2 = new Panel(new BorderLayout());
panel1 = getDictPanel(); panel1 = getDictPanel();
if (panel1!=null) panel2.add (panel1, BorderLayout.NORTH); if (panel1!=null) panel2.add (panel1, BorderLayout.NORTH);
@ -83,8 +104,36 @@ public class DuffScannerPanel extends ScannerPanel
panel2.add(panel1, BorderLayout.CENTER); panel2.add(panel1, BorderLayout.CENTER);
add(panel2, BorderLayout.CENTER); add(panel2, BorderLayout.CENTER);
showingTibetan = true; 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) public void addFocusListener(FocusListener fl)
@ -94,6 +143,29 @@ public class DuffScannerPanel extends ScannerPanel
fullDef.addFocusListener(fl); 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() /* public void printAllDefs()
{ {
@ -203,5 +275,20 @@ public class DuffScannerPanel extends ScannerPanel
showingTibetan = false; showingTibetan = false;
} }
table.repaint(); 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();
}
} }

View file

@ -36,23 +36,40 @@ public abstract class ScannerPanel extends Panel implements ActionListener
protected Checkbox chkDicts[]; protected Checkbox chkDicts[];
Button cmdTranslate; Button cmdTranslate;
protected TibetanScanner scanner; protected TibetanScanner scanner;
private Panel toolBar;
public ScannerPanel(String file)
{
this(file, false);
}
/** Individual components that are to be shown or /** Individual components that are to be shown or
hidden through the menu. hidden through the menu.
*/ */
public ScannerPanel(String file, boolean includeToolBar)
public ScannerPanel(String file)
{ {
boolean exito=true; boolean exito=true;
setLayout(new BorderLayout()); setLayout(new BorderLayout());
status = new Label(); status = new Label();
Panel panel1; Panel panel1, panel2;
panel1 = new Panel(new BorderLayout()); panel1 = new Panel(new BorderLayout());
panel1.add(status, BorderLayout.CENTER); panel1.add(status, BorderLayout.CENTER);
cmdTranslate = new Button("Translate"); cmdTranslate = new Button("Translate");
cmdTranslate.addActionListener(this); 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; chkDicts=null;
// Label copyright = new Label(TibetanScanner.copyrightUnicode); // Label copyright = new Label(TibetanScanner.copyrightUnicode);
@ -121,8 +138,6 @@ 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);
@ -162,6 +177,17 @@ public abstract class ScannerPanel extends Panel implements ActionListener
{ {
translate(); translate();
} }
/**Optionally overridden. */
public void setPreferences()
{
}
public Panel getToolBar()
{
return toolBar;
}
public abstract void translate(); public abstract void translate();
public abstract void clear(); public abstract void clear();

View file

@ -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 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 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 copyrightHTML="<hr><h5>" + "The Tibetan to English Translation Tool: Version 2.1.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 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" + "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 " +

View file

@ -27,7 +27,7 @@ import java.awt.*;
import java.awt.datatransfer.*; import java.awt.datatransfer.*;
import javax.swing.text.JTextComponent; import javax.swing.text.JTextComponent;
import javax.swing.JOptionPane; import javax.swing.JOptionPane;
import org.thdl.tib.input.DuffPane; import org.thdl.tib.input.*;
import org.thdl.util.*; import org.thdl.util.*;
/** Provides a graphical interfase to input Tibetan text (Roman or /** 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 static String defOpenOption = "thdl.scanner.default.open";
private ScannerPanel sp; private ScannerPanel sp;
private MenuItem mnuExit, mnuCut, mnuCopy, mnuPaste, mnuDelete, mnuSelectAll, mnuAbout, mnuClear, mnuOpen; private MenuItem mnuExit, mnuCut, mnuCopy, mnuPaste, mnuDelete, mnuSelectAll, mnuAbout, mnuClear, mnuOpen, mnuPreferences, mnuSavePref;
private CheckboxMenuItem tibScript, mnuDicts; private CheckboxMenuItem mnuDicts;
private Object objModified; private Object objModified;
private AboutDialog diagAbout; private AboutDialog diagAbout;
private Frame mainWindow; private Frame mainWindow;
private boolean pocketpc; private boolean pocketpc;
public WindowScannerFilter(boolean pocketpc) public WindowScannerFilter(boolean pocketpc)
{ {
String response; String response;
@ -120,13 +120,12 @@ public class WindowScannerFilter implements WindowListener, FocusListener, Actio
mnuAbout = null; mnuAbout = null;
Dimension d = Toolkit.getDefaultToolkit().getScreenSize(); Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
if (!pocketpc) if (pocketpc) sp = new SimpleScannerPanel(file, d.width >d.height);
sp = new DuffScannerPanel(file); else sp = new DuffScannerPanel(file);
else
sp = new SimpleScannerPanel(file, d.width >d.height);
MenuBar mb = new MenuBar(); MenuBar mb = new MenuBar();
Menu m = new Menu ("File"); Menu m;
m = new Menu ("File");
mnuOpen = new MenuItem("Open..."); mnuOpen = new MenuItem("Open...");
mnuOpen.addActionListener(this); mnuOpen.addActionListener(this);
m.add(mnuOpen); m.add(mnuOpen);
@ -159,36 +158,61 @@ public class WindowScannerFilter implements WindowListener, FocusListener, Actio
mnuClear = new MenuItem("Clear all"); mnuClear = new MenuItem("Clear all");
m.add(mnuClear); m.add(mnuClear);
mnuClear.addActionListener(this); mnuClear.addActionListener(this);
mb.add(m);
m = new Menu("View");
if (!pocketpc) if (!pocketpc)
{ {
tibScript = new CheckboxMenuItem("Tibetan Script", true); m.add("-");
m.add(tibScript); mnuPreferences = new MenuItem("Preferences");
tibScript.addItemListener(this); m.add(mnuPreferences);
mnuDicts=null; mnuPreferences.addActionListener(this);
} mnuSavePref = new MenuItem("Save preferences to " + ThdlOptions.getUserPreferencesPath());
else m.add(mnuSavePref);
{ mnuSavePref.addActionListener(this);
mnuDicts=null;
}
mb.add(m);
if (pocketpc)
{
m = new Menu("View");
mnuDicts = new CheckboxMenuItem("Dictionaries", false); mnuDicts = new CheckboxMenuItem("Dictionaries", false);
m.add(mnuDicts); m.add(mnuDicts);
mnuDicts.addItemListener(this); mnuDicts.addItemListener(this);
tibScript=null;
} }
mb.add(m); else
if (!pocketpc)
{ {
m = new Menu("Help"); 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..."); mnuAbout = new MenuItem("About...");
m.add(mnuAbout); m.add(mnuAbout);
mnuAbout.addActionListener(this); mnuAbout.addActionListener(this);
mb.add(m);
} }
mb.add(m);
// disable menus // disable menus
focusLost(null); focusLost(null);
sp.addFocusListener(this); sp.addFocusListener(this);
@ -405,6 +429,30 @@ public class WindowScannerFilter implements WindowListener, FocusListener, Actio
{ {
System.exit(0); 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 else
{ {
if (objModified==null) return; if (objModified==null) return;