Search in sources :

Example 1 with MagicEditionListRenderer

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());
}
Also used : JPanel(javax.swing.JPanel) JTextArea(javax.swing.JTextArea) MagicEdition(org.magic.api.beans.MagicEdition) ArrayList(java.util.ArrayList) HandPanel(org.magic.game.gui.components.HandPanel) EditionCellRenderer(org.magic.gui.renderer.EditionCellRenderer) BorderLayout(java.awt.BorderLayout) List(java.util.List) ArrayList(java.util.ArrayList) JList(javax.swing.JList) MagicCollection(org.magic.api.beans.MagicCollection) JXTable(org.jdesktop.swingx.JXTable) ManaCellRenderer(org.magic.gui.renderer.ManaCellRenderer) DefaultComboBoxModel(javax.swing.DefaultComboBoxModel) ManaRepartitionPanel(org.magic.gui.components.charts.ManaRepartitionPanel) JFileChooser(javax.swing.JFileChooser) JSplitPane(javax.swing.JSplitPane) File(java.io.File) ImageIcon(javax.swing.ImageIcon) FlowLayout(java.awt.FlowLayout) SQLException(java.sql.SQLException) DefaultTableModel(javax.swing.table.DefaultTableModel) JTabbedPane(javax.swing.JTabbedPane) MTGCardsExport(org.magic.api.interfaces.MTGCardsExport) DisplayableCard(org.magic.game.gui.components.DisplayableCard) JButton(javax.swing.JButton) JTextField(javax.swing.JTextField) URI(java.net.URI) GridLayout(java.awt.GridLayout) Observer(org.utils.patterns.observer.Observer) MagicCardComparator(org.magic.sorters.MagicCardComparator) HistoryPricesPanel(org.magic.gui.components.charts.HistoryPricesPanel) JMenuItem(javax.swing.JMenuItem) Component(java.awt.Component) TableRowSorter(javax.swing.table.TableRowSorter) JScrollPane(javax.swing.JScrollPane) MouseEvent(java.awt.event.MouseEvent) MouseAdapter(java.awt.event.MouseAdapter) JLabel(javax.swing.JLabel) RarityRepartitionPanel(org.magic.gui.components.charts.RarityRepartitionPanel) TableFilterHeader(net.coderazzi.filters.gui.TableFilterHeader) Dimension(java.awt.Dimension) Point(java.awt.Point) MagicCardNames(org.magic.api.beans.MagicCardNames) SQLException(java.sql.SQLException) TypeRepartitionPanel(org.magic.gui.components.charts.TypeRepartitionPanel) Observable(org.utils.patterns.observer.Observable) JPopupMenu(javax.swing.JPopupMenu) Point(java.awt.Point) MagicCard(org.magic.api.beans.MagicCard) CmcChartPanel(org.magic.gui.components.charts.CmcChartPanel) MagicEditionListRenderer(org.magic.gui.renderer.MagicEditionListRenderer)

Example 2 with MagicEditionListRenderer

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);
}
Also used : JPanel(javax.swing.JPanel) MagicEdition(org.magic.api.beans.MagicEdition) ArrayList(java.util.ArrayList) JProgressBar(javax.swing.JProgressBar) JButton(javax.swing.JButton) JTextPane(javax.swing.JTextPane) BorderLayout(java.awt.BorderLayout) MagicCollection(org.magic.api.beans.MagicCollection) MagicDeck(org.magic.api.beans.MagicDeck) JScrollPane(javax.swing.JScrollPane) JComboBox(javax.swing.JComboBox) JLabel(javax.swing.JLabel) IOException(java.io.IOException) SQLException(java.sql.SQLException) IOException(java.io.IOException) JCheckBox(javax.swing.JCheckBox) MagicCard(org.magic.api.beans.MagicCard) MagicEditionListRenderer(org.magic.gui.renderer.MagicEditionListRenderer)

Example 3 with MagicEditionListRenderer

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);
}
Also used : JPanel(javax.swing.JPanel) JTabbedPane(javax.swing.JTabbedPane) MagicEdition(org.magic.api.beans.MagicEdition) ArrayList(java.util.ArrayList) JButton(javax.swing.JButton) Rectangle(java.awt.Rectangle) MagicCardListRenderer(org.magic.gui.renderer.MagicCardListRenderer) SpinnerNumberModel(javax.swing.SpinnerNumberModel) JTextPane(javax.swing.JTextPane) Entry(java.util.Map.Entry) ArrayList(java.util.ArrayList) JList(javax.swing.JList) List(java.util.List) BoostersTableModel(org.magic.gui.models.BoostersTableModel) CardShake(org.magic.api.beans.CardShake) JScrollPane(javax.swing.JScrollPane) JXTable(org.jdesktop.swingx.JXTable) JComboBox(javax.swing.JComboBox) Booster(org.magic.api.beans.Booster) JLabel(javax.swing.JLabel) MagicCard(org.magic.api.beans.MagicCard) JSpinner(javax.swing.JSpinner) HashMap(java.util.HashMap) Map(java.util.Map) MagicEditionListRenderer(org.magic.gui.renderer.MagicEditionListRenderer) JList(javax.swing.JList)

Example 4 with MagicEditionListRenderer

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);
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) JComboBox(javax.swing.JComboBox) JXTable(org.jdesktop.swingx.JXTable) MagicEdition(org.magic.api.beans.MagicEdition) ArrayList(java.util.ArrayList) Rectangle(java.awt.Rectangle) JLabel(javax.swing.JLabel) DefaultComboBoxModel(javax.swing.DefaultComboBoxModel) TableFilterHeader(net.coderazzi.filters.gui.TableFilterHeader) CardShakeRenderer(org.magic.gui.renderer.CardShakeRenderer) EditionsShakerTableModel(org.magic.gui.models.EditionsShakerTableModel) MagicEditionListRenderer(org.magic.gui.renderer.MagicEditionListRenderer)

Example 5 with MagicEditionListRenderer

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);
}
Also used : SpinnerNumberModel(javax.swing.SpinnerNumberModel) FlowLayout(java.awt.FlowLayout) MagicEdition(org.magic.api.beans.MagicEdition) ArrayList(java.util.ArrayList) JSpinner(javax.swing.JSpinner) IOException(java.io.IOException) DefaultComboBoxModel(javax.swing.DefaultComboBoxModel) MagicEditionListRenderer(org.magic.gui.renderer.MagicEditionListRenderer)

Aggregations

ArrayList (java.util.ArrayList)6 MagicEdition (org.magic.api.beans.MagicEdition)6 MagicEditionListRenderer (org.magic.gui.renderer.MagicEditionListRenderer)6 JLabel (javax.swing.JLabel)5 JPanel (javax.swing.JPanel)5 JScrollPane (javax.swing.JScrollPane)5 DefaultComboBoxModel (javax.swing.DefaultComboBoxModel)4 JButton (javax.swing.JButton)4 BorderLayout (java.awt.BorderLayout)3 FlowLayout (java.awt.FlowLayout)3 IOException (java.io.IOException)3 JComboBox (javax.swing.JComboBox)3 JXTable (org.jdesktop.swingx.JXTable)3 MagicCard (org.magic.api.beans.MagicCard)3 Dimension (java.awt.Dimension)2 GridLayout (java.awt.GridLayout)2 Rectangle (java.awt.Rectangle)2 SQLException (java.sql.SQLException)2 List (java.util.List)2 JList (javax.swing.JList)2