Skip to content

Commit 422955e

Browse files
committed
Minor code cleanup
1 parent bb78b52 commit 422955e

5 files changed

Lines changed: 67 additions & 72 deletions

File tree

src/main/java/sc/fiji/snt/CurationManager.java

Lines changed: 24 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -355,17 +355,13 @@ public JPanel getPanel() {
355355
+ "Double-click an issue to navigate to its location; "
356356
+ "right-click the issues table for actions.", panel), gbc);
357357
gbc.gridy++;
358-
// Parameters region (live + on-demand). Wrapped in a scroll pane so
359-
// that when the user shrinks the top half of the split below the
360-
// params' natural height, the content scrolls instead of clipping.
361-
// The two sections are also independently collapsible via the
362-
// chevron next to each header -- collapse one to focus on the other.
363-
// WidthTrackingPanel (see below) instead of plain JPanel: it
364-
// implements Scrollable with getScrollableTracksViewportWidth() ==
365-
// true, so the panel reflows to the viewport's width instead of
366-
// sizing to its preferred width and overflowing the right edge
367-
// (which, with HORIZONTAL_SCROLLBAR_NEVER, would clip the histogram
368-
// buttons at the right of each row).
358+
// Parameters region (live + on-demand). Wrapped in a scroll pane so that when the user shrinks the top half of
359+
// the split below the params' natural height, the content scrolls instead of clipping. The two sections are
360+
// collapsible via the chevron next to each header -- collapse one to focus on the other.
361+
// WidthTrackingPanel (see below) instead of plain JPanel: it implements Scrollable with
362+
// getScrollableTracksViewportWidth() == true, so the panel reflows to the viewport's width instead of sizing
363+
// to its preferred width and overflowing the right edge (which, with HORIZONTAL_SCROLLBAR_NEVER, would clip the
364+
// histogram buttons at the right of each row)
369365
final JPanel paramsPane = new WidthTrackingPanel(new GridBagLayout());
370366
final GridBagConstraints paramsGbc = GuiUtils.defaultGbc();
371367
paramsGbc.fill = GridBagConstraints.HORIZONTAL;
@@ -378,26 +374,20 @@ public JPanel getPanel() {
378374
paramsGbc.weighty = 1.0;
379375
paramsPane.add(Box.createVerticalGlue(), paramsGbc);
380376

381-
// VERTICAL_SCROLLBAR_ALWAYS rather than AS_NEEDED so the scrollbar's
382-
// width is always reserved by the viewport, never overlapping the
383-
// chevron and per-row histogram buttons that sit at the right edge.
384-
// The "non-functional scrollbar when content fits" cost is small;
385-
// for this dense panel the bar is usually active anyway.
377+
// VERTICAL_SCROLLBAR_ALWAYS rather than AS_NEEDED so the scrollbar's width is always reserved by the viewport,
378+
// never overlapping the chevron and per-row histogram buttons that sit at the right edge. The "non-functional
379+
// scrollbar when content fits" cost is small; for this dense panel the bar is usually active anyway
386380
final JScrollPane paramsScroll = new JScrollPane(paramsPane,
387381
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
388382
JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
389-
paramsScroll.setBorder(BorderFactory.createEmptyBorder());
383+
GuiUtils.ScrollPanes.setTopBottomBorder(paramsScroll);
390384
paramsScroll.setViewportBorder(BorderFactory.createEmptyBorder());
391385
paramsScroll.setOpaque(false);
392386
paramsScroll.getViewport().setOpaque(false);
393-
// Faster scroll than the default 1px-per-tick
394-
paramsScroll.getVerticalScrollBar().setUnitIncrement(16);
395-
396-
// Bottom half of the split: toolbar + warnings table. Bundling them
397-
// here (rather than as separate top-level rows) lets the JSplitPane
398-
// treat "params" and "warnings + their controls" as the two natural
399-
// sides of the divider; the toolbar always sits with what it
400-
// operates on.
387+
388+
// Bottom half of the split: toolbar + warnings table. Bundling them here (rather than as separate top-level
389+
// rows) lets the JSplitPane treat "params" and "warnings + their controls" as the two natural sides of the
390+
// divider; the toolbar always sits with what it operates on
401391
tableScroll = new JScrollPane(warningsTable);
402392
tableScroll.setMinimumSize(new Dimension(0, 0)); // allow shrinking
403393
warningsTable.setPreferredScrollableViewportSize(null); // defer to layout
@@ -406,21 +396,18 @@ public JPanel getPanel() {
406396
bottomHalf.add(buildToolbar(), BorderLayout.NORTH);
407397
bottomHalf.add(tableScroll, BorderLayout.CENTER);
408398

409-
// Vertical split between params (top) and toolbar+table (bottom).
410-
// resizeWeight = 0.0 means: when the whole tab is resized, the
411-
// bottom (table) absorbs the change while params stays at its
412-
// current size -- which matches users' usual mental model of
413-
// "give me more room for the issues list".
399+
// Vertical split between params (top) and toolbar+table (bottom). resizeWeight = 0.0 means: when the whole tab
400+
// is resized, the bottom (table) absorbs the change while params stays at its current size -- which matches
401+
// users' usual mental model of "give me more room for the issues list"
414402
final javax.swing.JSplitPane paramsTableSplit = new javax.swing.JSplitPane(
415403
javax.swing.JSplitPane.VERTICAL_SPLIT, paramsScroll, bottomHalf);
416404
paramsTableSplit.setBorder(BorderFactory.createEmptyBorder());
417405
paramsTableSplit.setOpaque(false);
418406
paramsTableSplit.setContinuousLayout(true);
419407
paramsTableSplit.setOneTouchExpandable(false);
420-
// Initial split: ~60% to params (typical content fits there), rest
421-
// for the issues list. setDividerLocation(double) only works after
422-
// the component is realized, so we also set a sensible absolute
423-
// fallback that takes effect immediately.
408+
// Initial split: ~60% to params (typical content fits there), rest for the issues list.
409+
// setDividerLocation(double) only works after the component is realized, so we also set a sensible absolute
410+
// fallback that takes effect immediately
424411
paramsTableSplit.setDividerLocation(0.7);
425412
SwingUtilities.invokeLater(() -> paramsTableSplit.setDividerLocation(0.7));
426413

@@ -431,11 +418,9 @@ public JPanel getPanel() {
431418
gbc.gridy++;
432419
gbc.insets.top = 0;
433420

434-
// Detach / dock table: the helper needs the scroll pane to exist
435-
// (it captures a reference to it). We can't wire it inside
436-
// buildTablePopupMenu() because that runs from the constructor,
437-
// long before tableScroll is created here. Append the toggle item
438-
// to the existing popup now that everything it needs is in place.
421+
// Detach / dock table: the helper needs the scroll pane to exist. We can't wire it inside
422+
// buildTablePopupMenu() because that runs from the constructor, long before tableScroll is created here.
423+
// Append the toggle item to the existing popup now that everything it needs is in place
439424
if (tableDetacher == null) {
440425
tableDetacher = new GuiUtils.JTables.DetachableTable(
441426
tableScroll, "Issues (Curation Assistant)", this::redockTableScroll,

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

Lines changed: 40 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import com.formdev.flatlaf.*;
2626
import com.formdev.flatlaf.extras.FlatSVGIcon;
2727
import com.formdev.flatlaf.icons.FlatClearIcon;
28+
import com.formdev.flatlaf.ui.FlatLineBorder;
2829
import com.formdev.flatlaf.util.SystemFileChooser;
2930
import com.formdev.flatlaf.util.UIScale;
3031
import com.jidesoft.plaf.LookAndFeelFactory;
@@ -586,11 +587,11 @@ public int getNextMatch(final String prefix, final int startIndex, final Positio
586587
final JPanel panel = new JPanel(layout);
587588
panel.add(getLabel(message),gbc);
588589
gbc.gridy++;
589-
panel.add(getScrollPane(list), gbc);
590+
panel.add(ScrollPanes.create(list), gbc);
590591
gbc.gridy++;
591592
panel.add(new JLabel("<HTML>&nbsp;"), gbc); // spacer
592593
gbc.gridy++;
593-
panel.add(getScrollPane(ta), gbc);
594+
panel.add(ScrollPanes.create(ta), gbc);
594595
if (choices.length > 4) {
595596
final ListSearchable searchable = new ListSearchable(list) {
596597
@Override
@@ -648,15 +649,9 @@ public void keyTyped(final KeyEvent e) {
648649
return list;
649650
}
650651

651-
private JScrollPane getScrollPane(final Component c) {
652-
final JScrollPane sp = new JScrollPane(c);
653-
sp.setWheelScrollingEnabled(true);
654-
return sp;
655-
}
656-
657652
public List<String> getMultipleChoices(final String title, final String[] choices, final String defaultChoice) {
658653
final JList<String> list = getJList(choices, defaultChoice);
659-
if (JOptionPane.showConfirmDialog(parent, getScrollPane(list), title,
654+
if (JOptionPane.showConfirmDialog(parent, ScrollPanes.create(list), title,
660655
JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE) == JOptionPane.OK_OPTION)
661656
return list.getSelectedValuesList();
662657
return null;
@@ -671,7 +666,7 @@ public Object[] getMultipleChoicesAndChoice(final String title,
671666
combo.setSelectedItem(defaultChoice2);
672667
final JPanel panel = new JPanel();
673668
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
674-
panel.add(getScrollPane(list1));
669+
panel.add(ScrollPanes.create(list1));
675670
panel.add(combo);
676671
if (JOptionPane.showConfirmDialog(parent, panel, title,
677672
JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE) == JOptionPane.OK_OPTION) {
@@ -1492,7 +1487,7 @@ private Object getObj(final String promptMsg, final String promptTitle,
14921487
}
14931488

14941489
private JDialog htmlOptionPane(final String msg, final String title, final boolean modal) {
1495-
final JOptionPane op = new JOptionPane(getScrollPane(htmlEditorPane(msg)),
1490+
final JOptionPane op = new JOptionPane(ScrollPanes.create(htmlEditorPane(msg)),
14961491
JOptionPane.PLAIN_MESSAGE, JOptionPane.DEFAULT_OPTION);
14971492
final JDialog d = op.createDialog(parent, title);
14981493
d.setModal(modal);
@@ -2342,23 +2337,6 @@ public static GridBagConstraints defaultGbc() {
23422337
return cp;
23432338
}
23442339

2345-
public static void recolorTracks(final JScrollPane scrollPane, final Color color, final boolean updateUI) {
2346-
final Component c = scrollPane.getCorner(JScrollPane.LOWER_TRAILING_CORNER);
2347-
if (c != null) {
2348-
c.setBackground(color);
2349-
} else {
2350-
final JPanel dummy = new JPanel();
2351-
dummy.setBackground(color);
2352-
scrollPane.setCorner(JScrollPane.LOWER_TRAILING_CORNER, dummy);
2353-
}
2354-
final Map<String, Object> style = new HashMap<>();
2355-
style.put("track", color);
2356-
style.put("hoverTrackColor", color);
2357-
scrollPane.getHorizontalScrollBar().putClientProperty(FlatClientProperties.STYLE, style);
2358-
scrollPane.getVerticalScrollBar().putClientProperty(FlatClientProperties.STYLE, style);
2359-
if (updateUI) scrollPane.updateUI();
2360-
}
2361-
23622340
public static void addClearButton(final JTextField textField) {
23632341
textField.putClientProperty(FlatClientProperties.TEXT_FIELD_SHOW_CLEAR_BUTTON, true);
23642342
}
@@ -2737,7 +2715,7 @@ public JDialog showHTMLDialog(final String msg, final String title, final boolea
27372715

27382716
public boolean yesNoHTMLDialog(final String htmlMsg, final String title,
27392717
final String yesLabel, final String noLabel) {
2740-
return yesNoDialog(new Object[]{getScrollPane(htmlEditorPane(htmlMsg))}, title,
2718+
return yesNoDialog(new Object[]{ScrollPanes.create(htmlEditorPane(htmlMsg))}, title,
27412719
new String[]{yesLabel, noLabel}, JOptionPane.PLAIN_MESSAGE) == JOptionPane.YES_OPTION;
27422720
}
27432721

@@ -2804,7 +2782,7 @@ JPanel panel() {
28042782
++c.gridy;
28052783
contentPane.add(leftAlignedLabel("Charts to be combined:", true), c);
28062784
++c.gridy;
2807-
contentPane.add(getScrollPane(titles), c);
2785+
contentPane.add(ScrollPanes.create(titles), c);
28082786
++c.gridy;
28092787
contentPane.add(leftAlignedLabel("Montage Layout:", true), c);
28102788
++c.gridy;
@@ -5021,6 +4999,38 @@ public void setEnabled(final boolean enabled) {
50214999
}
50225000

50235001

5002+
public static class ScrollPanes {
5003+
5004+
private static JScrollPane create(final Component c) {
5005+
final JScrollPane sp = new JScrollPane(c);
5006+
sp.setWheelScrollingEnabled(true);
5007+
return sp;
5008+
}
5009+
5010+
public static void setTopBottomBorder(final JScrollPane scrollPane) {
5011+
scrollPane.setBorder(new FlatLineBorder(new Insets(1, 0, 1, 0),
5012+
UIManager.getColor("Component.borderColor")));
5013+
}
5014+
5015+
public static void recolorTracks(final JScrollPane scrollPane, final Color color, final boolean updateUI) {
5016+
final Component c = scrollPane.getCorner(JScrollPane.LOWER_TRAILING_CORNER);
5017+
if (c != null) {
5018+
c.setBackground(color);
5019+
} else {
5020+
final JPanel dummy = new JPanel();
5021+
dummy.setBackground(color);
5022+
scrollPane.setCorner(JScrollPane.LOWER_TRAILING_CORNER, dummy);
5023+
}
5024+
final Map<String, Object> style = new HashMap<>();
5025+
style.put("track", color);
5026+
style.put("hoverTrackColor", color);
5027+
scrollPane.getHorizontalScrollBar().putClientProperty(FlatClientProperties.STYLE, style);
5028+
scrollPane.getVerticalScrollBar().putClientProperty(FlatClientProperties.STYLE, style);
5029+
if (updateUI) scrollPane.updateUI();
5030+
}
5031+
}
5032+
5033+
50245034
public static class SplitPanes {
50255035

50265036
public static JSplitPane nonDraggableRightSplitPane() {

src/main/java/sc/fiji/snt/gui/SNTCommandFinder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1185,7 +1185,7 @@ private JScrollPane getScrollPane() {
11851185

11861186
@Override
11871187
public void updateUI() {
1188-
GuiUtils.recolorTracks(this, BACKGROUND, false);
1188+
GuiUtils.ScrollPanes.recolorTracks(this, BACKGROUND, false);
11891189
super.updateUI();
11901190
}
11911191
};

src/main/java/sc/fiji/snt/gui/SNTEditorPane.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ public void applyTheme(final String theme) throws IllegalArgumentException {
170170
th.apply(this);
171171
setFont(getFont().deriveFont(GuiUtils.uiFontSize())); // theme may contain hardwired fonts
172172
scrollPane.getGutter().setLineNumberFont(scrollPane.getGutter().getLineNumberFont().deriveFont(getFontSize()*.75f)); // theme may contain hardwired fonts
173-
GuiUtils.recolorTracks(scrollPane, th.bgColor, true);
173+
GuiUtils.ScrollPanes.recolorTracks(scrollPane, th.bgColor, true);
174174
// Ensure gutter and row header backgrounds match the editor
175175
scrollPane.getGutter().setBackground(th.bgColor);
176176
if (scrollPane.getRowHeader() != null) {

src/main/java/sc/fiji/snt/gui/cmds/BigDataLoaderCmd.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ and big data formats with lazy loading (N5, Zarr, HDF5, OME-TIFF,
133133
@Parameter(required = false, visibility= ItemVisibility.MESSAGE, persist = false)
134134
String msg;
135135

136-
@Parameter(label = "Load Remote Demo...", callback = "loadDemo", persist = false, required = false)
136+
@Parameter(label = "Load Remote Demo", callback = "loadDemo", persist = false, required = false)
137137
private Button demoButton;
138138

139139
@SuppressWarnings("unused")

0 commit comments

Comments
 (0)