use of org.magic.gui.components.charts.CmcChartPanel 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.components.charts.CmcChartPanel in project MtgDesktopCompanion by nicho92.
the class ConstructPanel method initGUI.
private void initGUI() {
JPanel panneauHaut = new JPanel();
JButton btnSearch;
JButton btnUpdate;
HandPanel thumbnail;
JPanel panelBottom;
JTextField txtSearch;
JComboBox<String> cboAttributs;
JScrollPane scrollResult;
JTabbedPane tabbedPane;
ButtonGroup groupsFilterResult;
lblExport.setIcon(MTGConstants.ICON_LOADING);
lblExport.setVisible(false);
setLayout(new BorderLayout(0, 0));
deckmodel = new DeckModel(DeckModel.TYPE.DECK);
deckSidemodel = new DeckModel(DeckModel.TYPE.SIDE);
deckDetailsPanel = new DeckDetailsPanel();
panelBottom = new JPanel();
thumbnail = new HandPanel();
thumbnail.setThumbnailSize(new Dimension(223, 311));
thumbnail.enableDragging(false);
thumbnail.setMaxCardsRow(4);
FlowLayout flowLayout = (FlowLayout) panneauHaut.getLayout();
flowLayout.setAlignment(FlowLayout.LEFT);
add(panneauHaut, BorderLayout.NORTH);
cboAttributs = new JComboBox<>(new DefaultComboBoxModel<String>(MTGControler.getInstance().getEnabledProviders().getQueryableAttributs()));
panneauHaut.add(cboAttributs);
txtSearch = new JTextField();
panneauHaut.add(txtSearch);
txtSearch.setColumns(25);
btnSearch = new JButton(MTGConstants.ICON_SEARCH);
panneauHaut.add(btnSearch);
final JLabel lblCards = new JLabel();
panneauHaut.add(lblCards);
JButton btnNewDeck = new JButton(MTGConstants.ICON_NEW);
btnNewDeck.setToolTipText(MTGControler.getInstance().getLangService().getCapitalize("CREATE_NEW_DECK"));
panneauHaut.add(btnNewDeck);
btnNewDeck.addActionListener(newDeckEvent -> {
MagicDeck newDeck = new MagicDeck();
setDeck(newDeck);
deckmodel.init(newDeck);
deckSidemodel.init(newDeck);
});
JButton btnOpen = new JButton(MTGConstants.ICON_OPEN);
btnOpen.setToolTipText(MTGControler.getInstance().getLangService().getCapitalize("OPEN_DECK"));
panneauHaut.add(btnOpen);
btnOpen.addActionListener(openEvent -> {
try {
JDeckChooserDialog choose = new JDeckChooserDialog();
choose.setVisible(true);
deck = choose.getSelectedDeck();
if (deck != null) {
deckDetailsPanel.setMagicDeck(deck);
deckmodel.init(deck);
deckSidemodel.init(deck);
setDeck(deck);
updatePanels();
}
} catch (Exception ex) {
logger.error(ex);
JOptionPane.showMessageDialog(null, ex, MTGControler.getInstance().getLangService().getError(), JOptionPane.ERROR_MESSAGE);
}
});
btnUpdate = new JButton();
btnUpdate.setToolTipText(MTGControler.getInstance().getLangService().getCapitalize("UPDATE_DECK"));
btnUpdate.addActionListener(updateEvent -> ThreadManager.getInstance().execute(() -> {
Map<MagicCard, Integer> updateM = new HashMap<>();
Map<MagicCard, Integer> updateS = new HashMap<>();
btnUpdate.setEnabled(false);
lblExport.setVisible(true);
for (MagicCard mc : deck.getMap().keySet()) {
try {
updateM.put(MTGControler.getInstance().getEnabledProviders().getCardById(mc.getId()), deck.getMap().get(mc));
} catch (Exception e) {
logger.error(e);
btnUpdate.setEnabled(true);
lblExport.setVisible(false);
}
}
for (MagicCard mc : deck.getMapSideBoard().keySet()) {
try {
updateS.put(MTGControler.getInstance().getEnabledProviders().getCardById(mc.getId()), deck.getMapSideBoard().get(mc));
} catch (Exception e) {
btnUpdate.setEnabled(true);
lblExport.setVisible(false);
}
}
deck.getMap().clear();
deck.setMapDeck(updateM);
deck.getMapSideBoard().clear();
deck.setMapSideBoard(updateS);
updatePanels();
btnUpdate.setEnabled(true);
lblExport.setVisible(false);
JOptionPane.showMessageDialog(null, MTGControler.getInstance().getLangService().getCapitalize("UPDATED_DECK"), MTGControler.getInstance().getLangService().getCapitalize("FINISHED"), JOptionPane.INFORMATION_MESSAGE);
}, "Update Deck"));
btnUpdate.setIcon(MTGConstants.ICON_REFRESH);
panneauHaut.add(btnUpdate);
JButton btnSave = new JButton(MTGConstants.ICON_SAVE);
btnSave.setToolTipText(MTGControler.getInstance().getLangService().getCapitalize("SAVE_DECK"));
panneauHaut.add(btnSave);
btnSave.addActionListener(e -> {
try {
String name = JOptionPane.showInputDialog(MTGControler.getInstance().getLangService().getCapitalize("DECK_NAME") + " ?", deck.getName());
deck.setName(name);
MTGControler.getInstance().saveDeck(deck);
} catch (Exception ex) {
logger.error("error saving", ex);
JOptionPane.showMessageDialog(null, ex, MTGControler.getInstance().getLangService().getError(), JOptionPane.ERROR_MESSAGE);
}
});
JButton btnImport = new JButton(MTGConstants.ICON_IMPORT);
btnImport.setToolTipText(MTGControler.getInstance().getLangService().getCapitalize("DECK_IMPORT_AS"));
btnImport.addActionListener(ae -> {
JPopupMenu menu = new JPopupMenu();
for (final MTGCardsExport exp : MTGControler.getInstance().getEnabledDeckExports()) {
if (exp.getMods() == MODS.BOTH || exp.getMods() == MODS.IMPORT) {
JMenuItem it = new JMenuItem();
it.setIcon(exp.getIcon());
it.setText(exp.getName());
it.addActionListener(itEvent -> {
JFileChooser jf = new JFileChooser(".");
jf.setFileFilter(new FileFilter() {
@Override
public String getDescription() {
return exp.getName();
}
@Override
public boolean accept(File f) {
return (f.isDirectory() || f.getName().endsWith(exp.getFileExtension()));
}
});
int res = -1;
f = new File("");
if (!exp.needDialogGUI()) {
res = jf.showOpenDialog(null);
f = jf.getSelectedFile();
} else {
res = JFileChooser.APPROVE_OPTION;
}
if (res == JFileChooser.APPROVE_OPTION)
ThreadManager.getInstance().execute(() -> {
try {
loading(true, MTGControler.getInstance().getLangService().get("LOADING_FILE", f.getName(), exp));
deck = exp.importDeck(f);
JOptionPane.showMessageDialog(null, MTGControler.getInstance().getLangService().getCapitalize("FINISHED"), exp.getName() + " " + MTGControler.getInstance().getLangService().get("FINISHED"), JOptionPane.INFORMATION_MESSAGE);
setDeck(deck);
loading(false, "");
deckmodel.init(deck);
deckSidemodel.init(deck);
setDeck(deck);
updatePanels();
} catch (Exception e) {
logger.error("error import", e);
MTGLogger.printStackTrace(e);
loading(false, "");
JOptionPane.showMessageDialog(null, e, MTGControler.getInstance().getLangService().getError(), JOptionPane.ERROR_MESSAGE);
}
}, "import " + exp);
});
menu.add(it);
}
}
Component b = (Component) ae.getSource();
Point point = b.getLocationOnScreen();
menu.show(b, 0, 0);
menu.setLocation(point.x, point.y + b.getHeight());
});
panneauHaut.add(btnImport);
btnExports = new JButton();
btnExports.setEnabled(false);
btnExports.setToolTipText(MTGControler.getInstance().getLangService().getCapitalize("EXPORT_AS"));
btnExports.setIcon(MTGConstants.ICON_EXPORT);
btnExports.addActionListener(exportsAction -> {
JPopupMenu menu = new JPopupMenu();
for (final MTGCardsExport exp : MTGControler.getInstance().getEnabledDeckExports()) {
if (exp.getMods() == MODS.BOTH || exp.getMods() == MODS.EXPORT) {
JMenuItem it = new JMenuItem();
it.setIcon(exp.getIcon());
it.setText(exp.getName());
it.addActionListener(pluginExportEvent -> {
JFileChooser jf = new JFileChooser(".");
jf.setSelectedFile(new File(deck.getName() + exp.getFileExtension()));
jf.showSaveDialog(null);
exportedFile = jf.getSelectedFile();
ThreadManager.getInstance().execute(() -> {
try {
loading(true, MTGControler.getInstance().getLangService().get("EXPORT_TO", deck, exp));
exp.export(deck, exportedFile);
JOptionPane.showMessageDialog(null, MTGControler.getInstance().getLangService().combine("EXPORT", "FINISHED"), exp.getName() + " " + MTGControler.getInstance().getLangService().getCapitalize("FINISHED"), JOptionPane.INFORMATION_MESSAGE);
loading(false, "");
} catch (Exception e) {
logger.error(e);
loading(false, "");
JOptionPane.showMessageDialog(null, e, MTGControler.getInstance().getLangService().getError(), JOptionPane.ERROR_MESSAGE);
}
}, "Export " + deck + " to " + exp.getName());
});
menu.add(it);
}
}
Component b = (Component) exportsAction.getSource();
Point point = b.getLocationOnScreen();
menu.show(b, 0, 0);
menu.setLocation(point.x, point.y + b.getHeight());
});
panneauHaut.add(btnExports);
panneauHaut.add(lblExport);
JPanel panneauBas = new JPanel();
add(panneauBas, BorderLayout.SOUTH);
tabbedPane = new JTabbedPane(JTabbedPane.TOP);
add(tabbedPane, BorderLayout.CENTER);
JSplitPane panneauDeck = new JSplitPane();
panneauDeck.setOrientation(JSplitPane.VERTICAL_SPLIT);
tabbedPane.addTab(MTGControler.getInstance().getLangService().getCapitalize("DECK"), null, panneauDeck, null);
DefaultRowSorter sorterCards = new TableRowSorter<DefaultTableModel>(deckmodel);
magicCardDetailPanel = new MagicCardDetailPanel();
magicCardDetailPanel.setPreferredSize(new Dimension(0, 0));
magicCardDetailPanel.enableThumbnail(true);
panelBottom.setLayout(new BorderLayout(0, 0));
panelBottom.add(magicCardDetailPanel);
panneauDeck.setRightComponent(panelBottom);
cardDrawProbaPanel = new DrawProbabilityPanel();
panelBottom.add(cardDrawProbaPanel, BorderLayout.EAST);
final JTabbedPane tabbedDeckSide = new JTabbedPane(JTabbedPane.BOTTOM);
panneauDeck.setLeftComponent(tabbedDeckSide);
JScrollPane scrollDeck = new JScrollPane();
tabbedDeckSide.addTab("Main", null, scrollDeck, null);
tableDeck = new JTable();
scrollDeck.setViewportView(tableDeck);
tableDeck.setModel(deckmodel);
tableDeck.getColumnModel().getColumn(2).setCellRenderer(new ManaCellRenderer());
tableDeck.setRowHeight(MTGConstants.TABLE_ROW_HEIGHT);
tableDeck.setRowSorter(sorterCards);
tableDeck.getColumnModel().getColumn(4).setCellEditor(new IntegerCellEditor());
tableDeck.getColumnModel().getColumn(3).setCellRenderer(new MagicEditionRenderer());
tableDeck.getColumnModel().getColumn(3).setCellEditor(new MagicEditionListEditor());
JScrollPane scrollSideboard = new JScrollPane();
tabbedDeckSide.addTab("SideBoard", null, scrollSideboard, null);
tableSide = new JTable();
tableSide.setModel(deckSidemodel);
tableSide.setRowHeight(MTGConstants.TABLE_ROW_HEIGHT);
tableSide.getColumnModel().getColumn(2).setCellRenderer(new ManaCellRenderer());
tableSide.getColumnModel().getColumn(4).setCellEditor(new IntegerCellEditor());
tableSide.getColumnModel().getColumn(3).setCellRenderer(new MagicEditionRenderer());
tableSide.getColumnModel().getColumn(3).setCellEditor(new MagicEditionListEditor());
tableSide.getColumnModel().getColumn(4).setCellEditor(new IntegerCellEditor());
scrollSideboard.setViewportView(tableSide);
tableDeck.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent ev) {
MagicCard mc = (MagicCard) tableDeck.getValueAt(tableDeck.getSelectedRow(), 0);
magicCardDetailPanel.setMagicCard(mc);
cardDrawProbaPanel.init(deck, mc);
}
});
tableSide.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent ev) {
MagicCard mc = (MagicCard) tableSide.getValueAt(tableSide.getSelectedRow(), 0);
magicCardDetailPanel.setMagicCard(mc);
}
});
tableDeck.addKeyListener(new KeyAdapter() {
@Override
public void keyTyped(KeyEvent e) {
MagicCard mc = (MagicCard) tableDeck.getValueAt(tableDeck.getSelectedRow(), 0);
if (e.getKeyCode() == 0) {
deck.getMap().remove(mc);
deckmodel.init(deck);
}
}
});
tableSide.addKeyListener(new KeyAdapter() {
@Override
public void keyTyped(KeyEvent e) {
MagicCard mc = (MagicCard) tableSide.getValueAt(tableSide.getSelectedRow(), 0);
if (e.getKeyCode() == 0) {
deck.getMapSideBoard().remove(mc);
deckmodel.init(deck);
}
}
});
tableDeck.getModel().addTableModelListener(e -> updatePanels());
tableSide.getModel().addTableModelListener(e -> updatePanels());
tableDeck.getDefaultEditor(String.class).addCellEditorListener(new CellEditorListener() {
@Override
public void editingStopped(ChangeEvent e) {
updatePanels();
}
@Override
public void editingCanceled(ChangeEvent e) {
updatePanels();
}
});
tableSide.getDefaultEditor(String.class).addCellEditorListener(new CellEditorListener() {
@Override
public void editingStopped(ChangeEvent e) {
updatePanels();
}
@Override
public void editingCanceled(ChangeEvent e) {
updatePanels();
}
});
JPanel panelInfoDeck = new JPanel();
tabbedPane.addTab(MTGControler.getInstance().getLangService().getCapitalize("INFORMATIONS"), null, panelInfoDeck, null);
panelInfoDeck.setLayout(new BorderLayout(0, 0));
panelInfoDeck.add(deckDetailsPanel, BorderLayout.NORTH);
deckDetailsPanel.setMagicDeck(deck);
cmcChartPanel = new CmcChartPanel();
manaRepartitionPanel = new ManaRepartitionPanel();
typeRepartitionPanel = new TypeRepartitionPanel();
rarityRepartitionPanel = new RarityRepartitionPanel();
drawProbabilityPanel = new DrawProbabilityPanel();
JPanel randomHandPanel = new JPanel();
JPanel statPanel = new JPanel();
randomHandPanel.setLayout(new BorderLayout(0, 0));
randomHandPanel.add(thumbnail, BorderLayout.CENTER);
statPanel.setLayout(new GridLayout(3, 2, 0, 0));
statPanel.add(manaRepartitionPanel);
statPanel.add(typeRepartitionPanel);
statPanel.add(rarityRepartitionPanel);
statPanel.add(cmcChartPanel);
statPanel.add(drawProbabilityPanel);
tabbedPane.addTab(MTGControler.getInstance().getLangService().getCapitalize("STATS"), null, statPanel, null);
deckPricePanel = new DeckPricePanel();
statPanel.add(deckPricePanel);
tabbedPane.addTab(MTGControler.getInstance().getLangService().getCapitalize("SAMPLE_HAND"), null, randomHandPanel, null);
JPanel panel = new JPanel();
randomHandPanel.add(panel, BorderLayout.NORTH);
JButton btnDrawAHand = new JButton(MTGControler.getInstance().getLangService().getCapitalize("DRAW_HAND"));
btnDrawAHand.addActionListener(ae -> {
thumbnail.removeAll();
p.mixHandAndLibrary();
p.shuffleLibrary();
p.drawCard(7);
thumbnail.initThumbnails(p.getHand(), false, false);
});
panel.add(btnDrawAHand);
JPanel panneauGauche = new JPanel();
add(panneauGauche, BorderLayout.WEST);
panneauGauche.setLayout(new BorderLayout(0, 0));
scrollResult = new JScrollPane();
panneauGauche.add(scrollResult);
listResult = new JList<>(new DefaultListModel<MagicCard>());
listResult.setCellRenderer(new MagicCardListRenderer());
listResult.setMinimumSize(new Dimension(100, 0));
listResult.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
scrollResult.setViewportView(listResult);
JPanel panneauResultFilter = new JPanel();
panneauGauche.add(panneauResultFilter, BorderLayout.NORTH);
groupsFilterResult = new ButtonGroup() {
@Override
public void setSelected(ButtonModel model, boolean selected) {
if (selected) {
super.setSelected(model, selected);
} else {
clearSelection();
}
}
};
JToggleButton tglbtnStd = new JToggleButton("STD");
tglbtnStd.setActionCommand("Standard");
panneauResultFilter.add(tglbtnStd);
JToggleButton tglbtnMdn = new JToggleButton("MDN");
tglbtnMdn.setActionCommand("Modern");
panneauResultFilter.add(tglbtnMdn);
JToggleButton tglbtnLeg = new JToggleButton("LEG");
tglbtnLeg.setActionCommand("Legacy");
panneauResultFilter.add(tglbtnLeg);
JToggleButton tglbtnVin = new JToggleButton("VIN");
tglbtnVin.setActionCommand("Vintage");
panneauResultFilter.add(tglbtnVin);
groupsFilterResult.add(tglbtnStd);
groupsFilterResult.add(tglbtnMdn);
groupsFilterResult.add(tglbtnLeg);
groupsFilterResult.add(tglbtnVin);
listResult.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent ev) {
if (ev.getClickCount() == 1 && !ev.isConsumed()) {
ev.consume();
MagicCard mc = listResult.getSelectedValue();
magicCardDetailPanel.setMagicCard(mc);
}
if (ev.getClickCount() == 2 && !ev.isConsumed()) {
ev.consume();
MagicCard mc = listResult.getSelectedValue();
if (getSelectedMap().get(mc) != null) {
getSelectedMap().put(mc, deck.getMap().get(mc) + 1);
} else {
getSelectedMap().put(mc, 1);
}
deckmodel.init(deck);
deckSidemodel.init(deck);
}
}
});
txtSearch.addActionListener(e -> btnSearch.doClick());
tabbedDeckSide.addChangeListener(e -> selectedIndex = tabbedDeckSide.getSelectedIndex());
btnSearch.addActionListener(aeSearch -> {
if (txtSearch.getText().equals(""))
return;
resultListModel.removeAllElements();
ThreadManager.getInstance().execute(() -> {
try {
String searchName = txtSearch.getText();
List<MagicCard> cards = MTGControler.getInstance().getEnabledProviders().searchCardByCriteria(cboAttributs.getSelectedItem().toString(), searchName, null, false);
MagicFormat form = new MagicFormat();
for (MagicCard m : cards) {
if (groupsFilterResult.getSelection() != null) {
form.setFormat(groupsFilterResult.getSelection().getActionCommand());
if (m.getLegalities().contains(form))
resultListModel.addElement(m);
} else {
resultListModel.addElement(m);
}
}
lblCards.setText(resultListModel.size() + " " + MTGControler.getInstance().getLangService().get("RESULTS"));
listResult.setModel(resultListModel);
listResult.updateUI();
} catch (Exception e) {
JOptionPane.showMessageDialog(null, e.getMessage(), MTGControler.getInstance().getLangService().getError(), JOptionPane.ERROR_MESSAGE);
}
}, "search deck");
});
}
use of org.magic.gui.components.charts.CmcChartPanel in project MtgDesktopCompanion by nicho92.
the class SealedPanel method initGUI.
private void initGUI() {
JPanel panelWest;
JButton btnSaveDeck;
JSplitPane panelCenter;
JButton btnAddBoosters;
JScrollPane scrollTablePack;
JTable table;
JPanel panelControl;
JPanel panelAnalyse;
JPanel panelSorters;
JRadioButton rdioCmcSortButton;
JRadioButton rdiocolorSort;
JRadioButton rdiotypeSort;
JPanel panel;
JPanel panelEast;
JPanel panelAnalyseChooser;
JRadioButton rdioDeckAnalyse;
JRadioButton rdioBoosterAnalyse;
JPanel panelLands;
setLayout(new BorderLayout(0, 0));
panelOpenedBooster = new BoosterPanel();
model = new SealedPackTableModel();
panelDetail = new MagicCardDetailPanel();
panelDetail.enableThumbnail(true);
panelDetail.enableCollectionLookup(false);
List<MagicEdition> li;
try {
li = MTGControler.getInstance().getEnabledProviders().loadEditions();
} catch (IOException e1) {
li = new ArrayList<>();
MTGLogger.printStackTrace(e1);
}
panelWest = new JPanel();
panelWest.setPreferredSize(new Dimension(300, 10));
add(panelWest, BorderLayout.WEST);
panelWest.setLayout(new BorderLayout(0, 0));
panelControl = new JPanel();
panelWest.add(panelControl, BorderLayout.NORTH);
table = new JTable(model);
table.getColumnModel().getColumn(1).setCellEditor(new IntegerCellEditor());
panelControl.setLayout(new BorderLayout(0, 0));
panel = new JPanel();
panelControl.add(panel, BorderLayout.NORTH);
GridBagLayout gblpanel = new GridBagLayout();
gblpanel.columnWidths = new int[] { 105, 65, 0, 0, 0 };
gblpanel.rowHeights = new int[] { 41, 0, 0 };
gblpanel.columnWeights = new double[] { 0.0, 0.0, 1.0, 0.0, Double.MIN_VALUE };
gblpanel.rowWeights = new double[] { 0.0, 0.0, Double.MIN_VALUE };
panel.setLayout(gblpanel);
cboEditions = new JComboBox<>();
GridBagConstraints gbccboEditions = new GridBagConstraints();
gbccboEditions.fill = GridBagConstraints.HORIZONTAL;
gbccboEditions.gridwidth = 4;
gbccboEditions.insets = new Insets(0, 0, 5, 0);
gbccboEditions.gridx = 0;
gbccboEditions.gridy = 0;
panel.add(cboEditions, gbccboEditions);
cboEditions.setRenderer(new MagicEditionListRenderer());
cboEditions.setModel(new DefaultComboBoxModel<MagicEdition>(li.toArray(new MagicEdition[li.size()])));
btnAddBoosters = new JButton(MTGConstants.ICON_NEW);
GridBagConstraints gbcbtnAddBoosters = new GridBagConstraints();
gbcbtnAddBoosters.anchor = GridBagConstraints.NORTH;
gbcbtnAddBoosters.insets = new Insets(0, 0, 0, 5);
gbcbtnAddBoosters.gridx = 0;
gbcbtnAddBoosters.gridy = 1;
panel.add(btnAddBoosters, gbcbtnAddBoosters);
btnOpen = new JButton(MTGConstants.ICON_OPEN);
GridBagConstraints gbcbtnOpen = new GridBagConstraints();
gbcbtnOpen.insets = new Insets(0, 0, 0, 5);
gbcbtnOpen.anchor = GridBagConstraints.NORTH;
gbcbtnOpen.gridx = 1;
gbcbtnOpen.gridy = 1;
panel.add(btnOpen, gbcbtnOpen);
btnOpen.setEnabled(false);
btnSaveDeck = new JButton(MTGConstants.ICON_SAVE);
GridBagConstraints gbcbtnSaveDeck = new GridBagConstraints();
gbcbtnSaveDeck.insets = new Insets(0, 0, 0, 5);
gbcbtnSaveDeck.gridx = 2;
gbcbtnSaveDeck.gridy = 1;
panel.add(btnSaveDeck, gbcbtnSaveDeck);
lblLoading = new JLabel(MTGConstants.ICON_LOADING);
lblLoading.setVisible(false);
GridBagConstraints gbclblLoading = new GridBagConstraints();
gbclblLoading.gridx = 3;
gbclblLoading.gridy = 1;
panel.add(lblLoading, gbclblLoading);
btnSaveDeck.addActionListener(e -> save());
btnOpen.addActionListener(ae -> open());
btnAddBoosters.addActionListener(ae -> addBooster());
scrollTablePack = new JScrollPane();
scrollTablePack.setPreferredSize(new Dimension(2, 100));
panelControl.add(scrollTablePack);
scrollTablePack.setViewportView(table);
panelAnalyse = new JPanel();
panelWest.add(panelAnalyse, BorderLayout.CENTER);
panelAnalyse.setLayout(new GridLayout(5, 1, 0, 0));
panelSorters = new JPanel();
panelAnalyse.add(panelSorters);
panelSorters.setLayout(new GridLayout(0, 1, 0, 0));
rdioCmcSortButton = new JRadioButton(MTGControler.getInstance().getLangService().getCapitalize("SORT_BY", "cmc"));
rdioCmcSortButton.addActionListener(ae -> sort(new CmcSorter()));
panelSorters.add(rdioCmcSortButton);
rdiocolorSort = new JRadioButton(MTGControler.getInstance().getLangService().getCapitalize("SORT_BY", "color"));
rdiocolorSort.addActionListener(ae -> sort(new ColorSorter()));
panelSorters.add(rdiocolorSort);
rdiotypeSort = new JRadioButton(MTGControler.getInstance().getLangService().getCapitalize("SORT_BY", "type"));
rdiotypeSort.addActionListener(ae -> sort(new TypesSorter()));
panelSorters.add(rdiotypeSort);
ButtonGroup groupSorter = new ButtonGroup();
groupSorter.add(rdioCmcSortButton);
groupSorter.add(rdiocolorSort);
groupSorter.add(rdiotypeSort);
panelAnalyseChooser = new JPanel();
panelSorters.add(panelAnalyseChooser);
FlowLayout flowLayout = (FlowLayout) panelAnalyseChooser.getLayout();
flowLayout.setAlignment(FlowLayout.LEFT);
rdioBoosterAnalyse = new JRadioButton("Booster");
rdioBoosterAnalyse.setSelected(true);
rdioBoosterAnalyse.addActionListener(e -> analyseDeck(false));
panelAnalyseChooser.add(rdioBoosterAnalyse);
rdioDeckAnalyse = new JRadioButton("Deck");
rdioDeckAnalyse.addActionListener(e -> analyseDeck(true));
panelAnalyseChooser.add(rdioDeckAnalyse);
ButtonGroup groupAnalyser = new ButtonGroup();
groupAnalyser.add(rdioBoosterAnalyse);
groupAnalyser.add(rdioDeckAnalyse);
progressBar = new JProgressBar();
progressBar.setMaximum(40);
progressBar.setStringPainted(true);
panelSorters.add(progressBar);
cmcChartPanel = new CmcChartPanel();
panelAnalyse.add(cmcChartPanel);
manaRepartitionPanel = new ManaRepartitionPanel();
panelAnalyse.add(manaRepartitionPanel);
typeRepartitionPanel = new TypeRepartitionPanel();
panelAnalyse.add(typeRepartitionPanel);
panelCenter = new JSplitPane();
panelCenter.setResizeWeight(0.5);
panelCenter.setOrientation(JSplitPane.VERTICAL_SPLIT);
JScrollPane paneBooster = new JScrollPane();
paneBooster.setViewportView(panelOpenedBooster);
panelCenter.setLeftComponent(paneBooster);
panelCenter.setRightComponent(panelDetail);
add(panelCenter, BorderLayout.CENTER);
panelEast = new JPanel();
add(panelEast, BorderLayout.EAST);
panelEast.setLayout(new BorderLayout(0, 0));
panelDeck = new GraveyardPanel() {
@Override
public PositionEnum getOrigine() {
return PositionEnum.DECK;
}
@Override
public void moveCard(DisplayableCard mc, PositionEnum to) {
if (to == PositionEnum.BOOSTER) {
deck.remove(mc.getMagicCard());
list.add(mc.getMagicCard());
refreshStats();
}
}
@Override
public void addComponent(DisplayableCard i) {
super.addComponent(i);
deck.add(i.getMagicCard());
refreshStats();
}
};
JScrollPane scrollDeck = new JScrollPane();
scrollDeck.setViewportView(panelDeck);
panelEast.add(scrollDeck);
panelDeck.setPreferredSize(new Dimension((int) MTGControler.getInstance().getCardsDimension().getWidth() + 5, (int) (MTGControler.getInstance().getCardsDimension().getHeight() * 30)));
panelEast.add(new JLabel(MTGControler.getInstance().getLangService().getCapitalize("DROP_HERE")), BorderLayout.NORTH);
panelLands = new JPanel();
panelEast.add(panelLands, BorderLayout.SOUTH);
txtNumberLand = new JTextField();
panelLands.add(txtNumberLand);
txtNumberLand.setColumns(2);
cboLands = new JComboBox<>(new DefaultComboBoxModel<>(new String[] { "Plains", "Island", "Swamp", "Mountain", "Forest" }));
panelLands.add(cboLands);
JButton btnAddLands = new JButton("+");
btnAddLands.addActionListener(ae -> addLands());
panelLands.add(btnAddLands);
}
Aggregations