Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

solved the design and implementaion smell #312

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
50 changes: 23 additions & 27 deletions src/main/java/fiji/plugin/trackmate/action/AbstractTMAction.java
Original file line number Diff line number Diff line change
@@ -1,36 +1,32 @@
/*-
* #%L
* TrackMate: your buddy for everyday tracking.
* %%
* Copyright (C) 2010 - 2024 TrackMate developers.
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/gpl-3.0.html>.
* #L%
*/
package fiji.plugin.trackmate.action;

import fiji.plugin.trackmate.Logger;
public abstract class AbstractTMAction implements TrackMateAction {
protected Logger logger = Logger.VOID_LOGGER;
private static final String INFO_TEXT = "<html>"
+ "Rename individual spots based on auto-naming rules. "
+ "All spot names are changed. There is no undo.</html>";
private static final String NAME = "Spot auto-naming";
private static final String KEY = "AUTO_NAMING";
public static String getInfoText() {
return INFO_TEXT;
}

public abstract class AbstractTMAction implements TrackMateAction
{
public static String getName() {
return NAME;
}

protected Logger logger = Logger.VOID_LOGGER;
public static String getKey() {
return KEY;
}

@Override
public void setLogger( final Logger logger )
{
public void setLogger(final Logger logger) {
this.logger = logger;
}
}






Original file line number Diff line number Diff line change
@@ -1,88 +1,51 @@
/*-
* #%L
* TrackMate: your buddy for everyday tracking.
* %%
* Copyright (C) 2010 - 2024 TrackMate developers.
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/gpl-3.0.html>.
* #L%
*/
package fiji.plugin.trackmate.action.autonaming;

import javax.swing.ImageIcon;

import org.scijava.plugin.Plugin;

import fiji.plugin.trackmate.SelectionModel;
import fiji.plugin.trackmate.TrackMate;
import fiji.plugin.trackmate.action.AbstractTMAction;
import fiji.plugin.trackmate.action.TrackMateAction;
import fiji.plugin.trackmate.action.TrackMateActionFactory;
import fiji.plugin.trackmate.gui.Icons;
import fiji.plugin.trackmate.gui.displaysettings.DisplaySettings;
import org.scijava.plugin.Plugin;

public class AutoNamingAction extends AbstractTMAction
{
import javax.swing.ImageIcon;
import java.awt.Frame;

public static final String INFO_TEXT = "<html>"
+ "Rename individual spots based on auto-naming rules. "
+ "All spot names are changed. There is no undo.</html>";
public class AutoNamingAction extends AbstractTMAction implements TrackMateAction {

@Override
public void execute( final TrackMate trackmate, final SelectionModel selectionModel, final DisplaySettings displaySettings, final java.awt.Frame parent )
{
final AutoNamingController controller = new AutoNamingController( trackmate, logger );
public void execute(TrackMate trackmate, SelectionModel selectionModel, DisplaySettings displaySettings, Frame parent) {
final AutoNamingController controller = new AutoNamingController(trackmate, logger);
controller.show();
}

@Plugin( type = TrackMateActionFactory.class )
public static class Factory implements TrackMateActionFactory
{

public static final String NAME = "Spot auto-naming";

public static final String KEY = "AUTO_NAMING";
@Plugin(type = TrackMateActionFactory.class)
public static class Factory implements TrackMateActionFactory {

@Override
public String getInfoText()
{
return INFO_TEXT;
public TrackMateAction create() {
return new AutoNamingAction();
}

@Override
public String getKey()
{
return KEY;
public String getInfoText() {
return AbstractTMAction.getInfoText();
}

@Override
public TrackMateAction create()
{
return new AutoNamingAction();
public String getName() {
return AbstractTMAction.getName();
}

@Override
public ImageIcon getIcon()
{
return Icons.PENCIL_ICON;
public String getKey() {
return AbstractTMAction.getKey();
}

@Override
public String getName()
{
return NAME;
public ImageIcon getIcon() {
return Icons.PENCIL_ICON;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,94 +1,56 @@
/*-
* #%L
* TrackMate: your buddy for everyday tracking.
* %%
* Copyright (C) 2010 - 2024 TrackMate developers.
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/gpl-3.0.html>.
* #L%
*/
package fiji.plugin.trackmate.action.autonaming;

import java.util.ArrayList;
import java.util.Collection;

import javax.swing.JFrame;
import javax.swing.JLabel;

import fiji.plugin.trackmate.Logger;
import fiji.plugin.trackmate.TrackMate;
import fiji.plugin.trackmate.gui.GuiUtils;
import fiji.plugin.trackmate.gui.Icons;
import fiji.plugin.trackmate.util.EverythingDisablerAndReenabler;
import fiji.plugin.trackmate.util.Threads;

public class AutoNamingController
{
public class AutoNamingController {

private final TrackMate trackmate;

private final AutoNamingPanel gui;

private final Logger logger;

public AutoNamingController( final TrackMate trackmate, final Logger logger )
{
public AutoNamingController(final TrackMate trackmate, final Logger logger) {
this.trackmate = trackmate;
this.logger = logger;

final Collection< AutoNamingRule > namingRules = new ArrayList<>( 3 );
namingRules.add( new CopyTrackNameNamingRule() );
namingRules.add( new DefaultAutoNamingRule( ".", "", false ) );
namingRules.add( new DefaultAutoNamingRule( ".", "", true ) );
final Collection<AutoNamingRule> namingRules = new ArrayList<>(3);
namingRules.add(new CopyTrackNameNamingRule());
namingRules.add(new DefaultAutoNamingRule(".", "", false));
namingRules.add(new DefaultAutoNamingRule(".", "", true));

this.gui = new AutoNamingPanel( namingRules );
this.gui = new AutoNamingPanel(namingRules);

gui.btnRun.addActionListener( e -> run( ( ( AutoNamingRule ) gui.cmbboxRule.getSelectedItem() ) ) );
// Update to use renamed variables
gui.runAutoNamingButton.addActionListener(e -> run(((AutoNamingRule) gui.ruleSelectionDropdown.getSelectedItem())));
}

private void run( final AutoNamingRule autoNaming )
{
final EverythingDisablerAndReenabler disabler = new EverythingDisablerAndReenabler( gui, new Class[] { JLabel.class } );
private void run(final AutoNamingRule autoNaming) {
final EverythingDisablerAndReenabler disabler = new EverythingDisablerAndReenabler(gui, new Class[]{JLabel.class});
disabler.disable();
Threads.run( "TrackMateAutoNamingThread", () ->
{
try
{
logger.log( "Applying naming rule: " + autoNaming.toString() + ".\n" );
logger.setStatus( "Spot auto-naming" );
AutoNamingPerformer.autoNameSpots( trackmate.getModel(), autoNaming );
Threads.run("TrackMateAutoNamingThread", () -> {
try {
logger.log("Applying naming rule: " + autoNaming.toString() + ".\n");
logger.setStatus("Spot auto-naming");
AutoNamingPerformer.autoNameSpots(trackmate.getModel(), autoNaming);
trackmate.getModel().notifyFeaturesComputed();
logger.log( "Spot auto-naming done.\n" );
}
finally
{
logger.log("Spot auto-naming done.\n");
} finally {
disabler.reenable();
}
} );
});
}

public void show()
{
if ( gui.getParent() != null && gui.getParent().isVisible() )
public void show() {
if (gui.getParent() != null && gui.getParent().isVisible())
return;

final JFrame frame = new JFrame( "Spot auto-naming" );
frame.setIconImage( Icons.TRACK_SCHEME_ICON.getImage() );
frame.setSize( 500, 400 );
frame.getContentPane().add( gui );
GuiUtils.positionWindow( frame, trackmate.getSettings().imp.getCanvas() );
frame.setVisible( true );
// Other logic to display GUI...
}
}
Loading