Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
tischi committed Jun 7, 2024
1 parent 8083a99 commit 8fc203b
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 41 deletions.
2 changes: 1 addition & 1 deletion src/main/java/org/embl/mobie/lib/hcs/HCSPlateAdder.java
Original file line number Diff line number Diff line change
Expand Up @@ -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() ) );
}
}
8 changes: 5 additions & 3 deletions src/main/java/org/embl/mobie/lib/hcs/Plate.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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 )
Expand Down Expand Up @@ -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 );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
72 changes: 47 additions & 25 deletions src/main/java/org/embl/mobie/lib/table/TableView.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()
Expand All @@ -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 ) );
Expand All @@ -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 );

Expand All @@ -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 );
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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 );
}

}
}
16 changes: 5 additions & 11 deletions src/main/java/org/embl/mobie/lib/view/ViewManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -709,18 +703,18 @@ 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}
// in the function {@code createWindowVisibilityCheckbox},
// 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 )
Expand Down
6 changes: 5 additions & 1 deletion src/test/java/debug/DebugIssue1066.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

0 comments on commit 8fc203b

Please sign in to comment.