From 3489a585019cf928320a07d7cd6c7f83b1012f1f Mon Sep 17 00:00:00 2001 From: falgunpatel07 <71875123+falgunpatel07@users.noreply.github.com> Date: Thu, 28 Nov 2024 00:31:30 -0400 Subject: [PATCH 01/10] Deficient Encapsulation design smell number one of type true positive --- .../trackmate/action/AbstractTMAction.java | 43 +++++------ .../action/autonaming/AutoNamingAction.java | 73 +++++-------------- .../action/autonaming/AutoNamingPanel.java | 24 +----- 3 files changed, 38 insertions(+), 102 deletions(-) diff --git a/src/main/java/fiji/plugin/trackmate/action/AbstractTMAction.java b/src/main/java/fiji/plugin/trackmate/action/AbstractTMAction.java index 3769a878a..7ea83e7e6 100644 --- a/src/main/java/fiji/plugin/trackmate/action/AbstractTMAction.java +++ b/src/main/java/fiji/plugin/trackmate/action/AbstractTMAction.java @@ -1,36 +1,29 @@ -/*- - * #%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 - * . - * #L% - */ package fiji.plugin.trackmate.action; import fiji.plugin.trackmate.Logger; -public abstract class AbstractTMAction implements TrackMateAction -{ +public abstract class AbstractTMAction implements TrackMateAction { protected Logger logger = Logger.VOID_LOGGER; + private static final String INFO_TEXT = "" + + "Rename individual spots based on auto-naming rules. " + + "All spot names are changed. There is no undo."; + private static final String NAME = "Spot auto-naming"; + private static final String KEY = "AUTO_NAMING"; + public static String getInfoText() { + return INFO_TEXT; + } + + public static String getName() { + return NAME; + } + + public static String getKey() { + return KEY; + } @Override - public void setLogger( final Logger logger ) - { + public void setLogger(final Logger logger) { this.logger = logger; } } diff --git a/src/main/java/fiji/plugin/trackmate/action/autonaming/AutoNamingAction.java b/src/main/java/fiji/plugin/trackmate/action/autonaming/AutoNamingAction.java index 13555be67..d642376c5 100644 --- a/src/main/java/fiji/plugin/trackmate/action/autonaming/AutoNamingAction.java +++ b/src/main/java/fiji/plugin/trackmate/action/autonaming/AutoNamingAction.java @@ -1,30 +1,5 @@ -/*- - * #%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 - * . - * #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; @@ -32,57 +7,45 @@ 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 = "" - + "Rename individual spots based on auto-naming rules. " - + "All spot names are changed. There is no undo."; +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; } } } diff --git a/src/main/java/fiji/plugin/trackmate/action/autonaming/AutoNamingPanel.java b/src/main/java/fiji/plugin/trackmate/action/autonaming/AutoNamingPanel.java index b69187731..f558a9306 100644 --- a/src/main/java/fiji/plugin/trackmate/action/autonaming/AutoNamingPanel.java +++ b/src/main/java/fiji/plugin/trackmate/action/autonaming/AutoNamingPanel.java @@ -1,24 +1,4 @@ -/*- - * #%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 - * . - * #L% - */ + package fiji.plugin.trackmate.action.autonaming; import java.awt.GridBagConstraints; @@ -66,7 +46,7 @@ public AutoNamingPanel( final Collection< AutoNamingRule > namingRules ) gbcLblTitle.gridy = 0; add( lblTitle, gbcLblTitle ); - final JLabel lblDoc = new JLabel( AutoNamingAction.INFO_TEXT ); + final JLabel lblDoc = new JLabel( AutoNamingAction.getInfoText() ); lblDoc.setFont( Fonts.SMALL_FONT ); final GridBagConstraints gbcLblDoc = new GridBagConstraints(); gbcLblDoc.gridwidth = 2; From 7d52d47c81b670ee7999105fb7ab3ce13acc3b51 Mon Sep 17 00:00:00 2001 From: falgunpatel07 <71875123+falgunpatel07@users.noreply.github.com> Date: Fri, 29 Nov 2024 14:43:39 -0400 Subject: [PATCH 02/10] Implementation smell Using Extractmethod solved the first implementaion smell and build successfully. --- .../trackmate/action/AbstractTMAction.java | 9 +- .../action/autonaming/AutoNamingPanel.java | 3 - .../action/autonaming/AutoNamingRule.java | 35 +++++ .../autonaming/DefaultAutoNamingRule.java | 120 +++++++----------- 4 files changed, 86 insertions(+), 81 deletions(-) diff --git a/src/main/java/fiji/plugin/trackmate/action/AbstractTMAction.java b/src/main/java/fiji/plugin/trackmate/action/AbstractTMAction.java index 7ea83e7e6..495c31183 100644 --- a/src/main/java/fiji/plugin/trackmate/action/AbstractTMAction.java +++ b/src/main/java/fiji/plugin/trackmate/action/AbstractTMAction.java @@ -1,9 +1,6 @@ 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 = "" + "Rename individual spots based on auto-naming rules. " @@ -27,3 +24,9 @@ public void setLogger(final Logger logger) { this.logger = logger; } } + + + + + + diff --git a/src/main/java/fiji/plugin/trackmate/action/autonaming/AutoNamingPanel.java b/src/main/java/fiji/plugin/trackmate/action/autonaming/AutoNamingPanel.java index f558a9306..d3df0fe73 100644 --- a/src/main/java/fiji/plugin/trackmate/action/autonaming/AutoNamingPanel.java +++ b/src/main/java/fiji/plugin/trackmate/action/autonaming/AutoNamingPanel.java @@ -1,12 +1,9 @@ - package fiji.plugin.trackmate.action.autonaming; - import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.Insets; import java.util.Collection; import java.util.Vector; - import javax.swing.BorderFactory; import javax.swing.JButton; import javax.swing.JComboBox; diff --git a/src/main/java/fiji/plugin/trackmate/action/autonaming/AutoNamingRule.java b/src/main/java/fiji/plugin/trackmate/action/autonaming/AutoNamingRule.java index 8921d43ea..325d91751 100644 --- a/src/main/java/fiji/plugin/trackmate/action/autonaming/AutoNamingRule.java +++ b/src/main/java/fiji/plugin/trackmate/action/autonaming/AutoNamingRule.java @@ -75,3 +75,38 @@ public default void nameSpot( final Spot current, final Spot predecessor ) public String getInfoText(); } + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/java/fiji/plugin/trackmate/action/autonaming/DefaultAutoNamingRule.java b/src/main/java/fiji/plugin/trackmate/action/autonaming/DefaultAutoNamingRule.java index 07a62d67c..aa401667b 100644 --- a/src/main/java/fiji/plugin/trackmate/action/autonaming/DefaultAutoNamingRule.java +++ b/src/main/java/fiji/plugin/trackmate/action/autonaming/DefaultAutoNamingRule.java @@ -21,10 +21,7 @@ */ package fiji.plugin.trackmate.action.autonaming; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Comparator; -import java.util.List; +import java.util.*; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -66,94 +63,67 @@ public void nameRoot( final Spot root, final TrackModel model ) : trackName; root.setName( rootName ); } - @Override - public void nameBranches( final Spot mother, final Collection< Spot > siblings ) - { - + public void nameBranches(final Spot mother, final Collection siblings) { // Sort siblings by their X position. - final List< Spot > spots = new ArrayList<>( siblings ); - spots.sort( Comparator.comparing( s -> s.getDoublePosition( 0 ) ) ); + final List spots = sortSiblingsByXPosition(siblings); // Predecessor name. final String motherName = mother.getName(); - final String[] tokens = motherName.split( Pattern.quote( suffixSeparator ) ); + final String[] tokens = motherName.split(Pattern.quote(suffixSeparator)); // Find in what token the branch suffix is stored. - int branchTokenIndex = -1; - for ( int i = 0; i < tokens.length; i++ ) - { - final String token = tokens[ i ]; - final Matcher matcher = branchPattern.matcher( token ); - if ( matcher.matches() ) - { - branchTokenIndex = i; - break; - } + int branchTokenIndex = findBranchTokenIndex(tokens); + + if (branchTokenIndex < 0) { + // Could not find branch token; add new branch suffix. + addNewBranchSuffix(motherName, spots); + return; } - if ( branchTokenIndex < 0 ) - { - /* - * Could not find it. Maybe because the mother comes from the root - * branch. In that case we add the suffix separator and a new char - * for the branch. - */ - if ( !incrementSuffix ) - { - // There won't be a '.23' at the end. - char bname = 'a'; - for ( final Spot spot : spots ) - { - spot.setName( motherName + suffixSeparator + bname ); - bname += 1; - } - } - else - { - // There is a '.23' at then end. - char bname = 'a'; - for ( final Spot spot : spots ) - { - final String[] newTokens = new String[ tokens.length + 1 ]; - for ( int i = 0; i < tokens.length; i++ ) - newTokens[ i ] = tokens[ i ]; - newTokens[ tokens.length - 1 ] = "" + bname; - newTokens[ tokens.length ] = "1"; // restart - final String branchName = String.join( suffixSeparator, newTokens ); - spot.setName( branchName ); - bname += 1; - } + // Add a new branch name for each sibling. + addBranchNames(tokens, spots, branchTokenIndex); + } + + private List sortSiblingsByXPosition(final Collection siblings) { + final List spots = new ArrayList<>(siblings); + spots.sort(Comparator.comparing(s -> s.getDoublePosition(0))); + return spots; + } + + private int findBranchTokenIndex(final String[] tokens) { + for (int i = 0; i < tokens.length; i++) { + final String token = tokens[i]; + final Matcher matcher = branchPattern.matcher(token); + if (matcher.matches()) { + return i; } - return; } + return -1; + } - /* - * A branch char combination already exists. We add to it. - */ + private void addNewBranchSuffix(final String motherName, final List spots) { char bname = 'a'; - for ( final Spot spot : spots ) - { - // Copy. - final String[] newTokens = new String[ tokens.length ]; - for ( int i = 0; i < tokens.length; i++ ) - newTokens[ i ] = tokens[ i ]; - // Edit. - if ( !incrementSuffix ) - { - newTokens[ newTokens.length - 1 ] += branchSeparator + bname; - } - else - { - newTokens[ newTokens.length - 2 ] += branchSeparator + bname; - newTokens[ newTokens.length - 1 ] = "1"; // restart - } - final String branchName = String.join( suffixSeparator, newTokens ); - spot.setName( branchName ); + for (final Spot spot : spots) { + spot.setName(motherName + suffixSeparator + bname); bname += 1; } } + private void addBranchNames(final String[] tokens, final List spots, final int branchTokenIndex) { + char bname = 'a'; + for (final Spot spot : spots) { + final String[] newTokens = Arrays.copyOf(tokens, tokens.length); + if (!incrementSuffix) { + newTokens[newTokens.length - 1] += branchSeparator + bname; + } else { + newTokens[newTokens.length - 2] += branchSeparator + bname; + newTokens[newTokens.length - 1] = "1"; // Restart. + } + spot.setName(String.join(suffixSeparator, newTokens)); + bname += 1; + } + } @Override public void nameSpot( final Spot current, final Spot predecessor ) { From 50710ed3ee3b3bf8536a4c17e2d4c2b873c198a2 Mon Sep 17 00:00:00 2001 From: falgunpatel07 <71875123+falgunpatel07@users.noreply.github.com> Date: Fri, 29 Nov 2024 16:40:55 -0400 Subject: [PATCH 03/10] second Implementation smell --- .../autonaming/AutoNamingController.java | 82 ++++---------- .../action/autonaming/AutoNamingPanel.java | 106 ++++++------------ 2 files changed, 56 insertions(+), 132 deletions(-) diff --git a/src/main/java/fiji/plugin/trackmate/action/autonaming/AutoNamingController.java b/src/main/java/fiji/plugin/trackmate/action/autonaming/AutoNamingController.java index 533e70ed0..1ff89e953 100644 --- a/src/main/java/fiji/plugin/trackmate/action/autonaming/AutoNamingController.java +++ b/src/main/java/fiji/plugin/trackmate/action/autonaming/AutoNamingController.java @@ -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 - * . - * #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 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... } } diff --git a/src/main/java/fiji/plugin/trackmate/action/autonaming/AutoNamingPanel.java b/src/main/java/fiji/plugin/trackmate/action/autonaming/AutoNamingPanel.java index d3df0fe73..4f33924fa 100644 --- a/src/main/java/fiji/plugin/trackmate/action/autonaming/AutoNamingPanel.java +++ b/src/main/java/fiji/plugin/trackmate/action/autonaming/AutoNamingPanel.java @@ -1,4 +1,5 @@ package fiji.plugin.trackmate.action.autonaming; + import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.Insets; @@ -13,87 +14,48 @@ import fiji.plugin.trackmate.gui.Fonts; -public class AutoNamingPanel extends JPanel -{ +public class AutoNamingPanel extends JPanel { private static final long serialVersionUID = 1L; - final JComboBox< AutoNamingRule > cmbboxRule; - - final JButton btnRun; + // Updated names + final JComboBox ruleSelectionDropdown; + final JButton runAutoNamingButton; - public AutoNamingPanel( final Collection< AutoNamingRule > namingRules ) - { - setBorder( BorderFactory.createEmptyBorder( 5, 5, 5, 5 ) ); + public AutoNamingPanel(final Collection namingRules) { + setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); final GridBagLayout gridBagLayout = new GridBagLayout(); - gridBagLayout.columnWidths = new int[] { 0, 0, 0 }; - gridBagLayout.rowHeights = new int[] { 0, 0, 0, 0, 0, 0 }; - gridBagLayout.columnWeights = new double[] { 1.0, 1.0, Double.MIN_VALUE }; - gridBagLayout.rowWeights = new double[] { 0.0, 1.0, 0.0, 1.0, 0.0, Double.MIN_VALUE }; - setLayout( gridBagLayout ); - - final JLabel lblTitle = new JLabel( "Auto naming spots" ); - lblTitle.setFont( Fonts.BIG_FONT ); - lblTitle.setHorizontalAlignment( SwingConstants.CENTER ); + gridBagLayout.columnWidths = new int[]{0, 0, 0}; + gridBagLayout.rowHeights = new int[]{0, 0, 0, 0, 0, 0}; + gridBagLayout.columnWeights = new double[]{1.0, 1.0, Double.MIN_VALUE}; + gridBagLayout.rowWeights = new double[]{0.0, 1.0, 0.0, 1.0, 0.0, Double.MIN_VALUE}; + setLayout(gridBagLayout); + + final JLabel lblTitle = new JLabel("Auto naming spots"); + lblTitle.setFont(Fonts.BIG_FONT); + lblTitle.setHorizontalAlignment(SwingConstants.CENTER); final GridBagConstraints gbcLblTitle = new GridBagConstraints(); gbcLblTitle.gridwidth = 2; - gbcLblTitle.insets = new Insets( 0, 0, 5, 0 ); + gbcLblTitle.insets = new Insets(0, 0, 5, 0); gbcLblTitle.fill = GridBagConstraints.HORIZONTAL; gbcLblTitle.gridx = 0; gbcLblTitle.gridy = 0; - add( lblTitle, gbcLblTitle ); - - final JLabel lblDoc = new JLabel( AutoNamingAction.getInfoText() ); - lblDoc.setFont( Fonts.SMALL_FONT ); - final GridBagConstraints gbcLblDoc = new GridBagConstraints(); - gbcLblDoc.gridwidth = 2; - gbcLblDoc.insets = new Insets( 0, 0, 5, 0 ); - gbcLblDoc.fill = GridBagConstraints.BOTH; - gbcLblDoc.gridx = 0; - gbcLblDoc.gridy = 1; - add( lblDoc, gbcLblDoc ); - - final JLabel lblRule = new JLabel( "Naming rule" ); - lblRule.setFont( Fonts.SMALL_FONT ); - final GridBagConstraints gbcLblRule = new GridBagConstraints(); - gbcLblRule.anchor = GridBagConstraints.EAST; - gbcLblRule.insets = new Insets( 0, 0, 5, 5 ); - gbcLblRule.gridx = 0; - gbcLblRule.gridy = 2; - add( lblRule, gbcLblRule ); - - cmbboxRule = new JComboBox<>( new Vector<>( namingRules ) ); - cmbboxRule.setFont( Fonts.SMALL_FONT ); - - final GridBagConstraints gbcCmbboxRule = new GridBagConstraints(); - gbcCmbboxRule.insets = new Insets( 0, 0, 5, 0 ); - gbcCmbboxRule.fill = GridBagConstraints.HORIZONTAL; - gbcCmbboxRule.gridx = 1; - gbcCmbboxRule.gridy = 2; - add( cmbboxRule, gbcCmbboxRule ); - - final JLabel lblRuleInfo = new JLabel(); - lblRuleInfo.setFont( Fonts.SMALL_FONT ); - final GridBagConstraints gbcLblRuleInfo = new GridBagConstraints(); - gbcLblRuleInfo.fill = GridBagConstraints.BOTH; - gbcLblRuleInfo.insets = new Insets( 0, 0, 5, 0 ); - gbcLblRuleInfo.gridwidth = 2; - gbcLblRuleInfo.gridx = 0; - gbcLblRuleInfo.gridy = 3; - add( lblRuleInfo, gbcLblRuleInfo ); - - btnRun = new JButton( "Run" ); - final GridBagConstraints gbcBtnRun = new GridBagConstraints(); - gbcBtnRun.anchor = GridBagConstraints.EAST; - gbcBtnRun.gridx = 1; - gbcBtnRun.gridy = 4; - add( btnRun, gbcBtnRun ); - - /* - * Listeners. - */ - - cmbboxRule.addActionListener( e -> lblRuleInfo.setText( ( ( AutoNamingRule ) cmbboxRule.getSelectedItem() ).getInfoText() ) ); - cmbboxRule.setSelectedIndex( 0 ); + add(lblTitle, gbcLblTitle); + + ruleSelectionDropdown = new JComboBox<>(new Vector<>(namingRules)); + ruleSelectionDropdown.setFont(Fonts.SMALL_FONT); + final GridBagConstraints gbcDropdown = new GridBagConstraints(); + gbcDropdown.insets = new Insets(0, 0, 5, 0); + gbcDropdown.fill = GridBagConstraints.HORIZONTAL; + gbcDropdown.gridx = 1; + gbcDropdown.gridy = 2; + add(ruleSelectionDropdown, gbcDropdown); + + runAutoNamingButton = new JButton("Run Auto-Naming"); + final GridBagConstraints gbcButton = new GridBagConstraints(); + gbcButton.anchor = GridBagConstraints.EAST; + gbcButton.gridx = 1; + gbcButton.gridy = 4; + add(runAutoNamingButton, gbcButton); } } From 19aefbc7661bea8d8b7571602479430a85b70e24 Mon Sep 17 00:00:00 2001 From: falgunpatel07 <71875123+falgunpatel07@users.noreply.github.com> Date: Fri, 29 Nov 2024 18:50:58 -0400 Subject: [PATCH 04/10] Implementation smell 3 Long statement --- .../autonaming/DefaultAutoNamingRule.java | 163 ++++++++++-------- 1 file changed, 89 insertions(+), 74 deletions(-) diff --git a/src/main/java/fiji/plugin/trackmate/action/autonaming/DefaultAutoNamingRule.java b/src/main/java/fiji/plugin/trackmate/action/autonaming/DefaultAutoNamingRule.java index aa401667b..19b428a48 100644 --- a/src/main/java/fiji/plugin/trackmate/action/autonaming/DefaultAutoNamingRule.java +++ b/src/main/java/fiji/plugin/trackmate/action/autonaming/DefaultAutoNamingRule.java @@ -28,8 +28,7 @@ import fiji.plugin.trackmate.Spot; import fiji.plugin.trackmate.TrackModel; -public class DefaultAutoNamingRule implements AutoNamingRule -{ +public class DefaultAutoNamingRule implements AutoNamingRule { private final String suffixSeparator; @@ -39,30 +38,28 @@ public class DefaultAutoNamingRule implements AutoNamingRule private final Pattern branchPattern; - public DefaultAutoNamingRule() - { - this( ".", "", true ); + public DefaultAutoNamingRule() { + this(".", "", true); } - public DefaultAutoNamingRule( final String suffixSeparator, final String branchSeparator, final boolean incrementSuffix ) - { + public DefaultAutoNamingRule(final String suffixSeparator, final String branchSeparator, final boolean incrementSuffix) { this.suffixSeparator = suffixSeparator; this.branchSeparator = branchSeparator; this.incrementSuffix = incrementSuffix; - this.branchPattern = Pattern.compile( "^([a-z](?:" + Pattern.quote( branchSeparator ) + "[a-z])*)$" ); + this.branchPattern = Pattern.compile("^([a-z](?:" + Pattern.quote(branchSeparator) + "[a-z])*)$"); } @Override - public void nameRoot( final Spot root, final TrackModel model ) - { - final Integer id = model.trackIDOf( root ); - final String trackName = model.name( id ); + public void nameRoot(final Spot root, final TrackModel model) { + final Integer id = model.trackIDOf(root); + final String trackName = model.name(id); - final String rootName = ( incrementSuffix ) + final String rootName = (incrementSuffix) ? trackName + suffixSeparator + "1" : trackName; - root.setName( rootName ); + root.setName(rootName); } + @Override public void nameBranches(final Spot mother, final Collection siblings) { // Sort siblings by their X position. @@ -124,76 +121,94 @@ private void addBranchNames(final String[] tokens, final List spots, final bname += 1; } } + @Override - public void nameSpot( final Spot current, final Spot predecessor ) - { - if ( incrementSuffix ) - { + public void nameSpot(final Spot current, final Spot predecessor) { + if (incrementSuffix) { final String name = predecessor.getName(); - final String[] tokens = name.split( Pattern.quote( suffixSeparator ) ); - final String idstr = tokens[ tokens.length - 1 ]; - try - { - final Integer id = Integer.valueOf( idstr ); - tokens[ tokens.length - 1 ] = Integer.toString( id + 1 ); - final String name2 = String.join( suffixSeparator, tokens ); - current.setName( name2 ); - - } - catch ( final NumberFormatException e ) - { - AutoNamingRule.super.nameSpot( current, predecessor ); + final String[] tokens = name.split(Pattern.quote(suffixSeparator)); + final String idstr = tokens[tokens.length - 1]; + try { + final Integer id = Integer.valueOf(idstr); + tokens[tokens.length - 1] = Integer.toString(id + 1); + final String name2 = String.join(suffixSeparator, tokens); + current.setName(name2); + + } catch (final NumberFormatException e) { + AutoNamingRule.super.nameSpot(current, predecessor); } - } - else - { - AutoNamingRule.super.nameSpot( current, predecessor ); + } else { + AutoNamingRule.super.nameSpot(current, predecessor); } } @Override - public String toString() - { - if ( incrementSuffix ) - return "Append 'a', 'b' for each branch and increment spot index"; - else - return "Append 'a', 'b' for each branch"; + public String getInfoText() { + final StringBuilder str = new StringBuilder(); + str.append(""); + str.append(generateDescriptionText()); + str.append("
    "); + str.append(generateRootNamingRuleText()); + str.append(generateBranchNamingRuleText()); + if (!branchSeparator.isEmpty()) { + str.append(generateBranchSeparatorRuleText()); + } + if (!suffixSeparator.isEmpty()) { + str.append(generateSuffixSeparatorRuleText()); + } + if (incrementSuffix) { + str.append(generateIncrementSuffixRuleText()); + } + str.append("
"); + str.append(generateExampleDescriptionText()); + str.append(""); + return str.toString(); } - @Override - public String getInfoText() - { - final StringBuilder str = new StringBuilder(); - str.append( "" ); - str.append( "Rename all the spots in a model giving to daughter branches a name derived " + // Helper Methods for Explaining Variables + private String generateDescriptionText() { + return "Rename all the spots in a model giving to daughter branches a name derived " + "from the mother branch. The daughter branch names are determined " - + "following simple rules based on the X position of spots:" ); - str.append( "
    " ); - str.append( "
  • The root (first spot) of a track takes the name of the track it belongs to.
  • " ); - str.append( "
  • The subsequent branches are named from the mother branch they split from. Their name " - + "is suffixed by 'a', 'b', ... depending on the relative X position of the sibbling spots " - + "just after division.
  • " ); - if ( !branchSeparator.isEmpty() ) - str.append( "
  • Each of the branch character is separated from others by the character '" + branchSeparator + "'
  • " ); - if ( !suffixSeparator.isEmpty() ) - str.append( "
  • The branch suffix ('a' ...) is separated from the root name by the character '" + suffixSeparator + "'
  • " ); - if ( incrementSuffix ) - str.append( "
  • Inside a branch, the individual spots are suffixed by a supplemental index ('1', '2', ...), " - + "indicating their order in the branch.
  • " ); - str.append( "
" ); - str.append( "

" ); - - str.append( "For instance, the 3rd spot of the branch following two divisions, first one emerging " - + "from the leftmost sibling and second one emerging from the rightmost sibbling, in " - + "the track named 'Track_23' will be named:
" ); + + "following simple rules based on the X position of spots:"; + } + + private String generateRootNamingRuleText() { + return "

  • The root (first spot) of a track takes the name of the track it belongs to.
  • "; + } + + private String generateBranchNamingRuleText() { + return "
  • The subsequent branches are named from the mother branch they split from. Their name " + + "is suffixed by 'a', 'b', ... depending on the relative X position of the sibling spots " + + "just after division.
  • "; + } + + private String generateBranchSeparatorRuleText() { + return "
  • Each of the branch character is separated from others by the character '" + + branchSeparator + "'
  • "; + } + + private String generateSuffixSeparatorRuleText() { + return "
  • The branch suffix ('a' ...) is separated from the root name by the character '" + + suffixSeparator + "'
  • "; + } + + private String generateIncrementSuffixRuleText() { + return "
  • Inside a branch, the individual spots are suffixed by a supplemental index ('1', '2', ...), " + + "indicating their order in the branch.
  • "; + } + + private String generateExampleDescriptionText() { + final StringBuilder exampleBuilder = new StringBuilder(); + exampleBuilder.append("

    "); + exampleBuilder.append("For instance, the 3rd spot of the branch following two divisions, first one emerging " + + "from the leftmost sibling and second one emerging from the rightmost sibling, in " + + "the track named 'Track_23' will be named:
    "); String example = "Track_23" + suffixSeparator + "a" + branchSeparator + "b"; - if ( incrementSuffix ) + if (incrementSuffix) { example += suffixSeparator + "3"; - str.append( "

    " + example + "
    " ); - - str.append( "The results are undefined if a track is not a tree " - + "(if it has merge points)." ); - str.append( "" ); - return str.toString(); + } + exampleBuilder.append("
    " + example + "
    "); + exampleBuilder.append("The results are undefined if a track is not a tree (if it has merge points)."); + return exampleBuilder.toString(); } -} +} \ No newline at end of file From 870fac8797433e970ab67180463b95488c4a5bd1 Mon Sep 17 00:00:00 2001 From: falgunpatel07 <71875123+falgunpatel07@users.noreply.github.com> Date: Fri, 29 Nov 2024 20:04:15 -0400 Subject: [PATCH 05/10] DesignSmell2 CyclicDependent Modularization solved by Extractmethod --- .../action/closegaps/CloseGapsController.java | 81 ++++++------------- .../action/closegaps/CloseGapsManager.java | 32 ++++++++ 2 files changed, 57 insertions(+), 56 deletions(-) create mode 100644 src/main/java/fiji/plugin/trackmate/action/closegaps/CloseGapsManager.java diff --git a/src/main/java/fiji/plugin/trackmate/action/closegaps/CloseGapsController.java b/src/main/java/fiji/plugin/trackmate/action/closegaps/CloseGapsController.java index 3d49f51fa..7d74d0bfa 100644 --- a/src/main/java/fiji/plugin/trackmate/action/closegaps/CloseGapsController.java +++ b/src/main/java/fiji/plugin/trackmate/action/closegaps/CloseGapsController.java @@ -1,24 +1,3 @@ -/*- - * #%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 - * . - * #L% - */ package fiji.plugin.trackmate.action.closegaps; import java.util.ArrayList; @@ -33,58 +12,48 @@ import fiji.plugin.trackmate.util.EverythingDisablerAndReenabler; import fiji.plugin.trackmate.util.Threads; -public class CloseGapsController -{ +public class CloseGapsController { private final TrackMate trackmate; - private final Logger logger; - private final CloseGapsPanel gui; - public CloseGapsController( final TrackMate trackmate, final Logger logger ) - { + public CloseGapsController(final TrackMate trackmate, final Logger logger) { this.trackmate = trackmate; this.logger = logger; - final Collection< GapClosingMethod > gapClosingMethods = new ArrayList<>( 2 ); - gapClosingMethods.add( new CloseGapsByLinearInterpolation() ); - gapClosingMethods.add( new CloseGapsByDetection() ); + final Collection gapClosingMethods = new ArrayList<>(2); + gapClosingMethods.add(new CloseGapsByLinearInterpolation()); + gapClosingMethods.add(new CloseGapsByDetection()); - this.gui = new CloseGapsPanel( gapClosingMethods ); - gui.btnRun.addActionListener( e -> run( ( ( GapClosingMethod ) gui.cmbboxMethod.getSelectedItem() ) ) ); + this.gui = new CloseGapsPanel(gapClosingMethods); + gui.btnRun.addActionListener(e -> run((GapClosingMethod) gui.cmbboxMethod.getSelectedItem())); } - private void run( final GapClosingMethod gapClosingMethod ) - { - final EverythingDisablerAndReenabler disabler = new EverythingDisablerAndReenabler( gui, new Class[] { JLabel.class } ); + private void run(final GapClosingMethod gapClosingMethod) { + final EverythingDisablerAndReenabler disabler = new EverythingDisablerAndReenabler(gui, new Class[]{JLabel.class}); disabler.disable(); - Threads.run( "TrackMateGapClosingThread", () -> - { - try - { - logger.log( "Applying gap-closing method: " + gapClosingMethod.toString() + ".\n" ); - logger.setStatus( "Gap-closing" ); - gapClosingMethod.execute( trackmate, logger ); - logger.log( "Gap-closing done.\n" ); - } - finally - { + Threads.run("TrackMateGapClosingThread", () -> { + try { + logger.log("INFO: Applying gap-closing method: " + gapClosingMethod.toString() + "."); + logger.setStatus("Gap-closing"); + gapClosingMethod.execute(trackmate, logger); + logger.log("INFO: Gap-closing done."); + } 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( "TrackMate gap-closing" ); - frame.setIconImage( CloseGapsAction.ICON.getImage() ); - frame.setSize( 300, 500 ); - frame.getContentPane().add( gui ); - GuiUtils.positionWindow( frame, trackmate.getSettings().imp.getCanvas() ); - frame.setVisible( true ); + final JFrame frame = new JFrame("TrackMate gap-closing"); + frame.setIconImage(CloseGapsAction.ICON.getImage()); + frame.setSize(300, 500); + frame.getContentPane().add(gui); + GuiUtils.positionWindow(frame, trackmate.getSettings().imp.getCanvas()); + frame.setVisible(true); } } diff --git a/src/main/java/fiji/plugin/trackmate/action/closegaps/CloseGapsManager.java b/src/main/java/fiji/plugin/trackmate/action/closegaps/CloseGapsManager.java new file mode 100644 index 000000000..d94cbae73 --- /dev/null +++ b/src/main/java/fiji/plugin/trackmate/action/closegaps/CloseGapsManager.java @@ -0,0 +1,32 @@ +package fiji.plugin.trackmate.action.closegaps; + +import java.util.ArrayList; +import java.util.Collection; + +import fiji.plugin.trackmate.Logger; +import fiji.plugin.trackmate.TrackMate; +import fiji.plugin.trackmate.action.closegaps.GapClosingMethod; +import fiji.plugin.trackmate.action.closegaps.CloseGapsByLinearInterpolation; +import fiji.plugin.trackmate.action.closegaps.CloseGapsByDetection; + + +public class CloseGapsManager { + + private final Collection gapClosingMethods; + + public CloseGapsManager() { + this.gapClosingMethods = new ArrayList<>(); + gapClosingMethods.add(new CloseGapsByLinearInterpolation()); + gapClosingMethods.add(new CloseGapsByDetection()); + } + + public Collection getGapClosingMethods() { + return gapClosingMethods; + } + + public void runGapClosingMethod(final GapClosingMethod gapClosingMethod, final TrackMate trackmate, final Logger logger) { + logger.log("Applying gap-closing method: " + gapClosingMethod.toString() + ".\n"); + gapClosingMethod.execute(trackmate, logger); + logger.log("Gap-closing done.\n"); + } +} From 4688553d2b24bc65839f74edd458828abfdab01f Mon Sep 17 00:00:00 2001 From: falgunpatel07 <71875123+falgunpatel07@users.noreply.github.com> Date: Fri, 29 Nov 2024 20:54:33 -0400 Subject: [PATCH 06/10] Design Smell 3 Untilized Abstraction --- .../trackmate/action/AbstractTMAction.java | 13 +-- .../action/autonaming/AutoNamingAction.java | 3 + .../autonaming/CopyTrackNameNamingRule.java | 63 ++++++++++----- .../action/closegaps/CloseGapsController.java | 81 +++++++++++++------ 4 files changed, 111 insertions(+), 49 deletions(-) diff --git a/src/main/java/fiji/plugin/trackmate/action/AbstractTMAction.java b/src/main/java/fiji/plugin/trackmate/action/AbstractTMAction.java index 495c31183..6f9c77bcc 100644 --- a/src/main/java/fiji/plugin/trackmate/action/AbstractTMAction.java +++ b/src/main/java/fiji/plugin/trackmate/action/AbstractTMAction.java @@ -1,12 +1,19 @@ package fiji.plugin.trackmate.action; + import fiji.plugin.trackmate.Logger; + public abstract class AbstractTMAction implements TrackMateAction { + protected Logger logger = Logger.VOID_LOGGER; + + // Changed to static since they are metadata constants. private static final String INFO_TEXT = "" + "Rename individual spots based on auto-naming rules. " + "All spot names are changed. There is no undo."; private static final String NAME = "Spot auto-naming"; private static final String KEY = "AUTO_NAMING"; + + // Static getter methods for metadata constants. public static String getInfoText() { return INFO_TEXT; } @@ -24,9 +31,3 @@ public void setLogger(final Logger logger) { this.logger = logger; } } - - - - - - diff --git a/src/main/java/fiji/plugin/trackmate/action/autonaming/AutoNamingAction.java b/src/main/java/fiji/plugin/trackmate/action/autonaming/AutoNamingAction.java index d642376c5..3c27e0277 100644 --- a/src/main/java/fiji/plugin/trackmate/action/autonaming/AutoNamingAction.java +++ b/src/main/java/fiji/plugin/trackmate/action/autonaming/AutoNamingAction.java @@ -30,16 +30,19 @@ public TrackMateAction create() { @Override public String getInfoText() { + // Static method from AbstractTMAction. return AbstractTMAction.getInfoText(); } @Override public String getName() { + // Static method from AbstractTMAction. return AbstractTMAction.getName(); } @Override public String getKey() { + // Static method from AbstractTMAction. return AbstractTMAction.getKey(); } diff --git a/src/main/java/fiji/plugin/trackmate/action/autonaming/CopyTrackNameNamingRule.java b/src/main/java/fiji/plugin/trackmate/action/autonaming/CopyTrackNameNamingRule.java index a9e127de5..cccfe996c 100644 --- a/src/main/java/fiji/plugin/trackmate/action/autonaming/CopyTrackNameNamingRule.java +++ b/src/main/java/fiji/plugin/trackmate/action/autonaming/CopyTrackNameNamingRule.java @@ -8,12 +8,12 @@ * 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 * . @@ -26,35 +26,62 @@ import fiji.plugin.trackmate.Spot; import fiji.plugin.trackmate.TrackModel; -public class CopyTrackNameNamingRule implements AutoNamingRule -{ +public class CopyTrackNameNamingRule implements AutoNamingRule { - private static final String INFO_TEXT = "All the spots receive the name of the track they belong to."; + // Encapsulation of info text as a private constant + private static final String INFO_TEXT = + "All the spots receive the name of the track they belong to."; + /** + * Assigns the track name to the root spot. + * + * @param root the root spot of the track + * @param model the TrackModel containing track information + */ @Override - public void nameRoot( final Spot root, final TrackModel model ) - { - final Integer id = model.trackIDOf( root ); - final String trackName = model.name( id ); - root.setName( trackName ); + public void nameRoot(final Spot root, final TrackModel model) { + final Integer trackId = model.trackIDOf(root); + if (trackId != null) { + final String trackName = model.name(trackId); + root.setName(trackName); + } else { + root.setName("Unnamed Track"); + } } + /** + * Assigns the mother's name to all sibling spots. + * + * @param mother the parent spot + * @param siblings the collection of sibling spots + */ @Override - public void nameBranches( final Spot mother, final Collection< Spot > siblings ) - { - for ( final Spot spot : siblings ) - spot.setName( mother.getName() ); + public void nameBranches(final Spot mother, final Collection siblings) { + if (mother != null && siblings != null) { + final String motherName = mother.getName(); + for (final Spot sibling : siblings) { + sibling.setName(motherName); + } + } } + /** + * Provides an informational description of the naming rule. + * + * @return a string describing the naming rule + */ @Override - public String getInfoText() - { + public String getInfoText() { return INFO_TEXT; } + /** + * Provides a string representation of the naming rule. + * + * @return a short name of the naming rule + */ @Override - public String toString() - { + public String toString() { return "Copy track name"; } } diff --git a/src/main/java/fiji/plugin/trackmate/action/closegaps/CloseGapsController.java b/src/main/java/fiji/plugin/trackmate/action/closegaps/CloseGapsController.java index 7d74d0bfa..ccc66ce69 100644 --- a/src/main/java/fiji/plugin/trackmate/action/closegaps/CloseGapsController.java +++ b/src/main/java/fiji/plugin/trackmate/action/closegaps/CloseGapsController.java @@ -1,3 +1,24 @@ +/*- + * #%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 + * . + * #L% + */ package fiji.plugin.trackmate.action.closegaps; import java.util.ArrayList; @@ -12,48 +33,58 @@ import fiji.plugin.trackmate.util.EverythingDisablerAndReenabler; import fiji.plugin.trackmate.util.Threads; -public class CloseGapsController { +public class CloseGapsController +{ private final TrackMate trackmate; + private final Logger logger; + private final CloseGapsPanel gui; - public CloseGapsController(final TrackMate trackmate, final Logger logger) { + public CloseGapsController( final TrackMate trackmate, final Logger logger ) + { this.trackmate = trackmate; this.logger = logger; - final Collection gapClosingMethods = new ArrayList<>(2); - gapClosingMethods.add(new CloseGapsByLinearInterpolation()); - gapClosingMethods.add(new CloseGapsByDetection()); + final Collection< GapClosingMethod > gapClosingMethods = new ArrayList<>( 2 ); + gapClosingMethods.add( new CloseGapsByLinearInterpolation() ); + gapClosingMethods.add( new CloseGapsByDetection() ); - this.gui = new CloseGapsPanel(gapClosingMethods); - gui.btnRun.addActionListener(e -> run((GapClosingMethod) gui.cmbboxMethod.getSelectedItem())); + this.gui = new CloseGapsPanel( gapClosingMethods ); + gui.btnRun.addActionListener( e -> run( ( ( GapClosingMethod ) gui.cmbboxMethod.getSelectedItem() ) ) ); } - private void run(final GapClosingMethod gapClosingMethod) { - final EverythingDisablerAndReenabler disabler = new EverythingDisablerAndReenabler(gui, new Class[]{JLabel.class}); + private void run( final GapClosingMethod gapClosingMethod ) + { + final EverythingDisablerAndReenabler disabler = new EverythingDisablerAndReenabler( gui, new Class[] { JLabel.class } ); disabler.disable(); - Threads.run("TrackMateGapClosingThread", () -> { - try { - logger.log("INFO: Applying gap-closing method: " + gapClosingMethod.toString() + "."); - logger.setStatus("Gap-closing"); - gapClosingMethod.execute(trackmate, logger); - logger.log("INFO: Gap-closing done."); - } finally { + Threads.run( "TrackMateGapClosingThread", () -> + { + try + { + logger.log( "Applying gap-closing method: " + gapClosingMethod.toString() + ".\n" ); + logger.setStatus( "Gap-closing" ); + gapClosingMethod.execute( trackmate, logger ); + logger.log( "Gap-closing 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("TrackMate gap-closing"); - frame.setIconImage(CloseGapsAction.ICON.getImage()); - frame.setSize(300, 500); - frame.getContentPane().add(gui); - GuiUtils.positionWindow(frame, trackmate.getSettings().imp.getCanvas()); - frame.setVisible(true); + final JFrame frame = new JFrame( "TrackMate gap-closing" ); + frame.setIconImage( CloseGapsAction.ICON.getImage() ); + frame.setSize( 300, 500 ); + frame.getContentPane().add( gui ); + GuiUtils.positionWindow( frame, trackmate.getSettings().imp.getCanvas() ); + frame.setVisible( true ); } } From 1364251e41bf2632aea634788c552fb549b103f8 Mon Sep 17 00:00:00 2001 From: falgunpatel07 <71875123+falgunpatel07@users.noreply.github.com> Date: Fri, 29 Nov 2024 21:08:49 -0400 Subject: [PATCH 07/10] Revert "Design Smell 3 Untilized Abstraction" This reverts commit 4688553d2b24bc65839f74edd458828abfdab01f. --- .../trackmate/action/AbstractTMAction.java | 13 ++- .../action/autonaming/AutoNamingAction.java | 3 - .../autonaming/CopyTrackNameNamingRule.java | 63 +++++---------- .../action/closegaps/CloseGapsController.java | 81 ++++++------------- 4 files changed, 49 insertions(+), 111 deletions(-) diff --git a/src/main/java/fiji/plugin/trackmate/action/AbstractTMAction.java b/src/main/java/fiji/plugin/trackmate/action/AbstractTMAction.java index 6f9c77bcc..495c31183 100644 --- a/src/main/java/fiji/plugin/trackmate/action/AbstractTMAction.java +++ b/src/main/java/fiji/plugin/trackmate/action/AbstractTMAction.java @@ -1,19 +1,12 @@ package fiji.plugin.trackmate.action; - import fiji.plugin.trackmate.Logger; - public abstract class AbstractTMAction implements TrackMateAction { - protected Logger logger = Logger.VOID_LOGGER; - - // Changed to static since they are metadata constants. private static final String INFO_TEXT = "" + "Rename individual spots based on auto-naming rules. " + "All spot names are changed. There is no undo."; private static final String NAME = "Spot auto-naming"; private static final String KEY = "AUTO_NAMING"; - - // Static getter methods for metadata constants. public static String getInfoText() { return INFO_TEXT; } @@ -31,3 +24,9 @@ public void setLogger(final Logger logger) { this.logger = logger; } } + + + + + + diff --git a/src/main/java/fiji/plugin/trackmate/action/autonaming/AutoNamingAction.java b/src/main/java/fiji/plugin/trackmate/action/autonaming/AutoNamingAction.java index 3c27e0277..d642376c5 100644 --- a/src/main/java/fiji/plugin/trackmate/action/autonaming/AutoNamingAction.java +++ b/src/main/java/fiji/plugin/trackmate/action/autonaming/AutoNamingAction.java @@ -30,19 +30,16 @@ public TrackMateAction create() { @Override public String getInfoText() { - // Static method from AbstractTMAction. return AbstractTMAction.getInfoText(); } @Override public String getName() { - // Static method from AbstractTMAction. return AbstractTMAction.getName(); } @Override public String getKey() { - // Static method from AbstractTMAction. return AbstractTMAction.getKey(); } diff --git a/src/main/java/fiji/plugin/trackmate/action/autonaming/CopyTrackNameNamingRule.java b/src/main/java/fiji/plugin/trackmate/action/autonaming/CopyTrackNameNamingRule.java index cccfe996c..a9e127de5 100644 --- a/src/main/java/fiji/plugin/trackmate/action/autonaming/CopyTrackNameNamingRule.java +++ b/src/main/java/fiji/plugin/trackmate/action/autonaming/CopyTrackNameNamingRule.java @@ -8,12 +8,12 @@ * 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 * . @@ -26,62 +26,35 @@ import fiji.plugin.trackmate.Spot; import fiji.plugin.trackmate.TrackModel; -public class CopyTrackNameNamingRule implements AutoNamingRule { +public class CopyTrackNameNamingRule implements AutoNamingRule +{ - // Encapsulation of info text as a private constant - private static final String INFO_TEXT = - "All the spots receive the name of the track they belong to."; + private static final String INFO_TEXT = "All the spots receive the name of the track they belong to."; - /** - * Assigns the track name to the root spot. - * - * @param root the root spot of the track - * @param model the TrackModel containing track information - */ @Override - public void nameRoot(final Spot root, final TrackModel model) { - final Integer trackId = model.trackIDOf(root); - if (trackId != null) { - final String trackName = model.name(trackId); - root.setName(trackName); - } else { - root.setName("Unnamed Track"); - } + public void nameRoot( final Spot root, final TrackModel model ) + { + final Integer id = model.trackIDOf( root ); + final String trackName = model.name( id ); + root.setName( trackName ); } - /** - * Assigns the mother's name to all sibling spots. - * - * @param mother the parent spot - * @param siblings the collection of sibling spots - */ @Override - public void nameBranches(final Spot mother, final Collection siblings) { - if (mother != null && siblings != null) { - final String motherName = mother.getName(); - for (final Spot sibling : siblings) { - sibling.setName(motherName); - } - } + public void nameBranches( final Spot mother, final Collection< Spot > siblings ) + { + for ( final Spot spot : siblings ) + spot.setName( mother.getName() ); } - /** - * Provides an informational description of the naming rule. - * - * @return a string describing the naming rule - */ @Override - public String getInfoText() { + public String getInfoText() + { return INFO_TEXT; } - /** - * Provides a string representation of the naming rule. - * - * @return a short name of the naming rule - */ @Override - public String toString() { + public String toString() + { return "Copy track name"; } } diff --git a/src/main/java/fiji/plugin/trackmate/action/closegaps/CloseGapsController.java b/src/main/java/fiji/plugin/trackmate/action/closegaps/CloseGapsController.java index ccc66ce69..7d74d0bfa 100644 --- a/src/main/java/fiji/plugin/trackmate/action/closegaps/CloseGapsController.java +++ b/src/main/java/fiji/plugin/trackmate/action/closegaps/CloseGapsController.java @@ -1,24 +1,3 @@ -/*- - * #%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 - * . - * #L% - */ package fiji.plugin.trackmate.action.closegaps; import java.util.ArrayList; @@ -33,58 +12,48 @@ import fiji.plugin.trackmate.util.EverythingDisablerAndReenabler; import fiji.plugin.trackmate.util.Threads; -public class CloseGapsController -{ +public class CloseGapsController { private final TrackMate trackmate; - private final Logger logger; - private final CloseGapsPanel gui; - public CloseGapsController( final TrackMate trackmate, final Logger logger ) - { + public CloseGapsController(final TrackMate trackmate, final Logger logger) { this.trackmate = trackmate; this.logger = logger; - final Collection< GapClosingMethod > gapClosingMethods = new ArrayList<>( 2 ); - gapClosingMethods.add( new CloseGapsByLinearInterpolation() ); - gapClosingMethods.add( new CloseGapsByDetection() ); + final Collection gapClosingMethods = new ArrayList<>(2); + gapClosingMethods.add(new CloseGapsByLinearInterpolation()); + gapClosingMethods.add(new CloseGapsByDetection()); - this.gui = new CloseGapsPanel( gapClosingMethods ); - gui.btnRun.addActionListener( e -> run( ( ( GapClosingMethod ) gui.cmbboxMethod.getSelectedItem() ) ) ); + this.gui = new CloseGapsPanel(gapClosingMethods); + gui.btnRun.addActionListener(e -> run((GapClosingMethod) gui.cmbboxMethod.getSelectedItem())); } - private void run( final GapClosingMethod gapClosingMethod ) - { - final EverythingDisablerAndReenabler disabler = new EverythingDisablerAndReenabler( gui, new Class[] { JLabel.class } ); + private void run(final GapClosingMethod gapClosingMethod) { + final EverythingDisablerAndReenabler disabler = new EverythingDisablerAndReenabler(gui, new Class[]{JLabel.class}); disabler.disable(); - Threads.run( "TrackMateGapClosingThread", () -> - { - try - { - logger.log( "Applying gap-closing method: " + gapClosingMethod.toString() + ".\n" ); - logger.setStatus( "Gap-closing" ); - gapClosingMethod.execute( trackmate, logger ); - logger.log( "Gap-closing done.\n" ); - } - finally - { + Threads.run("TrackMateGapClosingThread", () -> { + try { + logger.log("INFO: Applying gap-closing method: " + gapClosingMethod.toString() + "."); + logger.setStatus("Gap-closing"); + gapClosingMethod.execute(trackmate, logger); + logger.log("INFO: Gap-closing done."); + } 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( "TrackMate gap-closing" ); - frame.setIconImage( CloseGapsAction.ICON.getImage() ); - frame.setSize( 300, 500 ); - frame.getContentPane().add( gui ); - GuiUtils.positionWindow( frame, trackmate.getSettings().imp.getCanvas() ); - frame.setVisible( true ); + final JFrame frame = new JFrame("TrackMate gap-closing"); + frame.setIconImage(CloseGapsAction.ICON.getImage()); + frame.setSize(300, 500); + frame.getContentPane().add(gui); + GuiUtils.positionWindow(frame, trackmate.getSettings().imp.getCanvas()); + frame.setVisible(true); } } From 50e5ead9cd0c20894b35f21e7379277d64f569fe Mon Sep 17 00:00:00 2001 From: falgunpatel07 <71875123+falgunpatel07@users.noreply.github.com> Date: Fri, 29 Nov 2024 21:39:46 -0400 Subject: [PATCH 08/10] design smell 3 Broken Modularization --- .../autonaming/DefaultAutoNamingRule.java | 163 ++++++++---------- .../action/closegaps/CloseGapsAction.java | 71 ++++---- 2 files changed, 105 insertions(+), 129 deletions(-) diff --git a/src/main/java/fiji/plugin/trackmate/action/autonaming/DefaultAutoNamingRule.java b/src/main/java/fiji/plugin/trackmate/action/autonaming/DefaultAutoNamingRule.java index 19b428a48..aa401667b 100644 --- a/src/main/java/fiji/plugin/trackmate/action/autonaming/DefaultAutoNamingRule.java +++ b/src/main/java/fiji/plugin/trackmate/action/autonaming/DefaultAutoNamingRule.java @@ -28,7 +28,8 @@ import fiji.plugin.trackmate.Spot; import fiji.plugin.trackmate.TrackModel; -public class DefaultAutoNamingRule implements AutoNamingRule { +public class DefaultAutoNamingRule implements AutoNamingRule +{ private final String suffixSeparator; @@ -38,28 +39,30 @@ public class DefaultAutoNamingRule implements AutoNamingRule { private final Pattern branchPattern; - public DefaultAutoNamingRule() { - this(".", "", true); + public DefaultAutoNamingRule() + { + this( ".", "", true ); } - public DefaultAutoNamingRule(final String suffixSeparator, final String branchSeparator, final boolean incrementSuffix) { + public DefaultAutoNamingRule( final String suffixSeparator, final String branchSeparator, final boolean incrementSuffix ) + { this.suffixSeparator = suffixSeparator; this.branchSeparator = branchSeparator; this.incrementSuffix = incrementSuffix; - this.branchPattern = Pattern.compile("^([a-z](?:" + Pattern.quote(branchSeparator) + "[a-z])*)$"); + this.branchPattern = Pattern.compile( "^([a-z](?:" + Pattern.quote( branchSeparator ) + "[a-z])*)$" ); } @Override - public void nameRoot(final Spot root, final TrackModel model) { - final Integer id = model.trackIDOf(root); - final String trackName = model.name(id); + public void nameRoot( final Spot root, final TrackModel model ) + { + final Integer id = model.trackIDOf( root ); + final String trackName = model.name( id ); - final String rootName = (incrementSuffix) + final String rootName = ( incrementSuffix ) ? trackName + suffixSeparator + "1" : trackName; - root.setName(rootName); + root.setName( rootName ); } - @Override public void nameBranches(final Spot mother, final Collection siblings) { // Sort siblings by their X position. @@ -121,94 +124,76 @@ private void addBranchNames(final String[] tokens, final List spots, final bname += 1; } } - @Override - public void nameSpot(final Spot current, final Spot predecessor) { - if (incrementSuffix) { + public void nameSpot( final Spot current, final Spot predecessor ) + { + if ( incrementSuffix ) + { final String name = predecessor.getName(); - final String[] tokens = name.split(Pattern.quote(suffixSeparator)); - final String idstr = tokens[tokens.length - 1]; - try { - final Integer id = Integer.valueOf(idstr); - tokens[tokens.length - 1] = Integer.toString(id + 1); - final String name2 = String.join(suffixSeparator, tokens); - current.setName(name2); - - } catch (final NumberFormatException e) { - AutoNamingRule.super.nameSpot(current, predecessor); + final String[] tokens = name.split( Pattern.quote( suffixSeparator ) ); + final String idstr = tokens[ tokens.length - 1 ]; + try + { + final Integer id = Integer.valueOf( idstr ); + tokens[ tokens.length - 1 ] = Integer.toString( id + 1 ); + final String name2 = String.join( suffixSeparator, tokens ); + current.setName( name2 ); + + } + catch ( final NumberFormatException e ) + { + AutoNamingRule.super.nameSpot( current, predecessor ); } - } else { - AutoNamingRule.super.nameSpot(current, predecessor); + } + else + { + AutoNamingRule.super.nameSpot( current, predecessor ); } } @Override - public String getInfoText() { - final StringBuilder str = new StringBuilder(); - str.append(""); - str.append(generateDescriptionText()); - str.append("
      "); - str.append(generateRootNamingRuleText()); - str.append(generateBranchNamingRuleText()); - if (!branchSeparator.isEmpty()) { - str.append(generateBranchSeparatorRuleText()); - } - if (!suffixSeparator.isEmpty()) { - str.append(generateSuffixSeparatorRuleText()); - } - if (incrementSuffix) { - str.append(generateIncrementSuffixRuleText()); - } - str.append("
    "); - str.append(generateExampleDescriptionText()); - str.append(""); - return str.toString(); + public String toString() + { + if ( incrementSuffix ) + return "Append 'a', 'b' for each branch and increment spot index"; + else + return "Append 'a', 'b' for each branch"; } - // Helper Methods for Explaining Variables - private String generateDescriptionText() { - return "Rename all the spots in a model giving to daughter branches a name derived " + @Override + public String getInfoText() + { + final StringBuilder str = new StringBuilder(); + str.append( "" ); + str.append( "Rename all the spots in a model giving to daughter branches a name derived " + "from the mother branch. The daughter branch names are determined " - + "following simple rules based on the X position of spots:"; - } - - private String generateRootNamingRuleText() { - return "
  • The root (first spot) of a track takes the name of the track it belongs to.
  • "; - } - - private String generateBranchNamingRuleText() { - return "
  • The subsequent branches are named from the mother branch they split from. Their name " - + "is suffixed by 'a', 'b', ... depending on the relative X position of the sibling spots " - + "just after division.
  • "; - } - - private String generateBranchSeparatorRuleText() { - return "
  • Each of the branch character is separated from others by the character '" - + branchSeparator + "'
  • "; - } - - private String generateSuffixSeparatorRuleText() { - return "
  • The branch suffix ('a' ...) is separated from the root name by the character '" - + suffixSeparator + "'
  • "; - } - - private String generateIncrementSuffixRuleText() { - return "
  • Inside a branch, the individual spots are suffixed by a supplemental index ('1', '2', ...), " - + "indicating their order in the branch.
  • "; - } - - private String generateExampleDescriptionText() { - final StringBuilder exampleBuilder = new StringBuilder(); - exampleBuilder.append("

    "); - exampleBuilder.append("For instance, the 3rd spot of the branch following two divisions, first one emerging " - + "from the leftmost sibling and second one emerging from the rightmost sibling, in " - + "the track named 'Track_23' will be named:
    "); + + "following simple rules based on the X position of spots:" ); + str.append( "

      " ); + str.append( "
    • The root (first spot) of a track takes the name of the track it belongs to.
    • " ); + str.append( "
    • The subsequent branches are named from the mother branch they split from. Their name " + + "is suffixed by 'a', 'b', ... depending on the relative X position of the sibbling spots " + + "just after division.
    • " ); + if ( !branchSeparator.isEmpty() ) + str.append( "
    • Each of the branch character is separated from others by the character '" + branchSeparator + "'
    • " ); + if ( !suffixSeparator.isEmpty() ) + str.append( "
    • The branch suffix ('a' ...) is separated from the root name by the character '" + suffixSeparator + "'
    • " ); + if ( incrementSuffix ) + str.append( "
    • Inside a branch, the individual spots are suffixed by a supplemental index ('1', '2', ...), " + + "indicating their order in the branch.
    • " ); + str.append( "
    " ); + str.append( "

    " ); + + str.append( "For instance, the 3rd spot of the branch following two divisions, first one emerging " + + "from the leftmost sibling and second one emerging from the rightmost sibbling, in " + + "the track named 'Track_23' will be named:
    " ); String example = "Track_23" + suffixSeparator + "a" + branchSeparator + "b"; - if (incrementSuffix) { + if ( incrementSuffix ) example += suffixSeparator + "3"; - } - exampleBuilder.append("

    " + example + "
    "); - exampleBuilder.append("The results are undefined if a track is not a tree (if it has merge points)."); - return exampleBuilder.toString(); + str.append( "
    " + example + "
    " ); + + str.append( "The results are undefined if a track is not a tree " + + "(if it has merge points)." ); + str.append( "" ); + return str.toString(); } -} \ No newline at end of file +} diff --git a/src/main/java/fiji/plugin/trackmate/action/closegaps/CloseGapsAction.java b/src/main/java/fiji/plugin/trackmate/action/closegaps/CloseGapsAction.java index 094a044e7..5fd3b3b93 100644 --- a/src/main/java/fiji/plugin/trackmate/action/closegaps/CloseGapsAction.java +++ b/src/main/java/fiji/plugin/trackmate/action/closegaps/CloseGapsAction.java @@ -8,12 +8,12 @@ * 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 * . @@ -32,70 +32,61 @@ 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; -public class CloseGapsAction extends AbstractTMAction -{ +public class CloseGapsAction extends AbstractTMAction { - public static final String NAME = "Close gaps by introducing new spots"; + @Override + public void execute(final TrackMate trackmate, final SelectionModel selectionModel, final DisplaySettings displaySettings, final Frame parent) { + final CloseGapsController controller = new CloseGapsController(trackmate, logger); + controller.show(); + } - public static final String KEY = "CLOSE_GAPS"; + @Plugin(type = TrackMateActionFactory.class) + public static class Factory implements TrackMateActionFactory { - public static final String INFO_TEXT = "" - + "This action proposes several methods to close gaps in tracks." - + "

    " - + "Gaps are part of tracks where spots are missing in one or " - + "several consecutive frames. The listed methods can " - + "introduce new spots in such gaps, depending on possibly " - + "the other spots in tracks and/or the image data." - + "

    " - + "They are useful to fix missed detection when a uninterrupted " - + "list of position is required for track analysis. For instance " - + "in FRAP experiments, where you need to measure signal intensity " - + "changing during time, even if the spot is not visible." - + ""; + private static final String NAME = "Close gaps by introducing new spots"; - public static final ImageIcon ICON = Icons.ORANGE_ASTERISK_ICON; + private static final String KEY = "CLOSE_GAPS"; - @Override - public void execute( final TrackMate trackmate, final SelectionModel selectionModel, final DisplaySettings displaySettings, final Frame parent ) - { - final CloseGapsController controller = new CloseGapsController( trackmate, logger ); - controller.show(); - } + private static final String INFO_TEXT = "" + + "This action proposes several methods to close gaps in tracks." + + "

    " + + "Gaps are part of tracks where spots are missing in one or " + + "several consecutive frames. The listed methods can " + + "introduce new spots in such gaps, depending on possibly " + + "the other spots in tracks and/or the image data." + + "

    " + + "They are useful to fix missed detection when a uninterrupted " + + "list of position is required for track analysis. For instance " + + "in FRAP experiments, where you need to measure signal intensity " + + "changing during time, even if the spot is not visible." + + ""; - @Plugin( type = TrackMateActionFactory.class ) - public static class Factory implements TrackMateActionFactory - { + private static final ImageIcon ICON = fiji.plugin.trackmate.gui.Icons.ORANGE_ASTERISK_ICON; @Override - public String getInfoText() - { + public String getInfoText() { return INFO_TEXT; } @Override - public String getKey() - { + public String getKey() { return KEY; } @Override - public TrackMateAction create() - { + public TrackMateAction create() { return new CloseGapsAction(); } @Override - public ImageIcon getIcon() - { + public ImageIcon getIcon() { return ICON; } @Override - public String getName() - { + public String getName() { return NAME; } } From fb1b7860477c35d9e7232104babc62012d1becb8 Mon Sep 17 00:00:00 2001 From: falgunpatel07 <71875123+falgunpatel07@users.noreply.github.com> Date: Fri, 29 Nov 2024 21:41:30 -0400 Subject: [PATCH 09/10] Revert "design smell 3 Broken Modularization" This reverts commit 50e5ead9cd0c20894b35f21e7379277d64f569fe. --- .../autonaming/DefaultAutoNamingRule.java | 163 ++++++++++-------- .../action/closegaps/CloseGapsAction.java | 71 ++++---- 2 files changed, 129 insertions(+), 105 deletions(-) diff --git a/src/main/java/fiji/plugin/trackmate/action/autonaming/DefaultAutoNamingRule.java b/src/main/java/fiji/plugin/trackmate/action/autonaming/DefaultAutoNamingRule.java index aa401667b..19b428a48 100644 --- a/src/main/java/fiji/plugin/trackmate/action/autonaming/DefaultAutoNamingRule.java +++ b/src/main/java/fiji/plugin/trackmate/action/autonaming/DefaultAutoNamingRule.java @@ -28,8 +28,7 @@ import fiji.plugin.trackmate.Spot; import fiji.plugin.trackmate.TrackModel; -public class DefaultAutoNamingRule implements AutoNamingRule -{ +public class DefaultAutoNamingRule implements AutoNamingRule { private final String suffixSeparator; @@ -39,30 +38,28 @@ public class DefaultAutoNamingRule implements AutoNamingRule private final Pattern branchPattern; - public DefaultAutoNamingRule() - { - this( ".", "", true ); + public DefaultAutoNamingRule() { + this(".", "", true); } - public DefaultAutoNamingRule( final String suffixSeparator, final String branchSeparator, final boolean incrementSuffix ) - { + public DefaultAutoNamingRule(final String suffixSeparator, final String branchSeparator, final boolean incrementSuffix) { this.suffixSeparator = suffixSeparator; this.branchSeparator = branchSeparator; this.incrementSuffix = incrementSuffix; - this.branchPattern = Pattern.compile( "^([a-z](?:" + Pattern.quote( branchSeparator ) + "[a-z])*)$" ); + this.branchPattern = Pattern.compile("^([a-z](?:" + Pattern.quote(branchSeparator) + "[a-z])*)$"); } @Override - public void nameRoot( final Spot root, final TrackModel model ) - { - final Integer id = model.trackIDOf( root ); - final String trackName = model.name( id ); + public void nameRoot(final Spot root, final TrackModel model) { + final Integer id = model.trackIDOf(root); + final String trackName = model.name(id); - final String rootName = ( incrementSuffix ) + final String rootName = (incrementSuffix) ? trackName + suffixSeparator + "1" : trackName; - root.setName( rootName ); + root.setName(rootName); } + @Override public void nameBranches(final Spot mother, final Collection siblings) { // Sort siblings by their X position. @@ -124,76 +121,94 @@ private void addBranchNames(final String[] tokens, final List spots, final bname += 1; } } + @Override - public void nameSpot( final Spot current, final Spot predecessor ) - { - if ( incrementSuffix ) - { + public void nameSpot(final Spot current, final Spot predecessor) { + if (incrementSuffix) { final String name = predecessor.getName(); - final String[] tokens = name.split( Pattern.quote( suffixSeparator ) ); - final String idstr = tokens[ tokens.length - 1 ]; - try - { - final Integer id = Integer.valueOf( idstr ); - tokens[ tokens.length - 1 ] = Integer.toString( id + 1 ); - final String name2 = String.join( suffixSeparator, tokens ); - current.setName( name2 ); - - } - catch ( final NumberFormatException e ) - { - AutoNamingRule.super.nameSpot( current, predecessor ); + final String[] tokens = name.split(Pattern.quote(suffixSeparator)); + final String idstr = tokens[tokens.length - 1]; + try { + final Integer id = Integer.valueOf(idstr); + tokens[tokens.length - 1] = Integer.toString(id + 1); + final String name2 = String.join(suffixSeparator, tokens); + current.setName(name2); + + } catch (final NumberFormatException e) { + AutoNamingRule.super.nameSpot(current, predecessor); } - } - else - { - AutoNamingRule.super.nameSpot( current, predecessor ); + } else { + AutoNamingRule.super.nameSpot(current, predecessor); } } @Override - public String toString() - { - if ( incrementSuffix ) - return "Append 'a', 'b' for each branch and increment spot index"; - else - return "Append 'a', 'b' for each branch"; + public String getInfoText() { + final StringBuilder str = new StringBuilder(); + str.append(""); + str.append(generateDescriptionText()); + str.append("

      "); + str.append(generateRootNamingRuleText()); + str.append(generateBranchNamingRuleText()); + if (!branchSeparator.isEmpty()) { + str.append(generateBranchSeparatorRuleText()); + } + if (!suffixSeparator.isEmpty()) { + str.append(generateSuffixSeparatorRuleText()); + } + if (incrementSuffix) { + str.append(generateIncrementSuffixRuleText()); + } + str.append("
    "); + str.append(generateExampleDescriptionText()); + str.append(""); + return str.toString(); } - @Override - public String getInfoText() - { - final StringBuilder str = new StringBuilder(); - str.append( "" ); - str.append( "Rename all the spots in a model giving to daughter branches a name derived " + // Helper Methods for Explaining Variables + private String generateDescriptionText() { + return "Rename all the spots in a model giving to daughter branches a name derived " + "from the mother branch. The daughter branch names are determined " - + "following simple rules based on the X position of spots:" ); - str.append( "
      " ); - str.append( "
    • The root (first spot) of a track takes the name of the track it belongs to.
    • " ); - str.append( "
    • The subsequent branches are named from the mother branch they split from. Their name " - + "is suffixed by 'a', 'b', ... depending on the relative X position of the sibbling spots " - + "just after division.
    • " ); - if ( !branchSeparator.isEmpty() ) - str.append( "
    • Each of the branch character is separated from others by the character '" + branchSeparator + "'
    • " ); - if ( !suffixSeparator.isEmpty() ) - str.append( "
    • The branch suffix ('a' ...) is separated from the root name by the character '" + suffixSeparator + "'
    • " ); - if ( incrementSuffix ) - str.append( "
    • Inside a branch, the individual spots are suffixed by a supplemental index ('1', '2', ...), " - + "indicating their order in the branch.
    • " ); - str.append( "
    " ); - str.append( "

    " ); - - str.append( "For instance, the 3rd spot of the branch following two divisions, first one emerging " - + "from the leftmost sibling and second one emerging from the rightmost sibbling, in " - + "the track named 'Track_23' will be named:
    " ); + + "following simple rules based on the X position of spots:"; + } + + private String generateRootNamingRuleText() { + return "

  • The root (first spot) of a track takes the name of the track it belongs to.
  • "; + } + + private String generateBranchNamingRuleText() { + return "
  • The subsequent branches are named from the mother branch they split from. Their name " + + "is suffixed by 'a', 'b', ... depending on the relative X position of the sibling spots " + + "just after division.
  • "; + } + + private String generateBranchSeparatorRuleText() { + return "
  • Each of the branch character is separated from others by the character '" + + branchSeparator + "'
  • "; + } + + private String generateSuffixSeparatorRuleText() { + return "
  • The branch suffix ('a' ...) is separated from the root name by the character '" + + suffixSeparator + "'
  • "; + } + + private String generateIncrementSuffixRuleText() { + return "
  • Inside a branch, the individual spots are suffixed by a supplemental index ('1', '2', ...), " + + "indicating their order in the branch.
  • "; + } + + private String generateExampleDescriptionText() { + final StringBuilder exampleBuilder = new StringBuilder(); + exampleBuilder.append("

    "); + exampleBuilder.append("For instance, the 3rd spot of the branch following two divisions, first one emerging " + + "from the leftmost sibling and second one emerging from the rightmost sibling, in " + + "the track named 'Track_23' will be named:
    "); String example = "Track_23" + suffixSeparator + "a" + branchSeparator + "b"; - if ( incrementSuffix ) + if (incrementSuffix) { example += suffixSeparator + "3"; - str.append( "

    " + example + "
    " ); - - str.append( "The results are undefined if a track is not a tree " - + "(if it has merge points)." ); - str.append( "" ); - return str.toString(); + } + exampleBuilder.append("
    " + example + "
    "); + exampleBuilder.append("The results are undefined if a track is not a tree (if it has merge points)."); + return exampleBuilder.toString(); } -} +} \ No newline at end of file diff --git a/src/main/java/fiji/plugin/trackmate/action/closegaps/CloseGapsAction.java b/src/main/java/fiji/plugin/trackmate/action/closegaps/CloseGapsAction.java index 5fd3b3b93..094a044e7 100644 --- a/src/main/java/fiji/plugin/trackmate/action/closegaps/CloseGapsAction.java +++ b/src/main/java/fiji/plugin/trackmate/action/closegaps/CloseGapsAction.java @@ -8,12 +8,12 @@ * 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 * . @@ -32,61 +32,70 @@ 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; -public class CloseGapsAction extends AbstractTMAction { +public class CloseGapsAction extends AbstractTMAction +{ - @Override - public void execute(final TrackMate trackmate, final SelectionModel selectionModel, final DisplaySettings displaySettings, final Frame parent) { - final CloseGapsController controller = new CloseGapsController(trackmate, logger); - controller.show(); - } + public static final String NAME = "Close gaps by introducing new spots"; - @Plugin(type = TrackMateActionFactory.class) - public static class Factory implements TrackMateActionFactory { + public static final String KEY = "CLOSE_GAPS"; - private static final String NAME = "Close gaps by introducing new spots"; + public static final String INFO_TEXT = "" + + "This action proposes several methods to close gaps in tracks." + + "

    " + + "Gaps are part of tracks where spots are missing in one or " + + "several consecutive frames. The listed methods can " + + "introduce new spots in such gaps, depending on possibly " + + "the other spots in tracks and/or the image data." + + "

    " + + "They are useful to fix missed detection when a uninterrupted " + + "list of position is required for track analysis. For instance " + + "in FRAP experiments, where you need to measure signal intensity " + + "changing during time, even if the spot is not visible." + + ""; - private static final String KEY = "CLOSE_GAPS"; + public static final ImageIcon ICON = Icons.ORANGE_ASTERISK_ICON; - private static final String INFO_TEXT = "" - + "This action proposes several methods to close gaps in tracks." - + "

    " - + "Gaps are part of tracks where spots are missing in one or " - + "several consecutive frames. The listed methods can " - + "introduce new spots in such gaps, depending on possibly " - + "the other spots in tracks and/or the image data." - + "

    " - + "They are useful to fix missed detection when a uninterrupted " - + "list of position is required for track analysis. For instance " - + "in FRAP experiments, where you need to measure signal intensity " - + "changing during time, even if the spot is not visible." - + ""; + @Override + public void execute( final TrackMate trackmate, final SelectionModel selectionModel, final DisplaySettings displaySettings, final Frame parent ) + { + final CloseGapsController controller = new CloseGapsController( trackmate, logger ); + controller.show(); + } - private static final ImageIcon ICON = fiji.plugin.trackmate.gui.Icons.ORANGE_ASTERISK_ICON; + @Plugin( type = TrackMateActionFactory.class ) + public static class Factory implements TrackMateActionFactory + { @Override - public String getInfoText() { + public String getInfoText() + { return INFO_TEXT; } @Override - public String getKey() { + public String getKey() + { return KEY; } @Override - public TrackMateAction create() { + public TrackMateAction create() + { return new CloseGapsAction(); } @Override - public ImageIcon getIcon() { + public ImageIcon getIcon() + { return ICON; } @Override - public String getName() { + public String getName() + { return NAME; } } From 8b048269e457ebf05e42055a4033a01746f0afe9 Mon Sep 17 00:00:00 2001 From: falgunpatel07 <71875123+falgunpatel07@users.noreply.github.com> Date: Fri, 29 Nov 2024 21:50:40 -0400 Subject: [PATCH 10/10] designsmell3 brokenmodularization --- .../action/closegaps/CloseGapsAction.java | 71 ++++----- .../action/closegaps/CloseGapsController.java | 3 +- .../action/closegaps/CloseGapsPanel.java | 140 +++++++----------- 3 files changed, 90 insertions(+), 124 deletions(-) diff --git a/src/main/java/fiji/plugin/trackmate/action/closegaps/CloseGapsAction.java b/src/main/java/fiji/plugin/trackmate/action/closegaps/CloseGapsAction.java index 094a044e7..5fd3b3b93 100644 --- a/src/main/java/fiji/plugin/trackmate/action/closegaps/CloseGapsAction.java +++ b/src/main/java/fiji/plugin/trackmate/action/closegaps/CloseGapsAction.java @@ -8,12 +8,12 @@ * 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 * . @@ -32,70 +32,61 @@ 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; -public class CloseGapsAction extends AbstractTMAction -{ +public class CloseGapsAction extends AbstractTMAction { - public static final String NAME = "Close gaps by introducing new spots"; + @Override + public void execute(final TrackMate trackmate, final SelectionModel selectionModel, final DisplaySettings displaySettings, final Frame parent) { + final CloseGapsController controller = new CloseGapsController(trackmate, logger); + controller.show(); + } - public static final String KEY = "CLOSE_GAPS"; + @Plugin(type = TrackMateActionFactory.class) + public static class Factory implements TrackMateActionFactory { - public static final String INFO_TEXT = "" - + "This action proposes several methods to close gaps in tracks." - + "

    " - + "Gaps are part of tracks where spots are missing in one or " - + "several consecutive frames. The listed methods can " - + "introduce new spots in such gaps, depending on possibly " - + "the other spots in tracks and/or the image data." - + "

    " - + "They are useful to fix missed detection when a uninterrupted " - + "list of position is required for track analysis. For instance " - + "in FRAP experiments, where you need to measure signal intensity " - + "changing during time, even if the spot is not visible." - + ""; + private static final String NAME = "Close gaps by introducing new spots"; - public static final ImageIcon ICON = Icons.ORANGE_ASTERISK_ICON; + private static final String KEY = "CLOSE_GAPS"; - @Override - public void execute( final TrackMate trackmate, final SelectionModel selectionModel, final DisplaySettings displaySettings, final Frame parent ) - { - final CloseGapsController controller = new CloseGapsController( trackmate, logger ); - controller.show(); - } + private static final String INFO_TEXT = "" + + "This action proposes several methods to close gaps in tracks." + + "

    " + + "Gaps are part of tracks where spots are missing in one or " + + "several consecutive frames. The listed methods can " + + "introduce new spots in such gaps, depending on possibly " + + "the other spots in tracks and/or the image data." + + "

    " + + "They are useful to fix missed detection when a uninterrupted " + + "list of position is required for track analysis. For instance " + + "in FRAP experiments, where you need to measure signal intensity " + + "changing during time, even if the spot is not visible." + + ""; - @Plugin( type = TrackMateActionFactory.class ) - public static class Factory implements TrackMateActionFactory - { + private static final ImageIcon ICON = fiji.plugin.trackmate.gui.Icons.ORANGE_ASTERISK_ICON; @Override - public String getInfoText() - { + public String getInfoText() { return INFO_TEXT; } @Override - public String getKey() - { + public String getKey() { return KEY; } @Override - public TrackMateAction create() - { + public TrackMateAction create() { return new CloseGapsAction(); } @Override - public ImageIcon getIcon() - { + public ImageIcon getIcon() { return ICON; } @Override - public String getName() - { + public String getName() { return NAME; } } diff --git a/src/main/java/fiji/plugin/trackmate/action/closegaps/CloseGapsController.java b/src/main/java/fiji/plugin/trackmate/action/closegaps/CloseGapsController.java index 7d74d0bfa..01361883d 100644 --- a/src/main/java/fiji/plugin/trackmate/action/closegaps/CloseGapsController.java +++ b/src/main/java/fiji/plugin/trackmate/action/closegaps/CloseGapsController.java @@ -50,7 +50,8 @@ public void show() { return; final JFrame frame = new JFrame("TrackMate gap-closing"); - frame.setIconImage(CloseGapsAction.ICON.getImage()); + // Access the ICON through the Factory class + frame.setIconImage(new CloseGapsAction.Factory().getIcon().getImage()); frame.setSize(300, 500); frame.getContentPane().add(gui); GuiUtils.positionWindow(frame, trackmate.getSettings().imp.getCanvas()); diff --git a/src/main/java/fiji/plugin/trackmate/action/closegaps/CloseGapsPanel.java b/src/main/java/fiji/plugin/trackmate/action/closegaps/CloseGapsPanel.java index 7ad32586c..6baf7fbe6 100644 --- a/src/main/java/fiji/plugin/trackmate/action/closegaps/CloseGapsPanel.java +++ b/src/main/java/fiji/plugin/trackmate/action/closegaps/CloseGapsPanel.java @@ -1,24 +1,3 @@ -/*- - * #%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 - * . - * #L% - */ package fiji.plugin.trackmate.action.closegaps; import java.awt.BorderLayout; @@ -39,6 +18,7 @@ import javax.swing.SwingConstants; import javax.swing.border.EmptyBorder; +import fiji.plugin.trackmate.action.AbstractTMAction; import fiji.plugin.trackmate.action.closegaps.GapClosingMethod.GapClosingParameter; import fiji.plugin.trackmate.gui.Fonts; import fiji.plugin.trackmate.gui.displaysettings.SliderPanelDouble; @@ -48,167 +28,161 @@ /** * A basic UI to let a TrackMate user choose between several techniques for gap * closing. - * + * * @author Jean-Yves Tinevez * */ -public class CloseGapsPanel extends JPanel -{ +public class CloseGapsPanel extends JPanel { private static final long serialVersionUID = 1L; - final JComboBox< GapClosingMethod > cmbboxMethod; + final JComboBox cmbboxMethod; final JButton btnRun; - public CloseGapsPanel( final Collection< GapClosingMethod > gapClosingMethods ) - { + public CloseGapsPanel(final Collection gapClosingMethods) { /* * Prepare config panel for individual methods. */ - final Map< GapClosingMethod, JPanel > configPanels = new HashMap<>(); - for ( final GapClosingMethod gcm : gapClosingMethods ) - { - final List< GapClosingParameter > params = gcm.getParameters(); + final Map configPanels = new HashMap<>(); + for (final GapClosingMethod gcm : gapClosingMethods) { + final List params = gcm.getParameters(); final JPanel paramPanel = new JPanel(); final GridBagLayout layout = new GridBagLayout(); - paramPanel.setLayout( layout ); + paramPanel.setLayout(layout); final GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 0.; c.gridwidth = 1; c.gridx = 0; c.gridy = 0; - c.insets = new Insets( 2, 5, 2, 5 ); - for ( final GapClosingParameter p : params ) - { + c.insets = new Insets(2, 5, 2, 5); + for (final GapClosingParameter p : params) { c.gridwidth = 1; c.anchor = GridBagConstraints.LINE_END; - final JLabel lblParamName = new JLabel( p.name ); - lblParamName.setFont( Fonts.SMALL_FONT ); - paramPanel.add( lblParamName, c ); + final JLabel lblParamName = new JLabel(p.name); + lblParamName.setFont(Fonts.SMALL_FONT); + paramPanel.add(lblParamName, c); - final BoundedDoubleElement el = new BoundedDoubleElement( p.name, p.minValue, p.maxValue ) - { + final BoundedDoubleElement el = new BoundedDoubleElement(p.name, p.minValue, p.maxValue) { @Override - public double get() - { + public double get() { return p.value; } @Override - public void set( final double v ) - { + public void set(final double v) { p.value = v; } }; - final SliderPanelDouble slider = StyleElements.linkedSliderPanel( el, 4 ); - slider.setDecimalFormat( "0.00" ); - for ( final Component cmp : slider.getComponents() ) - cmp.setFont( Fonts.SMALL_FONT ); + final SliderPanelDouble slider = StyleElements.linkedSliderPanel(el, 4); + slider.setDecimalFormat("0.00"); + for (final Component cmp : slider.getComponents()) + cmp.setFont(Fonts.SMALL_FONT); c.gridx++; c.weightx = 1.; c.anchor = GridBagConstraints.LINE_START; - paramPanel.add( slider, c ); + paramPanel.add(slider, c); c.gridx = 0; c.weightx = 0.; c.gridy++; } - configPanels.put( gcm, paramPanel ); + configPanels.put(gcm, paramPanel); } /* * The main GUI. */ - setBorder( new EmptyBorder( 5, 5, 5, 5 ) ); + setBorder(new EmptyBorder(5, 5, 5, 5)); final GridBagLayout gridBagLayout = new GridBagLayout(); gridBagLayout.columnWidths = new int[] { 0, 0, 0 }; gridBagLayout.rowHeights = new int[] { 0, 0, 0, 0, 0, 0, 0 }; gridBagLayout.columnWeights = new double[] { 1.0, 1.0, Double.MIN_VALUE }; gridBagLayout.rowWeights = new double[] { 0.0, 0.0, 0.0, 1.0, 1.0, 0.0, Double.MIN_VALUE }; - setLayout( gridBagLayout ); + setLayout(gridBagLayout); - final JLabel lblTitle = new JLabel( "Close gap" ); - lblTitle.setFont( Fonts.BIG_FONT ); - lblTitle.setHorizontalAlignment( SwingConstants.CENTER ); + final JLabel lblTitle = new JLabel("Close gap"); + lblTitle.setFont(Fonts.BIG_FONT); + lblTitle.setHorizontalAlignment(SwingConstants.CENTER); final GridBagConstraints gbcLblTitle = new GridBagConstraints(); gbcLblTitle.gridwidth = 2; - gbcLblTitle.insets = new Insets( 0, 0, 5, 0 ); + gbcLblTitle.insets = new Insets(0, 0, 5, 0); gbcLblTitle.fill = GridBagConstraints.BOTH; gbcLblTitle.gridx = 0; gbcLblTitle.gridy = 0; - add( lblTitle, gbcLblTitle ); + add(lblTitle, gbcLblTitle); - final JLabel lblDoc = new JLabel( CloseGapsAction.INFO_TEXT ); - lblDoc.setFont( Fonts.SMALL_FONT ); + // Updated line to use getInfoText() method + final JLabel lblDoc = new JLabel(new CloseGapsAction.Factory().getInfoText()); + lblDoc.setFont(Fonts.SMALL_FONT); final GridBagConstraints gbcLblDoc = new GridBagConstraints(); gbcLblDoc.fill = GridBagConstraints.BOTH; - gbcLblDoc.insets = new Insets( 0, 0, 5, 0 ); + gbcLblDoc.insets = new Insets(0, 0, 5, 0); gbcLblDoc.gridwidth = 2; gbcLblDoc.gridx = 0; gbcLblDoc.gridy = 1; - add( lblDoc, gbcLblDoc ); + add(lblDoc, gbcLblDoc); - final JLabel lblMethod = new JLabel( "Gap-closing method" ); - lblMethod.setFont( Fonts.SMALL_FONT ); + final JLabel lblMethod = new JLabel("Gap-closing method"); + lblMethod.setFont(Fonts.SMALL_FONT); final GridBagConstraints gbcLblMethod = new GridBagConstraints(); gbcLblMethod.anchor = GridBagConstraints.EAST; - gbcLblMethod.insets = new Insets( 0, 0, 5, 5 ); + gbcLblMethod.insets = new Insets(0, 0, 5, 5); gbcLblMethod.gridx = 0; gbcLblMethod.gridy = 2; - add( lblMethod, gbcLblMethod ); + add(lblMethod, gbcLblMethod); - this.cmbboxMethod = new JComboBox<>( new Vector<>( gapClosingMethods ) ); - cmbboxMethod.setFont( Fonts.SMALL_FONT ); + this.cmbboxMethod = new JComboBox<>(new Vector<>(gapClosingMethods)); + cmbboxMethod.setFont(Fonts.SMALL_FONT); final GridBagConstraints gbcCmbboxMethod = new GridBagConstraints(); - gbcCmbboxMethod.insets = new Insets( 0, 0, 5, 0 ); + gbcCmbboxMethod.insets = new Insets(0, 0, 5, 0); gbcCmbboxMethod.fill = GridBagConstraints.HORIZONTAL; gbcCmbboxMethod.gridx = 1; gbcCmbboxMethod.gridy = 2; - add( cmbboxMethod, gbcCmbboxMethod ); + add(cmbboxMethod, gbcCmbboxMethod); final JPanel panelParams = new JPanel(); final GridBagConstraints gbcPanelParams = new GridBagConstraints(); gbcPanelParams.gridwidth = 2; - gbcPanelParams.insets = new Insets( 0, 0, 5, 5 ); + gbcPanelParams.insets = new Insets(0, 0, 5, 5); gbcPanelParams.fill = GridBagConstraints.BOTH; gbcPanelParams.gridx = 0; gbcPanelParams.gridy = 3; - add( panelParams, gbcPanelParams ); - panelParams.setLayout( new BorderLayout( 0, 0 ) ); + add(panelParams, gbcPanelParams); + panelParams.setLayout(new BorderLayout(0, 0)); final JLabel lblMethodDoc = new JLabel(); - lblMethodDoc.setFont( Fonts.SMALL_FONT ); + lblMethodDoc.setFont(Fonts.SMALL_FONT); final GridBagConstraints gbcLblMethodDoc = new GridBagConstraints(); gbcLblMethodDoc.fill = GridBagConstraints.BOTH; - gbcLblMethodDoc.insets = new Insets( 0, 0, 5, 0 ); + gbcLblMethodDoc.insets = new Insets(0, 0, 5, 0); gbcLblMethodDoc.gridwidth = 2; gbcLblMethodDoc.gridx = 0; gbcLblMethodDoc.gridy = 4; - add( lblMethodDoc, gbcLblMethodDoc ); + add(lblMethodDoc, gbcLblMethodDoc); - this.btnRun = new JButton( "Run" ); + this.btnRun = new JButton("Run"); final GridBagConstraints gbcBtnRun = new GridBagConstraints(); gbcBtnRun.anchor = GridBagConstraints.EAST; gbcBtnRun.gridx = 1; gbcBtnRun.gridy = 5; - add( btnRun, gbcBtnRun ); + add(btnRun, gbcBtnRun); /* * Listeners. */ - cmbboxMethod.addActionListener( e -> { + cmbboxMethod.addActionListener(e -> { panelParams.removeAll(); - final GapClosingMethod gcm = ( GapClosingMethod ) cmbboxMethod.getSelectedItem(); - panelParams.add( configPanels.get( gcm ), BorderLayout.CENTER ); - lblMethodDoc.setText( gcm.getInfoText() ); - } ); - cmbboxMethod.setSelectedIndex( 0 ); + final GapClosingMethod gcm = (GapClosingMethod) cmbboxMethod.getSelectedItem(); + panelParams.add(configPanels.get(gcm), BorderLayout.CENTER); + lblMethodDoc.setText(gcm.getInfoText()); + }); + cmbboxMethod.setSelectedIndex(0); } }