diff --git a/src/main/java/org/embl/mobie/command/context/ConfigureImageRenderingCommand.java b/src/main/java/org/embl/mobie/command/context/ConfigureImageRenderingCommand.java index 02640c72..b9b7526d 100644 --- a/src/main/java/org/embl/mobie/command/context/ConfigureImageRenderingCommand.java +++ b/src/main/java/org/embl/mobie/command/context/ConfigureImageRenderingCommand.java @@ -31,11 +31,9 @@ import bdv.util.BdvHandle; import bdv.viewer.SourceAndConverter; import org.embl.mobie.command.CommandConstants; -import org.embl.mobie.lib.bdv.blend.BlendingMode; import org.embl.mobie.lib.volume.ImageVolumeViewer; import org.scijava.Initializable; import org.scijava.command.DynamicCommand; -import org.scijava.module.MutableModuleItem; import org.scijava.plugin.Parameter; import org.scijava.plugin.Plugin; import sc.fiji.bdvpg.scijava.command.BdvPlaygroundActionCommand; @@ -50,10 +48,8 @@ public class ConfigureImageRenderingCommand extends DynamicCommand implements Bd { static { net.imagej.patcher.LegacyInjector.preinit(); } - protected static ISourceAndConverterService sourceAndConverterService = SourceAndConverterServices.getSourceAndConverterService(); - @Parameter - protected BdvHandle bdvh; + protected BdvHandle bdvHandle; @Parameter protected SourceAndConverter< ? >[] sourceAndConverters; @@ -61,9 +57,6 @@ public class ConfigureImageRenderingCommand extends DynamicCommand implements Bd @Parameter protected ImageVolumeViewer volumeViewer; - @Parameter( label = "Blending mode", choices = { BlendingMode.SUM, BlendingMode.ALPHA }, persist = false ) - String blendingMode = BlendingMode.SUM; - @Parameter ( label = "Volume rendering", choices = { AUTO, USE_BELOW_RESOLUTION } ) public String volumeRenderingMode = AUTO; @@ -73,40 +66,15 @@ public class ConfigureImageRenderingCommand extends DynamicCommand implements Bd @Override public void initialize() { - initBlendingModeItem(); - } - - private void initBlendingModeItem() - { - final MutableModuleItem< String > blendingModeItem = getInfo().getMutableInput("blendingMode", String.class ); - for ( SourceAndConverter sourceAndConverter : sourceAndConverters ) - { - final BlendingMode blendingMode = ( BlendingMode ) sourceAndConverterService.getMetadata( sourceAndConverter, BlendingMode.class.getName() ); - final String toString = blendingMode.toString(); - blendingModeItem.setValue( this, toString ); - return; - } } @Override public void run() { - updateBlendingMode(); - updateVolumeRendering(); } - private void updateBlendingMode() - { - for ( SourceAndConverter< ? > sourceAndConverter : sourceAndConverters ) - { - final BlendingMode blendingMode = BlendingMode.valueOf( this.blendingMode ); - SourceAndConverterServices.getSourceAndConverterService().setMetadata( sourceAndConverter, BlendingMode.class.getName(), blendingMode ); - } - bdvh.getViewerPanel().requestRepaint(); - } - private void updateVolumeRendering() { if ( volumeViewer == null ) return; diff --git a/src/main/java/org/embl/mobie/lib/bdv/ScreenShotMaker.java b/src/main/java/org/embl/mobie/lib/bdv/ScreenShotMaker.java index 90acfccf..5ce753fc 100644 --- a/src/main/java/org/embl/mobie/lib/bdv/ScreenShotMaker.java +++ b/src/main/java/org/embl/mobie/lib/bdv/ScreenShotMaker.java @@ -153,7 +153,7 @@ public void run( List< SourceAndConverter< ? > > sacs, double targetVoxelSpacing screenshotDimensions, blockSize ); - IJ.log( ThreadHelper.getNumIoThreads() + " threads working on blocks of " + Arrays.toString( blockSize ) ); + // IJ.log( ThreadHelper.getNumIoThreads() + " threads working on blocks of " + Arrays.toString( blockSize ) ); final long currentTimeMillis = System.currentTimeMillis(); for ( SourceAndConverter< ? > sac : sacs ) { diff --git a/src/main/java/org/embl/mobie/ui/UserInterfaceHelper.java b/src/main/java/org/embl/mobie/ui/UserInterfaceHelper.java index 59331a1c..d273c370 100644 --- a/src/main/java/org/embl/mobie/ui/UserInterfaceHelper.java +++ b/src/main/java/org/embl/mobie/ui/UserInterfaceHelper.java @@ -45,6 +45,7 @@ import org.embl.mobie.io.util.IOHelper; import org.embl.mobie.MoBIE; import org.embl.mobie.lib.bdv.AutoContrastAdjuster; +import org.embl.mobie.lib.bdv.blend.BlendingMode; import org.embl.mobie.lib.io.FileLocation; import org.embl.mobie.lib.MoBIEInfo; import org.embl.mobie.lib.Services; @@ -71,6 +72,8 @@ import org.embl.mobie.lib.transform.viewer.ViewerTransform; import org.embl.mobie.lib.volume.ImageVolumeViewer; import org.embl.mobie.lib.volume.SegmentVolumeViewer; +import org.jetbrains.annotations.NotNull; +import org.scijava.plugin.Parameter; import sc.fiji.bdvpg.services.ISourceAndConverterService; import sc.fiji.bdvpg.services.SourceAndConverterServices; import sc.fiji.bdvpg.sourceandconverter.display.ColorChanger; @@ -458,37 +461,13 @@ public static JFrame showOpacityAndContrastLimitsDialog( BdvHandle bdvHandle, boolean addContrastLimitUI ) { + ISourceAndConverterService service = SourceAndConverterServices.getSourceAndConverterService(); + JFrame frame = new JFrame( name ); frame.setDefaultCloseOperation( JFrame.DISPOSE_ON_CLOSE ); JPanel panel = new JPanel(); panel.setLayout( new BoxLayout( panel, BoxLayout.PAGE_AXIS ) ); - ISourceAndConverterService service = SourceAndConverterServices.getSourceAndConverterService(); - - // Opacity Slider - // - // TODO: This cast requires that the sourceAndConverter implements - // an OpacityAdjuster; how to do this more cleanly? - // Maybe we should rather operate on the coloring model that is - // wrapped in the converter? - final double current = ( ( OpacityAdjuster ) sacs.get( 0 ).getConverter()).getOpacity(); - - final BoundedValueDouble selection = - new BoundedValueDouble( - 0.0, - 1.0, - current ); - - final SliderPanelDouble opacitySlider = new SliderPanelDouble( "Opacity", selection, 0.05 ); - opacitySlider.setNumColummns( 3 ); - opacitySlider.setDecimalFormat( "#.##" ); - - final OpacityUpdateListener opacityUpdateListener = - new OpacityUpdateListener( selection, opacitySlider, sacs, bdvHandle ); - - selection.setUpdateListener( opacityUpdateListener ); - panel.add( opacitySlider ); - if ( addContrastLimitUI ) { // Contrast Limits @@ -547,6 +526,7 @@ public static JFrame showOpacityAndContrastLimitsDialog( panel.add( minSlider ); panel.add( maxSlider ); + JButton autoButton = new JButton("Auto Contrast"); autoButton.addActionListener( e -> { @@ -555,7 +535,9 @@ public static JFrame showOpacityAndContrastLimitsDialog( min.setCurrentValue( minMax[ 0 ] ); max.setCurrentValue( minMax[ 1 ] ); }); - panel.add( autoButton ); + JPanel autoPanel = SwingHelper.horizontalLayoutPanel(); + autoPanel.add( autoButton ); + panel.add( autoPanel ); boolean isInvert = false; for ( Converter< ?, ARGBType > converter : converters ) @@ -580,9 +562,56 @@ public static JFrame showOpacityAndContrastLimitsDialog( } bdvHandle.getViewerPanel().requestRepaint(); } ); - panel.add( invertCheckBox ); + JPanel invertPanel = SwingHelper.horizontalLayoutPanel(); + invertPanel.add( invertCheckBox ); + panel.add( invertPanel ); + panel.add( new JLabel("") ); // create some Luft } + // Blending mode + JPanel blendingPanel = SwingHelper.horizontalLayoutPanel(); + blendingPanel.add( new JLabel("Blending ") ); + JComboBox< BlendingMode > blendingModeComboBox = new JComboBox<>( + new BlendingMode[]{ BlendingMode.Sum, BlendingMode.Alpha } ); + BlendingMode currentBlendingMode = ( BlendingMode ) service.getMetadata( sacs.get( 0 ), BlendingMode.class.getName() ); + blendingModeComboBox.setSelectedItem( currentBlendingMode ); + blendingModeComboBox.addActionListener( e -> + { + for ( SourceAndConverter< ? > sourceAndConverter : sacs ) + { + service.setMetadata( sourceAndConverter, + BlendingMode.class.getName(), + blendingModeComboBox.getSelectedItem() ); + } + bdvHandle.getViewerPanel().requestRepaint(); + } ); + blendingPanel.add( blendingModeComboBox ); + panel.add( blendingPanel ); + + // Opacity Slider + // + // TODO: This cast requires that the sourceAndConverter implements + // an OpacityAdjuster; how to do this more cleanly? + // Maybe we should rather operate on the coloring model that is + // wrapped in the converter? + final double current = ( ( OpacityAdjuster ) sacs.get( 0 ).getConverter()).getOpacity(); + + final BoundedValueDouble selection = + new BoundedValueDouble( + 0.0, + 1.0, + current ); + + final SliderPanelDouble opacitySlider = new SliderPanelDouble( "Opacity", selection, 0.05 ); + opacitySlider.setNumColummns( 3 ); + opacitySlider.setDecimalFormat( "#.##" ); + + final OpacityUpdateListener opacityUpdateListener = + new OpacityUpdateListener( selection, opacitySlider, sacs, bdvHandle ); + + selection.setUpdateListener( opacityUpdateListener ); + panel.add( opacitySlider ); + //Display the window. frame.setContentPane( panel ); frame.setBounds( MouseInfo.getPointerInfo().getLocation().x, @@ -604,7 +633,7 @@ public JPanel createRegionDisplaySettingsPanel( RegionDisplay display ) // Buttons panel.add( space() ); panel.add( createFocusButton( display, display.sliceViewer.getBdvHandle(), sourceAndConverters.stream().map( sac -> sac.getSpimSource() ).collect( Collectors.toList() ) ) ); - panel.add( createOpacityAndContrastLimitsButton( sourceAndConverters, display.getName(), display.sliceViewer.getBdvHandle(), false ) ); + panel.add( createContrastButton( sourceAndConverters, display.getName(), display.sliceViewer.getBdvHandle(), false ) ); panel.add( createButtonPlaceholder() ); // color panel.add( createLabelRenderingSettingsButton( sourceAndConverters ) ); // special settings panel.add( createRemoveButton( display ) ); @@ -625,7 +654,7 @@ public JPanel createSpotDisplaySettingsPanel( SpotDisplay display ) // Buttons panel.add( space() ); panel.add( createFocusButton( display, display.sliceViewer.getBdvHandle(), sourceAndConverters.stream().map( sac -> sac.getSpimSource() ).collect( Collectors.toList() ) ) ); - panel.add( createOpacityAndContrastLimitsButton( sourceAndConverters, display.getName(), display.sliceViewer.getBdvHandle(), false ) ); + panel.add( createContrastButton( sourceAndConverters, display.getName(), display.sliceViewer.getBdvHandle(), false ) ); panel.add( createButtonPlaceholder() ); // color panel.add( createSpotSettingsButton( sourceAndConverters ) ); // special settings panel.add( createRemoveButton( display ) ); @@ -712,7 +741,7 @@ public JPanel createImageDisplaySettingsPanel( ImageDisplay< ? > display ) // Buttons panel.add( space() ); panel.add( createFocusButton( display, display.sliceViewer.getBdvHandle(), sourceAndConverters.stream().map( sac -> sac.getSpimSource() ).collect( Collectors.toList() ) ) ); - panel.add( createOpacityAndContrastLimitsButton( sourceAndConverters, display.getName(), display.sliceViewer.getBdvHandle(), true ) ); + panel.add( createContrastButton( sourceAndConverters, display.getName(), display.sliceViewer.getBdvHandle(), true ) ); panel.add( createColorButton( panel, sourceAndConverters, display.sliceViewer.getBdvHandle() ) ); //panel.add( createImageDisplayBrightnessButton( display ) ); panel.add( createImageRenderingSettingsButton( sourceAndConverters, display.imageVolumeViewer ) ); @@ -758,7 +787,7 @@ public JPanel createSegmentationDisplaySettingsPanel( SegmentationDisplay displa panel.add( space() ); panel.add( createFocusButton( display, display.sliceViewer.getBdvHandle(), sourceAndConverters.stream().map( sac -> sac.getSpimSource() ).collect( Collectors.toList() ) ) ); - panel.add( createOpacityAndContrastLimitsButton( sourceAndConverters, display.getName(), display.sliceViewer.getBdvHandle(), false ) ); + panel.add( createContrastButton( sourceAndConverters, display.getName(), display.sliceViewer.getBdvHandle(), false ) ); panel.add( createButtonPlaceholder() ); panel.add( createSegmentRenderingSettingsButton( sourceAndConverters, display.segmentVolumeViewer ) ); panel.add( createRemoveButton( display ) ); @@ -787,10 +816,7 @@ public JPanel createSegmentationDisplaySettingsPanel( SegmentationDisplay displa private JButton createImageRenderingSettingsButton( List< ? extends SourceAndConverter< ? > > sourceAndConverters, ImageVolumeViewer imageVolumeViewer ) { - final URL resource = UserInterfaceHelper.class.getResource( "/settings_19.png" ); - final ImageIcon imageIcon = new ImageIcon( resource ); - JButton button = new JButton( imageIcon ); - button.setPreferredSize( PREFERRED_BUTTON_SIZE ); + JButton button = getIconButton( "settings.png" ); button.addActionListener( e -> { SwingUtilities.invokeLater( () -> @@ -807,7 +833,7 @@ private JButton createImageRenderingSettingsButton( List< ? extends SourceAndCon private JButton createLabelRenderingSettingsButton( List< SourceAndConverter< ? > > sourceAndConverters ) { - JButton button = new JButton( "S" ); + JButton button = getIconButton( "settings.png" ); button.setPreferredSize( PREFERRED_BUTTON_SIZE ); button.addActionListener( e -> Services.commandService.run( ConfigureLabelRenderingCommand.class, true, "sourceAndConverters", sourceAndConverters.toArray( new SourceAndConverter[ 0 ] ) ) ); return button; @@ -815,7 +841,7 @@ private JButton createLabelRenderingSettingsButton( List< SourceAndConverter< ? private JButton createSegmentRenderingSettingsButton( List< SourceAndConverter< ? > > sourceAndConverters, SegmentVolumeViewer< ? > segmentVolumeViewer ) { - JButton button = new JButton( "S" ); + JButton button = getIconButton( "settings.png" ); button.setPreferredSize( PREFERRED_BUTTON_SIZE ); button.addActionListener( e -> Services.commandService.run( ConfigureSegmentRenderingCommand.class, true, "sourceAndConverters", sourceAndConverters.toArray( new SourceAndConverter[ 0 ] ), "volumeViewer", segmentVolumeViewer ) ); return button; @@ -1225,11 +1251,8 @@ public static JButton createFocusButton( AbstractDisplay< ? > sourceDisplay, BdvHandle bdvHandle, List< Source< ? > > sources ) { - final URL resource = UserInterfaceHelper.class.getResource( "/focus_19.png" ); - final ImageIcon imageIcon = new ImageIcon( resource ); - JButton button = new JButton( imageIcon ); + JButton button = getIconButton( "focus.png" ); button.setToolTipText( "Show whole dataset" ); - button.setPreferredSize( PREFERRED_BUTTON_SIZE ); button.addActionListener( e -> { @@ -1254,9 +1277,8 @@ public static JButton createFocusButton( AbstractDisplay< ? > sourceDisplay, public static JButton createImageDisplayBrightnessButton( ImageDisplay< ? > imageDisplay ) { - JButton button = new JButton( "B" ); + JButton button = getIconButton( "contrast.png" ); button.setToolTipText( "Change brightness/contrast" ); - button.setPreferredSize( PREFERRED_BUTTON_SIZE ); button.addActionListener( e -> { @@ -1270,17 +1292,14 @@ public static JButton createImageDisplayBrightnessButton( ImageDisplay< ? > imag return button; } - public static JButton createOpacityAndContrastLimitsButton( + public static JButton createContrastButton( List< ? extends SourceAndConverter< ? > > sourceAndConverters, String name, BdvHandle bdvHandle, boolean addContrastLimitUI ) { - final URL resource = UserInterfaceHelper.class.getResource( "/contrast_19.png" ); - final ImageIcon imageIcon = new ImageIcon( resource ); - JButton button = new JButton( imageIcon ); + JButton button = getIconButton( "contrast.png" ); button.setToolTipText( "Change opacity and contrast limits" ); - button.setPreferredSize( PREFERRED_BUTTON_SIZE ); button.addActionListener( e -> { @@ -1296,16 +1315,23 @@ public static JButton createOpacityAndContrastLimitsButton( return button; } - private static JButton createColorButton( JPanel parentPanel, List< ? extends SourceAndConverter< ? > > sourceAndConverters, BdvHandle bdvHandle ) + @NotNull + private static JButton getIconButton( final String iconResource ) { - final URL resource = UserInterfaceHelper.class.getResource( "/color_19.png" ); - final ImageIcon imageIcon = new ImageIcon( resource ); - JButton colorButton = new JButton( imageIcon ); - colorButton.setToolTipText( "Change color" ); + final URL resource = UserInterfaceHelper.class.getResource( "/" + iconResource ); + Image scaledInstance = new ImageIcon( resource ).getImage().getScaledInstance( 19, 19, Image.SCALE_SMOOTH ); + ImageIcon imageIcon = new ImageIcon( scaledInstance ); + JButton button = new JButton( imageIcon ); + button.setPreferredSize( PREFERRED_BUTTON_SIZE); + return button; + } - colorButton.setPreferredSize( PREFERRED_BUTTON_SIZE); + private static JButton createColorButton( JPanel parentPanel, List< ? extends SourceAndConverter< ? > > sourceAndConverters, BdvHandle bdvHandle ) + { + JButton button = getIconButton( "color.png" ); + button.setToolTipText( "Change color" ); - colorButton.addActionListener( e -> + button.addActionListener( e -> { Color color = JColorChooser.showDialog( null, "", null ); if ( color == null ) return; @@ -1320,7 +1346,7 @@ private static JButton createColorButton( JPanel parentPanel, List< ? extends So bdvHandle.getViewerPanel().requestRepaint(); } ); - return colorButton; + return button; } private void setPanelColor( JPanel panel, ARGBType argbType ) @@ -1345,11 +1371,8 @@ private void setPanelColor( JPanel panel, String colorString ) private JButton createRemoveButton( Display display ) { - final URL resource = UserInterfaceHelper.class.getResource( "/delete_19.png" ); - final ImageIcon imageIcon = new ImageIcon( resource ); - JButton button = new JButton( imageIcon ); + JButton button = getIconButton( "delete.png" ); button.setToolTipText( "Remove dataset" ); - button.setPreferredSize( PREFERRED_BUTTON_SIZE ); button.addActionListener( e -> { diff --git a/src/main/resources/color.png b/src/main/resources/color.png new file mode 100644 index 00000000..9d6e42b7 Binary files /dev/null and b/src/main/resources/color.png differ diff --git a/src/main/resources/color_19.png b/src/main/resources/color_19.png deleted file mode 100644 index 16256188..00000000 Binary files a/src/main/resources/color_19.png and /dev/null differ diff --git a/src/main/resources/contrast.png b/src/main/resources/contrast.png new file mode 100644 index 00000000..367ca9bc Binary files /dev/null and b/src/main/resources/contrast.png differ diff --git a/src/main/resources/contrast_19.png b/src/main/resources/contrast_19.png deleted file mode 100644 index 19ea91ab..00000000 Binary files a/src/main/resources/contrast_19.png and /dev/null differ diff --git a/src/main/resources/contrast_20.png b/src/main/resources/contrast_20.png deleted file mode 100644 index 358b2826..00000000 Binary files a/src/main/resources/contrast_20.png and /dev/null differ diff --git a/src/main/resources/contrast_24.png b/src/main/resources/contrast_24.png deleted file mode 100644 index 42c687cd..00000000 Binary files a/src/main/resources/contrast_24.png and /dev/null differ diff --git a/src/main/resources/contrast_30.png b/src/main/resources/contrast_30.png deleted file mode 100644 index e8f40a9d..00000000 Binary files a/src/main/resources/contrast_30.png and /dev/null differ diff --git a/src/main/resources/delete.png b/src/main/resources/delete.png new file mode 100644 index 00000000..c73497d3 Binary files /dev/null and b/src/main/resources/delete.png differ diff --git a/src/main/resources/delete_19.png b/src/main/resources/delete_19.png deleted file mode 100644 index 03c82747..00000000 Binary files a/src/main/resources/delete_19.png and /dev/null differ diff --git a/src/main/resources/focus.png b/src/main/resources/focus.png new file mode 100644 index 00000000..73c29959 Binary files /dev/null and b/src/main/resources/focus.png differ diff --git a/src/main/resources/focus_19.png b/src/main/resources/focus_19.png deleted file mode 100644 index 78eaa011..00000000 Binary files a/src/main/resources/focus_19.png and /dev/null differ diff --git a/src/main/resources/settings.png b/src/main/resources/settings.png new file mode 100644 index 00000000..d0bbaa5f Binary files /dev/null and b/src/main/resources/settings.png differ diff --git a/src/main/resources/settings_19.png b/src/main/resources/settings_19.png deleted file mode 100644 index 95580882..00000000 Binary files a/src/main/resources/settings_19.png and /dev/null differ