Search in sources :

Example 6 with MagicCard

use of org.magic.api.beans.MagicCard in project MtgDesktopCompanion by nicho92.

the class MagicCardDetailPanel method initDataBindings.

protected BindingGroup initDataBindings() {
    BeanProperty<MagicCard, Integer> cmcProperty = BeanProperty.create("cmc");
    BeanProperty<JTextField, String> textProperty = BeanProperty.create("text");
    AutoBinding<MagicCard, Integer, JTextField, String> autoBinding = Bindings.createAutoBinding(UpdateStrategy.READ_WRITE, magicCard, cmcProperty, cmcJTextField, textProperty);
    autoBinding.bind();
    // 
    BeanProperty<MagicCard, String> costProperty = BeanProperty.create("cost");
    BeanProperty<ManaPanel, String> textProperty1 = BeanProperty.create("manaCost");
    AutoBinding<MagicCard, String, ManaPanel, String> autoBinding1 = Bindings.createAutoBinding(UpdateStrategy.READ_WRITE, magicCard, costProperty, manaPanel, textProperty1);
    autoBinding1.bind();
    // 
    BeanProperty<MagicCard, String> fullTypeProperty = BeanProperty.create("fullType");
    BeanProperty<JTextField, String> textProperty2 = BeanProperty.create("text");
    AutoBinding<MagicCard, String, JTextField, String> autoBinding2 = Bindings.createAutoBinding(UpdateStrategy.READ_WRITE, magicCard, fullTypeProperty, fullTypeJTextField, textProperty2);
    autoBinding2.bind();
    // 
    BeanProperty<MagicCard, Integer> loyaltyProperty = BeanProperty.create("loyalty");
    BeanProperty<JTextField, String> textProperty4 = BeanProperty.create("text");
    AutoBinding<MagicCard, Integer, JTextField, String> autoBinding4 = Bindings.createAutoBinding(UpdateStrategy.READ_WRITE, magicCard, loyaltyProperty, loyaltyJTextField, textProperty4);
    autoBinding4.bind();
    // 
    BeanProperty<MagicCard, String> nameProperty = BeanProperty.create("name");
    BeanProperty<JTextField, String> textProperty5 = BeanProperty.create("text");
    AutoBinding<MagicCard, String, JTextField, String> autoBinding5 = Bindings.createAutoBinding(UpdateStrategy.READ_WRITE, magicCard, nameProperty, nameJTextField, textProperty5);
    autoBinding5.bind();
    // 
    BeanProperty<MagicCard, String> powerProperty = BeanProperty.create("power");
    BeanProperty<JTextField, String> textProperty6 = BeanProperty.create("text");
    AutoBinding<MagicCard, String, JTextField, String> autoBinding6 = Bindings.createAutoBinding(UpdateStrategy.READ_WRITE, magicCard, powerProperty, powerJTextField, textProperty6);
    autoBinding6.bind();
    // 
    BeanProperty<MagicCard, String> textProperty8 = BeanProperty.create("text");
    BeanProperty<MagicTextPane, String> textProperty9 = BeanProperty.create("text");
    AutoBinding<MagicCard, String, MagicTextPane, String> autoBinding8 = Bindings.createAutoBinding(UpdateStrategy.READ_WRITE, magicCard, textProperty8, txtTextPane, textProperty9);
    autoBinding8.bind();
    // 
    BeanProperty<MagicCard, String> toughnessProperty = BeanProperty.create("toughness");
    BeanProperty<JTextField, String> textProperty10 = BeanProperty.create("text");
    AutoBinding<MagicCard, String, JTextField, String> autoBinding9 = Bindings.createAutoBinding(UpdateStrategy.READ_WRITE, magicCard, toughnessProperty, toughnessJTextField, textProperty10);
    autoBinding9.bind();
    BeanProperty<MagicCard, String> flavorProperty = BeanProperty.create("flavor");
    BeanProperty<JTextPane, String> textProperty11 = BeanProperty.create("text");
    AutoBinding<MagicCard, String, JTextPane, String> autoBinding10 = Bindings.createAutoBinding(UpdateStrategy.READ_WRITE, magicCard, flavorProperty, txtFlavorArea, textProperty11);
    autoBinding10.bind();
    BeanProperty<MagicCard, String> artistProperty = BeanProperty.create("artist");
    BeanProperty<JTextField, String> textProperty12 = BeanProperty.create("text");
    AutoBinding<MagicCard, String, JTextField, String> autoBinding11 = Bindings.createAutoBinding(UpdateStrategy.READ_WRITE, magicCard, artistProperty, txtArtist, textProperty12);
    autoBinding11.bind();
    BeanProperty<MagicCard, String> layoutProperty = BeanProperty.create("layout");
    BeanProperty<JTextField, String> textProperty13 = BeanProperty.create("text");
    AutoBinding<MagicCard, String, JTextField, String> autoBinding12 = Bindings.createAutoBinding(UpdateStrategy.READ_WRITE, magicCard, layoutProperty, txtLayoutField, textProperty13);
    autoBinding12.bind();
    BeanProperty<MagicCard, String> waterProperty = BeanProperty.create("watermarks");
    BeanProperty<JTextField, String> textProperty14 = BeanProperty.create("text");
    AutoBinding<MagicCard, String, JTextField, String> autoBinding13 = Bindings.createAutoBinding(UpdateStrategy.READ_WRITE, magicCard, waterProperty, txtWatermark, textProperty14);
    autoBinding13.bind();
    BeanProperty<MagicCard, Boolean> reservedProperty = BeanProperty.create("reserved");
    BeanProperty<JCheckBox, Boolean> chkProperty15 = BeanProperty.create("selected");
    AutoBinding<MagicCard, Boolean, JCheckBox, Boolean> autoBinding15 = Bindings.createAutoBinding(UpdateStrategy.READ_WRITE, magicCard, reservedProperty, chckbxReserved, chkProperty15);
    autoBinding15.bind();
    try {
        if (magicCard != null)
            rarityJTextField.setText(magicCard.getEditions().get(0).getRarity());
    } catch (Exception e) {
        rarityJTextField.setText("");
    }
    txtTextPane.updateTextWithIcons();
    if (thumbnail && magicCard != null)
        ThreadManager.getInstance().execute(() -> loadPics(), "load pic");
    if (magicCard != null && !magicCard.getEditions().isEmpty()) {
        ThreadManager.getInstance().execute(() -> {
            setMagicLogo(magicCard.getEditions().get(0).getId(), magicCard.getEditions().get(0).getRarity());
            lblnumberInSet.setText(magicCard.getEditions().get(0).getNumber() + "/" + magicCard.getEditions().get(0).getCardCount());
        }, "loadLogo");
    }
    if (magicCard != null && enableCollectionLookup)
        ThreadManager.getInstance().execute(() -> {
            try {
                ((DefaultListModel) listCollection.getModel()).removeAllElements();
                for (MagicCollection col : MTGControler.getInstance().getEnabledDAO().listCollectionFromCards(magicCard)) ((DefaultListModel) listCollection.getModel()).addElement(col);
            } catch (Exception e) {
                logger.error(e);
            }
        }, "loadCollections");
    if (magicCard != null && enableCollectionLookup)
        ThreadManager.getInstance().execute(() -> {
            if (MTGControler.getInstance().getEnabledDAO().hasAlert(magicCard)) {
                btnAlert.setToolTipText(MTGControler.getInstance().getLangService().getCapitalize("HAD_ALERT"));
                btnAlert.setEnabled(false);
            } else {
                btnAlert.setToolTipText(MTGControler.getInstance().getLangService().getCapitalize("ADD_ALERT_FOR", magicCard.getName()));
                btnAlert.setEnabled(true);
            }
        }, "Get alerts for " + magicCard);
    ((DefaultListModel) lstFormats.getModel()).removeAllElements();
    if (magicCard != null)
        for (MagicFormat mf : magicCard.getLegalities()) ((DefaultListModel) lstFormats.getModel()).addElement(mf);
    // 
    BindingGroup bindingGroup = new BindingGroup();
    // 
    bindingGroup.addBinding(autoBinding);
    bindingGroup.addBinding(autoBinding1);
    bindingGroup.addBinding(autoBinding2);
    bindingGroup.addBinding(autoBinding4);
    bindingGroup.addBinding(autoBinding5);
    bindingGroup.addBinding(autoBinding6);
    bindingGroup.addBinding(autoBinding8);
    bindingGroup.addBinding(autoBinding9);
    bindingGroup.addBinding(autoBinding10);
    bindingGroup.addBinding(autoBinding11);
    bindingGroup.addBinding(autoBinding12);
    bindingGroup.addBinding(autoBinding13);
    bindingGroup.addBinding(autoBinding15);
    return bindingGroup;
}
Also used : DefaultListModel(javax.swing.DefaultListModel) JTextField(javax.swing.JTextField) JTextPane(javax.swing.JTextPane) BindingGroup(org.jdesktop.beansbinding.BindingGroup) MagicCollection(org.magic.api.beans.MagicCollection) MagicFormat(org.magic.api.beans.MagicFormat) JCheckBox(javax.swing.JCheckBox) MagicCard(org.magic.api.beans.MagicCard)

Example 7 with MagicCard

use of org.magic.api.beans.MagicCard in project MtgDesktopCompanion by nicho92.

the class SealedPanel method open.

protected void open() {
    deck = new MagicDeck();
    deck.setDateCreation(new Date());
    deck.setDescription("Sealed from " + model.getSealedPack());
    deck.setName("sealed from " + model.getSealedPack().toList().size() + " boosters");
    panelOpenedBooster.clear();
    panelDeck.removeAll();
    panelDeck.revalidate();
    panelDeck.repaint();
    ThreadManager.getInstance().execute(() -> {
        int column = 0;
        list = new ArrayList<>();
        lblLoading.setVisible(true);
        for (Entry<MagicEdition, Integer> ed : model.getSealedPack().getEntries()) {
            try {
                for (int i = 0; i < ed.getValue(); i++) {
                    Booster b = MTGControler.getInstance().getEnabledProviders().generateBooster(ed.getKey());
                    column++;
                    for (MagicCard mc : b.getCards()) {
                        list.add(mc);
                        DisplayableCard c = createCard(mc);
                        panelOpenedBooster.addComponent(c, column);
                    }
                }
            } catch (IOException e) {
                MTGLogger.printStackTrace(e);
                lblLoading.setVisible(false);
            }
        }
        panelOpenedBooster.setList(list);
        refreshStats();
        lblLoading.setVisible(false);
    });
}
Also used : MagicCard(org.magic.api.beans.MagicCard) Booster(org.magic.api.beans.Booster) DisplayableCard(org.magic.game.gui.components.DisplayableCard) MagicEdition(org.magic.api.beans.MagicEdition) IOException(java.io.IOException) Date(java.util.Date) MagicDeck(org.magic.api.beans.MagicDeck)

Example 8 with MagicCard

use of org.magic.api.beans.MagicCard in project MtgDesktopCompanion by nicho92.

the class SealedPanel method addLands.

private void addLands() {
    int qte = Integer.parseInt(txtNumberLand.getText());
    String land = cboLands.getSelectedItem().toString();
    MagicEdition ed = new MagicEdition();
    ed.setId(MTGControler.getInstance().get("default-land-deck"));
    try {
        MagicCard mc = MTGControler.getInstance().getEnabledProviders().searchCardByCriteria("name", land, ed, true).get(0);
        for (int i = 0; i < qte; i++) {
            deck.add(mc);
            DisplayableCard c = createCard(mc);
            panelDeck.addComponent(c);
            panelDeck.postTreatment(c);
        }
        refreshStats();
    } catch (IOException e) {
        MTGLogger.printStackTrace(e);
    }
}
Also used : MagicCard(org.magic.api.beans.MagicCard) DisplayableCard(org.magic.game.gui.components.DisplayableCard) MagicEdition(org.magic.api.beans.MagicEdition) IOException(java.io.IOException)

Example 9 with MagicCard

use of org.magic.api.beans.MagicCard 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)

Example 10 with MagicCard

use of org.magic.api.beans.MagicCard in project MtgDesktopCompanion by nicho92.

the class DeckDetailsPanel method updatePicture.

public void updatePicture() {
    ThreadManager.getInstance().execute(() -> {
        try {
            panel.removeAll();
            for (int i = 0; i < 4; i++) {
                JLabel lab = new JLabel();
                MagicCard mc = (MagicCard) magicDeck.getMap().keySet().toArray()[i];
                lab.setIcon(new ImageIcon(MTGControler.getInstance().getEnabledPicturesProvider().extractPicture(mc)));
                lab.setToolTipText(mc.getName());
                panel.add(lab);
            }
            panel.revalidate();
            panel.repaint();
        } catch (Exception e) {
            MTGLogger.printStackTrace(e);
        }
    }, "extract deck pictures");
}
Also used : ImageIcon(javax.swing.ImageIcon) MagicCard(org.magic.api.beans.MagicCard) JLabel(javax.swing.JLabel)

Aggregations

MagicCard (org.magic.api.beans.MagicCard)106 MagicEdition (org.magic.api.beans.MagicEdition)40 ArrayList (java.util.ArrayList)31 IOException (java.io.IOException)28 MagicDeck (org.magic.api.beans.MagicDeck)21 MagicCollection (org.magic.api.beans.MagicCollection)14 SQLException (java.sql.SQLException)12 Date (java.util.Date)11 MagicCardStock (org.magic.api.beans.MagicCardStock)10 DisplayableCard (org.magic.game.gui.components.DisplayableCard)10 JsonArray (com.google.gson.JsonArray)8 List (java.util.List)8 FileReader (java.io.FileReader)7 Before (org.junit.Before)7 BufferedReader (java.io.BufferedReader)6 File (java.io.File)6 FileWriter (java.io.FileWriter)6 MalformedURLException (java.net.MalformedURLException)6 PreparedStatement (java.sql.PreparedStatement)6 ResultSet (java.sql.ResultSet)6