Commits

beholdmyglory committed dfe02f1

Added *.wi file filter when saving and opening files

Comments (0)

Files changed (1)

src/se/kth/csc/inda11/remains/gui/MainWindow.java

 import javax.swing.KeyStroke;
 import javax.swing.event.ChangeEvent;
 import javax.swing.event.ChangeListener;
+import javax.swing.filechooser.FileNameExtensionFilter;
 
 import se.kth.csc.inda11.remains.file.FileParser;
 import se.kth.csc.inda11.remains.simulator.Simulator;
             @Override
             public void actionPerformed(ActionEvent e) {
                 JFileChooser fileChooser = new JFileChooser(".");
+                fileChooser.setFileFilter(new FileNameExtensionFilter("REMAINS save files (*.wi)", "wi"));
+                
                 if (fileChooser.showOpenDialog(MainWindow.this) == JFileChooser.APPROVE_OPTION) {
                     File f = fileChooser.getSelectedFile();
                     if (f.exists()) {
 			@Override
 			public void actionPerformed(ActionEvent e) {
                 JFileChooser fileChooser = new JFileChooser(".");
+                fileChooser.setFileFilter(new FileNameExtensionFilter("REMAINS save files (*.wi)", "wi"));
+                
                 if (fileChooser.showSaveDialog(MainWindow.this) == JFileChooser.APPROVE_OPTION) {
                     File f = fileChooser.getSelectedFile();
                     if (!f.exists() ||
                                 MainWindow.this.timer.stop();
                             }
                             
+                            // add file extension if missing
+                            if (!f.exists() && !f.getName().endsWith(".wi")) {
+                                f = new File(f.getAbsoluteFile() + ".wi");
+                            }
                             FileParser.saveFile(f, MainWindow.this.simulator);
                         } catch (IOException ex) {
                             JOptionPane.showMessageDialog(MainWindow.this,
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.