We had some useless code for enabling and disabling the clipboard; I've
killed it. Jskad in applets would take QA and some code changes, I bet, so a TODO is good enough. Documented better the clipboard code.
This commit is contained in:
parent
5d99c0ce7f
commit
25f5440218
2 changed files with 26 additions and 42 deletions
|
@ -186,7 +186,6 @@ public class DuffPane extends TibetanPane implements FocusListener {
|
||||||
private Caret caret;
|
private Caret caret;
|
||||||
private Style rootStyle;
|
private Style rootStyle;
|
||||||
private boolean skipUpdate = false;
|
private boolean skipUpdate = false;
|
||||||
private boolean isCutAndPasteEnabled = true;
|
|
||||||
|
|
||||||
private String romanFontFamily;
|
private String romanFontFamily;
|
||||||
private int romanFontSize;
|
private int romanFontSize;
|
||||||
|
@ -992,7 +991,6 @@ public class DuffPane extends TibetanPane implements FocusListener {
|
||||||
* false if it is 'copy'
|
* false if it is 'copy'
|
||||||
*/
|
*/
|
||||||
private void copy(int start, int end, boolean remove) {
|
private void copy(int start, int end, boolean remove) {
|
||||||
updateStatus("Copied to clipboard");
|
|
||||||
int p1 = start;
|
int p1 = start;
|
||||||
int p2 = end;
|
int p2 = end;
|
||||||
if (p1 != p2) {
|
if (p1 != p2) {
|
||||||
|
@ -1000,11 +998,14 @@ public class DuffPane extends TibetanPane implements FocusListener {
|
||||||
RTFSelection rtfSelection = new RTFSelection((StyledDocument)getDocument(), p1, p2-p1);
|
RTFSelection rtfSelection = new RTFSelection((StyledDocument)getDocument(), p1, p2-p1);
|
||||||
try {
|
try {
|
||||||
rtfBoard.setContents(rtfSelection, rtfSelection);
|
rtfBoard.setContents(rtfSelection, rtfSelection);
|
||||||
|
updateStatus("Copied to clipboard");
|
||||||
} catch (IllegalStateException ise) {
|
} catch (IllegalStateException ise) {
|
||||||
ise.printStackTrace();
|
ise.printStackTrace();
|
||||||
ThdlDebug.noteIffyCode();
|
ThdlDebug.noteIffyCode();
|
||||||
}
|
}
|
||||||
}
|
} else
|
||||||
|
updateStatus("Nothing to copy/cut");
|
||||||
|
|
||||||
if (remove) {
|
if (remove) {
|
||||||
// Respect setEditable(boolean):
|
// Respect setEditable(boolean):
|
||||||
if (!this.isEditable())
|
if (!this.isEditable())
|
||||||
|
@ -1013,6 +1014,7 @@ public class DuffPane extends TibetanPane implements FocusListener {
|
||||||
try {
|
try {
|
||||||
ThdlDebug.verify(getDocument() == getTibDoc());
|
ThdlDebug.verify(getDocument() == getTibDoc());
|
||||||
getDocument().remove(p1, p2-p1);
|
getDocument().remove(p1, p2-p1);
|
||||||
|
updateStatus("Cut to clipboard");
|
||||||
} catch (BadLocationException ble) {
|
} catch (BadLocationException ble) {
|
||||||
ble.printStackTrace();
|
ble.printStackTrace();
|
||||||
ThdlDebug.noteIffyCode();
|
ThdlDebug.noteIffyCode();
|
||||||
|
@ -1117,29 +1119,6 @@ public void paste(int offset)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Enables cutting and pasting of Tibetan text.
|
|
||||||
*/
|
|
||||||
public void enableCutAndPaste() {
|
|
||||||
isCutAndPasteEnabled = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Returns true iff cut-and-paste operations are enabled. */
|
|
||||||
public boolean isCutAndPasteOn() {
|
|
||||||
return isCutAndPasteEnabled;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Disables cutting and pasting of Tibetan text.
|
|
||||||
* Cut and paste must be disabled if Jskad's
|
|
||||||
* parent is an applet, because it violates the
|
|
||||||
* Java security sandbox to cut and paste from an
|
|
||||||
* applet to the system clipboard.
|
|
||||||
*/
|
|
||||||
public void disableCutAndPaste() {
|
|
||||||
isCutAndPasteEnabled = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void processRomanChar(String key, AttributeSet attSet) {
|
private void processRomanChar(String key, AttributeSet attSet) {
|
||||||
switch (key.charAt(0)) {
|
switch (key.charAt(0)) {
|
||||||
case KeyEvent.VK_TAB:
|
case KeyEvent.VK_TAB:
|
||||||
|
@ -1652,20 +1631,23 @@ public void paste(int offset)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// FIXMEDOC
|
/** The JDK contains StringSelection, but we want to copy and paste
|
||||||
|
RTF sometimes. Enter RTFSelection. */
|
||||||
class RTFSelection implements ClipboardOwner, Transferable {
|
class RTFSelection implements ClipboardOwner, Transferable {
|
||||||
private DataFlavor[] supportedFlavor;
|
private DataFlavor[] supportedFlavors;
|
||||||
private ByteArrayOutputStream rtfOut;
|
private ByteArrayOutputStream rtfOut;
|
||||||
private String plainText;
|
private String plainText;
|
||||||
|
|
||||||
// FIXMEDOC
|
|
||||||
RTFSelection(StyledDocument sdoc, int offset, int length) {
|
RTFSelection(StyledDocument sdoc, int offset, int length) {
|
||||||
supportedFlavor = new DataFlavor[2];
|
supportedFlavors = new DataFlavor[2];
|
||||||
supportedFlavor[0] = rtfFlavor;
|
supportedFlavors[0] = rtfFlavor;
|
||||||
supportedFlavor[1] = DataFlavor.stringFlavor;
|
supportedFlavors[1] = DataFlavor.stringFlavor;
|
||||||
try {
|
try {
|
||||||
//construct new document that contains only portion of text you want to copy
|
//construct new document that contains only portion of text you want to copy
|
||||||
//this workaround is due to bug 4129911, which will not be fixed (see below after source code)
|
//this workaround is due to bug 4129911, which will not be fixed
|
||||||
|
|
||||||
|
// TODO(dchandler): Is this where we lose formatting like
|
||||||
|
// centering and indention?
|
||||||
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 {
|
||||||
|
@ -1678,7 +1660,10 @@ class RTFSelection implements ClipboardOwner, Transferable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
rtfOut = new ByteArrayOutputStream();
|
rtfOut = new ByteArrayOutputStream();
|
||||||
rtfEd.write(rtfOut, newDoc, 0, newDoc.getLength()); //last two parameters ignored, see bug below
|
|
||||||
|
//last two parameters ignored (bug 4129911?):
|
||||||
|
rtfEd.write(rtfOut, newDoc, 0, newDoc.getLength());
|
||||||
|
|
||||||
plainText = getText(offset, length);
|
plainText = getText(offset, length);
|
||||||
} catch (BadLocationException ble) {
|
} catch (BadLocationException ble) {
|
||||||
ble.printStackTrace();
|
ble.printStackTrace();
|
||||||
|
@ -1688,10 +1673,8 @@ 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());
|
||||||
|
@ -1699,14 +1682,14 @@ class RTFSelection implements ClipboardOwner, Transferable {
|
||||||
return plainText;
|
return plainText;
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
// FIXMEDOC
|
|
||||||
public DataFlavor[] getTransferDataFlavors() {
|
public DataFlavor[] getTransferDataFlavors() {
|
||||||
return supportedFlavor;
|
// TODO(dchandler): Can't the caller modify our array? Let's
|
||||||
|
// return a new array that's a copy, for safety.
|
||||||
|
return supportedFlavors;
|
||||||
}
|
}
|
||||||
// FIXMEDOC
|
|
||||||
public boolean isDataFlavorSupported(DataFlavor flavor) {
|
public boolean isDataFlavorSupported(DataFlavor flavor) {
|
||||||
for (int i=0; i<supportedFlavor.length; i++)
|
for (int i=0; i<supportedFlavors.length; i++)
|
||||||
if (flavor.equals(supportedFlavor[i]))
|
if (flavor.equals(supportedFlavors[i]))
|
||||||
return true;
|
return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -858,7 +858,8 @@ public class Jskad extends JPanel implements DocumentListener {
|
||||||
} else if (parentObject instanceof JApplet) {
|
} else if (parentObject instanceof JApplet) {
|
||||||
JApplet parentApplet = (JApplet)parentObject;
|
JApplet parentApplet = (JApplet)parentObject;
|
||||||
parentApplet.setJMenuBar(menuBar);
|
parentApplet.setJMenuBar(menuBar);
|
||||||
dp.disableCutAndPaste();
|
// TODO(dchandler): disable cut and paste in the applet
|
||||||
|
// (we once did this...)
|
||||||
}
|
}
|
||||||
|
|
||||||
setLayout(new BorderLayout());
|
setLayout(new BorderLayout());
|
||||||
|
|
Loading…
Add table
Reference in a new issue