use of org.magic.api.beans.MagicEdition in project MtgDesktopCompanion by nicho92.
the class CollectionPanelGUI method initPopupCollection.
public void initPopupCollection() throws SQLException {
popupMenuEdition = new JPopupMenu();
popupMenuCards = new JPopupMenu();
JMenu menuItemAdd = new JMenu(MTGControler.getInstance().getLangService().getCapitalize("ADD_MISSING_CARDS_IN"));
JMenu menuItemMove = new JMenu(MTGControler.getInstance().getLangService().getCapitalize("MOVE_CARD_TO"));
for (MagicCollection mc : dao.getCollections()) {
JMenuItem adds = new JMenuItem(mc.getName());
JMenuItem movs = new JMenuItem(mc.getName());
movs.addActionListener(e -> {
DefaultMutableTreeNode nodeCol = ((DefaultMutableTreeNode) path.getPathComponent(1));
DefaultMutableTreeNode nodeCd = ((DefaultMutableTreeNode) path.getPathComponent(3));
MagicCard card = (MagicCard) nodeCd.getUserObject();
MagicCollection oldCol = (MagicCollection) nodeCol.getUserObject();
final String collec = ((JMenuItem) e.getSource()).getText();
MagicCollection nmagicCol = new MagicCollection();
nmagicCol.setName(collec);
try {
dao.removeCard(card, oldCol);
dao.saveCard(card, nmagicCol);
nodeCd.removeFromParent();
nodeCol.add(new DefaultMutableTreeNode(card));
tree.refresh();
} catch (SQLException e1) {
logger.error(e1);
}
});
adds.addActionListener(e -> {
final String destinationCollection = ((JMenuItem) e.getSource()).getText();
ThreadManager.getInstance().execute(() -> {
try {
DefaultMutableTreeNode node = ((DefaultMutableTreeNode) path.getPathComponent(2));
MagicEdition me = (MagicEdition) node.getUserObject();
MagicCollection col = new MagicCollection();
col.setName(destinationCollection);
List<MagicCard> sets = provider.searchCardByCriteria("set", me.getId(), null, false);
MagicCollection sourceCol = new MagicCollection();
sourceCol.setName(node.getPath()[1].toString());
List<MagicCard> list = dao.listCardsFromCollection(sourceCol, me);
sets.removeAll(list);
for (MagicCard m : sets) dao.saveCard(m, col);
tree.refresh();
} catch (Exception e1) {
MTGLogger.printStackTrace(e1);
}
}, "btnAdds addCardsCollection");
});
menuItemAdd.add(adds);
menuItemMove.add(movs);
}
JMenuItem menuItemOpen = new JMenuItem(MTGControler.getInstance().getLangService().getCapitalize("OPEN"));
menuItemOpen.addActionListener(e -> {
MagicCollection col = (MagicCollection) ((DefaultMutableTreeNode) path.getPathComponent(1)).getUserObject();
MagicEdition edition = (MagicEdition) ((DefaultMutableTreeNode) path.getPathComponent(2)).getUserObject();
try {
CardSearchPanel.getInstance().open(MTGControler.getInstance().getEnabledDAO().listCardsFromCollection(col, edition));
} catch (SQLException e1) {
logger.error(e1);
}
});
popupMenuEdition.add(menuItemOpen);
JMenuItem it = new JMenuItem(MTGControler.getInstance().getLangService().getCapitalize("MASS_MOVEMENTS"));
it.addActionListener(e -> {
MagicCollection col = (MagicCollection) ((DefaultMutableTreeNode) path.getPathComponent(1)).getUserObject();
MagicEdition edition = (MagicEdition) ((DefaultMutableTreeNode) path.getPathComponent(2)).getUserObject();
MassMoverDialog d = new MassMoverDialog(col, edition);
d.setVisible(true);
logger.debug("closing mass import with change =" + d.hasChange());
});
popupMenuEdition.add(it);
popupMenuEdition.add(menuItemAdd);
popupMenuCards.add(menuItemMove);
}
use of org.magic.api.beans.MagicEdition in project MtgDesktopCompanion by nicho92.
the class MagicWebSiteGenerator method generateEditionsTemplate.
private void generateEditionsTemplate(Set<MagicEdition> eds, MagicCollection col) throws IOException, SQLException, TemplateException {
Template cardTemplate = cfg.getTemplate("page-ed.html");
Map rootEd = new HashMap<>();
rootEd.put("cols", cols);
rootEd.put("editions", eds);
rootEd.put("col", col);
rootEd.put("colName", col.getName());
for (MagicEdition ed : eds) {
rootEd.put("cards", dao.listCardsFromCollection(col, ed));
rootEd.put("edition", ed);
FileWriter out = new FileWriter(Paths.get(dest, "page-ed-" + col.getName() + "-" + ed.getId() + ".htm").toFile());
cardTemplate.process(rootEd, out);
}
}
use of org.magic.api.beans.MagicEdition in project MtgDesktopCompanion by nicho92.
the class IconSetProvider method initCache.
private void initCache() throws IOException {
for (MagicEdition e : MTGControler.getInstance().getEnabledProviders().loadEditions()) {
BufferedImage im = extract(e.getId().toUpperCase());
cache24.put(e.getId(), new ImageIcon(im.getScaledInstance(24, 24, Image.SCALE_SMOOTH)));
cache16.put(e.getId(), new ImageIcon(im.getScaledInstance(16, 16, Image.SCALE_SMOOTH)));
}
}
use of org.magic.api.beans.MagicEdition in project MtgDesktopCompanion by nicho92.
the class JSONHttpServer method start.
@Override
public void start() throws IOException {
port(getInt("SERVER-PORT"));
exception(Exception.class, new ExceptionHandler<Exception>() {
@Override
public void handle(Exception exception, Request req, Response res) {
res.status(500);
res.body("{\"error\":\"" + exception + "\"}");
}
});
notFound((req, res) -> {
res.status(404);
return "{\"error\":\"not found\"}";
});
before("/*", (request, response) -> {
response.type(getString("MIME"));
logger.info("Received api call from " + request.ip());
});
get("/cards/search/:att/:val", getString("MIME"), (request, response) -> {
return MTGControler.getInstance().getEnabledProviders().searchCardByCriteria(request.params(":att"), request.params(":val"), null, false);
}, transformer);
post("/cards/move/:from/:to/:id", getString("MIME"), (request, response) -> {
MagicCollection from = new MagicCollection(request.params(":from"));
MagicCollection to = new MagicCollection(request.params(":to"));
MagicCard mc = MTGControler.getInstance().getEnabledProviders().getCardById(request.params(":id"));
MTGControler.getInstance().getEnabledDAO().removeCard(mc, from);
MTGControler.getInstance().getEnabledDAO().saveCard(mc, to);
return "OK";
}, transformer);
get("/cards/list/:col/:idEd", getString("MIME"), (request, response) -> {
MagicCollection col = new MagicCollection(request.params(":col"));
MagicEdition ed = new MagicEdition();
ed.setId(request.params(":idEd"));
ed.setSet(request.params(":idEd"));
return MTGControler.getInstance().getEnabledDAO().listCardsFromCollection(col, ed);
}, transformer);
get("/cards/:id", getString("MIME"), (request, response) -> {
return MTGControler.getInstance().getEnabledProviders().getCardById(request.params(":id"));
}, transformer);
get("/collections/list", getString("MIME"), (request, response) -> {
return MTGControler.getInstance().getEnabledDAO().getCollections();
}, transformer);
get("/collections/:name", getString("MIME"), (request, response) -> {
return MTGControler.getInstance().getEnabledDAO().getCollection(request.params(":name"));
}, transformer);
get("/editions/list", getString("MIME"), (request, response) -> {
return MTGControler.getInstance().getEnabledProviders().loadEditions();
}, transformer);
get("/editions/:idSet", getString("MIME"), (request, response) -> {
return MTGControler.getInstance().getEnabledProviders().getSetById(request.params(":idSet"));
}, transformer);
get("/editions/list/:colName", getString("MIME"), (request, response) -> {
List<MagicEdition> eds = new ArrayList<>();
List<String> list = MTGControler.getInstance().getEnabledDAO().getEditionsIDFromCollection(new MagicCollection(request.params(":colName")));
for (String s : list) eds.add(MTGControler.getInstance().getEnabledProviders().getSetById(s));
Collections.sort(eds);
return eds;
}, transformer);
get("/prices/:idSet/:name", getString("MIME"), (request, response) -> {
MagicCard mc = MTGControler.getInstance().getEnabledProviders().searchCardByCriteria("name", request.params(":name"), null, false).get(0);
MagicEdition ed = MTGControler.getInstance().getEnabledProviders().getSetById(request.params(":idSet"));
List<MagicPrice> pricesret = new ArrayList<>();
for (MTGPricesProvider prices : MTGControler.getInstance().getEnabledPricers()) pricesret.addAll(prices.getPrice(ed, mc));
return pricesret;
}, transformer);
if (getBoolean("ENABLE_GZIP")) {
after((request, response) -> {
response.header("Content-Encoding", "gzip");
});
}
Spark.init();
logger.info("Server start on port " + getString("SERVER-PORT"));
running = true;
}
use of org.magic.api.beans.MagicEdition in project MtgDesktopCompanion by nicho92.
the class CardsProviderTests method createCards.
@Before
public void createCards() {
mc = new MagicCard();
mc.setName("Black Lotus");
mc.setLayout("normal");
mc.setCost("{0}");
mc.setCmc(0);
mc.getTypes().add("Artifact");
mc.setReserved(true);
mc.setText("{T}, Sacrifice Black Lotus: Add three mana of any one color to your mana pool.");
mc.setRarity("Rare");
mc.setArtist("Christopher Rush");
mc.setNumber("232");
mc.setMciNumber("232");
ed = new MagicEdition();
ed.setId("lea");
ed.setSet("Limited Edition Alpha");
ed.setBorder("Black");
ed.setRarity("Rare");
ed.setArtist("Christopher Rush");
ed.setMultiverse_id("3");
ed.setNumber(mc.getNumber());
mc.getEditions().add(ed);
}
Aggregations