From efa8fc1f25837926e46a6bc2e7505be9e7fa2794 Mon Sep 17 00:00:00 2001 From: dchandler Date: Mon, 14 Apr 2003 05:22:27 +0000 Subject: [PATCH] DuffPane now has the start of a unit test suite. Invoke it via 'ant clean check'. Right now there are tests to ensure that typing certain sequences of keys in the Extended Wylie keyboard gives the expected Extended Wylie back when "Tools/Convert Tibetan to Wylie" is invoked. The syntactically illegal d.wa now converts to Tibetan and then back to d.wa (not dwa, as it did); likewise with the illegal g.wa. wa doesn't take any prefixes, but I prefer clean end-to-end behavior. (jeskd doesn't go end-to-end, though.) Note that you cannot successfully run the DuffPane tests on a Linux box unless your DISPLAY variable is set correctly. Thus, my nightly builds will fail with an Error (as opposed to a Failure). --- build.xml | 10 + dist/NightlyBuilds.html | 6 +- junitbuild.xml | 3 +- source/org/thdl/tib/input/DuffPane.java | 217 ++++++++------ source/org/thdl/tib/input/DuffPaneTest.java | 274 ++++++++++++++++++ source/org/thdl/tib/input/Jskad.java | 23 +- .../org/thdl/tib/text/TibetanMachineWeb.java | 9 +- source/org/thdl/util/ThdlOptions.java | 11 + 8 files changed, 444 insertions(+), 109 deletions(-) create mode 100644 source/org/thdl/tib/input/DuffPaneTest.java diff --git a/build.xml b/build.xml index 8c8a6d2..20d20c0 100644 --- a/build.xml +++ b/build.xml @@ -366,6 +366,16 @@ + + + + + + + + +
  • See here for results of the - nightly JUnit tests. + nightly JUnit tests.  Note that an error on DuffPaneTest is + quite normal; this test runs only when an X11 display can be + opened, and I'm too lazy to run the tests with a framebuffer X + display.  Run 'ant clean check' manually and DuffPaneTest + should pass with flying colors.
  • Today's Javadocs: [public (zip file)] diff --git a/junitbuild.xml b/junitbuild.xml index 1264f71..c01c518 100644 --- a/junitbuild.xml +++ b/junitbuild.xml @@ -34,13 +34,14 @@ - + + diff --git a/source/org/thdl/tib/input/DuffPane.java b/source/org/thdl/tib/input/DuffPane.java index dc34e0a..a81baca 100644 --- a/source/org/thdl/tib/input/DuffPane.java +++ b/source/org/thdl/tib/input/DuffPane.java @@ -26,6 +26,7 @@ import java.awt.font.*; import java.awt.event.*; import javax.swing.*; import javax.swing.text.*; +import javax.swing.event.*; import javax.swing.text.rtf.*; import org.thdl.tib.text.*; @@ -50,7 +51,6 @@ public class DuffPane extends TibetanPane implements FocusListener { */ private StatusBar statBar = null; - /** * A central part of the Tibetan keyboard. As keys are typed, they are * added to charList if they constitute a valid Wylie character. charList @@ -236,6 +236,20 @@ public class DuffPane extends TibetanPane implements FocusListener { initialize(null, null, keyboardURL); } + /** For testing purposes, it's useful to create a DuffPane and not + * hook it up to the UI. If this is true, this DuffPane will + * manage its document's caret rather than having the UI do + * it. */ + private boolean manageCaret = false; + + /** For testing purposes, it's useful to create a DuffPane and not + * hook it up to the UI. If you call htis, then this DuffPane + * will manage its document's caret rather than having the UI do + * it. */ + void enableCaretManaging() { + manageCaret = true; + } + /** Sets the status bar to update with mode information. If sb is null, no status bar will be updated. */ public void setStatusBar(StatusBar sb) { @@ -288,7 +302,7 @@ public class DuffPane extends TibetanPane implements FocusListener { newDocument(); romanFontFamily = ThdlOptions.getStringOption("thdl.default.roman.font.face", - "Serif"); // FIXME write out this preference. + "Serif"); romanFontSize = defaultRomanFontSize(); setRomanAttributeSet(romanFontFamily, romanFontSize); @@ -305,6 +319,32 @@ public class DuffPane extends TibetanPane implements FocusListener { setupKeymap(); } + /** Performs the keystroke key with selected ActionEvent-style + * modifiers modifiers. */ + void performKeyStroke(int modifiers, String key) { + // FIXME: do this assertion: assert(key.length() == 1); + if (!isEditable()) return; + if (((modifiers & ActionEvent.CTRL_MASK) == ActionEvent.CTRL_MASK) || + ((modifiers & ActionEvent.ALT_MASK) == ActionEvent.ALT_MASK) || + ((modifiers & ActionEvent.META_MASK) == ActionEvent.META_MASK)) { + initKeyboard(); + return; + } + if (key != null) { + if (getSelectionStart() < getSelectionEnd()) + replaceSelection(""); + if (isTibetan) { + processTibetanChar(key.charAt(0)); + } else { + processRomanChar(key, romanAttributeSet); + } + if (manageCaret) { + caret.setDot(getTibDoc().getLength()); + } + } + } + + /** * This method sets up the keymap used by DuffPane editors. * The keymap defines a default behavior for key presses @@ -313,30 +353,12 @@ public class DuffPane extends TibetanPane implements FocusListener { private void setupKeymap() { Action defaultAction = new AbstractAction() { public void actionPerformed(ActionEvent e) { - if (!DuffPane.this.isEditable()) return; - if ( ((e.getModifiers() & ActionEvent.CTRL_MASK) == ActionEvent.CTRL_MASK) || - ((e.getModifiers() & ActionEvent.ALT_MASK) == ActionEvent.ALT_MASK) || - ((e.getModifiers() & ActionEvent.META_MASK) == ActionEvent.META_MASK)) { - DuffPane.this.initKeyboard(); - return; - } - if (e.getActionCommand() != null) { - String key = e.getActionCommand(); - if (DuffPane.this.getSelectionStart() < DuffPane.this.getSelectionEnd()) - DuffPane.this.replaceSelection(""); - if (key != null) { - if (isTibetan) processTibetanChar(key.charAt(0)); - else { - //MutableAttributeSet inputAtts = DuffPane.this.getInputAttributes(); - //inputAtts.addAttributes(romanAttributeSet); - processRomanChar(key, romanAttributeSet);//, inputAtts); - } - } - } + DuffPane.this.performKeyStroke(e.getModifiers(), + e.getActionCommand()); } }; createActionTable(this); - Keymap keymap = addKeymap("DuffBindings", getKeymap()); + Keymap keymap = addKeymap("DuffBindings", getKeymap()); keymap.setDefaultAction(defaultAction); setKeymap(keymap); } @@ -373,7 +395,7 @@ public class DuffPane extends TibetanPane implements FocusListener { * respect to stacking, and concerning the differences between * Tibetan and Sanskrit; and then it initializes the input method. */ - public void setupKeyboard() { + private void setupKeyboard() { if (TibetanMachineWeb.hasTibetanStackingKey()) { if (TibetanMachineWeb.hasSanskritStackingKey()) { isDefinitelyTibetan_default = false; @@ -459,10 +481,14 @@ public class DuffPane extends TibetanPane implements FocusListener { // a small cursor, though most everything else will be normal, // if you call setDocument(doc) at the end of this method. setDocument(doc); + ThdlDebug.verify(getTibDoc() == doc); Style defaultStyle = styleContext.getStyle(StyleContext.DEFAULT_STYLE); StyleConstants.setFontFamily(defaultStyle, "TibetanMachineWeb"); StyleConstants.setFontSize(defaultStyle, defaultTibFontSize()); + + newGlyphList.clear(); + initKeyboard(); } /** @@ -474,10 +500,10 @@ public class DuffPane extends TibetanPane implements FocusListener { * backspacing, redrawing, etc. */ private void initKeyboard() { - updateStatus("Jskad is in its basic input mode"); charList.clear(); oldGlyphList.clear(); holdCurrent = new StringBuffer(); + updateStatus("Jskad is in its basic input mode"); isTopHypothesis = false; isTypingVowel = false; @@ -636,9 +662,13 @@ public class DuffPane extends TibetanPane implements FocusListener { */ private void backSpace(int k) { try { - getTibDoc().remove(caret.getDot()-k, k); - } - catch (BadLocationException ble) { + int newEnd = caret.getDot()-k; + if (newEnd >= 0) { + getTibDoc().remove(newEnd, k); + if (manageCaret) caret.setDot(newEnd); + } + } catch (BadLocationException ble) { + ThdlDebug.noteIffyCode(); } } @@ -894,66 +924,6 @@ public class DuffPane extends TibetanPane implements FocusListener { appendStatus(" (because the window focus was lost)"); } - // FIXMEDOC -class RTFSelection implements ClipboardOwner, Transferable { - private DataFlavor[] supportedFlavor; - private ByteArrayOutputStream rtfOut; - private String plainText; - - // FIXMEDOC - RTFSelection(StyledDocument sdoc, int offset, int length) { - supportedFlavor = new DataFlavor[2]; - supportedFlavor[0] = rtfFlavor; - supportedFlavor[1] = DataFlavor.stringFlavor; - try { - //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) - StyledDocument newDoc = new DefaultStyledDocument(); - for (int i=offset; i