diff --git a/gdsc-core-ij/src/main/java/uk/ac/sussex/gdsc/core/ij/gui/ExtendedGenericDialog.java b/gdsc-core-ij/src/main/java/uk/ac/sussex/gdsc/core/ij/gui/ExtendedGenericDialog.java index d7d5ddf9..869956f4 100644 --- a/gdsc-core-ij/src/main/java/uk/ac/sussex/gdsc/core/ij/gui/ExtendedGenericDialog.java +++ b/gdsc-core-ij/src/main/java/uk/ac/sussex/gdsc/core/ij/gui/ExtendedGenericDialog.java @@ -1202,6 +1202,24 @@ public TextField addFilenameField(final String label, String defaultText, int co return tf; } + @Override + public void addFileField(String label, String defaultPath) { + // Replace ij.gui.GenericDialog method with this implementation + addFilenameField(label, defaultPath); + } + + @Override + public void addFileField(String label, String defaultPath, int columns) { + // Replace ij.gui.GenericDialog method with this implementation + addFilenameField(label, defaultPath, columns); + } + + @Override + public void addButton(String label, ActionListener listener) { + // Replace ij.gui.GenericDialog method with this implementation + addAndGetButton(label, listener); + } + /** * Adds the directory field. * diff --git a/gdsc-core-ij/src/test/java/uk/ac/sussex/gdsc/core/ij/gui/ExtendedGenericDialogTest.java b/gdsc-core-ij/src/test/java/uk/ac/sussex/gdsc/core/ij/gui/ExtendedGenericDialogTest.java index 56dcbf03..aef80a9e 100644 --- a/gdsc-core-ij/src/test/java/uk/ac/sussex/gdsc/core/ij/gui/ExtendedGenericDialogTest.java +++ b/gdsc-core-ij/src/test/java/uk/ac/sussex/gdsc/core/ij/gui/ExtendedGenericDialogTest.java @@ -28,7 +28,10 @@ package uk.ac.sussex.gdsc.core.ij.gui; +import ij.IJ; +import ij.ImagePlus; import ij.Macro; +import ij.gui.GenericDialog; import java.awt.Color; import java.time.Duration; import org.junit.jupiter.api.Assertions; @@ -39,6 +42,10 @@ @SuppressWarnings({"javadoc"}) class ExtendedGenericDialogTest { + enum TestEnum { + A, B, C, D + } + @Test @DisabledIfHeadless void checkNotifyOptionCollectedListeners() { @@ -127,4 +134,50 @@ void checkAddHexField() { Assertions.assertArrayEquals(b2, gd.getNextHexBytes()); }); } + + /** + * Check {@link GenericDialog#addImageChoice(String, String)} is supported without any overrides. + */ + @Test + @DisabledIfHeadless + void checkAddImageChoice() { + Assertions.assertTimeoutPreemptively(Duration.ofMillis(1000), () -> { + // Run without showing the dialog. + // This requires manipulation of the thread name and setting of macro options. + Thread.currentThread().setName("Run$_ test"); + Macro.setOptions("something"); + + final ExtendedGenericDialog gd = new ExtendedGenericDialog("Test"); + String name1 = "test1"; + ImagePlus imp1 = IJ.createImage(name1, 3, 4, 1, 8); + imp1.show(); + gd.addImageChoice("image1", name1); + gd.showDialog(); + Assertions.assertEquals(imp1, gd.getNextImage()); + imp1.close(); + }); + } + + /** + * Check {@link GenericDialog#addEnumChoice(String, Enum)} is supported without any overrides. + */ + @Test + @DisabledIfHeadless + void checkAddEnumChoice() { + Assertions.assertTimeoutPreemptively(Duration.ofMillis(1000), () -> { + // Run without showing the dialog. + // This requires manipulation of the thread name and setting of macro options. + Thread.currentThread().setName("Run$_ test"); + Macro.setOptions("something"); + + final ExtendedGenericDialog gd = new ExtendedGenericDialog("Test"); + TestEnum ll1 = TestEnum.B; + TestEnum ll2 = TestEnum.C; + gd.addEnumChoice("enum1", ll1); + gd.addEnumChoice("enum2", new TestEnum[] {TestEnum.A, ll2}, ll2); + gd.showDialog(); + Assertions.assertEquals(ll1, gd.getNextEnumChoice(TestEnum.class)); + Assertions.assertEquals(ll2, gd.getNextEnumChoice(ll2.getDeclaringClass())); + }); + } }