Search in sources :

Example 31 with MagicDeck

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

the class ExportsProviderTests method testExports.

public void testExports(MTGCardsExport p) {
    System.out.println("*****************************" + p.getName());
    System.out.println("EXT  " + p.getFileExtension());
    System.out.println("STAT " + p.getStatut());
    System.out.println("PROP " + p.getProperties());
    System.out.println("TYPE " + p.getType());
    System.out.println("ENAB " + p.isEnable());
    System.out.println("ICON " + p.getIcon());
    System.out.println("VERS " + p.getVersion());
    MagicDeck d = new MagicDeck();
    d.setDateCreation(new Date());
    d.setDescription("Test of " + p);
    d.setTags(Arrays.asList("test", p.getName(), "mtgdesktopcompanion"));
    d.setName("TEST " + p);
    d.getMap().put(mc, 40);
    d.getMapSideBoard().put(mc, 10);
    File destD = new File("target", d.getName() + " DECK " + p.getFileExtension());
    File destL = new File("target", d.getName() + " LIST " + p.getFileExtension());
    try {
        p.export(d, destD);
        System.out.println(p + " export Deck OK");
    } catch (Exception e) {
        System.out.println(p + " export Deck ERROR " + e);
    }
    try {
        p.export(d.getAsList(), destL);
        System.out.println(p + " export List OK");
    } catch (Exception e) {
        System.out.println(p + " export List ERROR " + e);
    }
    File destS = new File("target", d.getName() + " STOCK " + p.getFileExtension());
    List<MagicCardStock> stocks = new ArrayList<>();
    MagicCardStock s = new MagicCardStock();
    s.setMagicCard(mc);
    s.setAltered(false);
    s.setFoil(false);
    s.setSigned(false);
    s.setCondition(EnumCondition.LIGHTLY_PLAYED);
    s.setLanguage("English");
    s.setMagicCollection(new MagicCollection("TEST"));
    s.setQte(8);
    s.setPrice(9999.0);
    s.setComment("Test");
    stocks.add(s);
    try {
        p.exportStock(stocks, destS);
        System.out.println(p + " export Stock OK");
    } catch (Exception e) {
        e.printStackTrace();
        System.out.println(p + " export Stock ERROR" + e);
    }
    MagicDeck d2;
    try {
        d2 = p.importDeck(destD);
        System.out.println(d2 + " " + " import deck OK");
    } catch (Exception e) {
        System.out.println(p + " import deck ERROR " + e);
    }
    try {
        System.out.println(p.importStock(destS));
        System.out.println(p + " " + " import stock OK");
    } catch (Exception e) {
        System.out.println(p + " " + " import stock ERROR " + e);
    }
}
Also used : ArrayList(java.util.ArrayList) File(java.io.File) Date(java.util.Date) MkmException(org.api.mkm.exceptions.MkmException) MagicCollection(org.magic.api.beans.MagicCollection) MagicDeck(org.magic.api.beans.MagicDeck) MagicCardStock(org.magic.api.beans.MagicCardStock)

Example 32 with MagicDeck

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

the class DeckSnifferProviderTests method test.

public void test(MTGDeckSniffer p) {
    System.out.println("*****************************" + p.getName());
    System.out.println("STAT " + p.getStatut());
    System.out.println("PROP " + p.getProperties());
    System.out.println("TYPE " + p.getType());
    System.out.println("ENAB " + p.isEnable());
    System.out.println("FILT " + p.listFilter());
    System.out.println("VERS " + p.getVersion());
    try {
        List<RetrievableDeck> decks = p.getDeckList();
        System.out.println("Retrieve decklist OK");
        RetrievableDeck d = decks.get(0);
        MagicDeck deck = p.getDeck(d);
        System.out.println("Retrieve " + deck.getName() + " ok");
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : RetrievableDeck(org.magic.api.beans.RetrievableDeck) MagicDeck(org.magic.api.beans.MagicDeck)

Example 33 with MagicDeck

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

the class DeckDetailsPanel method initDataBindings.

protected BindingGroup initDataBindings() {
    BeanProperty<MagicDeck, String> nameProperty = BeanProperty.create("name");
    BeanProperty<JTextField, String> textProperty1 = BeanProperty.create("text");
    AutoBinding<MagicDeck, String, JTextField, String> autoBinding1 = Bindings.createAutoBinding(UpdateStrategy.READ_WRITE, magicDeck, nameProperty, nameJTextField, textProperty1);
    autoBinding1.bind();
    // 
    BeanProperty<MagicDeck, Integer> nbCardsProperty = BeanProperty.create("nbCards");
    BeanProperty<JProgressBar, Integer> textProperty4 = BeanProperty.create("value");
    AutoBinding<MagicDeck, Integer, JProgressBar, Integer> autoBinding2 = Bindings.createAutoBinding(UpdateStrategy.READ, magicDeck, nbCardsProperty, nbCardsProgress, textProperty4);
    autoBinding2.bind();
    nbCardsProgress.setString("" + magicDeck.getNbCards());
    nbSideProgress.setValue(magicDeck.getSideAsList().size());
    setLegalities();
    // 
    BeanProperty<MagicDeck, String> descriptionProperty = BeanProperty.create("description");
    BeanProperty<JTextArea, String> textProperty2 = BeanProperty.create("text");
    AutoBinding<MagicDeck, String, JTextArea, String> autoBinding3 = Bindings.createAutoBinding(UpdateStrategy.READ_WRITE, magicDeck, descriptionProperty, textArea, textProperty2);
    autoBinding3.bind();
    // 
    BeanProperty<MagicDeck, String> colorIdentityProperty = BeanProperty.create("colors");
    BeanProperty<ManaPanel, String> manaCostProperty3 = BeanProperty.create("manaCost");
    AutoBinding<MagicDeck, String, ManaPanel, String> autoBinding4 = Bindings.createAutoBinding(UpdateStrategy.READ, magicDeck, colorIdentityProperty, manaPanel, manaCostProperty3);
    autoBinding4.bind();
    // 
    BindingGroup bindingGroup = new BindingGroup();
    bindingGroup.addBinding(autoBinding1);
    bindingGroup.addBinding(autoBinding2);
    bindingGroup.addBinding(autoBinding3);
    bindingGroup.addBinding(autoBinding4);
    if (magicDeck != null && magicDeck.getDateCreation() != null) {
        DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, MTGControler.getInstance().getLocale());
        lblDateInformation.setText(df.format(magicDeck.getDateCreation()));
    }
    tagsPanel.clean();
    if (magicDeck != null)
        tagsPanel.bind(magicDeck.getTags());
    return bindingGroup;
}
Also used : JTextArea(javax.swing.JTextArea) JProgressBar(javax.swing.JProgressBar) JTextField(javax.swing.JTextField) BindingGroup(org.jdesktop.beansbinding.BindingGroup) DateFormat(java.text.DateFormat) MagicDeck(org.magic.api.beans.MagicDeck)

Example 34 with MagicDeck

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

the class DeckstatsDeckSniffer method getDeck.

@Override
public MagicDeck getDeck(RetrievableDeck info) throws IOException {
    // 
    MagicDeck deck = new MagicDeck();
    logger.debug("get deck " + info.getUrl());
    Document d = Jsoup.connect(info.getUrl().toString()).userAgent(getString("USER_AGENT")).timeout(getInt("TIMEOUT")).get();
    deck.setDescription(info.getUrl().toString());
    deck.setName(info.getName());
    deck.setDateCreation(new Date());
    for (Element a : d.select("a.deck_tags_list_tag")) deck.getTags().add(a.text());
    boolean side = false;
    Elements e = d.select("div#deck_overview_cards").select("div.deck_overview_section_chunk");
    for (Element block : e) {
        if (block.hasClass("deck_overview_section_chunk__sideboard"))
            side = true;
        else
            side = false;
        for (Element cont : block.select("div.deck_overview_card_header")) {
            Integer qte = Integer.parseInt(cont.getElementsByClass("deck_overview_card_amount").get(0).text());
            String cardName = cont.getElementsByClass("deck_overview_card_name").get(0).text().trim();
            if (cardName.contains("//"))
                cardName = cardName.substring(0, cardName.indexOf("//")).trim();
            MagicCard mc = null;
            if (cardName.trim().equalsIgnoreCase("Plains") || cardName.trim().equalsIgnoreCase("Island") || cardName.trim().equalsIgnoreCase("Swamp") || cardName.trim().equalsIgnoreCase("Mountain") || cardName.trim().equalsIgnoreCase("Forest")) {
                MagicEdition ed = new MagicEdition();
                ed.setId(MTGControler.getInstance().get("default-land-deck"));
                mc = MTGControler.getInstance().getEnabledProviders().searchCardByCriteria("name", cardName, ed, true).get(0);
            } else {
                mc = MTGControler.getInstance().getEnabledProviders().searchCardByCriteria("name", cardName, null, true).get(0);
            }
            if (side)
                deck.getMapSideBoard().put(mc, qte);
            else
                deck.getMap().put(mc, qte);
        }
    }
    if (d.select("div#deck_overview_info") != null)
        deck.setDescription(d.select("div#deck_overview_info").select("div.deck_text_editable_container").text());
    return deck;
}
Also used : MagicCard(org.magic.api.beans.MagicCard) Element(org.jsoup.nodes.Element) MagicEdition(org.magic.api.beans.MagicEdition) Document(org.jsoup.nodes.Document) Elements(org.jsoup.select.Elements) Date(java.util.Date) MagicDeck(org.magic.api.beans.MagicDeck)

Example 35 with MagicDeck

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

the class LotusNoirDecks method getDeck.

@Override
public MagicDeck getDeck(RetrievableDeck info) throws IOException {
    MagicDeck deck = new MagicDeck();
    logger.debug("get deck at " + info.getUrl());
    Document d = Jsoup.connect(info.getUrl().toString()).userAgent(getString("USER_AGENT")).timeout(Integer.parseInt(getString("TIMEOUT"))).get();
    deck.setDescription(info.getUrl().toString());
    deck.setName(info.getName());
    deck.setDateCreation(new Date());
    Elements e = d.select("div.demi_page>table").select(MTGConstants.HTML_TAG_TR);
    boolean sideboard = false;
    for (Element cont : e) {
        Elements cont2 = cont.select("span.card_title_us");
        if (cont.text().startsWith("R\u00E9serve"))
            sideboard = true;
        if (cont2.text().length() > 0) {
            Integer qte = Integer.parseInt(cont2.text().substring(0, cont2.text().indexOf(' ')));
            String cardName = cont2.text().substring(cont2.text().indexOf(' '), cont2.text().length()).trim();
            if (// for transformatble cards
            cardName.contains("//"))
                cardName = cardName.substring(0, cardName.indexOf("//")).trim();
            MagicCard mc = MTGControler.getInstance().getEnabledProviders().searchCardByCriteria("name", cardName, null, true).get(0);
            if (!sideboard)
                deck.getMap().put(mc, qte);
            else
                deck.getMapSideBoard().put(mc, qte);
        }
    }
    return deck;
}
Also used : MagicCard(org.magic.api.beans.MagicCard) Element(org.jsoup.nodes.Element) Document(org.jsoup.nodes.Document) Elements(org.jsoup.select.Elements) 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