- Revision
- 598
- Author
- sirenian
- Date
- 2006-12-01 04:50:08 -0600 (Fri, 01 Dec 2006)
Log Message
[EK] Hellbound and swing behaviours now work in both 1.4 and 1.5 vms (Windows, but not the Microsoft vm which is still buggy buggy buggy.)
Modified Paths
- trunk/examples/hellbound/src/behaviour/com/sirenian/hellbound/gui/HellboundFrameBehaviour.java
- trunk/examples/hellbound/src/java/com/sirenian/hellbound/gui/ActionFactory.java
- trunk/extensions/swing/src/behaviour/jbehave/extensions/threaded/swing/DefaultWindowWrapperBehaviour.java
- trunk/extensions/swing/src/java/jbehave/extensions/threaded/swing/DefaultWindowWrapper.java
Diff
Modified: trunk/examples/hellbound/src/behaviour/com/sirenian/hellbound/gui/HellboundFrameBehaviour.java (597 => 598)
--- trunk/examples/hellbound/src/behaviour/com/sirenian/hellbound/gui/HellboundFrameBehaviour.java 2006-11-30 15:28:46 UTC (rev 597) +++ trunk/examples/hellbound/src/behaviour/com/sirenian/hellbound/gui/HellboundFrameBehaviour.java 2006-12-01 10:50:08 UTC (rev 598) @@ -30,35 +30,51 @@ } public void tearDown() { - frame.dispose(); + try { + windowWrapper.closeWindow(); + } catch (TimeoutException e) { + throw new RuntimeException(e); + } } public void shouldDisplayTheFrontPanelWhenTheGameIsReady() { + setUp(); frame.reportGameStateChanged(GameState.READY); ensureThat(frontPanel.isShowing()); ensureThat(!gamePanel.isShowing()); + tearDown(); } public void shouldDisplayGamePanelWhenTheGameIsRunning() { + setUp(); frame.reportGameStateChanged(GameState.RUNNING); ensureThat(!frontPanel.isShowing()); ensureThat(gamePanel.isShowing()); + tearDown(); } public void shouldRequestThatTheShapeIsDroppedWhenTheSpaceKeyIsPressed() throws Exception { + setUp(); ensureThatKeycodeProducesRequest(KeyEvent.VK_SPACE, "requestDropGlyph"); + tearDown(); } public void shouldRequestThatTheShapeIsMovedRightWhenTheRightKeyIsPressed() throws Exception { + setUp(); ensureThatKeycodeProducesRequest(KeyEvent.VK_RIGHT, "requestMoveGlyphRight"); + tearDown(); } public void shouldRequestThatTheShapeIsMovedLeftWhenTheMoveLeftKeyIsPressed() throws Exception { + setUp(); ensureThatKeycodeProducesRequest(KeyEvent.VK_LEFT, "requestMoveGlyphLeft"); + tearDown(); } public void shouldRequestThatTheShapeIsMovedDownWhenTheMoveDownKeyIsPressed() throws Exception { - ensureThatKeycodeProducesRequest(KeyEvent.VK_DOWN, "requestDropGlyph"); + setUp(); + ensureThatKeycodeProducesRequest(KeyEvent.VK_DOWN, "requestMoveGlyphDown"); + tearDown(); } private void ensureThatKeycodeProducesRequest(int keycode, String expectedRequest) throws TimeoutException {
Modified: trunk/examples/hellbound/src/java/com/sirenian/hellbound/gui/ActionFactory.java (597 => 598)
--- trunk/examples/hellbound/src/java/com/sirenian/hellbound/gui/ActionFactory.java 2006-11-30 15:28:46 UTC (rev 597) +++ trunk/examples/hellbound/src/java/com/sirenian/hellbound/gui/ActionFactory.java 2006-12-01 10:50:08 UTC (rev 598) @@ -6,18 +6,21 @@ import javax.swing.Action; import com.sirenian.hellbound.domain.game.GameRequestListener; +import com.sirenian.hellbound.util.Logger; public class ActionFactory { public Action right(final GameRequestListener gameRequestListener) { return new AbstractAction() { public void actionPerformed(ActionEvent e) { + Logger.debug(this, "Adding right action to frame action map"); gameRequestListener.requestMoveGlyphRight(); } }; } public Action left(final GameRequestListener gameRequestListener) { + Logger.debug(this, "Adding left action to frame action map"); return new AbstractAction() { public void actionPerformed(ActionEvent e) { gameRequestListener.requestMoveGlyphLeft(); @@ -28,6 +31,7 @@ public Action down(final GameRequestListener gameRequestListener) { return new AbstractAction() { public void actionPerformed(ActionEvent e) { + Logger.debug(this, "Adding down action to frame action map"); gameRequestListener.requestMoveGlyphDown(); } }; @@ -36,6 +40,7 @@ public Action drop(final GameRequestListener gameRequestListener) { return new AbstractAction() { public void actionPerformed(ActionEvent e) { + Logger.debug(this, "Adding drop action to frame action map"); gameRequestListener.requestDropGlyph(); } };
Modified: trunk/extensions/swing/src/behaviour/jbehave/extensions/threaded/swing/DefaultWindowWrapperBehaviour.java (597 => 598)
--- trunk/extensions/swing/src/behaviour/jbehave/extensions/threaded/swing/DefaultWindowWrapperBehaviour.java 2006-11-30 15:28:46 UTC (rev 597) +++ trunk/extensions/swing/src/behaviour/jbehave/extensions/threaded/swing/DefaultWindowWrapperBehaviour.java 2006-12-01 10:50:08 UTC (rev 598) @@ -5,11 +5,13 @@ import java.awt.event.KeyEvent; import java.awt.event.KeyListener; +import javax.swing.Action; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JTextArea; import javax.swing.JTextField; +import javax.swing.KeyStroke; import javax.swing.text.JTextComponent; import jbehave.core.minimock.UsingMiniMock; @@ -107,9 +109,12 @@ DefaultWindowWrapper wrapper = new DefaultWindowWrapper("a.window"); JFrame frame = new JFrame(); + JPanel panel = new JPanel(); + frame.setContentPane(panel); frame.setName("a.window"); frame.setVisible(true); + Constraint spaceKeyEvent = new Constraint() { public boolean matches(Object arg) { return ((KeyEvent)arg).getKeyCode() == KeyEvent.VK_SPACE; @@ -121,6 +126,12 @@ keyListener.stubs("keyPressed"); keyListener.expects("keyReleased").once().with(spaceKeyEvent); + Mock action = "" + action.expects("actionPerformed"); + + panel.getInputMap().put(KeyStroke.getKeyStroke(' '), "drop"); + panel.getActionMap().put("drop", (Action) action); + frame.addKeyListener((KeyListener) keyListener); wrapper.pressKey(KeyEvent.VK_SPACE);
Modified: trunk/extensions/swing/src/java/jbehave/extensions/threaded/swing/DefaultWindowWrapper.java (597 => 598)
--- trunk/extensions/swing/src/java/jbehave/extensions/threaded/swing/DefaultWindowWrapper.java 2006-11-30 15:28:46 UTC (rev 597) +++ trunk/extensions/swing/src/java/jbehave/extensions/threaded/swing/DefaultWindowWrapper.java 2006-12-01 10:50:08 UTC (rev 598) @@ -4,7 +4,6 @@ import java.awt.AWTException; import java.awt.Component; import java.awt.EventQueue; -import java.awt.Robot; import java.awt.TextComponent; import java.awt.Toolkit; import java.awt.Window; @@ -58,13 +57,11 @@ Component component = findComponent(componentName); component.requestFocus(); - if (component instanceof TextComponent) { typeIntoTextComponent((TextComponent)component, text); } else if (component instanceof JTextComponent) { typeIntoJTextComponent((JTextComponent)component, text); } - idler.waitForIdle(); } @@ -76,29 +73,29 @@ } idler.waitForIdle(); } + + public void typeIntoJTextComponent(JTextComponent textComponent, String text) { + for (int i = 0; i < text.length(); i++) { + sysQueue.postEvent(createKeyPressEvent(textComponent, text.charAt(i), KeyEvent.KEY_PRESSED)); + sysQueue.postEvent(createKeyPressEvent(textComponent, text.charAt(i), KeyEvent.KEY_RELEASED)); + sysQueue.postEvent(createKeyPressEvent(textComponent, text.charAt(i), KeyEvent.KEY_TYPED)); + } + idler.waitForIdle(); + } public void pressKey(int keycode) throws TimeoutException { - try { - Robot robot = new Robot(); - robot.keyPress(keycode); - robot.keyRelease(keycode); - } catch (AWTException e) { - throw new RuntimeException(e); - } +// try { + sysQueue.postEvent(createKeyPressEvent(getWindow().getFocusOwner(), keycode, KeyEvent.KEY_PRESSED)); + sysQueue.postEvent(createKeyPressEvent(getWindow().getFocusOwner(), keycode, KeyEvent.KEY_RELEASED)); +// Robot robot = new Robot(); +// robot.keyPress(keycode); +// robot.keyRelease(keycode); +// } catch (AWTException e) { +// throw new RuntimeException(e); +// } idler.waitForIdle(); } - - - public void typeIntoJTextComponent(JTextComponent textComponent, String text) { - for (int i = 0; i < text.length(); i++) { - sysQueue.postEvent(createKeyPressEvent(textComponent, text.charAt(i), KeyEvent.KEY_PRESSED)); - sysQueue.postEvent(createKeyPressEvent(textComponent, text.charAt(i), KeyEvent.KEY_RELEASED)); - sysQueue.postEvent(createKeyPressEvent(textComponent, text.charAt(i), KeyEvent.KEY_TYPED)); - } - idler.waitForIdle(); - } - public Component findComponent(String componentName) throws ComponentFinderException, TimeoutException { return finder.findExactComponent(getWindow(), new NamedComponentFilter(componentName)); } @@ -131,4 +128,13 @@ KeyEvent.VK_UNDEFINED, c); } + + private AWTEvent createKeyPressEvent(Component component, int keycode, int id) { + return new KeyEvent(component, + id, + System.currentTimeMillis(), + 0, + keycode, + KeyEvent.CHAR_UNDEFINED); + } }
To unsubscribe from this list please visit:
