Factored TibetanDocument into two classes, one that is a

DefaultStyledDocument, and another consisting entirely of static utility
methods for processing Tibetan text.  Moved TibetanDocument.DuffData
into its own class.

I think this makes things a bit more transparent, and gets us a little closer to
making clean use of Swing.
This commit is contained in:
dchandler 2002-11-02 03:38:59 +00:00
parent 5249c48807
commit abcf8f19b3
25 changed files with 1490 additions and 1337 deletions

View file

@ -34,7 +34,6 @@ import java.lang.reflect.*;
import org.thdl.tib.input.*; import org.thdl.tib.input.*;
import org.thdl.tib.text.*; import org.thdl.tib.text.*;
import org.thdl.tib.text.TibetanDocument.*;
import org.thdl.savant.JdkVersionHacks; import org.thdl.savant.JdkVersionHacks;
import org.thdl.media.*; import org.thdl.media.*;
@ -80,6 +79,8 @@ public class QD extends JDesktopPane {
public Style componentStyle; public Style componentStyle;
public DataFlavor timeFlavor; public DataFlavor timeFlavor;
/** Either "qt4j" or "jmf", corresponding to the thdl.media.player
property. */
protected String thdl_mediaplayer_property = null; protected String thdl_mediaplayer_property = null;
//class fields because they are affected depending on whether we're //class fields because they are affected depending on whether we're
@ -95,8 +96,8 @@ public class QD extends JDesktopPane {
protected DuffPane sharedDP = new DuffPane(); protected DuffPane sharedDP = new DuffPane();
protected DuffPane sharedDP2 = new DuffPane(); protected DuffPane sharedDP2 = new DuffPane();
protected TibetanDocument findDoc = null; protected AbstractDocument findDoc = null;
protected TibetanDocument replaceDoc = null; protected AbstractDocument replaceDoc = null;
protected KeyStroke cutKey, copyKey, pasteKey, selectAllKey; protected KeyStroke cutKey, copyKey, pasteKey, selectAllKey;
protected KeyStroke insert1TimeKey, insert2TimesKey, insertSpeakerKey; protected KeyStroke insert1TimeKey, insert2TimesKey, insertSpeakerKey;
@ -1385,7 +1386,7 @@ class SpeakerData extends AbstractTableModel
if (column == 0) if (column == 0)
return spIcon[sp.getIconID()]; return spIcon[sp.getIconID()];
try { //otherwise column 1, the speaker name try { //otherwise column 1, the speaker name
return TibetanDocument.getTibetanMachineWeb(sp.getName().trim()); return TibTextUtils.getTibetanMachineWeb(sp.getName().trim());
} catch (InvalidWylieException iwe) { } catch (InvalidWylieException iwe) {
iwe.printStackTrace(); iwe.printStackTrace();
ThdlDebug.noteIffyCode(); ThdlDebug.noteIffyCode();
@ -1653,7 +1654,7 @@ public void replaceText() {
java.util.List replaceDCs = new ArrayList(); java.util.List replaceDCs = new ArrayList();
for (int k=0; k<replaceDoc.getLength(); k++) for (int k=0; k<replaceDoc.getLength(); k++)
replaceDCs.add(new DuffCode(TibetanMachineWeb.getTMWFontNumber(StyleConstants.getFontFamily(replaceDoc.getCharacterElement(k).getAttributes())), replaceDoc.getText(k,1).charAt(0))); replaceDCs.add(new DuffCode(TibetanMachineWeb.getTMWFontNumber(StyleConstants.getFontFamily(replaceDoc.getCharacterElement(k).getAttributes())), replaceDoc.getText(k,1).charAt(0)));
TibetanDocument.DuffData[] dd = TibetanDocument.convertGlyphs(replaceDCs); DuffData[] dd = TibTextUtils.convertGlyphs(replaceDCs);
TibetanDocument doc = (TibetanDocument)pane.getDocument(); TibetanDocument doc = (TibetanDocument)pane.getDocument();
Position pos = doc.createPosition(pane.getCaretPosition()); Position pos = doc.createPosition(pane.getCaretPosition());

View file

@ -141,7 +141,7 @@ public class SavantShell extends JFrame
JMenu fileMenu = new JMenu("File"); JMenu fileMenu = new JMenu("File");
JMenuItem openItem = new JMenuItem("Open"); JMenuItem openItem = new JMenuItem("Open");
openItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O,2)); openItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O,java.awt.Event.CTRL_MASK));
openItem.addActionListener(new ThdlActionListener() { openItem.addActionListener(new ThdlActionListener() {
public void theRealActionPerformed(ActionEvent e) { public void theRealActionPerformed(ActionEvent e) {
if (fileChooser.showOpenDialog(SavantShell.this) != JFileChooser.APPROVE_OPTION) if (fileChooser.showOpenDialog(SavantShell.this) != JFileChooser.APPROVE_OPTION)
@ -166,7 +166,7 @@ public class SavantShell extends JFrame
}); });
JMenuItem closeItem = new JMenuItem("Close"); JMenuItem closeItem = new JMenuItem("Close");
closeItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C,2)); closeItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C,java.awt.Event.CTRL_MASK));
closeItem.addActionListener(new ThdlActionListener() closeItem.addActionListener(new ThdlActionListener()
{ {
public void theRealActionPerformed(ActionEvent e) public void theRealActionPerformed(ActionEvent e)
@ -177,7 +177,7 @@ public class SavantShell extends JFrame
}); });
JMenuItem quitItem = new JMenuItem("Quit"); JMenuItem quitItem = new JMenuItem("Quit");
quitItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q,2)); quitItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q,java.awt.Event.CTRL_MASK));
quitItem.addActionListener(new ThdlActionListener() quitItem.addActionListener(new ThdlActionListener()
{ {
public void theRealActionPerformed(ActionEvent e) public void theRealActionPerformed(ActionEvent e)

View file

@ -85,9 +85,9 @@ public class Tibetan implements TranscriptView
t2Buffer = new StringBuffer(); t2Buffer = new StringBuffer();
String thisStart, thisEnd, thisId; String thisStart, thisEnd, thisId;
Position endPos = null; Position endPos = null;
TibetanDocument.DuffData[] dd; DuffData[] dd;
TibetanDocument doc = new TibetanDocument(new StyleContext()); TibetanDocument doc = new TibetanDocument(new StyleContext());
TibetanDocument.DuffData[] space = TibetanDocument.getTibetanMachineWeb("_"); DuffData[] space = TibTextUtils.getTibetanMachineWeb("_");
MutableAttributeSet mas = new SimpleAttributeSet(); MutableAttributeSet mas = new SimpleAttributeSet();
StyleConstants.setForeground(mas, Color.blue); StyleConstants.setForeground(mas, Color.blue);
@ -99,7 +99,7 @@ public class Tibetan implements TranscriptView
while (current.getName().equals("spkr")) while (current.getName().equals("spkr"))
{ {
dd = TibetanDocument.getTibetanMachineWeb(current.getAttributeValue("who")); dd = TibTextUtils.getTibetanMachineWeb(current.getAttributeValue("who"));
if (endPos == null) if (endPos == null)
{ {
doc.insertDuff(0, dd); doc.insertDuff(0, dd);
@ -126,7 +126,7 @@ public class Tibetan implements TranscriptView
} }
wherestart = endPos.getOffset(); wherestart = endPos.getOffset();
dd = TibetanDocument.getTibetanMachineWeb(current.getText()); //from +"\n" dd = TibTextUtils.getTibetanMachineWeb(current.getText()); //from +"\n"
doc.insertDuff(endPos.getOffset(), dd); doc.insertDuff(endPos.getOffset(), dd);
startBuffer.append(String.valueOf(wherestart)+","); startBuffer.append(String.valueOf(wherestart)+",");
thisEnd = String.valueOf(endPos.getOffset()); thisEnd = String.valueOf(endPos.getOffset());
@ -145,7 +145,7 @@ public class Tibetan implements TranscriptView
while (current.getName().equals("spkr")) while (current.getName().equals("spkr"))
{ {
doc.insertString(endPos.getOffset(), "\n", null); doc.insertString(endPos.getOffset(), "\n", null);
dd = TibetanDocument.getTibetanMachineWeb(current.getAttributeValue("who")); //from +"\n" dd = TibTextUtils.getTibetanMachineWeb(current.getAttributeValue("who")); //from +"\n"
wherestart = endPos.getOffset(); wherestart = endPos.getOffset();
doc.insertDuff(endPos.getOffset(), dd); doc.insertDuff(endPos.getOffset(), dd);
doc.setCharacterAttributes(wherestart, endPos.getOffset()-wherestart, mas, false); doc.setCharacterAttributes(wherestart, endPos.getOffset()-wherestart, mas, false);
@ -155,7 +155,7 @@ public class Tibetan implements TranscriptView
doc.insertDuff(endPos.getOffset(), space); doc.insertDuff(endPos.getOffset(), space);
counter++; counter++;
dd = TibetanDocument.getTibetanMachineWeb(current.getText()); //from "+\n" dd = TibTextUtils.getTibetanMachineWeb(current.getText()); //from "+\n"
thisStart = String.valueOf(endPos.getOffset()); thisStart = String.valueOf(endPos.getOffset());
startBuffer.append(thisStart); startBuffer.append(thisStart);
startBuffer.append(','); startBuffer.append(',');

View file

@ -79,8 +79,8 @@ public class TibetanEnglish implements TranscriptView
Iterator iter = elements.iterator(); Iterator iter = elements.iterator();
Element current = null; Element current = null;
TibetanDocument.DuffData[] dd; DuffData[] dd;
TibetanDocument.DuffData[] space = TibetanDocument.getTibetanMachineWeb("_"); DuffData[] space = TibTextUtils.getTibetanMachineWeb("_");
MutableAttributeSet mas = new SimpleAttributeSet(); MutableAttributeSet mas = new SimpleAttributeSet();
StyleConstants.setForeground(mas, Color.blue); StyleConstants.setForeground(mas, Color.blue);
Position endPos = null; Position endPos = null;
@ -120,7 +120,7 @@ public class TibetanEnglish implements TranscriptView
current = (org.jdom.Element)iter.next(); current = (org.jdom.Element)iter.next();
} }
dd = TibetanDocument.getTibetanMachineWeb(current.getText()+"\n"); dd = TibTextUtils.getTibetanMachineWeb(current.getText()+"\n");
if (endPos == null) if (endPos == null)
{ {
thisStart = "0"; thisStart = "0";
@ -164,7 +164,7 @@ public class TibetanEnglish implements TranscriptView
thisStart = String.valueOf(endPos.getOffset()); thisStart = String.valueOf(endPos.getOffset());
startBuffer.append(thisStart); startBuffer.append(thisStart);
startBuffer.append(','); startBuffer.append(',');
dd = TibetanDocument.getTibetanMachineWeb(current.getText()+"\n"); dd = TibTextUtils.getTibetanMachineWeb(current.getText()+"\n");
doc.insertDuff(endPos.getOffset(), dd); doc.insertDuff(endPos.getOffset(), dd);
doc.insertString(endPos.getOffset(), current.getAttributeValue("eng"), null); doc.insertString(endPos.getOffset(), current.getAttributeValue("eng"), null);
thisEnd = String.valueOf(endPos.getOffset()); thisEnd = String.valueOf(endPos.getOffset());

View file

@ -80,8 +80,8 @@ public class TibetanWylie implements TranscriptView
Element current = null; Element current = null;
String wylie; String wylie;
TibetanDocument.DuffData[] dd; DuffData[] dd;
TibetanDocument.DuffData[] space = TibetanDocument.getTibetanMachineWeb("_"); DuffData[] space = TibTextUtils.getTibetanMachineWeb("_");
MutableAttributeSet mas = new SimpleAttributeSet(); MutableAttributeSet mas = new SimpleAttributeSet();
StyleConstants.setForeground(mas, Color.blue); StyleConstants.setForeground(mas, Color.blue);
Position endPos = null; Position endPos = null;
@ -122,7 +122,7 @@ public class TibetanWylie implements TranscriptView
} }
wylie = current.getText(); wylie = current.getText();
dd = TibetanDocument.getTibetanMachineWeb(wylie+"\n"); dd = TibTextUtils.getTibetanMachineWeb(wylie+"\n");
if (endPos == null) if (endPos == null)
{ {
thisStart = "0"; thisStart = "0";
@ -166,7 +166,7 @@ public class TibetanWylie implements TranscriptView
startBuffer.append(thisStart); startBuffer.append(thisStart);
startBuffer.append(','); startBuffer.append(',');
wylie = current.getText(); wylie = current.getText();
dd = TibetanDocument.getTibetanMachineWeb(wylie+"\n"); dd = TibTextUtils.getTibetanMachineWeb(wylie+"\n");
doc.insertDuff(endPos.getOffset(), dd); doc.insertDuff(endPos.getOffset(), dd);
doc.insertString(endPos.getOffset(), wylie, null); doc.insertString(endPos.getOffset(), wylie, null);

View file

@ -79,8 +79,8 @@ public class TibetanWylieEnglish implements TranscriptView
Iterator iter = elements.iterator(); Iterator iter = elements.iterator();
Element current = null; Element current = null;
TibetanDocument.DuffData[] dd; DuffData[] dd;
TibetanDocument.DuffData[] space = TibetanDocument.getTibetanMachineWeb("_"); DuffData[] space = TibTextUtils.getTibetanMachineWeb("_");
MutableAttributeSet mas = new SimpleAttributeSet(); MutableAttributeSet mas = new SimpleAttributeSet();
StyleConstants.setForeground(mas, Color.blue); StyleConstants.setForeground(mas, Color.blue);
MutableAttributeSet mas2 = new SimpleAttributeSet(); MutableAttributeSet mas2 = new SimpleAttributeSet();
@ -123,7 +123,7 @@ public class TibetanWylieEnglish implements TranscriptView
} }
wylie = current.getText(); wylie = current.getText();
dd = TibetanDocument.getTibetanMachineWeb(wylie+"\n"); dd = TibTextUtils.getTibetanMachineWeb(wylie+"\n");
if (endPos == null) if (endPos == null)
{ {
thisStart = "0"; thisStart = "0";
@ -168,7 +168,7 @@ public class TibetanWylieEnglish implements TranscriptView
startBuffer.append(thisStart); startBuffer.append(thisStart);
startBuffer.append(','); startBuffer.append(',');
wylie = current.getText(); wylie = current.getText();
dd = TibetanDocument.getTibetanMachineWeb(wylie+"\n"); dd = TibTextUtils.getTibetanMachineWeb(wylie+"\n");
doc.insertDuff(endPos.getOffset(), dd); doc.insertDuff(endPos.getOffset(), dd);
doc.insertString(endPos.getOffset(), wylie+"\n", mas2); doc.insertString(endPos.getOffset(), wylie+"\n", mas2);
doc.insertString(endPos.getOffset(), current.getAttributeValue("eng"), null); doc.insertString(endPos.getOffset(), current.getAttributeValue("eng"), null);

View file

@ -83,7 +83,7 @@ public class Wylie implements TranscriptView
MutableAttributeSet mas = new SimpleAttributeSet(); MutableAttributeSet mas = new SimpleAttributeSet();
StyleConstants.setForeground(mas, Color.blue); StyleConstants.setForeground(mas, Color.blue);
Position endPos = null; Position endPos = null;
TibetanDocument doc = new TibetanDocument(new StyleContext()); AbstractDocument doc = new TibetanDocument(new StyleContext());
idBuffer = new StringBuffer(); idBuffer = new StringBuffer();
startBuffer = new StringBuffer(); startBuffer = new StringBuffer();

View file

@ -79,7 +79,7 @@ public class WylieEnglish implements TranscriptView
Iterator iter = elements.iterator(); Iterator iter = elements.iterator();
Element current = null; Element current = null;
TibetanDocument.DuffData[] dd; DuffData[] dd;
MutableAttributeSet mas = new SimpleAttributeSet(); MutableAttributeSet mas = new SimpleAttributeSet();
StyleConstants.setForeground(mas, Color.blue); StyleConstants.setForeground(mas, Color.blue);
MutableAttributeSet mas2 = new SimpleAttributeSet(); MutableAttributeSet mas2 = new SimpleAttributeSet();
@ -87,7 +87,7 @@ public class WylieEnglish implements TranscriptView
Position endPos = null; Position endPos = null;
int wherestart; int wherestart;
String wylie; String wylie;
TibetanDocument doc = new TibetanDocument(new StyleContext()); AbstractDocument doc = new TibetanDocument(new StyleContext());
idBuffer = new StringBuffer(); idBuffer = new StringBuffer();
startBuffer = new StringBuffer(); startBuffer = new StringBuffer();

View file

@ -225,18 +225,6 @@ public RTFEditorKit rtfEd = null;
// this(new StyledEditorKit(), keyboardURL); // this(new StyledEditorKit(), keyboardURL);
} }
// DLC
private Action getActionByName(String name) {
Action[] actions = this.getActions();
for (int i = 0; i < actions.length; i++) {
if (actions[i].getValue(Action.NAME).equals(name)) {
return actions[i];
}
}
return null;
}
/** Creates a new DuffPane that updates sb, if sb is not null, /** Creates a new DuffPane that updates sb, if sb is not null,
with messages about how the users' keypresses are being with messages about how the users' keypresses are being
interpreted. */ interpreted. */
@ -640,7 +628,7 @@ public RTFEditorKit rtfEd = null;
backSpace(oldGlyphCount - beginDifference); backSpace(oldGlyphCount - beginDifference);
java.util.List sublist = newGlyphList.subList(k, newGlyphCount); java.util.List sublist = newGlyphList.subList(k, newGlyphCount);
TibetanDocument.DuffData[] dd = TibetanDocument.convertGlyphs(sublist); DuffData[] dd = TibTextUtils.convertGlyphs(sublist);
doc.insertDuff(caret.getDot(), dd); doc.insertDuff(caret.getDot(), dd);
return newGlyphList; return newGlyphList;
} }
@ -705,7 +693,7 @@ public RTFEditorKit rtfEd = null;
before_vowel.add(dc_1); before_vowel.add(dc_1);
before_vowel.add(dc_2); before_vowel.add(dc_2);
java.util.List after_vowel = TibetanDocument.getVowel(dc_1, dc_2, v); java.util.List after_vowel = TibTextUtils.getVowel(dc_1, dc_2, v);
redrawGlyphs(before_vowel, after_vowel); redrawGlyphs(before_vowel, after_vowel);
} }
catch(BadLocationException ble) { catch(BadLocationException ble) {
@ -728,8 +716,8 @@ public RTFEditorKit rtfEd = null;
private void printAChenWithVowel(String v) { private void printAChenWithVowel(String v) {
DuffCode[] dc_array = (DuffCode[])TibetanMachineWeb.getTibHash().get(TibetanMachineWeb.ACHEN); DuffCode[] dc_array = (DuffCode[])TibetanMachineWeb.getTibHash().get(TibetanMachineWeb.ACHEN);
DuffCode dc = dc_array[TibetanMachineWeb.TMW]; DuffCode dc = dc_array[TibetanMachineWeb.TMW];
java.util.List achenlist = TibetanDocument.getVowel(dc,v); java.util.List achenlist = TibTextUtils.getVowel(dc,v);
TibetanDocument.DuffData[] dd = TibetanDocument.convertGlyphs(achenlist); DuffData[] dd = TibTextUtils.convertGlyphs(achenlist);
doc.insertDuff(caret.getDot(), dd); doc.insertDuff(caret.getDot(), dd);
} }
@ -765,7 +753,7 @@ public RTFEditorKit rtfEd = null;
DuffCode dc = new DuffCode(fontNum, c2); DuffCode dc = new DuffCode(fontNum, c2);
java.util.List beforecaret = new ArrayList(); java.util.List beforecaret = new ArrayList();
beforecaret.add(dc); beforecaret.add(dc);
java.util.List bindulist = TibetanDocument.getBindu(dc); java.util.List bindulist = TibTextUtils.getBindu(dc);
redrawGlyphs(beforecaret, bindulist); redrawGlyphs(beforecaret, bindulist);
initKeyboard(); initKeyboard();
return; return;
@ -775,7 +763,7 @@ public RTFEditorKit rtfEd = null;
} }
} }
TibetanDocument.DuffData[] dd = TibetanDocument.convertGlyphs(TibetanDocument.getBindu(null)); DuffData[] dd = TibTextUtils.convertGlyphs(TibTextUtils.getBindu(null));
doc.insertDuff(caret.getDot(), dd); doc.insertDuff(caret.getDot(), dd);
initKeyboard(); initKeyboard();
} }
@ -1162,7 +1150,7 @@ public void paste(int offset) {
* type s-g-r, you see a single glyph, a three-letter stack, but if you * type s-g-r, you see a single glyph, a three-letter stack, but if you
* type s-d-r, you see two glyphs. If you examine the status bar, * type s-d-r, you see two glyphs. If you examine the status bar,
* you'll see that the thing determining that is * you'll see that the thing determining that is
* TibetanDocument.getGlyphs, which in turn relies on 'tibwn.ini'. * TibTextUtils.getGlyphs, which in turn relies on 'tibwn.ini'.
* *
* @param e a KeyEvent */ * @param e a KeyEvent */
public void processTibetan(KeyEvent e) { public void processTibetan(KeyEvent e) {
@ -1214,11 +1202,11 @@ public void paste(int offset) {
appendStatus(" (because you pressed the stacking key with nothing to stack on)"); appendStatus(" (because you pressed the stacking key with nothing to stack on)");
} 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 = TibTextUtils.getGlyphs(charList, isStackingRightToLeft, isDefinitelyTibetan, isDefinitelySanskrit);
oldGlyphList = redrawGlyphs(oldGlyphList, newGlyphList); oldGlyphList = redrawGlyphs(oldGlyphList, newGlyphList);
initKeyboard(); initKeyboard();
charList.add(s); charList.add(s);
newGlyphList = TibetanDocument.getGlyphs(charList, isStackingRightToLeft, isDefinitelyTibetan, isDefinitelySanskrit); newGlyphList = TibTextUtils.getGlyphs(charList, isStackingRightToLeft, isDefinitelyTibetan, isDefinitelySanskrit);
oldGlyphList = redrawGlyphs(oldGlyphList, newGlyphList); oldGlyphList = redrawGlyphs(oldGlyphList, newGlyphList);
holdCurrent = new StringBuffer(); holdCurrent = new StringBuffer();
isTopHypothesis = false; isTopHypothesis = false;
@ -1355,7 +1343,7 @@ public void paste(int offset) {
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 = TibTextUtils.getGlyphs(charList, isStackingRightToLeft, isDefinitelyTibetan, isDefinitelySanskrit);
oldGlyphList = redrawGlyphs(oldGlyphList, newGlyphList); oldGlyphList = redrawGlyphs(oldGlyphList, newGlyphList);
changedStatus = true; changedStatus = true;
updateStatus("You typed a non-vowel, Tibetan character."); updateStatus("You typed a non-vowel, Tibetan character.");
@ -1379,7 +1367,7 @@ public void paste(int offset) {
if (isTopHypothesis) { if (isTopHypothesis) {
if (TibetanMachineWeb.isAChungConsonant() && isStackingOn && charList.size()>1 && s2.equals(TibetanMachineWeb.ACHUNG)) { if (TibetanMachineWeb.isAChungConsonant() && isStackingOn && charList.size()>1 && s2.equals(TibetanMachineWeb.ACHUNG)) {
charList.remove(charList.size() - 1); charList.remove(charList.size() - 1);
newGlyphList = TibetanDocument.getGlyphs(charList, isStackingRightToLeft, isDefinitelyTibetan, isDefinitelySanskrit); newGlyphList = TibTextUtils.getGlyphs(charList, isStackingRightToLeft, isDefinitelyTibetan, isDefinitelySanskrit);
oldGlyphList = redrawGlyphs(oldGlyphList, newGlyphList); oldGlyphList = redrawGlyphs(oldGlyphList, newGlyphList);
putVowel(TibetanMachineWeb.A_VOWEL); putVowel(TibetanMachineWeb.A_VOWEL);
initKeyboard(); initKeyboard();
@ -1388,7 +1376,7 @@ public void paste(int offset) {
break key_block; break key_block;
} }
charList.set(charList.size()-1, s2); charList.set(charList.size()-1, s2);
newGlyphList = TibetanDocument.getGlyphs(charList, isStackingRightToLeft, isDefinitelyTibetan, isDefinitelySanskrit); newGlyphList = TibTextUtils.getGlyphs(charList, isStackingRightToLeft, isDefinitelyTibetan, isDefinitelySanskrit);
oldGlyphList = redrawGlyphs(oldGlyphList, newGlyphList); oldGlyphList = redrawGlyphs(oldGlyphList, newGlyphList);
} else { } else {
if (!isStackingOn) { if (!isStackingOn) {
@ -1406,7 +1394,7 @@ public void paste(int offset) {
charList.add(s2); charList.add(s2);
isTopHypothesis = true; isTopHypothesis = true;
newGlyphList = TibetanDocument.getGlyphs(charList, isStackingRightToLeft, isDefinitelyTibetan, isDefinitelySanskrit); newGlyphList = TibTextUtils.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
@ -1441,7 +1429,7 @@ public void paste(int offset) {
} }
charList.add(s2); charList.add(s2);
newGlyphList = TibetanDocument.getGlyphs(charList, isStackingRightToLeft, isDefinitelyTibetan, isDefinitelySanskrit); newGlyphList = TibTextUtils.getGlyphs(charList, isStackingRightToLeft, isDefinitelyTibetan, isDefinitelySanskrit);
oldGlyphList = redrawGlyphs(oldGlyphList, newGlyphList); oldGlyphList = redrawGlyphs(oldGlyphList, newGlyphList);
changedStatus = true; changedStatus = true;
updateStatus("added character to charList"); updateStatus("added character to charList");
@ -1511,7 +1499,7 @@ public void paste(int offset) {
dc_array = new DuffCode[0]; dc_array = new DuffCode[0];
dc_array = (DuffCode[])dcs.toArray(dc_array); dc_array = (DuffCode[])dcs.toArray(dc_array);
doc.remove(start, i-start); doc.remove(start, i-start);
append(start, TibetanDocument.getWylie(dc_array), romanAttributeSet); append(start, TibTextUtils.getWylie(dc_array), romanAttributeSet);
dcs.clear(); dcs.clear();
} }
start = i+1; start = i+1;
@ -1552,7 +1540,7 @@ public void paste(int offset) {
ThdlDebug.noteIffyCode(); ThdlDebug.noteIffyCode();
} }
} else { } else {
TibetanDocument.DuffData[] dd = TibetanDocument.getTibetanMachineWeb(next); DuffData[] dd = TibTextUtils.getTibetanMachineWeb(next);
offset = doc.insertDuff(offset, dd); offset = doc.insertDuff(offset, dd);
} }
} }
@ -1603,7 +1591,7 @@ public void paste(int offset) {
if ((0 != (fontNum = TibetanMachineWeb.getTMWFontNumber(fontName))) || i==endPos.getOffset()) { if ((0 != (fontNum = TibetanMachineWeb.getTMWFontNumber(fontName))) || i==endPos.getOffset()) {
if (i != start) { if (i != start) {
try { try {
TibetanDocument.DuffData[] duffdata = TibetanDocument.getTibetanMachineWeb(sb.toString()); DuffData[] duffdata = TibTextUtils.getTibetanMachineWeb(sb.toString());
doc.remove(start, i-start); doc.remove(start, i-start);
doc.insertDuff(start, duffdata); doc.insertDuff(start, duffdata);
} }
@ -1630,4 +1618,14 @@ public void paste(int offset) {
} }
} }
/**
* Converts the entire associated document into Extended Wylie. If the
* document consists of both Tibetan and non-Tibetan fonts, however,
* the conversion stops at the first non-Tibetan font.
* @return the string of Wylie corresponding to the associated document
* @see org.thdl.tib.text.TibetanDocument.getWylie() */
public String getWylie() {
return doc.getWylie();
}
} }

View file

@ -47,6 +47,7 @@ public class Jskad2JavaScript extends JApplet {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} }
catch (Exception e) { catch (Exception e) {
ThdlDebug.noteIffyCode();
} }
setContentPane(makeContentPane()); setContentPane(makeContentPane());
} }
@ -61,11 +62,10 @@ public class Jskad2JavaScript extends JApplet {
public void theRealActionPerformed(ActionEvent e) public void theRealActionPerformed(ActionEvent e)
{ {
try { try {
TibetanDocument t_doc = (TibetanDocument)jskad.dp.getDocument(); Object[] args = { jskad.dp.getWylie() };
String wylie = t_doc.getWylie();
Object[] args = {wylie};
JSObject.getWindow(Jskad2JavaScript.this).call("settext", args); JSObject.getWindow(Jskad2JavaScript.this).call("settext", args);
} catch (Exception ex) { } catch (Exception ex) {
ThdlDebug.noteIffyCode();
} }
} }
}); });

View file

@ -68,11 +68,11 @@ public class Jskad4JavaScript extends JApplet {
public void setWylie(String wylie) { public void setWylie(String wylie) {
try { try {
TibetanDocument.DuffData[] dd = TibetanDocument.getTibetanMachineWeb(wylie); DuffData[] dd = TibTextUtils.getTibetanMachineWeb(wylie);
TibetanDocument t_doc = (TibetanDocument)jskad.dp.getDocument(); TibetanDocument t_doc = (TibetanDocument)jskad.dp.getDocument();
if (t_doc.getLength() > 0) if (t_doc.getLength() > 0)
jskad.dp.newDocument(); jskad.dp.newDocument(); // DLC FIXME: is it intended that t_doc is the new document? Because it is the old document at present.
TibetanDocument.DuffData[] duffdata = TibetanDocument.getTibetanMachineWeb(wylie); DuffData[] duffdata = TibTextUtils.getTibetanMachineWeb(wylie);
t_doc.insertDuff(0, duffdata); t_doc.insertDuff(0, duffdata);
} }
catch (InvalidWylieException iwe) { catch (InvalidWylieException iwe) {
@ -84,7 +84,6 @@ public class Jskad4JavaScript extends JApplet {
} }
public String getWylie() { public String getWylie() {
TibetanDocument t_doc = (TibetanDocument)jskad.dp.getDocument(); return jskad.dp.getWylie();
return t_doc.getWylie();
} }
} }

View file

@ -61,8 +61,7 @@ public class JskadConversionTool extends JApplet {
public void theRealActionPerformed(ActionEvent e) public void theRealActionPerformed(ActionEvent e)
{ {
try { try {
TibetanDocument t_doc = (TibetanDocument)jskad.dp.getDocument(); String wylie = jskad.dp.getWylie();
String wylie = t_doc.getWylie();
String html = "<HTML>\n<HEAD>\n<STYLE>\n"; String html = "<HTML>\n<HEAD>\n<STYLE>\n";
html += TibetanHTML.getStyles("28"); html += TibetanHTML.getStyles("28");
html += "</STYLE>\n</HEAD>\n<BODY>\n"; html += "</STYLE>\n</HEAD>\n<BODY>\n";

View file

@ -25,7 +25,6 @@ import javax.swing.text.JTextComponent;
import java.awt.event.*; import java.awt.event.*;
import java.awt.datatransfer.*; import java.awt.datatransfer.*;
import org.thdl.tib.input.DuffPane; import org.thdl.tib.input.DuffPane;
import org.thdl.tib.text.TibetanDocument;
/** Inputs a Tibetan text and displays the words with /** Inputs a Tibetan text and displays the words with
their definitions through through a graphical interfase using a their definitions through through a graphical interfase using a
@ -244,7 +243,7 @@ public class AppletScannerFilter extends JApplet implements ActionListener, Focu
{ {
try try
{ {
((TibetanDocument)t.getDocument()).remove(t.getSelectionStart(), t.getSelectionEnd()); t.getDocument().remove(t.getSelectionStart(), t.getSelectionEnd());
} }
catch (Exception ex) catch (Exception ex)
{ {

View file

@ -19,8 +19,8 @@ package org.thdl.tib.scanner;
import javax.swing.*; import javax.swing.*;
import javax.swing.table.*; import javax.swing.table.*;
import org.thdl.tib.text.TibetanDocument; import org.thdl.tib.text.TibTextUtils;
import org.thdl.tib.text.TibetanDocument.DuffData; import org.thdl.tib.text.DuffData;
/** Stores the words being displayed in a DictionaryTable. /** Stores the words being displayed in a DictionaryTable.
@ -114,7 +114,7 @@ public class DictionaryTableModel extends AbstractTableModel
try try
{ {
for (i=0; i<array.length; i++) for (i=0; i<array.length; i++)
arrayTibetan[i]=TibetanDocument.getTibetanMachineWeb(array[i].getWylie()); arrayTibetan[i]=TibTextUtils.getTibetanMachineWeb(array[i].getWylie());
} }
catch (Exception e) catch (Exception e)
{ {
@ -122,4 +122,4 @@ public class DictionaryTableModel extends AbstractTableModel
} }
} }
} }
} }

View file

@ -24,7 +24,7 @@ import javax.swing.border.*;
import javax.swing.text.*; import javax.swing.text.*;
import org.thdl.tib.input.DuffPane; import org.thdl.tib.input.DuffPane;
import org.thdl.tib.text.*; import org.thdl.tib.text.*;
import org.thdl.tib.text.TibetanDocument.DuffData; import org.thdl.tib.text.DuffData;
import java.io.Serializable; import java.io.Serializable;
/** Used by DictionaryTable to display a Tibetan word or phrase /** Used by DictionaryTable to display a Tibetan word or phrase
@ -133,7 +133,8 @@ public class DuffCellRenderer extends DuffPane implements TableCellRenderer, Ser
catch (Exception e) catch (Exception e)
{ {
System.out.println(e); System.out.println(e);
ThdlDebug.noteIffyCode();
} }
doc.insertDuff(0, (DuffData []) value); doc.insertDuff(0, (DuffData []) value);
} }
} }

View file

@ -23,7 +23,6 @@ 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.DuffPane;
import org.thdl.tib.text.TibetanDocument;
/** 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
@ -142,7 +141,7 @@ public class DuffScannerPanel extends ScannerPanel
in = ""; in = "";
if (showingTibetan) if (showingTibetan)
in = ((TibetanDocument)duffInput.getDocument()).getWylie(); in = duffInput.getWylie();
else else
in = txtInput.getText(); in = txtInput.getText();
@ -192,7 +191,7 @@ public class DuffScannerPanel extends ScannerPanel
} }
if (!enabled && showingTibetan) if (!enabled && showingTibetan)
{ {
txtInput.setText(((TibetanDocument)duffInput.getDocument()).getWylie()); txtInput.setText(duffInput.getWylie());
table.activateTibetan(false); table.activateTibetan(false);
cl.last(inputPanel); cl.last(inputPanel);
showingTibetan = false; showingTibetan = false;

View file

@ -27,7 +27,6 @@ import java.awt.*;
import java.awt.datatransfer.*; import java.awt.datatransfer.*;
import javax.swing.text.JTextComponent; import javax.swing.text.JTextComponent;
import org.thdl.tib.input.DuffPane; import org.thdl.tib.input.DuffPane;
import org.thdl.tib.text.TibetanDocument;
public class WindowScannerFilter implements WindowListener, FocusListener, ActionListener, ItemListener public class WindowScannerFilter implements WindowListener, FocusListener, ActionListener, ItemListener
{ {
@ -339,7 +338,7 @@ public class WindowScannerFilter implements WindowListener, FocusListener, Actio
{ {
try try
{ {
((TibetanDocument)t.getDocument()).remove(t.getSelectionStart(), t.getSelectionEnd()); t.getDocument().remove(t.getSelectionStart(), t.getSelectionEnd());
} }
catch (Exception ex) catch (Exception ex)
{ {

View file

@ -25,7 +25,9 @@ import javax.swing.border.*;
import javax.swing.text.*; import javax.swing.text.*;
import org.thdl.tib.input.DuffPane; import org.thdl.tib.input.DuffPane;
import org.thdl.tib.text.*; import org.thdl.tib.text.*;
import org.thdl.tib.text.TibetanDocument.DuffData; import org.thdl.tib.text.DuffData;
import org.thdl.util.ThdlDebug;
import java.io.Serializable; import java.io.Serializable;
/** Used by DictionaryTable to display a Tibetan word or phrase /** Used by DictionaryTable to display a Tibetan word or phrase
@ -135,6 +137,7 @@ public class DuffCellRenderer extends DuffPane implements TableCellRenderer, Ser
catch (Exception e) catch (Exception e)
{ {
System.out.println(e); System.out.println(e);
org.thdl.util.ThdlDebug.noteIffyCode();
} }
doc.insertDuff(0, (DuffData []) value); doc.insertDuff(0, (DuffData []) value);
} }

View file

@ -0,0 +1,53 @@
/*
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.text;
/**
* A wrapper object for a stretch of TibetanMachineWeb data that shares the same font.
* A piece of DuffData consists of a font number and a string.
* The font number is a number from one to ten, corresponding
* to the ten TibetanMachineWeb fonts, as follows:
* <p>
* 1 - TibetanMachineWeb<br>
* 2 - TibetanMachineWeb1<br>
* ...<br>
* 10 - TibetanMachineWeb9<br>
* <p>
* The string represents a contiguous stretch of data in that
* font, i.e. a stretch of TibetanMachineWeb that doesn't require a font change.
*/
public class DuffData {
/**
* a string of text
*/
public String text;
/**
* the font number for this text (see class description)
*/
public int font;
/**
* @param s a string of TibetanMachineWeb text
* @param i a TibetanMachineWeb font number
*/
public DuffData(String s, int i) {
text = s;
font = i;
}
}

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -1,144 +1,225 @@
package org.thdl.tib.text; package org.thdl.tib.text;
public class TibetanHTML { import java.util.StringTokenizer;
static String[] styleNames =
{"tmw","tmw1","tmw2","tmw3","tmw4","tmw5","tmw6","tmw7","tmw8","tmw9"}; public class TibetanHTML {
static String[] styleNames =
public static String getStyles(String fontSize) { {"tmw","tmw1","tmw2","tmw3","tmw4","tmw5","tmw6","tmw7","tmw8","tmw9"};
return ".tmw {font: "+fontSize+"pt TibetanMachineWeb}\n"+
".tmw1 {font: "+fontSize+"pt TibetanMachineWeb1}\n"+ public static String getStyles(String fontSize) {
".tmw2 {font: "+fontSize+"pt TibetanMachineWeb2}\n"+ return ".tmw {font: "+fontSize+"pt TibetanMachineWeb}\n"+
".tmw3 {font: "+fontSize+"pt TibetanMachineWeb3}\n"+ ".tmw1 {font: "+fontSize+"pt TibetanMachineWeb1}\n"+
".tmw4 {font: "+fontSize+"pt TibetanMachineWeb4}\n"+ ".tmw2 {font: "+fontSize+"pt TibetanMachineWeb2}\n"+
".tmw5 {font: "+fontSize+"pt TibetanMachineWeb5}\n"+ ".tmw3 {font: "+fontSize+"pt TibetanMachineWeb3}\n"+
".tmw6 {font: "+fontSize+"pt TibetanMachineWeb6}\n"+ ".tmw4 {font: "+fontSize+"pt TibetanMachineWeb4}\n"+
".tmw7 {font: "+fontSize+"pt TibetanMachineWeb7}\n"+ ".tmw5 {font: "+fontSize+"pt TibetanMachineWeb5}\n"+
".tmw8 {font: "+fontSize+"pt TibetanMachineWeb8}\n"+ ".tmw6 {font: "+fontSize+"pt TibetanMachineWeb6}\n"+
".tmw9 {font: "+fontSize+"pt TibetanMachineWeb9}\n"; ".tmw7 {font: "+fontSize+"pt TibetanMachineWeb7}\n"+
} ".tmw8 {font: "+fontSize+"pt TibetanMachineWeb8}\n"+
".tmw9 {font: "+fontSize+"pt TibetanMachineWeb9}\n";
}
public static String getHTML(String wylie) {
try { public static String getHTMLX(String wylie) {
return getHTML(TibetanDocument.getTibetanMachineWeb(wylie)); try {
} StringBuffer buffer = new StringBuffer();
catch (InvalidWylieException ive) { for (StringTokenizer tokenizer = new StringTokenizer(wylie, " \t\n", true); tokenizer.hasMoreElements();) {
return null; String next = tokenizer.nextToken();
} if (next.equals("\t") || next.equals("\n")) {
} buffer.append("<wbr/>");
buffer.append(getHTML(TibTextUtils.getTibetanMachineWeb("_")));
public static String getHTML(TibetanDocument.DuffData[] duffData) { buffer.append("<wbr/>");
String[] styleNames = }
{"tmw","tmw1","tmw2","tmw3","tmw4","tmw5","tmw6","tmw7","tmw8","tmw9"}; else
buffer.append(getHTML(TibTextUtils.getTibetanMachineWeb(next)));
StringBuffer htmlBuffer = new StringBuffer(); }
htmlBuffer.append("<nobr>"); return buffer.toString();
} catch (InvalidWylieException ive) {
for (int i=0; i<duffData.length; i++) { return "";
char[] c = duffData[i].text.toCharArray(); }
for (int k=0; k<c.length; k++) { }
htmlBuffer.append("<span class=\"");
htmlBuffer.append(styleNames[duffData[i].font-1]); public static String getHTMLX(DuffData[] duffData) {
htmlBuffer.append("\">"); String[] styleNames =
{"tmw","tmw1","tmw2","tmw3","tmw4","tmw5","tmw6","tmw7","tmw8","tmw9"};
switch (c[k]) {
case '"': StringBuffer htmlBuffer = new StringBuffer();
htmlBuffer.append("&quot"); htmlBuffer.append("<nobr>");
break;
case '<': for (int i=0; i<duffData.length; i++) {
htmlBuffer.append("&lt"); char[] c = duffData[i].text.toCharArray();
break; for (int k=0; k<c.length; k++) {
case '>': htmlBuffer.append("<span class=\"");
htmlBuffer.append("&gt"); htmlBuffer.append(styleNames[duffData[i].font-1]);
break; htmlBuffer.append("\">");
case '&':
htmlBuffer.append("&amp"); if (c[k] > 32 && c[k] < 127) { //ie if it's not formatting
break; switch (c[k]) {
default: case '"':
htmlBuffer.append(c[k]); htmlBuffer.append("&quot;");
break; break;
} case '<':
htmlBuffer.append("&lt;");
htmlBuffer.append("</span>"); break;
if (c[k] < 32) //must be formatting, like carriage return or tab case '>':
htmlBuffer.append("<br>"); htmlBuffer.append("&gt;");
break;
else { case '&':
String wylie = TibetanMachineWeb.getWylieForGlyph(duffData[i].font, c[k]); htmlBuffer.append("&amp;");
if (TibetanMachineWeb.isWyliePunc(wylie)) break;
htmlBuffer.append("<wbr>"); default:
} htmlBuffer.append(c[k]);
} break;
} }
htmlBuffer.append("</span>");
htmlBuffer.append("</nobr>"); String wylie = TibetanMachineWeb.getWylieForGlyph(duffData[i].font, c[k]);
return htmlBuffer.toString(); if (TibetanMachineWeb.isWyliePunc(wylie))
} htmlBuffer.append("<wbr/>");
} } else {
htmlBuffer.append("</span><br/>");
}
}
//import org.apache.xerces.dom.DOMImplementationImpl; }
//import org.w3c.dom.*;
htmlBuffer.append("</nobr>");
/* return htmlBuffer.toString();
public static Node getHTML(String wylie) { }
try {
return getHTML(TibetanDocument.getTibetanMachineWeb(wylie)); public static String getIndentedHTML(String wylie) {
} return getHTML("_" + wylie);
catch (InvalidWylieException ive) { }
return null;
} public static String getHTML(String wylie) {
} try {
StringBuffer buffer = new StringBuffer();
public static Node getHTML(TibetanDocument.DuffData[] duffData) { for (StringTokenizer tokenizer = new StringTokenizer(wylie, " \t\n", true); tokenizer.hasMoreElements();) {
try { String next = tokenizer.nextToken();
DOMImplementationImpl impl = new DOMImplementationImpl(); if (next.equals("\t") || next.equals("\n")) {
Document doc = impl.createDocument(null, "root", null); buffer.append("<wbr/>");
// DocumentFragment frag = doc.createDocumentFragment() buffer.append(getHTML(TibTextUtils.getTibetanMachineWeb("_")));
buffer.append("<wbr/>");
}
Element nobr = doc.createElement("nobr"); else
// frag.appendChild(nobr); buffer.append(getHTML(TibTextUtils.getTibetanMachineWeb(next)));
}
for (int i=0; i<duffData.length; i++) { return buffer.toString();
char[] c = duffData[i].text.toCharArray(); } catch (InvalidWylieException ive) {
for (int k=0; k<c.length; k++) { return "";
Element span = doc.createElement("span"); }
span.setAttribute("class", styleNames[duffData[i].font-1]); }
// Text tib = doc.createTextNode(String.valueOf(c[k]));
// span.appendChild(tib); public static String getHTML(DuffData[] duffData) {
nobr.appendChild(span); String[] styleNames =
{"tmw","tmw1","tmw2","tmw3","tmw4","tmw5","tmw6","tmw7","tmw8","tmw9"};
String wylie = TibetanMachineWeb.getWylieForGlyph(duffData[i].font, c[k]);
if (TibetanMachineWeb.isWyliePunc(wylie)) { StringBuffer htmlBuffer = new StringBuffer();
Element wbr = doc.createElement("wbr"); htmlBuffer.append("<nobr>");
nobr.appendChild(wbr);
} for (int i=0; i<duffData.length; i++) {
} htmlBuffer.append("<span class=\"");
} htmlBuffer.append(styleNames[duffData[i].font-1]);
htmlBuffer.append("\">");
//doc.appendChild(nobr); char[] c = duffData[i].text.toCharArray();
return nobr; for (int k=0; k<c.length; k++) {
if (c[k] > 31 && c[k] < 127) { //ie if it's not formatting
// return frag; switch (c[k]) {
} case '"':
catch (DOMException dome) { htmlBuffer.append("&quot;");
switch (dome.code) { break;
case '<':
case DOMException.HIERARCHY_REQUEST_ERR: htmlBuffer.append("&lt;");
System.out.println("hierarchy error!!"); break;
break; case '>':
htmlBuffer.append("&gt;");
case DOMException.WRONG_DOCUMENT_ERR: break;
System.out.println("wrong doc error!!"); case '&':
break; htmlBuffer.append("&amp;");
break;
case DOMException.NO_MODIFICATION_ALLOWED_ERR: default:
System.out.println("no mod allowed error!!"); htmlBuffer.append(c[k]);
break; break;
} }
return null; String wylie = TibetanMachineWeb.getWylieForGlyph(duffData[i].font, c[k]);
} if (TibetanMachineWeb.isWyliePunc(wylie))
} htmlBuffer.append("<wbr/>");
*/ } else {
htmlBuffer.append("<br/>");
}
}
htmlBuffer.append("</span>");
}
htmlBuffer.append("</nobr>");
return htmlBuffer.toString();
}
public static String getHTMLforJava(String wylie) {
//differences:
// as of 1.4.1, anyway, browser built into java does not accept <wbr/> and <br/>,
// only <wbr> and <br>
try {
StringBuffer buffer = new StringBuffer();
for (StringTokenizer tokenizer = new StringTokenizer(wylie, " \t\n", true); tokenizer.hasMoreElements();) {
String next = tokenizer.nextToken();
if (next.equals("\t") || next.equals("\n")) {
buffer.append("<wbr>");
buffer.append(getHTML(TibTextUtils.getTibetanMachineWeb("_")));
buffer.append("<wbr>");
}
else
buffer.append(getHTML(TibTextUtils.getTibetanMachineWeb(next)));
}
return buffer.toString();
} catch (InvalidWylieException ive) {
return "";
}
}
public static String getHTMLforJava(DuffData[] duffData) {
String[] fontNames = {
"TibetanMachineWeb","TibetanMachineWeb1", "TibetanMachineWeb2",
"TibetanMachineWeb3","TibetanMachineWeb4","TibetanMachineWeb5",
"TibetanMachineWeb6","TibetanMachineWeb7","TibetanMachineWeb8",
"TibetanMachineWeb9"};
StringBuffer htmlBuffer = new StringBuffer();
htmlBuffer.append("<nobr>");
for (int i=0; i<duffData.length; i++) {
htmlBuffer.append("<font size=\"36\" face=\"");
htmlBuffer.append(fontNames[duffData[i].font-1]);
htmlBuffer.append("\">");
char[] c = duffData[i].text.toCharArray();
for (int k=0; k<c.length; k++) {
if (c[k] > 31 && c[k] < 127) { //ie if it's not formatting
switch (c[k]) {
case '"':
htmlBuffer.append("&quot;");
break;
case '<':
htmlBuffer.append("&lt;");
break;
case '>':
htmlBuffer.append("&gt;");
break;
case '&':
htmlBuffer.append("&amp;");
break;
default:
htmlBuffer.append(c[k]);
break;
}
String wylie = TibetanMachineWeb.getWylieForGlyph(duffData[i].font, c[k]);
if (TibetanMachineWeb.isWyliePunc(wylie))
htmlBuffer.append("<wbr>");
} else {
htmlBuffer.append("<br>");
}
}
htmlBuffer.append("</font>");
}
htmlBuffer.append("</nobr>");
return htmlBuffer.toString();
}
}

View file

@ -126,14 +126,14 @@ public class TibetanQTText {
public static String getQTText(String wylie) { public static String getQTText(String wylie) {
try { try {
return getQTText(TibetanDocument.getTibetanMachineWeb(wylie)); return getQTText(TibTextUtils.getTibetanMachineWeb(wylie));
} }
catch (InvalidWylieException ive) { catch (InvalidWylieException ive) {
return null; return null;
} }
} }
public static String getQTText(TibetanDocument.DuffData[] duffData) { public static String getQTText(DuffData[] duffData) {
StringBuffer qtBuffer = new StringBuffer(); StringBuffer qtBuffer = new StringBuffer();
qtBuffer.append("{size:" + tibFontSize + "}"); qtBuffer.append("{size:" + tibFontSize + "}");

View file

@ -126,14 +126,14 @@ public class TibetanQTText2 {
public static String getQTText(String wylie) { public static String getQTText(String wylie) {
try { try {
return getQTText(TibetanDocument.getTibetanMachineWeb(wylie)); return getQTText(TibTextUtils.getTibetanMachineWeb(wylie));
} }
catch (InvalidWylieException ive) { catch (InvalidWylieException ive) {
return null; return null;
} }
} }
public static String getQTText(TibetanDocument.DuffData[] duffData) { public static String getQTText(DuffData[] duffData) {
StringBuffer qtBuffer = new StringBuffer(); StringBuffer qtBuffer = new StringBuffer();
qtBuffer.append("{size:" + tibFontSize + "}"); qtBuffer.append("{size:" + tibFontSize + "}");

View file

@ -119,6 +119,17 @@ public class ThdlDebug {
System.exit(1); System.exit(1);
} }
/** Exits the program the hard way. Don't ever call this for code
that you expect to be executed. */
public static void abort(String message) {
System.err.println("THDL Internal Error. ABORTING.");
if (null != message) {
System.err.println(message);
System.err.println("THDL Internal Error. ABORTING.");
}
System.exit(37);
}
/** Sets it up so that a call to System.out or System.err prints /** Sets it up so that a call to System.out or System.err prints
* to standard output/error but ALSO prints to the log file named * to standard output/error but ALSO prints to the log file named
* (prefix + suffix). Be sure the log file name is a relative * (prefix + suffix). Be sure the log file name is a relative