private int selectSaveFile() {
        JFileChooser fc = new JFileChooser();
        FileNameExtensionFilter textFilter = new FileNameExtensionFilter("GenSim file", "gsm");

        fc.setFileFilter(textFilter);

        int chosen;
        boolean goodFile;
        do {
            goodFile = true;
            chosen = fc.showSaveDialog(MainWindow.this);

            if (chosen == JFileChooser.APPROVE_OPTION) {
                currentFile = fc.getSelectedFile();
                try {
                    String fileName = currentFile.getCanonicalPath();
                    if (!fileName.endsWith(".gsm")) {
                        currentFile = new File(fileName + ".gsm");
                    }
                } catch (IOException ex) {
                }
            }
            if (currentFile != null && currentFile.exists()) {
                int overwrite = JOptionPane.showConfirmDialog(MainWindow.this, "This file already exists. Overrite the current file?", "Warning!", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
                if (overwrite == JOptionPane.CANCEL_OPTION) {
                    goodFile = false;
                }
            }
        } while (!goodFile);

        return chosen;
    }