diff --git a/pom.xml b/pom.xml index 08b176db5..9ce3cc4f6 100644 --- a/pom.xml +++ b/pom.xml @@ -9,7 +9,7 @@ org.embl.mobie mobie-viewer-fiji - 5.3.7 + 5.3.8 diff --git a/src/main/java/org/embl/mobie/lib/table/TableView.java b/src/main/java/org/embl/mobie/lib/table/TableView.java index 89cb4fc96..3d07a274a 100644 --- a/src/main/java/org/embl/mobie/lib/table/TableView.java +++ b/src/main/java/org/embl/mobie/lib/table/TableView.java @@ -50,6 +50,7 @@ import org.embl.mobie.lib.select.SelectionModel; import org.embl.mobie.ui.ColumnColoringModelDialog; import net.imglib2.type.numeric.ARGBType; +import org.embl.mobie.ui.StringArraySelectorDialog; import org.embl.mobie.ui.UserInterfaceHelper; import javax.swing.*; @@ -371,12 +372,13 @@ private JMenuItem createColumnSearchMenuItem() menuItem.addActionListener( e -> SwingUtilities.invokeLater( () -> { - final String[] columnNames = Tables.getColumnNamesAsArray( jTable ); - final GenericDialog gd = new GenericDialog( "Focus Column" ); - gd.addChoice( "Column", columnNames, columnNames[ 0 ] ); - gd.showDialog(); - if ( gd.wasCanceled() ) return; - final String columnName = gd.getNextChoice(); + StringArraySelectorDialog dialog = + new StringArraySelectorDialog( + "Column Selector", + Tables.getColumnNamesAsArray( jTable ) + ); + if ( ! dialog.show() ) return; + final String columnName = dialog.getSelectedItem(); int columnIndex = jTable.getColumnModel().getColumnIndex( columnName ); JViewport viewport = (JViewport) jTable.getParent(); Rectangle rect = jTable.getCellRect(0, columnIndex, true); diff --git a/src/main/java/org/embl/mobie/ui/StringArraySelectorDialog.java b/src/main/java/org/embl/mobie/ui/StringArraySelectorDialog.java new file mode 100644 index 000000000..6bb5b238d --- /dev/null +++ b/src/main/java/org/embl/mobie/ui/StringArraySelectorDialog.java @@ -0,0 +1,89 @@ +package org.embl.mobie.ui; + +import org.embl.mobie.MoBIE; +import org.embl.mobie.lib.io.FileLocation; +import org.embl.mobie.lib.serialize.View; +import org.jetbrains.annotations.NotNull; + +import javax.swing.*; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; +import java.io.File; +import java.util.Arrays; + +import static org.embl.mobie.lib.view.save.ViewSaver.CREATE_SELECTION_GROUP; + +public class StringArraySelectorDialog +{ + private final String title; + private final String[] array; + + private JComboBox< String > arrayComboBox; + + private boolean isOkPressed; + + private JDialog dialog; + + public StringArraySelectorDialog( String title, String[] array ) + { + this.title = title; + this.array = array; + } + + public boolean show() + { + dialog = new JDialog( ( Frame ) null, title, true ); + dialog.setLayout( new BoxLayout( dialog.getContentPane(), BoxLayout.Y_AXIS ) ); + + // Array item selection + // + JPanel selectionPanel = SwingHelper.horizontalLayoutPanel(); + arrayComboBox = new JComboBox<>( array ); + Dimension maximumSize = new Dimension( 300, 20 ); + arrayComboBox.setMaximumSize( maximumSize ); + selectionPanel.add( new JLabel("Select item: ") ); + selectionPanel.add( arrayComboBox ); + + dialog.add( selectionPanel ); + + // OK and Cancel button + // + JPanel buttonPanel = new JPanel(); + JButton okButton = new JButton( "OK" ); + JButton cancelButton = new JButton( "Cancel" ); + buttonPanel.add( okButton ); + buttonPanel.add( cancelButton ); + dialog.add( buttonPanel ); + + okButton.addActionListener( e -> + { + isOkPressed = true; + dialog.setVisible( false ); + } ); + + cancelButton.addActionListener( e -> + { + isOkPressed = false; + dialog.setVisible( false ); + } ); + + dialog.setPreferredSize( new Dimension( 250, 120 ) ); + dialog.setLocation( + Toolkit.getDefaultToolkit().getScreenSize().width / 2 - 200, + Toolkit.getDefaultToolkit().getScreenSize().height / 2 - 200 + ); + dialog.pack(); + dialog.setVisible( true ); + + return isOkPressed; + } + + public String getSelectedItem() + { + return (String) arrayComboBox.getSelectedItem(); + } +} + diff --git a/src/main/java/org/embl/mobie/ui/UserInterfaceHelper.java b/src/main/java/org/embl/mobie/ui/UserInterfaceHelper.java index 5c3c08293..6199dca2f 100644 --- a/src/main/java/org/embl/mobie/ui/UserInterfaceHelper.java +++ b/src/main/java/org/embl/mobie/ui/UserInterfaceHelper.java @@ -1237,7 +1237,7 @@ public static JButton createFocusButton( AbstractDisplay< ? > sourceDisplay, BdvHandle bdvHandle, List< Source< ? > > sources ) { - JButton button = getIconButton( "focus.png" ); + JButton button = getIconButton( "focus.png" ); button.setToolTipText( "Fit image to viewer" ); button.addActionListener( e -> diff --git a/src/main/resources/focus.png b/src/main/resources/focus.png index 73c299597..06f48524d 100644 Binary files a/src/main/resources/focus.png and b/src/main/resources/focus.png differ diff --git a/src/test/java/org/embl/mobie/command/open/OpenIlastik2DImageAndSegmentationCommandTest.java b/src/test/java/org/embl/mobie/command/open/Open2DTIFFImageAndIlastikSegmentationCommandTest.java similarity index 96% rename from src/test/java/org/embl/mobie/command/open/OpenIlastik2DImageAndSegmentationCommandTest.java rename to src/test/java/org/embl/mobie/command/open/Open2DTIFFImageAndIlastikSegmentationCommandTest.java index 4d7722d08..9a6058f4e 100644 --- a/src/test/java/org/embl/mobie/command/open/OpenIlastik2DImageAndSegmentationCommandTest.java +++ b/src/test/java/org/embl/mobie/command/open/Open2DTIFFImageAndIlastikSegmentationCommandTest.java @@ -32,7 +32,7 @@ import java.io.File; -public class OpenIlastik2DImageAndSegmentationCommandTest +public class Open2DTIFFImageAndIlastikSegmentationCommandTest { static { net.imagej.patcher.LegacyInjector.preinit(); } diff --git a/src/test/java/org/embl/mobie/command/open/OpenIlastik2ChannelImageCommandTest.java b/src/test/java/org/embl/mobie/command/open/OpenIlastik2ChannelImageCommandTest.java new file mode 100644 index 000000000..9559fc582 --- /dev/null +++ b/src/test/java/org/embl/mobie/command/open/OpenIlastik2ChannelImageCommandTest.java @@ -0,0 +1,49 @@ +/*- + * #%L + * Fiji viewer for MoBIE projects + * %% + * Copyright (C) 2018 - 2024 EMBL + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ +package org.embl.mobie.command.open; + +import net.imagej.ImageJ; +import org.junit.jupiter.api.Test; + +import java.io.File; + +public class OpenIlastik2ChannelImageCommandTest +{ + static { net.imagej.patcher.LegacyInjector.preinit(); } + + @Test + public void test( ) + { + new ImageJ().ui().showUI(); // initialise SciJava Services + + final OpenImageAndLabelsCommand command = new OpenImageAndLabelsCommand(); + command.image = new File( "src/test/resources/ilastik-2d/probabilities-2channels.h5" ); + command.run(); + } +} diff --git a/src/test/java/org/embl/mobie/command/open/OpenIlastik2ChannelImagesCommandTest.java b/src/test/java/org/embl/mobie/command/open/OpenIlastik2ChannelImagesCommandTest.java new file mode 100644 index 000000000..26c074c78 --- /dev/null +++ b/src/test/java/org/embl/mobie/command/open/OpenIlastik2ChannelImagesCommandTest.java @@ -0,0 +1,51 @@ +/*- + * #%L + * Fiji viewer for MoBIE projects + * %% + * Copyright (C) 2018 - 2024 EMBL + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ +package org.embl.mobie.command.open; + +import net.imagej.ImageJ; +import org.embl.mobie.lib.transform.GridType; +import org.junit.jupiter.api.Test; + +import java.io.File; + +public class OpenIlastik2ChannelImagesCommandTest +{ + static { net.imagej.patcher.LegacyInjector.preinit(); } + + @Test + public void test( ) + { + new ImageJ().ui().showUI(); // initialise SciJava Services + + final OpenMultipleImagesAndLabelsCommand command = new OpenMultipleImagesAndLabelsCommand(); + command.image0 = new File( "src/test/resources/ilastik-2d/probabilities-2channels.h5;0" ); + command.image1 = new File( "src/test/resources/ilastik-2d/probabilities-2channels.h5;1" ); + command.run(); + } +} diff --git a/src/test/java/org/embl/mobie/command/open/OpenIlastikImageAndSegmentationCommandTest.java b/src/test/java/org/embl/mobie/command/open/OpenIlastikImageAndSegmentationCommandTest.java new file mode 100644 index 000000000..b8f4e6eb7 --- /dev/null +++ b/src/test/java/org/embl/mobie/command/open/OpenIlastikImageAndSegmentationCommandTest.java @@ -0,0 +1,51 @@ +/*- + * #%L + * Fiji viewer for MoBIE projects + * %% + * Copyright (C) 2018 - 2024 EMBL + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ +package org.embl.mobie.command.open; + +import net.imagej.ImageJ; +import org.junit.jupiter.api.Test; + +import java.io.File; + +public class OpenIlastikImageAndSegmentationCommandTest +{ + static { net.imagej.patcher.LegacyInjector.preinit(); } + + @Test + public void test( ) + { + new ImageJ().ui().showUI(); // initialise SciJava Services + + final OpenImageAndLabelsCommand command = new OpenImageAndLabelsCommand(); + command.image = new File( "src/test/resources/ilastik-2d/probabilities.h5" ); + command.labels = new File( "src/test/resources/ilastik-2d/labels.h5" ); + command.table = new File( "src/test/resources/ilastik-2d/table.csv" ); + command.run(); + } +} diff --git a/src/test/resources/ilastik-2d/probabilities-2channels.h5 b/src/test/resources/ilastik-2d/probabilities-2channels.h5 new file mode 100644 index 000000000..e08132139 Binary files /dev/null and b/src/test/resources/ilastik-2d/probabilities-2channels.h5 differ diff --git a/src/test/resources/ilastik-2d/probabilities.h5 b/src/test/resources/ilastik-2d/probabilities.h5 new file mode 100644 index 000000000..000936a59 Binary files /dev/null and b/src/test/resources/ilastik-2d/probabilities.h5 differ