Chris@2
|
1 /* Performance Worm: Visualisation of Expressive Musical Performance
|
Chris@2
|
2 Copyright (C) 2001, 2006 by Simon Dixon
|
Chris@2
|
3
|
Chris@2
|
4 This program is free software; you can redistribute it and/or modify
|
Chris@2
|
5 it under the terms of the GNU General Public License as published by
|
Chris@2
|
6 the Free Software Foundation; either version 2 of the License, or
|
Chris@2
|
7 (at your option) any later version.
|
Chris@2
|
8
|
Chris@2
|
9 This program is distributed in the hope that it will be useful,
|
Chris@2
|
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
|
Chris@2
|
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
Chris@2
|
12 GNU General Public License for more details.
|
Chris@2
|
13
|
Chris@2
|
14 You should have received a copy of the GNU General Public License along
|
Chris@2
|
15 with this program (the file gpl.txt); if not, download it from
|
Chris@2
|
16 http://www.gnu.org/licenses/gpl.txt or write to the
|
Chris@2
|
17 Free Software Foundation, Inc.,
|
Chris@2
|
18 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
Chris@2
|
19 */
|
Chris@2
|
20
|
Chris@2
|
21 package at.ofai.music.worm;
|
Chris@2
|
22
|
Chris@2
|
23 import javax.swing.JFileChooser;
|
Chris@2
|
24 import javax.swing.JOptionPane;
|
Chris@2
|
25 import java.awt.TextField;
|
Chris@2
|
26 import java.io.File;
|
Chris@2
|
27 import javax.swing.filechooser.FileFilter;
|
Chris@2
|
28
|
Chris@2
|
29 public class MyFileChooser extends JFileChooser {
|
Chris@2
|
30
|
Chris@2
|
31 static final long serialVersionUID = 0; // silence compiler warning
|
Chris@2
|
32
|
Chris@2
|
33 public MyFileChooser() {
|
Chris@2
|
34 super(".");
|
Chris@2
|
35 addChoosableFileFilter(MyFileFilter.mp3Filter);
|
Chris@2
|
36 addChoosableFileFilter(MyFileFilter.waveFilter);
|
Chris@2
|
37 addChoosableFileFilter(MyFileFilter.matchFilter);
|
Chris@2
|
38 addChoosableFileFilter(MyFileFilter.wormFilter);
|
Chris@2
|
39 addChoosableFileFilter(getAcceptAllFileFilter());
|
Chris@2
|
40 } // constructor
|
Chris@2
|
41
|
Chris@2
|
42 public String browseOpen(TextField t, FileFilter ff) {
|
Chris@2
|
43 setSelectedFile(new File(t.getText()));
|
Chris@2
|
44 setFileFilter(ff);
|
Chris@2
|
45 if (showOpenDialog(null) == JFileChooser.APPROVE_OPTION)
|
Chris@2
|
46 t.setText(getSelectedFile().getAbsolutePath());
|
Chris@2
|
47 return t.getText();
|
Chris@2
|
48 } // browseOpen()
|
Chris@2
|
49
|
Chris@2
|
50 public String browseSave() {
|
Chris@2
|
51 // setSelectedFile(s);
|
Chris@2
|
52 setFileFilter(MyFileFilter.wormFilter);
|
Chris@2
|
53 if (showSaveDialog(null) == JFileChooser.APPROVE_OPTION) {
|
Chris@2
|
54 if (!getSelectedFile().exists() || (
|
Chris@2
|
55 JOptionPane.showConfirmDialog(null, "File " +
|
Chris@2
|
56 getSelectedFile().getAbsolutePath() +
|
Chris@2
|
57 " exists.\nDo you want to replace it?",
|
Chris@2
|
58 "Are you sure?", JOptionPane.YES_NO_OPTION) ==
|
Chris@2
|
59 JOptionPane.YES_OPTION))
|
Chris@2
|
60 return getSelectedFile().getAbsolutePath();
|
Chris@2
|
61 }
|
Chris@2
|
62 return null;
|
Chris@2
|
63 } // browseSave()
|
Chris@2
|
64
|
Chris@2
|
65 } // class MyFileChooser
|