use of org.magic.gui.renderer.MagicEditionListRenderer in project MtgDesktopCompanion by nicho92.
the class CardSearchPanel method initGUI.
private void initGUI() {
logger.info("init search GUI");
JPanel panelResultsCards;
JPanel panelFilters;
JPanel panelmana;
JPanel editionDetailPanel;
JPanel panneauHaut;
JPanel panneauCard;
JPanel panneauStat;
JTextField txtFilter;
JComboBox<MagicEdition> cboEdition;
TableFilterHeader filterHeader;
JButton btnClear;
JButton btnSearch;
JButton btnFilter;
DefaultRowSorter<DefaultTableModel, Integer> sorterCards;
DefaultRowSorter<DefaultTableModel, Integer> sorterPrice = new TableRowSorter<>(priceModel);
sorterCards = new TableRowSorter<>(cardsModeltable);
sorterCards.setComparator(7, (String num1, String num2) -> {
try {
num1 = num1.replaceAll("a", "").replaceAll("b", "").trim();
num2 = num2.replaceAll("a", "").replaceAll("b", "").trim();
if (Integer.parseInt(num1) > Integer.parseInt(num2))
return 1;
else
return -1;
} catch (NumberFormatException e) {
return -1;
}
});
List<MagicEdition> li = new ArrayList<>();
try {
li = MTGControler.getInstance().getEnabledProviders().loadEditions();
Collections.sort(li);
} catch (Exception e2) {
logger.error("error no edition loaded", e2);
}
// //////INIT COMPONENTS
JScrollPane scrollEditions = new JScrollPane();
JScrollPane scrollThumbnails = new JScrollPane();
JScrollPane scrollPaneRules = new JScrollPane();
JScrollPane scrollPanePrices = new JScrollPane();
JScrollPane scrollCards = new JScrollPane();
JSplitPane panneauCentral = new JSplitPane();
panneauStat = new JPanel();
panneauHaut = new JPanel();
panneauCard = new JPanel();
editionDetailPanel = new JPanel();
panelResultsCards = new JPanel();
cmcChart = new CmcChartPanel();
manaRepartitionPanel = new ManaRepartitionPanel();
typeRepartitionPanel = new TypeRepartitionPanel();
historyChartPanel = new HistoryPricesPanel();
cardsPicPanel = new CardsPicPanel();
rarityRepartitionPanel = new RarityRepartitionPanel();
detailCardPanel = new MagicCardDetailPanel(new MagicCard());
panelmana = new JPanel();
panelFilters = new JPanel();
ManaPanel pan = new ManaPanel();
panelJson = new JSONPanel();
tabbedCardsView = new JTabbedPane(JTabbedPane.TOP);
tabbedCardsInfo = new JTabbedPane(JTabbedPane.TOP);
thumbnailPanel = new HandPanel();
thumbnailPanel.setBackground(MTGConstants.THUMBNAIL_BACKGROUND_COLOR);
btnSearch = new JButton(MTGConstants.ICON_SEARCH);
btnExport = new JButton(MTGConstants.ICON_EXPORT);
btnFilter = new JButton(MTGConstants.ICON_FILTER);
btnClear = new JButton(MTGConstants.ICON_CLEAR);
cboQuereableItems = new JComboBox<>(new DefaultComboBoxModel<String>(MTGControler.getInstance().getEnabledProviders().getQueryableAttributs()));
try {
cboCollections = new JComboBox<>(new DefaultComboBoxModel<MagicCollection>(MTGControler.getInstance().getEnabledDAO().getCollections().toArray(new MagicCollection[MTGControler.getInstance().getEnabledDAO().getCollections().size()])));
} catch (SQLException e2) {
logger.error("could not load collections combobox", e2);
}
cboLanguages = new JComboBox<>();
tablePrice = new JXTable();
tableCards = new JXTable();
lblLoading = new JLabel(MTGConstants.ICON_LOADING);
JLabel lblFilter = new JLabel();
listEdition = new JList<>();
txtMagicSearch = new JTextField();
txtRulesArea = new JTextArea();
txtFilter = new JTextField();
filterHeader = new TableFilterHeader(tableCards, AutoChoices.ENABLED);
cboEdition = new JComboBox<>(new DefaultComboBoxModel<MagicEdition>(li.toArray(new MagicEdition[li.size()])));
// //////MODELS
listEdition.setModel(new DefaultListModel<MagicEdition>());
tablePrice.setModel(priceModel);
tableCards.setModel(cardsModeltable);
// //////RENDERER
tableCards.getColumnModel().getColumn(2).setCellRenderer(new ManaCellRenderer());
tableCards.getColumnModel().getColumn(6).setCellRenderer(new EditionCellRenderer());
cboEdition.setRenderer(new MagicEditionListRenderer());
listEdition.setCellRenderer(new MagicEditionListRenderer());
// ///////CONFIGURE COMPONENTS
txtRulesArea.setLineWrap(true);
txtRulesArea.setWrapStyleWord(true);
txtRulesArea.setEditable(false);
btnFilter.setToolTipText(MTGControler.getInstance().getLangService().getCapitalize("FILTER"));
btnExport.setToolTipText(MTGControler.getInstance().getLangService().getCapitalize("EXPORT_RESULTS"));
btnExport.setEnabled(false);
filterHeader.setSelectionBackground(Color.LIGHT_GRAY);
cboQuereableItems.addItem("collections");
tablePrice.setRowSorter(sorterPrice);
listEdition.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
thumbnailPanel.enableDragging(false);
panneauCentral.setOrientation(JSplitPane.VERTICAL_SPLIT);
panneauCentral.setRightComponent(tabbedCardsInfo);
panneauCentral.setLeftComponent(tabbedCardsView);
tableCards.setRowHeight(MTGConstants.TABLE_ROW_HEIGHT);
tableCards.setRowSorter(sorterCards);
// /////LAYOUT
setLayout(new BorderLayout());
panneauStat.setLayout(new GridLayout(2, 2, 0, 0));
panneauCard.setLayout(new BorderLayout());
editionDetailPanel.setLayout(new BorderLayout());
panelResultsCards.setLayout(new BorderLayout(0, 0));
panelmana.setLayout(new GridLayout(1, 0, 2, 2));
FlowLayout flpanelFilters = (FlowLayout) panelFilters.getLayout();
flpanelFilters.setAlignment(FlowLayout.LEFT);
FlowLayout flowLayout = (FlowLayout) panneauHaut.getLayout();
flowLayout.setAlignment(FlowLayout.LEFT);
// /////DIMENSION
thumbnailPanel.setThumbnailSize(new Dimension(179, 240));
tabbedCardsInfo.setPreferredSize(new Dimension(0, 350));
historyChartPanel.setPreferredSize(new Dimension(400, 10));
cardsPicPanel.setPreferredSize(new Dimension(400, 10));
tabbedCardsInfo.setMinimumSize(new Dimension(23, 200));
scrollCards.setMinimumSize(new Dimension(0, 0));
scrollThumbnails.getVerticalScrollBar().setUnitIncrement(10);
txtFilter.setColumns(25);
txtMagicSearch.setColumns(35);
// /////VISIBILITY
tableCards.setColumnControlVisible(true);
filterHeader.setVisible(false);
panelFilters.setVisible(false);
lblLoading.setVisible(false);
cboCollections.setVisible(false);
tableCards.setShowVerticalLines(false);
cboEdition.setVisible(false);
// ////ADD PANELS
for (String s : new String[] { "W", "U", "B", "R", "G", "C", "1" }) {
final JButton btnG = new JButton();
btnG.setToolTipText(s);
if (s.equals("1"))
btnG.setToolTipText("[0-9]*");
btnG.setIcon(new ImageIcon(pan.getManaSymbol(s).getScaledInstance(15, 15, Image.SCALE_SMOOTH)));
btnG.setForeground(btnG.getBackground());
btnG.addActionListener(e -> {
txtFilter.setText("\\{" + btnG.getToolTipText() + "}");
sorterCards.setRowFilter(RowFilter.regexFilter(txtFilter.getText()));
});
panelmana.add(btnG);
}
scrollEditions.setViewportView(listEdition);
scrollPanePrices.setViewportView(tablePrice);
scrollCards.setViewportView(tableCards);
scrollPaneRules.setViewportView(txtRulesArea);
scrollThumbnails.setViewportView(thumbnailPanel);
panneauHaut.add(cboQuereableItems);
panneauHaut.add(cboCollections);
panneauHaut.add(txtMagicSearch);
panneauHaut.add(cboEdition);
panneauHaut.add(btnSearch);
panneauHaut.add(btnFilter);
panneauHaut.add(btnExport);
panneauHaut.add(lblLoading);
panneauCard.add(cboLanguages, BorderLayout.NORTH);
panneauCard.add(scrollEditions, BorderLayout.SOUTH);
panneauCard.add(cardsPicPanel, BorderLayout.CENTER);
panelResultsCards.add(panelFilters, BorderLayout.NORTH);
panelResultsCards.add(scrollCards);
magicEditionDetailPanel = new MagicEditionDetailPanel();
editionDetailPanel.add(magicEditionDetailPanel, BorderLayout.CENTER);
panelFilters.add(lblFilter);
panelFilters.add(txtFilter);
panelFilters.add(btnClear);
panelFilters.add(panelmana);
tabbedCardsInfo.addTab(MTGControler.getInstance().getLangService().getCapitalize("DETAILS"), null, detailCardPanel, null);
tabbedCardsInfo.addTab(MTGControler.getInstance().getLangService().getCapitalize("EDITION"), null, editionDetailPanel, null);
tabbedCardsInfo.addTab(MTGControler.getInstance().getLangService().getCapitalize("PRICES"), null, scrollPanePrices, null);
tabbedCardsInfo.addTab(MTGControler.getInstance().getLangService().getCapitalize("RULES"), null, scrollPaneRules, null);
tabbedCardsInfo.addTab(MTGControler.getInstance().getLangService().getCapitalize("PRICE_VARIATIONS"), null, historyChartPanel, null);
if (MTGControler.getInstance().get("debug-json-panel").equalsIgnoreCase("true"))
tabbedCardsInfo.addTab("Json", null, panelJson, null);
panneauStat.add(cmcChart);
panneauStat.add(manaRepartitionPanel);
panneauStat.add(typeRepartitionPanel);
panneauStat.add(rarityRepartitionPanel);
tabbedCardsView.addTab(MTGControler.getInstance().getLangService().getCapitalize("RESULTS"), null, panelResultsCards, null);
tabbedCardsView.addTab(MTGControler.getInstance().getLangService().getCapitalize("THUMBNAIL"), null, scrollThumbnails, null);
tabbedCardsView.addTab(MTGControler.getInstance().getLangService().getCapitalize("STATS"), null, panneauStat, null);
add(panneauHaut, BorderLayout.NORTH);
add(panneauCard, BorderLayout.EAST);
add(panneauCentral, BorderLayout.CENTER);
// /////Right click
try {
initPopupCollection();
} catch (Exception e2) {
MTGLogger.printStackTrace(e2);
}
// /////Action listners
cboEdition.addActionListener(ae -> txtMagicSearch.setText(((MagicEdition) cboEdition.getSelectedItem()).getId()));
btnClear.addActionListener(ae -> {
txtFilter.setText("");
sorterCards.setRowFilter(null);
});
btnFilter.addActionListener(ae -> {
if (panelFilters.isVisible()) {
panelFilters.setVisible(false);
filterHeader.setVisible(false);
} else {
panelFilters.setVisible(true);
filterHeader.setVisible(true);
}
});
cboQuereableItems.addActionListener(e -> {
if (cboQuereableItems.getSelectedItem().toString().equalsIgnoreCase("set")) {
txtMagicSearch.setVisible(false);
cboEdition.setVisible(true);
cboCollections.setVisible(false);
} else if (cboQuereableItems.getSelectedItem().toString().equalsIgnoreCase("collections")) {
txtMagicSearch.setVisible(false);
cboEdition.setVisible(false);
cboCollections.setVisible(true);
} else {
txtMagicSearch.setVisible(true);
cboEdition.setVisible(false);
cboCollections.setVisible(false);
}
});
btnSearch.addActionListener(ae -> {
Observer ob = new Observer() {
@Override
public void update(Observable o, Object arg) {
cardsModeltable.addCard((MagicCard) arg);
}
};
selectedEdition = null;
if (txtMagicSearch.getText().equals("") && !cboCollections.isVisible())
return;
cardsModeltable.clear();
new SwingWorker<Object, Object>() {
protected Void doInBackground() {
loading(true, MTGControler.getInstance().getLangService().getCapitalize("SEARCHING"));
String searchName = txtMagicSearch.getText();
try {
MTGControler.getInstance().getEnabledProviders().addObserver(ob);
if (cboCollections.isVisible())
cards = MTGControler.getInstance().getEnabledDAO().listCardsFromCollection((MagicCollection) cboCollections.getSelectedItem());
else
cards = MTGControler.getInstance().getEnabledProviders().searchCardByCriteria(cboQuereableItems.getSelectedItem().toString(), searchName, null, false);
if (cards.size() < 50)
Collections.sort(cards, new MagicCardComparator());
open(cards);
return null;
} catch (Exception e) {
logger.error("Erreur search", e);
return null;
}
}
@Override
protected void done() {
super.done();
loading(false, "");
cardsModeltable.fireTableDataChanged();
btnExport.setEnabled(tableCards.getRowCount() > 0);
MTGControler.getInstance().getEnabledProviders().removeObserver(ob);
}
}.execute();
});
tableCards.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent evt) {
if (SwingUtilities.isRightMouseButton(evt)) {
Point point = evt.getPoint();
popupMenu.show(tableCards, (int) point.getX(), (int) point.getY());
} else {
try {
selectedCard = (MagicCard) tableCards.getValueAt(tableCards.getSelectedRow(), 0);
selectedEdition = selectedCard.getEditions().get(0);
updateCards();
} catch (Exception e) {
logger.error(e);
}
}
}
});
listEdition.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent mev) {
selectedEdition = listEdition.getSelectedValue();
ThreadManager.getInstance().execute(() -> {
loading(true, MTGControler.getInstance().getLangService().getCapitalize("LOADING_EDITIONS"));
try {
selectedCard = MTGControler.getInstance().getEnabledProviders().searchCardByCriteria("name", selectedCard.getName(), selectedEdition, false).get(0);
detailCardPanel.setMagicCard(selectedCard);
magicEditionDetailPanel.setMagicEdition(selectedEdition);
} catch (Exception e) {
MTGLogger.printStackTrace(e);
}
// backcard
cardsPicPanel.showPhoto(selectedCard);
historyChartPanel.init(selectedCard, selectedEdition, selectedCard.getName());
if (tabbedCardsInfo.getSelectedIndex() == INDEX_PRICES)
updatePrices();
loading(false, "");
}, "changeEdition");
}
});
tablePrice.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent ev) {
if (ev.getClickCount() == 2 && !ev.isConsumed()) {
ev.consume();
try {
String url = tablePrice.getValueAt(tablePrice.getSelectedRow(), CardsPriceTableModel.ROW_URL).toString();
Desktop.getDesktop().browse(new URI(url));
} catch (Exception e) {
logger.error(e);
}
}
}
});
cboLanguages.addItemListener(e -> {
MagicCardNames selLang = (MagicCardNames) cboLanguages.getSelectedItem();
try {
if (e.getStateChange() == ItemEvent.SELECTED && selLang != null) {
MagicEdition ed = (MagicEdition) BeanUtils.cloneBean(selectedEdition);
ed.setMultiverse_id("" + selLang.getGathererId());
logger.debug("change lang to " + selLang + " for " + ed);
cardsPicPanel.showPhoto(selectedCard, ed);
}
} catch (Exception e1) {
logger.error(e1);
}
});
btnExport.addActionListener(ae -> {
JPopupMenu menu = new JPopupMenu();
for (final MTGCardsExport exp : MTGControler.getInstance().getEnabledDeckExports()) {
JMenuItem it = new JMenuItem();
it.setIcon(exp.getIcon());
it.setText(exp.getName());
it.addActionListener(exportEvent -> {
JFileChooser jf = new JFileChooser(".");
jf.setSelectedFile(new File("search" + exp.getFileExtension()));
int result = jf.showSaveDialog(null);
final File f = jf.getSelectedFile();
if (result == JFileChooser.APPROVE_OPTION)
ThreadManager.getInstance().execute(() -> {
try {
loading(true, "export " + exp);
List<MagicCard> export = ((MagicCardTableModel) tableCards.getRowSorter().getModel()).getListCards();
exp.export(export, f);
loading(false, "");
JOptionPane.showMessageDialog(null, MTGControler.getInstance().getLangService().combine("EXPORT", "FINISHED"), exp.getName() + " " + MTGControler.getInstance().getLangService().get("FINISHED"), JOptionPane.INFORMATION_MESSAGE);
} catch (Exception e) {
logger.error(e);
loading(false, "");
JOptionPane.showMessageDialog(null, e, MTGControler.getInstance().getLangService().getError(), JOptionPane.ERROR_MESSAGE);
}
}, "export search " + exp);
});
menu.add(it);
}
Component b = (Component) ae.getSource();
Point p = b.getLocationOnScreen();
menu.show(b, 0, 0);
menu.setLocation(p.x, p.y + b.getHeight());
});
tabbedCardsInfo.addChangeListener(e -> {
if (tabbedCardsInfo.getSelectedIndex() == INDEX_PRICES)
updatePrices();
});
txtFilter.addActionListener(ae -> {
String text = txtFilter.getText();
if (text.length() == 0) {
sorterCards.setRowFilter(null);
} else {
sorterCards.setRowFilter(RowFilter.regexFilter(text));
}
});
thumbnailPanel.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
DisplayableCard lab = (DisplayableCard) thumbnailPanel.getComponentAt(new Point(e.getX(), e.getY()));
selectedCard = lab.getMagicCard();
selectedEdition = lab.getMagicCard().getEditions().get(0);
cardsPicPanel.showPhoto(selectedCard);
updateCards();
}
});
txtMagicSearch.addActionListener(e -> btnSearch.doClick());
}
use of org.magic.gui.renderer.MagicEditionListRenderer 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.gui.renderer.MagicEditionListRenderer in project MtgDesktopCompanion by nicho92.
the class BoosterBoxDashlet method initGUI.
@Override
public void initGUI() {
JSpinner boxSizeSpinner;
JXTable table;
BoostersTableModel boostersModel;
DefaultListModel<MagicCard> cardsModel;
JTextPane txtDetailBox;
JPanel panneauHaut = new JPanel();
getContentPane().add(panneauHaut, BorderLayout.NORTH);
List<MagicEdition> eds = new ArrayList<>();
try {
eds.addAll(MTGControler.getInstance().getEnabledProviders().loadEditions());
Collections.sort(eds);
eds.add(0, null);
} catch (Exception e) {
MTGLogger.printStackTrace(e);
}
JComboBox<MagicEdition> cboEditions = new JComboBox<>(new DefaultComboBoxModel<MagicEdition>(eds.toArray(new MagicEdition[eds.size()])));
cboEditions.setRenderer(new MagicEditionListRenderer());
panneauHaut.add(cboEditions);
JLabel lblBoxSize = new JLabel("Box size: ");
panneauHaut.add(lblBoxSize);
boxSizeSpinner = new JSpinner();
boxSizeSpinner.setModel(new SpinnerNumberModel(36, 0, null, 1));
panneauHaut.add(boxSizeSpinner);
JScrollPane scrollPane = new JScrollPane();
getContentPane().add(scrollPane, BorderLayout.CENTER);
boostersModel = new BoostersTableModel();
cardsModel = new DefaultListModel<>();
table = new JXTable(boostersModel);
scrollPane.setViewportView(table);
JPanel panneauBas = new JPanel();
getContentPane().add(panneauBas, BorderLayout.SOUTH);
JButton btnCalculate = new JButton("Open");
panneauBas.add(btnCalculate);
JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
getContentPane().add(tabbedPane, BorderLayout.EAST);
txtDetailBox = new JTextPane();
txtDetailBox.setEditable(false);
tabbedPane.addTab("Box", null, txtDetailBox, null);
JScrollPane scrollPane1 = new JScrollPane();
tabbedPane.addTab("Booster", null, scrollPane1, null);
JList<MagicCard> list1 = new JList<>();
list1.setModel(cardsModel);
list1.setCellRenderer(new MagicCardListRenderer());
scrollPane1.setViewportView(list1);
btnCalculate.addActionListener(e -> ThreadManager.getInstance().execute(() -> {
try {
List<CardShake> prices = MTGControler.getInstance().getEnabledDashBoard().getShakeForEdition((MagicEdition) cboEditions.getSelectedItem());
boostersModel.clear();
double total = 0;
Map<String, Double> priceRarity = new HashMap<>();
for (int i = 0; i < (int) boxSizeSpinner.getValue(); i++) {
Booster booster = MTGControler.getInstance().getEnabledProviders().generateBooster((MagicEdition) cboEditions.getSelectedItem());
Collections.reverse(booster.getCards());
booster.setBoosterNumber(String.valueOf(i + 1));
double price = 0;
for (MagicCard mc : booster.getCards()) {
for (CardShake cs : prices) if (cs.getName().equalsIgnoreCase(mc.getName())) {
price += cs.getPrice();
booster.setPrice(price);
cs.setCard(mc);
String rarity = mc.getEditions().get(0).getRarity();
if (priceRarity.get(rarity) != null)
priceRarity.put(rarity, priceRarity.get(rarity) + cs.getPrice());
else
priceRarity.put(rarity, cs.getPrice());
}
}
boostersModel.addLine(booster);
total = total + booster.getPrice();
StringBuilder temp = new StringBuilder();
temp.append("TOTAL: ").append(doubleFormat.format(total)).append("\n");
for (Entry<String, Double> s : priceRarity.entrySet()) temp.append(s.getKey()).append(": ").append(doubleFormat.format(priceRarity.get(s.getKey()))).append("\n");
txtDetailBox.setText(temp.toString());
}
} catch (Exception e1) {
logger.error(e1);
}
}, "Open Box"));
table.getSelectionModel().addListSelectionListener(event -> {
if (!event.getValueIsAdjusting()) {
int viewRow = table.getSelectedRow();
if (viewRow > -1) {
int modelRow = table.convertRowIndexToModel(viewRow);
List<MagicCard> list = ((Booster) table.getModel().getValueAt(modelRow, 0)).getCards();
cardsModel.clear();
for (MagicCard mc : list) cardsModel.addElement(mc);
}
}
});
if (getProperties().size() > 0) {
Rectangle r = new Rectangle((int) Double.parseDouble(getProperty("x")), (int) Double.parseDouble(getProperty("y")), (int) Double.parseDouble(getProperty("w")), (int) Double.parseDouble(getProperty("h")));
setBounds(r);
}
setVisible(true);
}
use of org.magic.gui.renderer.MagicEditionListRenderer in project MtgDesktopCompanion by nicho92.
the class EditionsDashlet method initGUI.
public void initGUI() {
JPanel panel = new JPanel();
getContentPane().add(panel, BorderLayout.NORTH);
modEdition = new EditionsShakerTableModel();
List<MagicEdition> eds = new ArrayList<>();
try {
eds.addAll(MTGControler.getInstance().getEnabledProviders().loadEditions());
Collections.sort(eds);
eds.add(0, null);
} catch (Exception e) {
MTGLogger.printStackTrace(e);
}
cboEditions = new JComboBox(new DefaultComboBoxModel<MagicEdition>(eds.toArray(new MagicEdition[eds.size()])));
cboEditions.setRenderer(new MagicEditionListRenderer());
panel.add(cboEditions);
lblLoading = new JLabel("");
lblLoading.setIcon(MTGConstants.ICON_LOADING);
lblLoading.setVisible(false);
panel.add(lblLoading);
JScrollPane scrollPane = new JScrollPane();
getContentPane().add(scrollPane, BorderLayout.CENTER);
table = new JXTable(modEdition);
initToolTip(table, 0, 1);
table.getColumnModel().getColumn(3).setCellRenderer(new CardShakeRenderer());
table.getColumnModel().getColumn(5).setCellRenderer(new CardShakeRenderer());
scrollPane.setViewportView(table);
setVisible(true);
cboEditions.addActionListener(ae -> init());
if (getProperties().size() > 0) {
Rectangle r = new Rectangle((int) Double.parseDouble(getProperty("x")), (int) Double.parseDouble(getProperty("y")), (int) Double.parseDouble(getProperty("w")), (int) Double.parseDouble(getProperty("h")));
MagicEdition ed;
try {
ed = MTGControler.getInstance().getEnabledProviders().getSetById(getProperty("EDITION"));
cboEditions.setSelectedItem(ed);
} catch (Exception e) {
logger.error("Error retrieve editions", e);
}
setBounds(r);
}
try {
table.packAll();
} catch (Exception e) {
MTGLogger.printStackTrace(e);
}
new TableFilterHeader(table, AutoChoices.ENABLED);
}
use of org.magic.gui.renderer.MagicEditionListRenderer in project MtgDesktopCompanion by nicho92.
the class BoosterQtyPanel method initGUI.
private void initGUI() {
setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
List<MagicEdition> li = new ArrayList<>();
try {
li = MTGControler.getInstance().getEnabledProviders().loadEditions();
} catch (IOException e1) {
MTGLogger.printStackTrace(e1);
}
cboEditions = new JComboBox<>(new DefaultComboBoxModel<MagicEdition>(li.toArray(new MagicEdition[li.size()])));
cboEditions.setRenderer(new MagicEditionListRenderer());
add(cboEditions);
spinner = new JSpinner();
spinner.setModel(new SpinnerNumberModel(6, 0, null, 1));
add(spinner);
}
Aggregations