Search in sources :

Example 26 with MagicCard

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

the class DCIDeckSheetExport method export.

@Override
public void export(MagicDeck deck, File dest) throws IOException {
    PdfReader reader = new PdfReader(new URL(getString("PDF_URL")));
    Document document = new Document(reader.getPageSize(1));
    PdfWriter writer;
    try {
        writer = PdfWriter.getInstance(document, new FileOutputStream(dest));
    } catch (DocumentException e) {
        throw new IOException(e.getMessage());
    }
    document.open();
    PdfContentByte cb = writer.getDirectContent();
    // copy first page to new pdf file
    PdfImportedPage page = writer.getImportedPage(reader, 1);
    document.newPage();
    cb.addTemplate(page, 0, 0);
    Font helvetica = new Font(FontFamily.HELVETICA, 12);
    BaseFont bfHelv = helvetica.getCalculatedBaseFont(false);
    cb.beginText();
    cb.setFontAndSize(bfHelv, 11);
    // HEADER
    cb.setTextMatrix(page.getWidth() - 51f, page.getHeight() - 49);
    cb.showText(getString("LAST_NAME").substring(0, 1).toUpperCase());
    cb.setTextMatrix(page.getWidth() / 3.2f, page.getHeight() - 73);
    if (!getString("FORCED_DATE").equalsIgnoreCase(""))
        cb.showText(getString("FORCED_DATE"));
    else
        cb.showText(new SimpleDateFormat(getString("DATE_FORMAT")).format(new Date()));
    cb.setTextMatrix(page.getWidth() / 1.48f, page.getHeight() - 73);
    cb.showText(getString("EVENT_NAME"));
    cb.setTextMatrix(page.getWidth() / 3.2f, page.getHeight() - 96);
    cb.showText(getString("LOCATION"));
    cb.setTextMatrix(page.getWidth() / 1.48f, page.getHeight() - 96);
    cb.showText(deck.getName());
    cb.setTextMatrix(page.getWidth() / 1.48f, page.getHeight() - 119);
    if (getString("DECK_DESIGNER").equals(""))
        cb.showText(getString("LAST_NAME") + " " + getString("FIRST_NAME"));
    else
        cb.showText(getString("DECK_DESIGNER"));
    // MAIN DECK
    int count = 0;
    for (MagicCard mc : deck.getMap().keySet()) {
        cb.setTextMatrix(page.getWidth() / 6.4f, page.getHeight() - 185 - count);
        cb.showText(deck.getMap().get(mc) + space + mc.getName());
        count += 18;
    }
    // CONTINUED and BASIC LAND
    if (getString("FILL_CONTINUED_LANDS").equalsIgnoreCase("true")) {
        count = 0;
        for (MagicCard mc : deck.getMap().keySet()) {
            if (mc.getTypes().contains("Land")) {
                cb.setTextMatrix(page.getWidth() / 1.7f, page.getHeight() - 185 - count);
                cb.showText(deck.getMap().get(mc) + space + mc.getName());
                count += 18;
            }
        }
    }
    // SIDEBOARD
    count = 0;
    for (MagicCard mc : deck.getMapSideBoard().keySet()) {
        cb.setTextMatrix(page.getWidth() / 1.7f, page.getHeight() - 418 - count);
        cb.showText(deck.getMapSideBoard().get(mc) + space + mc.getName());
        count += 18;
    }
    // BOTTOM card count
    cb.setTextMatrix((page.getWidth() / 2f) - 30, 45);
    cb.showText(String.valueOf(deck.getAsList().size()));
    cb.setTextMatrix(page.getWidth() - 70, 100);
    cb.showText(String.valueOf(deck.getSideAsList().size()));
    // LEFT TEXT
    cb.showTextAligned(PdfContentByte.ALIGN_LEFT, getString("LAST_NAME"), 52, 90, 90);
    cb.showTextAligned(PdfContentByte.ALIGN_LEFT, getString("FIRST_NAME"), 52, 295, 90);
    String dci = getString("DCI_NUMBER");
    count = 0;
    for (int i = 0; i < dci.length(); i++) {
        char c = dci.charAt(i);
        cb.showTextAligned(PdfContentByte.ALIGN_LEFT, String.valueOf(c), 52, (428 + count), 90);
        count += 22;
    }
    cb.endText();
    document.close();
}
Also used : PdfWriter(com.itextpdf.text.pdf.PdfWriter) PdfReader(com.itextpdf.text.pdf.PdfReader) IOException(java.io.IOException) Document(com.itextpdf.text.Document) URL(java.net.URL) Font(com.itextpdf.text.Font) BaseFont(com.itextpdf.text.pdf.BaseFont) Date(java.util.Date) PdfImportedPage(com.itextpdf.text.pdf.PdfImportedPage) MagicCard(org.magic.api.beans.MagicCard) FileOutputStream(java.io.FileOutputStream) DocumentException(com.itextpdf.text.DocumentException) BaseFont(com.itextpdf.text.pdf.BaseFont) PdfContentByte(com.itextpdf.text.pdf.PdfContentByte) SimpleDateFormat(java.text.SimpleDateFormat)

Example 27 with MagicCard

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

the class JsonExport method importDeck.

@Override
public MagicDeck importDeck(File f) throws IOException {
    JsonReader reader = new JsonReader(new FileReader(f));
    JsonObject root = new JsonParser().parse(reader).getAsJsonObject();
    MagicDeck deck = new MagicDeck();
    deck.setDateCreation(new Date());
    if (!root.get("name").isJsonNull())
        deck.setName(root.get("name").getAsString());
    if (!root.get("description").isJsonNull())
        deck.setDescription(root.get("description").getAsString());
    if (!root.get("tags").isJsonNull()) {
        JsonArray arr = root.get("tags").getAsJsonArray();
        for (int i = 0; i < arr.size(); i++) deck.getTags().add(arr.get(i).getAsString());
    }
    JsonArray main = root.get("main").getAsJsonArray();
    for (int i = 0; i < main.size(); i++) {
        JsonObject line = main.get(i).getAsJsonObject();
        int qte = line.get("qty").getAsInt();
        MagicCard mc = new Gson().fromJson(line.get("card"), MagicCard.class);
        deck.getMap().put(mc, qte);
    }
    JsonArray side = root.get("side").getAsJsonArray();
    for (int i = 0; i < side.size(); i++) {
        JsonObject line = side.get(i).getAsJsonObject();
        int qte = line.get("qty").getAsInt();
        MagicCard mc = new Gson().fromJson(line.get("card"), MagicCard.class);
        deck.getMapSideBoard().put(mc, qte);
    }
    return deck;
}
Also used : JsonArray(com.google.gson.JsonArray) MagicCard(org.magic.api.beans.MagicCard) JsonReader(com.google.gson.stream.JsonReader) JsonObject(com.google.gson.JsonObject) Gson(com.google.gson.Gson) FileReader(java.io.FileReader) Date(java.util.Date) JsonParser(com.google.gson.JsonParser) MagicDeck(org.magic.api.beans.MagicDeck)

Example 28 with MagicCard

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

the class MKMFileWantListExport method export.

@Override
public void export(MagicDeck deck, File dest) throws IOException {
    try (BufferedWriter bw = new BufferedWriter(new FileWriter(dest))) {
        for (MagicCard mc : deck.getMap().keySet()) {
            StringBuilder temp = new StringBuilder();
            temp.append(deck.getMap().get(mc)).append(" ").append(mc.getName()).append(" (").append(mc.getEditions().get(0).getSet()).append(")");
            bw.write(temp.toString() + "\n");
        }
        for (MagicCard mc : deck.getMapSideBoard().keySet()) {
            StringBuilder temp = new StringBuilder();
            if (mc.getEditions().get(0).getMkm_name() != null)
                temp.append(deck.getMapSideBoard().get(mc)).append(" ").append(mc.getName()).append(" (").append(mc.getEditions().get(0).getMkm_name()).append(")");
            else
                temp.append(deck.getMapSideBoard().get(mc)).append(" ").append(mc.getName()).append(" (").append(mc.getEditions().get(0).getSet()).append(")");
            bw.write(temp.toString() + "\n");
        }
    }
}
Also used : MagicCard(org.magic.api.beans.MagicCard) FileWriter(java.io.FileWriter) BufferedWriter(java.io.BufferedWriter)

Example 29 with MagicCard

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

the class MTGODeckExport 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("//") && line.length() > 0) {
                int sep = line.indexOf(' ');
                String name = line.substring(sep, line.length()).trim();
                String qte = line.substring(0, sep).trim();
                if (line.startsWith("SB: ")) {
                    line = line.replaceAll("SB: ", "");
                    sep = line.indexOf(' ');
                    name = line.substring(sep, line.length()).trim();
                    qte = line.substring(0, sep).trim();
                    List<MagicCard> list = MTGControler.getInstance().getEnabledProviders().searchCardByCriteria("name", name, null, true);
                    deck.getMapSideBoard().put(list.get(0), Integer.parseInt(qte));
                } else {
                    List<MagicCard> list = MTGControler.getInstance().getEnabledProviders().searchCardByCriteria("name", name, null, true);
                    deck.getMap().put(list.get(0), Integer.parseInt(qte));
                }
            }
            line = read.readLine();
        }
        return deck;
    }
}
Also used : MagicCard(org.magic.api.beans.MagicCard) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) MagicDeck(org.magic.api.beans.MagicDeck)

Example 30 with MagicCard

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

the class MTGODeckExport method export.

@Override
public void export(MagicDeck deck, File dest) throws IOException {
    StringBuilder temp = new StringBuilder();
    temp.append("//NAME: " + deck.getName() + " from MTGDeskTopCompanion\n");
    temp.append("\n//MAIN\n");
    for (MagicCard mc : deck.getMap().keySet()) {
        temp.append(deck.getMap().get(mc)).append(" ").append(mc.getName()).append("\n");
    }
    temp.append("\n//Sideboard\n");
    for (MagicCard mc : deck.getMapSideBoard().keySet()) {
        temp.append("SB: ").append(deck.getMapSideBoard().get(mc)).append(" ").append(mc.getName()).append("\n");
    }
    FileUtils.writeStringToFile(dest, temp.toString(), "UTF-8");
}
Also used : MagicCard(org.magic.api.beans.MagicCard)

Aggregations

MagicCard (org.magic.api.beans.MagicCard)106 MagicEdition (org.magic.api.beans.MagicEdition)40 ArrayList (java.util.ArrayList)31 IOException (java.io.IOException)28 MagicDeck (org.magic.api.beans.MagicDeck)21 MagicCollection (org.magic.api.beans.MagicCollection)14 SQLException (java.sql.SQLException)12 Date (java.util.Date)11 MagicCardStock (org.magic.api.beans.MagicCardStock)10 DisplayableCard (org.magic.game.gui.components.DisplayableCard)10 JsonArray (com.google.gson.JsonArray)8 List (java.util.List)8 FileReader (java.io.FileReader)7 Before (org.junit.Before)7 BufferedReader (java.io.BufferedReader)6 File (java.io.File)6 FileWriter (java.io.FileWriter)6 MalformedURLException (java.net.MalformedURLException)6 PreparedStatement (java.sql.PreparedStatement)6 ResultSet (java.sql.ResultSet)6