Skip to content

Commit b5d96c9

Browse files
frauzufallctrueden
authored andcommitted
searchbar: layout improvements; default button
1 parent 11b8372 commit b5d96c9

File tree

2 files changed

+32
-19
lines changed

2 files changed

+32
-19
lines changed

src/main/java/org/scijava/search/web/WebSearchResult.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ public String iconPath() {
4343
public Map<String, String> properties() {
4444
final HashMap<String, String> properties = new HashMap<>();
4545
properties.put("name", name);
46-
properties.put("iconpath", iconPath);
46+
// properties.put("iconpath", iconPath);
4747
properties.put("url", url);
48-
properties.put("details", details);
48+
properties.put(null, "<body style='font-size: 11pt; font-family: Arial; background-color: #f4f4f7; padding: 10px 5px;'>.. " + details + " ..</body>");
4949
return properties;
5050
}
5151
}

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

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
import java.util.function.Function;
5252
import java.util.stream.Collectors;
5353

54+
import javax.swing.BorderFactory;
5455
import javax.swing.Box;
5556
import javax.swing.BoxLayout;
5657
import javax.swing.DefaultListModel;
@@ -61,6 +62,7 @@
6162
import javax.swing.JLabel;
6263
import javax.swing.JList;
6364
import javax.swing.JPanel;
65+
import javax.swing.JRootPane;
6466
import javax.swing.JScrollPane;
6567
import javax.swing.JSplitPane;
6668
import javax.swing.JTextField;
@@ -304,19 +306,16 @@ public SwingSearchPanel() {
304306

305307
final JPanel detailsPane = new JPanel();
306308
final JLabel detailsTitle = new JLabel();
307-
detailsTitle.setHorizontalAlignment(SwingConstants.CENTER);
309+
detailsTitle.setHorizontalAlignment(SwingConstants.LEFT);
308310
final JPanel detailsProps = new JPanel();
309311
final JPanel detailsButtons = new JPanel();
310312
detailsButtons.setLayout(new BoxLayout(detailsButtons, BoxLayout.X_AXIS));
311-
detailsTitle.setAlignmentX(0.5f);
312-
detailsProps.setAlignmentX(0.5f);
313-
detailsButtons.setAlignmentX(0.5f);
314313

315-
detailsPane.setLayout(new BoxLayout(detailsPane, BoxLayout.Y_AXIS));
314+
detailsPane.setLayout(new MigLayout("wrap","[grow]", "[][grow][]"));
315+
detailsPane.setBorder(BorderFactory.createEmptyBorder(PAD, PAD, PAD, PAD));
316316
detailsPane.add(detailsTitle);
317-
detailsPane.add(detailsProps);
318-
detailsPane.add(detailsButtons);
319-
detailsPane.add(Box.createVerticalGlue());
317+
detailsPane.add(detailsProps, "grow,span");
318+
detailsPane.add(detailsButtons, "grow");
320319

321320
resultsList.addListSelectionListener(lse -> {
322321
if (lse.getValueIsAdjusting()) return;
@@ -341,40 +340,54 @@ public SwingSearchPanel() {
341340
// populate details pane
342341
detailsTitle.setText("<html><h2>" + result.name() + "</h2>");
343342
detailsProps.removeAll();
344-
detailsProps.setLayout(new MigLayout("fillx,wrap 2", "[200px|pref]", "pref"));
343+
detailsProps.setLayout(new MigLayout("wrap 2, ins 0", "[123!][grow]", "pref"));
345344
result.properties().forEach((k, v) -> {
346345
if (k == null) {
347346
final JTextPane textPane = new JTextPane();
348347
textPane.setContentType("text/html");
349348
textPane.setText(v);
350-
detailsProps.add(textPane, "span 2");
349+
textPane.setMargin(null);
350+
textPane.setEditable(false);
351+
textPane.setOpaque(false);
352+
detailsProps.add(textPane, "span 2, grow");
351353
}
352354
else {
353355
final JLabel keyLabel = new JLabel("<html>" +
354-
"<strong style=\"color: gray; padding-right: 5px\">" + k +
355-
"&nbsp;&nbsp;</strong>", SwingConstants.RIGHT);
356-
detailsProps.add(keyLabel);
356+
"<strong style=\"color: gray;\">" + k +
357+
"&nbsp;&nbsp;</strong>");
358+
keyLabel.setHorizontalAlignment( RIGHT );
359+
detailsProps.add(keyLabel, "grow");
357360
final JTextField valueField = new JTextField();
358361
valueField.setText(v);
359362
valueField.setEditable(false);
360363
valueField.setBackground(null);
361364
valueField.setBorder(null);
362-
detailsProps.add(valueField);
365+
detailsProps.add(valueField, "grow");
363366
}
364367
});
365368
detailsButtons.removeAll();
366369
final List<SearchAction> actions = searchService.actions(result);
367-
actions.forEach(action -> {
370+
boolean first = true;
371+
for(SearchAction action : actions){
372+
if(!first){
373+
detailsButtons.add(Box.createHorizontalStrut(5));
374+
}
368375
final JButton button = new JButton(action.toString());
369376
button.addActionListener(ae -> {
370377
action.run();
371378
if(action.willCloseSearch()){
372-
reset();
379+
reset();
373380
}
374381
});
375382
button.addKeyListener(new SearchBarKeyAdapter());
376383
detailsButtons.add(button);
377-
});
384+
if(first){
385+
JRootPane rootPane = this.getRootPane();
386+
rootPane.setDefaultButton(button);
387+
detailsButtons.add(Box.createHorizontalGlue());
388+
first = false;
389+
}
390+
}
378391
}
379392
});
380393

0 commit comments

Comments
 (0)