Search in sources :

Example 6 with GameException

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);
}
Also used : IOException(java.io.IOException) File(java.io.File) GameException(mage.game.GameException)

Aggregations

GameException (mage.game.GameException)6 IOException (java.io.IOException)2 Table (mage.game.Table)2 TournamentPlayer (mage.game.tournament.TournamentPlayer)2 TableManager (mage.server.managers.TableManager)2 File (java.io.File)1 SecureRandom (java.security.SecureRandom)1 UUID (java.util.UUID)1 Deck (mage.cards.decks.Deck)1 DeckCardLists (mage.cards.decks.DeckCardLists)1 CardInfo (mage.cards.repository.CardInfo)1 ExpansionInfo (mage.cards.repository.ExpansionInfo)1 TournamentPlayerPanel (mage.client.table.TournamentPlayerPanel)1 IgnoreList (mage.client.util.IgnoreList)1 DraftOptions (mage.game.draft.DraftOptions)1 LimitedOptions (mage.game.tournament.LimitedOptions)1 TournamentOptions (mage.game.tournament.TournamentOptions)1 TournamentTypeView (mage.view.TournamentTypeView)1