예제 #1
0
  public void test_undoRedoSnapshotMode() throws Exception {
    DetailDataSource dataSource = new DetailDataSource(new MadGuiContext());

    final JCheckBox checkBox = new JCheckBox();
    final JTextField textField = new JTextField();
    final NoNullDateField dateField = new NoNullDateField();
    dateFieldWrapper = new Panel(dateField);
    textFieldWrapper = new TextBox(textField);
    checkBoxWrapper = new CheckBox(checkBox);

    dataSource.declare("checkbox", checkBox);
    dataSource.declare("textfield", textField);
    dataSource.declare("date", dateField);

    buttonPanelLogic.setMainDataSource(dataSource);

    checkBox.addItemListener(
        new ItemListener() {
          public void itemStateChanged(ItemEvent event) {
            if (checkBox.isSelected()) {
              buttonPanelLogic.startSnapshotMode();
              textField.setText("OK");
              dateField.setDate(java.sql.Date.valueOf("2007-08-24"));
              buttonPanelLogic.stopSnapshotMode();
            }
          }
        });

    assertGuiComponents(false, "", "");

    checkBoxWrapper.click();
    Thread.sleep(200);
    assertGuiComponents(true, "OK", "24-08-2007");

    textFieldWrapper.pressKey(Key.N);
    assertGuiComponents(true, "NOK", "24-08-2007");

    dateField.setDate(java.sql.Date.valueOf("2007-08-30"));
    assertGuiComponents(true, "NOK", "30-08-2007");

    undo();
    assertGuiComponents(true, "NOK", "24-08-2007");

    undo();
    assertGuiComponents(true, "OK", "24-08-2007");

    undo();
    assertGuiComponents(false, "", "");

    redo();
    assertGuiComponents(true, "OK", "24-08-2007");

    redo();
    assertGuiComponents(true, "NOK", "24-08-2007");

    redo();
    assertGuiComponents(true, "NOK", "30-08-2007");
  }
예제 #2
0
 private void assertGuiComponents(
     boolean expectedCheckBox, String expectedText, String expectedDate) {
   assertEquals(expectedCheckBox, checkBoxWrapper.isSelected());
   assertTrue(textFieldWrapper.textEquals(expectedText));
   assertDateField(expectedDate);
 }