Search in sources :

Example 1 with MTGDashBoard

use of org.magic.api.interfaces.MTGDashBoard 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 2 with MTGDashBoard

use of org.magic.api.interfaces.MTGDashBoard in project MtgDesktopCompanion by nicho92.

the class SpeedConfigurator method save.

protected void save() {
    for (MTGCardsProvider prov : MTGControler.getInstance().getListProviders()) {
        prov.enable(false);
        if (prov.getName().equals(cboProvider.getSelectedItem().toString()))
            prov.enable(true);
        MTGControler.getInstance().setProperty(prov, prov.isEnable());
    }
    for (MTGDao prov : MTGControler.getInstance().getDaoProviders()) {
        prov.enable(false);
        if (prov.getName().equals(cboDAOs.getSelectedItem().toString()))
            prov.enable(true);
        MTGControler.getInstance().setProperty(prov, prov.isEnable());
    }
    for (MTGPictureProvider prov : MTGControler.getInstance().getPicturesProviders()) {
        prov.enable(false);
        if (prov.getName().equals(cboPictures.getSelectedItem().toString()))
            prov.enable(true);
        MTGControler.getInstance().setProperty(prov, prov.isEnable());
    }
    for (MTGPicturesCache prov : MTGControler.getInstance().getListCaches()) {
        prov.enable(false);
        if (prov.getName().equals(cboCaches.getSelectedItem().toString()))
            prov.enable(true);
        MTGControler.getInstance().setProperty(prov, prov.isEnable());
    }
    for (MTGDashBoard prov : MTGControler.getInstance().getDashBoards()) {
        prov.enable(false);
        if (prov.getName().equals(cboDashboard.getSelectedItem().toString()))
            prov.enable(true);
        MTGControler.getInstance().setProperty(prov, prov.isEnable());
    }
    System.exit(0);
}
Also used : MTGPictureProvider(org.magic.api.interfaces.MTGPictureProvider) MTGDao(org.magic.api.interfaces.MTGDao) MTGDashBoard(org.magic.api.interfaces.MTGDashBoard) MTGPicturesCache(org.magic.api.interfaces.MTGPicturesCache) MTGCardsProvider(org.magic.api.interfaces.MTGCardsProvider)

Aggregations

MTGDashBoard (org.magic.api.interfaces.MTGDashBoard)2 IOException (java.io.IOException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 JFreeChart (org.jfree.chart.JFreeChart)1 XYTextAnnotation (org.jfree.chart.annotations.XYTextAnnotation)1 XYPlot (org.jfree.chart.plot.XYPlot)1 Day (org.jfree.data.time.Day)1 TimeSeries (org.jfree.data.time.TimeSeries)1 TimeSeriesCollection (org.jfree.data.time.TimeSeriesCollection)1 TimeSeriesDataItem (org.jfree.data.time.TimeSeriesDataItem)1 MagicEdition (org.magic.api.beans.MagicEdition)1 MTGCardsProvider (org.magic.api.interfaces.MTGCardsProvider)1 MTGDao (org.magic.api.interfaces.MTGDao)1 MTGPictureProvider (org.magic.api.interfaces.MTGPictureProvider)1 MTGPicturesCache (org.magic.api.interfaces.MTGPicturesCache)1