diff --git a/gdsc-smlm-ij/src/main/java/uk/ac/sussex/gdsc/smlm/ij/gui/ListSelectionModelHelper.java b/gdsc-smlm-ij/src/main/java/uk/ac/sussex/gdsc/smlm/ij/gui/ListSelectionModelHelper.java index 6b3b174a9..5796e8559 100644 --- a/gdsc-smlm-ij/src/main/java/uk/ac/sussex/gdsc/smlm/ij/gui/ListSelectionModelHelper.java +++ b/gdsc-smlm-ij/src/main/java/uk/ac/sussex/gdsc/smlm/ij/gui/ListSelectionModelHelper.java @@ -72,6 +72,21 @@ public static int[] getSelectedIndices(ListSelectionModel sm) { * @param indices the indices */ public static void setSelectedIndices(ListSelectionModel sm, int[] indices) { + setSelectedIndices(sm, indices, false); + } + + /** + * Sets the selected indices. + * + *

To continue with further adjustments set the {@code adjusting} flag to true. To propagate + * the selection change event the value must be set to false using + * {@link ListSelectionModel#setValueIsAdjusting(boolean)}. + * + * @param sm the selection model + * @param indices the indices + * @param adjusting the value for {@link ListSelectionModel#setValueIsAdjusting(boolean)} + */ + static void setSelectedIndices(ListSelectionModel sm, int[] indices, boolean adjusting) { if (ArrayUtils.getLength(indices) == 0) { return; } @@ -81,7 +96,7 @@ public static void setSelectedIndices(ListSelectionModel sm, int[] indices) { for (int i = 1; i < indices.length; i++) { sm.addSelectionInterval(indices[i], indices[i]); } - sm.setValueIsAdjusting(false); + sm.setValueIsAdjusting(adjusting); } /** diff --git a/gdsc-smlm-ij/src/main/java/uk/ac/sussex/gdsc/smlm/ij/gui/TraceDataTableModelFrame.java b/gdsc-smlm-ij/src/main/java/uk/ac/sussex/gdsc/smlm/ij/gui/TraceDataTableModelFrame.java index 92b6356a8..dea87447d 100644 --- a/gdsc-smlm-ij/src/main/java/uk/ac/sussex/gdsc/smlm/ij/gui/TraceDataTableModelFrame.java +++ b/gdsc-smlm-ij/src/main/java/uk/ac/sussex/gdsc/smlm/ij/gui/TraceDataTableModelFrame.java @@ -100,6 +100,7 @@ public class TraceDataTableModelFrame extends JFrame { private String saveName; private int windowSize = 7; private double pvalueThreshold = 1e-5; + private boolean invertSelection; /** The result model used to display selected trace results. */ private PeakResultTableModel resultModel; @@ -585,15 +586,18 @@ private void doAnalysisSlidingWindow() { final ExtendedGenericDialog gd = new ExtendedGenericDialog("Window Analysis", this); gd.addMessage("Compare intensity of localisations using two non-overlapping" + "\nsliding windows. Large jumps are used to select possible localisation" - + "\noverlap (assuming overlaps are on for longer than the window length)."); + + "\noverlap (assuming overlaps are on for longer than the window length)." + + "\nAny overlaps are selected in the table data."); gd.addSlider("Window_size", 2, 10, windowSize); gd.addNumericField("Probability_threshold", pvalueThreshold, -2); + gd.addCheckbox("Invert_selection", invertSelection); gd.showDialog(); if (gd.wasCanceled()) { return; } final int w = windowSize = Math.max(2, (int) gd.getNextNumber()); final double threshold = pvalueThreshold = MathUtils.clip(1e-10, 0.25, gd.getNextNumber()); + final boolean invert = invertSelection = gd.getNextBoolean(); final TypeConverter toPhotons = CalibrationHelper.getIntensityConverter(model.getCalibration(), IntensityUnit.PHOTON); @@ -633,7 +637,11 @@ private void doAnalysisSlidingWindow() { } final int[] indices = select.toIntArray(); table.convertRowIndexToView(indices); - ListSelectionModelHelper.setSelectedIndices(table.getSelectionModel(), indices); + final ListSelectionModel sm = table.getSelectionModel(); + ListSelectionModelHelper.setSelectedIndices(table.getSelectionModel(), indices, invert); + if (invert) { + ListSelectionModelHelper.invertSelection(table.getRowCount(), sm); + } } private static double mean(double[] array, int from, int to) {