use of org.eclipse.swt.widgets.Canvas in project BiglyBT by BiglySoftware.
the class PeersGraphicView method initialize.
protected void initialize(Composite composite) {
display = composite.getDisplay();
panel = new Canvas(composite, SWT.NO_BACKGROUND);
panel.addListener(SWT.MouseHover, new Listener() {
@Override
public void handleEvent(Event event) {
int x = event.x;
int y = event.y;
String tt = "";
synchronized (dm_data_lock) {
for (ManagerData data : dm_data) {
DownloadManager manager = data.manager;
if (x >= data.me_hit_x && x <= data.me_hit_x + OWN_SIZE && y >= data.me_hit_y && y <= data.me_hit_y + OWN_SIZE) {
if (dm_data.length > 1) {
tt = manager.getDisplayName() + "\r\n";
}
tt += DisplayFormatters.formatDownloadStatus(manager) + ", " + DisplayFormatters.formatPercentFromThousands(manager.getStats().getCompleted());
break;
} else {
PEPeer target = null;
for (Map.Entry<PEPeer, int[]> entry : data.peer_hit_map.entrySet()) {
int[] loc = entry.getValue();
int loc_x = loc[0];
int loc_y = loc[1];
if (x >= loc_x && x <= loc_x + PEER_SIZE && y >= loc_y && y <= loc_y + PEER_SIZE) {
target = entry.getKey();
break;
}
}
if (target != null) {
PEPeerStats stats = target.getStats();
String[] details = PeerUtils.getCountryDetails(target);
String dstr = (details == null || details.length < 2) ? "" : (" - " + details[0] + "/" + details[1]);
/*
if ( dm_map.size() > 1 ){
tt = manager.getDisplayName() + "\r\n";
}
*/
tt = target.getIp() + dstr + ", " + DisplayFormatters.formatPercentFromThousands(target.getPercentDoneInThousandNotation()) + "\r\n" + "Up=" + DisplayFormatters.formatByteCountToKiBEtcPerSec(stats.getDataSendRate() + stats.getProtocolSendRate()) + ", " + "Down=" + DisplayFormatters.formatByteCountToKiBEtcPerSec(stats.getDataReceiveRate() + stats.getProtocolReceiveRate());
break;
}
}
}
}
panel.setToolTipText(tt);
}
});
panel.addMouseListener(new MouseAdapter() {
@Override
public void mouseUp(MouseEvent event) {
if (event.button == 3) {
int x = event.x;
int y = event.y;
PEPeer target = null;
DownloadManager target_manager = null;
synchronized (dm_data_lock) {
for (ManagerData data : dm_data) {
DownloadManager manager = data.manager;
for (Map.Entry<PEPeer, int[]> entry : data.peer_hit_map.entrySet()) {
int[] loc = entry.getValue();
int loc_x = loc[0];
int loc_y = loc[1];
if (x >= loc_x && x <= loc_x + PEER_SIZE && y >= loc_y && y <= loc_y + PEER_SIZE) {
target = entry.getKey();
target_manager = manager;
break;
}
}
if (target != null) {
break;
}
}
}
if (target == null) {
return;
}
Menu menu = panel.getMenu();
if (menu != null && !menu.isDisposed()) {
menu.dispose();
}
menu = new Menu(panel);
PeersViewBase.fillMenu(menu, target, target_manager);
final Point cursorLocation = Display.getCurrent().getCursorLocation();
menu.setLocation(cursorLocation.x, cursorLocation.y);
menu.setVisible(true);
}
}
@Override
public void mouseDoubleClick(MouseEvent event) {
int x = event.x;
int y = event.y;
synchronized (dm_data_lock) {
for (ManagerData data : dm_data) {
DownloadManager manager = data.manager;
if (x >= data.me_hit_x && x <= data.me_hit_x + OWN_SIZE && y >= data.me_hit_y && y <= data.me_hit_y + OWN_SIZE) {
UIFunctions uiFunctions = UIFunctionsManager.getUIFunctions();
if (uiFunctions != null) {
uiFunctions.getMDI().showEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_TORRENT_DETAILS, manager);
}
} else {
for (Map.Entry<PEPeer, int[]> entry : data.peer_hit_map.entrySet()) {
int[] loc = entry.getValue();
int loc_x = loc[0];
int loc_y = loc[1];
if (x >= loc_x && x <= loc_x + PEER_SIZE && y >= loc_y && y <= loc_y + PEER_SIZE) {
PEPeer target = entry.getKey();
try {
String dm_id = "DMDetails_" + Base32.encode(manager.getTorrent().getHash());
MdiEntry mdi_entry = UIFunctionsManager.getUIFunctions().getMDI().getEntry(dm_id);
if (mdi_entry != null) {
mdi_entry.setDatasource(new Object[] { manager, target });
}
Composite comp = panel.getParent();
while (comp != null) {
if (comp instanceof CTabFolder) {
CTabFolder tf = (CTabFolder) comp;
CTabItem[] items = tf.getItems();
for (CTabItem item : items) {
UISWTViewCore view = (UISWTViewCore) item.getData("TabbedEntry");
UISWTViewEventListener listener = view.getEventListener();
if (listener instanceof UISWTViewEventListenerHolder) {
listener = ((UISWTViewEventListenerHolder) listener).getDelegatedEventListener(view);
}
if (listener instanceof PeersView) {
tf.setSelection(item);
Event ev = new Event();
ev.item = item;
// manual setSelection doesn't file selection event - derp
tf.notifyListeners(SWT.Selection, ev);
((PeersView) listener).selectPeer(target);
return;
}
}
}
comp = comp.getParent();
}
} catch (Throwable e) {
}
break;
}
}
}
}
}
}
});
// without this we get a transient blank when mousing in and out of the tab folder on OSX :(
panel.addPaintListener(new PaintListener() {
@Override
public void paintControl(PaintEvent e) {
doRefresh();
}
});
}
use of org.eclipse.swt.widgets.Canvas in project BiglyBT by BiglySoftware.
the class ViewUpSpeedGraph method initialize.
private void initialize(Composite composite) {
GridData gridData;
composite.setLayout(new GridLayout());
upSpeedCanvas = new Canvas(composite, SWT.DOUBLE_BUFFERED);
gridData = new GridData(GridData.FILL_BOTH);
upSpeedCanvas.setLayoutData(gridData);
upSpeedGraphic = SpeedGraphic.getInstance();
upSpeedGraphic.initialize(upSpeedCanvas);
// upSpeedGraphic.setAutoAlpha(true);
}
use of org.eclipse.swt.widgets.Canvas in project BiglyBT by BiglySoftware.
the class Legend method createLegendComposite.
public static Composite createLegendComposite(final Composite panel, final Color[] blockColors, final String[] keys, final String[] key_texts, Object layoutData, boolean horizontal, final LegendListener listener) {
final ConfigurationManager config = ConfigurationManager.getInstance();
if (blockColors.length != keys.length)
return null;
final Color[] defaultColors = new Color[blockColors.length];
final ParameterListener[] paramListeners = new ParameterListener[keys.length];
System.arraycopy(blockColors, 0, defaultColors, 0, blockColors.length);
Composite legend = new Composite(panel, SWT.NONE);
if (layoutData != null)
legend.setLayoutData(layoutData);
RowLayout layout = new RowLayout(horizontal ? SWT.HORIZONTAL : SWT.VERTICAL);
layout.wrap = true;
layout.marginBottom = 0;
layout.marginTop = 0;
layout.marginLeft = 0;
layout.marginRight = 0;
layout.spacing = 0;
legend.setLayout(layout);
RowData data;
final int[] hover_state = { -1, 0 };
for (int i = 0; i < blockColors.length; i++) {
int r = config.getIntParameter(keys[i] + ".red", -1);
if (r >= 0) {
int g = config.getIntParameter(keys[i] + ".green");
int b = config.getIntParameter(keys[i] + ".blue");
Color color = ColorCache.getColor(panel.getDisplay(), r, g, b);
blockColors[i] = color;
}
Composite colorSet = new Composite(legend, SWT.NONE);
Utils.setLayout(colorSet, new RowLayout(SWT.HORIZONTAL));
final Canvas cColor = new Canvas(colorSet, SWT.BORDER);
cColor.setData("Index", new Integer(i));
Messages.setLanguageTooltip(cColor, "label.click.to.change.tooltip");
// XXX Use paint instead of setBackgrond, because OSX does translucent
// crap
cColor.addPaintListener(new PaintListener() {
@Override
public void paintControl(PaintEvent e) {
int i = ((Integer) cColor.getData("Index")).intValue();
e.gc.setBackground(blockColors[i]);
e.gc.fillRectangle(e.x, e.y, e.width, e.height);
}
});
cColor.addMouseListener(new MouseAdapter() {
@Override
public void mouseUp(MouseEvent e) {
Integer iIndex = (Integer) cColor.getData("Index");
if (iIndex == null)
return;
int index = iIndex.intValue();
if (e.button == 1) {
RGB rgb = Utils.showColorDialog(panel, blockColors[index].getRGB());
if (rgb != null) {
config.setRGBParameter(keys[index], rgb.red, rgb.green, rgb.blue);
}
} else {
config.removeRGBParameter(keys[index]);
}
}
});
final Label lblDesc = new Label(colorSet, SWT.NULL);
if (key_texts == null) {
Messages.setLanguageText(lblDesc, keys[i]);
} else {
lblDesc.setText(key_texts[i]);
}
if (listener != null) {
Messages.setLanguageTooltip(lblDesc, "label.click.to.showhide.tooltip");
final int f_i = i;
lblDesc.addMouseListener(new MouseAdapter() {
@Override
public void mouseUp(MouseEvent e) {
boolean vis = !config.getBooleanParameter(keys[f_i] + ".vis", true);
config.setParameter(keys[f_i] + ".vis", vis);
listener.visibilityChange(vis, f_i);
lblDesc.setForeground(vis ? Colors.getSystemColor(lblDesc.getDisplay(), SWT.COLOR_BLACK) : Colors.grey);
}
});
boolean vis = config.getBooleanParameter(keys[f_i] + ".vis", true);
if (!vis) {
listener.visibilityChange(vis, i);
lblDesc.setForeground(Colors.grey);
}
}
data = new RowData();
data.width = 20;
data.height = lblDesc.computeSize(SWT.DEFAULT, SWT.DEFAULT).y - 3;
cColor.setLayoutData(data);
// If color changes, update our legend
config.addParameterListener(keys[i], paramListeners[i] = new ParameterListener() {
@Override
public void parameterChanged(String parameterName) {
for (int j = 0; j < keys.length; j++) {
if (keys[j].equals(parameterName)) {
final int index = j;
final int r = config.getIntParameter(keys[j] + ".red", -1);
if (r >= 0) {
final int g = config.getIntParameter(keys[j] + ".green");
final int b = config.getIntParameter(keys[j] + ".blue");
Utils.execSWTThread(new AERunnable() {
@Override
public void runSupport() {
if (panel == null || panel.isDisposed())
return;
Color color = ColorCache.getColor(panel.getDisplay(), r, g, b);
blockColors[index] = color;
cColor.redraw();
}
});
} else {
Utils.execSWTThread(new AERunnable() {
@Override
public void runSupport() {
if (panel == null || panel.isDisposed())
return;
blockColors[index] = defaultColors[index];
cColor.redraw();
}
});
}
}
}
}
});
if (listener != null) {
final int f_i = i;
Control[] controls = { colorSet, cColor, lblDesc };
MouseTrackListener ml = new MouseTrackListener() {
@Override
public void mouseEnter(MouseEvent e) {
handleHover(listener, true, f_i, hover_state);
}
@Override
public void mouseExit(MouseEvent e) {
handleHover(listener, false, f_i, hover_state);
}
@Override
public void mouseHover(MouseEvent e) {
}
};
for (Control c : controls) {
c.addMouseTrackListener(ml);
}
}
}
legend.addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent e) {
// We don't want to give them disposed colors
// Restore defaults in case blockColors is a static or is used
// afterwards, or if the view wants to dispose of the old colors.
System.arraycopy(defaultColors, 0, blockColors, 0, blockColors.length);
for (int i = 0; i < keys.length; i++) config.removeParameterListener(keys[i], paramListeners[i]);
}
});
return legend;
}
use of org.eclipse.swt.widgets.Canvas in project BiglyBT by BiglySoftware.
the class ActivityView method initialize.
private void initialize(Composite composite) {
panel = new Composite(composite, SWT.NULL);
panel.setLayout(new GridLayout());
GridData gridData;
Group gDownSpeed = new Group(panel, SWT.NULL);
Messages.setLanguageText(gDownSpeed, "SpeedView.downloadSpeed.title");
gridData = new GridData(GridData.FILL_BOTH);
gDownSpeed.setLayoutData(gridData);
gDownSpeed.setLayout(new GridLayout());
downSpeedCanvas = new Canvas(gDownSpeed, SWT.NO_BACKGROUND);
gridData = new GridData(GridData.FILL_BOTH);
downSpeedCanvas.setLayoutData(gridData);
downSpeedGraphic.initialize(downSpeedCanvas);
Color[] colors = downSpeedGraphic.colors;
Group gUpSpeed = new Group(panel, SWT.NULL);
Messages.setLanguageText(gUpSpeed, "SpeedView.uploadSpeed.title");
gridData = new GridData(GridData.FILL_BOTH);
gUpSpeed.setLayoutData(gridData);
gUpSpeed.setLayout(new GridLayout());
upSpeedCanvas = new Canvas(gUpSpeed, SWT.NO_BACKGROUND);
gridData = new GridData(GridData.FILL_BOTH);
upSpeedCanvas.setLayoutData(gridData);
upSpeedGraphic.initialize(upSpeedCanvas);
COConfigurationManager.addAndFireParameterListener("Stats Graph Dividers", this);
upSpeedGraphic.setLineColors(colors);
String[] colorConfigs = new String[] { "ActivityView.legend.peeraverage", "ActivityView.legend.achieved", "ActivityView.legend.overhead", "ActivityView.legend.limit", "ActivityView.legend.swarmaverage", "ActivityView.legend.trimmed" };
Legend.createLegendComposite(panel, colors, colorConfigs);
panel.addListener(SWT.Activate, new Listener() {
@Override
public void handleEvent(Event event) {
refresh(true);
}
});
}
use of org.eclipse.swt.widgets.Canvas 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);
}
Aggregations