From 839f9066dc45ffaa59ec6f3d9d6398a8ae3fd612 Mon Sep 17 00:00:00 2001 From: Stephan Preibisch Date: Sat, 7 Sep 2024 11:22:52 -0400 Subject: [PATCH] fix resaving -> relaunch BDV so it uses the resaved dataset --- .../spimdata/explorer/popup/BDVPopup.java | 68 +++++++++++++------ .../spimdata/explorer/popup/ResavePopup.java | 14 ++-- 2 files changed, 52 insertions(+), 30 deletions(-) diff --git a/src/main/java/net/preibisch/mvrecon/fiji/spimdata/explorer/popup/BDVPopup.java b/src/main/java/net/preibisch/mvrecon/fiji/spimdata/explorer/popup/BDVPopup.java index 4e600729..6c00260d 100644 --- a/src/main/java/net/preibisch/mvrecon/fiji/spimdata/explorer/popup/BDVPopup.java +++ b/src/main/java/net/preibisch/mvrecon/fiji/spimdata/explorer/popup/BDVPopup.java @@ -31,6 +31,7 @@ import java.awt.Dimension; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.awt.event.WindowEvent; import java.net.URI; import java.util.Collection; @@ -100,39 +101,62 @@ public void actionPerformed( final ActionEvent e ) return; } - // TODO (TP): replace with lambda - new Thread( new Runnable() + new Thread( () -> { - @Override - public void run() - { - // if BDV was closed by the user - if ( bdv != null && !bdv.getViewerFrame().isVisible() ) - bdv = null; + // if BDV was closed by the user + if ( bdv != null && !bdv.getViewerFrame().isVisible() ) + bdv = null; - if ( bdv == null ) + if ( bdv == null ) + { + try { - - try - { - bdv = createBDV( panel ); - } - catch (Exception e) - { - IOFunctions.println( "Could not run BigDataViewer: " + e ); - e.printStackTrace(); - bdv = null; - } + bdv = createBDV( panel ); } - else + catch (Exception ex) { - closeBDV(); + IOFunctions.println( "Could not run BigDataViewer: " + e ); + ex.printStackTrace(); + bdv = null; } } + else + { + closeBDV(); + } }).start(); } } + public void reStartBDV() + { + new Thread( () -> + { + // if BDV was closed by the user + if ( bdv != null && !bdv.getViewerFrame().isVisible() ) + bdv = null; + + if ( bdv != null ) + { + final ViewerFrame frame = bdv.getViewerFrame(); + final WindowEvent windowClosing = new WindowEvent( frame, WindowEvent.WINDOW_CLOSING ); + frame.dispatchEvent( windowClosing ); + bdv = null; + } + + try + { + bdv = createBDV( panel ); + } + catch (Exception ex) + { + IOFunctions.println( "Could not run BigDataViewer: " + ex ); + ex.printStackTrace(); + bdv = null; + } + }).start(); + } + @Override public void closeBDV() { diff --git a/src/main/java/net/preibisch/mvrecon/fiji/spimdata/explorer/popup/ResavePopup.java b/src/main/java/net/preibisch/mvrecon/fiji/spimdata/explorer/popup/ResavePopup.java index 244b598d..227714dc 100644 --- a/src/main/java/net/preibisch/mvrecon/fiji/spimdata/explorer/popup/ResavePopup.java +++ b/src/main/java/net/preibisch/mvrecon/fiji/spimdata/explorer/popup/ResavePopup.java @@ -95,7 +95,7 @@ public JMenuItem setExplorerWindow( ExplorerWindow< ? > panel ) public class MyActionListener implements ActionListener { - final int index; // 0 == TIFF, 1 == HDF5 + final int index; // 0 == TIFF, 1 == compressed TIFF, 2 == HDF5, 3 == compressed HDF5, 4 == N5 public MyActionListener( final int index ) { @@ -111,18 +111,12 @@ public void actionPerformed( final ActionEvent e ) return; } - if ( !SpimData2.class.isInstance( panel.getSpimData() ) ) - { - IOFunctions.println( "Only supported for SpimData2 objects: " + this.getClass().getSimpleName() ); - return; - } - new Thread( new Runnable() { @Override public void run() { - final SpimData2 data = (SpimData2)panel.getSpimData(); + final SpimData2 data = panel.getSpimData(); final List< ViewId > viewIds = ApplyTransformationPopup.getSelectedViews( panel ); String question; @@ -318,6 +312,10 @@ else if (index == 4) panel.saveXML(); progressWriter.out().println( "done" ); } + + // re-open BDV if active + if ( panel.bdvPopup().bdvRunning() ) + panel.bdvPopup().reStartBDV(); } } ).start(); }