Skip to content

Commit d12b58b

Browse files
committed
Misc fixes
1 parent badb275 commit d12b58b

3 files changed

Lines changed: 44 additions & 15 deletions

File tree

‎src/main/java/sc/fiji/snt/SNTUI.java‎

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,7 @@ public void runSecondaryLayerWizard() {
708708
private void runSecondaryLayerWizard(final boolean autoCTwarning) {
709709
if (!okToReplaceSecLayer())
710710
return;
711-
if (!plugin.accessToValidImageData()) {
711+
if (accessToValidImagePlus()) { // wizard requires image to be open
712712
noValidImageDataError();
713713
return;
714714
}
@@ -1524,7 +1524,7 @@ private JPanel viewsPanel() {
15241524
}
15251525

15261526
String msg = "";
1527-
if (plugin.accessToValidImageData()) {
1527+
if (accessToValidImagePlus()) {
15281528
msg = "Replace current image with a display canvas and ";
15291529
} else if (plugin.getPrefs().getTemp(SNTPrefs.NO_IMAGE_ASSOCIATED_DATA, false)) {
15301530
msg = "You have loaded paths without loading an image.";
@@ -1534,14 +1534,15 @@ private JPanel viewsPanel() {
15341534
resetPathSpacings(msg);
15351535
}
15361536

1537-
if (!plugin.accessToValidImageData()) {
1537+
if (accessToValidImagePlus()) {
15381538
// depending on what the user chose in the resetPathSpacings() prompt
15391539
// we need to check again if the plugin has access to a valid image
15401540
changeState(LOADING);
15411541
showStatus("Resizing Canvas...", false);
15421542
updateSinglePaneFlag();
15431543
if (plugin.isUnsavedChanges())
15441544
plugin.getPathAndFillManager().getBoundingBox(true);
1545+
plugin.closeAndResetAllPanes(); // flush cashed data as needed
15451546
plugin.rebuildDisplayCanvases(); // will change UI state
15461547
arrangeCanvases(false);
15471548
showStatus("Canvas rebuilt...", true);
@@ -1609,7 +1610,7 @@ private void validateImgDimensions() {
16091610
if (plugin.accessToValidImageData()) {
16101611
type = "image";
16111612
sb.append("<li>Use IJ's command Image&rarr;Adjust&rarr;Canvas Size... and press <i>Reload</i> in the Data Source widget of the Options pane</li>");
1612-
sb.append("<li>Close the current image and create a Display Canvas using the <i>Create Canvas</i> command in the Options pane</li>");
1613+
sb.append("<li>Close the current image and create a Display Canvas using <i>Create Canvas</i> in the Options pane</li>");
16131614
}
16141615
else {
16151616
sb.append("<li>Use the <i>Create/Resize Canvas</i> commands in the Options pane</li>");
@@ -2472,7 +2473,11 @@ private void initializeBvvFromPrompt() {
24722473
bvvSNT = new Bvv(plugin);
24732474
try {
24742475
if (choices[0].equals(choice)) {
2475-
bvvSNT.show(plugin.getImagePlus());
2476+
final ImagePlus imp = plugin.getImagePlus();
2477+
if (imp == null)
2478+
noValidImageDataError();
2479+
else
2480+
bvvSNT.show(imp);
24762481
} else if (choices[1].equals(choice)) {
24772482
bvvSNT.showLoadedData();
24782483
} else if (plugin.isSecondaryDataAvailable()) {

‎src/main/java/sc/fiji/snt/gui/GuiUtils.java‎

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2744,18 +2744,42 @@ private static JMenuItem summarizeMenuItem(final SNTTable sntTable, final JTable
27442744
return mItem;
27452745
}
27462746

2747+
/**
2748+
* Scrolls a JTable to show its last row.
2749+
* <p>
2750+
* This implementation avoids using {@link JTable#getCellRect} with row indices. That
2751+
* can trigger "row index is bigger than sorter's row count" warnings when the table's
2752+
* {@link RowSorter} hasn't fully synchronized. Instead, we manipulate the viewport.
2753+
* </p>
2754+
* <p>
2755+
* The double {@link SwingUtilities#invokeLater} ensures that:
2756+
* <ol>
2757+
* <li>1st pass: {@code revalidate()} triggers layout recalculation for any newly added rows</li>
2758+
* <li>2nd pass: scrolling occurs after layout is complete, so {@code table.getHeight()}
2759+
* reflects the actual table size including new rows</li>
2760+
* </ol>
2761+
* </p>
2762+
*
2763+
* @param table the table to scroll (must be inside a {@link JScrollPane})
2764+
*/
27472765
private static void scrollToBottom(final JTable table) {
27482766
SwingUtilities.invokeLater(() -> {
2749-
try {
2750-
final int lastRow = table.getRowCount() - 1;
2751-
final RowSorter<?> sorter = table.getRowSorter();
2752-
if (lastRow >= 0 && (sorter == null || lastRow < sorter.getViewRowCount())) {
2753-
final Rectangle rect = table.getCellRect(lastRow, 0, true);
2754-
table.scrollRectToVisible(rect);
2767+
table.revalidate();
2768+
SwingUtilities.invokeLater(() -> {
2769+
try {
2770+
final Container parent = table.getParent();
2771+
if (parent instanceof JViewport viewport) {
2772+
final int tableHeight = table.getHeight();
2773+
final int viewHeight = viewport.getHeight();
2774+
if (tableHeight > viewHeight) {
2775+
viewport.setViewPosition(new Point(0, tableHeight - viewHeight));
2776+
}
2777+
}
2778+
table.repaint();
2779+
} catch (final Exception ignored) {
2780+
// Fail silently
27552781
}
2756-
} catch (final Exception ignored) {
2757-
// Fail silently - scroll is non-critical
2758-
}
2782+
});
27592783
});
27602784
}
27612785

‎src/main/java/sc/fiji/snt/util/TreeUtils.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -872,7 +872,7 @@ public static Tree merge(final Collection<Tree> trees) {
872872
if (trees.size() == 1) return trees.iterator().next();
873873
final Tree holdingTree = new Tree();
874874
holdingTree.setLabel("Combined Paths");
875-
trees.forEach(tree -> tree.list().addAll(tree.list()));
875+
trees.forEach(tree -> holdingTree.list().addAll(tree.list()));
876876
return holdingTree;
877877
}
878878

0 commit comments

Comments
 (0)