Search in sources :

Example 31 with MagicEdition

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

the class CacheProviderTests method createCards.

@Before
public void createCards() {
    mc = new MagicCard();
    mc.setName("Black Lotus");
    mc.setLayout("normal");
    mc.setCost("{0}");
    mc.setCmc(0);
    mc.getTypes().add("Artifact");
    mc.setReserved(true);
    mc.setText("{T}, Sacrifice Black Lotus: Add three mana of any one color to your mana pool.");
    mc.setRarity("Rare");
    mc.setArtist("Christopher Rush");
    mc.setId("c944c7dc960c4832604973844edee2a1fdc82d98");
    mc.setMciNumber("232");
    MagicEdition ed = new MagicEdition();
    ed.setId("lea");
    ed.setSet("Limited Edition Alpha");
    ed.setBorder("Black");
    ed.setRarity("Rare");
    ed.setArtist("Christopher Rush");
    ed.setMultiverse_id("3");
    ed.setNumber("232");
    mc.getEditions().add(ed);
}
Also used : MagicCard(org.magic.api.beans.MagicCard) MagicEdition(org.magic.api.beans.MagicEdition) Before(org.junit.Before)

Example 32 with MagicEdition

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

the class MagicCardsTreeCellRenderer method getTreeCellRendererComponent.

@Override
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean isLeaf, int row, boolean focused) {
    Component c = super.getTreeCellRendererComponent(tree, value, selected, expanded, isLeaf, row, focused);
    try {
        if (((DefaultMutableTreeNode) value).getUserObject() instanceof MagicEdition) {
            MagicEdition ed = (MagicEdition) ((DefaultMutableTreeNode) value).getUserObject();
            setIcon(IconSetProvider.getInstance().get16(ed.getId()));
        } else if (((DefaultMutableTreeNode) value).getUserObject() instanceof MagicCard) {
            MagicCard mc = (MagicCard) ((DefaultMutableTreeNode) value).getUserObject();
            setOpaque(false);
            setIcon(uncolor);
            if (mc.getFullType().toLowerCase().contains("artifact")) {
                setIcon(map.get("{X}"));
            }
            if (mc.getColors().size() == 1) {
                setIcon(map.get(ColorParser.parse(mc.getColors().get(0))));
            }
            if (mc.getColors().size() > 1) {
                setIcon(gold);
            }
            if (mc.getFullType().toLowerCase().contains("land")) {
                setIcon(uncolor);
            }
        } else {
            setIcon(back);
        }
        return c;
    } catch (Exception e) {
        return c;
    }
}
Also used : MagicCard(org.magic.api.beans.MagicCard) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) MagicEdition(org.magic.api.beans.MagicEdition) Component(java.awt.Component)

Example 33 with MagicEdition

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

the class DAOProviderTests method createCards.

@Before
public void createCards() {
    mc = new MagicCard();
    mc.setName("Black Lotus");
    mc.setLayout("normal");
    mc.setCost("{0}");
    mc.setCmc(0);
    mc.getTypes().add("Artifact");
    mc.setReserved(true);
    mc.setText("{T}, Sacrifice Black Lotus: Add three mana of any one color to your mana pool.");
    mc.setRarity("Rare");
    mc.setArtist("Christopher Rush");
    mc.setId("c944c7dc960c4832604973844edee2a1fdc82d98");
    mc.setMciNumber("232");
    MagicEdition ed = new MagicEdition();
    ed.setId("lea");
    ed.setSet("Limited Edition Alpha");
    ed.setBorder("Black");
    ed.setRarity("Rare");
    ed.setArtist("Christopher Rush");
    ed.setMultiverse_id("3");
    ed.setNumber("232");
    mc.getEditions().add(ed);
    col = new MagicCollection("TEST");
    MTGLogger.changeLevel(Level.ERROR);
}
Also used : MagicCard(org.magic.api.beans.MagicCard) MagicEdition(org.magic.api.beans.MagicEdition) MagicCollection(org.magic.api.beans.MagicCollection) Before(org.junit.Before)

Example 34 with MagicEdition

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

the class DeckModel method setValueAt.

@Override
public void setValueAt(Object aValue, int row, int column) {
    MagicCard mc = (this.t == TYPE.DECK) ? deck.getValueAt(row) : deck.getSideValueAt(row);
    if (column == 3) {
        MagicEdition ed = (MagicEdition) aValue;
        mc.getEditions().remove(ed);
        mc.getEditions().add(0, (MagicEdition) aValue);
    }
    if (column == 4)
        if (Integer.valueOf(aValue.toString()) == 0) {
            if (t == TYPE.DECK) {
                deck.getMap().remove(deck.getValueAt(row));
            } else {
                deck.getMapSideBoard().remove(deck.getValueAt(row));
            }
        } else {
            if (t == TYPE.DECK) {
                deck.getMap().put(deck.getValueAt(row), Integer.valueOf(aValue.toString()));
            } else {
                deck.getMapSideBoard().put(deck.getSideValueAt(row), Integer.valueOf(aValue.toString()));
            }
        }
    fireTableDataChanged();
}
Also used : MagicCard(org.magic.api.beans.MagicCard) MagicEdition(org.magic.api.beans.MagicEdition)

Example 35 with MagicEdition

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

the class MongoDbDAO method listCardsFromCollection.

@Override
public List<MagicCard> listCardsFromCollection(MagicCollection collection, MagicEdition me) throws SQLException {
    logger.debug("getCardsFromCollection " + collection + " " + me);
    BasicDBObject query = new BasicDBObject();
    List<MagicCard> ret = new ArrayList<>();
    List<BasicDBObject> obj = new ArrayList<>();
    obj.add(new BasicDBObject(dbColIDField, collection.getName()));
    if (me != null) {
        obj.add(new BasicDBObject(dbEditionField, me.getId().toUpperCase()));
        query.put("$and", obj);
    }
    db.getCollection(colCards, BasicDBObject.class).find(query).forEach((Consumer<BasicDBObject>) result -> ret.add(deserialize(result.get("card").toString(), MagicCard.class)));
    return ret;
}
Also used : NotImplementedException(org.apache.commons.lang3.NotImplementedException) Document(org.bson.Document) Arrays(java.util.Arrays) MagicCollection(org.magic.api.beans.MagicCollection) MongoCollection(com.mongodb.client.MongoCollection) MagicCardAlert(org.magic.api.beans.MagicCardAlert) Aggregates(com.mongodb.client.model.Aggregates) CodecRegistry(org.bson.codecs.configuration.CodecRegistry) MongoDatabase(com.mongodb.client.MongoDatabase) MagicCardStock(org.magic.api.beans.MagicCardStock) ArrayList(java.util.ArrayList) Bson(org.bson.conversions.Bson) STATUT(org.magic.api.interfaces.MTGCardsProvider.STATUT) Filters(com.mongodb.client.model.Filters) SQLException(java.sql.SQLException) MongoClientOptions(com.mongodb.MongoClientOptions) UpdateResult(com.mongodb.client.result.UpdateResult) Gson(com.google.gson.Gson) Map(java.util.Map) AbstractMagicDAO(org.magic.api.interfaces.abstracts.AbstractMagicDAO) CodecRegistries.fromRegistries(org.bson.codecs.configuration.CodecRegistries.fromRegistries) ServerAddress(com.mongodb.ServerAddress) PojoCodecProvider(org.bson.codecs.pojo.PojoCodecProvider) Accumulators(com.mongodb.client.model.Accumulators) MagicNews(org.magic.api.beans.MagicNews) CodecRegistries.fromProviders(org.bson.codecs.configuration.CodecRegistries.fromProviders) BasicDBObject(com.mongodb.BasicDBObject) IOException(java.io.IOException) File(java.io.File) Consumer(java.util.function.Consumer) List(java.util.List) MagicEdition(org.magic.api.beans.MagicEdition) TreeMap(java.util.TreeMap) IDGenerator(org.magic.tools.IDGenerator) MongoClient(com.mongodb.MongoClient) MagicCard(org.magic.api.beans.MagicCard) DeleteResult(com.mongodb.client.result.DeleteResult) BasicDBObject(com.mongodb.BasicDBObject) MagicCard(org.magic.api.beans.MagicCard) ArrayList(java.util.ArrayList)

Aggregations

MagicEdition (org.magic.api.beans.MagicEdition)67 MagicCard (org.magic.api.beans.MagicCard)38 IOException (java.io.IOException)24 ArrayList (java.util.ArrayList)18 MagicCollection (org.magic.api.beans.MagicCollection)11 MagicDeck (org.magic.api.beans.MagicDeck)10 JsonObject (com.google.gson.JsonObject)9 InputStreamReader (java.io.InputStreamReader)9 JsonReader (com.google.gson.stream.JsonReader)8 List (java.util.List)8 JsonParser (com.google.gson.JsonParser)7 MalformedURLException (java.net.MalformedURLException)7 SQLException (java.sql.SQLException)7 Date (java.util.Date)7 JLabel (javax.swing.JLabel)7 Before (org.junit.Before)7 JsonArray (com.google.gson.JsonArray)6 BufferedImage (java.awt.image.BufferedImage)6 URL (java.net.URL)6 Map (java.util.Map)6