Search in sources :

Example 1 with CardShakeRenderer

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

the class BestTrendingDashlet method init.

@Override
public void init() {
    ThreadManager.getInstance().execute(() -> {
        try {
            List<CardShake> shakes = new ArrayList<>();
            if (boxM.isSelected())
                shakes.addAll(MTGControler.getInstance().getEnabledDashBoard().getShakerFor(FORMAT.MODERN.toString()));
            if (boxS.isSelected())
                shakes.addAll(MTGControler.getInstance().getEnabledDashBoard().getShakerFor(FORMAT.STANDARD.toString()));
            if (boxL.isSelected())
                shakes.addAll(MTGControler.getInstance().getEnabledDashBoard().getShakerFor(FORMAT.LEGACY.toString()));
            if (boxV.isSelected())
                shakes.addAll(MTGControler.getInstance().getEnabledDashBoard().getShakerFor(FORMAT.VINTAGE.toString()));
            Collections.sort(shakes, (CardShake o1, CardShake o2) -> {
                if (o1.getPriceDayChange() > o2.getPriceDayChange())
                    return -1;
                if (o1.getPriceDayChange() < o2.getPriceDayChange())
                    return 1;
                return 0;
            });
            int val = (Integer) spinner.getValue();
            save("LIMIT", String.valueOf(val));
            save("STD", String.valueOf(boxS.isSelected()));
            save("MDN", String.valueOf(boxM.isSelected()));
            save("LEG", String.valueOf(boxL.isSelected()));
            save("VIN", String.valueOf(boxV.isSelected()));
            List<CardShake> ret = new ArrayList<>();
            // X first
            ret.addAll(shakes.subList(0, val));
            // x last
            ret.addAll(shakes.subList(shakes.size() - (val + 1), shakes.size()));
            modStandard.init(ret);
        } catch (IOException e) {
            MTGLogger.printStackTrace(e);
        }
        table.setModel(modStandard);
        table.setRowSorter(new TableRowSorter(modStandard));
        table.packAll();
        table.getColumnModel().getColumn(3).setCellRenderer(new CardShakeRenderer());
        modStandard.fireTableDataChanged();
    }, "Init best Dashlet");
}
Also used : CardShakeRenderer(org.magic.gui.renderer.CardShakeRenderer) ArrayList(java.util.ArrayList) IOException(java.io.IOException) CardShake(org.magic.api.beans.CardShake) TableRowSorter(javax.swing.table.TableRowSorter)

Example 2 with CardShakeRenderer

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

the class EditionsDashlet method initGUI.

public void initGUI() {
    JPanel panel = new JPanel();
    getContentPane().add(panel, BorderLayout.NORTH);
    modEdition = new EditionsShakerTableModel();
    List<MagicEdition> eds = new ArrayList<>();
    try {
        eds.addAll(MTGControler.getInstance().getEnabledProviders().loadEditions());
        Collections.sort(eds);
        eds.add(0, null);
    } catch (Exception e) {
        MTGLogger.printStackTrace(e);
    }
    cboEditions = new JComboBox(new DefaultComboBoxModel<MagicEdition>(eds.toArray(new MagicEdition[eds.size()])));
    cboEditions.setRenderer(new MagicEditionListRenderer());
    panel.add(cboEditions);
    lblLoading = new JLabel("");
    lblLoading.setIcon(MTGConstants.ICON_LOADING);
    lblLoading.setVisible(false);
    panel.add(lblLoading);
    JScrollPane scrollPane = new JScrollPane();
    getContentPane().add(scrollPane, BorderLayout.CENTER);
    table = new JXTable(modEdition);
    initToolTip(table, 0, 1);
    table.getColumnModel().getColumn(3).setCellRenderer(new CardShakeRenderer());
    table.getColumnModel().getColumn(5).setCellRenderer(new CardShakeRenderer());
    scrollPane.setViewportView(table);
    setVisible(true);
    cboEditions.addActionListener(ae -> init());
    if (getProperties().size() > 0) {
        Rectangle r = new Rectangle((int) Double.parseDouble(getProperty("x")), (int) Double.parseDouble(getProperty("y")), (int) Double.parseDouble(getProperty("w")), (int) Double.parseDouble(getProperty("h")));
        MagicEdition ed;
        try {
            ed = MTGControler.getInstance().getEnabledProviders().getSetById(getProperty("EDITION"));
            cboEditions.setSelectedItem(ed);
        } catch (Exception e) {
            logger.error("Error retrieve editions", e);
        }
        setBounds(r);
    }
    try {
        table.packAll();
    } catch (Exception e) {
        MTGLogger.printStackTrace(e);
    }
    new TableFilterHeader(table, AutoChoices.ENABLED);
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) JComboBox(javax.swing.JComboBox) JXTable(org.jdesktop.swingx.JXTable) MagicEdition(org.magic.api.beans.MagicEdition) ArrayList(java.util.ArrayList) Rectangle(java.awt.Rectangle) JLabel(javax.swing.JLabel) DefaultComboBoxModel(javax.swing.DefaultComboBoxModel) TableFilterHeader(net.coderazzi.filters.gui.TableFilterHeader) CardShakeRenderer(org.magic.gui.renderer.CardShakeRenderer) EditionsShakerTableModel(org.magic.gui.models.EditionsShakerTableModel) MagicEditionListRenderer(org.magic.gui.renderer.MagicEditionListRenderer)

Example 3 with CardShakeRenderer

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

the class TrendingDashlet method init.

public void init() {
    ThreadManager.getInstance().execute(() -> {
        lblLoading.setVisible(true);
        modStandard.init((FORMAT) cboFormats.getSelectedItem());
        try {
            table.setModel(modStandard);
        } catch (Exception e) {
            MTGLogger.printStackTrace(e);
        }
        setProperty("FORMAT", ((FORMAT) cboFormats.getSelectedItem()).toString());
        lblLoading.setVisible(false);
        table.getColumnModel().getColumn(3).setCellRenderer(new CardShakeRenderer());
        lblInfoUpdate.setText(MTGControler.getInstance().getEnabledDashBoard().getName() + "(updated : " + new SimpleDateFormat("dd/MM/yyyy HH:mm").format(MTGControler.getInstance().getEnabledDashBoard().getUpdatedDate()) + ")");
        List<SortKey> keys = new ArrayList<>();
        // column index 2
        SortKey sortKey = new SortKey(3, SortOrder.DESCENDING);
        keys.add(sortKey);
        try {
            table.setRowSorter(new TableRowSorter(modStandard));
            ((TableRowSorter) table.getRowSorter()).setSortKeys(keys);
            ((TableRowSorter) table.getRowSorter()).sort();
            modStandard.fireTableDataChanged();
            table.packAll();
        } catch (Exception e) {
            MTGLogger.printStackTrace(e);
        }
    }, "Init Formats Dashlet");
}
Also used : CardShakeRenderer(org.magic.gui.renderer.CardShakeRenderer) ArrayList(java.util.ArrayList) SortKey(javax.swing.RowSorter.SortKey) SimpleDateFormat(java.text.SimpleDateFormat) TableRowSorter(javax.swing.table.TableRowSorter)

Aggregations

ArrayList (java.util.ArrayList)3 CardShakeRenderer (org.magic.gui.renderer.CardShakeRenderer)3 TableRowSorter (javax.swing.table.TableRowSorter)2 Rectangle (java.awt.Rectangle)1 IOException (java.io.IOException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 DefaultComboBoxModel (javax.swing.DefaultComboBoxModel)1 JComboBox (javax.swing.JComboBox)1 JLabel (javax.swing.JLabel)1 JPanel (javax.swing.JPanel)1 JScrollPane (javax.swing.JScrollPane)1 SortKey (javax.swing.RowSorter.SortKey)1 TableFilterHeader (net.coderazzi.filters.gui.TableFilterHeader)1 JXTable (org.jdesktop.swingx.JXTable)1 CardShake (org.magic.api.beans.CardShake)1 MagicEdition (org.magic.api.beans.MagicEdition)1 EditionsShakerTableModel (org.magic.gui.models.EditionsShakerTableModel)1 MagicEditionListRenderer (org.magic.gui.renderer.MagicEditionListRenderer)1