27
27
28
28
import org .apache .log4j .Logger ;
29
29
import org .broad .igv .track .WindowFunction ;
30
+ import org .broad .igv .ui .util .FileDialogUtils ;
30
31
31
32
import javax .swing .*;
32
33
import javax .swing .border .EtchedBorder ;
@@ -44,8 +45,6 @@ public class IgvToolsGui extends JDialog {
44
45
45
46
private static Logger log = Logger .getLogger (IgvToolsGui .class );
46
47
47
- static JFileChooser fileDialog ;
48
-
49
48
public enum Tool {
50
49
COUNT ("Count" ),
51
50
SORT ("Sort" ),
@@ -80,71 +79,51 @@ public IgvToolsGui() {
80
79
initUI ();
81
80
updateUI ();
82
81
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 );
98
85
});
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 ) {
117
92
}
118
93
});
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 ) {
127
100
}
128
101
});
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 ());
131
106
updateUI ();
107
+ } catch (NullPointerException npe ) {
132
108
}
133
109
});
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 ) {
137
116
}
138
117
});
118
+ toolCombo .addActionListener (e -> updateUI ());
119
+ runButton .addActionListener (e -> run ());
139
120
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 ) {
148
127
}
149
128
});
150
129
}
@@ -582,29 +561,7 @@ private Collection<WindowFunction> getWindowFunctions() {
582
561
* @return
583
562
*/
584
563
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 );
608
565
}
609
566
610
567
public static void main (String [] args ) {
0 commit comments