Moved JskadKeyboard-related code into separate files; made many things public.

This commit is contained in:
dchandler 2002-10-26 17:40:51 +00:00
parent 3ee1fbd3fa
commit b6b8cd73ff
4 changed files with 249 additions and 170 deletions

View file

@ -958,173 +958,3 @@ public class Jskad extends JPanel implements DocumentListener {
}
}
}
/** A JskadKeyboard is the high-level view of a Tibetan-input keyboard
that Jskad has. Each keyboard is associated with a .ini file
(except for the built-in, extended Wylie keyboard), an RTF
document for end users, and a short identifying string. */
class JskadKeyboard {
/** Cached RTFPane displaying the contents of the .rtf "quick
reference" file associated with this keyboard. */
private RTFPane keybdRTFPane = null;
/* the .rtf file named here better be included in the jar in the
same directory as 'Jskad.class': */
/** an optional RTF document */
private String keybdQuickRefFile;
/** a short identifying string */
private String keybdId;
/** the name of the .ini file for this keyboard */
private String keybdIniFile;
/** the associated .ini file, which is read in only when needed
and only once */
private URL tibKeybdURL = null;
/** Creates a new JskadKeyboard.
* @param identifyingString a short string used in the GUI to
* identify this keyboard
* @param dotIniResourceName the name of the .ini file used to
* initialize this keyboard, or null for the built-in extended
* Wylie keyboard
* @param RTFResourceName the optional name of the .rtf file that
* gives users a quick reference to this keyboard (null if no
* such file is available) */
public JskadKeyboard(String identifyingString,
String dotIniResourceName,
String RTFResourceName) {
keybdId = identifyingString;
keybdIniFile = dotIniResourceName;
keybdQuickRefFile = RTFResourceName;
}
/** Returns an RTFPane displaying the contents of the "Quick
* Reference" .rtf file associated with this keyboard, or null if
* no such file is associated with this keyboard. */
public RTFPane getQuickRefPane() {
if (!hasQuickRefFile())
return null;
if (keybdRTFPane == null) {
try {
keybdRTFPane = new RTFPane(Jskad.class, keybdQuickRefFile);
} catch (Exception e) {
e.printStackTrace(System.err);
throw new ThdlLazyException(e); /* FIXME--handle this better. */
}
}
return keybdRTFPane;
}
/** Returns true iff there is a "Quick Reference" document
associated with this keyboard. */
public boolean hasQuickRefFile() {
return (keybdQuickRefFile != null);
}
/** Returns the short identifying string associated with this
* keyboard. */
public String getIdentifyingString() {
return keybdId;
}
/** Activates this keyboard for the given DuffPane.
* @param dp the DuffPane for which this keyboard will be made
* the active keyboard */
public void activate(DuffPane dp) {
if (keybdIniFile != null) {
URL tibKeybdURL
= TibetanMachineWeb.class.getResource(keybdIniFile);
if (null == tibKeybdURL)
throw new Error("Cannot load the keyboard initialization resource "
+ keybdIniFile);
dp.registerKeyboard(tibKeybdURL);
} else {
dp.registerKeyboard();
}
}
}
/** Determines which Tibetan keyboards Jskad supports. Adding a
new one is as easy as adding 3 lines of text here. */
class JskadKeyboardFactory {
static JskadKeyboard[] getAllAvailableJskadKeyboards() {
return new JskadKeyboard[] {
new JskadKeyboard("Extended Wylie Keyboard",
null,
"Wylie_keyboard.rtf"),
new JskadKeyboard("TCC Keyboard #1",
"tcc_keyboard_1.ini",
"TCC_keyboard_1.rtf"),
new JskadKeyboard("TCC Keyboard #2",
"tcc_keyboard_2.ini",
"TCC_keyboard_2.rtf"),
new JskadKeyboard("Sambhota Keymap One",
"sambhota_keyboard_1.ini",
"Sambhota_keymap_one.rtf"),
new JskadKeyboard("Asian Classics Input Project (ACIP) Keyboard",
"acip_keyboard.ini",
null)
};
}
}
/** A JskadKeyboardManager maintains a list of JskadKeyboards. */
class JskadKeyboardManager {
/** A Vector of JskadKeyboards. Users will see the first
* keyboards most prominently. */
private Vector keybds;
/** Creates a manager without any keyboards in it, even the
* built-in extended Wylie keyboard. */
JskadKeyboardManager() {
keybds = new Vector(5);
}
/** Creates a manager with the specified keyboards in it. The
* keyboard at index 0 will be the most prominent in the user's
* eyes. */
JskadKeyboardManager(JskadKeyboard keyboards[])
throws NullPointerException
{
this();
for (int i = 0; i < keyboards.length; i++) {
addKeyboard(keyboards[i]);
}
}
/** Adds a JskadKeyboard to this manager. It will be the least
* prominent in the user's eyes of any yet added. */
void addKeyboard(JskadKeyboard keybd)
throws NullPointerException
{
if (null == keybd)
throw new NullPointerException();
keybds.add((Object)keybd);
}
/** Returns the JskadKeyboard at the zero-based index. */
JskadKeyboard elementAt(int index)
throws ArrayIndexOutOfBoundsException
{
return (JskadKeyboard)keybds.elementAt(index);
}
/** Returns the number of JskadKeyboards being managed. */
int size() {
return keybds.size();
}
/** Returns an array of the identifying strings associated with
* all managed keyboards. */
String[] getIdentifyingStrings() {
String x[] = new String[size()];
for (int i = 0; i < size(); i++) {
x[i] = elementAt(i).getIdentifyingString();
}
return x;
}
}