Search in sources :

Example 1 with MultiPlotGraphic

use of com.biglybt.ui.swt.components.graphics.MultiPlotGraphic in project BiglyBT by BiglySoftware.

the class DownloadActivityView method fillPanel.

public void fillPanel() {
    Utils.disposeComposite(panel, false);
    GridData gridData;
    ValueFormater formatter = new ValueFormater() {

        @Override
        public String format(int value) {
            return DisplayFormatters.formatByteCountToKiBEtcPerSec(value);
        }
    };
    final ValueSourceImpl[] sources = { new ValueSourceImpl("Up", 0, colors, true, false, false) {

        @Override
        public int getValue() {
            DownloadManager dm = manager;
            if (dm == null) {
                return (0);
            }
            DownloadManagerStats stats = manager.getStats();
            return ((int) (stats.getDataSendRate()));
        }
    }, new ValueSourceImpl("Up Smooth", 1, colors, true, false, true) {

        @Override
        public int getValue() {
            DownloadManager dm = manager;
            if (dm == null) {
                return (0);
            }
            DownloadManagerStats stats = manager.getStats();
            return ((int) (stats.getSmoothedDataSendRate()));
        }
    }, new ValueSourceImpl("Down", 2, colors, false, false, false) {

        @Override
        public int getValue() {
            DownloadManager dm = manager;
            if (dm == null) {
                return (0);
            }
            DownloadManagerStats stats = manager.getStats();
            return ((int) (stats.getDataReceiveRate()));
        }
    }, new ValueSourceImpl("Down Smooth", 3, colors, false, false, true) {

        @Override
        public int getValue() {
            DownloadManager dm = manager;
            if (dm == null) {
                return (0);
            }
            DownloadManagerStats stats = manager.getStats();
            return ((int) (stats.getSmoothedDataReceiveRate()));
        }
    }, new ValueSourceImpl("Swarm Peer Average", 4, colors, false, true, false) {

        @Override
        public int getValue() {
            DownloadManager dm = manager;
            if (dm == null) {
                return (0);
            }
            return ((int) (manager.getStats().getTotalAveragePerPeer()));
        }
    } };
    final MultiPlotGraphic f_mpg = mpg = MultiPlotGraphic.getInstance(sources, formatter);
    String[] color_configs = new String[] { "DownloadActivityView.legend.up", "DownloadActivityView.legend.up_smooth", "DownloadActivityView.legend.down", "DownloadActivityView.legend.down_smooth", "DownloadActivityView.legend.peeraverage" };
    Legend.LegendListener legend_listener = new Legend.LegendListener() {

        private int hover_index = -1;

        @Override
        public void hoverChange(boolean entry, int index) {
            if (hover_index != -1) {
                sources[hover_index].setHover(false);
            }
            if (entry) {
                hover_index = index;
                sources[index].setHover(true);
            }
            f_mpg.refresh(true);
        }

        @Override
        public void visibilityChange(boolean visible, int index) {
            sources[index].setVisible(visible);
            f_mpg.refresh(true);
        }
    };
    if (!legend_at_bottom) {
        gridData = new GridData(GridData.FILL_VERTICAL);
        gridData.verticalAlignment = SWT.CENTER;
        Legend.createLegendComposite(panel, colors, color_configs, null, gridData, false, legend_listener);
    }
    Composite gSpeed = new Composite(panel, SWT.NULL);
    gridData = new GridData(GridData.FILL_BOTH);
    gSpeed.setLayoutData(gridData);
    gSpeed.setLayout(new GridLayout());
    if (legend_at_bottom) {
        gridData = new GridData(GridData.FILL_HORIZONTAL);
        Legend.createLegendComposite(panel, colors, color_configs, null, gridData, true, legend_listener);
    }
    Canvas speedCanvas = new Canvas(gSpeed, SWT.NO_BACKGROUND);
    gridData = new GridData(GridData.FILL_BOTH);
    speedCanvas.setLayoutData(gridData);
    mpg.initialize(speedCanvas, false);
}
Also used : Legend(com.biglybt.ui.swt.components.Legend) MultiPlotGraphic(com.biglybt.ui.swt.components.graphics.MultiPlotGraphic) Composite(org.eclipse.swt.widgets.Composite) Canvas(org.eclipse.swt.widgets.Canvas) ValueFormater(com.biglybt.ui.swt.components.graphics.ValueFormater) DownloadManager(com.biglybt.core.download.DownloadManager) GridLayout(org.eclipse.swt.layout.GridLayout) GridData(org.eclipse.swt.layout.GridData) DownloadManagerStats(com.biglybt.core.download.DownloadManagerStats)

Example 2 with MultiPlotGraphic

use of com.biglybt.ui.swt.components.graphics.MultiPlotGraphic in project BiglyBT by BiglySoftware.

the class TagStatsView method build.

private void build() {
    if (legend_panel == null || legend_panel.isDisposed()) {
        return;
    }
    for (Control c : legend_panel.getChildren()) {
        c.dispose();
    }
    List<String> configs = new ArrayList<>();
    List<String> texts = new ArrayList<>();
    List<Color> colors = new ArrayList<>();
    TagManager tm = TagManagerFactory.getTagManager();
    List<TagType> tag_types = tm.getTagTypes();
    tag_types = TagUIUtils.sortTagTypes(tag_types);
    List<TagFeatureRateLimit> visible_tags = new ArrayList<>();
    for (TagType tag_type : tag_types) {
        if (tag_type.hasTagTypeFeature(TagFeature.TF_RATE_LIMIT)) {
            List<Tag> tags = tag_type.getTags();
            tags = TagUIUtils.sortTags(tags);
            for (Tag tag : tags) {
                if (!tag.isVisible()) {
                    continue;
                }
                TagFeatureRateLimit rl = (TagFeatureRateLimit) tag;
                if (!rl.supportsTagRates()) {
                    continue;
                }
                String config_key = "TagStatsView.cc." + tag_type.getTagType() + "." + tag.getTagID();
                configs.add(config_key);
                texts.add(tag.getTagName(true));
                Color tt_colour;
                int[] rgb = tag.getColor();
                if (rgb == null) {
                    tt_colour = Colors.blues[Colors.BLUES_DARKEST];
                } else {
                    tt_colour = ColorCache.getColor(legend_panel.getDisplay(), rgb);
                }
                colors.add(tt_colour);
                visible_tags.add(rl);
            }
        }
    }
    final Color[] color_array = colors.toArray(new Color[colors.size()]);
    final String[] text_array = texts.toArray(new String[texts.size()]);
    final List<ValueSourceImpl> sources = new ArrayList<>();
    List<int[]> history_records = new ArrayList<>();
    int history_record_max = 0;
    for (int i = 0; i < visible_tags.size(); i++) {
        final TagFeatureRateLimit tag = visible_tags.get(i);
        tag.setRecentHistoryRetention(true);
        int[][] history = tag.getRecentHistory();
        history_record_max = Math.max(history[0].length, history_record_max);
        history_records.add(history[0]);
        history_records.add(history[1]);
        sources.add(new ValueSourceImpl(tag, text_array[i], i, color_array, true));
        sources.add(new ValueSourceImpl(tag, text_array[i], i, color_array, false));
    }
    ValueFormater formatter = new ValueFormater() {

        @Override
        public String format(int value) {
            return DisplayFormatters.formatByteCountToKiBEtcPerSec(value);
        }
    };
    if (mpg != null) {
        mpg.dispose();
    }
    final MultiPlotGraphic f_mpg = mpg = MultiPlotGraphic.getInstance(sources.toArray(new ValueSource[sources.size()]), formatter);
    int[][] history = new int[history_records.size()][];
    for (int i = 0; i < history.length; i++) {
        int[] hist = history_records.get(i);
        int hist_len = hist.length;
        if (hist_len == history_record_max) {
            history[i] = hist;
        } else {
            int[] temp = new int[history_record_max];
            System.arraycopy(hist, 0, temp, history_record_max - hist_len, hist_len);
            history[i] = temp;
        }
    }
    mpg.reset(history);
    GridData gridData;
    if (color_array.length > 0) {
        gridData = new GridData(GridData.FILL_VERTICAL);
        gridData.verticalAlignment = SWT.CENTER;
        Legend.createLegendComposite(legend_panel, color_array, configs.toArray(new String[configs.size()]), text_array, gridData, false, new Legend.LegendListener() {

            private int hover_index = -1;

            @Override
            public void hoverChange(boolean entry, int index) {
                if (hover_index != -1) {
                    for (int i = hover_index * 2; i < hover_index * 2 + 2; i++) {
                        sources.get(i).setHover(false);
                    }
                }
                if (entry) {
                    hover_index = index;
                    for (int i = hover_index * 2; i < hover_index * 2 + 2; i++) {
                        sources.get(i).setHover(true);
                    }
                }
                f_mpg.refresh(true);
            }

            @Override
            public void visibilityChange(boolean visible, int index) {
                for (int i = index * 2; i < index * 2 + 2; i++) {
                    sources.get(i).setVisible(visible);
                }
                f_mpg.refresh(true);
            }
        });
    } else {
        gridData = new GridData(GridData.FILL_HORIZONTAL);
        gridData.verticalAlignment = SWT.TOP;
        Label lab = new Label(legend_panel, SWT.NULL);
        lab.setText(MessageText.getString("tag.stats.none.defined"));
        lab.setLayoutData(gridData);
    }
    legend_panel_sc.setMinSize(legend_panel.computeSize(SWT.DEFAULT, SWT.DEFAULT));
    for (Control c : speed_panel.getChildren()) {
        c.dispose();
    }
    Canvas speed_canvas = new Canvas(speed_panel, SWT.NO_BACKGROUND);
    gridData = new GridData(GridData.FILL_BOTH);
    speed_canvas.setLayoutData(gridData);
    mpg.initialize(speed_canvas, true);
    panel.layout(true, true);
}
Also used : Legend(com.biglybt.ui.swt.components.Legend) Label(org.eclipse.swt.widgets.Label) Control(org.eclipse.swt.widgets.Control) MultiPlotGraphic(com.biglybt.ui.swt.components.graphics.MultiPlotGraphic) Color(org.eclipse.swt.graphics.Color) Canvas(org.eclipse.swt.widgets.Canvas) ValueFormater(com.biglybt.ui.swt.components.graphics.ValueFormater) GridData(org.eclipse.swt.layout.GridData)

Aggregations

Legend (com.biglybt.ui.swt.components.Legend)2 MultiPlotGraphic (com.biglybt.ui.swt.components.graphics.MultiPlotGraphic)2 ValueFormater (com.biglybt.ui.swt.components.graphics.ValueFormater)2 GridData (org.eclipse.swt.layout.GridData)2 Canvas (org.eclipse.swt.widgets.Canvas)2 DownloadManager (com.biglybt.core.download.DownloadManager)1 DownloadManagerStats (com.biglybt.core.download.DownloadManagerStats)1 Color (org.eclipse.swt.graphics.Color)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 Composite (org.eclipse.swt.widgets.Composite)1 Control (org.eclipse.swt.widgets.Control)1 Label (org.eclipse.swt.widgets.Label)1