use of mage.game.GameException in project mage by magefree.
the class UpdateDeckTask method btnLoadActionPerformed.
// GEN-LAST:event_btnSaveActionPerformed
private void btnLoadActionPerformed(java.awt.event.ActionEvent evt) {
// GEN-FIRST:event_btnLoadActionPerformed
// fcSelectDeck.setCurrentDirectory(new File());
String lastFolder = MageFrame.getPreferences().get(LAST_DECK_FOLDER, "");
if (!lastFolder.isEmpty()) {
fcSelectDeck.setCurrentDirectory(new File(lastFolder));
}
int ret = fcSelectDeck.showOpenDialog(this);
if (ret == JFileChooser.APPROVE_OPTION) {
File file = fcSelectDeck.getSelectedFile();
{
/**
* Work around a JFileChooser bug on Windows 7-10 with JRT 7+ In
* the case where the user selects the exact same file as was
* previously selected without touching anything else in the
* dialog, getSelectedFile() will erroneously return null due to
* some combination of our settings.
*
* We manually sub in the last selected file in this case.
*/
if (file == null) {
if (!lastFolder.isEmpty()) {
file = new File(lastFolder);
}
}
}
MageFrame.getDesktop().setCursor(new Cursor(Cursor.WAIT_CURSOR));
try {
Deck newDeck = null;
StringBuilder errorMessages = new StringBuilder();
newDeck = Deck.load(DeckImporter.importDeckFromFile(file.getPath(), errorMessages, true), true, true);
processAndShowImportErrors(errorMessages);
if (newDeck != null) {
deck = newDeck;
refreshDeck(true);
}
// save last deck history
try {
MageFrame.getPreferences().put(LAST_DECK_FOLDER, file.getCanonicalPath());
} catch (IOException ex) {
logger.error("Error on save last load deck folder: " + ex.getMessage());
}
} catch (GameException ex) {
JOptionPane.showMessageDialog(MageFrame.getDesktop(), ex.getMessage(), "Error loading deck", JOptionPane.ERROR_MESSAGE);
} finally {
MageFrame.getDesktop().setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
}
}
fcSelectDeck.setSelectedFile(null);
}
Aggregations