Search in sources :

Example 26 with MagicDeck

use of org.magic.api.beans.MagicDeck in project MtgDesktopCompanion by nicho92.

the class PDFExport method exportStock.

@Override
public void exportStock(List<MagicCardStock> stock, File f) throws IOException {
    MagicDeck d = new MagicDeck();
    d.setName(f.getName());
    for (MagicCardStock mcs : stock) {
        d.getMap().put(mcs.getMagicCard(), mcs.getQte());
    }
    export(d, f);
}
Also used : MagicDeck(org.magic.api.beans.MagicDeck) MagicCardStock(org.magic.api.beans.MagicCardStock)

Example 27 with MagicDeck

use of org.magic.api.beans.MagicDeck in project MtgDesktopCompanion by nicho92.

the class WebsiteImportExport method importStock.

@Override
public List<MagicCardStock> importStock(File f) throws IOException {
    MagicDeck d = importDeck(f);
    List<MagicCardStock> ret = new ArrayList<>();
    for (MagicCard mc : d.getMap().keySet()) {
        MagicCardStock stock = new MagicCardStock();
        stock.setMagicCard(mc);
        stock.setQte(d.getMap().get(mc));
        stock.setUpdate(true);
        stock.setIdstock(-1);
        ret.add(stock);
    }
    return ret;
}
Also used : MagicCard(org.magic.api.beans.MagicCard) ArrayList(java.util.ArrayList) MagicDeck(org.magic.api.beans.MagicDeck) MagicCardStock(org.magic.api.beans.MagicCardStock)

Example 28 with MagicDeck

use of org.magic.api.beans.MagicDeck in project MtgDesktopCompanion by nicho92.

the class XMageDeckExport method importDeck.

@Override
public MagicDeck importDeck(File f) throws IOException {
    try (BufferedReader read = new BufferedReader(new FileReader(f))) {
        MagicDeck deck = new MagicDeck();
        deck.setName(f.getName().substring(0, f.getName().indexOf('.')));
        String line = read.readLine();
        while (line != null) {
            if (!line.startsWith("NAME:")) {
                if (!line.startsWith("SB:")) {
                    MagicEdition ed = new MagicEdition();
                    ed.setId(line.substring(line.indexOf('[') + 1, line.indexOf(':')));
                    String cardName = line.substring(line.indexOf(']') + 1, line.length()).trim();
                    int qte = Integer.parseInt(line.substring(0, line.indexOf('[')).trim());
                    MagicCard mc = MTGControler.getInstance().getEnabledProviders().searchCardByCriteria("name", cardName, ed, true).get(0);
                    deck.getMap().put(mc, qte);
                } else {
                    line = line.replace("SB:", "").trim();
                    MagicEdition ed = new MagicEdition();
                    ed.setId(line.substring(line.indexOf('[') + 1, line.indexOf(':')));
                    String cardName = line.substring(line.indexOf(']') + 1, line.length()).trim();
                    int qte = Integer.parseInt(line.substring(0, line.indexOf('[')).trim());
                    MagicCard mc = MTGControler.getInstance().getEnabledProviders().searchCardByCriteria("name", cardName, ed, true).get(0);
                    deck.getMap().put(mc, qte);
                }
            } else {
                deck.setName(line.replaceAll("NAME: ", ""));
            }
            line = read.readLine();
        }
        return deck;
    }
}
Also used : MagicCard(org.magic.api.beans.MagicCard) BufferedReader(java.io.BufferedReader) MagicEdition(org.magic.api.beans.MagicEdition) FileReader(java.io.FileReader) MagicDeck(org.magic.api.beans.MagicDeck)

Example 29 with MagicDeck

use of org.magic.api.beans.MagicDeck in project MtgDesktopCompanion by nicho92.

the class XMageDeckExport method exportStock.

@Override
public void exportStock(List<MagicCardStock> stock, File f) throws IOException {
    MagicDeck d = new MagicDeck();
    d.setName(f.getName());
    for (MagicCardStock mcs : stock) {
        d.getMap().put(mcs.getMagicCard(), mcs.getQte());
    }
    export(d, f);
}
Also used : MagicDeck(org.magic.api.beans.MagicDeck) MagicCardStock(org.magic.api.beans.MagicCardStock)

Example 30 with MagicDeck

use of org.magic.api.beans.MagicDeck in project MtgDesktopCompanion by nicho92.

the class AbstractCardExport method export.

@Override
public void export(List<MagicCard> cards, File f) throws IOException {
    MagicDeck d = new MagicDeck();
    d.setName("export " + getName() + " cards");
    d.setDescription(getName() + " export to " + f.getName());
    d.setDateCreation(new Date());
    int i = 0;
    for (MagicCard mc : cards) {
        d.add(mc);
        setChanged();
        notifyObservers(i++);
    }
    export(d, f);
}
Also used : MagicCard(org.magic.api.beans.MagicCard) Date(java.util.Date) MagicDeck(org.magic.api.beans.MagicDeck)

Aggregations

MagicDeck (org.magic.api.beans.MagicDeck)40 MagicCard (org.magic.api.beans.MagicCard)21 MagicCardStock (org.magic.api.beans.MagicCardStock)14 Date (java.util.Date)12 MagicEdition (org.magic.api.beans.MagicEdition)10 FileReader (java.io.FileReader)9 IOException (java.io.IOException)8 Document (org.jsoup.nodes.Document)7 Element (org.jsoup.nodes.Element)7 BufferedReader (java.io.BufferedReader)6 ArrayList (java.util.ArrayList)6 Elements (org.jsoup.select.Elements)6 BorderLayout (java.awt.BorderLayout)3 File (java.io.File)3 JsonArray (com.google.gson.JsonArray)2 JsonParser (com.google.gson.JsonParser)2 Dimension (java.awt.Dimension)2 SQLException (java.sql.SQLException)2 JButton (javax.swing.JButton)2 JFileChooser (javax.swing.JFileChooser)2