fixed the paste. when pasting from text (non-rtf) it used to produce garbage.
now it interprets it as wylie. also made some attributes protected to inherit it.
This commit is contained in:
parent
bff0e6b2fc
commit
650109200f
1 changed files with 31 additions and 45 deletions
|
@ -191,7 +191,7 @@ public class DuffPane extends TibetanPane implements FocusListener {
|
||||||
private String romanFontFamily;
|
private String romanFontFamily;
|
||||||
private int romanFontSize;
|
private int romanFontSize;
|
||||||
|
|
||||||
private Clipboard rtfBoard;
|
protected Clipboard rtfBoard;
|
||||||
|
|
||||||
private Hashtable actions;
|
private Hashtable actions;
|
||||||
|
|
||||||
|
@ -1029,32 +1029,27 @@ public void paste() {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pastes the contents of the system clipboard into this object's
|
* Pastes the contents of the system clipboard into this object's
|
||||||
* document, at the specified position. The only kind of
|
* document, at the specified position. If the text was copied from an
|
||||||
* text accepted from the clipboard is Wylie text.
|
* RTF compliant application, it will be pasted using with the original
|
||||||
|
* fonts and font sizes. Else it will be assumed that it is Wylie text.
|
||||||
* This Wylie is converted and pasted into the document as
|
* This Wylie is converted and pasted into the document as
|
||||||
* TibetanMachineWeb. If the text to paste is invalid Wylie,
|
* TibetanMachineWeb. If the text to paste is invalid Wylie,
|
||||||
* then it will not be pasted, and instead an error message will
|
* then it will not be pasted, and instead an error message will
|
||||||
* appear.
|
* appear.
|
||||||
* @param offset the position in the document you want to paste to
|
* @param offset the position in the document you want to paste to
|
||||||
*/
|
*/
|
||||||
public void paste(int offset) {
|
public void paste(int offset)
|
||||||
|
{
|
||||||
// Respect setEditable(boolean):
|
// Respect setEditable(boolean):
|
||||||
if (!this.isEditable())
|
if (!this.isEditable())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
try {
|
try
|
||||||
|
{
|
||||||
Transferable contents = rtfBoard.getContents(this);
|
Transferable contents = rtfBoard.getContents(this);
|
||||||
|
|
||||||
/*
|
if (contents.isDataFlavorSupported(rtfFlavor))
|
||||||
if (!isRomanEnabled) {
|
{
|
||||||
if (contents.isDataFlavorSupported(DataFlavor.stringFlavor)) {
|
|
||||||
String data = (String)contents.getTransferData(DataFlavor.stringFlavor);
|
|
||||||
toTibetanMachineWeb(data, offset);
|
|
||||||
}
|
|
||||||
} else if (contents.isDataFlavorSupported(rtfFlavor)) {
|
|
||||||
*/
|
|
||||||
|
|
||||||
if (contents.isDataFlavorSupported(rtfFlavor)){
|
|
||||||
|
|
||||||
InputStream in = (InputStream)contents.getTransferData(rtfFlavor);
|
InputStream in = (InputStream)contents.getTransferData(rtfFlavor);
|
||||||
int p1 = offset;
|
int p1 = offset;
|
||||||
|
@ -1068,54 +1063,45 @@ public void paste(int offset) {
|
||||||
|
|
||||||
boolean errorReading = false;
|
boolean errorReading = false;
|
||||||
|
|
||||||
try {
|
try
|
||||||
|
{
|
||||||
if (!ThdlOptions.getBooleanOption("thdl.do.not.fix.rtf.hex.escapes"))
|
if (!ThdlOptions.getBooleanOption("thdl.do.not.fix.rtf.hex.escapes"))
|
||||||
in = new RTFFixerInputStream(in);
|
in = new RTFFixerInputStream(in);
|
||||||
rtfEd.read(in, sd, 0);
|
rtfEd.read(in, sd, 0);
|
||||||
} catch (Exception e) {
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
|
||||||
errorReading = true;
|
errorReading = true;
|
||||||
JOptionPane.showMessageDialog(this,
|
JOptionPane.showMessageDialog(this,
|
||||||
"You cannot paste from the application from which you copied.\nIt uses an RTF format that is too advanced for the version\nof Java Jskad is running atop.");
|
"You cannot paste from the application from which you copied.\nIt uses an RTF format that is too advanced for the version\nof Java Jskad is running atop.");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!errorReading) {
|
if (!errorReading)
|
||||||
/** Added by AM, to fix copy-paste issues for
|
{
|
||||||
Translation Tool. Assumes that if roman is
|
for (int i=0; i<sd.getLength()-1; i++) { //getLength()-1 so that final newline is not included in paste
|
||||||
disabled and you are pasting something in RTF but
|
try {
|
||||||
it is not TibetanMachineWeb then it must be wylie. */
|
String s = sd.getText(i,1);
|
||||||
if (!sd.getFont((sd.getCharacterElement(0).getAttributes())).getFamily().startsWith("TibetanMachineWeb")
|
AttributeSet as
|
||||||
&& !isRomanEnabled
|
= sd.getCharacterElement(i).getAttributes();
|
||||||
&& contents.isDataFlavorSupported(DataFlavor.stringFlavor))
|
getTibDoc().insertString(p1+i, s, as);
|
||||||
{
|
} catch (BadLocationException ble) {
|
||||||
String data = (String)contents.getTransferData(DataFlavor.stringFlavor);
|
ble.printStackTrace();
|
||||||
toTibetanMachineWeb(data, offset);
|
ThdlDebug.noteIffyCode();
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
for (int i=0; i<sd.getLength()-1; i++) { //getLength()-1 so that final newline is not included in paste
|
|
||||||
try {
|
|
||||||
String s = sd.getText(i,1);
|
|
||||||
AttributeSet as
|
|
||||||
= sd.getCharacterElement(i).getAttributes();
|
|
||||||
getTibDoc().insertString(p1+i, s, as);
|
|
||||||
} catch (BadLocationException ble) {
|
|
||||||
ble.printStackTrace();
|
|
||||||
ThdlDebug.noteIffyCode();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else if (contents.isDataFlavorSupported(DataFlavor.stringFlavor))
|
} else if (contents.isDataFlavorSupported(DataFlavor.stringFlavor))
|
||||||
{
|
{
|
||||||
if (!isRomanEnabled) {
|
// if (!isRomanEnabled) {
|
||||||
String data = (String)contents.getTransferData(DataFlavor.stringFlavor);
|
String data = (String)contents.getTransferData(DataFlavor.stringFlavor);
|
||||||
toTibetanMachineWeb(data, offset);
|
toTibetanMachineWeb(data, offset);
|
||||||
}
|
/*}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
String s = (String)contents.getTransferData(DataFlavor.stringFlavor);
|
String s = (String)contents.getTransferData(DataFlavor.stringFlavor);
|
||||||
replaceSelection(s);
|
replaceSelection(s);
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
} catch (UnsupportedFlavorException ufe) {
|
} catch (UnsupportedFlavorException ufe) {
|
||||||
ufe.printStackTrace();
|
ufe.printStackTrace();
|
||||||
|
|
Loading…
Reference in a new issue