use of org.magic.api.beans.MagicCollection 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.MagicCollection in project MtgDesktopCompanion by nicho92.
the class HsqlDAO method getCollection.
@Override
public MagicCollection getCollection(String name) throws SQLException {
try (PreparedStatement pst = con.prepareStatement("select * from collections where name= ?")) {
pst.setString(1, name);
try (ResultSet rs = pst.executeQuery()) {
if (rs.next()) {
MagicCollection mc = new MagicCollection();
mc.setName(rs.getString("name"));
return mc;
}
return null;
}
}
}
use of org.magic.api.beans.MagicCollection in project MtgDesktopCompanion by nicho92.
the class HsqlDAO method listCollectionFromCards.
@Override
public List<MagicCollection> listCollectionFromCards(MagicCard mc) throws SQLException {
if (mc.getEditions().isEmpty())
throw new SQLException("No edition defined");
try (PreparedStatement pst = con.prepareStatement("SELECT COLLECTION FROM CARDS WHERE name=? and edition=?")) {
pst.setString(1, mc.getName());
pst.setString(2, mc.getEditions().get(0).getId());
logger.trace("SELECT COLLECTION FROM CARDS WHERE name='" + mc.getName() + "' and edition='" + mc.getEditions().get(0).getId() + "'");
try (ResultSet rs = pst.executeQuery()) {
List<MagicCollection> cols = new ArrayList<>();
while (rs.next()) {
MagicCollection col = new MagicCollection();
col.setName(rs.getString("COLLECTION"));
cols.add(col);
}
return cols;
}
}
}
use of org.magic.api.beans.MagicCollection in project MtgDesktopCompanion by nicho92.
the class HsqlDAO method getCollections.
@Override
public List<MagicCollection> getCollections() throws SQLException {
try (PreparedStatement pst = con.prepareStatement("select * from collections")) {
try (ResultSet rs = pst.executeQuery()) {
List<MagicCollection> colls = new ArrayList<>();
while (rs.next()) {
MagicCollection mc = new MagicCollection();
mc.setName(rs.getString(1));
colls.add(mc);
}
return colls;
}
}
}
use of org.magic.api.beans.MagicCollection in project MtgDesktopCompanion by nicho92.
the class MongoDbDAO method listStocks.
@Override
public List<MagicCardStock> listStocks(MagicCard mc, MagicCollection col) throws SQLException {
ArrayList<MagicCardStock> ret = new ArrayList<>();
BasicDBObject filter = new BasicDBObject(dbCardIDField, IDGenerator.generate(mc));
filter.put("stockItem.magicCollection.name", col.getName());
logger.debug(filter);
db.getCollection(colStocks, BasicDBObject.class).find(filter).forEach((Consumer<BasicDBObject>) result -> ret.add(deserialize(result.get(dbStockField).toString(), MagicCardStock.class)));
return ret;
}
Aggregations