Search in sources :

Example 26 with MagicEdition

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

the class BoosterBoxDashlet method initGUI.

@Override
public void initGUI() {
    JSpinner boxSizeSpinner;
    JXTable table;
    BoostersTableModel boostersModel;
    DefaultListModel<MagicCard> cardsModel;
    JTextPane txtDetailBox;
    JPanel panneauHaut = new JPanel();
    getContentPane().add(panneauHaut, BorderLayout.NORTH);
    List<MagicEdition> eds = new ArrayList<>();
    try {
        eds.addAll(MTGControler.getInstance().getEnabledProviders().loadEditions());
        Collections.sort(eds);
        eds.add(0, null);
    } catch (Exception e) {
        MTGLogger.printStackTrace(e);
    }
    JComboBox<MagicEdition> cboEditions = new JComboBox<>(new DefaultComboBoxModel<MagicEdition>(eds.toArray(new MagicEdition[eds.size()])));
    cboEditions.setRenderer(new MagicEditionListRenderer());
    panneauHaut.add(cboEditions);
    JLabel lblBoxSize = new JLabel("Box size: ");
    panneauHaut.add(lblBoxSize);
    boxSizeSpinner = new JSpinner();
    boxSizeSpinner.setModel(new SpinnerNumberModel(36, 0, null, 1));
    panneauHaut.add(boxSizeSpinner);
    JScrollPane scrollPane = new JScrollPane();
    getContentPane().add(scrollPane, BorderLayout.CENTER);
    boostersModel = new BoostersTableModel();
    cardsModel = new DefaultListModel<>();
    table = new JXTable(boostersModel);
    scrollPane.setViewportView(table);
    JPanel panneauBas = new JPanel();
    getContentPane().add(panneauBas, BorderLayout.SOUTH);
    JButton btnCalculate = new JButton("Open");
    panneauBas.add(btnCalculate);
    JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
    getContentPane().add(tabbedPane, BorderLayout.EAST);
    txtDetailBox = new JTextPane();
    txtDetailBox.setEditable(false);
    tabbedPane.addTab("Box", null, txtDetailBox, null);
    JScrollPane scrollPane1 = new JScrollPane();
    tabbedPane.addTab("Booster", null, scrollPane1, null);
    JList<MagicCard> list1 = new JList<>();
    list1.setModel(cardsModel);
    list1.setCellRenderer(new MagicCardListRenderer());
    scrollPane1.setViewportView(list1);
    btnCalculate.addActionListener(e -> ThreadManager.getInstance().execute(() -> {
        try {
            List<CardShake> prices = MTGControler.getInstance().getEnabledDashBoard().getShakeForEdition((MagicEdition) cboEditions.getSelectedItem());
            boostersModel.clear();
            double total = 0;
            Map<String, Double> priceRarity = new HashMap<>();
            for (int i = 0; i < (int) boxSizeSpinner.getValue(); i++) {
                Booster booster = MTGControler.getInstance().getEnabledProviders().generateBooster((MagicEdition) cboEditions.getSelectedItem());
                Collections.reverse(booster.getCards());
                booster.setBoosterNumber(String.valueOf(i + 1));
                double price = 0;
                for (MagicCard mc : booster.getCards()) {
                    for (CardShake cs : prices) if (cs.getName().equalsIgnoreCase(mc.getName())) {
                        price += cs.getPrice();
                        booster.setPrice(price);
                        cs.setCard(mc);
                        String rarity = mc.getEditions().get(0).getRarity();
                        if (priceRarity.get(rarity) != null)
                            priceRarity.put(rarity, priceRarity.get(rarity) + cs.getPrice());
                        else
                            priceRarity.put(rarity, cs.getPrice());
                    }
                }
                boostersModel.addLine(booster);
                total = total + booster.getPrice();
                StringBuilder temp = new StringBuilder();
                temp.append("TOTAL: ").append(doubleFormat.format(total)).append("\n");
                for (Entry<String, Double> s : priceRarity.entrySet()) temp.append(s.getKey()).append(": ").append(doubleFormat.format(priceRarity.get(s.getKey()))).append("\n");
                txtDetailBox.setText(temp.toString());
            }
        } catch (Exception e1) {
            logger.error(e1);
        }
    }, "Open Box"));
    table.getSelectionModel().addListSelectionListener(event -> {
        if (!event.getValueIsAdjusting()) {
            int viewRow = table.getSelectedRow();
            if (viewRow > -1) {
                int modelRow = table.convertRowIndexToModel(viewRow);
                List<MagicCard> list = ((Booster) table.getModel().getValueAt(modelRow, 0)).getCards();
                cardsModel.clear();
                for (MagicCard mc : list) cardsModel.addElement(mc);
            }
        }
    });
    if (getProperties().size() > 0) {
        Rectangle r = new Rectangle((int) Double.parseDouble(getProperty("x")), (int) Double.parseDouble(getProperty("y")), (int) Double.parseDouble(getProperty("w")), (int) Double.parseDouble(getProperty("h")));
        setBounds(r);
    }
    setVisible(true);
}
Also used : JPanel(javax.swing.JPanel) JTabbedPane(javax.swing.JTabbedPane) MagicEdition(org.magic.api.beans.MagicEdition) ArrayList(java.util.ArrayList) JButton(javax.swing.JButton) Rectangle(java.awt.Rectangle) MagicCardListRenderer(org.magic.gui.renderer.MagicCardListRenderer) SpinnerNumberModel(javax.swing.SpinnerNumberModel) JTextPane(javax.swing.JTextPane) Entry(java.util.Map.Entry) ArrayList(java.util.ArrayList) JList(javax.swing.JList) List(java.util.List) BoostersTableModel(org.magic.gui.models.BoostersTableModel) CardShake(org.magic.api.beans.CardShake) JScrollPane(javax.swing.JScrollPane) JXTable(org.jdesktop.swingx.JXTable) JComboBox(javax.swing.JComboBox) Booster(org.magic.api.beans.Booster) JLabel(javax.swing.JLabel) MagicCard(org.magic.api.beans.MagicCard) JSpinner(javax.swing.JSpinner) HashMap(java.util.HashMap) Map(java.util.Map) MagicEditionListRenderer(org.magic.gui.renderer.MagicEditionListRenderer) JList(javax.swing.JList)

Example 27 with MagicEdition

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

the class EditionsDashlet method initGUI.

public void initGUI() {
    JPanel panel = new JPanel();
    getContentPane().add(panel, BorderLayout.NORTH);
    modEdition = new EditionsShakerTableModel();
    List<MagicEdition> eds = new ArrayList<>();
    try {
        eds.addAll(MTGControler.getInstance().getEnabledProviders().loadEditions());
        Collections.sort(eds);
        eds.add(0, null);
    } catch (Exception e) {
        MTGLogger.printStackTrace(e);
    }
    cboEditions = new JComboBox(new DefaultComboBoxModel<MagicEdition>(eds.toArray(new MagicEdition[eds.size()])));
    cboEditions.setRenderer(new MagicEditionListRenderer());
    panel.add(cboEditions);
    lblLoading = new JLabel("");
    lblLoading.setIcon(MTGConstants.ICON_LOADING);
    lblLoading.setVisible(false);
    panel.add(lblLoading);
    JScrollPane scrollPane = new JScrollPane();
    getContentPane().add(scrollPane, BorderLayout.CENTER);
    table = new JXTable(modEdition);
    initToolTip(table, 0, 1);
    table.getColumnModel().getColumn(3).setCellRenderer(new CardShakeRenderer());
    table.getColumnModel().getColumn(5).setCellRenderer(new CardShakeRenderer());
    scrollPane.setViewportView(table);
    setVisible(true);
    cboEditions.addActionListener(ae -> init());
    if (getProperties().size() > 0) {
        Rectangle r = new Rectangle((int) Double.parseDouble(getProperty("x")), (int) Double.parseDouble(getProperty("y")), (int) Double.parseDouble(getProperty("w")), (int) Double.parseDouble(getProperty("h")));
        MagicEdition ed;
        try {
            ed = MTGControler.getInstance().getEnabledProviders().getSetById(getProperty("EDITION"));
            cboEditions.setSelectedItem(ed);
        } catch (Exception e) {
            logger.error("Error retrieve editions", e);
        }
        setBounds(r);
    }
    try {
        table.packAll();
    } catch (Exception e) {
        MTGLogger.printStackTrace(e);
    }
    new TableFilterHeader(table, AutoChoices.ENABLED);
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) JComboBox(javax.swing.JComboBox) JXTable(org.jdesktop.swingx.JXTable) MagicEdition(org.magic.api.beans.MagicEdition) ArrayList(java.util.ArrayList) Rectangle(java.awt.Rectangle) JLabel(javax.swing.JLabel) DefaultComboBoxModel(javax.swing.DefaultComboBoxModel) TableFilterHeader(net.coderazzi.filters.gui.TableFilterHeader) CardShakeRenderer(org.magic.gui.renderer.CardShakeRenderer) EditionsShakerTableModel(org.magic.gui.models.EditionsShakerTableModel) MagicEditionListRenderer(org.magic.gui.renderer.MagicEditionListRenderer)

Example 28 with MagicEdition

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

the class MagicWebSiteGenerator method generateCollectionsTemplate.

// lister les editions disponibles
private void generateCollectionsTemplate() throws IOException, TemplateException, SQLException {
    Template generatedColTemplate = cfg.getTemplate("page-col.html");
    for (MagicCollection col : cols) {
        Map rootEd = new HashMap<>();
        rootEd.put("cols", cols);
        rootEd.put("colName", col.getName());
        Set<MagicEdition> eds = new HashSet<>();
        for (MagicCard mc : dao.listCardsFromCollection(col)) {
            eds.add(mc.getEditions().get(0));
            generateCardsTemplate(mc);
        }
        rootEd.put("editions", eds);
        FileWriter out = new FileWriter(Paths.get(dest, "page-col-" + col.getName() + ".htm").toFile());
        generatedColTemplate.process(rootEd, out);
        generateEditionsTemplate(eds, col);
        out.close();
    }
}
Also used : MagicCard(org.magic.api.beans.MagicCard) HashMap(java.util.HashMap) FileWriter(java.io.FileWriter) MagicEdition(org.magic.api.beans.MagicEdition) HashMap(java.util.HashMap) Map(java.util.Map) MagicCollection(org.magic.api.beans.MagicCollection) Template(freemarker.template.Template) HashSet(java.util.HashSet)

Example 29 with MagicEdition

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

the class BoosterPicturesProvider method getBoosterFor.

public Icon getBoosterFor(String id) {
    MagicEdition ed = new MagicEdition();
    ed.setId(id);
    return getBoosterFor(ed);
}
Also used : MagicEdition(org.magic.api.beans.MagicEdition)

Example 30 with MagicEdition

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

the class BoosterQtyPanel method initGUI.

private void initGUI() {
    setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
    List<MagicEdition> li = new ArrayList<>();
    try {
        li = MTGControler.getInstance().getEnabledProviders().loadEditions();
    } catch (IOException e1) {
        MTGLogger.printStackTrace(e1);
    }
    cboEditions = new JComboBox<>(new DefaultComboBoxModel<MagicEdition>(li.toArray(new MagicEdition[li.size()])));
    cboEditions.setRenderer(new MagicEditionListRenderer());
    add(cboEditions);
    spinner = new JSpinner();
    spinner.setModel(new SpinnerNumberModel(6, 0, null, 1));
    add(spinner);
}
Also used : SpinnerNumberModel(javax.swing.SpinnerNumberModel) FlowLayout(java.awt.FlowLayout) MagicEdition(org.magic.api.beans.MagicEdition) ArrayList(java.util.ArrayList) JSpinner(javax.swing.JSpinner) IOException(java.io.IOException) DefaultComboBoxModel(javax.swing.DefaultComboBoxModel) MagicEditionListRenderer(org.magic.gui.renderer.MagicEditionListRenderer)

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