Search in sources :

Example 66 with MagicEdition

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

the class CSVExport method importStock.

@Override
public List<MagicCardStock> importStock(File f) throws IOException {
    try (BufferedReader read = new BufferedReader(new FileReader(f))) {
        List<MagicCardStock> stock = new ArrayList<>();
        String line = read.readLine();
        line = read.readLine();
        while (line != null) {
            String[] part = line.split(";");
            MagicCardStock mcs = new MagicCardStock();
            MagicCard mc = MTGControler.getInstance().getEnabledProviders().searchCardByCriteria("name", part[1], null, true).get(0);
            for (MagicEdition ed : mc.getEditions()) if (ed.getSet().equals(part[2])) {
                mc.getEditions().add(0, ed);
                break;
            }
            mcs.setMagicCard(mc);
            mcs.setLanguage(part[3]);
            mcs.setQte(Integer.parseInt(part[4]));
            mcs.setCondition(EnumCondition.valueOf(part[5]));
            mcs.setFoil(Boolean.valueOf(part[6]));
            mcs.setAltered(Boolean.valueOf(part[7]));
            mcs.setSigned(Boolean.valueOf(part[8]));
            mcs.setMagicCollection(new MagicCollection(part[9]));
            mcs.setPrice(Double.valueOf(part[10]));
            try {
                mcs.setComment(part[11]);
            } catch (ArrayIndexOutOfBoundsException aioob) {
                mcs.setComment("");
            }
            mcs.setIdstock(-1);
            mcs.setUpdate(true);
            stock.add(mcs);
            line = read.readLine();
        }
        return stock;
    }
}
Also used : MagicCard(org.magic.api.beans.MagicCard) BufferedReader(java.io.BufferedReader) ArrayList(java.util.ArrayList) MagicEdition(org.magic.api.beans.MagicEdition) FileReader(java.io.FileReader) MagicCollection(org.magic.api.beans.MagicCollection) MagicCardStock(org.magic.api.beans.MagicCardStock)

Example 67 with MagicEdition

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

the class ScryFallPicturesProvider method getPicture.

@Override
public BufferedImage getPicture(MagicCard mc, MagicEdition ed) throws IOException {
    MagicEdition selected = ed;
    if (ed == null)
        selected = mc.getEditions().get(0);
    if (MTGControler.getInstance().getEnabledCache().getPic(mc, selected) != null) {
        logger.trace("cached " + mc + "(" + selected + ") found");
        return resizeCard(MTGControler.getInstance().getEnabledCache().getPic(mc, selected), newW, newH);
    }
    URL url = generateLink(mc, selected, false);
    HttpURLConnection connection = (HttpURLConnection) url.openConnection();
    connection.setInstanceFollowRedirects(true);
    connection.setRequestProperty("User-Agent", getString("USER_AGENT"));
    connection.connect();
    logger.debug("load pics " + connection.getURL().toString());
    try {
        BufferedImage bufferedImage = ImageIO.read(connection.getInputStream());
        if (bufferedImage != null)
            MTGControler.getInstance().getEnabledCache().put(bufferedImage, mc, selected);
        return resizeCard(bufferedImage, newW, newH);
    } catch (Exception e) {
        logger.error(e);
        return getBackPicture();
    }
}
Also used : HttpURLConnection(java.net.HttpURLConnection) MagicEdition(org.magic.api.beans.MagicEdition) URL(java.net.URL) BufferedImage(java.awt.image.BufferedImage) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException)

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