From fb41b1550085f75235b9527836537fbea2c51326 Mon Sep 17 00:00:00 2001 From: Tiago Ferreira Date: Thu, 17 Oct 2024 14:54:14 -0400 Subject: [PATCH] Incorporate ET suggestions for GUI --- .../java/sc/fiji/snt/BookmarkManager.java | 39 +++++++++++++++++++ src/main/java/sc/fiji/snt/SNTUI.java | 20 +++++----- src/main/java/sc/fiji/snt/gui/MeasureUI.java | 2 +- .../sc/fiji/snt/gui/SNTSearchableBar.java | 1 + .../java/sc/fiji/snt/viewer/Viewer3D.java | 9 +++-- 5 files changed, 58 insertions(+), 13 deletions(-) diff --git a/src/main/java/sc/fiji/snt/BookmarkManager.java b/src/main/java/sc/fiji/snt/BookmarkManager.java index 2aba2f37..af6e6502 100644 --- a/src/main/java/sc/fiji/snt/BookmarkManager.java +++ b/src/main/java/sc/fiji/snt/BookmarkManager.java @@ -24,6 +24,7 @@ import ij.ImagePlus; import ij.gui.ImageCanvas; +import ij.gui.Overlay; import ij.gui.PointRoi; import ij.gui.Roi; import ij.plugin.frame.RoiManager; @@ -206,6 +207,23 @@ private JPopupMenu importMenu() { sntui.showStatus(model.getDataList().size() + " listed bookmarks ", true); } }); + jmi = new JMenuItem("From Image Overlay"); + jmi.setToolTipText("The Image Overlay is automatically saved in the image header of TIFF images"); + menu.add(jmi); + jmi.addActionListener(e -> { + final ImagePlus imp = sntui.plugin.getImagePlus(); + if (imp == null) { + sntui.guiUtils.error("No image is currently loaded."); + return; + } + if (imp.getOverlay() == null || imp.getOverlay().size() == 0) { + sntui.guiUtils.error("Image Overlay contains no ROIs."); + return; + } + load(imp.getOverlay().toArray()); + sntui.showStatus(model.getDataList().size() + " listed bookmarks ", true); + recordCmd("load(snt.getInstance().getImagePlus().getOverlay().toArray())"); + }); jmi = new JMenuItem("From ROI Manager"); menu.add(jmi); jmi.addActionListener(e -> { @@ -239,6 +257,22 @@ private JPopupMenu exportMenu() { } } }); + jmi = new JMenuItem("To Image Overlay"); + jmi.setToolTipText("The Image Overlay is automatically saved in the image header of TIFF images"); + menu.add(jmi); + jmi.addActionListener(e -> { + final ImagePlus imp = sntui.plugin.getImagePlus(); + if (imp == null) { + sntui.guiUtils.error("No image is currently loaded."); + return; + } + table.clearSelection(); + if (imp.getOverlay() == null) imp.setOverlay(new Overlay()); + toOverlay(imp.getOverlay()); + sntui.showStatus(model.getDataList().size() + " bookmarks exported to the Image Overlay", true); + recordCmd("clearSelection()"); + recordCmd("toOverlay(snt.getInstance().getImagePlus().getOverlay())"); + }); jmi = new JMenuItem("To ROI Manager"); menu.add(jmi); jmi.addActionListener(e -> { @@ -439,6 +473,11 @@ public List getROIs(final boolean onlySelectedRows) { return rois; } + public void toOverlay(final Overlay overlay) { + for (final Roi roi : getROIs(table.getSelectedRows().length>0)) + overlay.add(roi); + } + public void toRoiManager() { RoiManager rm = RoiManager.getInstance2(); if (rm == null) rm = new RoiManager(); diff --git a/src/main/java/sc/fiji/snt/SNTUI.java b/src/main/java/sc/fiji/snt/SNTUI.java index da9c88fe..3fa304f8 100644 --- a/src/main/java/sc/fiji/snt/SNTUI.java +++ b/src/main/java/sc/fiji/snt/SNTUI.java @@ -380,11 +380,16 @@ public void windowClosing(final WindowEvent e) { final GridBagConstraints dialogGbc = GuiUtils.defaultGbc(); add(statusPanel(), dialogGbc); dialogGbc.gridy++; - add(new JLabel(" "), dialogGbc); + add(new JLabel(" "), dialogGbc); // tabbed pane top spacer dialogGbc.gridy++; - add(tabbedPane, dialogGbc); dialogGbc.gridy++; + dialogGbc.weighty = 1; + add(new JLabel(" "), dialogGbc); // tabbed pane bottom spacer + dialogGbc.gridy++; + dialogGbc.weighty = 0; + add(new JSeparator(SwingConstants.HORIZONTAL), dialogGbc); + dialogGbc.gridy++; add(statusBar(), dialogGbc); addFileDrop(this, guiUtils); //registerCommandFinder(menuBar); // spurious addition if added here!? @@ -3343,14 +3348,11 @@ private JPanel hideWindowsPanel() { return hideWindowsPanel; } - private JPanel statusBar() { - final JPanel statusBar = new JPanel(); - statusBar.setLayout(new BoxLayout(statusBar, BoxLayout.X_AXIS)); + private JLabel statusBar() { statusBarText = GuiUtils.leftAlignedLabel("Ready to trace...", true); - statusBarText.setBorder(BorderFactory.createEmptyBorder(0, InternalUtils.MARGIN, InternalUtils.MARGIN / 2, 0)); - statusBar.add(statusBarText); + statusBarText.setBorder(BorderFactory.createEmptyBorder(InternalUtils.MARGIN, InternalUtils.MARGIN, InternalUtils.MARGIN, 0)); refreshStatus(); - statusBar.addMouseListener( new MouseAdapter() { + statusBarText.addMouseListener( new MouseAdapter() { @Override public void mousePressed(final MouseEvent e) { if (e.getClickCount() == 2) { @@ -3360,7 +3362,7 @@ public void mousePressed(final MouseEvent e) { } } }); - return statusBar; + return statusBarText; } boolean setFastMarchSearchEnabled(final boolean enable) { diff --git a/src/main/java/sc/fiji/snt/gui/MeasureUI.java b/src/main/java/sc/fiji/snt/gui/MeasureUI.java index 18012e2a..bce7caa8 100644 --- a/src/main/java/sc/fiji/snt/gui/MeasureUI.java +++ b/src/main/java/sc/fiji/snt/gui/MeasureUI.java @@ -215,7 +215,7 @@ public boolean isCellEditable(final int row, final int column) { // Enlarge default width of first column. Another option would be to have all // columns to auto-fit at all times, e.g., https://stackoverflow.com/a/25570812. // Maybe that would be better? - final String prototypeMetric = TreeStatistics.GRAPH_DIAMETER_ANGLE_XY; + final String prototypeMetric = TreeStatistics.N_BRANCH_NODES; for (int i = 0; i < statsTable.getColumnCount(); ++i) { final int width = SwingUtilities.computeStringWidth(statsTable.getFontMetrics(statsTable.getFont()), (i == 0) ? prototypeMetric : MEAN); diff --git a/src/main/java/sc/fiji/snt/gui/SNTSearchableBar.java b/src/main/java/sc/fiji/snt/gui/SNTSearchableBar.java index 2da93d90..202b5755 100644 --- a/src/main/java/sc/fiji/snt/gui/SNTSearchableBar.java +++ b/src/main/java/sc/fiji/snt/gui/SNTSearchableBar.java @@ -356,6 +356,7 @@ private void addButton(final JPanel panel, final AbstractButton button) { private JLabel statusLabel() { _statusLabel = new JLabel(statusLabelPlaceholder); + _statusLabel.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 0)); _statusLabel.addPropertyChangeListener("text", evt -> { final String text = _statusLabel.getText(); if (text == null || text.isEmpty()) _statusLabel.setText( diff --git a/src/main/java/sc/fiji/snt/viewer/Viewer3D.java b/src/main/java/sc/fiji/snt/viewer/Viewer3D.java index 4a415fde..8cafca49 100644 --- a/src/main/java/sc/fiji/snt/viewer/Viewer3D.java +++ b/src/main/java/sc/fiji/snt/viewer/Viewer3D.java @@ -3896,6 +3896,7 @@ public void actionPerformed(final ActionEvent e) { fitToVisibleObjects(true, true); return; case LOG_TO_RECORDER: + openRecorder(false); logSceneControls(true); break; case NONE: @@ -3926,7 +3927,7 @@ public void actionPerformed(final ActionEvent e) { keyController.showHelp(false); return; case RECORDER: - openRecorder(); + openRecorder(true); return; case SNAPSHOT_DISK: keyController.saveScreenshot(); @@ -3982,9 +3983,9 @@ private void showPanelAsNeeded() { toggleControlPanel(); // e.g, if action called via cmdFinder } - private void openRecorder() { + private void openRecorder(final boolean warnIfOpen) { if (getRecorder(false) != null) { - guiUtils.error("Script Recorder is already open."); + if (warnIfOpen) guiUtils.error("Script Recorder is already open."); return; } final StringBuilder sb = new StringBuilder(); @@ -5948,6 +5949,8 @@ public AllenCCFNavigator() { tree.setClickInCheckBoxOnly(false); searchableBar = new SNTSearchableBar(new TreeSearchable(tree)); searchableBar.setStatusLabelPlaceholder("CCF v"+ AllenUtils.VERSION); + searchableBar.setHighlightAll(false); + searchableBar.setShowMatchCount(true); searchableBar.setVisibleButtons( SNTSearchableBar.SHOW_NAVIGATION | SNTSearchableBar.SHOW_HIGHLIGHTS | SNTSearchableBar.SHOW_SEARCH_OPTIONS | SNTSearchableBar.SHOW_STATUS);