Skip to content

Commit

Permalink
Move the image path util to the TMUtils class.
Browse files Browse the repository at this point in the history
And make it able to harness weird cases.
  • Loading branch information
tinevez committed Oct 9, 2023
1 parent 72192e9 commit 347f114
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 18 deletions.
11 changes: 0 additions & 11 deletions src/main/java/fiji/plugin/trackmate/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -303,17 +303,6 @@ public Settings copyOn( final ImagePlus newImp )
* METHODS
*/

/**
* Returns a string of the name of the image without the extension, with the
* full path
*
* @return full name of the image without the extension
*/
public String getFileNameWithoutExtension()
{
return imageFolder + imageFileName.substring( 0, imageFileName.lastIndexOf( "." ) );
}

/**
* Returns a string description of the target image.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import fiji.plugin.trackmate.SelectionModel;
import fiji.plugin.trackmate.TrackMate;
import fiji.plugin.trackmate.gui.displaysettings.DisplaySettings;
import fiji.plugin.trackmate.util.TMUtils;
import fiji.plugin.trackmate.visualization.table.AllSpotsTableView;

public class ExportAllSpotsStatsAction extends AbstractTMAction
Expand All @@ -51,7 +52,7 @@ public class ExportAllSpotsStatsAction extends AbstractTMAction
@Override
public void execute( final TrackMate trackmate, final SelectionModel selectionModel, final DisplaySettings displaySettings, final Frame parent )
{
createSpotsTable( trackmate.getModel(), selectionModel, displaySettings, trackmate.getSettings().getFileNameWithoutExtension() ).render();
createSpotsTable( trackmate.getModel(), selectionModel, displaySettings, TMUtils.getImagePathWithoutExtension( trackmate.getSettings() ) ).render();
}

public static final AllSpotsTableView createSpotsTable( final Model model, final SelectionModel selectionModel, final DisplaySettings displaySettings, final String imageFileName )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import fiji.plugin.trackmate.SelectionModel;
import fiji.plugin.trackmate.TrackMate;
import fiji.plugin.trackmate.gui.displaysettings.DisplaySettings;
import fiji.plugin.trackmate.util.TMUtils;
import fiji.plugin.trackmate.visualization.table.TrackTableView;

public class ExportStatsTablesAction extends AbstractTMAction
Expand All @@ -57,7 +58,7 @@ public class ExportStatsTablesAction extends AbstractTMAction
@Override
public void execute( final TrackMate trackmate, final SelectionModel selectionModel, final DisplaySettings displaySettings, final Frame parent )
{
createTrackTables( trackmate.getModel(), selectionModel, displaySettings, trackmate.getSettings().getFileNameWithoutExtension() ).render();
createTrackTables( trackmate.getModel(), selectionModel, displaySettings, TMUtils.getImagePathWithoutExtension( trackmate.getSettings() ) ).render();
}

public static TrackTableView createTrackTables( final Model model, final SelectionModel selectionModel, final DisplaySettings displaySettings, final String imageFileName )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import fiji.plugin.trackmate.SelectionModel;
import fiji.plugin.trackmate.TrackMate;
import fiji.plugin.trackmate.gui.displaysettings.DisplaySettings;
import fiji.plugin.trackmate.util.TMUtils;
import fiji.plugin.trackmate.visualization.table.BranchTableView;

public class TrackBranchAnalysis extends AbstractTMAction
Expand All @@ -55,7 +56,7 @@ public class TrackBranchAnalysis extends AbstractTMAction
@Override
public void execute( final TrackMate trackmate, final SelectionModel selectionModel, final DisplaySettings displaySettings, final Frame parent )
{
createBranchTable( trackmate.getModel(), selectionModel, trackmate.getSettings().getFileNameWithoutExtension() ).render();
createBranchTable( trackmate.getModel(), selectionModel, TMUtils.getImagePathWithoutExtension( trackmate.getSettings() ) ).render();
}

public static final BranchTableView createBranchTable( final Model model, final SelectionModel selectionModel, final String imageFileName )
Expand Down
35 changes: 31 additions & 4 deletions src/main/java/fiji/plugin/trackmate/util/TMUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public class TMUtils
{

private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat( "EEE, d MMM yyyy HH:mm:ss" );

private static Context context;

/*
Expand Down Expand Up @@ -713,12 +714,12 @@ public static final Interval getInterval( final ImgPlus< ? > img, final Settings
public static Context getContext()
{
final Context localContext = context;
if (localContext != null)
if ( localContext != null )
return localContext;
synchronized (TMUtils.class)

synchronized ( TMUtils.class )
{
if (context == null)
if ( context == null )
context = ( Context ) IJ.runPlugIn( "org.scijava.Context", "" );
return context;
}
Expand Down Expand Up @@ -842,6 +843,32 @@ public static double standardDeviation( final DoubleArray data )
return Math.sqrt( variance( data ) );
}

/**
* Returns a string of the name of the image without the extension, with the
* full path
*
* @return full name of the image without the extension
*/
public static String getImagePathWithoutExtension( final Settings settings )
{
final String imageFolder = ( settings.imageFolder == null )
? System.getProperty( "user.home" )
: settings.imageFolder;

final String imageFileName = settings.imageFileName;
if ( imageFileName != null )
{
final int lastIndexOf = imageFileName.lastIndexOf( "." );
if ( lastIndexOf > 0 )
return imageFolder + imageFileName.substring( 0, imageFileName.lastIndexOf( "." ) );
return imageFolder + imageFileName;
}
else
{
return imageFolder + File.separator + "TrackMate";
}
}

private TMUtils()
{}
}

0 comments on commit 347f114

Please sign in to comment.