Search in sources :

Example 1 with MagicEditionRenderer

use of org.magic.gui.renderer.MagicEditionRenderer in project MtgDesktopCompanion by nicho92.

the class StockPanelGUI method initGUI.

private void initGUI() {
    JLabel lblSelect;
    JPanel bottomPanel;
    JLabel lblCollection;
    JLabel lblQuality;
    JLabel lblFoil;
    JLabel lblSigned;
    JLabel lblAltered;
    JSplitPane splitPane;
    JLabel lblQte;
    JLabel lblLanguage;
    JLabel lblComment;
    setLayout(new BorderLayout(0, 0));
    model = new CardStockTableModel();
    magicCardDetailPanel = new MagicCardDetailPanel();
    JPanel centerPanel = new JPanel();
    add(centerPanel, BorderLayout.CENTER);
    centerPanel.setLayout(new BorderLayout(0, 0));
    JPanel actionPanel = new JPanel();
    centerPanel.add(actionPanel, BorderLayout.NORTH);
    btnDelete.setEnabled(false);
    btnDelete.setIcon(MTGConstants.ICON_DELETE);
    actionPanel.add(btnDelete);
    btnSave.setToolTipText(MTGControler.getInstance().getLangService().getCapitalize("BATCH_SAVE"));
    btnSave.setIcon(MTGConstants.ICON_SAVE);
    actionPanel.add(btnSave);
    btnReload = new JButton("");
    btnReload.setIcon(MTGConstants.ICON_REFRESH);
    btnReload.setToolTipText(MTGControler.getInstance().getLangService().getCapitalize("RELOAD"));
    actionPanel.add(btnReload);
    lblLoading = new JLabel();
    lblLoading.setVisible(false);
    btnshowMassPanel = new JButton("");
    btnImport = new JButton();
    btnImport.setIcon(MTGConstants.ICON_IMPORT);
    btnImport.setToolTipText(MTGControler.getInstance().getLangService().getCapitalize("IMPORT"));
    actionPanel.add(btnImport);
    btnExport = new JButton("");
    btnExport.setToolTipText(MTGControler.getInstance().getLangService().getCapitalize("EXPORT"));
    btnExport.setIcon(MTGConstants.ICON_EXPORT);
    actionPanel.add(btnExport);
    btnGeneratePrice = new JButton();
    btnGeneratePrice.setIcon(MTGConstants.ICON_EURO);
    btnGeneratePrice.setToolTipText(MTGControler.getInstance().getLangService().getCapitalize("GENERATE_PRICE"));
    actionPanel.add(btnGeneratePrice);
    btnshowMassPanel.setToolTipText(MTGControler.getInstance().getLangService().getCapitalize("MASS_MODIFICATION"));
    btnshowMassPanel.setIcon(MTGConstants.ICON_MANUAL);
    actionPanel.add(btnshowMassPanel);
    lblLoading.setIcon(MTGConstants.ICON_LOADING);
    actionPanel.add(lblLoading);
    JScrollPane scrollTable = new JScrollPane();
    table = new JXTable(model);
    StockTableRenderer render = new StockTableRenderer();
    table.setDefaultRenderer(Object.class, render);
    table.setDefaultEditor(EnumCondition.class, new EnumConditionEditor());
    table.setDefaultEditor(Integer.class, new IntegerCellEditor());
    table.getColumnModel().getColumn(2).setCellEditor(new MagicEditionListEditor());
    table.getColumnModel().getColumn(2).setCellRenderer(new MagicEditionRenderer());
    table.packAll();
    new TableFilterHeader(table, AutoChoices.ENABLED);
    scrollTable.setViewportView(table);
    magicCardDetailPanel.enableThumbnail(true);
    splitPane = new JSplitPane();
    splitPane.setDividerLocation(0.5);
    splitPane.setResizeWeight(0.5);
    splitPane.setOrientation(JSplitPane.VERTICAL_SPLIT);
    centerPanel.add(splitPane, BorderLayout.CENTER);
    splitPane.setLeftComponent(scrollTable);
    splitPane.setRightComponent(magicCardDetailPanel);
    rightPanel = new JPanel();
    rightPanel.setBackground(SystemColor.inactiveCaption);
    rightPanel.setVisible(false);
    add(rightPanel, BorderLayout.EAST);
    GridBagLayout gblrightPanel = new GridBagLayout();
    gblrightPanel.columnWidths = new int[] { 84, 103, 0 };
    gblrightPanel.rowHeights = new int[] { 83, 56, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
    gblrightPanel.columnWeights = new double[] { 0.0, 1.0, Double.MIN_VALUE };
    gblrightPanel.rowWeights = new double[] { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE };
    rightPanel.setLayout(gblrightPanel);
    lblSelect = new JLabel("Select :");
    GridBagConstraints gbclblSelect = new GridBagConstraints();
    gbclblSelect.anchor = GridBagConstraints.NORTHEAST;
    gbclblSelect.insets = new Insets(0, 0, 5, 5);
    gbclblSelect.gridx = 0;
    gbclblSelect.gridy = 1;
    rightPanel.add(lblSelect, gbclblSelect);
    cboSelections = new JComboBox<>();
    cboSelections.setModel(new DefaultComboBoxModel<String>(selections));
    GridBagConstraints gbccomboBox = new GridBagConstraints();
    gbccomboBox.anchor = GridBagConstraints.NORTH;
    gbccomboBox.insets = new Insets(0, 0, 5, 0);
    gbccomboBox.fill = GridBagConstraints.HORIZONTAL;
    gbccomboBox.gridx = 1;
    gbccomboBox.gridy = 1;
    rightPanel.add(cboSelections, gbccomboBox);
    lblQte = new JLabel(MTGControler.getInstance().getLangService().getCapitalize("QTY") + " :");
    GridBagConstraints gbclblQte = new GridBagConstraints();
    gbclblQte.anchor = GridBagConstraints.EAST;
    gbclblQte.insets = new Insets(0, 0, 5, 5);
    gbclblQte.gridx = 0;
    gbclblQte.gridy = 2;
    rightPanel.add(lblQte, gbclblQte);
    spinner = new JSpinner();
    spinner.setModel(new SpinnerNumberModel(0, 0, null, 1));
    GridBagConstraints gbcspinner = new GridBagConstraints();
    gbcspinner.fill = GridBagConstraints.HORIZONTAL;
    gbcspinner.insets = new Insets(0, 0, 5, 0);
    gbcspinner.gridx = 1;
    gbcspinner.gridy = 2;
    rightPanel.add(spinner, gbcspinner);
    lblLanguage = new JLabel(MTGControler.getInstance().getLangService().getCapitalize("CARD_LANGUAGE") + " :");
    GridBagConstraints gbclblLanguage = new GridBagConstraints();
    gbclblLanguage.anchor = GridBagConstraints.EAST;
    gbclblLanguage.insets = new Insets(0, 0, 5, 5);
    gbclblLanguage.gridx = 0;
    gbclblLanguage.gridy = 3;
    rightPanel.add(lblLanguage, gbclblLanguage);
    DefaultComboBoxModel<String> lModel = new DefaultComboBoxModel<>();
    lModel.addElement(null);
    for (Locale l : Locale.getAvailableLocales()) lModel.addElement(l.getDisplayLanguage(Locale.US));
    cboLanguages = new JComboBox<>(lModel);
    GridBagConstraints gbccboLanguages = new GridBagConstraints();
    gbccboLanguages.insets = new Insets(0, 0, 5, 0);
    gbccboLanguages.fill = GridBagConstraints.HORIZONTAL;
    gbccboLanguages.gridx = 1;
    gbccboLanguages.gridy = 3;
    rightPanel.add(cboLanguages, gbccboLanguages);
    lblFoil = new JLabel(MTGControler.getInstance().getLangService().getCapitalize("FOIL") + " :");
    GridBagConstraints gbclblFoil = new GridBagConstraints();
    gbclblFoil.anchor = GridBagConstraints.EAST;
    gbclblFoil.insets = new Insets(0, 0, 5, 5);
    gbclblFoil.gridx = 0;
    gbclblFoil.gridy = 4;
    rightPanel.add(lblFoil, gbclblFoil);
    cboFoil = new JComboBox<>(new DefaultComboBoxModel<Boolean>(values));
    GridBagConstraints gbccboFoil = new GridBagConstraints();
    gbccboFoil.insets = new Insets(0, 0, 5, 0);
    gbccboFoil.fill = GridBagConstraints.HORIZONTAL;
    gbccboFoil.gridx = 1;
    gbccboFoil.gridy = 4;
    rightPanel.add(cboFoil, gbccboFoil);
    lblSigned = new JLabel(MTGControler.getInstance().getLangService().getCapitalize("SIGNED") + " :");
    GridBagConstraints gbclblSigned = new GridBagConstraints();
    gbclblSigned.anchor = GridBagConstraints.EAST;
    gbclblSigned.insets = new Insets(0, 0, 5, 5);
    gbclblSigned.gridx = 0;
    gbclblSigned.gridy = 5;
    rightPanel.add(lblSigned, gbclblSigned);
    cboSigned = new JComboBox<>(new DefaultComboBoxModel<Boolean>(values));
    GridBagConstraints gbccboSigned = new GridBagConstraints();
    gbccboSigned.insets = new Insets(0, 0, 5, 0);
    gbccboSigned.fill = GridBagConstraints.HORIZONTAL;
    gbccboSigned.gridx = 1;
    gbccboSigned.gridy = 5;
    rightPanel.add(cboSigned, gbccboSigned);
    lblAltered = new JLabel(MTGControler.getInstance().getLangService().getCapitalize("ALTERED") + " :");
    GridBagConstraints gbclblAltered = new GridBagConstraints();
    gbclblAltered.anchor = GridBagConstraints.EAST;
    gbclblAltered.insets = new Insets(0, 0, 5, 5);
    gbclblAltered.gridx = 0;
    gbclblAltered.gridy = 6;
    rightPanel.add(lblAltered, gbclblAltered);
    cboAltered = new JComboBox<>(new DefaultComboBoxModel<Boolean>(values));
    GridBagConstraints gbccboAltered = new GridBagConstraints();
    gbccboAltered.insets = new Insets(0, 0, 5, 0);
    gbccboAltered.fill = GridBagConstraints.HORIZONTAL;
    gbccboAltered.gridx = 1;
    gbccboAltered.gridy = 6;
    rightPanel.add(cboAltered, gbccboAltered);
    lblQuality = new JLabel(MTGControler.getInstance().getLangService().getCapitalize("QUALITY") + " :");
    GridBagConstraints gbclblQuality = new GridBagConstraints();
    gbclblQuality.anchor = GridBagConstraints.EAST;
    gbclblQuality.insets = new Insets(0, 0, 5, 5);
    gbclblQuality.gridx = 0;
    gbclblQuality.gridy = 7;
    rightPanel.add(lblQuality, gbclblQuality);
    DefaultComboBoxModel<EnumCondition> qModel = new DefaultComboBoxModel<>();
    qModel.addElement(null);
    for (EnumCondition l : EnumCondition.values()) qModel.addElement(l);
    cboQuality = new JComboBox<>(qModel);
    GridBagConstraints gbccboQuality = new GridBagConstraints();
    gbccboQuality.insets = new Insets(0, 0, 5, 0);
    gbccboQuality.fill = GridBagConstraints.HORIZONTAL;
    gbccboQuality.gridx = 1;
    gbccboQuality.gridy = 7;
    rightPanel.add(cboQuality, gbccboQuality);
    lblCollection = new JLabel(MTGControler.getInstance().getLangService().getCapitalize("COLLECTION") + " :");
    GridBagConstraints gbclblCollection = new GridBagConstraints();
    gbclblCollection.anchor = GridBagConstraints.EAST;
    gbclblCollection.insets = new Insets(0, 0, 5, 5);
    gbclblCollection.gridx = 0;
    gbclblCollection.gridy = 8;
    rightPanel.add(lblCollection, gbclblCollection);
    DefaultComboBoxModel<MagicCollection> cModel = new DefaultComboBoxModel<>();
    cModel.addElement(null);
    try {
        for (MagicCollection l : MTGControler.getInstance().getEnabledDAO().getCollections()) cModel.addElement(l);
    } catch (SQLException e1) {
        MTGLogger.printStackTrace(e1);
    }
    cboCollection = new JComboBox<>(cModel);
    GridBagConstraints gbccboCollection = new GridBagConstraints();
    gbccboCollection.insets = new Insets(0, 0, 5, 0);
    gbccboCollection.fill = GridBagConstraints.HORIZONTAL;
    gbccboCollection.gridx = 1;
    gbccboCollection.gridy = 8;
    rightPanel.add(cboCollection, gbccboCollection);
    lblComment = new JLabel("Comment :");
    GridBagConstraints gbclblComment = new GridBagConstraints();
    gbclblComment.insets = new Insets(0, 0, 5, 5);
    gbclblComment.gridx = 0;
    gbclblComment.gridy = 9;
    rightPanel.add(lblComment, gbclblComment);
    textPane = new JTextPane();
    GridBagConstraints gbctextPane = new GridBagConstraints();
    gbctextPane.insets = new Insets(0, 0, 5, 0);
    gbctextPane.gridwidth = 2;
    gbctextPane.gridheight = 3;
    gbctextPane.fill = GridBagConstraints.BOTH;
    gbctextPane.gridx = 0;
    gbctextPane.gridy = 10;
    rightPanel.add(textPane, gbctextPane);
    btnApplyModification = new JButton(MTGControler.getInstance().getLangService().getCapitalize("APPLY"));
    GridBagConstraints gbcbtnApplyModification = new GridBagConstraints();
    gbcbtnApplyModification.gridwidth = 2;
    gbcbtnApplyModification.gridx = 0;
    gbcbtnApplyModification.gridy = 13;
    rightPanel.add(btnApplyModification, gbcbtnApplyModification);
    bottomPanel = new JPanel();
    add(bottomPanel, BorderLayout.SOUTH);
    lblCount = new JLabel();
    bottomPanel.add(lblCount);
    ThreadManager.getInstance().execute(() -> {
        try {
            lblLoading.setVisible(true);
            model.init();
        } catch (SQLException e1) {
            JOptionPane.showMessageDialog(null, e1.getMessage(), MTGControler.getInstance().getLangService().getError(), JOptionPane.ERROR_MESSAGE);
        }
        lblLoading.setVisible(false);
        updateCount();
    }, "init stock");
}
Also used : Locale(java.util.Locale) JPanel(javax.swing.JPanel) GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) GridBagLayout(java.awt.GridBagLayout) SQLException(java.sql.SQLException) JButton(javax.swing.JButton) EnumConditionEditor(org.magic.gui.renderer.EnumConditionEditor) MagicEditionListEditor(org.magic.gui.renderer.MagicEditionListEditor) SpinnerNumberModel(javax.swing.SpinnerNumberModel) JTextPane(javax.swing.JTextPane) BorderLayout(java.awt.BorderLayout) IntegerCellEditor(org.magic.gui.renderer.IntegerCellEditor) StockTableRenderer(org.magic.gui.renderer.StockTableRenderer) MagicCollection(org.magic.api.beans.MagicCollection) JScrollPane(javax.swing.JScrollPane) JXTable(org.jdesktop.swingx.JXTable) MagicCardDetailPanel(org.magic.gui.components.MagicCardDetailPanel) JLabel(javax.swing.JLabel) TableFilterHeader(net.coderazzi.filters.gui.TableFilterHeader) DefaultComboBoxModel(javax.swing.DefaultComboBoxModel) EnumCondition(org.magic.api.beans.EnumCondition) JSpinner(javax.swing.JSpinner) MagicEditionRenderer(org.magic.gui.renderer.MagicEditionRenderer) JSplitPane(javax.swing.JSplitPane) CardStockTableModel(org.magic.gui.models.CardStockTableModel)

Example 2 with MagicEditionRenderer

use of org.magic.gui.renderer.MagicEditionRenderer 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");
    });
}
Also used : JPanel(javax.swing.JPanel) KeyAdapter(java.awt.event.KeyAdapter) HandPanel(org.magic.game.gui.components.HandPanel) BorderLayout(java.awt.BorderLayout) JToggleButton(javax.swing.JToggleButton) DrawProbabilityPanel(org.magic.gui.components.charts.DrawProbabilityPanel) MagicDeck(org.magic.api.beans.MagicDeck) ManaCellRenderer(org.magic.gui.renderer.ManaCellRenderer) DefaultComboBoxModel(javax.swing.DefaultComboBoxModel) MagicFormat(org.magic.api.beans.MagicFormat) ManaRepartitionPanel(org.magic.gui.components.charts.ManaRepartitionPanel) JFileChooser(javax.swing.JFileChooser) JTable(javax.swing.JTable) MagicEditionRenderer(org.magic.gui.renderer.MagicEditionRenderer) JSplitPane(javax.swing.JSplitPane) Map(java.util.Map) HashMap(java.util.HashMap) File(java.io.File) FlowLayout(java.awt.FlowLayout) JTabbedPane(javax.swing.JTabbedPane) MTGCardsExport(org.magic.api.interfaces.MTGCardsExport) JButton(javax.swing.JButton) DefaultListModel(javax.swing.DefaultListModel) CellEditorListener(javax.swing.event.CellEditorListener) JTextField(javax.swing.JTextField) MagicCardListRenderer(org.magic.gui.renderer.MagicCardListRenderer) MagicEditionListEditor(org.magic.gui.renderer.MagicEditionListEditor) KeyEvent(java.awt.event.KeyEvent) GridLayout(java.awt.GridLayout) IntegerCellEditor(org.magic.gui.renderer.IntegerCellEditor) JMenuItem(javax.swing.JMenuItem) FileFilter(javax.swing.filechooser.FileFilter) Component(java.awt.Component) TableRowSorter(javax.swing.table.TableRowSorter) JScrollPane(javax.swing.JScrollPane) MouseEvent(java.awt.event.MouseEvent) JDeckChooserDialog(org.magic.gui.components.dialog.JDeckChooserDialog) MouseAdapter(java.awt.event.MouseAdapter) JLabel(javax.swing.JLabel) DefaultRowSorter(javax.swing.DefaultRowSorter) RarityRepartitionPanel(org.magic.gui.components.charts.RarityRepartitionPanel) Dimension(java.awt.Dimension) Point(java.awt.Point) JPopupMenu(javax.swing.JPopupMenu) Point(java.awt.Point) TypeRepartitionPanel(org.magic.gui.components.charts.TypeRepartitionPanel) DeckModel(org.magic.gui.models.DeckModel) MagicCard(org.magic.api.beans.MagicCard) ChangeEvent(javax.swing.event.ChangeEvent) ButtonGroup(javax.swing.ButtonGroup) CmcChartPanel(org.magic.gui.components.charts.CmcChartPanel) ButtonModel(javax.swing.ButtonModel)

Aggregations

BorderLayout (java.awt.BorderLayout)2 DefaultComboBoxModel (javax.swing.DefaultComboBoxModel)2 JButton (javax.swing.JButton)2 JLabel (javax.swing.JLabel)2 JPanel (javax.swing.JPanel)2 JScrollPane (javax.swing.JScrollPane)2 JSplitPane (javax.swing.JSplitPane)2 IntegerCellEditor (org.magic.gui.renderer.IntegerCellEditor)2 MagicEditionListEditor (org.magic.gui.renderer.MagicEditionListEditor)2 MagicEditionRenderer (org.magic.gui.renderer.MagicEditionRenderer)2 Component (java.awt.Component)1 Dimension (java.awt.Dimension)1 FlowLayout (java.awt.FlowLayout)1 GridBagConstraints (java.awt.GridBagConstraints)1 GridBagLayout (java.awt.GridBagLayout)1 GridLayout (java.awt.GridLayout)1 Insets (java.awt.Insets)1 Point (java.awt.Point)1 KeyAdapter (java.awt.event.KeyAdapter)1 KeyEvent (java.awt.event.KeyEvent)1