use of org.magic.api.beans.MagicEdition 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.MagicEdition in project MtgDesktopCompanion by nicho92.
the class MTGSalvationDeckSniffer method getDeck.
@Override
public MagicDeck getDeck(RetrievableDeck info) throws IOException {
String url = info.getUrl() + "#Details:deck-export";
logger.debug("sniff url : " + url);
MagicDeck deck = new MagicDeck();
deck.setName(info.getName());
deck.setDateCreation(new Date());
Document d = Jsoup.connect(url).userAgent(getString("USER_AGENT")).get();
deck.setDescription(info.getUrl().toString() + "\n" + d.select("section.guide div").text());
for (Element a : d.select("span.deck-type")) deck.getTags().add(a.text());
String plainDeck = d.select("section.deck-export-section pre").get(1).text();
boolean sideboard = false;
List<String> elements = new ArrayList<>(Arrays.asList(plainDeck.split("\n")));
elements.remove(0);
for (String s : elements) {
if (s.toLowerCase().startsWith("sideboard")) {
sideboard = true;
} else if (s.length() > 1) {
try {
int qte = Integer.parseInt(s.substring(0, s.indexOf(' ')));
String cardName = s.substring(s.indexOf(' '), s.length()).trim();
MagicEdition ed = null;
if (cardName.trim().equalsIgnoreCase("Plains") || cardName.trim().equalsIgnoreCase("Island") || cardName.trim().equalsIgnoreCase("Swamp") || cardName.trim().equalsIgnoreCase("Mountain") || cardName.trim().equalsIgnoreCase("Forest")) {
ed = new MagicEdition();
ed.setId(MTGControler.getInstance().get("default-land-deck"));
}
MagicCard mc = MTGControler.getInstance().getEnabledProviders().searchCardByCriteria("name", cardName, ed, true).get(0);
if (!sideboard) {
deck.getMap().put(mc, qte);
} else {
deck.getMapSideBoard().put(mc, qte);
}
} catch (Exception e) {
logger.error(e);
}
}
}
return deck;
}
use of org.magic.api.beans.MagicEdition in project MtgDesktopCompanion by nicho92.
the class TCGPlayerDeckSniffer method getDeck.
@Override
public MagicDeck getDeck(RetrievableDeck info) throws IOException {
logger.debug("get deck at " + info.getUrl());
MagicDeck deck = new MagicDeck();
deck.setName(info.getName());
deck.setDescription(info.getUrl().toString());
deck.setDateCreation(new Date());
Document d = Jsoup.connect(info.getUrl().toString()).userAgent(getString("USER_AGENT")).get();
for (Element e : d.select("span.singleTag")) {
deck.getTags().add(e.text());
}
Elements main = d.getElementsByClass("subdeck");
int taille = main.get(0).getElementsByClass("subdeck-group__card-qty").size();
for (int i = 0; i < taille; i++) {
int qte = Integer.parseInt(main.get(0).getElementsByClass("subdeck-group__card-qty").get(i).text());
String cardName = main.get(0).getElementsByClass("subdeck-group__card-name").get(i).text();
MagicEdition ed = null;
if (cardName.trim().equalsIgnoreCase("Plains") || cardName.trim().equalsIgnoreCase("Island") || cardName.trim().equalsIgnoreCase("Swamp") || cardName.trim().equalsIgnoreCase("Mountain") || cardName.trim().equalsIgnoreCase("Forest")) {
ed = new MagicEdition();
ed.setId(MTGControler.getInstance().get("default-land-deck"));
}
if (cardName.contains("//"))
cardName = cardName.substring(0, cardName.indexOf("//")).trim();
MagicCard mc = MTGControler.getInstance().getEnabledProviders().searchCardByCriteria("name", cardName, ed, true).get(0);
deck.getMap().put(mc, qte);
}
if (main.size() > 1) {
int tailleSide = main.get(1).getElementsByClass("subdeck-group__card-qty").size();
for (int i = 0; i < tailleSide; i++) {
int qte = Integer.parseInt(main.get(1).getElementsByClass("subdeck-group__card-qty").get(i).text());
String cardName = main.get(1).getElementsByClass("subdeck-group__card-name").get(i).text();
MagicEdition ed = null;
if (cardName.trim().equalsIgnoreCase("Plains") || cardName.trim().equalsIgnoreCase("Island") || cardName.trim().equalsIgnoreCase("Swamp") || cardName.trim().equalsIgnoreCase("Mountain") || cardName.trim().equalsIgnoreCase("Forest")) {
ed = new MagicEdition();
ed.setId(MTGControler.getInstance().get("default-land-deck"));
}
if (cardName.contains("//"))
cardName = cardName.substring(0, cardName.indexOf("//")).trim();
MagicCard mc = MTGControler.getInstance().getEnabledProviders().searchCardByCriteria("name", cardName, ed, true).get(0);
deck.getMapSideBoard().put(mc, qte);
}
}
return deck;
}
use of org.magic.api.beans.MagicEdition in project MtgDesktopCompanion by nicho92.
the class Apprentice2DeckExport method importDeck.
@Override
public MagicDeck importDeck(File f) throws IOException {
try (BufferedReader read = new BufferedReader(new FileReader(f))) {
MagicDeck deck = new MagicDeck();
deck.setName(f.getName().substring(0, f.getName().indexOf('.')));
String line = read.readLine();
int ecart = 0;
while (line != null) {
line = line.trim();
if (!line.startsWith("//")) {
String[] elements = line.split(getString("SEPARATOR"));
MagicEdition ed = null;
try {
ed = new MagicEdition();
ed.setId(elements[3]);
} catch (Exception e) {
ed = null;
ecart = 1;
}
String name = elements[2 - ecart].replaceAll("\"", "");
MagicCard mc = MTGControler.getInstance().getEnabledProviders().searchCardByCriteria("name", name, ed, true).get(0);
Integer qte = Integer.parseInt(elements[1 - ecart]);
if (line.startsWith("SB"))
deck.getMapSideBoard().put(mc, qte);
else
deck.getMap().put(mc, qte);
}
line = read.readLine();
}
return deck;
}
}
use of org.magic.api.beans.MagicEdition in project MtgDesktopCompanion by nicho92.
the class CSVExport method importDeck.
@Override
public MagicDeck importDeck(File f) throws IOException {
try (BufferedReader read = new BufferedReader(new FileReader(f))) {
MagicDeck deck = new MagicDeck();
deck.setName(f.getName().substring(0, f.getName().indexOf('.')));
String line = read.readLine();
line = read.readLine();
while (line != null) {
String[] part = line.split(getString("importDeckCharSeparator"));
String name = part[0];
String qte = part[1];
String set = part[2];
MagicEdition ed = new MagicEdition();
ed.setId(set);
List<MagicCard> list = MTGControler.getInstance().getEnabledProviders().searchCardByCriteria("name", name, ed, true);
deck.getMap().put(list.get(0), Integer.parseInt(qte));
line = read.readLine();
}
return deck;
}
}
Aggregations