Jskad keyboards are now configured via keyboards.ini, a file that has

comments that explain its function.  It's quite simple.  This is in
response to Jeff C. H. Wu's request.
This commit is contained in:
dchandler 2003-05-14 03:25:36 +00:00
parent dcb36ec338
commit 78dc46a979
6 changed files with 115 additions and 23 deletions

View file

@ -947,6 +947,11 @@
<include name="org/thdl/tib/**/*.ini"/> <include name="org/thdl/tib/**/*.ini"/>
</fileset> </fileset>
</copy> </copy>
<copy todir="${mybin}">
<fileset dir="${source}">
<include name="keyboards.ini"/>
</fileset>
</copy>
</target> </target>

30
source/keyboards.ini Normal file
View file

@ -0,0 +1,30 @@
# Jskad keyboard init file
#
# This file must remain readable by the
# java.util.Properties.load(InputStream) mechanism, so don't just edit
# it willy-nilly. Follow the trend!
#
# "nil" is used to mean "there isn't one for this keyboard."
# How many keyboards are there?
number.of.keyboards = 5
keyboard.name.for.popup.1 = Extended Wylie
keyboard.rtf.help.file.1 = Wylie_keyboard.rtf
keyboard.ini.file.1 = nil
keyboard.name.for.popup.2 = TCC Keyboard \#1
keyboard.rtf.help.file.2 = TCC_keyboard_1.rtf
keyboard.ini.file.2 = tcc_keyboard_1.ini
keyboard.name.for.popup.3 = TCC Keyboard \#2
keyboard.rtf.help.file.3 = TCC_keyboard_2.rtf
keyboard.ini.file.3 = tcc_keyboard_2.ini
keyboard.name.for.popup.4 = Sambhota Keymap One
keyboard.rtf.help.file.4 = Sambhota_keymap_one.rtf
keyboard.ini.file.4 = sambhota_keyboard_1.ini
keyboard.name.for.popup.5 = Asian Classics Input Project (ACIP) -- BUGGY
keyboard.rtf.help.file.5 = nil
keyboard.ini.file.5 = acip_keyboard.ini

View file

@ -73,8 +73,16 @@ public class Jskad extends JPanel implements DocumentListener {
/** the middleman that keeps code regarding Tibetan keyboards /** the middleman that keeps code regarding Tibetan keyboards
* clean */ * clean */
private final static JskadKeyboardManager keybdMgr private final static JskadKeyboardManager keybdMgr;
= new JskadKeyboardManager(JskadKeyboardFactory.getAllAvailableJskadKeyboards());
static {
try {
keybdMgr
= new JskadKeyboardManager(JskadKeyboardFactory.getAllAvailableJskadKeyboards());
} catch (Exception e) {
throw new ThdlLazyException(e);
}
}
private JComboBox fontFamilies, fontSizes; private JComboBox fontFamilies, fontSizes;
private JFileChooser fileChooser; private JFileChooser fileChooser;

View file

@ -18,31 +18,75 @@ Contributor(s): ______________________________________.
package org.thdl.tib.input; package org.thdl.tib.input;
import java.util.Properties;
import org.thdl.tib.input.JskadKeyboard; import org.thdl.tib.input.JskadKeyboard;
import org.thdl.util.ThdlLazyException;
import org.thdl.util.ThdlOptions;
/** A JskadKeyboardFactory determines which Tibetan keyboards Jskad /** A JskadKeyboardFactory determines which Tibetan keyboards Jskad
supports. Adding a new one is as easy as adding 3 lines of text supports. Adding a new one is as easy as adding 3 lines of text
to this class's source code. to this class's source code.
*/ */
public class JskadKeyboardFactory { public class JskadKeyboardFactory {
public static JskadKeyboard[] getAllAvailableJskadKeyboards() { private static final String keyIniPath = "/keyboards.ini";
return new JskadKeyboard[] {
new JskadKeyboard("Extended Wylie", /** Reads /keyboards.ini to learn which Tibetan keyboards are
null, * available. Returns them. */
"Wylie_keyboard.rtf"), public static JskadKeyboard[] getAllAvailableJskadKeyboards()
new JskadKeyboard("TCC Keyboard #1", throws Exception
"tcc_keyboard_1.ini", {
"TCC_keyboard_1.rtf"), Properties keyboardProps
new JskadKeyboard("TCC Keyboard #2", = ThdlOptions.getPropertiesFromResource(JskadKeyboardFactory.class,
"tcc_keyboard_2.ini", keyIniPath,
"TCC_keyboard_2.rtf"), false,
new JskadKeyboard("Sambhota Keymap One", null);
"sambhota_keyboard_1.ini", String numberOfKeyboardsString
"Sambhota_keymap_one.rtf"), = keyboardProps.getProperty("number.of.keyboards", null);
new JskadKeyboard("Asian Classics Input Project (ACIP)", if (null == numberOfKeyboardsString) {
"acip_keyboard.ini", throw new Exception(keyIniPath
null) + " doesn't contain a number.of.keyboards property");
}; }
int numberOfKeyboards;
try {
Integer num = new Integer(numberOfKeyboardsString);
numberOfKeyboards = num.intValue();
if (numberOfKeyboards < 0) throw new NumberFormatException();
} catch (NumberFormatException e) {
throw new Exception(keyIniPath
+ " has a number.of.keyboards property, but it's not a nonnegative integer.");
}
JskadKeyboard[] keyboards;
keyboards = new JskadKeyboard[numberOfKeyboards];
for (int i = 1; i <= numberOfKeyboards; i++) {
String description
= keyboardProps.getProperty("keyboard.name.for.popup." + i,
null);
String iniFile
= keyboardProps.getProperty("keyboard.ini.file." + i,
null);
String rtfFile
= keyboardProps.getProperty("keyboard.rtf.help.file." + i,
null);
if (null == description)
throw new Exception(keyIniPath
+ ": keyboard.name.for.popup." + i + " not defined.");
if (null == iniFile)
throw new Exception(keyIniPath
+ ": keyboard.ini.file." + i + " not defined.");
if (null == rtfFile)
throw new Exception(keyIniPath
+ ": keyboard.rtf.help.file." + i + " not defined.");
if (iniFile.equals("nil"))
iniFile = null;
if (rtfFile.equals("nil"))
rtfFile = null;
keyboards[i - 1] = new JskadKeyboard(description,
iniFile,
rtfFile);
}
return keyboards;
} }
} }

View file

@ -282,7 +282,8 @@ public class TibetanMachineWeb implements THDLWylieConstants {
InputStreamReader isr = new InputStreamReader(url.openStream()); InputStreamReader isr = new InputStreamReader(url.openStream());
BufferedReader in = new BufferedReader(isr); BufferedReader in = new BufferedReader(isr);
System.out.println("reading "+fileName); System.out.println("Reading Tibetan Machine Web code table "
+ fileName);
String line; String line;
boolean hashOn = false; boolean hashOn = false;
boolean isSanskrit = false; //FIXME: this is never read. boolean isSanskrit = false; //FIXME: this is never read.

View file

@ -332,8 +332,12 @@ public final class ThdlOptions {
} }
// FIXMEDOC /** The resource named resourceName is find and read in using
private static Properties getPropertiesFromResource(Class resourceHolder, * resourceHolder for guidance. Default properties are provided
* by defaults if it is non-null. If suppressErrors is true, no
* exceptions will be thrown in normal operation. Otherwise, an
* unchecked exception may be thrown upon error. */
public static Properties getPropertiesFromResource(Class resourceHolder,
String resourceName, String resourceName,
boolean suppressErrors, boolean suppressErrors,
Properties defaults) Properties defaults)