diff --git a/src/main/java/fiji/plugin/trackmate/action/AbstractTMAction.java b/src/main/java/fiji/plugin/trackmate/action/AbstractTMAction.java index 3769a878a..495c31183 100644 --- a/src/main/java/fiji/plugin/trackmate/action/AbstractTMAction.java +++ b/src/main/java/fiji/plugin/trackmate/action/AbstractTMAction.java @@ -1,36 +1,32 @@ -/*- - * #%L - * TrackMate: your buddy for everyday tracking. - * %% - * Copyright (C) 2010 - 2024 TrackMate developers. - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * . - * #L% - */ package fiji.plugin.trackmate.action; - import fiji.plugin.trackmate.Logger; +public abstract class AbstractTMAction implements TrackMateAction { + protected Logger logger = Logger.VOID_LOGGER; + private static final String INFO_TEXT = "" + + "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 abstract class AbstractTMAction implements TrackMateAction -{ + public static String getName() { + return NAME; + } - protected Logger logger = Logger.VOID_LOGGER; + public static String getKey() { + return KEY; + } @Override - public void setLogger( final Logger logger ) - { + public void setLogger(final Logger logger) { this.logger = logger; } } + + + + + + 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/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 b69187731..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,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.autonaming; import java.awt.GridBagConstraints; @@ -26,7 +5,6 @@ import java.awt.Insets; import java.util.Collection; import java.util.Vector; - import javax.swing.BorderFactory; import javax.swing.JButton; import javax.swing.JComboBox; @@ -36,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.INFO_TEXT ); - 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); } } 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..19b428a48 100644 --- a/src/main/java/fiji/plugin/trackmate/action/autonaming/DefaultAutoNamingRule.java +++ b/src/main/java/fiji/plugin/trackmate/action/autonaming/DefaultAutoNamingRule.java @@ -21,18 +21,14 @@ */ 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; import fiji.plugin.trackmate.Spot; import fiji.plugin.trackmate.TrackModel; -public class DefaultAutoNamingRule implements AutoNamingRule -{ +public class DefaultAutoNamingRule implements AutoNamingRule { private final String suffixSeparator; @@ -42,188 +38,177 @@ 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< 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 + 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. } - final String branchName = String.join( suffixSeparator, newTokens ); - spot.setName( branchName ); + spot.setName(String.join(suffixSeparator, newTokens)); 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 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 3d49f51fa..01361883d 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,49 @@ 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"); + // 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()); + 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"); + } +} 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); } }