Skip to content

Commit

Permalink
Ensure tree-selection prompts respect location of active window
Browse files Browse the repository at this point in the history
while at it, some minor code cleanup
  • Loading branch information
tferr committed May 5, 2021
1 parent b22435f commit bed052c
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 21 deletions.
6 changes: 3 additions & 3 deletions src/main/java/sc/fiji/snt/InteractiveTracerCanvas.java
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ private NearPoint getNearPointToMousePointer() {
return null;
}

System.out.println(last_x_in_pane_precise + ", " + last_y_in_pane_precise);
// System.out.println(last_x_in_pane_precise + ", " + last_y_in_pane_precise);
final double[] p = new double[3];
tracerPlugin.findPointInStackPrecise(last_x_in_pane_precise,
last_y_in_pane_precise, plane, p);
Expand All @@ -484,8 +484,8 @@ private NearPoint getNearPointToMousePointer() {
final PointInImage cursor = new PointInImage(p[0], p[1], 0);
final double maxSquaredLength = Math.max(cursor.distanceSquaredTo(rectMin),
cursor.distanceSquaredTo(rectMax));
System.out.println(SNTUtils.formatDouble(last_x_in_pane_precise, 2) + ", " +
SNTUtils.formatDouble(last_y_in_pane_precise, 2) + " | dx:" + maxSquaredLength);
// System.out.println(SNTUtils.formatDouble(last_x_in_pane_precise, 2) + ", " +
// SNTUtils.formatDouble(last_y_in_pane_precise, 2) + " | dx:" + maxSquaredLength);

// Find the nearest point on unselected Paths currently displayed in
// viewPort
Expand Down
10 changes: 6 additions & 4 deletions src/main/java/sc/fiji/snt/PathManagerUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -903,16 +903,17 @@ private void addNode(final MutableTreeNode parent, final Path childPath,
}

protected Tree getSingleTree() {
return getSingleTreePrompt();
return getSingleTreePrompt((this.hasFocus()) ? guiUtils : new GuiUtils(plugin.getActiveWindow()));
}

protected Collection<Tree> getMultipleTrees() {
return getMultipleTreesPrompt(true);
return getMultipleTreesPrompt((this.hasFocus()) ? guiUtils : new GuiUtils(plugin.getActiveWindow()), true);
}

protected Tree getMultipleTreesInASingleContainer() {
final Collection<Tree> trees = getMultipleTrees();
if (trees == null) return null;
if (trees.size() == 1) trees.iterator().next();
final Tree holdingTree = new Tree();
holdingTree.setLabel("Mixed Paths");
trees.forEach(tree -> tree.list().forEach(path -> holdingTree.add(path)));
Expand All @@ -932,7 +933,7 @@ private Tree getSingleTreeMimickingPrompt(final String description) {
return getTreesMimickingPrompt(description).iterator().next();
}

private Tree getSingleTreePrompt() {
private Tree getSingleTreePrompt(final GuiUtils guiUtils) {
final Collection<Tree> trees = pathAndFillManager.getTrees();
if (trees.size() == 1) return trees.iterator().next();
final ArrayList<String> treeLabels = new ArrayList<>(trees.size());
Expand All @@ -949,7 +950,7 @@ private Tree getSingleTreePrompt() {
return null; // user pressed canceled prompt
}

private Collection<Tree> getMultipleTreesPrompt(final boolean includeAll) {
private Collection<Tree> getMultipleTreesPrompt(final GuiUtils guiUtils, final boolean includeAll) {
final Collection<Tree> trees = pathAndFillManager.getTrees();
if (trees.size() == 1) return trees;
final ArrayList<String> treeLabels = new ArrayList<>(trees.size() + 1);
Expand Down Expand Up @@ -2300,6 +2301,7 @@ private void setSelectAllTagsMenu(final boolean select) {
/** ActionListener for JCheckBoxMenuItem's "default tags" */
private class TagMenuItem extends JCheckBoxMenuItem implements ActionListener {

private static final long serialVersionUID = 1L;

private TagMenuItem(final String tag) {
super(tag, false);
Expand Down
27 changes: 14 additions & 13 deletions src/main/java/sc/fiji/snt/SNT.java
Original file line number Diff line number Diff line change
Expand Up @@ -1882,18 +1882,19 @@ private boolean justFirstPoint() {
}

protected void startSholl(final PointInImage centerScaled) {
setZPositionAllPanes((int) Math.round(centerScaled.x), (int) Math.round(
centerScaled.y), (int) Math.round(centerScaled.z));
setShowOnlySelectedPaths(false);
SNTUtils.log("Starting Sholl Analysis centered at " + centerScaled);
final Map<String, Object> input = new HashMap<>();
input.put("snt", this);
input.put("center", centerScaled);
input.put("tree", (getUI() == null) ? new Tree(getPathAndFillManager().getPathsFiltered())
: getUI().getPathManager().getMultipleTreesInASingleContainer());
final CommandService cmdService = getContext().getService(
CommandService.class);
cmdService.run(ShollAnalysisTreeCmd.class, true, input);
SwingUtilities.invokeLater(() -> {
setZPositionAllPanes((int) Math.round(centerScaled.x), (int) Math.round(centerScaled.y),
(int) Math.round(centerScaled.z));
setShowOnlySelectedPaths(false);
SNTUtils.log("Starting Sholl Analysis centered at " + centerScaled);
final Map<String, Object> input = new HashMap<>();
input.put("snt", this);
input.put("center", centerScaled);
input.put("tree", (getUI() == null) ? new Tree(getPathAndFillManager().getPathsFiltered())
: getUI().getPathManager().getMultipleTreesInASingleContainer());
final CommandService cmdService = getContext().getService(CommandService.class);
cmdService.run(ShollAnalysisTreeCmd.class, true, input);
});
}

public ImagePlus getFilledVolume(final boolean asMask) {
Expand Down Expand Up @@ -2399,7 +2400,7 @@ private Component getActiveCanvas() {
return null;
}

private Component getActiveWindow() {
protected Component getActiveWindow() {
if (!isUIready()) return null;
if (ui.isActive()) return ui;
final Window[] images = { xy_window, xz_window, zy_window };
Expand Down
1 change: 0 additions & 1 deletion src/main/java/sc/fiji/snt/plugin/ShollAnalysisTreeCmd.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

package sc.fiji.snt.plugin;

import java.awt.Color;
import java.io.File;
import java.net.URL;
import java.util.ArrayList;
Expand Down

0 comments on commit bed052c

Please sign in to comment.