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:
parent
5249c48807
commit
abcf8f19b3
25 changed files with 1490 additions and 1337 deletions
|
@ -34,7 +34,6 @@ import java.lang.reflect.*;
|
|||
|
||||
import org.thdl.tib.input.*;
|
||||
import org.thdl.tib.text.*;
|
||||
import org.thdl.tib.text.TibetanDocument.*;
|
||||
import org.thdl.savant.JdkVersionHacks;
|
||||
import org.thdl.media.*;
|
||||
|
||||
|
@ -80,6 +79,8 @@ public class QD extends JDesktopPane {
|
|||
public Style componentStyle;
|
||||
public DataFlavor timeFlavor;
|
||||
|
||||
/** Either "qt4j" or "jmf", corresponding to the thdl.media.player
|
||||
property. */
|
||||
protected String thdl_mediaplayer_property = null;
|
||||
|
||||
//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 sharedDP2 = new DuffPane();
|
||||
|
||||
protected TibetanDocument findDoc = null;
|
||||
protected TibetanDocument replaceDoc = null;
|
||||
protected AbstractDocument findDoc = null;
|
||||
protected AbstractDocument replaceDoc = null;
|
||||
|
||||
protected KeyStroke cutKey, copyKey, pasteKey, selectAllKey;
|
||||
protected KeyStroke insert1TimeKey, insert2TimesKey, insertSpeakerKey;
|
||||
|
@ -1385,7 +1386,7 @@ class SpeakerData extends AbstractTableModel
|
|||
if (column == 0)
|
||||
return spIcon[sp.getIconID()];
|
||||
try { //otherwise column 1, the speaker name
|
||||
return TibetanDocument.getTibetanMachineWeb(sp.getName().trim());
|
||||
return TibTextUtils.getTibetanMachineWeb(sp.getName().trim());
|
||||
} catch (InvalidWylieException iwe) {
|
||||
iwe.printStackTrace();
|
||||
ThdlDebug.noteIffyCode();
|
||||
|
@ -1653,7 +1654,7 @@ public void replaceText() {
|
|||
java.util.List replaceDCs = new ArrayList();
|
||||
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)));
|
||||
TibetanDocument.DuffData[] dd = TibetanDocument.convertGlyphs(replaceDCs);
|
||||
DuffData[] dd = TibTextUtils.convertGlyphs(replaceDCs);
|
||||
|
||||
TibetanDocument doc = (TibetanDocument)pane.getDocument();
|
||||
Position pos = doc.createPosition(pane.getCaretPosition());
|
||||
|
|
|
@ -141,7 +141,7 @@ public class SavantShell extends JFrame
|
|||
JMenu fileMenu = new JMenu("File");
|
||||
|
||||
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() {
|
||||
public void theRealActionPerformed(ActionEvent e) {
|
||||
if (fileChooser.showOpenDialog(SavantShell.this) != JFileChooser.APPROVE_OPTION)
|
||||
|
@ -166,7 +166,7 @@ public class SavantShell extends JFrame
|
|||
});
|
||||
|
||||
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()
|
||||
{
|
||||
public void theRealActionPerformed(ActionEvent e)
|
||||
|
@ -177,7 +177,7 @@ public class SavantShell extends JFrame
|
|||
});
|
||||
|
||||
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()
|
||||
{
|
||||
public void theRealActionPerformed(ActionEvent e)
|
||||
|
|
|
@ -85,9 +85,9 @@ public class Tibetan implements TranscriptView
|
|||
t2Buffer = new StringBuffer();
|
||||
String thisStart, thisEnd, thisId;
|
||||
Position endPos = null;
|
||||
TibetanDocument.DuffData[] dd;
|
||||
DuffData[] dd;
|
||||
TibetanDocument doc = new TibetanDocument(new StyleContext());
|
||||
TibetanDocument.DuffData[] space = TibetanDocument.getTibetanMachineWeb("_");
|
||||
DuffData[] space = TibTextUtils.getTibetanMachineWeb("_");
|
||||
MutableAttributeSet mas = new SimpleAttributeSet();
|
||||
StyleConstants.setForeground(mas, Color.blue);
|
||||
|
||||
|
@ -99,7 +99,7 @@ public class Tibetan implements TranscriptView
|
|||
|
||||
while (current.getName().equals("spkr"))
|
||||
{
|
||||
dd = TibetanDocument.getTibetanMachineWeb(current.getAttributeValue("who"));
|
||||
dd = TibTextUtils.getTibetanMachineWeb(current.getAttributeValue("who"));
|
||||
if (endPos == null)
|
||||
{
|
||||
doc.insertDuff(0, dd);
|
||||
|
@ -126,7 +126,7 @@ public class Tibetan implements TranscriptView
|
|||
}
|
||||
|
||||
wherestart = endPos.getOffset();
|
||||
dd = TibetanDocument.getTibetanMachineWeb(current.getText()); //from +"\n"
|
||||
dd = TibTextUtils.getTibetanMachineWeb(current.getText()); //from +"\n"
|
||||
doc.insertDuff(endPos.getOffset(), dd);
|
||||
startBuffer.append(String.valueOf(wherestart)+",");
|
||||
thisEnd = String.valueOf(endPos.getOffset());
|
||||
|
@ -145,7 +145,7 @@ public class Tibetan implements TranscriptView
|
|||
while (current.getName().equals("spkr"))
|
||||
{
|
||||
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();
|
||||
doc.insertDuff(endPos.getOffset(), dd);
|
||||
doc.setCharacterAttributes(wherestart, endPos.getOffset()-wherestart, mas, false);
|
||||
|
@ -155,7 +155,7 @@ public class Tibetan implements TranscriptView
|
|||
|
||||
doc.insertDuff(endPos.getOffset(), space);
|
||||
counter++;
|
||||
dd = TibetanDocument.getTibetanMachineWeb(current.getText()); //from "+\n"
|
||||
dd = TibTextUtils.getTibetanMachineWeb(current.getText()); //from "+\n"
|
||||
thisStart = String.valueOf(endPos.getOffset());
|
||||
startBuffer.append(thisStart);
|
||||
startBuffer.append(',');
|
||||
|
|
|
@ -79,8 +79,8 @@ public class TibetanEnglish implements TranscriptView
|
|||
Iterator iter = elements.iterator();
|
||||
Element current = null;
|
||||
|
||||
TibetanDocument.DuffData[] dd;
|
||||
TibetanDocument.DuffData[] space = TibetanDocument.getTibetanMachineWeb("_");
|
||||
DuffData[] dd;
|
||||
DuffData[] space = TibTextUtils.getTibetanMachineWeb("_");
|
||||
MutableAttributeSet mas = new SimpleAttributeSet();
|
||||
StyleConstants.setForeground(mas, Color.blue);
|
||||
Position endPos = null;
|
||||
|
@ -120,7 +120,7 @@ public class TibetanEnglish implements TranscriptView
|
|||
current = (org.jdom.Element)iter.next();
|
||||
}
|
||||
|
||||
dd = TibetanDocument.getTibetanMachineWeb(current.getText()+"\n");
|
||||
dd = TibTextUtils.getTibetanMachineWeb(current.getText()+"\n");
|
||||
if (endPos == null)
|
||||
{
|
||||
thisStart = "0";
|
||||
|
@ -164,7 +164,7 @@ public class TibetanEnglish implements TranscriptView
|
|||
thisStart = String.valueOf(endPos.getOffset());
|
||||
startBuffer.append(thisStart);
|
||||
startBuffer.append(',');
|
||||
dd = TibetanDocument.getTibetanMachineWeb(current.getText()+"\n");
|
||||
dd = TibTextUtils.getTibetanMachineWeb(current.getText()+"\n");
|
||||
doc.insertDuff(endPos.getOffset(), dd);
|
||||
doc.insertString(endPos.getOffset(), current.getAttributeValue("eng"), null);
|
||||
thisEnd = String.valueOf(endPos.getOffset());
|
||||
|
|
|
@ -80,8 +80,8 @@ public class TibetanWylie implements TranscriptView
|
|||
Element current = null;
|
||||
|
||||
String wylie;
|
||||
TibetanDocument.DuffData[] dd;
|
||||
TibetanDocument.DuffData[] space = TibetanDocument.getTibetanMachineWeb("_");
|
||||
DuffData[] dd;
|
||||
DuffData[] space = TibTextUtils.getTibetanMachineWeb("_");
|
||||
MutableAttributeSet mas = new SimpleAttributeSet();
|
||||
StyleConstants.setForeground(mas, Color.blue);
|
||||
Position endPos = null;
|
||||
|
@ -122,7 +122,7 @@ public class TibetanWylie implements TranscriptView
|
|||
}
|
||||
|
||||
wylie = current.getText();
|
||||
dd = TibetanDocument.getTibetanMachineWeb(wylie+"\n");
|
||||
dd = TibTextUtils.getTibetanMachineWeb(wylie+"\n");
|
||||
if (endPos == null)
|
||||
{
|
||||
thisStart = "0";
|
||||
|
@ -166,7 +166,7 @@ public class TibetanWylie implements TranscriptView
|
|||
startBuffer.append(thisStart);
|
||||
startBuffer.append(',');
|
||||
wylie = current.getText();
|
||||
dd = TibetanDocument.getTibetanMachineWeb(wylie+"\n");
|
||||
dd = TibTextUtils.getTibetanMachineWeb(wylie+"\n");
|
||||
doc.insertDuff(endPos.getOffset(), dd);
|
||||
doc.insertString(endPos.getOffset(), wylie, null);
|
||||
|
||||
|
|
|
@ -79,8 +79,8 @@ public class TibetanWylieEnglish implements TranscriptView
|
|||
Iterator iter = elements.iterator();
|
||||
Element current = null;
|
||||
|
||||
TibetanDocument.DuffData[] dd;
|
||||
TibetanDocument.DuffData[] space = TibetanDocument.getTibetanMachineWeb("_");
|
||||
DuffData[] dd;
|
||||
DuffData[] space = TibTextUtils.getTibetanMachineWeb("_");
|
||||
MutableAttributeSet mas = new SimpleAttributeSet();
|
||||
StyleConstants.setForeground(mas, Color.blue);
|
||||
MutableAttributeSet mas2 = new SimpleAttributeSet();
|
||||
|
@ -123,7 +123,7 @@ public class TibetanWylieEnglish implements TranscriptView
|
|||
}
|
||||
|
||||
wylie = current.getText();
|
||||
dd = TibetanDocument.getTibetanMachineWeb(wylie+"\n");
|
||||
dd = TibTextUtils.getTibetanMachineWeb(wylie+"\n");
|
||||
if (endPos == null)
|
||||
{
|
||||
thisStart = "0";
|
||||
|
@ -168,7 +168,7 @@ public class TibetanWylieEnglish implements TranscriptView
|
|||
startBuffer.append(thisStart);
|
||||
startBuffer.append(',');
|
||||
wylie = current.getText();
|
||||
dd = TibetanDocument.getTibetanMachineWeb(wylie+"\n");
|
||||
dd = TibTextUtils.getTibetanMachineWeb(wylie+"\n");
|
||||
doc.insertDuff(endPos.getOffset(), dd);
|
||||
doc.insertString(endPos.getOffset(), wylie+"\n", mas2);
|
||||
doc.insertString(endPos.getOffset(), current.getAttributeValue("eng"), null);
|
||||
|
|
|
@ -83,7 +83,7 @@ public class Wylie implements TranscriptView
|
|||
MutableAttributeSet mas = new SimpleAttributeSet();
|
||||
StyleConstants.setForeground(mas, Color.blue);
|
||||
Position endPos = null;
|
||||
TibetanDocument doc = new TibetanDocument(new StyleContext());
|
||||
AbstractDocument doc = new TibetanDocument(new StyleContext());
|
||||
|
||||
idBuffer = new StringBuffer();
|
||||
startBuffer = new StringBuffer();
|
||||
|
|
|
@ -79,7 +79,7 @@ public class WylieEnglish implements TranscriptView
|
|||
Iterator iter = elements.iterator();
|
||||
Element current = null;
|
||||
|
||||
TibetanDocument.DuffData[] dd;
|
||||
DuffData[] dd;
|
||||
MutableAttributeSet mas = new SimpleAttributeSet();
|
||||
StyleConstants.setForeground(mas, Color.blue);
|
||||
MutableAttributeSet mas2 = new SimpleAttributeSet();
|
||||
|
@ -87,7 +87,7 @@ public class WylieEnglish implements TranscriptView
|
|||
Position endPos = null;
|
||||
int wherestart;
|
||||
String wylie;
|
||||
TibetanDocument doc = new TibetanDocument(new StyleContext());
|
||||
AbstractDocument doc = new TibetanDocument(new StyleContext());
|
||||
|
||||
idBuffer = new StringBuffer();
|
||||
startBuffer = new StringBuffer();
|
||||
|
|
|
@ -225,18 +225,6 @@ public RTFEditorKit rtfEd = null;
|
|||
// 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,
|
||||
with messages about how the users' keypresses are being
|
||||
interpreted. */
|
||||
|
@ -640,7 +628,7 @@ public RTFEditorKit rtfEd = null;
|
|||
backSpace(oldGlyphCount - beginDifference);
|
||||
|
||||
java.util.List sublist = newGlyphList.subList(k, newGlyphCount);
|
||||
TibetanDocument.DuffData[] dd = TibetanDocument.convertGlyphs(sublist);
|
||||
DuffData[] dd = TibTextUtils.convertGlyphs(sublist);
|
||||
doc.insertDuff(caret.getDot(), dd);
|
||||
return newGlyphList;
|
||||
}
|
||||
|
@ -705,7 +693,7 @@ public RTFEditorKit rtfEd = null;
|
|||
before_vowel.add(dc_1);
|
||||
|
||||
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);
|
||||
}
|
||||
catch(BadLocationException ble) {
|
||||
|
@ -728,8 +716,8 @@ public RTFEditorKit rtfEd = null;
|
|||
private void printAChenWithVowel(String v) {
|
||||
DuffCode[] dc_array = (DuffCode[])TibetanMachineWeb.getTibHash().get(TibetanMachineWeb.ACHEN);
|
||||
DuffCode dc = dc_array[TibetanMachineWeb.TMW];
|
||||
java.util.List achenlist = TibetanDocument.getVowel(dc,v);
|
||||
TibetanDocument.DuffData[] dd = TibetanDocument.convertGlyphs(achenlist);
|
||||
java.util.List achenlist = TibTextUtils.getVowel(dc,v);
|
||||
DuffData[] dd = TibTextUtils.convertGlyphs(achenlist);
|
||||
doc.insertDuff(caret.getDot(), dd);
|
||||
}
|
||||
|
||||
|
@ -765,7 +753,7 @@ public RTFEditorKit rtfEd = null;
|
|||
DuffCode dc = new DuffCode(fontNum, c2);
|
||||
java.util.List beforecaret = new ArrayList();
|
||||
beforecaret.add(dc);
|
||||
java.util.List bindulist = TibetanDocument.getBindu(dc);
|
||||
java.util.List bindulist = TibTextUtils.getBindu(dc);
|
||||
redrawGlyphs(beforecaret, bindulist);
|
||||
initKeyboard();
|
||||
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);
|
||||
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-d-r, you see two glyphs. If you examine the status bar,
|
||||
* 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 */
|
||||
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)");
|
||||
} else if (size > 1 && isStackingRightToLeft) {
|
||||
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);
|
||||
initKeyboard();
|
||||
charList.add(s);
|
||||
newGlyphList = TibetanDocument.getGlyphs(charList, isStackingRightToLeft, isDefinitelyTibetan, isDefinitelySanskrit);
|
||||
newGlyphList = TibTextUtils.getGlyphs(charList, isStackingRightToLeft, isDefinitelyTibetan, isDefinitelySanskrit);
|
||||
oldGlyphList = redrawGlyphs(oldGlyphList, newGlyphList);
|
||||
holdCurrent = new StringBuffer();
|
||||
isTopHypothesis = false;
|
||||
|
@ -1355,7 +1343,7 @@ public void paste(int offset) {
|
|||
s = TibetanMachineWeb.getWylieForChar(s);
|
||||
charList.add(s);
|
||||
isTopHypothesis = true;
|
||||
newGlyphList = TibetanDocument.getGlyphs(charList, isStackingRightToLeft, isDefinitelyTibetan, isDefinitelySanskrit);
|
||||
newGlyphList = TibTextUtils.getGlyphs(charList, isStackingRightToLeft, isDefinitelyTibetan, isDefinitelySanskrit);
|
||||
oldGlyphList = redrawGlyphs(oldGlyphList, newGlyphList);
|
||||
changedStatus = true;
|
||||
updateStatus("You typed a non-vowel, Tibetan character.");
|
||||
|
@ -1379,7 +1367,7 @@ public void paste(int offset) {
|
|||
if (isTopHypothesis) {
|
||||
if (TibetanMachineWeb.isAChungConsonant() && isStackingOn && charList.size()>1 && s2.equals(TibetanMachineWeb.ACHUNG)) {
|
||||
charList.remove(charList.size() - 1);
|
||||
newGlyphList = TibetanDocument.getGlyphs(charList, isStackingRightToLeft, isDefinitelyTibetan, isDefinitelySanskrit);
|
||||
newGlyphList = TibTextUtils.getGlyphs(charList, isStackingRightToLeft, isDefinitelyTibetan, isDefinitelySanskrit);
|
||||
oldGlyphList = redrawGlyphs(oldGlyphList, newGlyphList);
|
||||
putVowel(TibetanMachineWeb.A_VOWEL);
|
||||
initKeyboard();
|
||||
|
@ -1388,7 +1376,7 @@ public void paste(int offset) {
|
|||
break key_block;
|
||||
}
|
||||
charList.set(charList.size()-1, s2);
|
||||
newGlyphList = TibetanDocument.getGlyphs(charList, isStackingRightToLeft, isDefinitelyTibetan, isDefinitelySanskrit);
|
||||
newGlyphList = TibTextUtils.getGlyphs(charList, isStackingRightToLeft, isDefinitelyTibetan, isDefinitelySanskrit);
|
||||
oldGlyphList = redrawGlyphs(oldGlyphList, newGlyphList);
|
||||
} else {
|
||||
if (!isStackingOn) {
|
||||
|
@ -1406,7 +1394,7 @@ public void paste(int offset) {
|
|||
|
||||
charList.add(s2);
|
||||
isTopHypothesis = true;
|
||||
newGlyphList = TibetanDocument.getGlyphs(charList, isStackingRightToLeft, isDefinitelyTibetan, isDefinitelySanskrit);
|
||||
newGlyphList = TibTextUtils.getGlyphs(charList, isStackingRightToLeft, isDefinitelyTibetan, isDefinitelySanskrit);
|
||||
oldGlyphList = redrawGlyphs(oldGlyphList, newGlyphList);
|
||||
}
|
||||
} else { //the holding string is not a character
|
||||
|
@ -1441,7 +1429,7 @@ public void paste(int offset) {
|
|||
}
|
||||
|
||||
charList.add(s2);
|
||||
newGlyphList = TibetanDocument.getGlyphs(charList, isStackingRightToLeft, isDefinitelyTibetan, isDefinitelySanskrit);
|
||||
newGlyphList = TibTextUtils.getGlyphs(charList, isStackingRightToLeft, isDefinitelyTibetan, isDefinitelySanskrit);
|
||||
oldGlyphList = redrawGlyphs(oldGlyphList, newGlyphList);
|
||||
changedStatus = true;
|
||||
updateStatus("added character to charList");
|
||||
|
@ -1511,7 +1499,7 @@ public void paste(int offset) {
|
|||
dc_array = new DuffCode[0];
|
||||
dc_array = (DuffCode[])dcs.toArray(dc_array);
|
||||
doc.remove(start, i-start);
|
||||
append(start, TibetanDocument.getWylie(dc_array), romanAttributeSet);
|
||||
append(start, TibTextUtils.getWylie(dc_array), romanAttributeSet);
|
||||
dcs.clear();
|
||||
}
|
||||
start = i+1;
|
||||
|
@ -1552,7 +1540,7 @@ public void paste(int offset) {
|
|||
ThdlDebug.noteIffyCode();
|
||||
}
|
||||
} else {
|
||||
TibetanDocument.DuffData[] dd = TibetanDocument.getTibetanMachineWeb(next);
|
||||
DuffData[] dd = TibTextUtils.getTibetanMachineWeb(next);
|
||||
offset = doc.insertDuff(offset, dd);
|
||||
}
|
||||
}
|
||||
|
@ -1603,7 +1591,7 @@ public void paste(int offset) {
|
|||
if ((0 != (fontNum = TibetanMachineWeb.getTMWFontNumber(fontName))) || i==endPos.getOffset()) {
|
||||
if (i != start) {
|
||||
try {
|
||||
TibetanDocument.DuffData[] duffdata = TibetanDocument.getTibetanMachineWeb(sb.toString());
|
||||
DuffData[] duffdata = TibTextUtils.getTibetanMachineWeb(sb.toString());
|
||||
doc.remove(start, i-start);
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -47,6 +47,7 @@ public class Jskad2JavaScript extends JApplet {
|
|||
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
|
||||
}
|
||||
catch (Exception e) {
|
||||
ThdlDebug.noteIffyCode();
|
||||
}
|
||||
setContentPane(makeContentPane());
|
||||
}
|
||||
|
@ -61,11 +62,10 @@ public class Jskad2JavaScript extends JApplet {
|
|||
public void theRealActionPerformed(ActionEvent e)
|
||||
{
|
||||
try {
|
||||
TibetanDocument t_doc = (TibetanDocument)jskad.dp.getDocument();
|
||||
String wylie = t_doc.getWylie();
|
||||
Object[] args = {wylie};
|
||||
Object[] args = { jskad.dp.getWylie() };
|
||||
JSObject.getWindow(Jskad2JavaScript.this).call("settext", args);
|
||||
} catch (Exception ex) {
|
||||
ThdlDebug.noteIffyCode();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -68,11 +68,11 @@ public class Jskad4JavaScript extends JApplet {
|
|||
|
||||
public void setWylie(String wylie) {
|
||||
try {
|
||||
TibetanDocument.DuffData[] dd = TibetanDocument.getTibetanMachineWeb(wylie);
|
||||
DuffData[] dd = TibTextUtils.getTibetanMachineWeb(wylie);
|
||||
TibetanDocument t_doc = (TibetanDocument)jskad.dp.getDocument();
|
||||
if (t_doc.getLength() > 0)
|
||||
jskad.dp.newDocument();
|
||||
TibetanDocument.DuffData[] duffdata = TibetanDocument.getTibetanMachineWeb(wylie);
|
||||
jskad.dp.newDocument(); // DLC FIXME: is it intended that t_doc is the new document? Because it is the old document at present.
|
||||
DuffData[] duffdata = TibTextUtils.getTibetanMachineWeb(wylie);
|
||||
t_doc.insertDuff(0, duffdata);
|
||||
}
|
||||
catch (InvalidWylieException iwe) {
|
||||
|
@ -84,7 +84,6 @@ public class Jskad4JavaScript extends JApplet {
|
|||
}
|
||||
|
||||
public String getWylie() {
|
||||
TibetanDocument t_doc = (TibetanDocument)jskad.dp.getDocument();
|
||||
return t_doc.getWylie();
|
||||
return jskad.dp.getWylie();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -61,8 +61,7 @@ public class JskadConversionTool extends JApplet {
|
|||
public void theRealActionPerformed(ActionEvent e)
|
||||
{
|
||||
try {
|
||||
TibetanDocument t_doc = (TibetanDocument)jskad.dp.getDocument();
|
||||
String wylie = t_doc.getWylie();
|
||||
String wylie = jskad.dp.getWylie();
|
||||
String html = "<HTML>\n<HEAD>\n<STYLE>\n";
|
||||
html += TibetanHTML.getStyles("28");
|
||||
html += "</STYLE>\n</HEAD>\n<BODY>\n";
|
||||
|
|
|
@ -25,7 +25,6 @@ import javax.swing.text.JTextComponent;
|
|||
import java.awt.event.*;
|
||||
import java.awt.datatransfer.*;
|
||||
import org.thdl.tib.input.DuffPane;
|
||||
import org.thdl.tib.text.TibetanDocument;
|
||||
|
||||
/** Inputs a Tibetan text and displays the words with
|
||||
their definitions through through a graphical interfase using a
|
||||
|
@ -244,7 +243,7 @@ public class AppletScannerFilter extends JApplet implements ActionListener, Focu
|
|||
{
|
||||
try
|
||||
{
|
||||
((TibetanDocument)t.getDocument()).remove(t.getSelectionStart(), t.getSelectionEnd());
|
||||
t.getDocument().remove(t.getSelectionStart(), t.getSelectionEnd());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
|
|
@ -19,8 +19,8 @@ package org.thdl.tib.scanner;
|
|||
|
||||
import javax.swing.*;
|
||||
import javax.swing.table.*;
|
||||
import org.thdl.tib.text.TibetanDocument;
|
||||
import org.thdl.tib.text.TibetanDocument.DuffData;
|
||||
import org.thdl.tib.text.TibTextUtils;
|
||||
import org.thdl.tib.text.DuffData;
|
||||
|
||||
/** Stores the words being displayed in a DictionaryTable.
|
||||
|
||||
|
@ -114,7 +114,7 @@ public class DictionaryTableModel extends AbstractTableModel
|
|||
try
|
||||
{
|
||||
for (i=0; i<array.length; i++)
|
||||
arrayTibetan[i]=TibetanDocument.getTibetanMachineWeb(array[i].getWylie());
|
||||
arrayTibetan[i]=TibTextUtils.getTibetanMachineWeb(array[i].getWylie());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
@ -122,4 +122,4 @@ public class DictionaryTableModel extends AbstractTableModel
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ import javax.swing.border.*;
|
|||
import javax.swing.text.*;
|
||||
import org.thdl.tib.input.DuffPane;
|
||||
import org.thdl.tib.text.*;
|
||||
import org.thdl.tib.text.TibetanDocument.DuffData;
|
||||
import org.thdl.tib.text.DuffData;
|
||||
import java.io.Serializable;
|
||||
|
||||
/** 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)
|
||||
{
|
||||
System.out.println(e);
|
||||
ThdlDebug.noteIffyCode();
|
||||
}
|
||||
doc.insertDuff(0, (DuffData []) value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,7 +23,6 @@ import javax.swing.*;
|
|||
import javax.swing.event.*;
|
||||
import javax.swing.table.*;
|
||||
import org.thdl.tib.input.DuffPane;
|
||||
import org.thdl.tib.text.TibetanDocument;
|
||||
|
||||
/** Graphical interfase to be used by applications and applets
|
||||
to input a Tibetan text (in Roman or Tibetan script) and
|
||||
|
@ -142,7 +141,7 @@ public class DuffScannerPanel extends ScannerPanel
|
|||
|
||||
in = "";
|
||||
if (showingTibetan)
|
||||
in = ((TibetanDocument)duffInput.getDocument()).getWylie();
|
||||
in = duffInput.getWylie();
|
||||
else
|
||||
in = txtInput.getText();
|
||||
|
||||
|
@ -192,7 +191,7 @@ public class DuffScannerPanel extends ScannerPanel
|
|||
}
|
||||
if (!enabled && showingTibetan)
|
||||
{
|
||||
txtInput.setText(((TibetanDocument)duffInput.getDocument()).getWylie());
|
||||
txtInput.setText(duffInput.getWylie());
|
||||
table.activateTibetan(false);
|
||||
cl.last(inputPanel);
|
||||
showingTibetan = false;
|
||||
|
|
|
@ -27,7 +27,6 @@ import java.awt.*;
|
|||
import java.awt.datatransfer.*;
|
||||
import javax.swing.text.JTextComponent;
|
||||
import org.thdl.tib.input.DuffPane;
|
||||
import org.thdl.tib.text.TibetanDocument;
|
||||
|
||||
public class WindowScannerFilter implements WindowListener, FocusListener, ActionListener, ItemListener
|
||||
{
|
||||
|
@ -339,7 +338,7 @@ public class WindowScannerFilter implements WindowListener, FocusListener, Actio
|
|||
{
|
||||
try
|
||||
{
|
||||
((TibetanDocument)t.getDocument()).remove(t.getSelectionStart(), t.getSelectionEnd());
|
||||
t.getDocument().remove(t.getSelectionStart(), t.getSelectionEnd());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
|
|
@ -25,7 +25,9 @@ import javax.swing.border.*;
|
|||
import javax.swing.text.*;
|
||||
import org.thdl.tib.input.DuffPane;
|
||||
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;
|
||||
|
||||
/** 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)
|
||||
{
|
||||
System.out.println(e);
|
||||
org.thdl.util.ThdlDebug.noteIffyCode();
|
||||
}
|
||||
doc.insertDuff(0, (DuffData []) value);
|
||||
}
|
||||
|
|
53
source/org/thdl/tib/text/DuffData.java
Normal file
53
source/org/thdl/tib/text/DuffData.java
Normal 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;
|
||||
}
|
||||
}
|
1100
source/org/thdl/tib/text/TibTextUtils.java
Normal file
1100
source/org/thdl/tib/text/TibTextUtils.java
Normal file
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
@ -1,144 +1,225 @@
|
|||
package org.thdl.tib.text;
|
||||
|
||||
public class TibetanHTML {
|
||||
static String[] styleNames =
|
||||
{"tmw","tmw1","tmw2","tmw3","tmw4","tmw5","tmw6","tmw7","tmw8","tmw9"};
|
||||
|
||||
public static String getStyles(String fontSize) {
|
||||
return ".tmw {font: "+fontSize+"pt TibetanMachineWeb}\n"+
|
||||
".tmw1 {font: "+fontSize+"pt TibetanMachineWeb1}\n"+
|
||||
".tmw2 {font: "+fontSize+"pt TibetanMachineWeb2}\n"+
|
||||
".tmw3 {font: "+fontSize+"pt TibetanMachineWeb3}\n"+
|
||||
".tmw4 {font: "+fontSize+"pt TibetanMachineWeb4}\n"+
|
||||
".tmw5 {font: "+fontSize+"pt TibetanMachineWeb5}\n"+
|
||||
".tmw6 {font: "+fontSize+"pt TibetanMachineWeb6}\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 {
|
||||
return getHTML(TibetanDocument.getTibetanMachineWeb(wylie));
|
||||
}
|
||||
catch (InvalidWylieException ive) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static String getHTML(TibetanDocument.DuffData[] duffData) {
|
||||
String[] styleNames =
|
||||
{"tmw","tmw1","tmw2","tmw3","tmw4","tmw5","tmw6","tmw7","tmw8","tmw9"};
|
||||
|
||||
StringBuffer htmlBuffer = new StringBuffer();
|
||||
htmlBuffer.append("<nobr>");
|
||||
|
||||
for (int i=0; i<duffData.length; i++) {
|
||||
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]);
|
||||
htmlBuffer.append("\">");
|
||||
|
||||
switch (c[k]) {
|
||||
case '"':
|
||||
htmlBuffer.append(""");
|
||||
break;
|
||||
case '<':
|
||||
htmlBuffer.append("<");
|
||||
break;
|
||||
case '>':
|
||||
htmlBuffer.append(">");
|
||||
break;
|
||||
case '&':
|
||||
htmlBuffer.append("&");
|
||||
break;
|
||||
default:
|
||||
htmlBuffer.append(c[k]);
|
||||
break;
|
||||
}
|
||||
|
||||
htmlBuffer.append("</span>");
|
||||
if (c[k] < 32) //must be formatting, like carriage return or tab
|
||||
htmlBuffer.append("<br>");
|
||||
|
||||
else {
|
||||
String wylie = TibetanMachineWeb.getWylieForGlyph(duffData[i].font, c[k]);
|
||||
if (TibetanMachineWeb.isWyliePunc(wylie))
|
||||
htmlBuffer.append("<wbr>");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
htmlBuffer.append("</nobr>");
|
||||
return htmlBuffer.toString();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//import org.apache.xerces.dom.DOMImplementationImpl;
|
||||
//import org.w3c.dom.*;
|
||||
|
||||
/*
|
||||
public static Node getHTML(String wylie) {
|
||||
try {
|
||||
return getHTML(TibetanDocument.getTibetanMachineWeb(wylie));
|
||||
}
|
||||
catch (InvalidWylieException ive) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static Node getHTML(TibetanDocument.DuffData[] duffData) {
|
||||
try {
|
||||
DOMImplementationImpl impl = new DOMImplementationImpl();
|
||||
Document doc = impl.createDocument(null, "root", null);
|
||||
// DocumentFragment frag = doc.createDocumentFragment()
|
||||
|
||||
|
||||
Element nobr = doc.createElement("nobr");
|
||||
// frag.appendChild(nobr);
|
||||
|
||||
for (int i=0; i<duffData.length; i++) {
|
||||
char[] c = duffData[i].text.toCharArray();
|
||||
for (int k=0; k<c.length; k++) {
|
||||
Element span = doc.createElement("span");
|
||||
span.setAttribute("class", styleNames[duffData[i].font-1]);
|
||||
// Text tib = doc.createTextNode(String.valueOf(c[k]));
|
||||
// span.appendChild(tib);
|
||||
nobr.appendChild(span);
|
||||
|
||||
String wylie = TibetanMachineWeb.getWylieForGlyph(duffData[i].font, c[k]);
|
||||
if (TibetanMachineWeb.isWyliePunc(wylie)) {
|
||||
Element wbr = doc.createElement("wbr");
|
||||
nobr.appendChild(wbr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//doc.appendChild(nobr);
|
||||
return nobr;
|
||||
|
||||
// return frag;
|
||||
}
|
||||
catch (DOMException dome) {
|
||||
switch (dome.code) {
|
||||
|
||||
case DOMException.HIERARCHY_REQUEST_ERR:
|
||||
System.out.println("hierarchy error!!");
|
||||
break;
|
||||
|
||||
case DOMException.WRONG_DOCUMENT_ERR:
|
||||
System.out.println("wrong doc error!!");
|
||||
break;
|
||||
|
||||
case DOMException.NO_MODIFICATION_ALLOWED_ERR:
|
||||
System.out.println("no mod allowed error!!");
|
||||
break;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
*/
|
||||
package org.thdl.tib.text;
|
||||
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
public class TibetanHTML {
|
||||
static String[] styleNames =
|
||||
{"tmw","tmw1","tmw2","tmw3","tmw4","tmw5","tmw6","tmw7","tmw8","tmw9"};
|
||||
|
||||
public static String getStyles(String fontSize) {
|
||||
return ".tmw {font: "+fontSize+"pt TibetanMachineWeb}\n"+
|
||||
".tmw1 {font: "+fontSize+"pt TibetanMachineWeb1}\n"+
|
||||
".tmw2 {font: "+fontSize+"pt TibetanMachineWeb2}\n"+
|
||||
".tmw3 {font: "+fontSize+"pt TibetanMachineWeb3}\n"+
|
||||
".tmw4 {font: "+fontSize+"pt TibetanMachineWeb4}\n"+
|
||||
".tmw5 {font: "+fontSize+"pt TibetanMachineWeb5}\n"+
|
||||
".tmw6 {font: "+fontSize+"pt TibetanMachineWeb6}\n"+
|
||||
".tmw7 {font: "+fontSize+"pt TibetanMachineWeb7}\n"+
|
||||
".tmw8 {font: "+fontSize+"pt TibetanMachineWeb8}\n"+
|
||||
".tmw9 {font: "+fontSize+"pt TibetanMachineWeb9}\n";
|
||||
}
|
||||
|
||||
public static String getHTMLX(String wylie) {
|
||||
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 getHTMLX(DuffData[] duffData) {
|
||||
String[] styleNames =
|
||||
{"tmw","tmw1","tmw2","tmw3","tmw4","tmw5","tmw6","tmw7","tmw8","tmw9"};
|
||||
|
||||
StringBuffer htmlBuffer = new StringBuffer();
|
||||
htmlBuffer.append("<nobr>");
|
||||
|
||||
for (int i=0; i<duffData.length; i++) {
|
||||
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]);
|
||||
htmlBuffer.append("\">");
|
||||
|
||||
if (c[k] > 32 && c[k] < 127) { //ie if it's not formatting
|
||||
switch (c[k]) {
|
||||
case '"':
|
||||
htmlBuffer.append(""");
|
||||
break;
|
||||
case '<':
|
||||
htmlBuffer.append("<");
|
||||
break;
|
||||
case '>':
|
||||
htmlBuffer.append(">");
|
||||
break;
|
||||
case '&':
|
||||
htmlBuffer.append("&");
|
||||
break;
|
||||
default:
|
||||
htmlBuffer.append(c[k]);
|
||||
break;
|
||||
}
|
||||
htmlBuffer.append("</span>");
|
||||
String wylie = TibetanMachineWeb.getWylieForGlyph(duffData[i].font, c[k]);
|
||||
if (TibetanMachineWeb.isWyliePunc(wylie))
|
||||
htmlBuffer.append("<wbr/>");
|
||||
} else {
|
||||
htmlBuffer.append("</span><br/>");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
htmlBuffer.append("</nobr>");
|
||||
return htmlBuffer.toString();
|
||||
}
|
||||
|
||||
public static String getIndentedHTML(String wylie) {
|
||||
return getHTML("_" + wylie);
|
||||
}
|
||||
|
||||
public static String getHTML(String wylie) {
|
||||
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 getHTML(DuffData[] duffData) {
|
||||
String[] styleNames =
|
||||
{"tmw","tmw1","tmw2","tmw3","tmw4","tmw5","tmw6","tmw7","tmw8","tmw9"};
|
||||
|
||||
StringBuffer htmlBuffer = new StringBuffer();
|
||||
htmlBuffer.append("<nobr>");
|
||||
|
||||
for (int i=0; i<duffData.length; i++) {
|
||||
htmlBuffer.append("<span class=\"");
|
||||
htmlBuffer.append(styleNames[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(""");
|
||||
break;
|
||||
case '<':
|
||||
htmlBuffer.append("<");
|
||||
break;
|
||||
case '>':
|
||||
htmlBuffer.append(">");
|
||||
break;
|
||||
case '&':
|
||||
htmlBuffer.append("&");
|
||||
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("</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(""");
|
||||
break;
|
||||
case '<':
|
||||
htmlBuffer.append("<");
|
||||
break;
|
||||
case '>':
|
||||
htmlBuffer.append(">");
|
||||
break;
|
||||
case '&':
|
||||
htmlBuffer.append("&");
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -126,14 +126,14 @@ public class TibetanQTText {
|
|||
|
||||
public static String getQTText(String wylie) {
|
||||
try {
|
||||
return getQTText(TibetanDocument.getTibetanMachineWeb(wylie));
|
||||
return getQTText(TibTextUtils.getTibetanMachineWeb(wylie));
|
||||
}
|
||||
catch (InvalidWylieException ive) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static String getQTText(TibetanDocument.DuffData[] duffData) {
|
||||
public static String getQTText(DuffData[] duffData) {
|
||||
StringBuffer qtBuffer = new StringBuffer();
|
||||
qtBuffer.append("{size:" + tibFontSize + "}");
|
||||
|
||||
|
|
|
@ -126,14 +126,14 @@ public class TibetanQTText2 {
|
|||
|
||||
public static String getQTText(String wylie) {
|
||||
try {
|
||||
return getQTText(TibetanDocument.getTibetanMachineWeb(wylie));
|
||||
return getQTText(TibTextUtils.getTibetanMachineWeb(wylie));
|
||||
}
|
||||
catch (InvalidWylieException ive) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static String getQTText(TibetanDocument.DuffData[] duffData) {
|
||||
public static String getQTText(DuffData[] duffData) {
|
||||
StringBuffer qtBuffer = new StringBuffer();
|
||||
qtBuffer.append("{size:" + tibFontSize + "}");
|
||||
|
||||
|
|
|
@ -119,6 +119,17 @@ public class ThdlDebug {
|
|||
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
|
||||
* to standard output/error but ALSO prints to the log file named
|
||||
* (prefix + suffix). Be sure the log file name is a relative
|
||||
|
|
Loading…
Reference in a new issue