Search in sources :

Example 11 with MagicCard

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

the class ManaRepartitionPanel method init.

public void init(MagicDeck deck) {
    cards = new ArrayList<>();
    try {
        for (Entry<MagicCard, Integer> cci : deck.getMap().entrySet()) {
            MagicCard mc = cci.getKey();
            for (int i = 0; i < cci.getValue(); i++) cards.add(mc);
        }
    } catch (Exception e) {
        MTGLogger.printStackTrace(e);
    }
    refresh();
}
Also used : MagicCard(org.magic.api.beans.MagicCard)

Example 12 with MagicCard

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

the class MassCollectionImporterDialog method initGUI.

private void initGUI() throws SQLException {
    getContentPane().setLayout(new BorderLayout(0, 0));
    deck = new MagicDeck();
    JPanel panelCollectionInput = new JPanel();
    getContentPane().add(panelCollectionInput, BorderLayout.NORTH);
    JLabel lblImport = new JLabel(MTGControler.getInstance().getLangService().getCapitalize("IMPORT") + " ");
    panelCollectionInput.add(lblImport);
    List<MagicEdition> list = new ArrayList<>();
    try {
        list = MTGControler.getInstance().getEnabledProviders().loadEditions();
    } catch (IOException e2) {
        MTGLogger.printStackTrace(e2);
    }
    final JComboBox cboEditions = new JComboBox(list.toArray());
    cboEditions.setRenderer(new MagicEditionListRenderer());
    panelCollectionInput.add(cboEditions);
    List<MagicCollection> lc = MTGControler.getInstance().getEnabledDAO().getCollections();
    JLabel lblNewLabel = new JLabel(MTGControler.getInstance().getLangService().getCapitalize("BY"));
    panelCollectionInput.add(lblNewLabel);
    final JComboBox<String> cboByType = new JComboBox<>();
    cboByType.setModel(new DefaultComboBoxModel<String>(new String[] { "number", "name" }));
    panelCollectionInput.add(cboByType);
    JLabel lblIn = new JLabel("in");
    panelCollectionInput.add(lblIn);
    final JComboBox cboCollections = new JComboBox(lc.toArray());
    panelCollectionInput.add(cboCollections);
    JPanel panneauBas = new JPanel();
    getContentPane().add(panneauBas, BorderLayout.SOUTH);
    final JProgressBar progressBar = new JProgressBar();
    progressBar.setStringPainted(true);
    final JCheckBox checkNewOne = new JCheckBox(MTGControler.getInstance().getLangService().getCapitalize("IMPORT_OTHER_SERIE"));
    JButton btnInverse = new JButton("Inverse");
    btnInverse.addActionListener(e -> {
        MagicEdition ed = (MagicEdition) cboEditions.getSelectedItem();
        int max = ed.getCardCount();
        List<String> elements = Arrays.asList(txtNumbersInput.getText().replaceAll("\n", " ").replaceAll("  ", " ").trim().split(" "));
        List<String> edList = new ArrayList<>();
        for (int i = 1; i <= max; i++) edList.add(String.valueOf(i));
        edList.removeAll(elements);
        StringBuilder temp = new StringBuilder();
        for (String s : edList) temp.append(s).append(" ");
        txtNumbersInput.setText(temp.toString());
    });
    panneauBas.add(btnInverse);
    panneauBas.add(checkNewOne);
    JButton btnImport = new JButton(MTGControler.getInstance().getLangService().getCapitalize("IMPORT"));
    btnImport.addActionListener(e -> {
        final MagicEdition ed = (MagicEdition) cboEditions.getSelectedItem();
        final MagicCollection col = (MagicCollection) cboCollections.getSelectedItem();
        if (cboByType.getSelectedItem().equals("number"))
            ids = txtNumbersInput.getText().replaceAll("\n", " ").replaceAll("  ", " ").trim().split(" ");
        else
            ids = txtNumbersInput.getText().split("\n");
        progressBar.setMaximum(ids.length);
        ThreadManager.getInstance().execute(() -> {
            int i = 1;
            for (String id : ids) {
                try {
                    MagicCard mc = null;
                    if (cboByType.getSelectedItem().toString().equalsIgnoreCase("number"))
                        mc = MTGControler.getInstance().getEnabledProviders().getCardByNumber(id, ed);
                    else
                        mc = MTGControler.getInstance().getEnabledProviders().searchCardByCriteria("name", id.replaceAll("\n", " ").replaceAll("  ", " ").trim(), (MagicEdition) cboEditions.getSelectedItem(), true).get(0);
                    deck.add(mc);
                    MTGControler.getInstance().getEnabledDAO().saveCard(mc, col);
                    progressBar.setValue(i++);
                } catch (Exception e1) {
                    MTGLogger.printStackTrace(e1);
                }
            }
            JOptionPane.showMessageDialog(null, MTGControler.getInstance().getLangService().getCapitalize("X_ITEMS_IMPORTED", ids.length), MTGControler.getInstance().getLangService().getCapitalize("FINISHED"), JOptionPane.INFORMATION_MESSAGE);
            if (!checkNewOne.isSelected()) {
                setVisible(false);
                progressBar.setValue(0);
            }
        }, "btnImport importCards");
    });
    panneauBas.add(btnImport);
    panneauBas.add(progressBar);
    txtNumbersInput = new JTextPane();
    JScrollPane scrollPane = new JScrollPane();
    getContentPane().add(scrollPane, BorderLayout.CENTER);
    scrollPane.setViewportView(txtNumbersInput);
    setModal(true);
    setLocationRelativeTo(null);
}
Also used : JPanel(javax.swing.JPanel) MagicEdition(org.magic.api.beans.MagicEdition) ArrayList(java.util.ArrayList) JProgressBar(javax.swing.JProgressBar) JButton(javax.swing.JButton) JTextPane(javax.swing.JTextPane) BorderLayout(java.awt.BorderLayout) MagicCollection(org.magic.api.beans.MagicCollection) MagicDeck(org.magic.api.beans.MagicDeck) JScrollPane(javax.swing.JScrollPane) JComboBox(javax.swing.JComboBox) JLabel(javax.swing.JLabel) IOException(java.io.IOException) SQLException(java.sql.SQLException) IOException(java.io.IOException) JCheckBox(javax.swing.JCheckBox) MagicCard(org.magic.api.beans.MagicCard) MagicEditionListRenderer(org.magic.gui.renderer.MagicEditionListRenderer)

Example 13 with MagicCard

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

the class HandPanel method initThumbnails.

public void initThumbnails(final List<MagicCard> cards, final boolean activateCards, final boolean rightClick) {
    if (t != null && t.isAlive())
        t.stop();
    c.weightx = 1;
    c.weighty = 1;
    c.gridx = 0;
    c.gridy = 0;
    c.insets = new Insets(2, 2, 2, 2);
    c.anchor = GridBagConstraints.NORTHWEST;
    this.removeAll();
    index = 0;
    t = new Thread(() -> {
        for (MagicCard mc : cards) {
            if (d == null)
                d = MTGControler.getInstance().getCardsDimension();
            DisplayableCard lab = new DisplayableCard(mc, d, activateCards, rightClick);
            lab.setTappable(activateCards);
            try {
                if (mc.getEditions().get(0).getMultiverse_id() == "0")
                    lab.setText(mc.getName());
                addComponent(lab);
                revalidate();
            } catch (Exception e) {
                lab.setText(mc.getName());
                lab.setBorder(new LineBorder(Color.BLACK));
            }
        }
    });
    t.start();
}
Also used : Insets(java.awt.Insets) MagicCard(org.magic.api.beans.MagicCard) LineBorder(javax.swing.border.LineBorder)

Example 14 with MagicCard

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

the class DeckSideBoardSwitcherDialog method init.

private void init() {
    modMain.removeAllElements();
    modSide.removeAllElements();
    for (MagicCard mc : bckDeck.getAsList()) modMain.addElement(mc);
    for (MagicCard mc : bckDeck.getSideAsList()) modSide.addElement(mc);
    lblDecksize.setText("DeckSize : " + savedDeck.getNbCards());
}
Also used : MagicCard(org.magic.api.beans.MagicCard)

Example 15 with MagicCard

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

the class FileDAO method listCardsFromCollection.

@Override
public List<MagicCard> listCardsFromCollection(MagicCollection c, MagicEdition me) throws SQLException {
    File col = new File(new File(directory, CARDSDIR), c.getName());
    if (me != null)
        col = new File(col, removeCon(me.getId()));
    logger.debug("Load " + col);
    List<MagicCard> ret = new ArrayList<>();
    for (File f : FileUtils.listFilesAndDirs(col, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE)) {
        try {
            if (!f.isDirectory())
                ret.add(read(MagicCard.class, f));
        } catch (Exception e) {
            throw new SQLException(e);
        }
    }
    return ret;
}
Also used : MagicCard(org.magic.api.beans.MagicCard) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) File(java.io.File) SQLException(java.sql.SQLException) IOException(java.io.IOException)

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