Skip to content

Commit 143918f

Browse files
committed
Adapt to the new TrackMate API.
1 parent 2edf702 commit 143918f

3 files changed

Lines changed: 24 additions & 124 deletions

File tree

src/main/java/fiji/plugin/trackmate/morpholibj/MorphoLibJDetectorConfigurationPanel.java

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
* it under the terms of the GNU General Public License as
99
* published by the Free Software Foundation, either version 3 of the
1010
* License, or (at your option) any later version.
11-
*
11+
*
1212
* This program is distributed in the hope that it will be useful,
1313
* but WITHOUT ANY WARRANTY; without even the implied warranty of
1414
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1515
* GNU General Public License for more details.
16-
*
16+
*
1717
* You should have received a copy of the GNU General Public
1818
* License along with this program. If not, see
1919
* <http://www.gnu.org/licenses/gpl-3.0.html>.
@@ -25,6 +25,7 @@
2525
import static fiji.plugin.trackmate.detection.ThresholdDetectorFactory.KEY_SIMPLIFY_CONTOURS;
2626
import static fiji.plugin.trackmate.gui.Fonts.BIG_FONT;
2727
import static fiji.plugin.trackmate.gui.Fonts.SMALL_FONT;
28+
import static fiji.plugin.trackmate.morpholibj.MorphoLibJDetectorFactory.ICON;
2829
import static fiji.plugin.trackmate.morpholibj.MorphoLibJDetectorFactory.KEY_CONNECTIVITY;
2930
import static fiji.plugin.trackmate.morpholibj.MorphoLibJDetectorFactory.KEY_TOLERANCE;
3031

@@ -33,15 +34,13 @@
3334
import java.awt.GridBagConstraints;
3435
import java.awt.GridBagLayout;
3536
import java.awt.Insets;
36-
import java.net.URL;
3737
import java.text.DecimalFormat;
3838
import java.text.NumberFormat;
3939
import java.util.Arrays;
4040
import java.util.HashMap;
4141
import java.util.Map;
4242
import java.util.Vector;
4343

44-
import javax.swing.ImageIcon;
4544
import javax.swing.JCheckBox;
4645
import javax.swing.JComboBox;
4746
import javax.swing.JFormattedTextField;
@@ -64,8 +63,6 @@ public class MorphoLibJDetectorConfigurationPanel extends ConfigurationPanel
6463

6564
private static final NumberFormat THRESHOLD_FORMAT = new DecimalFormat( "#.##" );
6665

67-
protected static final ImageIcon ICON = new ImageIcon( getResource( "images/TrackMateMorphoLibJ-logo-100px.png" ) );
68-
6966
private static final String TITLE = MorphoLibJDetectorFactory.NAME;
7067

7168
private final JSlider sliderChannel;
@@ -80,9 +77,8 @@ public MorphoLibJDetectorConfigurationPanel( final Settings settings, final Mode
8077
{
8178
final GridBagLayout gridBagLayout = new GridBagLayout();
8279
gridBagLayout.columnWidths = new int[] { 144, 0, 32 };
83-
gridBagLayout.rowHeights = new int[] { 0, 84, 0, 27, 0, 0, 0 };
80+
gridBagLayout.rowHeights = new int[] { 0, 84, 0, 27, 0, 0, 150 };
8481
gridBagLayout.columnWeights = new double[] { 0.0, 1.0, 0.0 };
85-
gridBagLayout.rowWeights = new double[] { 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
8682
setLayout( gridBagLayout );
8783

8884
final JLabel lblDetector = new JLabel( TITLE, ICON, JLabel.RIGHT );
@@ -107,7 +103,14 @@ public MorphoLibJDetectorConfigurationPanel( final Settings settings, final Mode
107103
gbcLblHelptext.insets = new Insets( 5, 5, 5, 5 );
108104
gbcLblHelptext.gridx = 0;
109105
gbcLblHelptext.gridy = 1;
110-
add( GuiUtils.textInScrollPanel( GuiUtils.infoDisplay( MorphoLibJDetectorFactory.INFO_TEXT ) ), gbcLblHelptext );
106+
gbcLblHelptext.weighty = 1.;
107+
add( GuiUtils.textInScrollPanel( GuiUtils.infoDisplay(
108+
MorphoLibJDetectorFactory.INFO_TEXT.replace( "</html>", "" )
109+
+ "<html>Online documentation: <br/>"
110+
+ "<a href='" + MorphoLibJDetectorFactory.DOC_URL + "'>"
111+
+ MorphoLibJDetectorFactory.DOC_URL
112+
+ "</a></html>" ) ),
113+
gbcLblHelptext );
111114

112115
/*
113116
* Channel selector.
@@ -301,9 +304,4 @@ public void setSettings( final Map< String, Object > settings )
301304
@Override
302305
public void clean()
303306
{}
304-
305-
protected static URL getResource( final String name )
306-
{
307-
return MorphoLibJDetectorFactory.class.getClassLoader().getResource( name );
308-
}
309307
}

src/main/java/fiji/plugin/trackmate/morpholibj/MorphoLibJDetectorFactory.java

Lines changed: 12 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
* it under the terms of the GNU General Public License as
99
* published by the Free Software Foundation, either version 3 of the
1010
* License, or (at your option) any later version.
11-
*
11+
*
1212
* This program is distributed in the hope that it will be useful,
1313
* but WITHOUT ANY WARRANTY; without even the implied warranty of
1414
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1515
* GNU General Public License for more details.
16-
*
16+
*
1717
* You should have received a copy of the GNU General Public
1818
* License along with this program. If not, see
1919
* <http://www.gnu.org/licenses/gpl-3.0.html>.
@@ -24,29 +24,20 @@
2424
import static fiji.plugin.trackmate.detection.DetectorKeys.DEFAULT_TARGET_CHANNEL;
2525
import static fiji.plugin.trackmate.detection.DetectorKeys.KEY_TARGET_CHANNEL;
2626
import static fiji.plugin.trackmate.detection.ThresholdDetectorFactory.KEY_SIMPLIFY_CONTOURS;
27-
import static fiji.plugin.trackmate.io.IOUtils.readBooleanAttribute;
28-
import static fiji.plugin.trackmate.io.IOUtils.readDoubleAttribute;
29-
import static fiji.plugin.trackmate.io.IOUtils.readIntegerAttribute;
30-
import static fiji.plugin.trackmate.io.IOUtils.writeAttribute;
31-
import static fiji.plugin.trackmate.io.IOUtils.writeTargetChannel;
32-
import static fiji.plugin.trackmate.util.TMUtils.checkMapKeys;
33-
import static fiji.plugin.trackmate.util.TMUtils.checkParameter;
3427

35-
import java.util.ArrayList;
3628
import java.util.HashMap;
37-
import java.util.List;
3829
import java.util.Map;
3930

4031
import javax.swing.ImageIcon;
4132

42-
import org.jdom2.Element;
4333
import org.scijava.Priority;
4434
import org.scijava.plugin.Plugin;
4535

4636
import fiji.plugin.trackmate.Model;
4737
import fiji.plugin.trackmate.Settings;
4838
import fiji.plugin.trackmate.detection.SpotDetector;
4939
import fiji.plugin.trackmate.detection.SpotDetectorFactory;
40+
import fiji.plugin.trackmate.gui.GuiUtils;
5041
import fiji.plugin.trackmate.gui.components.ConfigurationPanel;
5142
import fiji.plugin.trackmate.util.TMUtils;
5243
import net.imagej.ImgPlus;
@@ -57,11 +48,6 @@
5748
@Plugin( type = SpotDetectorFactory.class, priority = Priority.LOW - 5. )
5849
public class MorphoLibJDetectorFactory< T extends RealType< T > & NativeType< T > > implements SpotDetectorFactory< T >
5950
{
60-
61-
/*
62-
* CONSTANTS
63-
*/
64-
6551
/**
6652
* The key to the parameter that stores the tolerance value to use in
6753
* morphological segmentation. Accepted values are doubles.
@@ -99,29 +85,14 @@ public class MorphoLibJDetectorFactory< T extends RealType< T > & NativeType< T
9985
+ "also cite the MorphoLibJ paper: <a href=\"https://doi.org/10.1093/bioinformatics/btw413\">Legland, D.; Arganda-Carreras, I. & Andrey, P. (2016), "
10086
+ "'MorphoLibJ: integrated library and plugins for mathematical morphology with ImageJ', "
10187
+ "Bioinformatics (Oxford Univ Press) 32(22): 3532-3534.</a> "
102-
+ "<p>"
103-
+ "Documentation for this module "
104-
+ "<a href=\"https://imagej.net/plugins/trackmate/trackmate-morpholibj\">on the ImageJ Wiki</a>."
105-
+ "<p>"
10688
+ "</html>";
10789

108-
/*
109-
* FIELDS
110-
*/
111-
112-
/** The image to operate on. Multiple frames, single channel. */
113-
protected ImgPlus< T > img;
114-
115-
protected Map< String, Object > settings;
90+
public static final String DOC_URL = "https://imagej.net/plugins/trackmate/trackmate-morpholibj";
11691

117-
protected String errorMessage;
118-
119-
/*
120-
* METHODS
121-
*/
92+
public static final ImageIcon ICON = new ImageIcon( GuiUtils.getResource( "images/TrackMateMorphoLibJ-logo-64px.png", MorphoLibJDetectorFactory.class ) );
12293

12394
@Override
124-
public SpotDetector< T > getDetector( final Interval interval, final int frame )
95+
public SpotDetector< T > getDetector( final ImgPlus< T > img, final Map< String, Object > settings, final Interval interval, final int frame )
12596
{
12697
final int channel = ( Integer ) settings.get( KEY_TARGET_CHANNEL ) - 1;
12798
final ImgPlus< T > input = TMUtils.hyperSlice( img, channel, frame );
@@ -138,54 +109,6 @@ public SpotDetector< T > getDetector( final Interval interval, final int frame )
138109
return detector;
139110
}
140111

141-
@Override
142-
public boolean setTarget( final ImgPlus< T > img, final Map< String, Object > settings )
143-
{
144-
this.img = img;
145-
this.settings = settings;
146-
return checkSettings( settings );
147-
}
148-
149-
@Override
150-
public String getErrorMessage()
151-
{
152-
return errorMessage;
153-
}
154-
155-
@Override
156-
public boolean marshall( final Map< String, Object > settings, final Element element )
157-
{
158-
final StringBuilder errorHolder = new StringBuilder();
159-
boolean ok = writeTargetChannel( settings, element, errorHolder );
160-
ok = ok && writeAttribute( settings, element, KEY_TOLERANCE, Double.class, errorHolder );
161-
ok = ok && writeAttribute( settings, element, KEY_CONNECTIVITY, Integer.class, errorHolder );
162-
ok = ok && writeAttribute( settings, element, KEY_SIMPLIFY_CONTOURS, Boolean.class, errorHolder );
163-
164-
if ( !ok )
165-
errorMessage = errorHolder.toString();
166-
167-
return ok;
168-
}
169-
170-
@Override
171-
public boolean unmarshall( final Element element, final Map< String, Object > settings )
172-
{
173-
settings.clear();
174-
final StringBuilder errorHolder = new StringBuilder();
175-
boolean ok = true;
176-
ok = ok && readIntegerAttribute( element, settings, KEY_TARGET_CHANNEL, errorHolder );
177-
ok = ok && readDoubleAttribute( element, settings, KEY_TOLERANCE, errorHolder );
178-
ok = ok && readIntegerAttribute( element, settings, KEY_CONNECTIVITY, errorHolder );
179-
ok = ok && readBooleanAttribute( element, settings, KEY_SIMPLIFY_CONTOURS, errorHolder );
180-
181-
if ( !ok )
182-
{
183-
errorMessage = errorHolder.toString();
184-
return false;
185-
}
186-
return checkSettings( settings );
187-
}
188-
189112
@Override
190113
public ConfigurationPanel getDetectorConfigurationPanel( final Settings settings, final Model model )
191114
{
@@ -204,36 +127,21 @@ public Map< String, Object > getDefaultSettings()
204127
}
205128

206129
@Override
207-
public boolean checkSettings( final Map< String, Object > settings )
130+
public String getInfoText()
208131
{
209-
boolean ok = true;
210-
final StringBuilder errorHolder = new StringBuilder();
211-
ok = ok & checkParameter( settings, KEY_TARGET_CHANNEL, Integer.class, errorHolder );
212-
ok = ok & checkParameter( settings, KEY_TOLERANCE, Double.class, errorHolder );
213-
ok = ok & checkParameter( settings, KEY_CONNECTIVITY, Integer.class, errorHolder );
214-
ok = ok & checkParameter( settings, KEY_SIMPLIFY_CONTOURS, Boolean.class, errorHolder );
215-
final List< String > mandatoryKeys = new ArrayList<>();
216-
mandatoryKeys.add( KEY_TARGET_CHANNEL );
217-
mandatoryKeys.add( KEY_TOLERANCE );
218-
mandatoryKeys.add( KEY_CONNECTIVITY );
219-
mandatoryKeys.add( KEY_SIMPLIFY_CONTOURS );
220-
ok = ok & checkMapKeys( settings, mandatoryKeys, null, errorHolder );
221-
if ( !ok )
222-
errorMessage = errorHolder.toString();
223-
224-
return ok;
132+
return INFO_TEXT;
225133
}
226134

227135
@Override
228-
public String getInfoText()
136+
public ImageIcon getIcon()
229137
{
230-
return INFO_TEXT;
138+
return ICON;
231139
}
232140

233141
@Override
234-
public ImageIcon getIcon()
142+
public String getUrl()
235143
{
236-
return null;
144+
return DOC_URL;
237145
}
238146

239147
@Override
@@ -253,10 +161,4 @@ public boolean has2Dsegmentation()
253161
{
254162
return true;
255163
}
256-
257-
@Override
258-
public MorphoLibJDetectorFactory< T > copy()
259-
{
260-
return new MorphoLibJDetectorFactory<>();
261-
}
262164
}
7.09 KB
Loading

0 commit comments

Comments
 (0)