Skip to content

Commit

Permalink
Allow the selection to be inverted
Browse files Browse the repository at this point in the history
  • Loading branch information
aherbert committed Sep 20, 2023
1 parent 27fb144 commit 2bcf53e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
* <p>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;
}
Expand All @@ -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);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<IntensityUnit> toPhotons =
CalibrationHelper.getIntensityConverter(model.getCalibration(), IntensityUnit.PHOTON);
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 2bcf53e

Please sign in to comment.