From 8fc203b340f2f93cf59756be899c9a4a1f966a8b Mon Sep 17 00:00:00 2001 From: Christian Tischer Date: Fri, 7 Jun 2024 11:41:32 +0200 Subject: [PATCH] WIP --- .../org/embl/mobie/lib/hcs/HCSPlateAdder.java | 2 +- .../java/org/embl/mobie/lib/hcs/Plate.java | 8 ++- .../embl/mobie/lib/table/SwingTableModel.java | 1 + .../org/embl/mobie/lib/table/TableView.java | 72 ++++++++++++------- .../org/embl/mobie/lib/view/ViewManager.java | 16 ++--- src/test/java/debug/DebugIssue1066.java | 6 +- 6 files changed, 64 insertions(+), 41 deletions(-) diff --git a/src/main/java/org/embl/mobie/lib/hcs/HCSPlateAdder.java b/src/main/java/org/embl/mobie/lib/hcs/HCSPlateAdder.java index 3286570a5..5137d12f1 100644 --- a/src/main/java/org/embl/mobie/lib/hcs/HCSPlateAdder.java +++ b/src/main/java/org/embl/mobie/lib/hcs/HCSPlateAdder.java @@ -227,6 +227,6 @@ private String getSiteID( Plate plate, Channel channel, Well well, Site site ) private String getWellID( Plate plate, Channel channel, Well well ) { - return Strings.join( "-", Arrays.asList( plate.getName(), "ch" + channel.getName(), "w" + well.getName() ) ); + return Strings.join( "-", Arrays.asList( plate.getName(), channel.getName(), well.getName() ) ); } } diff --git a/src/main/java/org/embl/mobie/lib/hcs/Plate.java b/src/main/java/org/embl/mobie/lib/hcs/Plate.java index 27d32cdf2..8f6183993 100644 --- a/src/main/java/org/embl/mobie/lib/hcs/Plate.java +++ b/src/main/java/org/embl/mobie/lib/hcs/Plate.java @@ -59,6 +59,7 @@ import java.util.concurrent.ExecutionException; import java.util.stream.Collectors; import java.util.stream.IntStream; +import java.util.stream.Stream; import static org.embl.mobie.lib.MoBIEHelper.computeMinMax; @@ -111,8 +112,9 @@ public Plate( String hcsDirectory, @Nullable VoxelDimensions voxelDimensions ) t } imagePaths = OMEZarrHCSHelper.imagePathsFromMetadata( hcsDirectory ); - - ImageData< ? > imageData = ImageDataOpener.open( imagePaths.get( 0 ), imageDataFormat, ThreadHelper.sharedQueue ); + Collections.sort( imagePaths ); + String referenceImagePath = imagePaths.get( 0 ); + ImageData< ? > imageData = ImageDataOpener.open( referenceImagePath, imageDataFormat, ThreadHelper.sharedQueue ); int numChannels = imageData.getNumDatasets(); List< String > channelNames = IntStream.range( 0, numChannels ) .mapToObj( imageData::getName ) @@ -311,7 +313,7 @@ private void buildPlateMap( List< String > imagePaths ) IJ.log( "" ); final Map< String, Entity > attributes = viewSetup.getAttributes(); IJ.log( "Image index:" + imageIndex ); - IJ.log( "Series index: " + ( ( SeriesIndex ) attributes.get( "seriesindex" ) ).getId() ); + IJ.log( "Series index: " + attributes.get( "seriesindex" ).getId() ); IJ.log( "Setup name: " + viewSetup.getName() ); IJ.log( "File name: " + new File( imagePath ).getName() ); site = new Site( siteGroup, imageDataFormat, spimDataPlate, imageIndex ); diff --git a/src/main/java/org/embl/mobie/lib/table/SwingTableModel.java b/src/main/java/org/embl/mobie/lib/table/SwingTableModel.java index e94396b71..a2293bc80 100644 --- a/src/main/java/org/embl/mobie/lib/table/SwingTableModel.java +++ b/src/main/java/org/embl/mobie/lib/table/SwingTableModel.java @@ -127,6 +127,7 @@ public void removeTableModelListener( TableModelListener l ) public void tableChanged() { + // https://github.com/mobie/mobie-viewer-fiji/issues/1146 for ( TableModelListener listener : tableModelListeners ) { final TableModelEvent tableModelEvent = new TableModelEvent( this, TableModelEvent.HEADER_ROW ); 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 e55482e19..eeb81bc38 100644 --- a/src/main/java/org/embl/mobie/lib/table/TableView.java +++ b/src/main/java/org/embl/mobie/lib/table/TableView.java @@ -28,6 +28,7 @@ */ package org.embl.mobie.lib.table; +import IceInternal.Ex; import de.embl.cba.tables.Logger; import de.embl.cba.tables.TableUIs; import ij.IJ; @@ -111,6 +112,7 @@ public void close() public void show() { + // Prefetch the columns and wait a bit as this hopefully makes it less likely that // there are errors thrown by Java Swing when rendering the table window // below during frame.pack() @@ -119,8 +121,10 @@ public void show() for ( int columnIndex = 0; columnIndex < columnCount; columnIndex++ ) { TableColumn column = columnModel.getColumn( columnIndex ); + if ( column == null ) + throw new NullPointerException(""); } - IJ.log( "Showing table " + tableName + " with " + columnCount + " columns."); + IJ.log( "Showing table \"" + tableName + "\" with " + columnCount + " columns."); IJ.wait( 200 ); final JPanel panel = new JPanel( new GridLayout( 1, 0 ) ); @@ -130,7 +134,6 @@ public void show() JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED ); panel.add( scrollPane ); - jTable.setAutoResizeMode( JTable.AUTO_RESIZE_OFF ); panel.updateUI(); panel.setOpaque( true ); @@ -139,31 +142,37 @@ public void show() frame.setJMenuBar( menuBar ); frame.setContentPane( panel ); - // Display the window try { - frame.pack(); + // Adding a delay + Timer timer = new Timer(200, e -> { + frame.pack(); + frame.setVisible(true); + }); + timer.setRepeats(false); + timer.start(); } catch ( Exception e ) { IJ.log("Error showing table: " + tableName ); } - // Replace closing by making it invisible frame.setDefaultCloseOperation( WindowConstants.DO_NOTHING_ON_CLOSE ); frame.addWindowListener( new WindowAdapter() { public void windowClosing( WindowEvent ev) { frame.setVisible( false ); } - }); + }); //frame.pack(); } private void configureJTable() { swingTableModel = new SwingTableModel( tableModel ); jTable = new JTable( swingTableModel ); + TableColumnModel columnModel = jTable.getColumnModel(); + TableColumn column = columnModel.getColumn( 0 ); jTable.updateUI(); - jTable.setPreferredScrollableViewportSize( new Dimension(500, 200) ); + jTable.setPreferredScrollableViewportSize( new Dimension( 500, 200 ) ); jTable.setFillsViewportHeight( true ); jTable.setAutoCreateRowSorter( true ); jTable.setRowSelectionAllowed( true ); @@ -316,8 +325,11 @@ private synchronized void updateTable() { if ( jTable == null ) return; + // https://github.com/mobie/mobie-viewer-fiji/issues/1146 swingTableModel.tableChanged(); - repaintTable(); + + if ( jTable.isVisible() ) + repaintTable(); } private JMenuItem createSaveTableAsMenuItem() @@ -850,28 +862,38 @@ private synchronized void repaintTable() @Override public void annotationsAdded( Collection< A > annotations ) { + // https://github.com/mobie/mobie-viewer-fiji/issues/1146 updateTable(); } @Override public synchronized void columnsAdded( Collection< String > columns ) { - updateTable(); - // TODO: errors such as - // Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 31 >= 31 - // at java.util.Vector.elementAt(Vector.java:479) - // at javax.swing.table.DefaultTableColumnModel -// For debugging: -// final List< String > columnNames = tableModel.columnNames(); -// final int swingColumnCount = swingTableModel.getColumnCount(); -// final TableColumnModel columnModel = jTable.getColumnModel(); -// final int jTableColumnCount = columnModel.getColumnCount(); -//// IJ.wait( 100 ); // maybe this avoids the updating error? -// for ( int i = 0; i < columnNames.size(); i++ ) -// { -// System.out.println( columnNames.get( i ) ); -// System.out.println( swingTableModel.getColumnName( i ) ); -// System.out.println( jTable.getColumnName( i ) ); -// } + try + { + updateTable(); + } + catch ( Exception e ) + { + // TODO: errors such as + // Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 31 >= 31 + // at java.util.Vector.elementAt(Vector.java:479) + // at javax.swing.table.DefaultTableColumnModel + // For debugging: + System.out.println("Error updating " + tableName ); + final List< String > columnNames = tableModel.columnNames(); + final int swingColumnCount = swingTableModel.getColumnCount(); + final TableColumnModel columnModel = jTable.getColumnModel(); + final int jTableColumnCount = columnModel.getColumnCount(); + IJ.wait( 100 ); // maybe this avoids the updating error? + for ( int i = 0; i < columnNames.size(); i++ ) + { + System.out.println( columnNames.get( i ) ); + System.out.println( swingTableModel.getColumnName( i ) ); + System.out.println( jTable.getColumnName( i ) ); + } + throw new RuntimeException( e ); + } + } } diff --git a/src/main/java/org/embl/mobie/lib/view/ViewManager.java b/src/main/java/org/embl/mobie/lib/view/ViewManager.java index 253774810..cbe80c964 100644 --- a/src/main/java/org/embl/mobie/lib/view/ViewManager.java +++ b/src/main/java/org/embl/mobie/lib/view/ViewManager.java @@ -342,18 +342,12 @@ public void initData( View view ) final MergedGridTransformation mergedGridTransformation = ( MergedGridTransformation ) transformOrDisplay; if ( mergedGridTransformation.metadataSource != null ) { - if ( dataSourceName.equals( mergedGridTransformation.metadataSource ) ) - dataSource.preInit( true ); - else - dataSource.preInit( false ); + dataSource.preInit( dataSourceName.equals( mergedGridTransformation.metadataSource ) ); } else // no metadata source specified, use the first in the grid as metadata source { final String firstImageInGrid = mergedGridTransformation.getSources().get( 0 ); - if ( dataSourceName.equals( firstImageInGrid ) ) - dataSource.preInit( true ); - else - dataSource.preInit( false ); + dataSource.preInit( dataSourceName.equals( firstImageInGrid ) ); } } else @@ -709,6 +703,9 @@ private void initImageVolumeViewer( ImageDisplay< ? > imageDisplay ) private void initTableView( AbstractAnnotationDisplay< ? extends Annotation > display ) { display.tableView = new TableView( display ); + display.selectionModel.listeners().add( display.tableView ); + display.coloringModel.listeners().add( display.tableView ); + // TODO: currently we must show the table here // in order to instantiate the window. // This window is needed in {@code UserInterfaceHelper} @@ -716,11 +713,8 @@ private void initTableView( AbstractAnnotationDisplay< ? extends Annotation > di // in which the table window will be // hidden, if {@code display.showTable == false}. // It would be good if we would not have to show it. - display.tableView.show(); setTablePosition( display.sliceViewer.getWindow(), display.tableView.getWindow() ); - display.selectionModel.listeners().add( display.tableView ); - display.coloringModel.listeners().add( display.tableView ); } private void setTablePosition( Window reference, Window table ) diff --git a/src/test/java/debug/DebugIssue1066.java b/src/test/java/debug/DebugIssue1066.java index ee5cfb75e..8e3ea8e27 100644 --- a/src/test/java/debug/DebugIssue1066.java +++ b/src/test/java/debug/DebugIssue1066.java @@ -43,7 +43,11 @@ public static void main( String[] args ) throws IOException imageJ.ui().showUI(); OpenHCSDatasetCommand command = new OpenHCSDatasetCommand(); - command.hcsDirectory = "/Users/tischer/Downloads/20200812-CardiomyocyteDifferentiation14-Cycle1_mip.zarr"; + //command.hcsDirectory = "/Users/tischer/Downloads/20200812-CardiomyocyteDifferentiation14-Cycle1_mip.zarr"; + + // https://forum.image.sc/t/ome-zarr-hcs-with-labels-on-s3/97327/3 + command.hcsDirectory = "https://uk1s3.embassy.ebi.ac.uk/idr/zarr/v0.4/idr0001A/2551.zarr"; + command.run(); } }