Skip to content

Commit b4a0e3d

Browse files
committed
Use native file dialog on MacOS for "igvtools" UI. Possibly fixes problem with Catalina.
1 parent ebe1273 commit b4a0e3d

File tree

1 file changed

+36
-79
lines changed

1 file changed

+36
-79
lines changed

src/main/java/org/broad/igv/tools/IgvToolsGui.java

Lines changed: 36 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
import org.apache.log4j.Logger;
2929
import org.broad.igv.track.WindowFunction;
30+
import org.broad.igv.ui.util.FileDialogUtils;
3031

3132
import javax.swing.*;
3233
import javax.swing.border.EtchedBorder;
@@ -44,8 +45,6 @@ public class IgvToolsGui extends JDialog {
4445

4546
private static Logger log = Logger.getLogger(IgvToolsGui.class);
4647

47-
static JFileChooser fileDialog;
48-
4948
public enum Tool {
5049
COUNT("Count"),
5150
SORT("Sort"),
@@ -80,71 +79,51 @@ public IgvToolsGui() {
8079
initUI();
8180
updateUI();
8281

83-
closeButton.addActionListener(new ActionListener() {
84-
public void actionPerformed(ActionEvent e) {
85-
close();
86-
setVisible(false);
87-
}
88-
});
89-
inputButton.addActionListener(new ActionListener() {
90-
public void actionPerformed(ActionEvent e) {
91-
try {
92-
File chosenFile = chooseFile();
93-
inputField.setText(chosenFile.getAbsolutePath());
94-
updateUI();
95-
} catch (NullPointerException npe) {
96-
}
97-
}
82+
closeButton.addActionListener(e -> {
83+
close();
84+
setVisible(false);
9885
});
99-
outputButton.addActionListener(new ActionListener() {
100-
public void actionPerformed(ActionEvent e) {
101-
try {
102-
File chosenFile = chooseFile();
103-
outputField.setText(chosenFile.getAbsolutePath());
104-
updateUI();
105-
} catch (NullPointerException npe) {
106-
}
107-
}
108-
});
109-
genomeButton.addActionListener(new ActionListener() {
110-
public void actionPerformed(ActionEvent e) {
111-
try {
112-
File chosenFile = chooseFile();
113-
genomeField.setText(chosenFile.getAbsolutePath());
114-
updateUI();
115-
} catch (NullPointerException npe) {
116-
}
86+
inputButton.addActionListener(e -> {
87+
try {
88+
File chosenFile = chooseFile();
89+
inputField.setText(chosenFile.getAbsolutePath());
90+
updateUI();
91+
} catch (NullPointerException npe) {
11792
}
11893
});
119-
probeButton.addActionListener(new ActionListener() {
120-
public void actionPerformed(ActionEvent e) {
121-
try {
122-
File chosenFile = chooseFile();
123-
probeField.setText(chosenFile.getAbsolutePath());
124-
updateUI();
125-
} catch (NullPointerException npe) {
126-
}
94+
outputButton.addActionListener(e -> {
95+
try {
96+
File chosenFile = chooseFile();
97+
outputField.setText(chosenFile.getAbsolutePath());
98+
updateUI();
99+
} catch (NullPointerException npe) {
127100
}
128101
});
129-
toolCombo.addActionListener(new ActionListener() {
130-
public void actionPerformed(ActionEvent e) {
102+
genomeButton.addActionListener(e -> {
103+
try {
104+
File chosenFile = chooseFile();
105+
genomeField.setText(chosenFile.getAbsolutePath());
131106
updateUI();
107+
} catch (NullPointerException npe) {
132108
}
133109
});
134-
runButton.addActionListener(new ActionListener() {
135-
public void actionPerformed(ActionEvent e) {
136-
run();
110+
probeButton.addActionListener(e -> {
111+
try {
112+
File chosenFile = chooseFile();
113+
probeField.setText(chosenFile.getAbsolutePath());
114+
updateUI();
115+
} catch (NullPointerException npe) {
137116
}
138117
});
118+
toolCombo.addActionListener(e -> updateUI());
119+
runButton.addActionListener(e -> run());
139120

140-
tempButton.addActionListener(new ActionListener() {
141-
public void actionPerformed(ActionEvent e) {
142-
try {
143-
File chosenFile = chooseFile();
144-
tmpDirectoryField.setText(chosenFile.getAbsolutePath());
145-
updateUI();
146-
} catch (NullPointerException npe) {
147-
}
121+
tempButton.addActionListener(e -> {
122+
try {
123+
File chosenFile = FileDialogUtils.chooseDirectory("Choose Directory:", lastDirectory);
124+
tmpDirectoryField.setText(chosenFile.getAbsolutePath());
125+
updateUI();
126+
} catch (NullPointerException npe) {
148127
}
149128
});
150129
}
@@ -582,29 +561,7 @@ private Collection<WindowFunction> getWindowFunctions() {
582561
* @return
583562
*/
584563
private File chooseFile() {
585-
586-
//TODO Override so you can specify the file type with a string array ex: {".wig", ".tdf"}
587-
588-
// if (fileDialog == null) {
589-
fileDialog = new JFileChooser();
590-
// }
591-
592-
if (lastDirectory != null) {
593-
fileDialog.setCurrentDirectory(lastDirectory);
594-
}
595-
596-
fileDialog.setMultiSelectionEnabled(false);
597-
598-
fileDialog.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
599-
600-
int returnVal = fileDialog.showDialog(this, "Select File");
601-
if (returnVal == JFileChooser.CANCEL_OPTION) {
602-
return null;
603-
} else {
604-
File selected = fileDialog.getSelectedFile();
605-
lastDirectory = selected.isDirectory() ? selected : selected.getParentFile();
606-
return selected;
607-
}
564+
return FileDialogUtils.chooseFile("Select File: ", lastDirectory, FileDialogUtils.LOAD);
608565
}
609566

610567
public static void main(String[] args) {

0 commit comments

Comments
 (0)