01: // This file is part of KeY - Integrated Deductive Software Design
02: // Copyright (C) 2001-2007 Universitaet Karlsruhe, Germany
03: // Universitaet Koblenz-Landau, Germany
04: // Chalmers University of Technology, Sweden
05: //
06: // The KeY system is protected by the GNU General Public License.
07: // See LICENSE.TXT for details.
08: //
09: //
10:
11: package de.uka.ilkd.key.gui;
12:
13: import java.io.File;
14:
15: import javax.swing.JFileChooser;
16:
17: public class KeYFileChooser {
18:
19: JFileChooser fileChooser;
20:
21: public KeYFileChooser() {
22: fileChooser = new JFileChooser(new File(System
23: .getProperty("user.dir")));
24: fileChooser
25: .setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
26: fileChooser
27: .setFileFilter(new javax.swing.filechooser.FileFilter() {
28: public boolean accept(File f) {
29: return f.isDirectory()
30: || f.toString().endsWith(".key")
31: || f.toString().endsWith(".java")
32: || f.toString().endsWith(".proof");
33: }
34:
35: public String getDescription() {
36: return "KeY and JML files";
37: }
38: });
39: }
40:
41: public void prepare() {
42: File selFile = fileChooser.getSelectedFile();
43: if ((selFile != null) && selFile.isFile()) { // present & not dir.
44: String filename = selFile.getAbsolutePath();
45: if (!filename.endsWith(".proof"))
46: fileChooser.setSelectedFile(new File(filename
47: + ".proof"));
48: }
49: }
50:
51: public void setDialogTitle(String title) {
52: if (title != null) {
53: fileChooser.setDialogTitle(title);
54: } else {
55: fileChooser.setDialogTitle("Select file to load");
56: }
57: }
58:
59: public boolean showSaveDialog(Main main) {
60: int result = fileChooser.showSaveDialog(main);
61: return (result == JFileChooser.APPROVE_OPTION);
62: }
63:
64: public boolean showOpenDialog(Main main) {
65: int result = fileChooser.showOpenDialog(main);
66: return (result == JFileChooser.APPROVE_OPTION);
67: }
68:
69: public File getSelectedFile() {
70: return fileChooser.getSelectedFile();
71: }
72:
73: public void selectFile(File f) {
74: fileChooser.setSelectedFile(f);
75: }
76:
77: }
|