use of com.biglybt.ui.swt.SimpleTextEntryWindow in project BiglyBT by BiglySoftware.
the class BuddyPluginViewBetaChat method buildStatus.
private void buildStatus(Composite main_component, Composite component) {
boolean public_chat = !chat.isPrivateChat();
final Label menu_drop = new Label(component, SWT.NULL);
Messages.setLanguageTooltip(menu_drop, "TagSettingsView.title");
FontData fontData = menu_drop.getFont().getFontData()[0];
Display display = menu_drop.getDisplay();
italic_font = new Font(display, new FontData(fontData.getName(), fontData.getHeight(), SWT.ITALIC));
bold_font = new Font(display, new FontData(fontData.getName(), fontData.getHeight(), SWT.BOLD));
big_font = new Font(display, new FontData(fontData.getName(), (int) (fontData.getHeight() * 1.5), SWT.BOLD));
small_font = new Font(display, new FontData(fontData.getName(), (int) (fontData.getHeight() * 0.5), SWT.BOLD));
ftux_dark_bg = new Color(display, 183, 200, 212);
ftux_dark_fg = new Color(display, 0, 81, 134);
ftux_light_bg = new Color(display, 236, 242, 246);
component.addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent arg0) {
Font[] fonts = { italic_font, bold_font, big_font, small_font };
for (Font f : fonts) {
if (f != null) {
f.dispose();
}
}
Color[] colours = { ftux_dark_bg, ftux_dark_fg, ftux_light_bg };
for (Color c : colours) {
if (c != null) {
c.dispose();
}
}
if (drop_targets != null) {
for (DropTarget dt : drop_targets) {
dt.dispose();
}
}
closed();
}
});
status = new BufferedLabel(component, SWT.LEFT | SWT.DOUBLE_BUFFERED);
GridData grid_data = new GridData(GridData.FILL_HORIZONTAL);
Utils.setLayoutData(status, grid_data);
status.setText(MessageText.getString("PeersView.state.pending"));
Image image = ImageLoader.getInstance().getImage("cog_down");
menu_drop.setImage(image);
grid_data = new GridData();
grid_data.widthHint = image.getBounds().width;
grid_data.heightHint = image.getBounds().height;
Utils.setLayoutData(menu_drop, grid_data);
menu_drop.setCursor(menu_drop.getDisplay().getSystemCursor(SWT.CURSOR_HAND));
Control status_control = status.getControl();
final Menu status_menu = new Menu(status_control);
status.getControl().setMenu(status_menu);
menu_drop.setMenu(status_menu);
menu_drop.addMouseListener(new MouseAdapter() {
@Override
public void mouseDown(MouseEvent event) {
try {
Point p = status_menu.getDisplay().map(menu_drop, null, event.x, event.y);
status_menu.setLocation(p);
status_menu.setVisible(true);
} catch (Throwable e) {
Debug.out(e);
}
}
});
if (public_chat) {
Menu status_clip_menu = new Menu(component.getShell(), SWT.DROP_DOWN);
MenuItem status_clip_item = new MenuItem(status_menu, SWT.CASCADE);
status_clip_item.setMenu(status_clip_menu);
status_clip_item.setText(MessageText.getString("label.copy.to.clipboard"));
MenuItem status_mi = new MenuItem(status_clip_menu, SWT.PUSH);
status_mi.setText(MessageText.getString("azbuddy.dchat.copy.channel.key"));
status_mi.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
ClipboardCopy.copyToClipBoard(chat.getKey());
}
});
status_mi = new MenuItem(status_clip_menu, SWT.PUSH);
status_mi.setText(MessageText.getString("azbuddy.dchat.copy.channel.url"));
status_mi.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
ClipboardCopy.copyToClipBoard(chat.getURL());
}
});
status_mi = new MenuItem(status_clip_menu, SWT.PUSH);
status_mi.setText(MessageText.getString("azbuddy.dchat.copy.rss.url"));
status_mi.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
ClipboardCopy.copyToClipBoard("azplug:?id=azbuddy&arg=" + UrlUtils.encode(chat.getURL() + "&format=rss"));
}
});
status_mi = new MenuItem(status_clip_menu, SWT.PUSH);
status_mi.setText(MessageText.getString("azbuddy.dchat.copy.channel.pk"));
status_mi.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
ClipboardCopy.copyToClipBoard(Base32.encode(chat.getPublicKey()));
}
});
status_mi = new MenuItem(status_clip_menu, SWT.PUSH);
status_mi.setText(MessageText.getString("azbuddy.dchat.copy.channel.export"));
status_mi.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
ClipboardCopy.copyToClipBoard(chat.export());
}
});
if (!chat.isManaged()) {
Menu status_channel_menu = new Menu(component.getShell(), SWT.DROP_DOWN);
MenuItem status_channel_item = new MenuItem(status_menu, SWT.CASCADE);
status_channel_item.setMenu(status_channel_menu);
status_channel_item.setText(MessageText.getString("azbuddy.dchat.rchans"));
// Managed channel
status_mi = new MenuItem(status_channel_menu, SWT.PUSH);
status_mi.setText(MessageText.getString("azbuddy.dchat.rchans.managed"));
status_mi.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
try {
ChatInstance inst = chat.getManagedChannel();
BuddyPluginViewBetaChat.createChatWindow(view, plugin, inst);
} catch (Throwable e) {
Debug.out(e);
}
}
});
// RO channel
status_mi = new MenuItem(status_channel_menu, SWT.PUSH);
status_mi.setText(MessageText.getString("azbuddy.dchat.rchans.ro"));
status_mi.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
try {
ChatInstance inst = chat.getReadOnlyChannel();
createChatWindow(view, plugin, inst);
} catch (Throwable e) {
Debug.out(e);
}
}
});
// Random sub-channel
status_mi = new MenuItem(status_channel_menu, SWT.PUSH);
status_mi.setText(MessageText.getString("azbuddy.dchat.rchans.rand"));
status_mi.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
try {
byte[] rand = new byte[20];
RandomUtils.nextSecureBytes(rand);
ChatInstance inst = beta.getChat(chat.getNetwork(), chat.getKey() + " {" + Base32.encode(rand) + "}");
createChatWindow(view, plugin, inst);
} catch (Throwable e) {
Debug.out(e);
}
}
});
if (beta.isI2PAvailable()) {
status_mi = new MenuItem(status_channel_menu, SWT.PUSH);
status_mi.setText(MessageText.getString(chat.getNetwork() == AENetworkClassifier.AT_I2P ? "azbuddy.dchat.rchans.pub" : "azbuddy.dchat.rchans.anon"));
status_mi.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
try {
ChatInstance inst = beta.getChat(chat.getNetwork() == AENetworkClassifier.AT_I2P ? AENetworkClassifier.AT_PUBLIC : AENetworkClassifier.AT_I2P, chat.getKey());
createChatWindow(view, plugin, inst);
} catch (Throwable e) {
Debug.out(e);
}
}
});
}
}
final MenuItem fave_mi = new MenuItem(status_menu, SWT.CHECK);
fave_mi.setText(MessageText.getString("label.fave"));
fave_mi.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
chat.setFavourite(fave_mi.getSelection());
}
});
final MenuItem sis_mi = new MenuItem(status_menu, SWT.PUSH);
sis_mi.setText(MessageText.getString(Utils.isAZ2UI() ? "label.show.in.tab" : "label.show.in.sidebar"));
sis_mi.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
BuddyPluginUI.openChat(chat.getNetwork(), chat.getKey());
}
});
addFriendsMenu(status_menu);
// advanced
final Menu advanced_menu = new Menu(status_menu.getShell(), SWT.DROP_DOWN);
MenuItem advanced_menu_item = new MenuItem(status_menu, SWT.CASCADE);
advanced_menu_item.setMenu(advanced_menu);
advanced_menu_item.setText(MessageText.getString("MyTorrentsView.menu.advancedmenu"));
// rename
final MenuItem rename_mi = new MenuItem(advanced_menu, SWT.PUSH);
rename_mi.setText(MessageText.getString("MyTorrentsView.menu.rename"));
rename_mi.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
String name = chat.getDisplayName();
if (name == null) {
name = chat.getName();
}
UISWTInputReceiver entry = new SimpleTextEntryWindow();
entry.setPreenteredText(name, false);
entry.maintainWhitespace(false);
entry.allowEmptyInput(false);
entry.setLocalisedTitle(MessageText.getString("label.rename", new String[] { name }));
entry.prompt(new UIInputReceiverListener() {
@Override
public void UIInputReceiverClosed(UIInputReceiver entry) {
if (!entry.hasSubmittedInput()) {
return;
}
String input = entry.getSubmittedInput().trim();
if (input.length() > 0) {
try {
chat.setDisplayName(input);
} catch (Throwable e) {
Debug.printStackTrace(e);
}
}
}
});
}
});
// view type
final Menu vt_menu = new Menu(status_menu.getShell(), SWT.DROP_DOWN);
MenuItem vt_menu_item = new MenuItem(advanced_menu, SWT.CASCADE);
vt_menu_item.setMenu(vt_menu);
vt_menu_item.setText(MessageText.getString("menu.view.options"));
SelectionAdapter listener = new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
int vt = -1;
for (MenuItem mi : vt_menu.getItems()) {
if (mi.getSelection()) {
vt = (Integer) mi.getData();
}
}
if (vt != -1) {
chat.setViewType(vt);
buildSupport(main_component);
main_component.layout(true, true);
}
}
};
MenuItem vt_mi = new MenuItem(vt_menu, SWT.RADIO);
vt_mi.setText(MessageText.getString("label.full"));
vt_mi.setData(BuddyPluginBeta.VIEW_TYPE_DEFAULT);
vt_mi.addSelectionListener(listener);
vt_mi = new MenuItem(vt_menu, SWT.RADIO);
vt_mi.setText(MessageText.getString("ConfigView.section.sharing"));
vt_mi.setData(BuddyPluginBeta.VIEW_TYPE_SHARING);
if (chat.isReadOnly()) {
vt_mi.setEnabled(false);
}
vt_mi.addSelectionListener(listener);
vt_menu.addMenuListener(new MenuAdapter() {
@Override
public void menuShown(MenuEvent e) {
int vt = chat.getViewType();
for (MenuItem mi : vt_menu.getItems()) {
mi.setSelection(vt == (Integer) mi.getData());
}
}
});
// persist messages
final MenuItem persist_mi = new MenuItem(advanced_menu, SWT.CHECK);
persist_mi.setText(MessageText.getString("azbuddy.dchat.save.messages"));
persist_mi.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
chat.setSaveMessages(persist_mi.getSelection());
}
});
final MenuItem log_mi = new MenuItem(advanced_menu, SWT.CHECK);
log_mi.setText(MessageText.getString("azbuddy.dchat.log.messages"));
log_mi.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
chat.setLogMessages(log_mi.getSelection());
}
});
final MenuItem automute_mi = new MenuItem(advanced_menu, SWT.CHECK);
automute_mi.setText(MessageText.getString("azbuddy.dchat.auto.mute"));
automute_mi.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
chat.setAutoMute(automute_mi.getSelection());
}
});
final MenuItem postnotifications_mi = new MenuItem(advanced_menu, SWT.CHECK);
postnotifications_mi.setText(MessageText.getString("azbuddy.dchat.post.to.notifcations"));
postnotifications_mi.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
chat.setEnableNotificationsPost(postnotifications_mi.getSelection());
}
});
final MenuItem disableindicators_mi = new MenuItem(advanced_menu, SWT.CHECK);
disableindicators_mi.setText(MessageText.getString("azbuddy.dchat.disable.msg.indicators"));
disableindicators_mi.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
chat.setDisableNewMsgIndications(disableindicators_mi.getSelection());
}
});
// setup menu
status_menu.addMenuListener(new MenuAdapter() {
@Override
public void menuShown(MenuEvent e) {
fave_mi.setSelection(chat.isFavourite());
persist_mi.setSelection(chat.getSaveMessages());
log_mi.setSelection(chat.getLogMessages());
automute_mi.setSelection(chat.getAutoMute());
postnotifications_mi.setSelection(chat.getEnableNotificationsPost());
boolean disable_indications = chat.getDisableNewMsgIndications();
disableindicators_mi.setSelection(disable_indications);
postnotifications_mi.setEnabled(!disable_indications);
}
});
} else {
final Menu status_priv_menu = new Menu(component.getShell(), SWT.DROP_DOWN);
MenuItem status_priv_item = new MenuItem(status_menu, SWT.CASCADE);
status_priv_item.setMenu(status_priv_menu);
status_priv_item.setText(MessageText.getString("label.private.chat"));
SelectionAdapter listener = new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
beta.setPrivateChatState((Integer) ((MenuItem) e.widget).getData());
}
};
MenuItem status_mi = new MenuItem(status_priv_menu, SWT.RADIO);
status_mi.setText(MessageText.getString("label.enabled"));
status_mi.setData(BuddyPluginBeta.PRIVATE_CHAT_ENABLED);
status_mi.addSelectionListener(listener);
status_mi = new MenuItem(status_priv_menu, SWT.RADIO);
status_mi.setText(MessageText.getString("label.pinned.only"));
status_mi.setData(BuddyPluginBeta.PRIVATE_CHAT_PINNED_ONLY);
status_mi.addSelectionListener(listener);
status_mi = new MenuItem(status_priv_menu, SWT.RADIO);
status_mi.setText(MessageText.getString("label.disabled"));
status_mi.setData(BuddyPluginBeta.PRIVATE_CHAT_DISABLED);
status_mi.addSelectionListener(listener);
status_priv_menu.addMenuListener(new MenuAdapter() {
@Override
public void menuShown(MenuEvent e) {
int pc_state = beta.getPrivateChatState();
for (MenuItem mi : status_priv_menu.getItems()) {
mi.setSelection(pc_state == (Integer) mi.getData());
}
}
});
addFriendsMenu(status_menu);
final MenuItem keep_alive_mi = new MenuItem(status_menu, SWT.CHECK);
keep_alive_mi.setText(MessageText.getString("label.keep.alive"));
status_menu.addMenuListener(new MenuAdapter() {
@Override
public void menuShown(MenuEvent e) {
keep_alive_mi.setSelection(chat.getUserData("AC:KeepAlive") != null);
}
});
keep_alive_mi.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
ChatInstance clone = (ChatInstance) chat.getUserData("AC:KeepAlive");
if (clone != null) {
clone.destroy();
clone = null;
} else {
try {
clone = chat.getClone();
} catch (Throwable f) {
}
}
chat.setUserData("AC:KeepAlive", clone);
}
});
final MenuItem sis_mi = new MenuItem(status_menu, SWT.PUSH);
sis_mi.setText(MessageText.getString("label.show.in.sidebar"));
sis_mi.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
BuddyPluginUI.openChat(chat.getNetwork(), chat.getKey());
}
});
}
}
use of com.biglybt.ui.swt.SimpleTextEntryWindow in project BiglyBT by BiglySoftware.
the class SelectableSpeedMenu method generateMenuItems.
public static void generateMenuItems(final Menu parent, final Core core, final GlobalManager globalManager, final boolean up_menu) {
// can't currently do this properly as global limits stored as K not B :(
final int kInB = 1024;
final MenuItem[] oldItems = parent.getItems();
for (int i = 0; i < oldItems.length; i++) {
oldItems[i].dispose();
}
final String configKey = up_menu ? TransferSpeedValidator.getActiveUploadParameter(globalManager) : "Max Download Speed KBs";
final int speedPartitions = 12;
int maxBandwidth = COConfigurationManager.getIntParameter(configKey);
final boolean unlim = (maxBandwidth == 0);
maxBandwidth = adjustMaxBandWidth(maxBandwidth, globalManager, up_menu, kInB);
boolean auto = false;
if (up_menu) {
final String configAutoKey = TransferSpeedValidator.getActiveAutoUploadParameter(globalManager);
auto = TransferSpeedValidator.isAutoSpeedActive(globalManager);
// auto
final MenuItem auto_item = new MenuItem(parent, SWT.CHECK);
auto_item.setText(MessageText.getString("ConfigView.auto"));
auto_item.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event e) {
COConfigurationManager.setParameter(configAutoKey, auto_item.getSelection());
COConfigurationManager.save();
}
});
if (auto)
auto_item.setSelection(true);
auto_item.setEnabled(TransferSpeedValidator.isAutoUploadAvailable(core));
new MenuItem(parent, SWT.SEPARATOR);
}
MenuItem item = new MenuItem(parent, SWT.RADIO);
item.setText(MessageText.getString("MyTorrentsView.menu.setSpeed.unlimited"));
item.setData("maxkb", new Integer(0));
item.setSelection(unlim && !auto);
item.addListener(SWT.Selection, getLimitMenuItemListener(up_menu, parent, globalManager, configKey));
Integer[] speed_limits = null;
final String config_prefix = "config.ui.speed.partitions.manual." + ((up_menu) ? "upload" : "download") + ".";
if (COConfigurationManager.getBooleanParameter(config_prefix + "enabled", false)) {
speed_limits = parseSpeedPartitionString(COConfigurationManager.getStringParameter(config_prefix + "values", ""));
}
if (speed_limits == null) {
speed_limits = getGenericSpeedList(speedPartitions, maxBandwidth);
}
for (int i = 0; i < speed_limits.length; i++) {
Integer i_value = speed_limits[i];
int value = i_value.intValue();
// Don't allow the user to easily select slow speeds.
if (value < 5) {
continue;
}
item = new MenuItem(parent, SWT.RADIO);
item.setText(DisplayFormatters.formatByteCountToKiBEtcPerSec(value * kInB, true));
item.setData("maxkb", i_value);
item.addListener(SWT.Selection, getLimitMenuItemListener(up_menu, parent, globalManager, configKey));
item.setSelection(!unlim && value == maxBandwidth && !auto);
}
new MenuItem(parent, SWT.SEPARATOR);
final MenuItem itemDownSpeedManual = new MenuItem(parent, SWT.PUSH);
Messages.setLanguageText(itemDownSpeedManual, "MyTorrentsView.menu.manual");
itemDownSpeedManual.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
String kbps_str = MessageText.getString("MyTorrentsView.dialog.setNumber.inKbps", new String[] { DisplayFormatters.getRateUnit(DisplayFormatters.UNIT_KB) });
SimpleTextEntryWindow entryWindow = new SimpleTextEntryWindow();
entryWindow.initTexts("MyTorrentsView.dialog.setSpeed.title", new String[] { MessageText.getString(up_menu ? "MyTorrentsView.dialog.setNumber.upload" : "MyTorrentsView.dialog.setNumber.download") }, "MyTorrentsView.dialog.setNumber.text", new String[] { kbps_str, MessageText.getString(up_menu ? "MyTorrentsView.dialog.setNumber.upload" : "MyTorrentsView.dialog.setNumber.download") });
entryWindow.prompt(new UIInputReceiverListener() {
@Override
public void UIInputReceiverClosed(UIInputReceiver entryWindow) {
if (!entryWindow.hasSubmittedInput()) {
return;
}
String sReturn = entryWindow.getSubmittedInput();
if (sReturn == null)
return;
int newSpeed;
try {
newSpeed = (int) (Double.valueOf(sReturn).doubleValue());
} catch (NumberFormatException er) {
MessageBox mb = new MessageBox(parent.getShell(), SWT.ICON_ERROR | SWT.OK);
mb.setText(MessageText.getString("MyTorrentsView.dialog.NumberError.title"));
mb.setMessage(MessageText.getString("MyTorrentsView.dialog.NumberError.text"));
mb.open();
return;
}
if (up_menu) {
String configAutoKey = TransferSpeedValidator.getActiveAutoUploadParameter(globalManager);
COConfigurationManager.setParameter(configAutoKey, false);
}
final int cValue = ((Integer) new TransferSpeedValidator(configKey, new Integer(newSpeed)).getValue()).intValue();
COConfigurationManager.setParameter(configKey, cValue);
COConfigurationManager.save();
}
});
}
});
}
use of com.biglybt.ui.swt.SimpleTextEntryWindow in project BiglyBT by BiglySoftware.
the class FilesViewMenuUtil method changePriorityManual.
private static void changePriorityManual(final List<DiskManagerFileInfo> file_list) {
SimpleTextEntryWindow entryWindow = new SimpleTextEntryWindow("FilesView.dialog.priority.title", "FilesView.dialog.priority.text");
entryWindow.prompt(new UIInputReceiverListener() {
@Override
public void UIInputReceiverClosed(UIInputReceiver entryWindow) {
if (!entryWindow.hasSubmittedInput()) {
return;
}
String sReturn = entryWindow.getSubmittedInput();
if (sReturn == null)
return;
int priority = 0;
try {
priority = Integer.valueOf(sReturn).intValue();
} catch (NumberFormatException er) {
Debug.out("Invalid priority: " + sReturn);
new MessageBoxShell(SWT.ICON_ERROR | SWT.OK, MessageText.getString("FilePriority.invalid.title"), MessageText.getString("FilePriority.invalid.text", new String[] { sReturn })).open(null);
return;
}
Map<DownloadManager, ArrayList<DiskManagerFileInfo>> mapDMtoDMFI = new IdentityHashMap<>();
for (DiskManagerFileInfo file : file_list) {
DownloadManager dm = file.getDownloadManager();
ArrayList<DiskManagerFileInfo> listFileInfos = mapDMtoDMFI.get(dm);
if (listFileInfos == null) {
listFileInfos = new ArrayList<>(1);
mapDMtoDMFI.put(dm, listFileInfos);
}
listFileInfos.add(file);
file.setPriority(priority);
}
for (DownloadManager dm : mapDMtoDMFI.keySet()) {
ArrayList<DiskManagerFileInfo> list = mapDMtoDMFI.get(dm);
DiskManagerFileInfo[] fileInfos = list.toArray(new DiskManagerFileInfo[0]);
boolean paused = setSkipped(dm, fileInfos, false, false);
if (paused) {
dm.resume();
}
}
}
});
}
use of com.biglybt.ui.swt.SimpleTextEntryWindow in project BiglyBT by BiglySoftware.
the class FilesViewMenuUtil method askForRenameFilenameAndExec.
private static void askForRenameFilenameAndExec(final DiskManagerFileInfo fileInfo, final TableView tv) {
final SimpleTextEntryWindow dialog = new SimpleTextEntryWindow("FilesView.rename.filename.title", "FilesView.rename.filename.text");
String file_name = fileInfo.getFile(true).getName();
// false -> it's not "suggested", it's a previous value
dialog.setPreenteredText(file_name, false);
int pos = file_name.lastIndexOf('.');
if (pos > 0) {
String suffix = fileInfo.getDownloadManager().getDownloadState().getAttribute(DownloadManagerState.AT_INCOMP_FILE_SUFFIX);
if (suffix != null && file_name.substring(pos).equals(suffix)) {
pos--;
while (pos > 0 && file_name.charAt(pos) != '.') {
pos--;
}
}
if (pos > 0) {
dialog.selectPreenteredTextRange(new int[] { 0, pos });
}
}
dialog.allowEmptyInput(false);
dialog.prompt(new UIInputReceiverListener() {
@Override
public void UIInputReceiverClosed(UIInputReceiver receiver) {
if (!receiver.hasSubmittedInput()) {
return;
}
File existing_file = fileInfo.getFile(true);
File f_target = new File(existing_file.getParentFile(), receiver.getSubmittedInput());
DownloadManager manager = fileInfo.getDownloadManager();
boolean needsUnpause = manager.pause();
moveFile(fileInfo.getDownloadManager(), fileInfo, f_target, false, new Runnable() {
@Override
public void run() {
if (needsUnpause) {
manager.resume();
}
invalidateRows(tv, Arrays.asList(fileInfo));
}
});
}
});
}
use of com.biglybt.ui.swt.SimpleTextEntryWindow 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);
}
Aggregations