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();
}
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);
}
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();
}
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());
}
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;
}
Aggregations