use of com.biglybt.ui.UIFunctions in project BiglyBT by BiglySoftware.
the class PeersViewBase method fillMenu.
private static void fillMenu(final Menu menu, final PEPeer[] peers, final Shell shell, DownloadManager download_specific) {
boolean hasSelection = (peers.length > 0);
boolean downSpeedDisabled = false;
boolean downSpeedUnlimited = false;
long totalDownSpeed = 0;
long downSpeedSetMax = 0;
long maxDown = 0;
boolean upSpeedDisabled = false;
boolean upSpeedUnlimited = false;
long totalUpSpeed = 0;
long upSpeedSetMax = 0;
long maxUp = 0;
GlobalManager gm = CoreFactory.getSingleton().getGlobalManager();
final IdentityHashSet<DownloadManager> download_managers = new IdentityHashSet<>();
Map<PEPeer, DownloadManager> peer_dm_map = new HashMap<>();
if (hasSelection) {
for (int i = 0; i < peers.length; i++) {
PEPeer peer = peers[i];
PEPeerManager m = peer.getManager();
if (m != null) {
if (gm != null) {
DownloadManager dm = gm.getDownloadManager(new HashWrapper(m.getHash()));
if (dm != null) {
peer_dm_map.put(peer, dm);
download_managers.add(dm);
}
}
}
try {
int maxul = peer.getStats().getUploadRateLimitBytesPerSecond();
maxUp += maxul * 4;
if (maxul == 0) {
upSpeedUnlimited = true;
} else {
if (maxul > upSpeedSetMax) {
upSpeedSetMax = maxul;
}
}
if (maxul == -1) {
maxul = 0;
upSpeedDisabled = true;
}
totalUpSpeed += maxul;
int maxdl = peer.getStats().getDownloadRateLimitBytesPerSecond();
maxDown += maxdl * 4;
if (maxdl == 0) {
downSpeedUnlimited = true;
} else {
if (maxdl > downSpeedSetMax) {
downSpeedSetMax = maxdl;
}
}
if (maxdl == -1) {
maxdl = 0;
downSpeedDisabled = true;
}
totalDownSpeed += maxdl;
} catch (Exception ex) {
Debug.printStackTrace(ex);
}
}
}
if (download_specific != null) {
final MenuItem block_item = new MenuItem(menu, SWT.CHECK);
PEPeer peer = peers.length == 0 ? null : peers[0];
if (peer == null || peer.getManager().getDiskManager().getRemainingExcludingDND() > 0) {
// disallow peer upload blocking when downloading
block_item.setSelection(false);
block_item.setEnabled(false);
} else {
block_item.setEnabled(true);
block_item.setSelection(peer.isSnubbed());
}
if (peer != null) {
final boolean newSnubbedValue = !peer.isSnubbed();
Messages.setLanguageText(block_item, "PeersView.menu.blockupload");
block_item.addListener(SWT.Selection, new PeersRunner(peers) {
@Override
public void run(PEPeer peer) {
peer.setSnubbed(newSnubbedValue);
}
});
}
} else {
if (download_managers.size() > 0) {
MenuItem itemDetails = new MenuItem(menu, SWT.PUSH);
Messages.setLanguageText(itemDetails, "PeersView.menu.showdownload");
Utils.setMenuItemImage(itemDetails, "details");
itemDetails.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
UIFunctions uiFunctions = UIFunctionsManager.getUIFunctions();
if (uiFunctions != null) {
for (DownloadManager dm : download_managers) {
uiFunctions.getMDI().showEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_TORRENT_DETAILS, dm);
}
}
}
});
new MenuItem(menu, SWT.SEPARATOR);
}
}
BuddyPlugin bp = BuddyPluginUtils.getPlugin();
if (bp != null) {
boolean has_pb = false;
boolean has_public = false;
for (PEPeer peer : peers) {
if (AENetworkClassifier.categoriseAddress(peer.getIp()) == AENetworkClassifier.AT_PUBLIC) {
has_public = true;
DownloadManager dm = peer_dm_map.get(peer);
if (dm != null && bp.isPartialBuddy(PluginCoreUtils.wrap(dm), PluginCoreUtils.wrap(peer))) {
has_pb = true;
}
}
}
MenuItem boost_item = new MenuItem(menu, SWT.CHECK);
Messages.setLanguageText(boost_item, "PeersView.menu.boost");
boost_item.setSelection(has_pb);
boost_item.setEnabled(has_public);
boost_item.addListener(SWT.Selection, new PeersRunner(peers) {
@Override
public void run(PEPeer peer) {
boolean sel = boost_item.getSelection();
if (AENetworkClassifier.categoriseAddress(peer.getIp()) == AENetworkClassifier.AT_PUBLIC) {
DownloadManager dm = peer_dm_map.get(peer);
if (dm != null) {
bp.setPartialBuddy(PluginCoreUtils.wrap(dm), PluginCoreUtils.wrap(peer), sel);
}
}
}
});
}
final MenuItem kick_item = new MenuItem(menu, SWT.PUSH);
Messages.setLanguageText(kick_item, "PeersView.menu.kick");
kick_item.addListener(SWT.Selection, new PeersRunner(peers) {
@Override
public void run(PEPeer peer) {
peer.getManager().removePeer(peer, "Peer kicked");
}
});
final MenuItem ban_item = new MenuItem(menu, SWT.PUSH);
Messages.setLanguageText(ban_item, "PeersView.menu.kickandban");
ban_item.addListener(SWT.Selection, new PeersRunner(peers) {
@Override
public void run(PEPeer peer) {
String msg = MessageText.getString("PeersView.menu.kickandban.reason");
IpFilterManagerFactory.getSingleton().getIPFilter().ban(peer.getIp(), msg, true);
peer.getManager().removePeer(peer, "Peer kicked and banned");
}
});
final MenuItem ban_for_item = new MenuItem(menu, SWT.PUSH);
Messages.setLanguageText(ban_for_item, "PeersView.menu.kickandbanfor");
ban_for_item.addListener(SWT.Selection, new PeersRunner(peers) {
@Override
public boolean run(final PEPeer[] peers) {
String text = MessageText.getString("dialog.ban.for.period.text");
SimpleTextEntryWindow entryWindow = new SimpleTextEntryWindow("dialog.ban.for.period.title", "!" + text + "!");
int def = COConfigurationManager.getIntParameter("ban.for.period.default", 60);
entryWindow.setPreenteredText(String.valueOf(def), false);
entryWindow.prompt(new UIInputReceiverListener() {
@Override
public void UIInputReceiverClosed(UIInputReceiver entryWindow) {
if (!entryWindow.hasSubmittedInput()) {
return;
}
String sReturn = entryWindow.getSubmittedInput();
if (sReturn == null) {
return;
}
int mins = -1;
try {
mins = Integer.valueOf(sReturn).intValue();
} catch (NumberFormatException er) {
// Ignore
}
if (mins <= 0) {
MessageBox mb = new MessageBox(Utils.findAnyShell(), SWT.ICON_ERROR | SWT.OK);
mb.setText(MessageText.getString("MyTorrentsView.dialog.NumberError.title"));
mb.setMessage(MessageText.getString("MyTorrentsView.dialog.NumberError.text"));
mb.open();
return;
}
COConfigurationManager.setParameter("ban.for.period.default", mins);
IpFilter filter = IpFilterManagerFactory.getSingleton().getIPFilter();
for (PEPeer peer : peers) {
String msg = MessageText.getString("PeersView.menu.kickandbanfor.reason", new String[] { String.valueOf(mins) });
filter.ban(peer.getIp(), msg, true, mins);
peer.getManager().removePeer(peer, "Peer kicked and banned");
}
}
});
return (true);
}
});
// === advanced menu ===
final MenuItem itemAdvanced = new MenuItem(menu, SWT.CASCADE);
Messages.setLanguageText(itemAdvanced, "MyTorrentsView.menu.advancedmenu");
itemAdvanced.setEnabled(hasSelection);
final Menu menuAdvanced = new Menu(shell, SWT.DROP_DOWN);
itemAdvanced.setMenu(menuAdvanced);
// advanced > Download Speed Menu //
Map<String, Object> menu_properties = new HashMap<>();
menu_properties.put(ViewUtils.SM_PROP_PERMIT_UPLOAD_DISABLE, true);
menu_properties.put(ViewUtils.SM_PROP_PERMIT_DOWNLOAD_DISABLE, true);
ViewUtils.addSpeedMenu(shell, menuAdvanced, true, true, false, hasSelection, downSpeedDisabled, downSpeedUnlimited, totalDownSpeed, downSpeedSetMax, maxDown, upSpeedDisabled, upSpeedUnlimited, totalUpSpeed, upSpeedSetMax, maxUp, peers.length, menu_properties, new ViewUtils.SpeedAdapter() {
@Override
public void setDownSpeed(int speed) {
if (peers.length > 0) {
for (int i = 0; i < peers.length; i++) {
try {
PEPeer peer = (PEPeer) peers[i];
peer.getStats().setDownloadRateLimitBytesPerSecond(speed);
} catch (Exception e) {
Debug.printStackTrace(e);
}
}
}
}
@Override
public void setUpSpeed(int speed) {
if (peers.length > 0) {
for (int i = 0; i < peers.length; i++) {
try {
PEPeer peer = (PEPeer) peers[i];
peer.getStats().setUploadRateLimitBytesPerSecond(speed);
} catch (Exception e) {
Debug.printStackTrace(e);
}
}
}
}
});
addPeersMenu(download_specific, "", menu);
}
use of com.biglybt.ui.UIFunctions in project BiglyBT by BiglySoftware.
the class PrivacyView method initialize.
private void initialize() {
if (cMainComposite == null || cMainComposite.isDisposed()) {
if (parent == null || parent.isDisposed()) {
return;
}
sc = new ScrolledComposite(parent, SWT.V_SCROLL);
sc.setExpandHorizontal(true);
sc.setExpandVertical(true);
sc.getVerticalBar().setIncrement(16);
Layout parentLayout = parent.getLayout();
if (parentLayout instanceof GridLayout) {
GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
Utils.setLayoutData(sc, gd);
} else if (parentLayout instanceof FormLayout) {
Utils.setLayoutData(sc, Utils.getFilledFormData());
}
cMainComposite = new Composite(sc, SWT.NONE);
sc.setContent(cMainComposite);
} else {
Utils.disposeComposite(cMainComposite, false);
}
GridLayout layout = new GridLayout(1, false);
layout.horizontalSpacing = 0;
layout.verticalSpacing = 0;
layout.marginHeight = 0;
layout.marginWidth = 0;
cMainComposite.setLayout(layout);
GridData gd;
// overview
Composite overview_comp = new Composite(cMainComposite, SWT.NULL);
overview_comp.setLayout(new GridLayout(3, false));
gd = new GridData(GridData.FILL_HORIZONTAL);
Utils.setLayoutData(overview_comp, gd);
Label label = new Label(overview_comp, SWT.NULL);
label.setText(MessageText.getString("privacy.view.intro"));
LinkLabel link = new LinkLabel(overview_comp, "label.read.more", MessageText.getString("privacy.view.wiki.url"));
// slider component
Composite slider_comp = new Composite(cMainComposite, SWT.NULL);
layout = new GridLayout(3, false);
layout.horizontalSpacing = 0;
layout.verticalSpacing = 0;
layout.marginHeight = 0;
// layout.marginWidth = 0;
slider_comp.setLayout(layout);
gd = new GridData(GridData.FILL_HORIZONTAL);
Utils.setLayoutData(slider_comp, gd);
label = new Label(slider_comp, SWT.NULL);
label.setText(MessageText.getString("privacy.view.level") + ":");
Composite slider2_comp = new Composite(slider_comp, SWT.NULL);
slider2_comp.setLayout(new GridLayout(6, true));
gd = new GridData(GridData.FILL_HORIZONTAL);
Utils.setLayoutData(slider2_comp, gd);
label = new Label(slider2_comp, SWT.NULL);
label.setText(MessageText.getString("privacy.view.public.only"));
label = new Label(slider2_comp, SWT.NULL);
label.setText(MessageText.getString("privacy.view.public.anon"));
label.setAlignment(SWT.CENTER);
gd = new GridData(GridData.FILL_HORIZONTAL);
gd.horizontalSpan = 2;
Utils.setLayoutData(label, gd);
label = new Label(slider2_comp, SWT.NULL);
label.setText(MessageText.getString("privacy.view.anon.only"));
label.setAlignment(SWT.CENTER);
gd = new GridData(GridData.FILL_HORIZONTAL);
gd.horizontalSpan = 2;
Utils.setLayoutData(label, gd);
label = new Label(slider2_comp, SWT.NULL);
label.setText(MessageText.getString("label.invalid"));
gd = new GridData(GridData.FILL_HORIZONTAL);
gd.horizontalAlignment = SWT.END;
Utils.setLayoutData(label, gd);
privacy_scale = new Scale(slider2_comp, SWT.HORIZONTAL);
gd = new GridData(GridData.FILL_HORIZONTAL);
gd.horizontalSpan = 6;
Utils.setLayoutData(privacy_scale, gd);
privacy_scale.setMinimum(0);
privacy_scale.setMaximum(30);
final boolean[] slider_mouse_down = { false };
privacy_scale.addMouseListener(new MouseAdapter() {
@Override
public void mouseUp(MouseEvent e) {
int pos = privacy_scale.getSelection();
int level = ((pos + 5) / 10);
if (level * 10 != pos) {
privacy_scale.setSelection(level * 10);
}
setPrivacyLevel(level);
slider_mouse_down[0] = false;
}
@Override
public void mouseDown(MouseEvent e) {
slider_mouse_down[0] = true;
}
});
privacy_scale.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
if (!slider_mouse_down[0]) {
int pos = privacy_scale.getSelection();
int level = ((pos + 5) / 10);
setPrivacyLevel(level);
}
}
});
// network selection
Composite network_comp = new Composite(slider_comp, SWT.NULL);
gd = new GridData();
Utils.setLayoutData(network_comp, gd);
network_buttons = new Button[AENetworkClassifier.AT_NETWORKS.length];
network_comp.setLayout(new GridLayout(1, false));
label = new Label(network_comp, SWT.NULL);
label.setText(MessageText.getString("ConfigView.section.connection.group.networks") + ":");
for (int i = 0; i < network_buttons.length; i++) {
final String nn = AENetworkClassifier.AT_NETWORKS[i];
String msg_text = "ConfigView.section.connection.networks." + nn;
Button button = new Button(network_comp, SWT.CHECK);
Messages.setLanguageText(button, msg_text);
network_buttons[i] = button;
button.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
boolean selected = ((Button) e.widget).getSelection();
if (current_dm != null) {
current_dm.getDownloadState().setNetworkEnabled(nn, selected);
}
}
});
GridData gridData = new GridData();
Utils.setLayoutData(button, gridData);
}
label = new Label(slider_comp, SWT.NULL);
final Composite tracker_webseed_comp = new Composite(slider_comp, SWT.NULL);
layout = new GridLayout(2, true);
layout.marginTop = layout.marginBottom = layout.marginLeft = layout.marginRight = 1;
tracker_webseed_comp.setLayout(layout);
gd = new GridData(GridData.FILL_HORIZONTAL);
gd.horizontalSpan = 2;
Utils.setLayoutData(tracker_webseed_comp, gd);
tracker_webseed_comp.addPaintListener(new PaintListener() {
@Override
public void paintControl(PaintEvent e) {
Rectangle client_area = tracker_webseed_comp.getClientArea();
Rectangle rect = new Rectangle(0, 0, client_area.width - 1, client_area.height - 1);
e.gc.setAlpha(50);
e.gc.drawRectangle(rect);
}
});
// Tracker Info
Composite tracker_comp = new Composite(tracker_webseed_comp, SWT.NULL);
gd = new GridData(GridData.FILL_HORIZONTAL);
Utils.setLayoutData(tracker_comp, gd);
tracker_comp.setLayout(new GridLayout(2, false));
label = new Label(tracker_comp, SWT.NULL);
label.setText(MessageText.getString("label.trackers") + ":");
tracker_info = new BufferedLabel(tracker_comp, SWT.DOUBLE_BUFFERED);
gd = new GridData(GridData.FILL_HORIZONTAL);
Utils.setLayoutData(tracker_info, gd);
// Webseed Info
Composite webseed_comp = new Composite(tracker_webseed_comp, SWT.NULL);
gd = new GridData(GridData.FILL_HORIZONTAL);
Utils.setLayoutData(webseed_comp, gd);
webseed_comp.setLayout(new GridLayout(2, false));
label = new Label(webseed_comp, SWT.NULL);
label.setText(MessageText.getString("label.webseeds") + ":");
webseed_info = new BufferedLabel(webseed_comp, SWT.DOUBLE_BUFFERED);
gd = new GridData(GridData.FILL_HORIZONTAL);
Utils.setLayoutData(webseed_info, gd);
// Peer Info
// label = new Label( slider_comp, SWT.NULL );
Composite peer_comp = new Composite(tracker_webseed_comp, SWT.NULL);
gd = new GridData(GridData.FILL_HORIZONTAL);
Utils.setLayoutData(peer_comp, gd);
peer_comp.setLayout(new GridLayout(2, false));
label = new Label(peer_comp, SWT.NULL);
label.setText(MessageText.getString("TableColumn.header.peers") + ":");
peer_info = new BufferedLabel(peer_comp, SWT.DOUBLE_BUFFERED);
gd = new GridData(GridData.FILL_HORIZONTAL);
Utils.setLayoutData(peer_info, gd);
// I2P install state
Group i2p_group = new Group(cMainComposite, SWT.NULL);
i2p_group.setText("I2P");
// Composite i2p_group = new Composite( cMainComposite, SWT.NULL );
gd = new GridData(GridData.FILL_HORIZONTAL);
Utils.setLayoutData(i2p_group, gd);
i2p_group.setLayout(new GridLayout(4, false));
label = new Label(i2p_group, SWT.NULL);
label.setText(MessageText.getString("privacy.view.lookup.info"));
gd = new GridData();
gd.horizontalSpan = 2;
Utils.setLayoutData(label, gd);
label = new Label(i2p_group, SWT.NULL);
label.setText(MessageText.getString("label.lookup.status") + ":");
i2p_result_summary = new BufferedLabel(i2p_group, SWT.DOUBLE_BUFFERED);
gd = new GridData(GridData.FILL_HORIZONTAL);
// gd.horizontalIndent = 4;
Utils.setLayoutData(i2p_result_summary, gd);
Composite i2p_button_comp = new Composite(i2p_group, SWT.NULL);
i2p_button_comp.setLayout(new GridLayout(2, false));
gd = new GridData(GridData.FILL_VERTICAL);
Utils.setLayoutData(i2p_button_comp, gd);
label = new Label(i2p_button_comp, SWT.NULL);
label.setText(MessageText.getString("GeneralView.section.availability"));
i2p_install_button = new Button(i2p_button_comp, SWT.PUSH);
i2p_install_button.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
final boolean[] result = { false };
I2PHelpers.installI2PHelper(null, result, new Runnable() {
@Override
public void run() {
Utils.execSWTThread(new Runnable() {
@Override
public void run() {
updateI2PState();
}
});
}
});
}
});
// I2P peer lookup
i2p_lookup_comp = new Composite(i2p_group, SWT.BORDER);
gd = new GridData();
gd.widthHint = 300;
gd.heightHint = 150;
Utils.setLayoutData(i2p_lookup_comp, gd);
i2p_lookup_comp.setBackground(Colors.white);
// i2p results
i2p_result_list = new Text(i2p_group, SWT.BORDER | SWT.READ_ONLY | SWT.V_SCROLL | SWT.WRAP | SWT.NO_FOCUS);
gd = new GridData(GridData.FILL_BOTH);
gd.horizontalSpan = 2;
Utils.setLayoutData(i2p_result_list, gd);
i2p_result_list.setEditable(false);
// i2p lookup button
label = new Label(i2p_button_comp, SWT.NULL);
label.setText(MessageText.getString("button.lookup.peers"));
i2p_lookup_button = new Button(i2p_button_comp, SWT.PUSH);
i2p_lookup_button.setText(MessageText.getString("button.search.dht"));
i2p_lookup_button.addSelectionListener(new SelectionAdapter() {
private int search_count;
@Override
public void widgetSelected(SelectionEvent event) {
Utils.disposeComposite(i2p_lookup_comp, false);
i2p_result_summary.setText("");
i2p_result_list.setText("");
PluginInterface i2p_pi = CoreFactory.getSingleton().getPluginManager().getPluginInterfaceByID("azneti2phelper", true);
if (i2p_pi != null) {
IPCInterface ipc = i2p_pi.getIPC();
Map<String, Object> options = new HashMap<>();
options.put("server_id", "Scraper");
options.put("server_id_transient", true);
options.put("ui_composite", i2p_lookup_comp);
final byte[] hash = (byte[]) i2p_lookup_button.getData("hash");
search_count++;
final int search_id = search_count;
IPCInterface callback = new IPCInterface() {
@Override
public Object invoke(String methodName, final Object[] params) throws IPCException {
if (search_id != search_count) {
return (null);
}
if (methodName.equals("statusUpdate")) {
final int status = (Integer) params[0];
if (status != TrackerPeerSource.ST_INITIALISING && status != TrackerPeerSource.ST_UPDATING) {
Utils.execSWTThread(new Runnable() {
@Override
public void run() {
if (i2p_lookup_button.isDisposed() || hash != i2p_lookup_button.getData("hash")) {
return;
}
i2p_lookup_button.setEnabled(true);
if (i2p_result_list.getText().length() == 0 && status != TrackerPeerSource.ST_UNAVAILABLE) {
i2p_result_summary.setText(MessageText.getString("label.no.peers.found"));
}
}
});
}
if (params.length == 4) {
Utils.execSWTThread(new Runnable() {
@Override
public void run() {
if (i2p_result_summary.isDisposed() || hash != i2p_lookup_button.getData("hash")) {
return;
}
int seeds = (Integer) params[1];
int leechers = (Integer) params[2];
int peers = (Integer) params[3];
i2p_result_summary.setText(MessageText.getString("privacy.view.lookup.msg", new String[] { String.valueOf(seeds), String.valueOf(leechers), String.valueOf(peers) }));
}
});
}
} else if (methodName.equals("msgUpdate")) {
Utils.execSWTThread(new Runnable() {
@Override
public void run() {
if (i2p_result_summary.isDisposed() || hash != i2p_lookup_button.getData("hash")) {
return;
}
String msg = (String) params[0];
i2p_result_summary.setText(msg);
}
});
} else if (methodName.equals("peerFound")) {
Utils.execSWTThread(new Runnable() {
@Override
public void run() {
if (i2p_result_list.isDisposed() || hash != i2p_lookup_button.getData("hash")) {
return;
}
String host = (String) params[0];
int peer_type = (Integer) params[1];
i2p_result_list.append(host + "\r\n");
}
});
}
return (null);
}
@Override
public boolean canInvoke(String methodName, Object[] params) {
return (true);
}
};
i2p_lookup_button.setEnabled(false);
i2p_result_summary.setText(MessageText.getString("label.searching"));
try {
ipc.invoke("lookupTorrent", new Object[] { "", hash, options, callback });
} catch (Throwable e) {
i2p_lookup_button.setEnabled(true);
e.printStackTrace();
}
}
}
});
Label i2p_options_info = new Label(i2p_button_comp, SWT.WRAP);
gd = new GridData(GridData.FILL_HORIZONTAL);
gd.horizontalSpan = 2;
gd.widthHint = 150;
Utils.setLayoutData(i2p_options_info, gd);
i2p_options_info.setText(MessageText.getString("privacy.view.check.bw.info"));
if (!COConfigurationManager.getBooleanParameter("privacy.view.check.bw.clicked", false)) {
FontData fontData = i2p_options_info.getFont().getFontData()[0];
final Font bold_font = new Font(i2p_options_info.getDisplay(), new FontData(fontData.getName(), fontData.getHeight(), SWT.BOLD));
i2p_options_info.setFont(bold_font);
i2p_options_info.addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent e) {
bold_font.dispose();
}
});
}
i2p_options_link = new Label(i2p_button_comp, SWT.NULL);
gd = new GridData(GridData.FILL_HORIZONTAL);
gd.horizontalSpan = 2;
Utils.setLayoutData(i2p_options_link, gd);
i2p_options_link.setText(MessageText.getString("privacy.view.check.bw"));
i2p_options_link.setCursor(i2p_options_link.getDisplay().getSystemCursor(SWT.CURSOR_HAND));
i2p_options_link.setForeground(Colors.blue);
i2p_options_link.addMouseListener(new MouseAdapter() {
@Override
public void mouseDoubleClick(MouseEvent arg0) {
openOptions();
}
@Override
public void mouseUp(MouseEvent arg0) {
openOptions();
}
private void openOptions() {
COConfigurationManager.setParameter("privacy.view.check.bw.clicked", true);
UIFunctions uif = UIFunctionsManager.getUIFunctions();
if (uif != null) {
uif.getMDI().showEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_CONFIG, "azi2phelper.name");
}
}
});
updateI2PState();
Utils.makeButtonsEqualWidth(Arrays.asList(new Button[] { i2p_install_button, i2p_lookup_button }));
label = new Label(i2p_button_comp, SWT.NULL);
gd = new GridData(GridData.FILL_BOTH);
gd.horizontalSpan = 2;
Utils.setLayoutData(label, gd);
Group bottom_comp = new Group(cMainComposite, SWT.NULL);
gd = new GridData(GridData.FILL_HORIZONTAL);
Utils.setLayoutData(bottom_comp, gd);
bottom_comp.setLayout(new GridLayout(2, false));
// Torrent Info
label = new Label(bottom_comp, SWT.NULL);
label.setText(MessageText.getString("authenticator.torrent") + ":");
Composite torrent_comp = new Composite(bottom_comp, SWT.NULL);
gd = new GridData(GridData.FILL_HORIZONTAL);
Utils.setLayoutData(torrent_comp, gd);
torrent_comp.setLayout(removeMarginsAndSpacing(new GridLayout(2, false)));
torrent_info = new BufferedLabel(torrent_comp, SWT.DOUBLE_BUFFERED);
gd = new GridData(GridData.FILL_HORIZONTAL);
Utils.setLayoutData(torrent_info, gd);
// source selection
label = new Label(bottom_comp, SWT.NULL);
label.setText(MessageText.getString("ConfigView.section.connection.group.peersources") + ":");
Composite sources_comp = new Composite(bottom_comp, SWT.NULL);
gd = new GridData(GridData.FILL_HORIZONTAL);
Utils.setLayoutData(sources_comp, gd);
source_buttons = new Button[PEPeerSource.PS_SOURCES.length];
sources_comp.setLayout(removeMargins(new GridLayout(source_buttons.length + 1, false)));
for (int i = 0; i < source_buttons.length; i++) {
final String src = PEPeerSource.PS_SOURCES[i];
String msg_text = "ConfigView.section.connection.peersource." + src;
Button button = new Button(sources_comp, SWT.CHECK);
Messages.setLanguageText(button, msg_text);
source_buttons[i] = button;
button.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
boolean selected = ((Button) e.widget).getSelection();
if (current_dm != null) {
current_dm.getDownloadState().setPeerSourceEnabled(src, selected);
}
}
});
GridData gridData = new GridData();
Utils.setLayoutData(button, gridData);
}
// IP Filter
label = new Label(bottom_comp, SWT.NULL);
label.setText(MessageText.getString("label.ip.filter") + ":");
Composite ipfilter_comp = new Composite(bottom_comp, SWT.NULL);
gd = new GridData(GridData.FILL_HORIZONTAL);
Utils.setLayoutData(ipfilter_comp, gd);
ipfilter_comp.setLayout(removeMargins(new GridLayout(2, false)));
ipfilter_enabled = new Button(ipfilter_comp, SWT.CHECK);
ipfilter_enabled.setText(MessageText.getString("label.enabled"));
ipfilter_enabled.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
current_dm.getDownloadState().setFlag(DownloadManagerState.FLAG_DISABLE_IP_FILTER, !ipfilter_enabled.getSelection());
}
});
gd = new GridData(GridData.FILL_HORIZONTAL);
Utils.setLayoutData(ipfilter_enabled, gd);
// VPN Info
label = new Label(bottom_comp, SWT.NULL);
label.setText(MessageText.getString("label.vpn.status") + ":");
Composite vpn_comp = new Composite(bottom_comp, SWT.NULL);
gd = new GridData(GridData.FILL_HORIZONTAL);
Utils.setLayoutData(vpn_comp, gd);
vpn_comp.setLayout(removeMargins(new GridLayout(2, false)));
vpn_info = new BufferedLabel(vpn_comp, SWT.DOUBLE_BUFFERED);
gd = new GridData(GridData.FILL_HORIZONTAL);
Utils.setLayoutData(vpn_info, gd);
// SOCKS Info
label = new Label(bottom_comp, SWT.NULL);
label.setText(MessageText.getString("label.socks.status") + ":");
Composite socks_comp = new Composite(bottom_comp, SWT.NULL);
gd = new GridData(GridData.FILL_HORIZONTAL);
Utils.setLayoutData(socks_comp, gd);
socks_comp.setLayout(removeMargins(new GridLayout(10, false)));
label = new Label(socks_comp, SWT.NULL);
label.setText(MessageText.getString("label.proxy") + ":");
socks_state = new BufferedLabel(socks_comp, SWT.DOUBLE_BUFFERED);
gd = new GridData();
gd.widthHint = 120;
Utils.setLayoutData(socks_state, gd);
// current details
label = new Label(socks_comp, SWT.NULL);
label.setText(MessageText.getString("PeersView.state") + ":");
socks_current = new BufferedLabel(socks_comp, SWT.DOUBLE_BUFFERED);
gd = new GridData();
gd.widthHint = 120;
Utils.setLayoutData(socks_current, gd);
// fail details
label = new Label(socks_comp, SWT.NULL);
label.setText(MessageText.getString("label.fails") + ":");
socks_fails = new BufferedLabel(socks_comp, SWT.DOUBLE_BUFFERED);
gd = new GridData();
gd.widthHint = 120;
Utils.setLayoutData(socks_fails, gd);
// more info
label = new Label(socks_comp, SWT.NULL);
gd = new GridData(GridData.FILL_HORIZONTAL);
gd.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING;
socks_more = new Label(socks_comp, SWT.NULL);
socks_more.setText(MessageText.getString("label.more") + "...");
Utils.setLayoutData(socks_more, gd);
socks_more.setCursor(socks_more.getDisplay().getSystemCursor(SWT.CURSOR_HAND));
socks_more.setForeground(Colors.blue);
socks_more.addMouseListener(new MouseAdapter() {
@Override
public void mouseDoubleClick(MouseEvent arg0) {
showSOCKSInfo();
}
@Override
public void mouseUp(MouseEvent arg0) {
showSOCKSInfo();
}
});
// the rest
sc.addControlListener(new ControlAdapter() {
@Override
public void controlResized(ControlEvent e) {
Rectangle r = sc.getClientArea();
Point size = cMainComposite.computeSize(r.width, SWT.DEFAULT);
sc.setMinSize(size);
}
});
swt_updateFields(null, current_dm);
updatePeersEtc(current_dm);
updateVPNSocks();
Rectangle r = sc.getClientArea();
Point size = cMainComposite.computeSize(r.width, SWT.DEFAULT);
sc.setMinSize(size);
Utils.relayout(cMainComposite);
}
use of com.biglybt.ui.UIFunctions in project BiglyBT by BiglySoftware.
the class SBC_SubscriptionResultsView method initTable.
private void initTable(Composite control) {
tv_subs_results = TableViewFactory.createTableViewSWT(SBC_SubscriptionResult.class, TABLE_SR, TABLE_SR, new TableColumnCore[0], ColumnSearchSubResultAge.COLUMN_ID, SWT.MULTI | SWT.FULL_SELECTION | SWT.VIRTUAL);
TableColumnManager tableManager = TableColumnManager.getInstance();
tableManager.setDefaultColumnNames(TABLE_SR, new String[] { ColumnSubResultNew.COLUMN_ID, ColumnSearchSubResultType.COLUMN_ID, ColumnSearchSubResultName.COLUMN_ID, ColumnSearchSubResultActions.COLUMN_ID, ColumnSearchSubResultSize.COLUMN_ID, ColumnSearchSubResultSeedsPeers.COLUMN_ID, ColumnSearchSubResultRatings.COLUMN_ID, ColumnSearchSubResultAge.COLUMN_ID, ColumnSearchSubResultRank.COLUMN_ID, ColumnSearchSubResultCategory.COLUMN_ID });
tableManager.setDefaultSortColumnName(TABLE_SR, ColumnSearchSubResultAge.COLUMN_ID);
TableColumnCore tcc = tableManager.getTableColumnCore(TABLE_SR, ColumnSearchSubResultAge.COLUMN_ID);
if (tcc != null) {
tcc.setDefaultSortAscending(true);
}
if (txtFilter != null) {
tv_subs_results.enableFilterCheck(txtFilter, this);
}
tv_subs_results.setRowDefaultHeight(COConfigurationManager.getIntParameter("Search Subs Row Height"));
SWTSkinObject soSizeSlider = getSkinObject("table-size-slider");
if (soSizeSlider instanceof SWTSkinObjectContainer) {
SWTSkinObjectContainer so = (SWTSkinObjectContainer) soSizeSlider;
if (!tv_subs_results.enableSizeSlider(so.getComposite(), 16, 100)) {
so.setVisible(false);
}
}
table_parent = new Composite(control, SWT.NONE);
table_parent.setLayoutData(Utils.getFilledFormData());
GridLayout layout = new GridLayout();
layout.marginHeight = layout.marginWidth = layout.verticalSpacing = layout.horizontalSpacing = 0;
table_parent.setLayout(layout);
tv_subs_results.addSelectionListener(new TableSelectionListener() {
@Override
public void selected(TableRowCore[] _rows) {
updateSelectedContent();
}
@Override
public void mouseExit(TableRowCore row) {
}
@Override
public void mouseEnter(TableRowCore row) {
}
@Override
public void focusChanged(TableRowCore focus) {
UIFunctions uiFunctions = UIFunctionsManager.getUIFunctions();
if (uiFunctions != null) {
uiFunctions.refreshIconBar();
}
}
@Override
public void deselected(TableRowCore[] rows) {
updateSelectedContent();
}
@Override
public void defaultSelected(TableRowCore[] rows, int stateMask) {
if (rows.length == 1) {
SBC_SubscriptionResult rc = (SBC_SubscriptionResult) rows[0].getDataSource();
SBC_SearchResultsView.downloadAction(rc);
}
}
private void updateSelectedContent() {
TableRowCore[] rows = tv_subs_results.getSelectedRows();
ArrayList<ISelectedContent> valid = new ArrayList<>();
last_selected_content.clear();
for (int i = 0; i < rows.length; i++) {
SBC_SubscriptionResult rc = (SBC_SubscriptionResult) rows[i].getDataSource();
last_selected_content.add(rc);
byte[] hash = rc.getHash();
if (hash != null && hash.length > 0) {
SelectedContent sc = new SelectedContent(Base32.encode(hash), rc.getName());
sc.setDownloadInfo(new DownloadUrlInfo(getDownloadURI(rc)));
valid.add(sc);
}
}
ISelectedContent[] sels = valid.toArray(new ISelectedContent[valid.size()]);
SelectedContentManager.changeCurrentlySelectedContent("IconBarEnabler", sels, tv_subs_results);
UIFunctions uiFunctions = UIFunctionsManager.getUIFunctions();
if (uiFunctions != null) {
uiFunctions.refreshIconBar();
}
}
}, false);
tv_subs_results.addLifeCycleListener(new TableLifeCycleListener() {
@Override
public void tableLifeCycleEventOccurred(TableView tv, int eventType, Map<String, Object> data) {
if (eventType == TableLifeCycleListener.EVENT_TABLELIFECYCLE_INITIALIZED) {
reconcileResults(ds);
}
}
});
tv_subs_results.addMenuFillListener(new TableViewSWTMenuFillListener() {
@Override
public void fillMenu(String sColumnName, Menu menu) {
Object[] _related_content = tv_subs_results.getSelectedDataSources().toArray();
final SBC_SubscriptionResult[] results = new SBC_SubscriptionResult[_related_content.length];
System.arraycopy(_related_content, 0, results, 0, results.length);
MenuItem item = new MenuItem(menu, SWT.PUSH);
item.setText(MessageText.getString("label.copy.url.to.clip"));
item.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
StringBuffer buffer = new StringBuffer(1024);
for (SBC_SubscriptionResult result : results) {
if (buffer.length() > 0) {
buffer.append("\r\n");
}
buffer.append(getDownloadURI(result));
}
ClipboardCopy.copyToClipBoard(buffer.toString());
}
});
item.setEnabled(results.length > 0);
SearchSubsUtils.addMenu(results, menu);
new MenuItem(menu, SWT.SEPARATOR);
if (results.length == 1) {
if (SearchSubsUtils.addMenu(results[0], menu)) {
new MenuItem(menu, SWT.SEPARATOR);
}
}
final MenuItem remove_item = new MenuItem(menu, SWT.PUSH);
remove_item.setText(MessageText.getString("azbuddy.ui.menu.remove"));
Utils.setMenuItemImage(remove_item, "delete");
remove_item.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
userDelete(results);
}
});
remove_item.setEnabled(results.length > 0);
new MenuItem(menu, SWT.SEPARATOR);
}
@Override
public void addThisColumnSubMenu(String columnName, Menu menuThisColumn) {
}
});
tv_subs_results.addKeyListener(new KeyListener() {
@Override
public void keyPressed(KeyEvent e) {
if (e.stateMask == 0 && e.keyCode == SWT.DEL) {
Object[] selected;
synchronized (this) {
if (tv_subs_results == null) {
selected = new Object[0];
} else {
selected = tv_subs_results.getSelectedDataSources().toArray();
}
}
SBC_SubscriptionResult[] content = new SBC_SubscriptionResult[selected.length];
for (int i = 0; i < content.length; i++) {
content[i] = (SBC_SubscriptionResult) selected[i];
}
userDelete(content);
e.doit = false;
}
}
@Override
public void keyReleased(KeyEvent arg0) {
}
});
/*
if (ds instanceof RCMItemSubView) {
tv_related_content.addCountChangeListener(new TableCountChangeListener() {
public void rowRemoved(TableRowCore row) {
updateCount();
}
public void rowAdded(TableRowCore row) {
updateCount();
}
private void updateCount() {
int size = tv_related_content == null ? 0 : tv_related_content.size(false);
((RCMItemSubView) ds).setCount(size);
}
});
((RCMItemSubView) ds).setCount(0);
}
*/
tv_subs_results.initialize(table_parent);
control.layout(true);
}
use of com.biglybt.ui.UIFunctions in project BiglyBT by BiglySoftware.
the class SubscriptionManagerUI method setupSideBar.
protected void setupSideBar(final UISWTInstance swt_ui) {
MultipleDocumentInterfaceSWT mdi = UIFunctionsManagerSWT.getUIFunctionsSWT().getMDISWT();
if (mdi == null) {
return;
}
mdiEntryOverview = mdi.createEntryFromEventListener(MultipleDocumentInterface.SIDEBAR_HEADER_DISCOVERY, new UISWTViewEventListenerHolder(MultipleDocumentInterface.SIDEBAR_SECTION_SUBSCRIPTIONS, SubscriptionsView.class, null, null), MultipleDocumentInterface.SIDEBAR_SECTION_SUBSCRIPTIONS, false, null, null);
if (mdiEntryOverview == null) {
return;
}
mdiEntryOverview.setDefaultExpanded(true);
synchronized (this) {
if (sidebar_setup_done) {
return;
}
sidebar_setup_done = true;
}
mdiEntryOverview.setImageLeftID("image.sidebar.subscriptions");
setupHeader(mdi, mdiEntryOverview);
String parentID = "sidebar." + MultipleDocumentInterface.SIDEBAR_SECTION_SUBSCRIPTIONS;
MenuManager menu_manager = ui_manager.getMenuManager();
MenuItem mi = menu_manager.addMenuItem(parentID, "menu.update.all.now");
mi.setDisposeWithUIDetach(UIInstance.UIT_SWT);
mi.addListener(new MenuItemListener() {
@Override
public void selected(MenuItem menu, Object target) {
SubscriptionManager subs_man = SubscriptionManagerFactory.getSingleton();
SubscriptionScheduler sched = subs_man.getScheduler();
Subscription[] subs = subs_man.getSubscriptions(true);
for (Subscription sub : subs) {
if (!sub.isSearchTemplate()) {
if (sub.getHistory().isEnabled()) {
try {
sched.downloadAsync(sub, true);
} catch (Throwable e) {
Debug.out(e);
}
}
}
}
}
});
mi = menu_manager.addMenuItem(parentID, "sep1");
mi.setDisposeWithUIDetach(UIInstance.UIT_SWT);
mi.setStyle(MenuItem.STYLE_SEPARATOR);
mi = menu_manager.addMenuItem(parentID, "MainWindow.menu.view.configuration");
mi.setDisposeWithUIDetach(UIInstance.UIT_SWT);
mi.addListener(new MenuItemListener() {
@Override
public void selected(MenuItem menu, Object target) {
UIFunctions uif = UIFunctionsManager.getUIFunctions();
if (uif != null) {
uif.getMDI().showEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_CONFIG, CONFIG_SECTION_ID);
}
}
});
}
use of com.biglybt.ui.UIFunctions in project BiglyBT by BiglySoftware.
the class MySharesView method defaultSelected.
private void defaultSelected(TableRowCore[] rows) {
ShareResource share = (ShareResource) tv.getFirstSelectedDataSource();
if (share == null) {
return;
}
// if a row was selected that means it was added, which
// required a core, so we assume there's a core here
List dms = CoreFactory.getSingleton().getGlobalManager().getDownloadManagers();
for (int i = 0; i < dms.size(); i++) {
DownloadManager dm = (DownloadManager) dms.get(i);
try {
byte[] share_hash = null;
if (share.getType() == ShareResource.ST_DIR) {
share_hash = ((ShareResourceDir) share).getItem().getTorrent().getHash();
} else if (share.getType() == ShareResource.ST_FILE) {
share_hash = ((ShareResourceFile) share).getItem().getTorrent().getHash();
}
if (Arrays.equals(share_hash, dm.getTorrent().getHash())) {
UIFunctions uiFunctions = UIFunctionsManager.getUIFunctions();
if (uiFunctions != null) {
uiFunctions.getMDI().showEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_TORRENT_DETAILS, dm);
}
break;
}
} catch (Throwable e) {
Debug.printStackTrace(e);
}
}
}
Aggregations