Changed many /* */ comments regarding fields to Javadoc (/** */)
comments. Reformatted the code in processTibetan() in an attempt to understand what it does. I'll soon commit some code that updates a status bar with "what Jskad is thinking" in this maze of control flow.
This commit is contained in:
parent
7bf2a0e574
commit
3f9e23cdcd
1 changed files with 49 additions and 63 deletions
|
@ -45,7 +45,7 @@ import org.thdl.util.ThdlDebug;
|
||||||
* @version 1.0
|
* @version 1.0
|
||||||
*/
|
*/
|
||||||
public class DuffPane extends JTextPane implements KeyListener, FocusListener {
|
public class DuffPane extends JTextPane implements KeyListener, FocusListener {
|
||||||
/*
|
/**
|
||||||
* A central part of the Tibetan keyboard. As keys are typed, they are
|
* A central part of the Tibetan keyboard. As keys are typed, they are
|
||||||
* added to charList if they constitute a valid Wylie character. charList
|
* added to charList if they constitute a valid Wylie character. charList
|
||||||
* is added to in this manner until the user types punctuation, a vowel,
|
* is added to in this manner until the user types punctuation, a vowel,
|
||||||
|
@ -54,7 +54,7 @@ public class DuffPane extends JTextPane implements KeyListener, FocusListener {
|
||||||
* of charList.
|
* of charList.
|
||||||
*/
|
*/
|
||||||
private java.util.ArrayList charList;
|
private java.util.ArrayList charList;
|
||||||
/*
|
/**
|
||||||
* This field holds a copy of the last {@link #newGlyphList}.
|
* This field holds a copy of the last {@link #newGlyphList}.
|
||||||
* Then, when a key is pressed, {@link #charList} is updated, a new
|
* Then, when a key is pressed, {@link #charList} is updated, a new
|
||||||
* newGlyphList is computed, and the newGlyphList is compared against
|
* newGlyphList is computed, and the newGlyphList is compared against
|
||||||
|
@ -62,7 +62,7 @@ public class DuffPane extends JTextPane implements KeyListener, FocusListener {
|
||||||
* the new newGlyphList.
|
* the new newGlyphList.
|
||||||
*/
|
*/
|
||||||
private java.util.List oldGlyphList;
|
private java.util.List oldGlyphList;
|
||||||
/*
|
/**
|
||||||
* A central component of the Tibetan input method. While {@link #charList charList}
|
* A central component of the Tibetan input method. While {@link #charList charList}
|
||||||
* keeps track of the characters that have been entered, it does not organize them
|
* keeps track of the characters that have been entered, it does not organize them
|
||||||
* correctly into the proper glyphs. For example, charList might have four characters
|
* correctly into the proper glyphs. For example, charList might have four characters
|
||||||
|
@ -73,7 +73,7 @@ public class DuffPane extends JTextPane implements KeyListener, FocusListener {
|
||||||
* which constructs an optimal arrangement of glyphs from the charList.
|
* which constructs an optimal arrangement of glyphs from the charList.
|
||||||
*/
|
*/
|
||||||
private java.util.List newGlyphList;
|
private java.util.List newGlyphList;
|
||||||
/*
|
/**
|
||||||
* This field keeps track of what is currently being typed, to account
|
* This field keeps track of what is currently being typed, to account
|
||||||
* for characters (such as Wylie 'tsh') which correspond to more than one
|
* for characters (such as Wylie 'tsh') which correspond to more than one
|
||||||
* keystroke in the keyboard. It is cleared or readjusted when it is clear
|
* keystroke in the keyboard. It is cleared or readjusted when it is clear
|
||||||
|
@ -82,31 +82,33 @@ public class DuffPane extends JTextPane implements KeyListener, FocusListener {
|
||||||
* a valid character.
|
* a valid character.
|
||||||
*/
|
*/
|
||||||
private StringBuffer holdCurrent;
|
private StringBuffer holdCurrent;
|
||||||
/*
|
/**
|
||||||
* This field says whether or not the character atop {@link #charList} has
|
* This field says whether or not the character atop {@link #charList}
|
||||||
* been finalized, and therefore whether subsequent keystrokes are
|
* has been finalized, and therefore whether subsequent keystrokes are
|
||||||
* allowed to displace this character. For example, if 'k' is at the top
|
* allowed to displace this character. For example, if 'k' is at the
|
||||||
* of charList, and isTopHypothesis is true, then typing 'h' would replace
|
* top of charList, and isTopHypothesis is true, then typing 'h' would
|
||||||
* 'k' with 'kh'. On the other hand, were isTopHypothesis false, then typing
|
* replace 'k' with 'kh'. On the other hand, were isTopHypothesis
|
||||||
* 'h' would add 'h' to the top of charList instead.
|
* false, then typing 'h' would add 'h' to the top of charList instead.
|
||||||
|
* In short, is the top character on {@link #charList} a fact or just a
|
||||||
|
* hypothesis?
|
||||||
*/
|
*/
|
||||||
private boolean isTopHypothesis;
|
private boolean isTopHypothesis;
|
||||||
/*
|
/**
|
||||||
* Is the user in the process of typing a vowel?
|
* Is the user in the process of typing a vowel?
|
||||||
*/
|
*/
|
||||||
private boolean isTypingVowel;
|
private boolean isTypingVowel;
|
||||||
/*
|
/**
|
||||||
* Is it definitely the case that the user is typing Tibetan, rather than
|
* Is it definitely the case that the user is typing Tibetan, rather than
|
||||||
* Sanskrit?
|
* Sanskrit?
|
||||||
*/
|
*/
|
||||||
private boolean isDefinitelyTibetan;
|
private boolean isDefinitelyTibetan;
|
||||||
/*
|
/**
|
||||||
* According to the active keyboard, what value is
|
* According to the active keyboard, what value is
|
||||||
* {@link #isDefinitelyTibetan} assigned by default when the
|
* {@link #isDefinitelyTibetan} assigned by default when the
|
||||||
* keyboard is initialized by {@link #initKeyboard() initKeyboard}?
|
* keyboard is initialized by {@link #initKeyboard() initKeyboard}?
|
||||||
*/
|
*/
|
||||||
private boolean isDefinitelyTibetan_default;
|
private boolean isDefinitelyTibetan_default;
|
||||||
/*
|
/**
|
||||||
* According to the active keyboard, what value should
|
* According to the active keyboard, what value should
|
||||||
* be assigned to {@link #isDefinitelyTibetan} if the
|
* be assigned to {@link #isDefinitelyTibetan} if the
|
||||||
* user has initiated a stack by typing a stack key?
|
* user has initiated a stack by typing a stack key?
|
||||||
|
@ -117,18 +119,18 @@ public class DuffPane extends JTextPane implements KeyListener, FocusListener {
|
||||||
* be Sanskrit, not Tibetan.
|
* be Sanskrit, not Tibetan.
|
||||||
*/
|
*/
|
||||||
private boolean isDefinitelyTibetan_withStackKey;
|
private boolean isDefinitelyTibetan_withStackKey;
|
||||||
/*
|
/**
|
||||||
* Is it definitely the case that the user is typing Sanskrit
|
* Is it definitely the case that the user is typing Sanskrit
|
||||||
* (e.g. a Sanskrit stack), rather than Tibetan?
|
* (e.g. a Sanskrit stack), rather than Tibetan?
|
||||||
*/
|
*/
|
||||||
private boolean isDefinitelySanskrit;
|
private boolean isDefinitelySanskrit;
|
||||||
/*
|
/**
|
||||||
* According to the active keyboard, what value is
|
* According to the active keyboard, what value is
|
||||||
* {@link #isDefinitelySanskrit} assigned by default when the
|
* {@link #isDefinitelySanskrit} assigned by default when the
|
||||||
* keyboard is initialized by {@link #initKeyboard() initKeyboard}?
|
* keyboard is initialized by {@link #initKeyboard() initKeyboard}?
|
||||||
*/
|
*/
|
||||||
private boolean isDefinitelySanskrit_default;
|
private boolean isDefinitelySanskrit_default;
|
||||||
/*
|
/**
|
||||||
* According to the active keyboard, what value should
|
* According to the active keyboard, what value should
|
||||||
* be assigned to {@link #isDefinitelySanskrit} if the
|
* be assigned to {@link #isDefinitelySanskrit} if the
|
||||||
* user has initiated a stack by typing a stack key?
|
* user has initiated a stack by typing a stack key?
|
||||||
|
@ -139,7 +141,7 @@ public class DuffPane extends JTextPane implements KeyListener, FocusListener {
|
||||||
* be Sanskrit, not Tibetan.
|
* be Sanskrit, not Tibetan.
|
||||||
*/
|
*/
|
||||||
private boolean isDefinitelySanskrit_withStackKey;
|
private boolean isDefinitelySanskrit_withStackKey;
|
||||||
/*
|
/**
|
||||||
* Is consonant stacking allowed at the moment? In the Wylie
|
* Is consonant stacking allowed at the moment? In the Wylie
|
||||||
* keyboard, consonant stacking is usually on, since stacking
|
* keyboard, consonant stacking is usually on, since stacking
|
||||||
* is automatic. However, in the TCC and Sambhota keyboards,
|
* is automatic. However, in the TCC and Sambhota keyboards,
|
||||||
|
@ -147,12 +149,12 @@ public class DuffPane extends JTextPane implements KeyListener, FocusListener {
|
||||||
* you've pressed a stacking key.
|
* you've pressed a stacking key.
|
||||||
*/
|
*/
|
||||||
private boolean isStackingOn;
|
private boolean isStackingOn;
|
||||||
/*
|
/**
|
||||||
* According to the active keyboard, is stacking on by
|
* According to the active keyboard, is stacking on by
|
||||||
* default or not, assuming no stack key has been pressed?
|
* default or not, assuming no stack key has been pressed?
|
||||||
*/
|
*/
|
||||||
private boolean isStackingOn_default;
|
private boolean isStackingOn_default;
|
||||||
/*
|
/**
|
||||||
* Automatic stacking in Wylie is from right to left. For
|
* Automatic stacking in Wylie is from right to left. For
|
||||||
* example, if the user types 'brg', the resulting glyph
|
* example, if the user types 'brg', the resulting glyph
|
||||||
* sequence is 'b' plus 'rg', not 'br' plus 'g'. If
|
* sequence is 'b' plus 'rg', not 'br' plus 'g'. If
|
||||||
|
@ -160,32 +162,32 @@ public class DuffPane extends JTextPane implements KeyListener, FocusListener {
|
||||||
* it is from left to right.
|
* it is from left to right.
|
||||||
*/
|
*/
|
||||||
private boolean isStackingRightToLeft;
|
private boolean isStackingRightToLeft;
|
||||||
/*
|
/**
|
||||||
* If the character last displayed was a vowel,
|
* If the character last displayed was a vowel,
|
||||||
* how many glyphs is the vowel composed of?
|
* how many glyphs is the vowel composed of?
|
||||||
* (Some vowels, such as Wylie 'I', consist of
|
* (Some vowels, such as Wylie 'I', consist of
|
||||||
* two glyphs.)
|
* two glyphs.)
|
||||||
*/
|
*/
|
||||||
private int numberOfGlyphsForLastVowel;
|
private int numberOfGlyphsForLastVowel;
|
||||||
/*
|
/**
|
||||||
* used for tracking changes in Wylie to TMW conversion
|
* used for tracking changes in Wylie to TMW conversion
|
||||||
*/
|
*/
|
||||||
private int lastStart;
|
private int lastStart;
|
||||||
/*
|
/**
|
||||||
* is the user in Tibetan typing mode? this is true
|
* is the user in Tibetan typing mode? this is true
|
||||||
* by default
|
* by default
|
||||||
*/
|
*/
|
||||||
private boolean isTibetan = true;
|
private boolean isTibetan = true;
|
||||||
/*
|
/**
|
||||||
* is the user allowed to type non-Tibetan? this is true
|
* is the user allowed to type non-Tibetan? this is true
|
||||||
* by default
|
* by default
|
||||||
*/
|
*/
|
||||||
private boolean isRomanEnabled = true;
|
private boolean isRomanEnabled = true;
|
||||||
/*
|
/**
|
||||||
* The document displayed by this object.
|
* The document displayed by this object.
|
||||||
*/
|
*/
|
||||||
private TibetanDocument doc;
|
private TibetanDocument doc;
|
||||||
/*
|
/**
|
||||||
* The caret of {@link #doc}, used to keep track of the
|
* The caret of {@link #doc}, used to keep track of the
|
||||||
* current entry/edit/deletion position.
|
* current entry/edit/deletion position.
|
||||||
*/
|
*/
|
||||||
|
@ -378,7 +380,7 @@ public RTFEditorKit rtfEd = null;
|
||||||
* could be part of a stack, or require manipulation of glyphs - e.g.
|
* could be part of a stack, or require manipulation of glyphs - e.g.
|
||||||
* backspacing, redrawing, etc.
|
* backspacing, redrawing, etc.
|
||||||
*/
|
*/
|
||||||
public void initKeyboard() {
|
private void initKeyboard() {
|
||||||
charList.clear();
|
charList.clear();
|
||||||
oldGlyphList.clear();
|
oldGlyphList.clear();
|
||||||
holdCurrent = new StringBuffer();
|
holdCurrent = new StringBuffer();
|
||||||
|
@ -1070,10 +1072,9 @@ public void paste(int offset) {
|
||||||
if (TibetanMachineWeb.isStackingMedial()) {
|
if (TibetanMachineWeb.isStackingMedial()) {
|
||||||
int size = charList.size();
|
int size = charList.size();
|
||||||
|
|
||||||
if (size == 0)
|
if (size == 0) {
|
||||||
initKeyboard();
|
initKeyboard();
|
||||||
|
} else if (size > 1 && isStackingRightToLeft) {
|
||||||
else if (size > 1 && isStackingRightToLeft) {
|
|
||||||
String s = (String)charList.remove(charList.size() - 1);
|
String s = (String)charList.remove(charList.size() - 1);
|
||||||
newGlyphList = TibetanDocument.getGlyphs(charList, isStackingRightToLeft, isDefinitelyTibetan, isDefinitelySanskrit);
|
newGlyphList = TibetanDocument.getGlyphs(charList, isStackingRightToLeft, isDefinitelyTibetan, isDefinitelySanskrit);
|
||||||
oldGlyphList = redrawGlyphs(oldGlyphList, newGlyphList);
|
oldGlyphList = redrawGlyphs(oldGlyphList, newGlyphList);
|
||||||
|
@ -1087,8 +1088,7 @@ public void paste(int offset) {
|
||||||
isStackingRightToLeft = false;
|
isStackingRightToLeft = false;
|
||||||
isDefinitelyTibetan = isDefinitelyTibetan_withStackKey;
|
isDefinitelyTibetan = isDefinitelyTibetan_withStackKey;
|
||||||
isDefinitelySanskrit = isDefinitelySanskrit_withStackKey;
|
isDefinitelySanskrit = isDefinitelySanskrit_withStackKey;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
holdCurrent = new StringBuffer();
|
holdCurrent = new StringBuffer();
|
||||||
isTopHypothesis = false;
|
isTopHypothesis = false;
|
||||||
isStackingOn = true;
|
isStackingOn = true;
|
||||||
|
@ -1118,8 +1118,7 @@ public void paste(int offset) {
|
||||||
isStackingRightToLeft = false;
|
isStackingRightToLeft = false;
|
||||||
isDefinitelyTibetan = isDefinitelyTibetan_withStackKey;
|
isDefinitelyTibetan = isDefinitelyTibetan_withStackKey;
|
||||||
isDefinitelySanskrit = isDefinitelySanskrit_withStackKey;
|
isDefinitelySanskrit = isDefinitelySanskrit_withStackKey;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
initKeyboard();
|
initKeyboard();
|
||||||
DuffCode dc = new DuffCode(fontNum, ch);
|
DuffCode dc = new DuffCode(fontNum, ch);
|
||||||
|
|
||||||
|
@ -1168,7 +1167,7 @@ public void paste(int offset) {
|
||||||
}
|
}
|
||||||
|
|
||||||
initKeyboard();
|
initKeyboard();
|
||||||
return;
|
break key_block; /* DLC is this right? */
|
||||||
}
|
}
|
||||||
|
|
||||||
if (charList.size()==0) { //add current character to charList if possible
|
if (charList.size()==0) { //add current character to charList if possible
|
||||||
|
@ -1183,8 +1182,7 @@ public void paste(int offset) {
|
||||||
|
|
||||||
putVowel(s);
|
putVowel(s);
|
||||||
isTypingVowel = true;
|
isTypingVowel = true;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
if (isTypingVowel) {
|
if (isTypingVowel) {
|
||||||
isTypingVowel = false;
|
isTypingVowel = false;
|
||||||
s = String.valueOf(c);
|
s = String.valueOf(c);
|
||||||
|
@ -1195,20 +1193,16 @@ public void paste(int offset) {
|
||||||
s = TibetanMachineWeb.getWylieForVowel(s);
|
s = TibetanMachineWeb.getWylieForVowel(s);
|
||||||
putVowel(s);
|
putVowel(s);
|
||||||
isTypingVowel = true;
|
isTypingVowel = true;
|
||||||
}
|
} else if (TibetanMachineWeb.isChar(s)) {
|
||||||
|
|
||||||
else if (TibetanMachineWeb.isChar(s)) {
|
|
||||||
s = TibetanMachineWeb.getWylieForChar(s);
|
s = TibetanMachineWeb.getWylieForChar(s);
|
||||||
charList.add(s);
|
charList.add(s);
|
||||||
isTopHypothesis = true;
|
isTopHypothesis = true;
|
||||||
newGlyphList = TibetanDocument.getGlyphs(charList, isStackingRightToLeft, isDefinitelyTibetan, isDefinitelySanskrit);
|
newGlyphList = TibetanDocument.getGlyphs(charList, isStackingRightToLeft, isDefinitelyTibetan, isDefinitelySanskrit);
|
||||||
oldGlyphList = redrawGlyphs(oldGlyphList, newGlyphList);
|
oldGlyphList = redrawGlyphs(oldGlyphList, newGlyphList);
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
isTopHypothesis = false;
|
isTopHypothesis = false;
|
||||||
}
|
}
|
||||||
}
|
} else { //there is already a character in charList
|
||||||
else { //there is already a character in charList
|
|
||||||
holdCurrent.append(c);
|
holdCurrent.append(c);
|
||||||
String s = holdCurrent.toString();
|
String s = holdCurrent.toString();
|
||||||
|
|
||||||
|
@ -1217,8 +1211,7 @@ public void paste(int offset) {
|
||||||
initKeyboard();
|
initKeyboard();
|
||||||
isTypingVowel = true;
|
isTypingVowel = true;
|
||||||
putVowel(s);
|
putVowel(s);
|
||||||
}
|
} else if (TibetanMachineWeb.isChar(s)) { //the holding string is a character
|
||||||
else if (TibetanMachineWeb.isChar(s)) { //the holding string is a character
|
|
||||||
String s2 = TibetanMachineWeb.getWylieForChar(s);
|
String s2 = TibetanMachineWeb.getWylieForChar(s);
|
||||||
|
|
||||||
if (isTopHypothesis) {
|
if (isTopHypothesis) {
|
||||||
|
@ -1233,13 +1226,11 @@ public void paste(int offset) {
|
||||||
charList.set(charList.size()-1, s2);
|
charList.set(charList.size()-1, s2);
|
||||||
newGlyphList = TibetanDocument.getGlyphs(charList, isStackingRightToLeft, isDefinitelyTibetan, isDefinitelySanskrit);
|
newGlyphList = TibetanDocument.getGlyphs(charList, isStackingRightToLeft, isDefinitelyTibetan, isDefinitelySanskrit);
|
||||||
oldGlyphList = redrawGlyphs(oldGlyphList, newGlyphList);
|
oldGlyphList = redrawGlyphs(oldGlyphList, newGlyphList);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
if (!isStackingOn) {
|
if (!isStackingOn) {
|
||||||
initKeyboard();
|
initKeyboard();
|
||||||
holdCurrent = new StringBuffer(s);
|
holdCurrent = new StringBuffer(s);
|
||||||
}
|
} else if (TibetanMachineWeb.isAChungConsonant() && s2.equals(TibetanMachineWeb.ACHUNG)) {
|
||||||
else if (TibetanMachineWeb.isAChungConsonant() && s2.equals(TibetanMachineWeb.ACHUNG)) {
|
|
||||||
putVowel(TibetanMachineWeb.A_VOWEL);
|
putVowel(TibetanMachineWeb.A_VOWEL);
|
||||||
initKeyboard();
|
initKeyboard();
|
||||||
break key_block;
|
break key_block;
|
||||||
|
@ -1250,8 +1241,7 @@ public void paste(int offset) {
|
||||||
newGlyphList = TibetanDocument.getGlyphs(charList, isStackingRightToLeft, isDefinitelyTibetan, isDefinitelySanskrit);
|
newGlyphList = TibetanDocument.getGlyphs(charList, isStackingRightToLeft, isDefinitelyTibetan, isDefinitelySanskrit);
|
||||||
oldGlyphList = redrawGlyphs(oldGlyphList, newGlyphList);
|
oldGlyphList = redrawGlyphs(oldGlyphList, newGlyphList);
|
||||||
}
|
}
|
||||||
}
|
} else { //the holding string is not a character
|
||||||
else { //the holding string is not a character
|
|
||||||
if (isTopHypothesis) { //finalize top character and add new hypothesis to top
|
if (isTopHypothesis) { //finalize top character and add new hypothesis to top
|
||||||
holdCurrent = new StringBuffer();
|
holdCurrent = new StringBuffer();
|
||||||
holdCurrent.append(c);
|
holdCurrent.append(c);
|
||||||
|
@ -1263,18 +1253,16 @@ public void paste(int offset) {
|
||||||
initKeyboard();
|
initKeyboard();
|
||||||
isTypingVowel = true;
|
isTypingVowel = true;
|
||||||
holdCurrent = new StringBuffer(s);
|
holdCurrent = new StringBuffer(s);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
if (TibetanMachineWeb.isStackingMedial() && !isStackingRightToLeft)
|
if (TibetanMachineWeb.isStackingMedial() && !isStackingRightToLeft)
|
||||||
initKeyboard();
|
initKeyboard();
|
||||||
|
|
||||||
if (TibetanMachineWeb.isChar(s)) {
|
if (TibetanMachineWeb.isChar(s)) {
|
||||||
String s2 = TibetanMachineWeb.getWylieForChar(s);
|
String s2 = TibetanMachineWeb.getWylieForChar(s);
|
||||||
|
|
||||||
if (!isStackingOn)
|
if (!isStackingOn) {
|
||||||
initKeyboard();
|
initKeyboard();
|
||||||
|
} else if (TibetanMachineWeb.isAChungConsonant() && s2.equals(TibetanMachineWeb.ACHUNG)) {
|
||||||
else if (TibetanMachineWeb.isAChungConsonant() && s2.equals(TibetanMachineWeb.ACHUNG)) {
|
|
||||||
putVowel(TibetanMachineWeb.A_VOWEL);
|
putVowel(TibetanMachineWeb.A_VOWEL);
|
||||||
initKeyboard();
|
initKeyboard();
|
||||||
break key_block;
|
break key_block;
|
||||||
|
@ -1283,14 +1271,12 @@ public void paste(int offset) {
|
||||||
charList.add(s2);
|
charList.add(s2);
|
||||||
newGlyphList = TibetanDocument.getGlyphs(charList, isStackingRightToLeft, isDefinitelyTibetan, isDefinitelySanskrit);
|
newGlyphList = TibetanDocument.getGlyphs(charList, isStackingRightToLeft, isDefinitelyTibetan, isDefinitelySanskrit);
|
||||||
oldGlyphList = redrawGlyphs(oldGlyphList, newGlyphList);
|
oldGlyphList = redrawGlyphs(oldGlyphList, newGlyphList);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
holdCurrent = new StringBuffer(s);
|
holdCurrent = new StringBuffer(s);
|
||||||
isTopHypothesis = false;
|
isTopHypothesis = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else { //top char is just a guess! just keep it in holdCurrent
|
||||||
else { //top char is just a guess! just keep it in holdCurrent
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue