if(filename.lastIndexOf('.') == -1) { filename = filename.concat(".tmx"); }
    public void saveMap(String filename, boolean bSaveAs) {        if (bSaveAs || filename == null) {            JFileChooser ch;            if (filename == null) {                ch = new JFileChooser();            } else {                ch = new JFileChooser(filename);            }            MapWriter writers[] = (MapWriter[]) pluginLoader.getWriters();            for(int i = 0; i < writers.length; i++) {                try {                    ch.addChoosableFileFilter(new TiledFileFilter(                                writers[i].getFilter(), writers[i].getName()));                } catch (Exception e) {                    e.printStackTrace();                }            }            ch.addChoosableFileFilter(                    new TiledFileFilter(TiledFileFilter.FILTER_TMX));            if (ch.showSaveDialog(appFrame) == JFileChooser.APPROVE_OPTION) {                filename = ch.getSelectedFile().getAbsolutePath();            } else {                // User cancelled operation, do nothing                return;            }        }        try {            // Check if file exists            File exist = new File(filename);            if (exist.exists() && bSaveAs) {                int result = JOptionPane.showConfirmDialog(appFrame,                        "The file already exists. Are you sure you want to " +                        "overwrite it?", "Overwrite file?",                        JOptionPane.YES_NO_OPTION);                if (result != JOptionPane.OK_OPTION) {                    return;                }            }            MapHelper.saveMap(currentMap, filename);            currentMap.setFilename(filename);            updateRecent(filename);            undoStack.commitSave();            updateTitle();        } catch (Exception e) {            e.printStackTrace();            JOptionPane.showMessageDialog(appFrame,                    "Error while saving " + filename + ": " + e.toString(),                    "Error while saving map",                    JOptionPane.ERROR_MESSAGE);        }    }