Skip to content

Commit

Permalink
ADD: DatasetSelectorDialog() "OK" button changes:
Browse files Browse the repository at this point in the history
- renamed to "Open in Imagej"
- is disabled if there's any tree item selected,
  or non-selectable items are clicked
- ENTER key associated with the button
  • Loading branch information
xulman committed Nov 21, 2024
1 parent 4488228 commit 9f3f6a1
Showing 1 changed file with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.KeyEvent;
import java.io.File;
import java.net.URI;
import java.nio.file.Paths;
Expand All @@ -49,6 +50,7 @@
import java.util.function.Predicate;
import java.util.function.Supplier;

import javax.swing.KeyStroke;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFileChooser;
Expand Down Expand Up @@ -95,6 +97,8 @@
import net.imglib2.util.Pair;
import se.sawano.java.text.AlphanumericComparator;

import static javax.swing.JComponent.WHEN_IN_FOCUSED_WINDOW;

public class DatasetSelectorDialog {

/**
Expand Down Expand Up @@ -342,6 +346,10 @@ public void run(final Consumer<DataSelection> okCallback) {

// ok and cancel buttons
okBtn.addActionListener(e -> ok());
okBtn.registerKeyboardAction(a -> ok(),
"n5_open_button",
KeyStroke.getKeyStroke(KeyEvent.VK_ENTER,0,true),
WHEN_IN_FOCUSED_WINDOW);
cancelBtn.addActionListener(e -> cancel());
dialog.setVisible(true);
}
Expand Down Expand Up @@ -486,7 +494,7 @@ private JFrame buildDialog() {
cbot.anchor = GridBagConstraints.CENTER;
panel.add(messageLabel, cbot);

okBtn = new JButton("OK");
okBtn = new JButton("Open in Imagej");
cbot.gridx = 4;
cbot.ipadx = 20;
cbot.anchor = GridBagConstraints.EAST;
Expand All @@ -503,6 +511,15 @@ private JFrame buildDialog() {
panel.add(cancelBtn, cbot);

containerTree.addMouseListener(new NodePopupMenu(this).getPopupListener());
containerTree.addTreeSelectionListener(tsl -> {
if (containerTree.getSelectionCount() == 0) {
okBtn.setEnabled( false );
} else {
int selectedRow = containerTree.getSelectionRows()[0];
N5SwingTreeNode n = (N5SwingTreeNode)containerTree.getPathForRow(selectedRow).getLastPathComponent();
okBtn.setEnabled( selectionFilter.test(n.getMetadata()) );
}
});

dialog.pack();
return dialog;
Expand Down

0 comments on commit 9f3f6a1

Please sign in to comment.