A DuffPane is now a TibetanPane. A TibetanPane is much more lightweight
but does line breaks correctly. I.e., I refactored DuffPane into two classes. I did this trying to track down a subtle bug in line breaking: 'gye ' breaks after 'gy' sometimes, with the dreng bo on the next line, but only when you resize the window certain ways, and only in Savant (and maybe QD and the translation tool, I don't know) but not in Jskad. I was not successful in finding the bug, but it still exists when I use TibetanPanes instead of DuffPanes in org.thdl.savant.tib.*.
This commit is contained in:
parent
86e384352b
commit
04da61688d
2 changed files with 141 additions and 65 deletions
|
@ -43,7 +43,7 @@ import org.thdl.util.StatusBar;
|
||||||
* @author Edward Garrett, Tibetan and Himalayan Digital Library
|
* @author Edward Garrett, Tibetan and Himalayan Digital Library
|
||||||
* @version 1.0
|
* @version 1.0
|
||||||
*/
|
*/
|
||||||
public class DuffPane extends JTextPane implements KeyListener, FocusListener {
|
public class DuffPane extends TibetanPane implements KeyListener, FocusListener {
|
||||||
/**
|
/**
|
||||||
* The status bar to update with messages about the current input mode.
|
* The status bar to update with messages about the current input mode.
|
||||||
* Are we expecting a vowel? a subscript? et cetera.
|
* Are we expecting a vowel? a subscript? et cetera.
|
||||||
|
@ -179,16 +179,10 @@ public class DuffPane extends JTextPane implements KeyListener, FocusListener {
|
||||||
*/
|
*/
|
||||||
private boolean isRomanEnabled = true;
|
private boolean isRomanEnabled = true;
|
||||||
/**
|
/**
|
||||||
* The document displayed by this object.
|
|
||||||
*/
|
|
||||||
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.
|
||||||
*/
|
*/
|
||||||
private Caret caret;
|
private Caret caret;
|
||||||
// private StyledEditorKit editorKit;
|
|
||||||
private StyleContext styleContext;
|
|
||||||
private Style rootStyle;
|
private Style rootStyle;
|
||||||
private boolean skipUpdate = false;
|
private boolean skipUpdate = false;
|
||||||
private boolean isCutAndPasteEnabled = true;
|
private boolean isCutAndPasteEnabled = true;
|
||||||
|
@ -197,9 +191,7 @@ public class DuffPane extends JTextPane implements KeyListener, FocusListener {
|
||||||
private int romanFontSize;
|
private int romanFontSize;
|
||||||
private MutableAttributeSet romanAttributeSet;
|
private MutableAttributeSet romanAttributeSet;
|
||||||
|
|
||||||
public Clipboard rtfBoard;
|
private Clipboard rtfBoard;
|
||||||
public DataFlavor rtfFlavor;
|
|
||||||
public RTFEditorKit rtfEd = null;
|
|
||||||
|
|
||||||
/** Initializes this object. All constructors should call
|
/** Initializes this object. All constructors should call
|
||||||
this. */
|
this. */
|
||||||
|
@ -289,25 +281,14 @@ public RTFEditorKit rtfEd = null;
|
||||||
*/
|
*/
|
||||||
private void setupEditor() {
|
private void setupEditor() {
|
||||||
rtfBoard = getToolkit().getSystemClipboard();
|
rtfBoard = getToolkit().getSystemClipboard();
|
||||||
rtfFlavor = new DataFlavor("text/rtf", "Rich Text Format");
|
|
||||||
rtfEd = new TibetanRTFEditorKit();
|
|
||||||
setEditorKit(rtfEd);
|
|
||||||
styleContext = new StyleContext();
|
|
||||||
|
|
||||||
doc = new TibetanDocument(styleContext);
|
newDocument();
|
||||||
doc.setTibetanFontSize(defaultTibFontSize());
|
|
||||||
setDocument(doc);
|
|
||||||
|
|
||||||
Style defaultStyle = styleContext.getStyle(StyleContext.DEFAULT_STYLE);
|
|
||||||
StyleConstants.setFontFamily(defaultStyle, "TibetanMachineWeb");
|
|
||||||
StyleConstants.setFontSize(defaultStyle, defaultTibFontSize()); // FIXME make pref
|
|
||||||
|
|
||||||
romanFontFamily = ThdlOptions.getStringOption("thdl.default.roman.font.face",
|
romanFontFamily = ThdlOptions.getStringOption("thdl.default.roman.font.face",
|
||||||
"Serif"); // FIXME write out this preference.
|
"Serif"); // FIXME write out this preference.
|
||||||
romanFontSize = defaultRomanFontSize(); // FIXME make pref
|
romanFontSize = defaultRomanFontSize();
|
||||||
setRomanAttributeSet(romanFontFamily, romanFontSize);
|
setRomanAttributeSet(romanFontFamily, romanFontSize);
|
||||||
|
|
||||||
// newDocument();
|
|
||||||
caret = getCaret();
|
caret = getCaret();
|
||||||
|
|
||||||
addKeyListener(this);
|
addKeyListener(this);
|
||||||
|
@ -397,10 +378,15 @@ public RTFEditorKit rtfEd = null;
|
||||||
* Clears the current document.
|
* Clears the current document.
|
||||||
*/
|
*/
|
||||||
public void newDocument() {
|
public void newDocument() {
|
||||||
styleContext = new StyleContext();
|
StyleContext styleContext = new StyleContext();
|
||||||
|
|
||||||
doc = new TibetanDocument(styleContext);
|
doc = new TibetanDocument(styleContext);
|
||||||
doc.setTibetanFontSize(defaultTibFontSize());
|
doc.setTibetanFontSize(defaultTibFontSize());
|
||||||
|
|
||||||
|
// Something about the order in which you do this step
|
||||||
|
// relative to the others in this method matters. You'll get
|
||||||
|
// a small cursor, though most everything else will be normal,
|
||||||
|
// if you call setDocument(doc) at the end of this method.
|
||||||
setDocument(doc);
|
setDocument(doc);
|
||||||
|
|
||||||
Style defaultStyle = styleContext.getStyle(StyleContext.DEFAULT_STYLE);
|
Style defaultStyle = styleContext.getStyle(StyleContext.DEFAULT_STYLE);
|
||||||
|
@ -493,7 +479,7 @@ public RTFEditorKit rtfEd = null;
|
||||||
*/
|
*/
|
||||||
public void append(int offset, String s, MutableAttributeSet attr) {
|
public void append(int offset, String s, MutableAttributeSet attr) {
|
||||||
try {
|
try {
|
||||||
doc.insertString(offset, s, attr);
|
getTibDoc().insertString(offset, s, attr);
|
||||||
}
|
}
|
||||||
catch (BadLocationException ble) {
|
catch (BadLocationException ble) {
|
||||||
}
|
}
|
||||||
|
@ -506,7 +492,7 @@ public RTFEditorKit rtfEd = null;
|
||||||
*/
|
*/
|
||||||
public void setTibetanFontSize(int size) {
|
public void setTibetanFontSize(int size) {
|
||||||
if (size > 0)
|
if (size > 0)
|
||||||
doc.setTibetanFontSize(size);
|
getTibDoc().setTibetanFontSize(size);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -515,7 +501,7 @@ public RTFEditorKit rtfEd = null;
|
||||||
* text entry mode
|
* text entry mode
|
||||||
*/
|
*/
|
||||||
public int getTibetanFontSize() {
|
public int getTibetanFontSize() {
|
||||||
return doc.getTibetanFontSize();
|
return getTibDoc().getTibetanFontSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -556,7 +542,7 @@ public RTFEditorKit rtfEd = null;
|
||||||
*/
|
*/
|
||||||
private void backSpace(int k) {
|
private void backSpace(int k) {
|
||||||
try {
|
try {
|
||||||
doc.remove(caret.getDot()-k, k);
|
getTibDoc().remove(caret.getDot()-k, k);
|
||||||
}
|
}
|
||||||
catch (BadLocationException ble) {
|
catch (BadLocationException ble) {
|
||||||
}
|
}
|
||||||
|
@ -628,7 +614,7 @@ public RTFEditorKit rtfEd = null;
|
||||||
|
|
||||||
java.util.List sublist = newGlyphList.subList(k, newGlyphCount);
|
java.util.List sublist = newGlyphList.subList(k, newGlyphCount);
|
||||||
DuffData[] dd = TibTextUtils.convertGlyphs(sublist);
|
DuffData[] dd = TibTextUtils.convertGlyphs(sublist);
|
||||||
doc.insertDuff(caret.getDot(), dd);
|
getTibDoc().insertDuff(caret.getDot(), dd);
|
||||||
return newGlyphList;
|
return newGlyphList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -652,13 +638,13 @@ public RTFEditorKit rtfEd = null;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
AttributeSet attr = doc.getCharacterElement(caret.getDot()-1).getAttributes();
|
AttributeSet attr = getTibDoc().getCharacterElement(caret.getDot()-1).getAttributes();
|
||||||
String fontName = StyleConstants.getFontFamily(attr);
|
String fontName = StyleConstants.getFontFamily(attr);
|
||||||
int fontNum;
|
int fontNum;
|
||||||
|
|
||||||
if (0 != (fontNum = TibetanMachineWeb.getTMWFontNumber(fontName))) {
|
if (0 != (fontNum = TibetanMachineWeb.getTMWFontNumber(fontName))) {
|
||||||
try {
|
try {
|
||||||
char c2 = doc.getText(caret.getDot()-1, 1).charAt(0);
|
char c2 = getTibDoc().getText(caret.getDot()-1, 1).charAt(0);
|
||||||
int k = (int)c2;
|
int k = (int)c2;
|
||||||
if (k<32 || k>126) { //if previous character is formatting or some other non-character
|
if (k<32 || k>126) { //if previous character is formatting or some other non-character
|
||||||
if (!TibetanMachineWeb.isAChenRequiredBeforeVowel())
|
if (!TibetanMachineWeb.isAChenRequiredBeforeVowel())
|
||||||
|
@ -679,10 +665,10 @@ public RTFEditorKit rtfEd = null;
|
||||||
DuffCode dc_2 = new DuffCode(fontNum, c2);
|
DuffCode dc_2 = new DuffCode(fontNum, c2);
|
||||||
|
|
||||||
if (caret.getDot() > 2) {
|
if (caret.getDot() > 2) {
|
||||||
attr = doc.getCharacterElement(caret.getDot()-2).getAttributes();
|
attr = getTibDoc().getCharacterElement(caret.getDot()-2).getAttributes();
|
||||||
fontName = StyleConstants.getFontFamily(attr);
|
fontName = StyleConstants.getFontFamily(attr);
|
||||||
if (0 != (fontNum = TibetanMachineWeb.getTMWFontNumber(fontName))) {
|
if (0 != (fontNum = TibetanMachineWeb.getTMWFontNumber(fontName))) {
|
||||||
c2 = doc.getText(caret.getDot()-2, 1).charAt(0);
|
c2 = getTibDoc().getText(caret.getDot()-2, 1).charAt(0);
|
||||||
dc_1 = new DuffCode(fontNum, c2);
|
dc_1 = new DuffCode(fontNum, c2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -739,7 +725,7 @@ public RTFEditorKit rtfEd = null;
|
||||||
DuffCode dc = dc_array[TibetanMachineWeb.TMW];
|
DuffCode dc = dc_array[TibetanMachineWeb.TMW];
|
||||||
java.util.List achenlist = TibTextUtils.getVowel(dc,v);
|
java.util.List achenlist = TibTextUtils.getVowel(dc,v);
|
||||||
DuffData[] dd = TibTextUtils.convertGlyphs(achenlist);
|
DuffData[] dd = TibTextUtils.convertGlyphs(achenlist);
|
||||||
doc.insertDuff(caret.getDot(), dd);
|
getTibDoc().insertDuff(caret.getDot(), dd);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -754,7 +740,7 @@ public RTFEditorKit rtfEd = null;
|
||||||
if (caret.getDot()==0)
|
if (caret.getDot()==0)
|
||||||
break special_bindu_block;
|
break special_bindu_block;
|
||||||
|
|
||||||
AttributeSet attr = doc.getCharacterElement(caret.getDot()-1).getAttributes();
|
AttributeSet attr = getTibDoc().getCharacterElement(caret.getDot()-1).getAttributes();
|
||||||
String fontName = StyleConstants.getFontFamily(attr);
|
String fontName = StyleConstants.getFontFamily(attr);
|
||||||
int fontNum;
|
int fontNum;
|
||||||
|
|
||||||
|
@ -762,7 +748,7 @@ public RTFEditorKit rtfEd = null;
|
||||||
break special_bindu_block;
|
break special_bindu_block;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
char c2 = doc.getText(caret.getDot()-1, 1).charAt(0);
|
char c2 = getTibDoc().getText(caret.getDot()-1, 1).charAt(0);
|
||||||
int k = (int)c2;
|
int k = (int)c2;
|
||||||
if (k<32 || k>126) //if previous character is formatting or some other non-character
|
if (k<32 || k>126) //if previous character is formatting or some other non-character
|
||||||
break special_bindu_block;
|
break special_bindu_block;
|
||||||
|
@ -786,7 +772,7 @@ public RTFEditorKit rtfEd = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
DuffData[] dd = TibTextUtils.convertGlyphs(TibTextUtils.getBindu(null));
|
DuffData[] dd = TibTextUtils.convertGlyphs(TibTextUtils.getBindu(null));
|
||||||
doc.insertDuff(caret.getDot(), dd);
|
getTibDoc().insertDuff(caret.getDot(), dd);
|
||||||
initKeyboard();
|
initKeyboard();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -814,12 +800,14 @@ public RTFEditorKit rtfEd = null;
|
||||||
appendStatus(" (because the window focus was lost)");
|
appendStatus(" (because the window focus was lost)");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIXMEDOC
|
||||||
class RTFSelection implements ClipboardOwner, Transferable {
|
class RTFSelection implements ClipboardOwner, Transferable {
|
||||||
DataFlavor[] supportedFlavor;
|
private DataFlavor[] supportedFlavor;
|
||||||
ByteArrayOutputStream rtfOut;
|
private ByteArrayOutputStream rtfOut;
|
||||||
String plainText;
|
private String plainText;
|
||||||
|
|
||||||
RTFSelection(StyledDocument doc, int offset, int length) {
|
// FIXMEDOC
|
||||||
|
RTFSelection(StyledDocument sdoc, int offset, int length) {
|
||||||
supportedFlavor = new DataFlavor[2];
|
supportedFlavor = new DataFlavor[2];
|
||||||
supportedFlavor[0] = rtfFlavor;
|
supportedFlavor[0] = rtfFlavor;
|
||||||
supportedFlavor[1] = DataFlavor.stringFlavor;
|
supportedFlavor[1] = DataFlavor.stringFlavor;
|
||||||
|
@ -829,8 +817,8 @@ class RTFSelection implements ClipboardOwner, Transferable {
|
||||||
StyledDocument newDoc = new DefaultStyledDocument();
|
StyledDocument newDoc = new DefaultStyledDocument();
|
||||||
for (int i=offset; i<offset+length; i++) {
|
for (int i=offset; i<offset+length; i++) {
|
||||||
try {
|
try {
|
||||||
String s = doc.getText(i,1);
|
String s = sdoc.getText(i,1);
|
||||||
AttributeSet as = doc.getCharacterElement(i).getAttributes();
|
AttributeSet as = sdoc.getCharacterElement(i).getAttributes();
|
||||||
newDoc.insertString(i-offset, s, as);
|
newDoc.insertString(i-offset, s, as);
|
||||||
} catch (BadLocationException ble) {
|
} catch (BadLocationException ble) {
|
||||||
ble.printStackTrace();
|
ble.printStackTrace();
|
||||||
|
@ -848,8 +836,10 @@ class RTFSelection implements ClipboardOwner, Transferable {
|
||||||
ThdlDebug.noteIffyCode();
|
ThdlDebug.noteIffyCode();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// FIXMEDOC
|
||||||
public void lostOwnership(Clipboard clipboard, Transferable contents) {
|
public void lostOwnership(Clipboard clipboard, Transferable contents) {
|
||||||
}
|
}
|
||||||
|
// FIXMEDOC
|
||||||
public Object getTransferData(DataFlavor flavor) {
|
public Object getTransferData(DataFlavor flavor) {
|
||||||
if (flavor.equals(rtfFlavor))
|
if (flavor.equals(rtfFlavor))
|
||||||
return new ByteArrayInputStream(rtfOut.toByteArray());
|
return new ByteArrayInputStream(rtfOut.toByteArray());
|
||||||
|
@ -857,16 +847,18 @@ class RTFSelection implements ClipboardOwner, Transferable {
|
||||||
return plainText;
|
return plainText;
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
// FIXMEDOC
|
||||||
public DataFlavor[] getTransferDataFlavors() {
|
public DataFlavor[] getTransferDataFlavors() {
|
||||||
return supportedFlavor;
|
return supportedFlavor;
|
||||||
}
|
}
|
||||||
|
// FIXMEDOC
|
||||||
public boolean isDataFlavorSupported(DataFlavor flavor) {
|
public boolean isDataFlavorSupported(DataFlavor flavor) {
|
||||||
for (int i=0; i<supportedFlavor.length; i++)
|
for (int i=0; i<supportedFlavor.length; i++)
|
||||||
if (flavor.equals(supportedFlavor[i]))
|
if (flavor.equals(supportedFlavor[i]))
|
||||||
return true;
|
return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
} // class RTFSelection
|
||||||
|
|
||||||
/** Copies the current selection to the system clipboard, unless
|
/** Copies the current selection to the system clipboard, unless
|
||||||
cut-and-paste operations are disabled. */
|
cut-and-paste operations are disabled. */
|
||||||
|
@ -974,7 +966,7 @@ public void paste(int offset) {
|
||||||
try {
|
try {
|
||||||
String s = sd.getText(i,1);
|
String s = sd.getText(i,1);
|
||||||
AttributeSet as = sd.getCharacterElement(i).getAttributes();
|
AttributeSet as = sd.getCharacterElement(i).getAttributes();
|
||||||
doc.insertString(p1+i, s, as);
|
getTibDoc().insertString(p1+i, s, as);
|
||||||
} catch (BadLocationException ble) {
|
} catch (BadLocationException ble) {
|
||||||
ble.printStackTrace();
|
ble.printStackTrace();
|
||||||
ThdlDebug.noteIffyCode();
|
ThdlDebug.noteIffyCode();
|
||||||
|
@ -1056,7 +1048,7 @@ public void paste(int offset) {
|
||||||
if (e.isControlDown() && isCutAndPasteEnabled) {
|
if (e.isControlDown() && isCutAndPasteEnabled) {
|
||||||
e.consume();
|
e.consume();
|
||||||
setSelectionStart(0);
|
setSelectionStart(0);
|
||||||
setSelectionEnd(doc.getLength());
|
setSelectionEnd(getTibDoc().getLength());
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -1086,7 +1078,7 @@ public void paste(int offset) {
|
||||||
if (this.isEditable()) {
|
if (this.isEditable()) {
|
||||||
initKeyboard();
|
initKeyboard();
|
||||||
if (isTibetan)
|
if (isTibetan)
|
||||||
doc.appendDuff(caret.getDot()," ",TibetanMachineWeb.getAttributeSet(1));
|
getTibDoc().appendDuff(caret.getDot()," ",TibetanMachineWeb.getAttributeSet(1));
|
||||||
else
|
else
|
||||||
append(" ", romanAttributeSet);
|
append(" ", romanAttributeSet);
|
||||||
}
|
}
|
||||||
|
@ -1097,7 +1089,7 @@ public void paste(int offset) {
|
||||||
if (this.isEditable()) {
|
if (this.isEditable()) {
|
||||||
initKeyboard();
|
initKeyboard();
|
||||||
if (isTibetan)
|
if (isTibetan)
|
||||||
doc.appendDuff(caret.getDot(),"\n",TibetanMachineWeb.getAttributeSet(1)); // FIXME does this work on all platforms?
|
getTibDoc().appendDuff(caret.getDot(),"\n",TibetanMachineWeb.getAttributeSet(1)); // FIXME does this work on all platforms?
|
||||||
else
|
else
|
||||||
append("\n", romanAttributeSet); // FIXME does this work on all platforms?
|
append("\n", romanAttributeSet); // FIXME does this work on all platforms?
|
||||||
}
|
}
|
||||||
|
@ -1197,7 +1189,7 @@ public void paste(int offset) {
|
||||||
if (kev.getKeyCode() != KeyEvent.VK_ESCAPE) {
|
if (kev.getKeyCode() != KeyEvent.VK_ESCAPE) {
|
||||||
try {
|
try {
|
||||||
initKeyboard();
|
initKeyboard();
|
||||||
doc.remove(start, end-start);
|
getTibDoc().remove(start, end-start);
|
||||||
shouldIBackSpace = false;
|
shouldIBackSpace = false;
|
||||||
}
|
}
|
||||||
catch (BadLocationException ble) {
|
catch (BadLocationException ble) {
|
||||||
|
@ -1279,8 +1271,8 @@ public void paste(int offset) {
|
||||||
updateStatus("!isStackingOn || (isStackingOn && isDefinitelyTibetan==isDefinitelyTibetan_default)");
|
updateStatus("!isStackingOn || (isStackingOn && isDefinitelyTibetan==isDefinitelyTibetan_default)");
|
||||||
}
|
}
|
||||||
else {try {
|
else {try {
|
||||||
char ch = doc.getText(caret.getDot()-1, 1).charAt(0);
|
char ch = getTibDoc().getText(caret.getDot()-1, 1).charAt(0);
|
||||||
AttributeSet attr = doc.getCharacterElement(caret.getDot()-1).getAttributes();
|
AttributeSet attr = getTibDoc().getCharacterElement(caret.getDot()-1).getAttributes();
|
||||||
String fontName = StyleConstants.getFontFamily(attr);
|
String fontName = StyleConstants.getFontFamily(attr);
|
||||||
int fontNum = TibetanMachineWeb.getTMWFontNumber(fontName);
|
int fontNum = TibetanMachineWeb.getTMWFontNumber(fontName);
|
||||||
|
|
||||||
|
@ -1343,7 +1335,7 @@ public void paste(int offset) {
|
||||||
else {
|
else {
|
||||||
DuffCode puncDc = TibetanMachineWeb.getGlyph(val);
|
DuffCode puncDc = TibetanMachineWeb.getGlyph(val);
|
||||||
MutableAttributeSet mas = TibetanMachineWeb.getAttributeSet(puncDc.getFontNum());
|
MutableAttributeSet mas = TibetanMachineWeb.getAttributeSet(puncDc.getFontNum());
|
||||||
doc.appendDuff(caret.getDot(), String.valueOf(puncDc.getCharacter()), mas);
|
getTibDoc().appendDuff(caret.getDot(), String.valueOf(puncDc.getCharacter()), mas);
|
||||||
}
|
}
|
||||||
|
|
||||||
initKeyboard();
|
initKeyboard();
|
||||||
|
@ -1599,25 +1591,25 @@ public void paste(int offset) {
|
||||||
java.util.List dcs = new ArrayList();
|
java.util.List dcs = new ArrayList();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
endPos = doc.createPosition(end);
|
endPos = getTibDoc().createPosition(end);
|
||||||
i = start;
|
i = start;
|
||||||
|
|
||||||
while (i < endPos.getOffset()+1) {
|
while (i < endPos.getOffset()+1) {
|
||||||
attr = doc.getCharacterElement(i).getAttributes();
|
attr = getTibDoc().getCharacterElement(i).getAttributes();
|
||||||
fontName = StyleConstants.getFontFamily(attr);
|
fontName = StyleConstants.getFontFamily(attr);
|
||||||
|
|
||||||
if ((0 == (fontNum = TibetanMachineWeb.getTMWFontNumber(fontName))) || i==endPos.getOffset()) {
|
if ((0 == (fontNum = TibetanMachineWeb.getTMWFontNumber(fontName))) || i==endPos.getOffset()) {
|
||||||
if (i != start) {
|
if (i != start) {
|
||||||
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);
|
getTibDoc().remove(start, i-start);
|
||||||
append(start, TibTextUtils.getWylie(dc_array), romanAttributeSet);
|
append(start, TibTextUtils.getWylie(dc_array), romanAttributeSet);
|
||||||
dcs.clear();
|
dcs.clear();
|
||||||
}
|
}
|
||||||
start = i+1;
|
start = i+1;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
ch = doc.getText(i,1).charAt(0);
|
ch = getTibDoc().getText(i,1).charAt(0);
|
||||||
dc = new DuffCode(fontNum, ch);
|
dc = new DuffCode(fontNum, ch);
|
||||||
dcs.add(dc);
|
dcs.add(dc);
|
||||||
}
|
}
|
||||||
|
@ -1645,7 +1637,7 @@ public void paste(int offset) {
|
||||||
String next = sTok.nextToken();
|
String next = sTok.nextToken();
|
||||||
if (next.equals("\n") || next.equals("\t")) { // FIXME does this work on all platforms?
|
if (next.equals("\n") || next.equals("\t")) { // FIXME does this work on all platforms?
|
||||||
try {
|
try {
|
||||||
doc.insertString(offset, next, null);
|
getTibDoc().insertString(offset, next, null);
|
||||||
offset++;
|
offset++;
|
||||||
} catch (BadLocationException ble) {
|
} catch (BadLocationException ble) {
|
||||||
ble.printStackTrace();
|
ble.printStackTrace();
|
||||||
|
@ -1653,7 +1645,7 @@ public void paste(int offset) {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
DuffData[] dd = TibTextUtils.getTibetanMachineWeb(next);
|
DuffData[] dd = TibTextUtils.getTibetanMachineWeb(next);
|
||||||
offset = doc.insertDuff(offset, dd);
|
offset = getTibDoc().insertDuff(offset, dd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1692,19 +1684,19 @@ public void paste(int offset) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
sb = new StringBuffer();
|
sb = new StringBuffer();
|
||||||
endPos = doc.createPosition(end);
|
endPos = getTibDoc().createPosition(end);
|
||||||
i = start;
|
i = start;
|
||||||
|
|
||||||
while (i < endPos.getOffset()+1) {
|
while (i < endPos.getOffset()+1) {
|
||||||
attr = doc.getCharacterElement(i).getAttributes();
|
attr = getTibDoc().getCharacterElement(i).getAttributes();
|
||||||
fontName = StyleConstants.getFontFamily(attr);
|
fontName = StyleConstants.getFontFamily(attr);
|
||||||
|
|
||||||
if ((0 != TibetanMachineWeb.getTMWFontNumber(fontName)) || i==endPos.getOffset()) {
|
if ((0 != TibetanMachineWeb.getTMWFontNumber(fontName)) || i==endPos.getOffset()) {
|
||||||
if (i != start) {
|
if (i != start) {
|
||||||
try {
|
try {
|
||||||
DuffData[] duffdata = TibTextUtils.getTibetanMachineWeb(sb.toString());
|
DuffData[] duffdata = TibTextUtils.getTibetanMachineWeb(sb.toString());
|
||||||
doc.remove(start, i-start);
|
getTibDoc().remove(start, i-start);
|
||||||
doc.insertDuff(start, duffdata);
|
getTibDoc().insertDuff(start, duffdata);
|
||||||
}
|
}
|
||||||
catch (InvalidWylieException iwe) {
|
catch (InvalidWylieException iwe) {
|
||||||
JOptionPane.showMessageDialog(this,
|
JOptionPane.showMessageDialog(this,
|
||||||
|
@ -1718,7 +1710,7 @@ public void paste(int offset) {
|
||||||
start = i+1;
|
start = i+1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
sb.append(doc.getText(i, 1));
|
sb.append(getTibDoc().getText(i, 1));
|
||||||
|
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
@ -1736,7 +1728,7 @@ public void paste(int offset) {
|
||||||
* @return the string of Wylie corresponding to the associated document
|
* @return the string of Wylie corresponding to the associated document
|
||||||
* @see org.thdl.tib.text.TibetanDocument#getWylie() */
|
* @see org.thdl.tib.text.TibetanDocument#getWylie() */
|
||||||
public String getWylie() {
|
public String getWylie() {
|
||||||
return doc.getWylie();
|
return getTibDoc().getWylie();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
84
source/org/thdl/tib/input/TibetanPane.java
Normal file
84
source/org/thdl/tib/input/TibetanPane.java
Normal file
|
@ -0,0 +1,84 @@
|
||||||
|
/*
|
||||||
|
The contents of this file are subject to the THDL Open Community License
|
||||||
|
Version 1.0 (the "License"); you may not use this file except in compliance
|
||||||
|
with the License. You may obtain a copy of the License on the THDL web site
|
||||||
|
(http://www.thdl.org/).
|
||||||
|
|
||||||
|
Software distributed under the License is distributed on an "AS IS" basis,
|
||||||
|
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
|
||||||
|
License for the specific terms governing rights and limitations under the
|
||||||
|
License.
|
||||||
|
|
||||||
|
The Initial Developer of this software is the Tibetan and Himalayan Digital
|
||||||
|
Library (THDL). Portions created by the THDL are Copyright 2001 THDL.
|
||||||
|
All Rights Reserved.
|
||||||
|
|
||||||
|
Contributor(s): ______________________________________.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.thdl.tib.input;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
|
import java.util.*;
|
||||||
|
import java.awt.datatransfer.*;
|
||||||
|
import javax.swing.*;
|
||||||
|
import javax.swing.text.*;
|
||||||
|
import javax.swing.text.rtf.*;
|
||||||
|
|
||||||
|
import org.thdl.tib.text.*;
|
||||||
|
import org.thdl.util.ThdlDebug;
|
||||||
|
import org.thdl.util.ThdlLazyException;
|
||||||
|
import org.thdl.util.ThdlOptions;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enables display of Tibetan text using Tibetan Computer Company's
|
||||||
|
* free cross-platform TibetanMachineWeb fonts. Breaks lines
|
||||||
|
* correctly.
|
||||||
|
*
|
||||||
|
* <p> Conceptually, we'd like to override getDocument(),
|
||||||
|
* getStyledDocument(), setStyledDocument(..), and setDocument(..).
|
||||||
|
* However, JTextPane is not written flexibly enough to allow that.
|
||||||
|
* You'll get exceptions during construction of a DuffPane if you try.
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author Edward Garrett, Tibetan and Himalayan Digital Library */
|
||||||
|
public class TibetanPane extends JTextPane {
|
||||||
|
/**
|
||||||
|
* The document displayed by this object.
|
||||||
|
*/
|
||||||
|
protected TibetanDocument doc;
|
||||||
|
|
||||||
|
protected DataFlavor rtfFlavor;
|
||||||
|
protected RTFEditorKit rtfEd = null;
|
||||||
|
|
||||||
|
/** Creates a new TibetanPane with a null document model. */
|
||||||
|
TibetanPane() {
|
||||||
|
super();
|
||||||
|
setupJustTheEditor();
|
||||||
|
doc = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Creates a new TibetanPane with a document model d. */
|
||||||
|
public TibetanPane(TibetanDocument d) {
|
||||||
|
super();
|
||||||
|
setupJustTheEditor();
|
||||||
|
doc = d;
|
||||||
|
setDocument(d);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Returns the model of a Tibetan document associated with this
|
||||||
|
* JTextPane. */
|
||||||
|
public TibetanDocument getTibDoc() {
|
||||||
|
return (TibetanDocument)doc;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method sets up the editor.
|
||||||
|
*/
|
||||||
|
private void setupJustTheEditor() {
|
||||||
|
rtfFlavor = new DataFlavor("text/rtf", "Rich Text Format");
|
||||||
|
rtfEd = new TibetanRTFEditorKit();
|
||||||
|
setEditorKit(rtfEd);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // class TibetanPane
|
Loading…
Reference in a new issue