Moved JskadKeyboard-related code into separate files; made many things public.
This commit is contained in:
parent
3ee1fbd3fa
commit
b6b8cd73ff
4 changed files with 249 additions and 170 deletions
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
117
source/org/thdl/tib/input/JskadKeyboard.java
Normal file
117
source/org/thdl/tib/input/JskadKeyboard.java
Normal file
|
@ -0,0 +1,117 @@
|
|||
/*
|
||||
The contents of this file are subject to the THDL Open Community License
|
||||
Version 1.0 (the "License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License on the THDL web site
|
||||
(http://www.thdl.org/).
|
||||
|
||||
Software distributed under the License is distributed on an "AS IS" basis,
|
||||
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
|
||||
License for the specific terms governing rights and limitations under the
|
||||
License.
|
||||
|
||||
The Initial Developer of this software is the Tibetan and Himalayan Digital
|
||||
Library (THDL). Portions created by the THDL are Copyright 2001 THDL.
|
||||
All Rights Reserved.
|
||||
|
||||
Contributor(s): ______________________________________.
|
||||
*/
|
||||
|
||||
package org.thdl.tib.input;
|
||||
|
||||
import java.util.Vector;
|
||||
import java.net.URL;
|
||||
|
||||
import org.thdl.util.RTFPane;
|
||||
import org.thdl.util.ThdlLazyException;
|
||||
import org.thdl.tib.text.TibetanMachineWeb;
|
||||
import org.thdl.tib.input.DuffPane;
|
||||
|
||||
/** 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.
|
||||
|
||||
@author David Chandler
|
||||
*/
|
||||
public 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();
|
||||
}
|
||||
}
|
||||
}
|
48
source/org/thdl/tib/input/JskadKeyboardFactory.java
Normal file
48
source/org/thdl/tib/input/JskadKeyboardFactory.java
Normal file
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
The contents of this file are subject to the THDL Open Community License
|
||||
Version 1.0 (the "License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License on the THDL web site
|
||||
(http://www.thdl.org/).
|
||||
|
||||
Software distributed under the License is distributed on an "AS IS" basis,
|
||||
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
|
||||
License for the specific terms governing rights and limitations under the
|
||||
License.
|
||||
|
||||
The Initial Developer of this software is the Tibetan and Himalayan Digital
|
||||
Library (THDL). Portions created by the THDL are Copyright 2001 THDL.
|
||||
All Rights Reserved.
|
||||
|
||||
Contributor(s): ______________________________________.
|
||||
*/
|
||||
|
||||
package org.thdl.tib.input;
|
||||
|
||||
import org.thdl.tib.input.JskadKeyboard;
|
||||
|
||||
/** A JskadKeyboardFactory determines which Tibetan keyboards Jskad
|
||||
supports. Adding a new one is as easy as adding 3 lines of text
|
||||
to this class's source code.
|
||||
*/
|
||||
public class JskadKeyboardFactory {
|
||||
public 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)
|
||||
};
|
||||
}
|
||||
}
|
||||
|
84
source/org/thdl/tib/input/JskadKeyboardManager.java
Normal file
84
source/org/thdl/tib/input/JskadKeyboardManager.java
Normal file
|
@ -0,0 +1,84 @@
|
|||
/*
|
||||
The contents of this file are subject to the THDL Open Community License
|
||||
Version 1.0 (the "License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License on the THDL web site
|
||||
(http://www.thdl.org/).
|
||||
|
||||
Software distributed under the License is distributed on an "AS IS" basis,
|
||||
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
|
||||
License for the specific terms governing rights and limitations under the
|
||||
License.
|
||||
|
||||
The Initial Developer of this software is the Tibetan and Himalayan Digital
|
||||
Library (THDL). Portions created by the THDL are Copyright 2001 THDL.
|
||||
All Rights Reserved.
|
||||
|
||||
Contributor(s): ______________________________________.
|
||||
*/
|
||||
|
||||
package org.thdl.tib.input;
|
||||
|
||||
import java.util.Vector;
|
||||
|
||||
import org.thdl.tib.input.JskadKeyboard;
|
||||
|
||||
/** A JskadKeyboardManager maintains a list of JskadKeyboards.
|
||||
|
||||
@author David Chandler
|
||||
*/
|
||||
public 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. */
|
||||
public 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. */
|
||||
public 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. */
|
||||
public void addKeyboard(JskadKeyboard keybd)
|
||||
throws NullPointerException
|
||||
{
|
||||
if (null == keybd)
|
||||
throw new NullPointerException();
|
||||
keybds.add((Object)keybd);
|
||||
}
|
||||
|
||||
/** Returns the JskadKeyboard at the zero-based index. */
|
||||
public JskadKeyboard elementAt(int index)
|
||||
throws ArrayIndexOutOfBoundsException
|
||||
{
|
||||
return (JskadKeyboard)keybds.elementAt(index);
|
||||
}
|
||||
|
||||
/** Returns the number of JskadKeyboards being managed. */
|
||||
public int size() {
|
||||
return keybds.size();
|
||||
}
|
||||
|
||||
/** Returns an array of the identifying strings associated with
|
||||
* all managed keyboards. */
|
||||
|
||||
public String[] getIdentifyingStrings() {
|
||||
String x[] = new String[size()];
|
||||
for (int i = 0; i < size(); i++) {
|
||||
x[i] = elementAt(i).getIdentifyingString();
|
||||
}
|
||||
return x;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue