use of mage.cards.decks.importer.DeckImporter in project mage by magefree.
the class UpdateDeckTask method importFromFile.
private void importFromFile(java.awt.event.ActionEvent evt) {
String lastFolder = MageFrame.getPreferences().get("lastImportFolder", "");
if (!lastFolder.isEmpty()) {
fcImportDeck.setCurrentDirectory(new File(lastFolder));
}
int ret = fcImportDeck.showOpenDialog(this);
if (ret == JFileChooser.APPROVE_OPTION) {
File file = fcImportDeck.getSelectedFile();
MageFrame.getDesktop().setCursor(new Cursor(Cursor.WAIT_CURSOR));
try {
DeckImporter importer = DeckImporter.getDeckImporter(file.getPath());
if (importer != null) {
StringBuilder errorMessages = new StringBuilder();
Deck newDeck = null;
// file will be auto-fixed and saved on simple errors
newDeck = Deck.load(importer.importDeck(file.getPath(), errorMessages, true));
processAndShowImportErrors(errorMessages);
if (newDeck != null) {
deck = newDeck;
refreshDeck();
}
// save last deck import folder
try {
MageFrame.getPreferences().put("lastImportFolder", file.getCanonicalPath());
} catch (IOException ex) {
logger.error("Error on save last used import folder: " + ex.getMessage());
}
} else {
JOptionPane.showMessageDialog(MageFrame.getDesktop(), "Unknown deck format", "Error importing deck", JOptionPane.ERROR_MESSAGE);
}
} catch (Exception ex) {
logger.fatal(ex);
} finally {
MageFrame.getDesktop().setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
}
}
fcImportDeck.setSelectedFile(null);
}
Aggregations