Skip to content

Commit 7bed0b5

Browse files
committed
SwingSearchBar: tweak formatting in a few places
1 parent a3fa53d commit 7bed0b5

File tree

1 file changed

+69
-72
lines changed

1 file changed

+69
-72
lines changed

src/main/java/org/scijava/ui/swing/search/SwingSearchBar.java

Lines changed: 69 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -415,10 +415,10 @@ public void mouseClicked(final MouseEvent e) {
415415
final SearchResult result = resultsList.getSelectedValue();
416416
if (result == null || isHeader(result)) {
417417
if (result != null) {
418-
final Searcher searcher = ((SearchResultHeader) result)
419-
.searcher();
420-
searchService.setEnabled(searcher, !searchService.enabled(
421-
searcher));
418+
final Searcher searcher = //
419+
((SearchResultHeader) result).searcher();
420+
searchService.setEnabled(searcher, //
421+
!searchService.enabled(searcher));
422422
SwingSearchBar.this.search();
423423
}
424424
}
@@ -448,82 +448,79 @@ public void mouseMoved(final MouseEvent e) {
448448
resultsList.addListSelectionListener(lse -> {
449449
if (lse.getValueIsAdjusting()) return;
450450
final SearchResult result = resultsList.getSelectedValue();
451-
if (result == null || isHeader(result)) {
452-
if (result != null) {
453-
threadService.queue(() -> {
454-
down();
455-
});
456-
return;
457-
}
451+
if (isHeader(result)) {
452+
threadService.queue(() -> down());
453+
return;
454+
}
455+
if (result == null) {
458456
// clear details pane
459457
detailsTitle.setText("");
460458
detailsProps.removeAll();
461459
detailsButtons.removeAll();
460+
return;
462461
}
463-
else {
464-
// populate details pane
465-
detailsTitle.setText("<html><h2>" + highlightSearchUnderline(
466-
escapeHtml(result.name()), searchText) + "</h2>");
467-
detailsProps.removeAll();
468-
result.properties().forEach((k, v) -> {
469-
if (v != "") {
470-
if (k == null) {
471-
final JTextPane textPane = new JTextPane();
472-
textPane.setContentType("text/html");
473-
textPane.setText(highlightSearchBold(v, searchText));
474-
final Font font = UIManager.getFont("Label.font");
475-
final String bodyRule = "body { font-family: " + font
476-
.getFamily() + "; " + "font-size: " + font.getSize() +
477-
"pt; }";
478-
((HTMLDocument) textPane.getDocument()).getStyleSheet().addRule(
479-
bodyRule);
480-
textPane.setBorder(BorderFactory.createCompoundBorder(
481-
BorderFactory.createMatteBorder(1, 0, 1, 0, Color.DARK_GRAY),
482-
BorderFactory.createEmptyBorder(PAD, 0, PAD, 0)));
483-
textPane.setEditable(false);
484-
textPane.setOpaque(false);
485-
detailsProps.add(textPane, "growx, wmax 100%");
486-
}
487-
else {
488-
final JLabel keyLabel = new JLabel("<html>" +
489-
"<strong style=\"color: gray;\">" + k +
490-
"&nbsp;&nbsp;</strong>");
491-
keyLabel.setFont(smaller(keyLabel.getFont(), 1));
492-
detailsProps.add(keyLabel, "growx, pad 0 0 10 0");
493-
final JTextArea valueField = new JTextArea();
494-
valueField.setText(v);
495-
valueField.setLineWrap(true);
496-
valueField.setWrapStyleWord(true);
497-
valueField.setEditable(false);
498-
valueField.setBackground(null);
499-
valueField.setBorder(null);
500-
detailsProps.add(valueField, "growx, wmax 100%");
501-
}
502-
}
503-
});
504-
detailsButtons.removeAll();
505-
final List<SearchAction> actions = searchService.actions(result);
506-
boolean first = true;
507-
for (final SearchAction action : actions) {
508-
final JButton button = new JButton(action.toString());
509-
button.addActionListener(ae -> {
510-
action.run();
511-
if (action.closesSearch()) {
512-
reset();
513-
}
514-
});
515-
button.addKeyListener(new SearchBarKeyAdapter());
516-
if (first) {
517-
detailsButtons.add(button, "grow, spanx");
518-
final JRootPane rootPane = this.getRootPane();
519-
if (rootPane != null) {
520-
rootPane.setDefaultButton(button);
521-
}
522-
first = false;
462+
// populate details pane
463+
detailsTitle.setText("<html><h2>" + highlightSearchUnderline(
464+
escapeHtml(result.name()), searchText) + "</h2>");
465+
detailsProps.removeAll();
466+
result.properties().forEach((k, v) -> {
467+
if (v != "") {
468+
if (k == null) {
469+
final JTextPane textPane = new JTextPane();
470+
textPane.setContentType("text/html");
471+
textPane.setText(highlightSearchBold(v, searchText));
472+
final Font font = UIManager.getFont("Label.font");
473+
final String bodyRule = "body { font-family: " + font
474+
.getFamily() + "; " + "font-size: " + font.getSize() +
475+
"pt; }";
476+
((HTMLDocument) textPane.getDocument()).getStyleSheet().addRule(
477+
bodyRule);
478+
textPane.setBorder(BorderFactory.createCompoundBorder(
479+
BorderFactory.createMatteBorder(1, 0, 1, 0, Color.DARK_GRAY),
480+
BorderFactory.createEmptyBorder(PAD, 0, PAD, 0)));
481+
textPane.setEditable(false);
482+
textPane.setOpaque(false);
483+
detailsProps.add(textPane, "growx, wmax 100%");
523484
}
524485
else {
525-
detailsButtons.add(button, "growx");
486+
final JLabel keyLabel = new JLabel("<html>" +
487+
"<strong style=\"color: gray;\">" + k +
488+
"&nbsp;&nbsp;</strong>");
489+
keyLabel.setFont(smaller(keyLabel.getFont(), 1));
490+
detailsProps.add(keyLabel, "growx, pad 0 0 10 0");
491+
final JTextArea valueField = new JTextArea();
492+
valueField.setText(v);
493+
valueField.setLineWrap(true);
494+
valueField.setWrapStyleWord(true);
495+
valueField.setEditable(false);
496+
valueField.setBackground(null);
497+
valueField.setBorder(null);
498+
detailsProps.add(valueField, "growx, wmax 100%");
499+
}
500+
}
501+
});
502+
detailsButtons.removeAll();
503+
final List<SearchAction> actions = searchService.actions(result);
504+
boolean first = true;
505+
for (final SearchAction action : actions) {
506+
final JButton button = new JButton(action.toString());
507+
button.addActionListener(ae -> {
508+
action.run();
509+
if (action.closesSearch()) {
510+
reset();
511+
}
512+
});
513+
button.addKeyListener(new SearchBarKeyAdapter());
514+
if (first) {
515+
detailsButtons.add(button, "grow, spanx");
516+
final JRootPane rootPane = this.getRootPane();
517+
if (rootPane != null) {
518+
rootPane.setDefaultButton(button);
526519
}
520+
first = false;
521+
}
522+
else {
523+
detailsButtons.add(button, "growx");
527524
}
528525
}
529526
});

0 commit comments

Comments
 (0)