Search in sources :

Example 1 with MagicDeck

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

the class MagicGUI method initGUI.

public void initGUI() throws ClassNotFoundException, IOException, SQLException, AWTException {
    JMenuBar mtgMnuBar;
    JMenu mnFile;
    JMenu mnuAbout;
    JMenuItem mntmExit;
    logger.info("init Main GUI");
    setSize(new Dimension(1420, 900));
    setTitle(MTGConstants.MTG_APP_NAME + " ( v" + MTGControler.getInstance().getVersion() + ")");
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setIconImage(MTGConstants.IMAGE_LOGO);
    getContentPane().setLayout(new BorderLayout());
    try {
        tray = SystemTray.getSystemTray();
    } catch (Exception e) {
        logger.error(e);
    }
    mtgMnuBar = new JMenuBar();
    setJMenuBar(mtgMnuBar);
    mnFile = new JMenu(MTGControler.getInstance().getLangService().getCapitalize("FILE"));
    mnuAbout = new JMenu("?");
    mntmExit = new JMenuItem(MTGControler.getInstance().getLangService().getCapitalize("EXIT"));
    JMenuItem mntmHelp = new JMenuItem(MTGControler.getInstance().getLangService().getCapitalize("READ_MANUAL"));
    JMenuItem mntmThreadItem = new JMenuItem(MTGControler.getInstance().getLangService().getCapitalize("THREADS"));
    JMenuItem mntmLogsItem = new JMenuItem(MTGControler.getInstance().getLangService().getCapitalize("LOGS"));
    JMenuItem mntmAboutMagicDesktop = new JMenuItem(MTGControler.getInstance().getLangService().getCapitalize("ABOUT"));
    JMenuItem mntmReportBug = new JMenuItem(MTGControler.getInstance().getLangService().getCapitalize("REPORT_BUG"));
    JMenuItem mntmFileOpen = new JMenuItem(MTGControler.getInstance().getLangService().getCapitalize("OPEN"));
    mtgMnuBar.add(mnFile);
    mnFile.add(mntmFileOpen);
    mnFile.add(mntmExit);
    mtgMnuBar.add(mnuAbout);
    mnuAbout.add(mntmThreadItem);
    mnuAbout.add(mntmLogsItem);
    mnuAbout.add(mntmHelp);
    mnuAbout.add(mntmAboutMagicDesktop);
    mnuAbout.add(mntmReportBug);
    mntmLogsItem.addActionListener(ae -> SwingUtilities.invokeLater(() -> {
        JFrame f = new JFrame(MTGControler.getInstance().getLangService().getCapitalize("LOGS"));
        f.getContentPane().add(new LoggerViewPanel());
        f.setLocationRelativeTo(null);
        f.setVisible(true);
        f.pack();
        f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    }));
    mntmThreadItem.addActionListener(e -> SwingUtilities.invokeLater(() -> {
        JFrame f = new JFrame(MTGControler.getInstance().getLangService().getCapitalize("THREADS"));
        f.getContentPane().add(new ThreadMonitorPanel());
        f.setLocationRelativeTo(null);
        f.setVisible(true);
        f.pack();
        f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    }));
    mntmExit.addActionListener(e -> System.exit(0));
    mntmHelp.addActionListener(e -> {
        String url = MTGConstants.MTG_DESKTOP_WIKI_URL;
        try {
            Desktop.getDesktop().browse(new URI(url));
        } catch (Exception e1) {
            logger.error(e1);
        }
    });
    mntmAboutMagicDesktop.addActionListener(ae -> new AboutDialog().setVisible(true));
    mntmReportBug.addActionListener(ae -> {
        try {
            String url = MTGConstants.MTG_DESKTOP_ISSUES_URL;
            Desktop.getDesktop().browse(new URI(url));
        } catch (Exception e) {
            logger.error(e);
        }
    });
    mntmFileOpen.addActionListener(ae -> {
        JFileChooser choose = new JFileChooser();
        int returnVal = choose.showOpenDialog(null);
        if (returnVal == JFileChooser.APPROVE_OPTION) {
            File f = choose.getSelectedFile();
            MTGCardsExport exp = MTGControler.getInstance().getAbstractExporterFromExt(f);
            if (exp != null) {
                ThreadManager.getInstance().execute(() -> {
                    try {
                        if (cardSearchPanel == null)
                            throw new NullPointerException(MTGControler.getInstance().getLangService().getCapitalize("MUST_BE_LOADED", MTGControler.getInstance().getLangService().get("SEARCH_MODULE")));
                        cardSearchPanel.loading(true, MTGControler.getInstance().getLangService().getCapitalize("LOADING_FILE", f.getName(), exp));
                        MagicDeck d = exp.importDeck(f);
                        cardSearchPanel.open(d.getAsList());
                        cardSearchPanel.loading(false, "");
                        tabbedPane.setSelectedIndex(0);
                    } catch (Exception e) {
                        logger.error(e);
                    }
                }, "open " + f);
            } else {
                JOptionPane.showMessageDialog(null, "NO EXPORTER AVAILABLE", MTGControler.getInstance().getLangService().getError(), JOptionPane.ERROR_MESSAGE);
            }
        }
    });
    if (serviceUpdate.hasNewVersion()) {
        JMenuItem newversion = new JMenuItem(MTGControler.getInstance().getLangService().getCapitalize("DOWNLOAD_LAST_VERSION") + " : " + serviceUpdate.getOnlineVersion());
        newversion.addActionListener(e -> {
            try {
                Desktop.getDesktop().browse(new URI(MTGConstants.MTG_DESKTOP_APP_ZIP));
            } catch (Exception e1) {
                logger.error(e1.getMessage());
            }
        });
        mnuAbout.add(newversion);
    }
    tabbedPane = new JTabbedPane(MTGConstants.MTG_DESKTOP_TABBED_POSITION);
    if (MTGControler.getInstance().get("modules/search").equals("true"))
        tabbedPane.addTab(MTGControler.getInstance().getLangService().getCapitalize("SEARCH_MODULE"), MTGConstants.ICON_SEARCH_2, CardSearchPanel.getInstance(), null);
    if (MTGControler.getInstance().get("modules/deckbuilder").equals("true"))
        tabbedPane.addTab(MTGControler.getInstance().getLangService().getCapitalize("DECK_MODULE"), MTGConstants.ICON_DECK, new DeckBuilderGUI(), null);
    if (MTGControler.getInstance().get("modules/game").equals("true"))
        tabbedPane.addTab(MTGControler.getInstance().getLangService().getCapitalize("GAME_MODULE"), MTGConstants.ICON_COLLECTION_SMALL, new GameGUI(), null);
    if (MTGControler.getInstance().get("modules/collection").equals("true"))
        tabbedPane.addTab(MTGControler.getInstance().getLangService().getCapitalize("COLLECTION_MODULE"), MTGConstants.ICON_COLLECTION, new CollectionPanelGUI(), null);
    if (MTGControler.getInstance().get("modules/stock").equals("true"))
        tabbedPane.addTab(MTGControler.getInstance().getLangService().getCapitalize("STOCK_MODULE"), MTGConstants.ICON_STOCK, new StockPanelGUI(), null);
    if (MTGControler.getInstance().get("modules/dashboard").equals("true"))
        tabbedPane.addTab(MTGControler.getInstance().getLangService().getCapitalize("DASHBOARD_MODULE"), MTGConstants.ICON_DASHBOARD, new DashBoardGUI2(), null);
    if (MTGControler.getInstance().get("modules/shopper").equals("true"))
        tabbedPane.addTab(MTGControler.getInstance().getLangService().getCapitalize("SHOPPING_MODULE"), MTGConstants.ICON_SHOP, new ShopperGUI(), null);
    if (MTGControler.getInstance().get("modules/alarm").equals("true"))
        tabbedPane.addTab(MTGControler.getInstance().getLangService().getCapitalize("ALERT_MODULE"), MTGConstants.ICON_ALERT, new AlarmGUI(), null);
    if (MTGControler.getInstance().get("modules/cardbuilder").equals("true"))
        tabbedPane.addTab(MTGControler.getInstance().getLangService().getCapitalize("BUILDER_MODULE"), MTGConstants.ICON_BUILDER, new CardBuilder2GUI(), null);
    if (MTGControler.getInstance().get("modules/rss").equals("true"))
        tabbedPane.addTab(MTGControler.getInstance().getLangService().getCapitalize("RSS_MODULE"), MTGConstants.ICON_RSS, new RssGUI(), null);
    if (MTGControler.getInstance().get("modules/history").equals("true"))
        tabbedPane.addTab(MTGControler.getInstance().getLangService().getCapitalize("HISTORY_MODULE"), MTGConstants.ICON_STORY, new StoriesGUI(), null);
    if (MTGControler.getInstance().get("modules/wallpaper").equals("true"))
        tabbedPane.addTab(MTGControler.getInstance().getLangService().getCapitalize("WALLPAPER"), MTGConstants.ICON_WALLPAPER, new WallpaperGUI(), null);
    if (MTGControler.getInstance().get("modules/mkm").equals("true"))
        tabbedPane.addTab("MKM", MTGConstants.ICON_SHOP, new MkmPanel(), null);
    getContentPane().add(tabbedPane, BorderLayout.CENTER);
    if (SystemTray.isSupported()) {
        tray.add(trayNotifier);
        trayNotifier.addActionListener(e -> {
            if (!isVisible())
                setVisible(true);
            else
                setVisible(false);
        });
        PopupMenu menuTray = new PopupMenu();
        for (int index_tab = 0; index_tab < tabbedPane.getTabCount(); index_tab++) {
            final int index = index_tab;
            MenuItem it = new MenuItem(tabbedPane.getTitleAt(index_tab));
            it.addActionListener(e -> {
                setVisible(true);
                setSelectedTab(index);
            });
            menuTray.add(it);
        }
        trayNotifier.setPopupMenu(menuTray);
        trayNotifier.setToolTip("MTG Desktop Companion");
        if (serviceUpdate.hasNewVersion())
            trayNotifier.displayMessage(getTitle(), MTGControler.getInstance().getLangService().getCapitalize("NEW_VERSION") + " " + serviceUpdate.getOnlineVersion() + " " + MTGControler.getInstance().getLangService().get("AVAILABLE"), TrayIcon.MessageType.INFO);
        ThreadManager.getInstance().execute(() -> {
            try {
                new TipsOfTheDayDialog().show();
            } catch (IOException e) {
                logger.error(e);
            }
        }, "launch tooltip");
    }
}
Also used : AboutDialog(org.magic.gui.components.dialog.AboutDialog) ThreadMonitorPanel(org.magic.gui.components.ThreadMonitorPanel) MTGCardsExport(org.magic.api.interfaces.MTGCardsExport) JTabbedPane(javax.swing.JTabbedPane) TipsOfTheDayDialog(org.magic.gui.components.dialog.TipsOfTheDayDialog) URI(java.net.URI) LoggerViewPanel(org.magic.gui.components.LoggerViewPanel) BorderLayout(java.awt.BorderLayout) JFrame(javax.swing.JFrame) JMenuItem(javax.swing.JMenuItem) MagicDeck(org.magic.api.beans.MagicDeck) MkmPanel(org.mkm.gui.MkmPanel) JMenuItem(javax.swing.JMenuItem) MenuItem(java.awt.MenuItem) Dimension(java.awt.Dimension) IOException(java.io.IOException) SQLException(java.sql.SQLException) IOException(java.io.IOException) AWTException(java.awt.AWTException) JFileChooser(javax.swing.JFileChooser) File(java.io.File) JMenuBar(javax.swing.JMenuBar) JMenu(javax.swing.JMenu) PopupMenu(java.awt.PopupMenu)

Example 2 with MagicDeck

use of org.magic.api.beans.MagicDeck 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 3 with MagicDeck

use of org.magic.api.beans.MagicDeck 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 4 with MagicDeck

use of org.magic.api.beans.MagicDeck 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 5 with MagicDeck

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

the class MTGSalvationDeckSniffer method getDeck.

@Override
public MagicDeck getDeck(RetrievableDeck info) throws IOException {
    String url = info.getUrl() + "#Details:deck-export";
    logger.debug("sniff url : " + url);
    MagicDeck deck = new MagicDeck();
    deck.setName(info.getName());
    deck.setDateCreation(new Date());
    Document d = Jsoup.connect(url).userAgent(getString("USER_AGENT")).get();
    deck.setDescription(info.getUrl().toString() + "\n" + d.select("section.guide div").text());
    for (Element a : d.select("span.deck-type")) deck.getTags().add(a.text());
    String plainDeck = d.select("section.deck-export-section pre").get(1).text();
    boolean sideboard = false;
    List<String> elements = new ArrayList<>(Arrays.asList(plainDeck.split("\n")));
    elements.remove(0);
    for (String s : elements) {
        if (s.toLowerCase().startsWith("sideboard")) {
            sideboard = true;
        } else if (s.length() > 1) {
            try {
                int qte = Integer.parseInt(s.substring(0, s.indexOf(' ')));
                String cardName = s.substring(s.indexOf(' '), s.length()).trim();
                MagicEdition ed = null;
                if (cardName.trim().equalsIgnoreCase("Plains") || cardName.trim().equalsIgnoreCase("Island") || cardName.trim().equalsIgnoreCase("Swamp") || cardName.trim().equalsIgnoreCase("Mountain") || cardName.trim().equalsIgnoreCase("Forest")) {
                    ed = new MagicEdition();
                    ed.setId(MTGControler.getInstance().get("default-land-deck"));
                }
                MagicCard mc = MTGControler.getInstance().getEnabledProviders().searchCardByCriteria("name", cardName, ed, true).get(0);
                if (!sideboard) {
                    deck.getMap().put(mc, qte);
                } else {
                    deck.getMapSideBoard().put(mc, qte);
                }
            } catch (Exception e) {
                logger.error(e);
            }
        }
    }
    return deck;
}
Also used : MagicCard(org.magic.api.beans.MagicCard) Element(org.jsoup.nodes.Element) ArrayList(java.util.ArrayList) MagicEdition(org.magic.api.beans.MagicEdition) Document(org.jsoup.nodes.Document) Date(java.util.Date) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) MagicDeck(org.magic.api.beans.MagicDeck)

Aggregations

MagicDeck (org.magic.api.beans.MagicDeck)40 MagicCard (org.magic.api.beans.MagicCard)21 MagicCardStock (org.magic.api.beans.MagicCardStock)14 Date (java.util.Date)12 MagicEdition (org.magic.api.beans.MagicEdition)10 FileReader (java.io.FileReader)9 IOException (java.io.IOException)8 Document (org.jsoup.nodes.Document)7 Element (org.jsoup.nodes.Element)7 BufferedReader (java.io.BufferedReader)6 ArrayList (java.util.ArrayList)6 Elements (org.jsoup.select.Elements)6 BorderLayout (java.awt.BorderLayout)3 File (java.io.File)3 JsonArray (com.google.gson.JsonArray)2 JsonParser (com.google.gson.JsonParser)2 Dimension (java.awt.Dimension)2 SQLException (java.sql.SQLException)2 JButton (javax.swing.JButton)2 JFileChooser (javax.swing.JFileChooser)2