Search in sources :

Example 1 with MagicCollection

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

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

the class CardSearchPanel method initPopupCollection.

public void initPopupCollection() throws SQLException {
    JMenu menuItemAdd = new JMenu(MTGControler.getInstance().getLangService().getCapitalize("ADD"));
    for (MagicCollection mc : MTGControler.getInstance().getEnabledDAO().getCollections()) {
        JMenuItem adds = new JMenuItem(mc.getName());
        adds.addActionListener(addEvent -> {
            String collec = ((JMenuItem) addEvent.getSource()).getText();
            loading(true, MTGControler.getInstance().getLangService().getCapitalize("ADD_CARDS_TO") + " " + collec);
            for (int i = 0; i < tableCards.getSelectedRowCount(); i++) {
                int viewRow = tableCards.getSelectedRows()[i];
                int modelRow = tableCards.convertRowIndexToModel(viewRow);
                MagicCard mcCard = (MagicCard) tableCards.getModel().getValueAt(modelRow, 0);
                try {
                    MTGControler.getInstance().getEnabledDAO().saveCard(mcCard, MTGControler.getInstance().getEnabledDAO().getCollection(collec));
                } catch (SQLException e1) {
                    logger.error(e1);
                    JOptionPane.showMessageDialog(null, e1, MTGControler.getInstance().getLangService().getError(), JOptionPane.ERROR_MESSAGE);
                }
            }
            loading(false, "");
        });
        menuItemAdd.add(adds);
    }
    popupMenu.add(menuItemAdd);
}
Also used : MagicCard(org.magic.api.beans.MagicCard) SQLException(java.sql.SQLException) JMenuItem(javax.swing.JMenuItem) JMenu(javax.swing.JMenu) MagicCollection(org.magic.api.beans.MagicCollection) Point(java.awt.Point)

Example 3 with MagicCollection

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

the class CardSearchPanel method initGUI.

private void initGUI() {
    logger.info("init search GUI");
    JPanel panelResultsCards;
    JPanel panelFilters;
    JPanel panelmana;
    JPanel editionDetailPanel;
    JPanel panneauHaut;
    JPanel panneauCard;
    JPanel panneauStat;
    JTextField txtFilter;
    JComboBox<MagicEdition> cboEdition;
    TableFilterHeader filterHeader;
    JButton btnClear;
    JButton btnSearch;
    JButton btnFilter;
    DefaultRowSorter<DefaultTableModel, Integer> sorterCards;
    DefaultRowSorter<DefaultTableModel, Integer> sorterPrice = new TableRowSorter<>(priceModel);
    sorterCards = new TableRowSorter<>(cardsModeltable);
    sorterCards.setComparator(7, (String num1, String num2) -> {
        try {
            num1 = num1.replaceAll("a", "").replaceAll("b", "").trim();
            num2 = num2.replaceAll("a", "").replaceAll("b", "").trim();
            if (Integer.parseInt(num1) > Integer.parseInt(num2))
                return 1;
            else
                return -1;
        } catch (NumberFormatException e) {
            return -1;
        }
    });
    List<MagicEdition> li = new ArrayList<>();
    try {
        li = MTGControler.getInstance().getEnabledProviders().loadEditions();
        Collections.sort(li);
    } catch (Exception e2) {
        logger.error("error no edition loaded", e2);
    }
    // //////INIT COMPONENTS
    JScrollPane scrollEditions = new JScrollPane();
    JScrollPane scrollThumbnails = new JScrollPane();
    JScrollPane scrollPaneRules = new JScrollPane();
    JScrollPane scrollPanePrices = new JScrollPane();
    JScrollPane scrollCards = new JScrollPane();
    JSplitPane panneauCentral = new JSplitPane();
    panneauStat = new JPanel();
    panneauHaut = new JPanel();
    panneauCard = new JPanel();
    editionDetailPanel = new JPanel();
    panelResultsCards = new JPanel();
    cmcChart = new CmcChartPanel();
    manaRepartitionPanel = new ManaRepartitionPanel();
    typeRepartitionPanel = new TypeRepartitionPanel();
    historyChartPanel = new HistoryPricesPanel();
    cardsPicPanel = new CardsPicPanel();
    rarityRepartitionPanel = new RarityRepartitionPanel();
    detailCardPanel = new MagicCardDetailPanel(new MagicCard());
    panelmana = new JPanel();
    panelFilters = new JPanel();
    ManaPanel pan = new ManaPanel();
    panelJson = new JSONPanel();
    tabbedCardsView = new JTabbedPane(JTabbedPane.TOP);
    tabbedCardsInfo = new JTabbedPane(JTabbedPane.TOP);
    thumbnailPanel = new HandPanel();
    thumbnailPanel.setBackground(MTGConstants.THUMBNAIL_BACKGROUND_COLOR);
    btnSearch = new JButton(MTGConstants.ICON_SEARCH);
    btnExport = new JButton(MTGConstants.ICON_EXPORT);
    btnFilter = new JButton(MTGConstants.ICON_FILTER);
    btnClear = new JButton(MTGConstants.ICON_CLEAR);
    cboQuereableItems = new JComboBox<>(new DefaultComboBoxModel<String>(MTGControler.getInstance().getEnabledProviders().getQueryableAttributs()));
    try {
        cboCollections = new JComboBox<>(new DefaultComboBoxModel<MagicCollection>(MTGControler.getInstance().getEnabledDAO().getCollections().toArray(new MagicCollection[MTGControler.getInstance().getEnabledDAO().getCollections().size()])));
    } catch (SQLException e2) {
        logger.error("could not load collections combobox", e2);
    }
    cboLanguages = new JComboBox<>();
    tablePrice = new JXTable();
    tableCards = new JXTable();
    lblLoading = new JLabel(MTGConstants.ICON_LOADING);
    JLabel lblFilter = new JLabel();
    listEdition = new JList<>();
    txtMagicSearch = new JTextField();
    txtRulesArea = new JTextArea();
    txtFilter = new JTextField();
    filterHeader = new TableFilterHeader(tableCards, AutoChoices.ENABLED);
    cboEdition = new JComboBox<>(new DefaultComboBoxModel<MagicEdition>(li.toArray(new MagicEdition[li.size()])));
    // //////MODELS
    listEdition.setModel(new DefaultListModel<MagicEdition>());
    tablePrice.setModel(priceModel);
    tableCards.setModel(cardsModeltable);
    // //////RENDERER
    tableCards.getColumnModel().getColumn(2).setCellRenderer(new ManaCellRenderer());
    tableCards.getColumnModel().getColumn(6).setCellRenderer(new EditionCellRenderer());
    cboEdition.setRenderer(new MagicEditionListRenderer());
    listEdition.setCellRenderer(new MagicEditionListRenderer());
    // ///////CONFIGURE COMPONENTS
    txtRulesArea.setLineWrap(true);
    txtRulesArea.setWrapStyleWord(true);
    txtRulesArea.setEditable(false);
    btnFilter.setToolTipText(MTGControler.getInstance().getLangService().getCapitalize("FILTER"));
    btnExport.setToolTipText(MTGControler.getInstance().getLangService().getCapitalize("EXPORT_RESULTS"));
    btnExport.setEnabled(false);
    filterHeader.setSelectionBackground(Color.LIGHT_GRAY);
    cboQuereableItems.addItem("collections");
    tablePrice.setRowSorter(sorterPrice);
    listEdition.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    thumbnailPanel.enableDragging(false);
    panneauCentral.setOrientation(JSplitPane.VERTICAL_SPLIT);
    panneauCentral.setRightComponent(tabbedCardsInfo);
    panneauCentral.setLeftComponent(tabbedCardsView);
    tableCards.setRowHeight(MTGConstants.TABLE_ROW_HEIGHT);
    tableCards.setRowSorter(sorterCards);
    // /////LAYOUT
    setLayout(new BorderLayout());
    panneauStat.setLayout(new GridLayout(2, 2, 0, 0));
    panneauCard.setLayout(new BorderLayout());
    editionDetailPanel.setLayout(new BorderLayout());
    panelResultsCards.setLayout(new BorderLayout(0, 0));
    panelmana.setLayout(new GridLayout(1, 0, 2, 2));
    FlowLayout flpanelFilters = (FlowLayout) panelFilters.getLayout();
    flpanelFilters.setAlignment(FlowLayout.LEFT);
    FlowLayout flowLayout = (FlowLayout) panneauHaut.getLayout();
    flowLayout.setAlignment(FlowLayout.LEFT);
    // /////DIMENSION
    thumbnailPanel.setThumbnailSize(new Dimension(179, 240));
    tabbedCardsInfo.setPreferredSize(new Dimension(0, 350));
    historyChartPanel.setPreferredSize(new Dimension(400, 10));
    cardsPicPanel.setPreferredSize(new Dimension(400, 10));
    tabbedCardsInfo.setMinimumSize(new Dimension(23, 200));
    scrollCards.setMinimumSize(new Dimension(0, 0));
    scrollThumbnails.getVerticalScrollBar().setUnitIncrement(10);
    txtFilter.setColumns(25);
    txtMagicSearch.setColumns(35);
    // /////VISIBILITY
    tableCards.setColumnControlVisible(true);
    filterHeader.setVisible(false);
    panelFilters.setVisible(false);
    lblLoading.setVisible(false);
    cboCollections.setVisible(false);
    tableCards.setShowVerticalLines(false);
    cboEdition.setVisible(false);
    // ////ADD PANELS
    for (String s : new String[] { "W", "U", "B", "R", "G", "C", "1" }) {
        final JButton btnG = new JButton();
        btnG.setToolTipText(s);
        if (s.equals("1"))
            btnG.setToolTipText("[0-9]*");
        btnG.setIcon(new ImageIcon(pan.getManaSymbol(s).getScaledInstance(15, 15, Image.SCALE_SMOOTH)));
        btnG.setForeground(btnG.getBackground());
        btnG.addActionListener(e -> {
            txtFilter.setText("\\{" + btnG.getToolTipText() + "}");
            sorterCards.setRowFilter(RowFilter.regexFilter(txtFilter.getText()));
        });
        panelmana.add(btnG);
    }
    scrollEditions.setViewportView(listEdition);
    scrollPanePrices.setViewportView(tablePrice);
    scrollCards.setViewportView(tableCards);
    scrollPaneRules.setViewportView(txtRulesArea);
    scrollThumbnails.setViewportView(thumbnailPanel);
    panneauHaut.add(cboQuereableItems);
    panneauHaut.add(cboCollections);
    panneauHaut.add(txtMagicSearch);
    panneauHaut.add(cboEdition);
    panneauHaut.add(btnSearch);
    panneauHaut.add(btnFilter);
    panneauHaut.add(btnExport);
    panneauHaut.add(lblLoading);
    panneauCard.add(cboLanguages, BorderLayout.NORTH);
    panneauCard.add(scrollEditions, BorderLayout.SOUTH);
    panneauCard.add(cardsPicPanel, BorderLayout.CENTER);
    panelResultsCards.add(panelFilters, BorderLayout.NORTH);
    panelResultsCards.add(scrollCards);
    magicEditionDetailPanel = new MagicEditionDetailPanel();
    editionDetailPanel.add(magicEditionDetailPanel, BorderLayout.CENTER);
    panelFilters.add(lblFilter);
    panelFilters.add(txtFilter);
    panelFilters.add(btnClear);
    panelFilters.add(panelmana);
    tabbedCardsInfo.addTab(MTGControler.getInstance().getLangService().getCapitalize("DETAILS"), null, detailCardPanel, null);
    tabbedCardsInfo.addTab(MTGControler.getInstance().getLangService().getCapitalize("EDITION"), null, editionDetailPanel, null);
    tabbedCardsInfo.addTab(MTGControler.getInstance().getLangService().getCapitalize("PRICES"), null, scrollPanePrices, null);
    tabbedCardsInfo.addTab(MTGControler.getInstance().getLangService().getCapitalize("RULES"), null, scrollPaneRules, null);
    tabbedCardsInfo.addTab(MTGControler.getInstance().getLangService().getCapitalize("PRICE_VARIATIONS"), null, historyChartPanel, null);
    if (MTGControler.getInstance().get("debug-json-panel").equalsIgnoreCase("true"))
        tabbedCardsInfo.addTab("Json", null, panelJson, null);
    panneauStat.add(cmcChart);
    panneauStat.add(manaRepartitionPanel);
    panneauStat.add(typeRepartitionPanel);
    panneauStat.add(rarityRepartitionPanel);
    tabbedCardsView.addTab(MTGControler.getInstance().getLangService().getCapitalize("RESULTS"), null, panelResultsCards, null);
    tabbedCardsView.addTab(MTGControler.getInstance().getLangService().getCapitalize("THUMBNAIL"), null, scrollThumbnails, null);
    tabbedCardsView.addTab(MTGControler.getInstance().getLangService().getCapitalize("STATS"), null, panneauStat, null);
    add(panneauHaut, BorderLayout.NORTH);
    add(panneauCard, BorderLayout.EAST);
    add(panneauCentral, BorderLayout.CENTER);
    // /////Right click
    try {
        initPopupCollection();
    } catch (Exception e2) {
        MTGLogger.printStackTrace(e2);
    }
    // /////Action listners
    cboEdition.addActionListener(ae -> txtMagicSearch.setText(((MagicEdition) cboEdition.getSelectedItem()).getId()));
    btnClear.addActionListener(ae -> {
        txtFilter.setText("");
        sorterCards.setRowFilter(null);
    });
    btnFilter.addActionListener(ae -> {
        if (panelFilters.isVisible()) {
            panelFilters.setVisible(false);
            filterHeader.setVisible(false);
        } else {
            panelFilters.setVisible(true);
            filterHeader.setVisible(true);
        }
    });
    cboQuereableItems.addActionListener(e -> {
        if (cboQuereableItems.getSelectedItem().toString().equalsIgnoreCase("set")) {
            txtMagicSearch.setVisible(false);
            cboEdition.setVisible(true);
            cboCollections.setVisible(false);
        } else if (cboQuereableItems.getSelectedItem().toString().equalsIgnoreCase("collections")) {
            txtMagicSearch.setVisible(false);
            cboEdition.setVisible(false);
            cboCollections.setVisible(true);
        } else {
            txtMagicSearch.setVisible(true);
            cboEdition.setVisible(false);
            cboCollections.setVisible(false);
        }
    });
    btnSearch.addActionListener(ae -> {
        Observer ob = new Observer() {

            @Override
            public void update(Observable o, Object arg) {
                cardsModeltable.addCard((MagicCard) arg);
            }
        };
        selectedEdition = null;
        if (txtMagicSearch.getText().equals("") && !cboCollections.isVisible())
            return;
        cardsModeltable.clear();
        new SwingWorker<Object, Object>() {

            protected Void doInBackground() {
                loading(true, MTGControler.getInstance().getLangService().getCapitalize("SEARCHING"));
                String searchName = txtMagicSearch.getText();
                try {
                    MTGControler.getInstance().getEnabledProviders().addObserver(ob);
                    if (cboCollections.isVisible())
                        cards = MTGControler.getInstance().getEnabledDAO().listCardsFromCollection((MagicCollection) cboCollections.getSelectedItem());
                    else
                        cards = MTGControler.getInstance().getEnabledProviders().searchCardByCriteria(cboQuereableItems.getSelectedItem().toString(), searchName, null, false);
                    if (cards.size() < 50)
                        Collections.sort(cards, new MagicCardComparator());
                    open(cards);
                    return null;
                } catch (Exception e) {
                    logger.error("Erreur search", e);
                    return null;
                }
            }

            @Override
            protected void done() {
                super.done();
                loading(false, "");
                cardsModeltable.fireTableDataChanged();
                btnExport.setEnabled(tableCards.getRowCount() > 0);
                MTGControler.getInstance().getEnabledProviders().removeObserver(ob);
            }
        }.execute();
    });
    tableCards.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent evt) {
            if (SwingUtilities.isRightMouseButton(evt)) {
                Point point = evt.getPoint();
                popupMenu.show(tableCards, (int) point.getX(), (int) point.getY());
            } else {
                try {
                    selectedCard = (MagicCard) tableCards.getValueAt(tableCards.getSelectedRow(), 0);
                    selectedEdition = selectedCard.getEditions().get(0);
                    updateCards();
                } catch (Exception e) {
                    logger.error(e);
                }
            }
        }
    });
    listEdition.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent mev) {
            selectedEdition = listEdition.getSelectedValue();
            ThreadManager.getInstance().execute(() -> {
                loading(true, MTGControler.getInstance().getLangService().getCapitalize("LOADING_EDITIONS"));
                try {
                    selectedCard = MTGControler.getInstance().getEnabledProviders().searchCardByCriteria("name", selectedCard.getName(), selectedEdition, false).get(0);
                    detailCardPanel.setMagicCard(selectedCard);
                    magicEditionDetailPanel.setMagicEdition(selectedEdition);
                } catch (Exception e) {
                    MTGLogger.printStackTrace(e);
                }
                // backcard
                cardsPicPanel.showPhoto(selectedCard);
                historyChartPanel.init(selectedCard, selectedEdition, selectedCard.getName());
                if (tabbedCardsInfo.getSelectedIndex() == INDEX_PRICES)
                    updatePrices();
                loading(false, "");
            }, "changeEdition");
        }
    });
    tablePrice.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent ev) {
            if (ev.getClickCount() == 2 && !ev.isConsumed()) {
                ev.consume();
                try {
                    String url = tablePrice.getValueAt(tablePrice.getSelectedRow(), CardsPriceTableModel.ROW_URL).toString();
                    Desktop.getDesktop().browse(new URI(url));
                } catch (Exception e) {
                    logger.error(e);
                }
            }
        }
    });
    cboLanguages.addItemListener(e -> {
        MagicCardNames selLang = (MagicCardNames) cboLanguages.getSelectedItem();
        try {
            if (e.getStateChange() == ItemEvent.SELECTED && selLang != null) {
                MagicEdition ed = (MagicEdition) BeanUtils.cloneBean(selectedEdition);
                ed.setMultiverse_id("" + selLang.getGathererId());
                logger.debug("change lang to " + selLang + " for " + ed);
                cardsPicPanel.showPhoto(selectedCard, ed);
            }
        } catch (Exception e1) {
            logger.error(e1);
        }
    });
    btnExport.addActionListener(ae -> {
        JPopupMenu menu = new JPopupMenu();
        for (final MTGCardsExport exp : MTGControler.getInstance().getEnabledDeckExports()) {
            JMenuItem it = new JMenuItem();
            it.setIcon(exp.getIcon());
            it.setText(exp.getName());
            it.addActionListener(exportEvent -> {
                JFileChooser jf = new JFileChooser(".");
                jf.setSelectedFile(new File("search" + exp.getFileExtension()));
                int result = jf.showSaveDialog(null);
                final File f = jf.getSelectedFile();
                if (result == JFileChooser.APPROVE_OPTION)
                    ThreadManager.getInstance().execute(() -> {
                        try {
                            loading(true, "export " + exp);
                            List<MagicCard> export = ((MagicCardTableModel) tableCards.getRowSorter().getModel()).getListCards();
                            exp.export(export, f);
                            loading(false, "");
                            JOptionPane.showMessageDialog(null, MTGControler.getInstance().getLangService().combine("EXPORT", "FINISHED"), exp.getName() + " " + MTGControler.getInstance().getLangService().get("FINISHED"), JOptionPane.INFORMATION_MESSAGE);
                        } catch (Exception e) {
                            logger.error(e);
                            loading(false, "");
                            JOptionPane.showMessageDialog(null, e, MTGControler.getInstance().getLangService().getError(), JOptionPane.ERROR_MESSAGE);
                        }
                    }, "export search " + exp);
            });
            menu.add(it);
        }
        Component b = (Component) ae.getSource();
        Point p = b.getLocationOnScreen();
        menu.show(b, 0, 0);
        menu.setLocation(p.x, p.y + b.getHeight());
    });
    tabbedCardsInfo.addChangeListener(e -> {
        if (tabbedCardsInfo.getSelectedIndex() == INDEX_PRICES)
            updatePrices();
    });
    txtFilter.addActionListener(ae -> {
        String text = txtFilter.getText();
        if (text.length() == 0) {
            sorterCards.setRowFilter(null);
        } else {
            sorterCards.setRowFilter(RowFilter.regexFilter(text));
        }
    });
    thumbnailPanel.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent e) {
            DisplayableCard lab = (DisplayableCard) thumbnailPanel.getComponentAt(new Point(e.getX(), e.getY()));
            selectedCard = lab.getMagicCard();
            selectedEdition = lab.getMagicCard().getEditions().get(0);
            cardsPicPanel.showPhoto(selectedCard);
            updateCards();
        }
    });
    txtMagicSearch.addActionListener(e -> btnSearch.doClick());
}
Also used : JPanel(javax.swing.JPanel) JTextArea(javax.swing.JTextArea) MagicEdition(org.magic.api.beans.MagicEdition) ArrayList(java.util.ArrayList) HandPanel(org.magic.game.gui.components.HandPanel) EditionCellRenderer(org.magic.gui.renderer.EditionCellRenderer) BorderLayout(java.awt.BorderLayout) List(java.util.List) ArrayList(java.util.ArrayList) JList(javax.swing.JList) MagicCollection(org.magic.api.beans.MagicCollection) JXTable(org.jdesktop.swingx.JXTable) ManaCellRenderer(org.magic.gui.renderer.ManaCellRenderer) DefaultComboBoxModel(javax.swing.DefaultComboBoxModel) ManaRepartitionPanel(org.magic.gui.components.charts.ManaRepartitionPanel) JFileChooser(javax.swing.JFileChooser) JSplitPane(javax.swing.JSplitPane) File(java.io.File) ImageIcon(javax.swing.ImageIcon) FlowLayout(java.awt.FlowLayout) SQLException(java.sql.SQLException) DefaultTableModel(javax.swing.table.DefaultTableModel) JTabbedPane(javax.swing.JTabbedPane) MTGCardsExport(org.magic.api.interfaces.MTGCardsExport) DisplayableCard(org.magic.game.gui.components.DisplayableCard) JButton(javax.swing.JButton) JTextField(javax.swing.JTextField) URI(java.net.URI) GridLayout(java.awt.GridLayout) Observer(org.utils.patterns.observer.Observer) MagicCardComparator(org.magic.sorters.MagicCardComparator) HistoryPricesPanel(org.magic.gui.components.charts.HistoryPricesPanel) JMenuItem(javax.swing.JMenuItem) Component(java.awt.Component) TableRowSorter(javax.swing.table.TableRowSorter) JScrollPane(javax.swing.JScrollPane) MouseEvent(java.awt.event.MouseEvent) MouseAdapter(java.awt.event.MouseAdapter) JLabel(javax.swing.JLabel) RarityRepartitionPanel(org.magic.gui.components.charts.RarityRepartitionPanel) TableFilterHeader(net.coderazzi.filters.gui.TableFilterHeader) Dimension(java.awt.Dimension) Point(java.awt.Point) MagicCardNames(org.magic.api.beans.MagicCardNames) SQLException(java.sql.SQLException) TypeRepartitionPanel(org.magic.gui.components.charts.TypeRepartitionPanel) Observable(org.utils.patterns.observer.Observable) JPopupMenu(javax.swing.JPopupMenu) Point(java.awt.Point) MagicCard(org.magic.api.beans.MagicCard) CmcChartPanel(org.magic.gui.components.charts.CmcChartPanel) MagicEditionListRenderer(org.magic.gui.renderer.MagicEditionListRenderer)

Example 4 with MagicCollection

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

the class CollectionPanelGUI method initGUI.

public void initGUI() throws IOException, SQLException, ClassNotFoundException {
    logger.info("init collection GUI");
    MagicEditionsTableModel model;
    JProgressBar progressBar;
    JTabbedPane tabbedPane;
    TypeRepartitionPanel typeRepartitionPanel;
    ManaRepartitionPanel manaRepartitionPanel;
    RarityRepartitionPanel rarityRepartitionPanel;
    MagicCardDetailPanel magicCardDetailPanel;
    CardStockPanel statsPanel;
    JLabel lblTotal;
    // //////INIT COMPONENTS
    JPanel panneauHaut = new JPanel();
    JButton btnAdd = new JButton(MTGConstants.ICON_NEW);
    JButton btnRefresh = new JButton(MTGConstants.ICON_REFRESH);
    JButton btnRemove = new JButton(MTGConstants.ICON_DELETE);
    JButton btnAddAllSet = new JButton(MTGConstants.ICON_CHECK);
    JButton btnExport = new JButton(MTGConstants.ICON_EXPORT);
    JButton btnMassCollection = new JButton(MTGConstants.ICON_IMPORT);
    JButton btnExportPriceCatalog = new JButton(MTGConstants.ICON_EURO);
    JButton btnGenerateWebSite = new JButton(MTGConstants.ICON_WEBSITE);
    JScrollPane scrollPaneCollections = new JScrollPane();
    JScrollPane scrollPrices = new JScrollPane();
    JSplitPane splitListPanel = new JSplitPane();
    JSplitPane splitPane = new JSplitPane();
    JPanel panneauGauche = new JPanel();
    JScrollPane scrollPane = new JScrollPane();
    JPanel panelTotal = new JPanel();
    JPanel panneauDroite = new JPanel();
    MagicCollectionTableCellRenderer render = new MagicCollectionTableCellRenderer();
    tabbedPane = new JTabbedPane(JTabbedPane.TOP);
    progressBar = new JProgressBar();
    lblTotal = new JLabel();
    magicEditionDetailPanel = new MagicEditionDetailPanel(true, false);
    magicCardDetailPanel = new MagicCardDetailPanel();
    typeRepartitionPanel = new TypeRepartitionPanel();
    manaRepartitionPanel = new ManaRepartitionPanel();
    rarityRepartitionPanel = new RarityRepartitionPanel();
    statsPanel = new CardStockPanel();
    historyPricesPanel = new HistoryPricesPanel();
    jsonPanel = new JSONPanel();
    tree = new LazyLoadingTree();
    tableEditions = new JXTable();
    // //////MODELS
    model = new MagicEditionsTableModel();
    DefaultRowSorter sorterEditions = new TableRowSorter<DefaultTableModel>(model);
    modelPrices = new CardsPriceTableModel();
    tablePrices = new JXTable(modelPrices);
    model.init(provider.loadEditions());
    tableEditions.setModel(model);
    new TableFilterHeader(tableEditions, AutoChoices.ENABLED);
    // ///////CONFIGURE COMPONENTS
    splitListPanel.setDividerLocation(0.5);
    splitListPanel.setResizeWeight(0.5);
    progressBar.setVisible(false);
    btnRemove.setEnabled(true);
    btnExport.setEnabled(false);
    btnExportPriceCatalog.setEnabled(false);
    splitPane.setResizeWeight(0.5);
    splitPane.setOrientation(JSplitPane.VERTICAL_SPLIT);
    scrollPaneCollections.setMinimumSize(new Dimension(0, 0));
    tree.setCellRenderer(new MagicCardsTreeCellRenderer());
    tablePrices.setColumnControlVisible(true);
    magicCardDetailPanel.setPreferredSize(new Dimension(0, 0));
    magicCardDetailPanel.enableThumbnail(true);
    tableEditions.setDefaultRenderer(Object.class, render);
    tableEditions.setDefaultRenderer(String.class, render);
    tableEditions.setDefaultRenderer(Integer.class, render);
    tableEditions.setDefaultRenderer(double.class, render);
    tableEditions.setRowHeight(25);
    tableEditions.setRowSorter(sorterEditions);
    // ///////LAYOUT
    setLayout(new BorderLayout(0, 0));
    panneauDroite.setLayout(new BorderLayout());
    panneauGauche.setLayout(new BorderLayout(0, 0));
    // ///////ADD PANELS
    add(panneauHaut, BorderLayout.NORTH);
    panneauHaut.add(btnAdd);
    panneauHaut.add(btnRefresh);
    panneauHaut.add(btnRemove);
    panneauHaut.add(btnAddAllSet);
    panneauHaut.add(btnMassCollection);
    panneauHaut.add(btnExport);
    panneauHaut.add(btnExportPriceCatalog);
    panneauHaut.add(btnGenerateWebSite);
    panneauHaut.add(progressBar);
    add(splitListPanel, BorderLayout.CENTER);
    splitListPanel.setRightComponent(panneauDroite);
    panneauDroite.add(splitPane, BorderLayout.CENTER);
    splitPane.setLeftComponent(scrollPaneCollections);
    scrollPaneCollections.setViewportView(tree);
    splitPane.setRightComponent(tabbedPane);
    scrollPrices.setViewportView(tablePrices);
    splitListPanel.setLeftComponent(panneauGauche);
    panneauGauche.add(scrollPane);
    scrollPane.setViewportView(tableEditions);
    panneauGauche.add(panelTotal, BorderLayout.SOUTH);
    panelTotal.add(lblTotal);
    tabbedPane.addTab(MTGControler.getInstance().getLangService().getCapitalize("DETAILS"), null, magicCardDetailPanel, null);
    tabbedPane.addTab(MTGControler.getInstance().getLangService().getCapitalize("CARD_EDITIONS"), null, magicEditionDetailPanel, null);
    tabbedPane.addTab(MTGControler.getInstance().getLangService().getCapitalize("PRICES"), null, scrollPrices, null);
    tabbedPane.addTab(MTGControler.getInstance().getLangService().getCapitalize("CARD_TYPES"), null, typeRepartitionPanel, null);
    tabbedPane.addTab(MTGControler.getInstance().getLangService().getCapitalize("CARD_MANA"), null, manaRepartitionPanel, null);
    tabbedPane.addTab(MTGControler.getInstance().getLangService().getCapitalize("CARD_RARITY"), null, rarityRepartitionPanel, null);
    tabbedPane.addTab(MTGControler.getInstance().getLangService().getCapitalize("STOCK_MODULE"), null, statsPanel, null);
    tabbedPane.addTab(MTGControler.getInstance().getLangService().getCapitalize("PRICE_VARIATIONS"), null, historyPricesPanel, null);
    if (MTGControler.getInstance().get("debug-json-panel").equalsIgnoreCase("true"))
        tabbedPane.addTab("Json", null, jsonPanel, null);
    // ///////Labels
    lblTotal.setText("Total : " + model.getCountDefaultLibrary() + "/" + model.getCountTotal());
    btnAdd.setToolTipText(MTGControler.getInstance().getLangService().get("COLLECTION_ADD"));
    btnRefresh.setToolTipText(MTGControler.getInstance().getLangService().getCapitalize("COLLECTION_REFRESH"));
    btnRemove.setToolTipText(MTGControler.getInstance().getLangService().getCapitalize("ITEM_SELECTED_REMOVE"));
    btnAddAllSet.setToolTipText(MTGControler.getInstance().getLangService().getCapitalize("COLLECTION_SET_FULL"));
    btnExport.setToolTipText(MTGControler.getInstance().getLangService().getCapitalize("EXPORT_AS"));
    btnMassCollection.setToolTipText(MTGControler.getInstance().getLangService().getCapitalize("COLLECTION_IMPORT"));
    btnExportPriceCatalog.setToolTipText(MTGControler.getInstance().getLangService().getCapitalize("COLLECTION_EXPORT_PRICES"));
    btnGenerateWebSite.setToolTipText(MTGControler.getInstance().getLangService().getCapitalize("GENERATE_WEBSITE"));
    List<SortKey> keys = new ArrayList<>();
    // column index 2
    SortKey sortKey = new SortKey(3, SortOrder.DESCENDING);
    keys.add(sortKey);
    sorterEditions.setSortKeys(keys);
    tableEditions.packAll();
    initPopupCollection();
    tableEditions.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent arg0) {
            int row = tableEditions.getSelectedRow();
            MagicEdition ed = (MagicEdition) tableEditions.getValueAt(row, 1);
            magicEditionDetailPanel.setMagicEdition(ed);
            historyPricesPanel.init(null, ed, ed.getSet());
            jsonPanel.show(ed);
        }
    });
    btnAdd.addActionListener(e -> {
        String name = JOptionPane.showInputDialog(MTGControler.getInstance().getLangService().getCapitalize("NAME") + " ?");
        MagicCollection collectionAdd = new MagicCollection();
        collectionAdd.setName(name);
        try {
            dao.saveCollection(collectionAdd);
            ((LazyLoadingTree.MyNode) getJTree().getModel().getRoot()).add(new DefaultMutableTreeNode(collectionAdd));
            getJTree().refresh();
            initPopupCollection();
        } catch (Exception ex) {
            logger.error(ex);
            JOptionPane.showMessageDialog(null, ex, MTGControler.getInstance().getLangService().getError(), JOptionPane.ERROR_MESSAGE);
        }
    });
    btnRefresh.addActionListener(e -> ThreadManager.getInstance().execute(() -> {
        progressBar.setVisible(true);
        tree.refresh();
        try {
            model.calculate();
            lblTotal.setText("Total : " + model.getCountDefaultLibrary() + "/" + model.getCountTotal());
        } catch (Exception ex) {
            logger.error(ex);
        }
        model.fireTableDataChanged();
        progressBar.setVisible(false);
    }, "update Tree"));
    btnExport.addActionListener(ae -> {
        JPopupMenu menu = new JPopupMenu();
        for (final MTGCardsExport exp : MTGControler.getInstance().getEnabledDeckExports()) {
            JMenuItem it = new JMenuItem();
            it.setIcon(exp.getIcon());
            it.setText(exp.getName());
            it.addActionListener(arg0 -> ThreadManager.getInstance().execute(() -> {
                try {
                    DefaultMutableTreeNode curr = (DefaultMutableTreeNode) path.getLastPathComponent();
                    JFileChooser jf = new JFileChooser();
                    MagicCollection mc = null;
                    MagicEdition ed = null;
                    if (curr.getUserObject() instanceof MagicEdition) {
                        ed = (MagicEdition) curr.getUserObject();
                        mc = (MagicCollection) ((DefaultMutableTreeNode) curr.getParent()).getUserObject();
                    } else {
                        mc = (MagicCollection) curr.getUserObject();
                    }
                    jf.setSelectedFile(new File(mc.getName() + exp.getFileExtension()));
                    int result = jf.showSaveDialog(null);
                    File f = jf.getSelectedFile();
                    exp.addObserver((Observable o, Object arg) -> progressBar.setValue((int) arg));
                    if (result == JFileChooser.APPROVE_OPTION) {
                        progressBar.setVisible(true);
                        if (ed == null)
                            exp.export(dao.listCardsFromCollection(mc), f);
                        else
                            exp.export(dao.listCardsFromCollection(mc, ed), f);
                        progressBar.setVisible(false);
                        JOptionPane.showMessageDialog(null, MTGControler.getInstance().getLangService().combine("EXPORT", "FINISHED"), MTGControler.getInstance().getLangService().getCapitalize("FINISHED"), JOptionPane.INFORMATION_MESSAGE);
                    }
                } catch (Exception e) {
                    logger.error(e);
                    progressBar.setVisible(false);
                    JOptionPane.showMessageDialog(null, e, MTGControler.getInstance().getLangService().getError(), JOptionPane.ERROR_MESSAGE);
                }
            }, "export collection with " + exp));
            menu.add(it);
        }
        Component b = (Component) ae.getSource();
        Point p = b.getLocationOnScreen();
        menu.show(b, 0, 0);
        menu.setLocation(p.x, p.y + b.getHeight());
    });
    splitPane.addComponentListener(new ComponentAdapter() {

        @Override
        public void componentShown(ComponentEvent componentEvent) {
            splitPane.setDividerLocation(.5);
            removeComponentListener(this);
        }
    });
    tablePrices.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent ev) {
            if (ev.getClickCount() == 2 && !ev.isConsumed()) {
                ev.consume();
                try {
                    String url = tablePrices.getValueAt(tablePrices.getSelectedRow(), CardsPriceTableModel.ROW_URL).toString();
                    Desktop.getDesktop().browse(new URI(url));
                } catch (Exception e) {
                    logger.error(e);
                }
            }
        }
    });
    tree.addTreeSelectionListener(tse -> {
        path = tse.getPath();
        final DefaultMutableTreeNode curr = (DefaultMutableTreeNode) path.getLastPathComponent();
        if (curr.getUserObject() instanceof String) {
            btnExport.setEnabled(false);
            btnExportPriceCatalog.setEnabled(false);
            statsPanel.enabledAdd(false);
        }
        if (curr.getUserObject() instanceof MagicCollection) {
            btnExport.setEnabled(true);
            btnExportPriceCatalog.setEnabled(true);
            selectedcol = (MagicCollection) curr.getUserObject();
            statsPanel.enabledAdd(false);
            btnExport.setEnabled(true);
            btnExportPriceCatalog.setEnabled(true);
        }
        if (curr.getUserObject() instanceof MagicEdition) {
            magicEditionDetailPanel.setMagicEdition((MagicEdition) curr.getUserObject());
            btnExport.setEnabled(true);
            btnExportPriceCatalog.setEnabled(false);
            statsPanel.enabledAdd(false);
            ThreadManager.getInstance().execute(() -> {
                try {
                    MagicCollection collec = (MagicCollection) ((DefaultMutableTreeNode) curr.getParent()).getUserObject();
                    List<MagicCard> list = dao.listCardsFromCollection(collec, (MagicEdition) curr.getUserObject());
                    rarityRepartitionPanel.init(list);
                    typeRepartitionPanel.init(list);
                    manaRepartitionPanel.init(list);
                    historyPricesPanel.init(null, (MagicEdition) curr.getUserObject(), curr.getUserObject().toString());
                    jsonPanel.show(curr.getUserObject());
                } catch (Exception e) {
                    logger.error(e);
                }
            }, "Refresh Collection");
        }
        if (curr.getUserObject() instanceof MagicCard) {
            final MagicCard card = (MagicCard) ((DefaultMutableTreeNode) path.getLastPathComponent()).getUserObject();
            btnExport.setEnabled(false);
            btnExportPriceCatalog.setEnabled(false);
            magicCardDetailPanel.setMagicCard((MagicCard) curr.getUserObject());
            magicEditionDetailPanel.setMagicEdition(card.getEditions().get(0));
            magicCardDetailPanel.enableThumbnail(true);
            jsonPanel.show(curr.getUserObject());
            ThreadManager.getInstance().execute(() -> {
                statsPanel.initMagicCardStock(card, (MagicCollection) ((DefaultMutableTreeNode) curr.getParent().getParent()).getUserObject());
                statsPanel.enabledAdd(true);
            }, "Update Collection");
            if (tabbedPane.getSelectedIndex() == 2) {
                loadPrices(card);
            }
            ThreadManager.getInstance().execute(() -> {
                try {
                    historyPricesPanel.init(card, null, card.getName());
                } catch (Exception e) {
                    logger.error(e);
                }
            }, "update history");
        }
    });
    tabbedPane.addChangeListener(e -> {
        if ((tabbedPane.getSelectedIndex() == 2) && ((DefaultMutableTreeNode) tree.getLastSelectedPathComponent()).getUserObject() instanceof MagicCard)
            loadPrices((MagicCard) ((DefaultMutableTreeNode) tree.getLastSelectedPathComponent()).getUserObject());
    });
    tree.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent e) {
            if (SwingUtilities.isRightMouseButton(e)) {
                int row = tree.getClosestRowForLocation(e.getX(), e.getY());
                tree.setSelectionRow(row);
                final DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent();
                if (node.getUserObject() instanceof MagicEdition) {
                    popupMenuEdition.show(e.getComponent(), e.getX(), e.getY());
                }
                if (node.getUserObject() instanceof MagicCard) {
                    popupMenuCards.show(e.getComponent(), e.getX(), e.getY());
                }
                if (node.getUserObject() instanceof MagicCollection) {
                    JPopupMenu p = new JPopupMenu();
                    JMenuItem it = new JMenuItem("Mass movement");
                    p.add(it);
                    it.addActionListener(ae -> {
                        MassMoverDialog d = new MassMoverDialog((MagicCollection) node.getUserObject(), null);
                        d.setVisible(true);
                        logger.debug("closing mass import with change =" + d.hasChange());
                    });
                    p.show(e.getComponent(), e.getX(), e.getY());
                }
            }
        }
    });
    btnMassCollection.addActionListener(ae -> {
        MassCollectionImporterDialog diag = new MassCollectionImporterDialog();
        diag.setVisible(true);
        try {
            model.calculate();
        } catch (Exception e) {
            logger.error(e);
        }
        model.fireTableDataChanged();
    });
    btnExportPriceCatalog.addActionListener(ae -> ThreadManager.getInstance().execute(() -> {
        try {
            PriceCatalogExportDialog diag = new PriceCatalogExportDialog(selectedcol);
            diag.setVisible(true);
            if (diag.value()) {
                progressBar.setVisible(true);
                progressBar.setStringPainted(true);
                progressBar.setMinimum(0);
                progressBar.setMaximum(dao.getCardsCount(selectedcol, null));
                CSVExport exp = new CSVExport();
                exp.addObserver((Observable o, Object arg) -> progressBar.setValue((int) arg));
                exp.exportPriceCatalog(dao.listCardsFromCollection(selectedcol), diag.getDest(), diag.getPriceProviders());
                JOptionPane.showMessageDialog(null, MTGControler.getInstance().getLangService().combine("EXPORT", "FINISHED"));
                progressBar.setVisible(false);
            }
        } catch (Exception e) {
            logger.error(e);
        }
    }, "btnExportPriceCatalog export Prices"));
    btnGenerateWebSite.addActionListener(ae -> ThreadManager.getInstance().execute(() -> {
        try {
            WebSiteGeneratorDialog diag = new WebSiteGeneratorDialog(dao.getCollections());
            diag.setVisible(true);
            if (diag.value()) {
                progressBar.setVisible(true);
                progressBar.setStringPainted(true);
                progressBar.setMinimum(0);
                int max = 0;
                for (MagicCollection col : diag.getSelectedCollections()) max += dao.getCardsCount(col, null);
                progressBar.setMaximum(max);
                progressBar.setValue(0);
                MagicWebSiteGenerator gen = new MagicWebSiteGenerator(diag.getTemplate(), diag.getDest().getAbsolutePath());
                gen.addObserver((Observable o, Object arg) -> progressBar.setValue((int) arg));
                gen.generate(diag.getSelectedCollections(), diag.getPriceProviders());
                int res = JOptionPane.showConfirmDialog(null, MTGControler.getInstance().getLangService().getCapitalize("WEBSITE_CONFIRMATION_VIEW"));
                if (res == JOptionPane.YES_OPTION) {
                    Path p = Paths.get(diag.getDest().getAbsolutePath() + "/index.htm");
                    Desktop.getDesktop().browse(p.toUri());
                }
                progressBar.setVisible(false);
            }
        } catch (Exception e) {
            logger.error("error generating website", e);
            progressBar.setVisible(false);
            JOptionPane.showMessageDialog(null, e, MTGControler.getInstance().getLangService().getError(), JOptionPane.ERROR_MESSAGE);
        }
    }, "btnGenerateWebSite generate website"));
    btnAddAllSet.addActionListener(evt -> {
        MagicEdition ed = (MagicEdition) tableEditions.getValueAt(tableEditions.getSelectedRow(), 1);
        int res = JOptionPane.showConfirmDialog(null, MTGControler.getInstance().getLangService().getCapitalize("CONFIRM_COLLECTION_ITEM_ADDITION", ed, MTGControler.getInstance().get("default-library")));
        if (res == JOptionPane.YES_OPTION)
            try {
                List<MagicCard> list = provider.searchCardByCriteria("set", ed.getId(), null, false);
                logger.debug("save " + list.size() + " cards from " + ed.getId());
                for (MagicCard mc : list) {
                    MagicCollection col = new MagicCollection();
                    col.setName(MTGControler.getInstance().get("default-library"));
                    dao.saveCard(mc, col);
                }
                model.calculate();
                model.fireTableDataChanged();
            } catch (Exception e) {
                JOptionPane.showMessageDialog(null, e.getMessage(), MTGControler.getInstance().getLangService().getError(), JOptionPane.ERROR_MESSAGE);
                logger.error(e);
            }
    });
    btnRemove.addActionListener(evt -> {
        MagicCollection col = (MagicCollection) ((DefaultMutableTreeNode) path.getPathComponent(1)).getUserObject();
        int res = 0;
        DefaultMutableTreeNode curr = (DefaultMutableTreeNode) path.getLastPathComponent();
        if (curr.getUserObject() instanceof MagicCard) {
            MagicCard card = (MagicCard) ((DefaultMutableTreeNode) path.getLastPathComponent()).getUserObject();
            try {
                res = JOptionPane.showConfirmDialog(null, MTGControler.getInstance().getLangService().getCapitalize("CONFIRM_COLLECTION_ITEM_DELETE", card, col));
                if (res == JOptionPane.YES_OPTION) {
                    dao.removeCard(card, col);
                    curr.removeFromParent();
                }
            } catch (SQLException e) {
                JOptionPane.showMessageDialog(null, e.getMessage(), MTGControler.getInstance().getLangService().getError(), JOptionPane.ERROR_MESSAGE);
            }
        }
        if (curr.getUserObject() instanceof MagicEdition) {
            MagicEdition me = (MagicEdition) ((DefaultMutableTreeNode) path.getPathComponent(2)).getUserObject();
            try {
                res = JOptionPane.showConfirmDialog(null, MTGControler.getInstance().getLangService().getCapitalize("CONFIRM_COLLECTION_ITEM_DELETE", me, col));
                if (res == JOptionPane.YES_OPTION) {
                    dao.removeEdition(me, col);
                    curr.removeFromParent();
                }
            } catch (SQLException e) {
                JOptionPane.showMessageDialog(null, e.getMessage(), MTGControler.getInstance().getLangService().getError(), JOptionPane.ERROR_MESSAGE);
            }
        }
        if (curr.getUserObject() instanceof MagicCollection) {
            try {
                res = JOptionPane.showConfirmDialog(null, MTGControler.getInstance().getLangService().getCapitalize("CONFIRM_COLLECTION_DELETE", col, dao.getCardsCount(col, null)));
                if (res == JOptionPane.YES_OPTION) {
                    dao.removeCollection(col);
                    curr.removeFromParent();
                }
            } catch (SQLException e) {
                JOptionPane.showMessageDialog(null, e.getMessage(), MTGControler.getInstance().getLangService().getError(), JOptionPane.ERROR_MESSAGE);
            }
        }
        if (res == JOptionPane.YES_OPTION) {
            try {
                model.calculate();
            } catch (Exception e) {
                JOptionPane.showMessageDialog(null, e.getMessage(), MTGControler.getInstance().getLangService().getError(), JOptionPane.ERROR_MESSAGE);
            }
            tree.refresh();
        }
    });
}
Also used : MagicCollection(org.magic.api.beans.MagicCollection) Point(java.awt.Point) MTGDao(org.magic.api.interfaces.MTGDao) RarityRepartitionPanel(org.magic.gui.components.charts.RarityRepartitionPanel) Logger(org.apache.log4j.Logger) TableFilterHeader(net.coderazzi.filters.gui.TableFilterHeader) MouseAdapter(java.awt.event.MouseAdapter) URI(java.net.URI) JFileChooser(javax.swing.JFileChooser) PriceCatalogExportDialog(org.magic.gui.components.dialog.PriceCatalogExportDialog) WebSiteGeneratorDialog(org.magic.gui.components.dialog.WebSiteGeneratorDialog) BorderLayout(java.awt.BorderLayout) Path(java.nio.file.Path) CSVExport(org.magic.api.exports.impl.CSVExport) MTGCardsProvider(org.magic.api.interfaces.MTGCardsProvider) TypeRepartitionPanel(org.magic.gui.components.charts.TypeRepartitionPanel) DefaultTableModel(javax.swing.table.DefaultTableModel) TreePath(javax.swing.tree.TreePath) MagicCardsTreeCellRenderer(org.magic.gui.renderer.MagicCardsTreeCellRenderer) JMenu(javax.swing.JMenu) ComponentEvent(java.awt.event.ComponentEvent) Component(java.awt.Component) TableRowSorter(javax.swing.table.TableRowSorter) JXTable(org.jdesktop.swingx.JXTable) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) CardsPriceTableModel(org.magic.gui.models.CardsPriceTableModel) HistoryPricesPanel(org.magic.gui.components.charts.HistoryPricesPanel) Dimension(java.awt.Dimension) List(java.util.List) MagicEdition(org.magic.api.beans.MagicEdition) MagicCard(org.magic.api.beans.MagicCard) MagicCardDetailPanel(org.magic.gui.components.MagicCardDetailPanel) JPanel(javax.swing.JPanel) DefaultRowSorter(javax.swing.DefaultRowSorter) JSplitPane(javax.swing.JSplitPane) MassCollectionImporterDialog(org.magic.gui.components.dialog.MassCollectionImporterDialog) Observable(org.utils.patterns.observer.Observable) MTGControler(org.magic.services.MTGControler) SortKey(javax.swing.RowSorter.SortKey) CardStockPanel(org.magic.gui.components.CardStockPanel) MagicEditionDetailPanel(org.magic.gui.components.MagicEditionDetailPanel) ArrayList(java.util.ArrayList) SQLException(java.sql.SQLException) SwingUtilities(javax.swing.SwingUtilities) JMenuItem(javax.swing.JMenuItem) JTabbedPane(javax.swing.JTabbedPane) JProgressBar(javax.swing.JProgressBar) JSONPanel(org.magic.gui.components.JSONPanel) MagicCollectionTableCellRenderer(org.magic.gui.renderer.MagicCollectionTableCellRenderer) ManaRepartitionPanel(org.magic.gui.components.charts.ManaRepartitionPanel) Desktop(java.awt.Desktop) LazyLoadingTree(org.magic.gui.components.LazyLoadingTree) MTGLogger(org.magic.services.MTGLogger) JButton(javax.swing.JButton) JPopupMenu(javax.swing.JPopupMenu) MTGCardsExport(org.magic.api.interfaces.MTGCardsExport) IOException(java.io.IOException) JOptionPane(javax.swing.JOptionPane) CardSearchPanel(org.magic.gui.components.CardSearchPanel) MouseEvent(java.awt.event.MouseEvent) File(java.io.File) ComponentAdapter(java.awt.event.ComponentAdapter) JScrollPane(javax.swing.JScrollPane) SortOrder(javax.swing.SortOrder) MagicWebSiteGenerator(org.magic.services.MagicWebSiteGenerator) Paths(java.nio.file.Paths) JLabel(javax.swing.JLabel) ThreadManager(org.magic.services.ThreadManager) AutoChoices(net.coderazzi.filters.gui.AutoChoices) MagicEditionsTableModel(org.magic.gui.models.MagicEditionsTableModel) MassMoverDialog(org.magic.gui.components.dialog.MassMoverDialog) MTGConstants(org.magic.services.MTGConstants) JPanel(javax.swing.JPanel) ArrayList(java.util.ArrayList) MagicEdition(org.magic.api.beans.MagicEdition) CardsPriceTableModel(org.magic.gui.models.CardsPriceTableModel) WebSiteGeneratorDialog(org.magic.gui.components.dialog.WebSiteGeneratorDialog) MassMoverDialog(org.magic.gui.components.dialog.MassMoverDialog) BorderLayout(java.awt.BorderLayout) CardStockPanel(org.magic.gui.components.CardStockPanel) PriceCatalogExportDialog(org.magic.gui.components.dialog.PriceCatalogExportDialog) List(java.util.List) ArrayList(java.util.ArrayList) MagicCollection(org.magic.api.beans.MagicCollection) MassCollectionImporterDialog(org.magic.gui.components.dialog.MassCollectionImporterDialog) JXTable(org.jdesktop.swingx.JXTable) MagicCardDetailPanel(org.magic.gui.components.MagicCardDetailPanel) ManaRepartitionPanel(org.magic.gui.components.charts.ManaRepartitionPanel) JFileChooser(javax.swing.JFileChooser) ComponentEvent(java.awt.event.ComponentEvent) JSplitPane(javax.swing.JSplitPane) File(java.io.File) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) SQLException(java.sql.SQLException) JTabbedPane(javax.swing.JTabbedPane) MTGCardsExport(org.magic.api.interfaces.MTGCardsExport) JProgressBar(javax.swing.JProgressBar) JButton(javax.swing.JButton) MagicEditionDetailPanel(org.magic.gui.components.MagicEditionDetailPanel) SortKey(javax.swing.RowSorter.SortKey) URI(java.net.URI) HistoryPricesPanel(org.magic.gui.components.charts.HistoryPricesPanel) JMenuItem(javax.swing.JMenuItem) Component(java.awt.Component) TableRowSorter(javax.swing.table.TableRowSorter) ComponentAdapter(java.awt.event.ComponentAdapter) JScrollPane(javax.swing.JScrollPane) Path(java.nio.file.Path) TreePath(javax.swing.tree.TreePath) MouseEvent(java.awt.event.MouseEvent) MagicCollectionTableCellRenderer(org.magic.gui.renderer.MagicCollectionTableCellRenderer) MouseAdapter(java.awt.event.MouseAdapter) JLabel(javax.swing.JLabel) RarityRepartitionPanel(org.magic.gui.components.charts.RarityRepartitionPanel) LazyLoadingTree(org.magic.gui.components.LazyLoadingTree) DefaultRowSorter(javax.swing.DefaultRowSorter) CSVExport(org.magic.api.exports.impl.CSVExport) TableFilterHeader(net.coderazzi.filters.gui.TableFilterHeader) Dimension(java.awt.Dimension) MagicCardsTreeCellRenderer(org.magic.gui.renderer.MagicCardsTreeCellRenderer) Point(java.awt.Point) MagicEditionsTableModel(org.magic.gui.models.MagicEditionsTableModel) TypeRepartitionPanel(org.magic.gui.components.charts.TypeRepartitionPanel) SQLException(java.sql.SQLException) IOException(java.io.IOException) JPopupMenu(javax.swing.JPopupMenu) Observable(org.utils.patterns.observer.Observable) Point(java.awt.Point) MagicCard(org.magic.api.beans.MagicCard) MagicWebSiteGenerator(org.magic.services.MagicWebSiteGenerator) JSONPanel(org.magic.gui.components.JSONPanel)

Example 5 with MagicCollection

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

Aggregations

MagicCollection (org.magic.api.beans.MagicCollection)32 ArrayList (java.util.ArrayList)20 MagicCard (org.magic.api.beans.MagicCard)15 SQLException (java.sql.SQLException)14 MagicEdition (org.magic.api.beans.MagicEdition)13 PreparedStatement (java.sql.PreparedStatement)12 ResultSet (java.sql.ResultSet)12 IOException (java.io.IOException)9 MagicCardStock (org.magic.api.beans.MagicCardStock)8 File (java.io.File)7 List (java.util.List)6 BorderLayout (java.awt.BorderLayout)4 Map (java.util.Map)4 JButton (javax.swing.JButton)4 JLabel (javax.swing.JLabel)4 JPanel (javax.swing.JPanel)4 JScrollPane (javax.swing.JScrollPane)4 BasicDBObject (com.mongodb.BasicDBObject)3 DeleteResult (com.mongodb.client.result.DeleteResult)3 Point (java.awt.Point)3