Search in sources :

Example 46 with MagicCard

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

the class MoveGraveyardActions method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    String res = JOptionPane.showInputDialog("How many card to discard ?");
    if (res != null) {
        int c = Integer.parseInt(res);
        List<MagicCard> disc = GamePanelGUI.getInstance().getPlayer().discardCardFromLibrary(c);
        for (MagicCard mc : disc) {
            GamePanelGUI.getInstance().getPanelGrave().addComponent(new DisplayableCard(mc, MTGControler.getInstance().getCardsDimension(), true));
        }
        GamePanelGUI.getInstance().getPanelGrave().postTreatment(null);
    }
}
Also used : MagicCard(org.magic.api.beans.MagicCard) DisplayableCard(org.magic.game.gui.components.DisplayableCard)

Example 47 with MagicCard

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

the class FlipActions method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    try {
        MagicCard mc = MTGControler.getInstance().getEnabledProviders().searchCardByCriteria("name", card.getMagicCard().getRotatedCardName(), card.getMagicCard().getEditions().get(0), true).get(0);
        card.setMagicCard(mc);
        BufferedImage bufferedImage = new BufferedImage(card.getWidth(), card.getHeight(), BufferedImage.TYPE_INT_RGB);
        AffineTransform tx = AffineTransform.getScaleInstance(-1, -1);
        tx.translate(-bufferedImage.getWidth(null), -bufferedImage.getHeight(null));
        AffineTransformOp op = new AffineTransformOp(tx, AffineTransformOp.TYPE_NEAREST_NEIGHBOR);
        bufferedImage = op.filter(bufferedImage, null);
        Graphics2D g2 = bufferedImage.createGraphics();
        g2.drawImage(card.getImageIcon().getImage(), tx, null);
        g2.dispose();
        card.setImage(new ImageIcon(bufferedImage));
        card.setRotated(true);
        card.revalidate();
        card.repaint();
        card.initActions();
        GamePanelGUI.getInstance().getPlayer().logAction("Flip " + card.getMagicCard());
    } catch (Exception ex) {
        logger.error(ex);
    }
}
Also used : ImageIcon(javax.swing.ImageIcon) MagicCard(org.magic.api.beans.MagicCard) AffineTransform(java.awt.geom.AffineTransform) BufferedImage(java.awt.image.BufferedImage) AffineTransformOp(java.awt.image.AffineTransformOp) Graphics2D(java.awt.Graphics2D)

Example 48 with MagicCard

use of org.magic.api.beans.MagicCard 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 49 with MagicCard

use of org.magic.api.beans.MagicCard 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 50 with MagicCard

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

the class MagicCardEditorPanel method initDataBindings.

protected BindingGroup initDataBindings() {
    BeanProperty<MagicCard, String> artistProperty = BeanProperty.create("artist");
    BeanProperty<JTextField, String> textProperty = BeanProperty.create("text");
    AutoBinding<MagicCard, String, JTextField, String> autoBinding = Bindings.createAutoBinding(UpdateStrategy.READ_WRITE, magicCard, artistProperty, artistJTextField, textProperty);
    autoBinding.bind();
    // 
    BeanProperty<MagicCard, String> costProperty = BeanProperty.create("cost");
    BeanProperty<JTextField, String> textProperty1 = BeanProperty.create("text");
    AutoBinding<MagicCard, String, JTextField, String> autoBinding2 = Bindings.createAutoBinding(UpdateStrategy.READ_WRITE, magicCard, costProperty, costJTextField, textProperty1);
    autoBinding2.bind();
    // 
    BeanProperty<MagicCard, String> flavorProperty = BeanProperty.create("flavor");
    BeanProperty<JTextField, String> textProperty2 = BeanProperty.create("text");
    AutoBinding<MagicCard, String, JTextField, String> autoBinding3 = Bindings.createAutoBinding(UpdateStrategy.READ_WRITE, magicCard, flavorProperty, flavorJTextField, textProperty2);
    autoBinding3.bind();
    // 
    BeanProperty<MagicCard, Boolean> flippableProperty = BeanProperty.create("flippable");
    BeanProperty<JCheckBox, Boolean> selectedProperty = BeanProperty.create("selected");
    AutoBinding<MagicCard, Boolean, JCheckBox, Boolean> autoBinding4 = Bindings.createAutoBinding(UpdateStrategy.READ_WRITE, magicCard, flippableProperty, flippableJCheckBox, selectedProperty);
    autoBinding4.bind();
    // 
    BeanProperty<MagicCard, String> gathererCodeProperty = BeanProperty.create("gathererCode");
    BeanProperty<JTextField, String> textProperty3 = BeanProperty.create("text");
    AutoBinding<MagicCard, String, JTextField, String> autoBinding5 = Bindings.createAutoBinding(UpdateStrategy.READ_WRITE, magicCard, gathererCodeProperty, gathererCodeJTextField, textProperty3);
    autoBinding5.bind();
    // 
    BeanProperty<MagicCard, Object> layoutProperty = BeanProperty.create("layout");
    BeanProperty<JComboBox, Object> selectedIndexProperty = BeanProperty.create("selectedItem");
    AutoBinding<MagicCard, Object, JComboBox, Object> autoBinding6 = Bindings.createAutoBinding(UpdateStrategy.READ_WRITE, magicCard, layoutProperty, layoutJComboBox, selectedIndexProperty);
    autoBinding6.bind();
    // 
    BeanProperty<MagicCard, Object> loyaltyProperty = BeanProperty.create("loyalty");
    BeanProperty<JTextField, Object> valueProperty1 = BeanProperty.create("value");
    AutoBinding<MagicCard, Object, JTextField, Object> autoBinding7 = Bindings.createAutoBinding(UpdateStrategy.READ_WRITE, magicCard, loyaltyProperty, loyaltyJTextField, valueProperty1);
    autoBinding7.bind();
    // 
    BeanProperty<MagicCard, String> mciNumberProperty = BeanProperty.create("mciNumber");
    BeanProperty<JTextField, String> textProperty4 = BeanProperty.create("text");
    AutoBinding<MagicCard, String, JTextField, String> autoBinding8 = Bindings.createAutoBinding(UpdateStrategy.READ_WRITE, magicCard, mciNumberProperty, mciNumberJTextField, textProperty4);
    autoBinding8.bind();
    // 
    BeanProperty<MagicCard, String> nameProperty = BeanProperty.create("name");
    BeanProperty<JTextField, String> textProperty5 = BeanProperty.create("text");
    AutoBinding<MagicCard, String, JTextField, String> autoBinding10 = Bindings.createAutoBinding(UpdateStrategy.READ_WRITE, magicCard, nameProperty, nameJTextField, textProperty5);
    autoBinding10.bind();
    // 
    BeanProperty<MagicCard, String> numberProperty = BeanProperty.create("number");
    BeanProperty<JTextField, Object> valueProperty3 = BeanProperty.create("text");
    AutoBinding<MagicCard, String, JTextField, Object> autoBinding11 = Bindings.createAutoBinding(UpdateStrategy.READ_WRITE, magicCard, numberProperty, numberJTextField, valueProperty3);
    autoBinding11.bind();
    // 
    BeanProperty<MagicCard, String> powerProperty = BeanProperty.create("power");
    BeanProperty<JTextField, Object> valueProperty4 = BeanProperty.create("text");
    AutoBinding<MagicCard, String, JTextField, Object> autoBinding13 = Bindings.createAutoBinding(UpdateStrategy.READ_WRITE, magicCard, powerProperty, powerJTextField, valueProperty4);
    autoBinding13.bind();
    // 
    BeanProperty<MagicCard, Object> rarityProperty = BeanProperty.create("rarity");
    BeanProperty<JComboBox, Object> selectedIndexProperty1 = BeanProperty.create("selectedItem");
    AutoBinding<MagicCard, Object, JComboBox, Object> autoBinding14 = Bindings.createAutoBinding(UpdateStrategy.READ_WRITE, magicCard, rarityProperty, rarityJComboBox, selectedIndexProperty1);
    autoBinding14.bind();
    // 
    BeanProperty<MagicCard, String> rotatedCardNameProperty = BeanProperty.create("rotatedCardName");
    BeanProperty<JTextField, String> textProperty7 = BeanProperty.create("text");
    AutoBinding<MagicCard, String, JTextField, String> autoBinding15 = Bindings.createAutoBinding(UpdateStrategy.READ_WRITE, magicCard, rotatedCardNameProperty, rotatedCardNameJTextField, textProperty7);
    autoBinding15.bind();
    // 
    BeanProperty<MagicCard, String> textProperty8 = BeanProperty.create("text");
    BeanProperty<JEditorPane, String> textProperty9 = BeanProperty.create("text");
    AutoBinding<MagicCard, String, JEditorPane, String> autoBinding16 = Bindings.createAutoBinding(UpdateStrategy.READ_WRITE, magicCard, textProperty8, textJEditorPane, textProperty9);
    autoBinding16.bind();
    // 
    BeanProperty<MagicCard, String> toughnessProperty = BeanProperty.create("toughness");
    BeanProperty<JTextField, Object> valueProperty5 = BeanProperty.create("text");
    AutoBinding<MagicCard, String, JTextField, Object> autoBinding17 = Bindings.createAutoBinding(UpdateStrategy.READ_WRITE, magicCard, toughnessProperty, toughnessJTextField, valueProperty5);
    autoBinding17.bind();
    // 
    BeanProperty<MagicCard, Boolean> tranformableProperty = BeanProperty.create("tranformable");
    BeanProperty<JCheckBox, Boolean> selectedProperty1 = BeanProperty.create("selected");
    AutoBinding<MagicCard, Boolean, JCheckBox, Boolean> autoBinding18 = Bindings.createAutoBinding(UpdateStrategy.READ_WRITE, magicCard, tranformableProperty, tranformableJCheckBox, selectedProperty1);
    autoBinding18.bind();
    // 
    BeanProperty<MagicCard, String> watermarksProperty = BeanProperty.create("watermarks");
    BeanProperty<JTextField, String> textProperty10 = BeanProperty.create("text");
    AutoBinding<MagicCard, String, JTextField, String> autoBinding19 = Bindings.createAutoBinding(UpdateStrategy.READ_WRITE, magicCard, watermarksProperty, watermarksJTextField, textProperty10);
    autoBinding19.bind();
    BindingGroup bindingGroup = new BindingGroup();
    // 
    bindingGroup.addBinding(autoBinding);
    bindingGroup.addBinding(autoBinding2);
    bindingGroup.addBinding(autoBinding3);
    bindingGroup.addBinding(autoBinding4);
    bindingGroup.addBinding(autoBinding5);
    bindingGroup.addBinding(autoBinding6);
    bindingGroup.addBinding(autoBinding7);
    bindingGroup.addBinding(autoBinding8);
    bindingGroup.addBinding(autoBinding10);
    bindingGroup.addBinding(autoBinding11);
    bindingGroup.addBinding(autoBinding13);
    bindingGroup.addBinding(autoBinding14);
    bindingGroup.addBinding(autoBinding15);
    bindingGroup.addBinding(autoBinding16);
    bindingGroup.addBinding(autoBinding17);
    bindingGroup.addBinding(autoBinding18);
    bindingGroup.addBinding(autoBinding19);
    return bindingGroup;
}
Also used : JComboBox(javax.swing.JComboBox) JTextField(javax.swing.JTextField) JCheckBox(javax.swing.JCheckBox) MagicCard(org.magic.api.beans.MagicCard) BindingGroup(org.jdesktop.beansbinding.BindingGroup) JEditorPane(javax.swing.JEditorPane)

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