From d870211b1c6bfba7ce1768f1aec18e885c9c0a99 Mon Sep 17 00:00:00 2001 From: Jean-Yves TINEVEZ Date: Wed, 1 May 2024 18:08:27 +0200 Subject: [PATCH] A utility widget to specify a threshold on a probability value. --- .../gui/components/PanelProbaThreshold.java | 88 +++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 src/main/java/fiji/plugin/trackmate/gui/components/PanelProbaThreshold.java diff --git a/src/main/java/fiji/plugin/trackmate/gui/components/PanelProbaThreshold.java b/src/main/java/fiji/plugin/trackmate/gui/components/PanelProbaThreshold.java new file mode 100644 index 000000000..bf0212b17 --- /dev/null +++ b/src/main/java/fiji/plugin/trackmate/gui/components/PanelProbaThreshold.java @@ -0,0 +1,88 @@ +/*- + * #%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.gui.components; + +import static fiji.plugin.trackmate.gui.Fonts.SMALL_FONT; + +import java.util.function.Consumer; +import java.util.function.DoubleSupplier; + +import javax.swing.Box; +import javax.swing.BoxLayout; +import javax.swing.JLabel; +import javax.swing.JPanel; + +import fiji.plugin.trackmate.gui.displaysettings.SliderPanelDouble; +import fiji.plugin.trackmate.gui.displaysettings.StyleElements; +import fiji.plugin.trackmate.gui.displaysettings.StyleElements.BoundedDoubleElement; + +/** + * A utility widget that lets a user specify a threshold on a probability value, + * from 0 to 1. + */ +public class PanelProbaThreshold extends JPanel +{ + + private static final long serialVersionUID = 1L; + + private double threshold; + + private final SliderPanelDouble sliderPanel; + + private final BoundedDoubleElement thresholdEl; + + public PanelProbaThreshold( final double threshold ) + { + this.threshold = threshold; + setLayout( new BoxLayout( this, BoxLayout.X_AXIS ) ); + + final JLabel chckbxSmooth = new JLabel( "Proba threshold" ); + chckbxSmooth.setFont( SMALL_FONT ); + add( chckbxSmooth ); + add( Box.createHorizontalGlue() ); + + final DoubleSupplier getter = () -> getThreshold(); + final Consumer< Double > setter = v -> setThresholdPrivate( v ); + thresholdEl = StyleElements.boundedDoubleElement( "threshold", 0., 1., getter, setter ); + sliderPanel = StyleElements.linkedSliderPanel( thresholdEl, 3, 0.1 ); + sliderPanel.setFont( SMALL_FONT ); + + add( sliderPanel ); + } + + private void setThresholdPrivate( final double threshold ) + { + this.threshold = threshold; + } + + public void setThreshold( final double threshold ) + { + setThresholdPrivate( threshold ); + thresholdEl.getValue().setCurrentValue( threshold ); + sliderPanel.update(); + } + + public double getThreshold() + { + return threshold; + } +}