/** * Writes the CLUE game data as XML to a file. * * @param defaultGameFile default file to offer as file choice for saving. * @param gameData CLUE game data to save * @return the chosen file were the game was saved or null if canceled or unable to save */ public static File writeToFile(File defaultGameFile, ClueGameData gameData) { JFileChooser chooser = new JFileChooser("ccgs/"); FileNameExtensionFilter filter = new FileNameExtensionFilter("Custom Clue Game (*.ccg)", "ccg"); chooser.setFileFilter(filter); chooser.setSelectedFile(defaultGameFile); int returnVal = chooser.showSaveDialog(null); if (returnVal != JFileChooser.APPROVE_OPTION) return null; File selectedFile = chooser.getSelectedFile(); if (!selectedFile.getName().endsWith(".ccg")) selectedFile = new File(selectedFile.getAbsolutePath() + ".ccg"); XMLTag rootTag = convertToXML(gameData); try { XMLWriter.writeXMLToFile(rootTag, selectedFile); return selectedFile; } catch (XMLException ex) { Messenger.error( ex, "Unable to write to save file: " + selectedFile.getAbsolutePath(), "Game Creation Save Error"); return null; } }