This commit is contained in:
hneemann 2018-06-18 13:06:18 +02:00
parent 9c078062a6
commit addc9c26e3
2 changed files with 85 additions and 7 deletions

View File

@ -43,7 +43,7 @@ public class ClosingWindowListener extends WindowAdapter {
* @param confirmSave the ConfirmSave interface
* @param doExit if true the parent JFrame is disposed by this listener
*/
public ClosingWindowListener(final JFrame parent, final ConfirmSave confirmSave, final boolean doExit) {
private ClosingWindowListener(final JFrame parent, final ConfirmSave confirmSave, final boolean doExit) {
this((Component) parent, new GUICloser() {
@Override
public void closeGUI() {
@ -80,14 +80,14 @@ public class ClosingWindowListener extends WindowAdapter {
.setCancleOption(CANCEL_MESSAGE)
.show(parent);
if (r != JOptionPane.CANCEL_OPTION) {
if (r == JOptionPane.YES_OPTION || r == JOptionPane.NO_OPTION) {
if (r == JOptionPane.YES_OPTION) {
confirmSave.saveChanges();
}
return true;
} else {
return !confirmSave.isStateChanged();
} else
return true;
} else
return false;
}
}
return true;
}
@ -98,7 +98,7 @@ public class ClosingWindowListener extends WindowAdapter {
* @param parent the parent component of the confirm dialog
* @param guiCloser the guiCloser
*/
public ClosingWindowListener(Component parent, GUICloser guiCloser) {
private ClosingWindowListener(Component parent, GUICloser guiCloser) {
this.parent = parent;
this.guiCloser = guiCloser;
}

View File

@ -543,6 +543,84 @@ public class TestInGUI extends TestCase {
.execute();
}
public void testSaveDialog() {
new GuiTester()
.press("F10")
.press("RIGHT", 5)
.press("DOWN", "RIGHT", "ENTER")
.mouseMove(100, 150)
.mouseClick(InputEvent.BUTTON1_MASK)
.delay(100)
// aboard with escape
.press("control typed n")
.delay(100)
.add(new GuiTester.WindowCheck<>(JDialog.class,
(guiTester, window) -> assertEquals(Lang.get("win_stateChanged"), window.getTitle())))
.press("ESCAPE")
.add(new GuiTester.WindowCheck<>(Main.class,
(gt, main) -> assertEquals(1, main.getCircuitComponent().getCircuit().getElements().size())))
// press edit further
.press("control typed n")
.delay(100)
.add(new GuiTester.SetFocusTo<>(JDialog.class,
c -> c instanceof JButton && ((JButton)c).getText().equals(Lang.get("btn_editFurther"))))
.press("SPACE")
.delay(100)
.add(new GuiTester.WindowCheck<>(Main.class,
(gt, main) -> assertEquals(1, main.getCircuitComponent().getCircuit().getElements().size())))
// press save and the escape the save dialog (JFileChooser)
.press("control typed n")
.delay(100)
.add(new GuiTester.SetFocusTo<>(JDialog.class,
c -> c instanceof JButton && ((JButton)c).getText().equals(Lang.get("btn_save"))))
.press("SPACE")
.delay(100)
.add(new GuiTester.WindowCheck<>(JDialog.class))
.press("ESCAPE")
.add(new GuiTester.WindowCheck<>(Main.class,
(gt, main) -> assertEquals(1, main.getCircuitComponent().getCircuit().getElements().size())))
// press save and save the file
.press("control typed n")
.delay(100)
.add(new GuiTester.SetFocusTo<>(JDialog.class,
c -> c instanceof JButton && ((JButton)c).getText().equals(Lang.get("btn_save"))))
.press("SPACE")
.delay(100)
.add(new GuiTester.WindowCheck<>(JDialog.class))
.typeTempFile("save.dig")
.press("ENTER")
.delay(100)
.add(new GuiTester.WindowCheck<>(Main.class,
(gt, main) -> assertEquals(0, main.getCircuitComponent().getCircuit().getElements().size())))
.execute();
}
public void testSaveDialog2() {
new GuiTester()
.press("F10")
.press("RIGHT", 5)
.press("DOWN", "RIGHT", "ENTER")
.mouseMove(100, 150)
.mouseClick(InputEvent.BUTTON1_MASK)
.delay(100)
// discard changes
.press("control typed n")
.delay(100)
.add(new GuiTester.SetFocusTo<>(JDialog.class,
c -> c instanceof JButton && ((JButton)c).getText().equals(Lang.get("btn_discard"))))
.press("SPACE")
.delay(100)
.add(new GuiTester.WindowCheck<>(Main.class,
(gt, main) -> assertEquals(0, main.getCircuitComponent().getCircuit().getElements().size())))
.execute();
}
public void test74xxFunctions() {
new GuiTester("dig/manualError/10_74xx.dig")