use of com.biglybt.ui.swt.components.graphics.ValueFormater 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);
}
use of com.biglybt.ui.swt.components.graphics.ValueFormater 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);
}
use of com.biglybt.ui.swt.components.graphics.ValueFormater in project BiglyBT by BiglySoftware.
the class TransferStatsView method createConnectionPanel.
private void createConnectionPanel() {
connectionPanel = new Composite(mainPanel, SWT.NONE);
GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
Utils.setLayoutData(connectionPanel, gridData);
GridLayout panelLayout = new GridLayout();
panelLayout.numColumns = 2;
panelLayout.makeColumnsEqualWidth = true;
connectionPanel.setLayout(panelLayout);
Composite conn_area = new Composite(connectionPanel, SWT.NULL);
gridData = new GridData(GridData.FILL_HORIZONTAL);
Utils.setLayoutData(conn_area, gridData);
panelLayout = new GridLayout();
panelLayout.numColumns = 2;
conn_area.setLayout(panelLayout);
Label label = new Label(conn_area, SWT.NULL);
Messages.setLanguageText(label, "SpeedView.stats.con");
connection_label = new BufferedLabel(conn_area, SWT.DOUBLE_BUFFERED);
gridData = new GridData(GridData.FILL_HORIZONTAL);
Utils.setLayoutData(connection_label, gridData);
Composite upload_area = new Composite(connectionPanel, SWT.NULL);
gridData = new GridData(GridData.FILL_HORIZONTAL);
Utils.setLayoutData(upload_area, gridData);
panelLayout = new GridLayout();
panelLayout.numColumns = 2;
upload_area.setLayout(panelLayout);
label = new Label(upload_area, SWT.NULL);
Messages.setLanguageText(label, "SpeedView.stats.upload");
upload_label = new BufferedLabel(upload_area, SWT.DOUBLE_BUFFERED);
gridData = new GridData(GridData.FILL_HORIZONTAL);
Utils.setLayoutData(upload_label, gridData);
// connections
con_folder = new TabFolder(connectionPanel, SWT.LEFT);
gridData = new GridData(GridData.FILL_BOTH);
gridData.horizontalSpan = 1;
Utils.setLayoutData(con_folder, gridData);
con_folder.setBackground(Colors.background);
// connection counts
TabItem conn_item = new TabItem(con_folder, SWT.NULL);
conn_item.setText(MessageText.getString("label.connections"));
Canvas connection_canvas = new Canvas(con_folder, SWT.NO_BACKGROUND);
conn_item.setControl(connection_canvas);
gridData = new GridData(GridData.FILL_BOTH);
gridData.heightHint = 200;
Utils.setLayoutData(connection_canvas, gridData);
connection_graphic = SpeedGraphic.getInstance(new Scale(false), new ValueFormater() {
@Override
public String format(int value) {
return (String.valueOf(value));
}
});
connection_graphic.initialize(connection_canvas);
Color[] colors = connection_graphic.colors;
connection_graphic.setLineColors(colors);
// route info
TabItem route_info_tab = new TabItem(con_folder, SWT.NULL);
route_info_tab.setText(MessageText.getString("label.routing"));
Composite route_tab_comp = new Composite(con_folder, SWT.NULL);
Utils.setLayoutData(route_tab_comp, new GridData(SWT.FILL, SWT.FILL, true, true));
GridLayout routeTabLayout = new GridLayout();
routeTabLayout.numColumns = 1;
route_tab_comp.setLayout(routeTabLayout);
route_info_tab.setControl(route_tab_comp);
ScrolledComposite sc = new ScrolledComposite(route_tab_comp, SWT.V_SCROLL);
Utils.setLayoutData(sc, new GridData(SWT.FILL, SWT.FILL, true, true));
route_comp = new Composite(sc, SWT.NULL);
Utils.setLayoutData(route_comp, new GridData(SWT.FILL, SWT.FILL, true, true));
GridLayout routeLayout = new GridLayout();
routeLayout.numColumns = 3;
// routeLayout.makeColumnsEqualWidth = true;
route_comp.setLayout(routeLayout);
sc.setContent(route_comp);
buildRouteComponent(5);
// upload queued
Canvas upload_canvas = new Canvas(connectionPanel, SWT.NO_BACKGROUND);
gridData = new GridData(GridData.FILL_BOTH);
gridData.heightHint = 200;
Utils.setLayoutData(upload_canvas, gridData);
upload_graphic = SpeedGraphic.getInstance(new ValueFormater() {
@Override
public String format(int value) {
return DisplayFormatters.formatByteCountToKiBEtc(value);
}
});
upload_graphic.initialize(upload_canvas);
}
use of com.biglybt.ui.swt.components.graphics.ValueFormater in project BiglyBT by BiglySoftware.
the class TransferStatsView method createAutoSpeedPanel.
private void createAutoSpeedPanel() {
autoSpeedPanel = new Group(mainPanel, SWT.NONE);
GridData generalPanelData = new GridData(GridData.FILL_BOTH);
Utils.setLayoutData(autoSpeedPanel, generalPanelData);
Messages.setLanguageText(autoSpeedPanel, "SpeedView.stats.autospeed", new String[] { String.valueOf(MAX_DISPLAYED_PING_MILLIS_DISP) });
autoSpeedPanelLayout = new StackLayout();
autoSpeedPanel.setLayout(autoSpeedPanelLayout);
autoSpeedInfoPanel = new Composite(autoSpeedPanel, SWT.NULL);
Utils.setLayoutData(autoSpeedInfoPanel, new GridData(GridData.FILL_BOTH));
GridLayout layout = new GridLayout();
layout.numColumns = 8;
layout.makeColumnsEqualWidth = true;
autoSpeedInfoPanel.setLayout(layout);
Canvas pingCanvas = new Canvas(autoSpeedInfoPanel, SWT.NO_BACKGROUND);
GridData gridData = new GridData(GridData.FILL_BOTH);
gridData.horizontalSpan = 4;
Utils.setLayoutData(pingCanvas, gridData);
pingGraph.initialize(pingCanvas);
TabFolder folder = new TabFolder(autoSpeedInfoPanel, SWT.LEFT);
gridData = new GridData(GridData.FILL_BOTH);
gridData.horizontalSpan = 4;
Utils.setLayoutData(folder, gridData);
folder.setBackground(Colors.background);
ValueFormater speed_formatter = new ValueFormater() {
@Override
public String format(int value) {
return (DisplayFormatters.formatByteCountToKiBEtc(value));
}
};
ValueFormater time_formatter = new ValueFormater() {
@Override
public String format(int value) {
return (value + " ms");
}
};
ValueFormater[] formatters = new ValueFormater[] { speed_formatter, speed_formatter, time_formatter };
String[] labels = new String[] { "up", "down", "ping" };
SpeedManagerPingMapper[] mappers = speedManager.getMappers();
plot_views = new plotView[mappers.length];
zone_views = new zoneView[mappers.length];
for (int i = 0; i < mappers.length; i++) {
SpeedManagerPingMapper mapper = mappers[i];
TabItem plot_item = new TabItem(folder, SWT.NULL);
plot_item.setText("Plot " + mapper.getName());
Canvas plotCanvas = new Canvas(folder, SWT.NO_BACKGROUND);
gridData = new GridData(GridData.FILL_BOTH);
Utils.setLayoutData(plotCanvas, gridData);
plot_views[i] = new plotView(mapper, plotCanvas, labels, formatters);
plot_item.setControl(plotCanvas);
TabItem zones_item = new TabItem(folder, SWT.NULL);
zones_item.setText("Zones " + mapper.getName());
Canvas zoneCanvas = new Canvas(folder, SWT.NO_BACKGROUND);
gridData = new GridData(GridData.FILL_BOTH);
Utils.setLayoutData(zoneCanvas, gridData);
zone_views[i] = new zoneView(mapper, zoneCanvas, labels, formatters);
zones_item.setControl(zoneCanvas);
}
autoSpeedDisabledPanel = new Composite(autoSpeedPanel, SWT.NULL);
autoSpeedDisabledPanel.setLayout(new GridLayout());
Label disabled = new Label(autoSpeedDisabledPanel, SWT.NULL);
disabled.setEnabled(false);
Messages.setLanguageText(disabled, "SpeedView.stats.autospeed.disabled");
Utils.setLayoutData(disabled, new GridData(GridData.HORIZONTAL_ALIGN_CENTER | GridData.FILL_HORIZONTAL));
autoSpeedPanelLayout.topControl = speedManager.isAvailable() ? autoSpeedInfoPanel : autoSpeedDisabledPanel;
gridData = new GridData(GridData.FILL_HORIZONTAL);
gridData.horizontalSpan = 8;
Legend.createLegendComposite(autoSpeedInfoPanel, PingGraphic.defaultColors, new String[] { "TransferStatsView.legend.pingaverage", "TransferStatsView.legend.ping1", "TransferStatsView.legend.ping2", "TransferStatsView.legend.ping3" }, gridData);
}
Aggregations