Search in sources :

Example 46 with MagicEdition

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

the class ShoppersProviderTests method createCards.

@Before
public void createCards() {
    mc = new MagicCard();
    mc.setName("Black Lotus");
    mc.setLayout("normal");
    mc.setCost("{0}");
    mc.setCmc(0);
    mc.getTypes().add("Artifact");
    mc.setReserved(true);
    mc.setText("{T}, Sacrifice Black Lotus: Add three mana of any one color to your mana pool.");
    mc.setRarity("Rare");
    mc.setArtist("Christopher Rush");
    mc.setId("c944c7dc960c4832604973844edee2a1fdc82d98");
    mc.setMciNumber("232");
    ed = new MagicEdition();
    ed.setId("LEA");
    ed.setSet("Limited Edition Alpha");
    ed.setBorder("Black");
    ed.setRarity("Rare");
    ed.setArtist("Christopher Rush");
    ed.setMultiverse_id("3");
    ed.setNumber("232");
    ed.setMkm_id(1);
    ed.setMkm_name("Alpha");
    mc.getEditions().add(ed);
}
Also used : MagicCard(org.magic.api.beans.MagicCard) MagicEdition(org.magic.api.beans.MagicEdition) Before(org.junit.Before)

Example 47 with MagicEdition

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

the class SealedPanel method initGUI.

private void initGUI() {
    JPanel panelWest;
    JButton btnSaveDeck;
    JSplitPane panelCenter;
    JButton btnAddBoosters;
    JScrollPane scrollTablePack;
    JTable table;
    JPanel panelControl;
    JPanel panelAnalyse;
    JPanel panelSorters;
    JRadioButton rdioCmcSortButton;
    JRadioButton rdiocolorSort;
    JRadioButton rdiotypeSort;
    JPanel panel;
    JPanel panelEast;
    JPanel panelAnalyseChooser;
    JRadioButton rdioDeckAnalyse;
    JRadioButton rdioBoosterAnalyse;
    JPanel panelLands;
    setLayout(new BorderLayout(0, 0));
    panelOpenedBooster = new BoosterPanel();
    model = new SealedPackTableModel();
    panelDetail = new MagicCardDetailPanel();
    panelDetail.enableThumbnail(true);
    panelDetail.enableCollectionLookup(false);
    List<MagicEdition> li;
    try {
        li = MTGControler.getInstance().getEnabledProviders().loadEditions();
    } catch (IOException e1) {
        li = new ArrayList<>();
        MTGLogger.printStackTrace(e1);
    }
    panelWest = new JPanel();
    panelWest.setPreferredSize(new Dimension(300, 10));
    add(panelWest, BorderLayout.WEST);
    panelWest.setLayout(new BorderLayout(0, 0));
    panelControl = new JPanel();
    panelWest.add(panelControl, BorderLayout.NORTH);
    table = new JTable(model);
    table.getColumnModel().getColumn(1).setCellEditor(new IntegerCellEditor());
    panelControl.setLayout(new BorderLayout(0, 0));
    panel = new JPanel();
    panelControl.add(panel, BorderLayout.NORTH);
    GridBagLayout gblpanel = new GridBagLayout();
    gblpanel.columnWidths = new int[] { 105, 65, 0, 0, 0 };
    gblpanel.rowHeights = new int[] { 41, 0, 0 };
    gblpanel.columnWeights = new double[] { 0.0, 0.0, 1.0, 0.0, Double.MIN_VALUE };
    gblpanel.rowWeights = new double[] { 0.0, 0.0, Double.MIN_VALUE };
    panel.setLayout(gblpanel);
    cboEditions = new JComboBox<>();
    GridBagConstraints gbccboEditions = new GridBagConstraints();
    gbccboEditions.fill = GridBagConstraints.HORIZONTAL;
    gbccboEditions.gridwidth = 4;
    gbccboEditions.insets = new Insets(0, 0, 5, 0);
    gbccboEditions.gridx = 0;
    gbccboEditions.gridy = 0;
    panel.add(cboEditions, gbccboEditions);
    cboEditions.setRenderer(new MagicEditionListRenderer());
    cboEditions.setModel(new DefaultComboBoxModel<MagicEdition>(li.toArray(new MagicEdition[li.size()])));
    btnAddBoosters = new JButton(MTGConstants.ICON_NEW);
    GridBagConstraints gbcbtnAddBoosters = new GridBagConstraints();
    gbcbtnAddBoosters.anchor = GridBagConstraints.NORTH;
    gbcbtnAddBoosters.insets = new Insets(0, 0, 0, 5);
    gbcbtnAddBoosters.gridx = 0;
    gbcbtnAddBoosters.gridy = 1;
    panel.add(btnAddBoosters, gbcbtnAddBoosters);
    btnOpen = new JButton(MTGConstants.ICON_OPEN);
    GridBagConstraints gbcbtnOpen = new GridBagConstraints();
    gbcbtnOpen.insets = new Insets(0, 0, 0, 5);
    gbcbtnOpen.anchor = GridBagConstraints.NORTH;
    gbcbtnOpen.gridx = 1;
    gbcbtnOpen.gridy = 1;
    panel.add(btnOpen, gbcbtnOpen);
    btnOpen.setEnabled(false);
    btnSaveDeck = new JButton(MTGConstants.ICON_SAVE);
    GridBagConstraints gbcbtnSaveDeck = new GridBagConstraints();
    gbcbtnSaveDeck.insets = new Insets(0, 0, 0, 5);
    gbcbtnSaveDeck.gridx = 2;
    gbcbtnSaveDeck.gridy = 1;
    panel.add(btnSaveDeck, gbcbtnSaveDeck);
    lblLoading = new JLabel(MTGConstants.ICON_LOADING);
    lblLoading.setVisible(false);
    GridBagConstraints gbclblLoading = new GridBagConstraints();
    gbclblLoading.gridx = 3;
    gbclblLoading.gridy = 1;
    panel.add(lblLoading, gbclblLoading);
    btnSaveDeck.addActionListener(e -> save());
    btnOpen.addActionListener(ae -> open());
    btnAddBoosters.addActionListener(ae -> addBooster());
    scrollTablePack = new JScrollPane();
    scrollTablePack.setPreferredSize(new Dimension(2, 100));
    panelControl.add(scrollTablePack);
    scrollTablePack.setViewportView(table);
    panelAnalyse = new JPanel();
    panelWest.add(panelAnalyse, BorderLayout.CENTER);
    panelAnalyse.setLayout(new GridLayout(5, 1, 0, 0));
    panelSorters = new JPanel();
    panelAnalyse.add(panelSorters);
    panelSorters.setLayout(new GridLayout(0, 1, 0, 0));
    rdioCmcSortButton = new JRadioButton(MTGControler.getInstance().getLangService().getCapitalize("SORT_BY", "cmc"));
    rdioCmcSortButton.addActionListener(ae -> sort(new CmcSorter()));
    panelSorters.add(rdioCmcSortButton);
    rdiocolorSort = new JRadioButton(MTGControler.getInstance().getLangService().getCapitalize("SORT_BY", "color"));
    rdiocolorSort.addActionListener(ae -> sort(new ColorSorter()));
    panelSorters.add(rdiocolorSort);
    rdiotypeSort = new JRadioButton(MTGControler.getInstance().getLangService().getCapitalize("SORT_BY", "type"));
    rdiotypeSort.addActionListener(ae -> sort(new TypesSorter()));
    panelSorters.add(rdiotypeSort);
    ButtonGroup groupSorter = new ButtonGroup();
    groupSorter.add(rdioCmcSortButton);
    groupSorter.add(rdiocolorSort);
    groupSorter.add(rdiotypeSort);
    panelAnalyseChooser = new JPanel();
    panelSorters.add(panelAnalyseChooser);
    FlowLayout flowLayout = (FlowLayout) panelAnalyseChooser.getLayout();
    flowLayout.setAlignment(FlowLayout.LEFT);
    rdioBoosterAnalyse = new JRadioButton("Booster");
    rdioBoosterAnalyse.setSelected(true);
    rdioBoosterAnalyse.addActionListener(e -> analyseDeck(false));
    panelAnalyseChooser.add(rdioBoosterAnalyse);
    rdioDeckAnalyse = new JRadioButton("Deck");
    rdioDeckAnalyse.addActionListener(e -> analyseDeck(true));
    panelAnalyseChooser.add(rdioDeckAnalyse);
    ButtonGroup groupAnalyser = new ButtonGroup();
    groupAnalyser.add(rdioBoosterAnalyse);
    groupAnalyser.add(rdioDeckAnalyse);
    progressBar = new JProgressBar();
    progressBar.setMaximum(40);
    progressBar.setStringPainted(true);
    panelSorters.add(progressBar);
    cmcChartPanel = new CmcChartPanel();
    panelAnalyse.add(cmcChartPanel);
    manaRepartitionPanel = new ManaRepartitionPanel();
    panelAnalyse.add(manaRepartitionPanel);
    typeRepartitionPanel = new TypeRepartitionPanel();
    panelAnalyse.add(typeRepartitionPanel);
    panelCenter = new JSplitPane();
    panelCenter.setResizeWeight(0.5);
    panelCenter.setOrientation(JSplitPane.VERTICAL_SPLIT);
    JScrollPane paneBooster = new JScrollPane();
    paneBooster.setViewportView(panelOpenedBooster);
    panelCenter.setLeftComponent(paneBooster);
    panelCenter.setRightComponent(panelDetail);
    add(panelCenter, BorderLayout.CENTER);
    panelEast = new JPanel();
    add(panelEast, BorderLayout.EAST);
    panelEast.setLayout(new BorderLayout(0, 0));
    panelDeck = new GraveyardPanel() {

        @Override
        public PositionEnum getOrigine() {
            return PositionEnum.DECK;
        }

        @Override
        public void moveCard(DisplayableCard mc, PositionEnum to) {
            if (to == PositionEnum.BOOSTER) {
                deck.remove(mc.getMagicCard());
                list.add(mc.getMagicCard());
                refreshStats();
            }
        }

        @Override
        public void addComponent(DisplayableCard i) {
            super.addComponent(i);
            deck.add(i.getMagicCard());
            refreshStats();
        }
    };
    JScrollPane scrollDeck = new JScrollPane();
    scrollDeck.setViewportView(panelDeck);
    panelEast.add(scrollDeck);
    panelDeck.setPreferredSize(new Dimension((int) MTGControler.getInstance().getCardsDimension().getWidth() + 5, (int) (MTGControler.getInstance().getCardsDimension().getHeight() * 30)));
    panelEast.add(new JLabel(MTGControler.getInstance().getLangService().getCapitalize("DROP_HERE")), BorderLayout.NORTH);
    panelLands = new JPanel();
    panelEast.add(panelLands, BorderLayout.SOUTH);
    txtNumberLand = new JTextField();
    panelLands.add(txtNumberLand);
    txtNumberLand.setColumns(2);
    cboLands = new JComboBox<>(new DefaultComboBoxModel<>(new String[] { "Plains", "Island", "Swamp", "Mountain", "Forest" }));
    panelLands.add(cboLands);
    JButton btnAddLands = new JButton("+");
    btnAddLands.addActionListener(ae -> addLands());
    panelLands.add(btnAddLands);
}
Also used : ColorSorter(org.magic.sorters.ColorSorter) JPanel(javax.swing.JPanel) GridBagConstraints(java.awt.GridBagConstraints) CmcSorter(org.magic.sorters.CmcSorter) JRadioButton(javax.swing.JRadioButton) Insets(java.awt.Insets) FlowLayout(java.awt.FlowLayout) GridBagLayout(java.awt.GridBagLayout) DisplayableCard(org.magic.game.gui.components.DisplayableCard) JButton(javax.swing.JButton) MagicEdition(org.magic.api.beans.MagicEdition) ArrayList(java.util.ArrayList) JProgressBar(javax.swing.JProgressBar) JTextField(javax.swing.JTextField) GridLayout(java.awt.GridLayout) BorderLayout(java.awt.BorderLayout) IntegerCellEditor(org.magic.gui.renderer.IntegerCellEditor) SealedPackTableModel(org.magic.gui.models.SealedPackTableModel) GraveyardPanel(org.magic.game.gui.components.GraveyardPanel) JScrollPane(javax.swing.JScrollPane) PositionEnum(org.magic.game.model.PositionEnum) JLabel(javax.swing.JLabel) IOException(java.io.IOException) Dimension(java.awt.Dimension) DefaultComboBoxModel(javax.swing.DefaultComboBoxModel) ManaRepartitionPanel(org.magic.gui.components.charts.ManaRepartitionPanel) TypesSorter(org.magic.sorters.TypesSorter) TypeRepartitionPanel(org.magic.gui.components.charts.TypeRepartitionPanel) BoosterPanel(org.magic.game.gui.components.BoosterPanel) ButtonGroup(javax.swing.ButtonGroup) JTable(javax.swing.JTable) CmcChartPanel(org.magic.gui.components.charts.CmcChartPanel) JSplitPane(javax.swing.JSplitPane) MagicEditionListRenderer(org.magic.gui.renderer.MagicEditionListRenderer)

Example 48 with MagicEdition

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

the class HistoryPricesPanel method refresh.

private void refresh() {
    TimeSeriesCollection dataset = new TimeSeriesCollection();
    TimeSeries series1 = new TimeSeries(title);
    if (showAll) {
        for (MTGDashBoard d : MTGControler.getInstance().getDashBoards()) {
            TimeSeries series = new TimeSeries(d.getName());
            Map<Date, Double> mapTime;
            try {
                mapTime = d.getPriceVariation(mc, me);
                if (mapTime != null) {
                    for (Entry<Date, Double> da : mapTime.entrySet()) series.add(new Day(da.getKey()), da.getValue().doubleValue());
                    dataset.addSeries(series);
                }
            } catch (IOException e) {
                MTGLogger.printStackTrace(e);
            }
        }
    } else {
        for (Entry<Date, Double> d : map.entrySet()) series1.add(new Day(d.getKey()), d.getValue().doubleValue());
        dataset.addSeries(series1);
    }
    JFreeChart chart = ChartFactory.createTimeSeriesChart("Price Variation", "Date", "Price", dataset, true, true, false);
    if (showEdition)
        try {
            for (MagicEdition edition : MTGControler.getInstance().getEnabledProviders().loadEditions()) {
                Date d = new SimpleDateFormat("yyyy-MM-dd hh:mm").parse(edition.getReleaseDate() + " 00:00");
                TimeSeriesDataItem item = series1.getDataItem(new Day(d));
                if (item != null) {
                    double x = item.getPeriod().getFirstMillisecond();
                    double y = item.getValue().doubleValue();
                    XYTextAnnotation annot = new XYTextAnnotation(edition.getId(), x, y);
                    annot.setToolTipText(edition.getSet());
                    XYPlot plot = (XYPlot) chart.getPlot();
                    plot.addAnnotation(annot);
                }
            }
        } catch (Exception e) {
            MTGLogger.printStackTrace(e);
        }
    pane.setChart(chart);
    pane.addMouseWheelListener(mwe -> {
        if (mwe.getWheelRotation() > 0) {
            pane.zoomOutDomain(0.5, 0.5);
        } else if (mwe.getWheelRotation() < 0) {
            pane.zoomInDomain(1.5, 1.5);
        }
    });
    this.add(pane, BorderLayout.CENTER);
    chart.fireChartChanged();
}
Also used : TimeSeries(org.jfree.data.time.TimeSeries) MTGDashBoard(org.magic.api.interfaces.MTGDashBoard) MagicEdition(org.magic.api.beans.MagicEdition) TimeSeriesDataItem(org.jfree.data.time.TimeSeriesDataItem) IOException(java.io.IOException) Date(java.util.Date) JFreeChart(org.jfree.chart.JFreeChart) IOException(java.io.IOException) XYTextAnnotation(org.jfree.chart.annotations.XYTextAnnotation) XYPlot(org.jfree.chart.plot.XYPlot) TimeSeriesCollection(org.jfree.data.time.TimeSeriesCollection) Day(org.jfree.data.time.Day) SimpleDateFormat(java.text.SimpleDateFormat)

Example 49 with MagicEdition

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

the class AbstractJDashlet method initToolTip.

protected void initToolTip(final JTable table, final Integer cardPos, final Integer edPos) {
    pane = new MagicCardDetailPanel();
    pane.enableThumbnail(true);
    final JPopupMenu popUp = new JPopupMenu();
    table.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent e) {
            int row = table.rowAtPoint(e.getPoint());
            if (row > -1) {
                table.setRowSelectionInterval(row, row);
                String cardName = table.getValueAt(row, cardPos.intValue()).toString();
                if (cardName.indexOf('(') >= 0)
                    cardName = cardName.substring(0, cardName.indexOf('(')).trim();
                MagicEdition ed = null;
                if (edPos != null) {
                    String edID = table.getValueAt(row, edPos).toString();
                    ed = new MagicEdition();
                    ed.setId(edID);
                }
                try {
                    MagicCard mc = MTGControler.getInstance().getEnabledProviders().searchCardByCriteria("name", cardName, ed, true).get(0);
                    pane.setMagicCard(mc);
                    popUp.setBorder(new LineBorder(Color.black));
                    popUp.setVisible(false);
                    popUp.removeAll();
                    popUp.setLayout(new BorderLayout());
                    popUp.add(pane, BorderLayout.CENTER);
                    popUp.show(table, e.getX(), e.getY());
                    popUp.setVisible(true);
                } catch (Exception ex) {
                    logger.error("Error on " + cardName, ex);
                }
            }
        }
    });
}
Also used : MouseEvent(java.awt.event.MouseEvent) MagicCard(org.magic.api.beans.MagicCard) BorderLayout(java.awt.BorderLayout) MagicCardDetailPanel(org.magic.gui.components.MagicCardDetailPanel) LineBorder(javax.swing.border.LineBorder) MouseAdapter(java.awt.event.MouseAdapter) MagicEdition(org.magic.api.beans.MagicEdition) JPopupMenu(javax.swing.JPopupMenu)

Example 50 with MagicEdition

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

the class CardSearchPanel method updateCards.

public void updateCards() {
    try {
        cboLanguages.removeAllItems();
        txtRulesArea.setText("");
        ((DefaultListModel<MagicEdition>) listEdition.getModel()).removeAllElements();
        for (MagicCardNames mcn : selectedCard.getForeignNames()) cboLanguages.addItem(mcn);
        for (MagicEdition me : selectedCard.getEditions()) ((DefaultListModel<MagicEdition>) listEdition.getModel()).addElement(me);
        detailCardPanel.setMagicCard(selectedCard, true);
        magicEditionDetailPanel.setMagicEdition(selectedCard.getEditions().get(0));
        for (MagicRuling mr : selectedCard.getRulings()) {
            txtRulesArea.append(mr.toString());
            txtRulesArea.append("\n");
        }
        if (tabbedCardsInfo.getSelectedIndex() == INDEX_PRICES)
            updatePrices();
        panelJson.show(selectedCard);
        ThreadManager.getInstance().execute(() -> historyChartPanel.init(selectedCard, selectedEdition, selectedCard.getName()), "load history for " + selectedEdition);
    } catch (Exception e1) {
        logger.error(e1);
    }
}
Also used : MagicEdition(org.magic.api.beans.MagicEdition) DefaultListModel(javax.swing.DefaultListModel) MagicCardNames(org.magic.api.beans.MagicCardNames) MagicRuling(org.magic.api.beans.MagicRuling) SQLException(java.sql.SQLException)

Aggregations

MagicEdition (org.magic.api.beans.MagicEdition)67 MagicCard (org.magic.api.beans.MagicCard)38 IOException (java.io.IOException)24 ArrayList (java.util.ArrayList)18 MagicCollection (org.magic.api.beans.MagicCollection)11 MagicDeck (org.magic.api.beans.MagicDeck)10 JsonObject (com.google.gson.JsonObject)9 InputStreamReader (java.io.InputStreamReader)9 JsonReader (com.google.gson.stream.JsonReader)8 List (java.util.List)8 JsonParser (com.google.gson.JsonParser)7 MalformedURLException (java.net.MalformedURLException)7 SQLException (java.sql.SQLException)7 Date (java.util.Date)7 JLabel (javax.swing.JLabel)7 Before (org.junit.Before)7 JsonArray (com.google.gson.JsonArray)6 BufferedImage (java.awt.image.BufferedImage)6 URL (java.net.URL)6 Map (java.util.Map)6