Fixed bug 617156, "DuffPane ignores setEditable(false)".

I fixed this the easy way, by checking the value of isEditable() before
cutting, pasting, or adding typed text.  I may have missed a spot, but
checking at a lower level is a bit less efficient.

Fixing this the hard way, the keymaps-and-overridden-default-action way,
seems like it will make the code uglier, not cleaner.  And it won't get us
closer to fixing the killer bug, 614475, "Improper Line Wrapping".
This commit is contained in:
dchandler 2002-10-20 05:54:29 +00:00
parent 79776d44f9
commit 0097be4266
2 changed files with 26 additions and 7 deletions

View file

@ -882,13 +882,18 @@ class RTFSelection implements ClipboardOwner, Transferable {
ThdlDebug.noteIffyCode(); ThdlDebug.noteIffyCode();
} }
} }
if (remove) if (remove) {
// Respect setEditable(boolean):
if (!this.isEditable())
return;
try { try {
getDocument().remove(p1, p2-p1); getDocument().remove(p1, p2-p1);
} catch (BadLocationException ble) { } catch (BadLocationException ble) {
ble.printStackTrace(); ble.printStackTrace();
ThdlDebug.noteIffyCode(); ThdlDebug.noteIffyCode();
} }
}
} }
/** /**
@ -902,6 +907,9 @@ class RTFSelection implements ClipboardOwner, Transferable {
* @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):
if (!this.isEditable())
return;
try { try {
Transferable contents = rtfBoard.getContents(this); Transferable contents = rtfBoard.getContents(this);
if (contents.isDataFlavorSupported(rtfFlavor)) { if (contents.isDataFlavorSupported(rtfFlavor)) {
@ -971,9 +979,7 @@ public void paste(int offset) {
if (e.isActionKey()) if (e.isActionKey())
initKeyboard(); initKeyboard();
int code = e.getKeyCode(); switch (e.getKeyCode()) {
switch (code) {
case KeyEvent.VK_ESCAPE: case KeyEvent.VK_ESCAPE:
e.consume(); e.consume();
initKeyboard(); initKeyboard();
@ -1041,9 +1047,7 @@ public void paste(int offset) {
* and init the keyboard here in key released * and init the keyboard here in key released
* though i don't really know why... * though i don't really know why...
*/ */
int code = e.getKeyCode(); if (e.getKeyCode() == KeyEvent.VK_BACK_SPACE)
if (code == KeyEvent.VK_BACK_SPACE)
initKeyboard(); initKeyboard();
} }
@ -1060,6 +1064,10 @@ public void paste(int offset) {
public void keyTyped(KeyEvent e) { public void keyTyped(KeyEvent e) {
e.consume(); e.consume();
// Respect setEditable(boolean):
if (!this.isEditable())
return;
if (isTibetan) if (isTibetan)
processTibetan(e); processTibetan(e);
else { else {

View file

@ -277,6 +277,17 @@ public class Jskad extends JPanel implements DocumentListener {
toolsMenu.add(importItem); toolsMenu.add(importItem);
} }
if (ThdlOptions.getBooleanOption("thdl.add.developer.options.to.menu")) {
toolsMenu.addSeparator();
JMenuItem DevelItem = new JMenuItem("Toggle read-only");
DevelItem.addActionListener(new ThdlActionListener() {
public void theRealActionPerformed(ActionEvent e) {
dp.setEditable(!dp.isEditable());
}
});
toolsMenu.add(DevelItem);
}
menuBar.add(toolsMenu); menuBar.add(toolsMenu);
JMenu infoMenu = new JMenu("Info"); JMenu infoMenu = new JMenu("Info");