use of com.biglybt.pif.ui.UIInputReceiver in project BiglyBT by BiglySoftware.
the class TagUIUtils method addTagGroupMenu.
private static boolean addTagGroupMenu(Menu menu, TagGroup group) {
int tt = group.getTagType().getTagType();
boolean need_sep = false;
if (tt == TagType.TT_DOWNLOAD_MANUAL) {
// exclusive
MenuItem exclusive_item = new MenuItem(menu, SWT.CHECK);
exclusive_item.setText(MessageText.getString("label.exclusive"));
exclusive_item.setSelection(group.isExclusive());
exclusive_item.addListener(SWT.Selection, (e) -> {
group.setExclusive(exclusive_item.getSelection());
});
// move on assign root
File existing = group.getRootMoveOnAssignLocation();
final Menu moa_menu = new Menu(menu.getShell(), SWT.DROP_DOWN);
MenuItem isl_item = new MenuItem(menu, SWT.CASCADE);
Messages.setLanguageText(isl_item, "label.tag.group.moa.root");
isl_item.setMenu(moa_menu);
MenuItem clear_item = new MenuItem(moa_menu, SWT.CASCADE);
Messages.setLanguageText(clear_item, "Button.clear");
clear_item.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
group.setRootMoveOnAssignLocation(null);
}
});
if (existing != null) {
MenuItem current_item = new MenuItem(moa_menu, SWT.RADIO);
current_item.setSelection(true);
current_item.setText(existing.getAbsolutePath());
new MenuItem(moa_menu, SWT.SEPARATOR);
} else {
clear_item.setEnabled(false);
}
MenuItem set_item = new MenuItem(moa_menu, SWT.CASCADE);
Messages.setLanguageText(set_item, "label.set");
set_item.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
DirectoryDialog dd = new DirectoryDialog(moa_menu.getShell());
dd.setFilterPath(TorrentOpener.getFilterPathData());
dd.setText(MessageText.getString("MyTorrentsView.menu.movedata.dialog"));
String path = dd.open();
if (path != null) {
TorrentOpener.setFilterPathData(path);
group.setRootMoveOnAssignLocation(new File(path));
}
}
});
MenuItem rename_item = new MenuItem(menu, SWT.CASCADE);
Messages.setLanguageText(rename_item, "MyTorrentsView.menu.rename");
rename_item.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
String name = group.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) {
Utils.getOffOfSWTThread(() -> {
for (Tag t : group.getTags()) {
t.setGroup(input);
}
});
}
}
});
}
});
need_sep = true;
}
if (tt == TagType.TT_DOWNLOAD_MANUAL || tt == TagType.TT_PEER_IPSET) {
addColourChooser(menu, "TagGroup.menu.defaultcolor", group.getColor() != null, group, (selected) -> {
group.setColor(selected == null ? null : new int[] { selected.red, selected.green, selected.blue });
});
need_sep = true;
}
return (need_sep);
}
use of com.biglybt.pif.ui.UIInputReceiver in project BiglyBT by BiglySoftware.
the class TagUIUtils method createTFProperitesMenuItems.
private static void createTFProperitesMenuItems(Menu menu, Tag tag) {
final Menu props_menu = new Menu(menu.getShell(), SWT.DROP_DOWN);
MenuItem props_item = new MenuItem(menu, SWT.CASCADE);
Messages.setLanguageText(props_item, "label.properties");
props_item.setMenu(props_menu);
addColourChooser(props_menu, "label.color", !tag.isColorDefault(), tag, (selected) -> {
tag.setColor(selected == null ? null : new int[] { selected.red, selected.green, selected.blue });
});
if (!tag.getTagType().hasTagTypeFeature(TagFeature.TF_PROPERTIES)) {
return;
}
TagFeatureProperties props = (TagFeatureProperties) tag;
TagProperty[] tps = props.getSupportedProperties();
for (final TagProperty tp : tps) {
if (tp.getType() == TagFeatureProperties.PT_STRING_LIST) {
String tp_name = tp.getName(false);
if (tp_name.equals(TagFeatureProperties.PR_CONSTRAINT)) {
MenuItem const_item = new MenuItem(props_menu, SWT.PUSH);
Messages.setLanguageText(const_item, "label.contraints");
const_item.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
final String[] old_value = tp.getStringList();
String def_val;
if (old_value != null && old_value.length > 0) {
def_val = old_value[0];
} else {
def_val = "";
}
String msg = MessageText.getString("UpdateConstraint.message");
SimpleTextEntryWindow entryWindow = new SimpleTextEntryWindow("UpdateConstraint.title", "!" + msg + "!");
entryWindow.setPreenteredText(def_val, false);
entryWindow.selectPreenteredText(true);
entryWindow.prompt(new UIInputReceiverListener() {
@Override
public void UIInputReceiverClosed(UIInputReceiver receiver) {
if (!receiver.hasSubmittedInput()) {
return;
}
try {
String text = receiver.getSubmittedInput().trim();
if (text.length() == 0) {
tp.setStringList(null);
} else {
String old_options = old_value.length > 1 ? old_value[1] : "";
tp.setStringList(new String[] { text, old_options });
}
} catch (Throwable e) {
Debug.out(e);
}
}
});
}
});
} else if (tp_name.equals(TagFeatureProperties.PR_TRACKER_TEMPLATES)) {
final TrackersUtil tut = TrackersUtil.getInstance();
List<String> templates = new ArrayList<>(tut.getMultiTrackers().keySet());
String str_merge = MessageText.getString("label.merge");
String str_replace = MessageText.getString("label.replace");
String str_remove = MessageText.getString("Button.remove");
String[] val = tp.getStringList();
String def_str;
final List<String> selected = new ArrayList<>();
if (val == null || val.length == 0) {
def_str = "";
} else {
def_str = "";
for (String v : val) {
String[] bits = v.split(":");
if (bits.length == 2) {
String tn = bits[1];
if (templates.contains(tn)) {
String type = bits[0];
if (type.equals("m")) {
tn += ": " + str_merge;
} else if (type.equals("r")) {
tn += ": " + str_replace;
} else {
tn += ": " + str_remove;
}
selected.add(v);
def_str += (def_str.length() == 0 ? "" : ", ") + tn;
}
}
}
}
Collections.sort(templates);
// deliberately hanging this off the main menu, not properties...
Menu ttemp_menu = new Menu(menu.getShell(), SWT.DROP_DOWN);
MenuItem ttemp_item = new MenuItem(menu, SWT.CASCADE);
ttemp_item.setText(MessageText.getString("label.tracker.templates") + (def_str.length() == 0 ? "" : (" (" + def_str + ") ")));
ttemp_item.setMenu(ttemp_menu);
MenuItem new_item = new MenuItem(ttemp_menu, SWT.PUSH);
Messages.setLanguageText(new_item, "wizard.multitracker.new");
new_item.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
List<List<String>> group = new ArrayList<>();
List<String> tracker = new ArrayList<>();
group.add(tracker);
new MultiTrackerEditor(props_menu.getShell(), null, group, new TrackerEditorListener() {
@Override
public void trackersChanged(String oldName, String newName, List<List<String>> trackers) {
if (trackers != null) {
tut.addMultiTracker(newName, trackers);
}
}
});
}
});
MenuItem reapply_item = new MenuItem(ttemp_menu, SWT.PUSH);
Messages.setLanguageText(reapply_item, "label.reapply");
reapply_item.addListener(SWT.Selection, (ListenerGetOffSWT) event -> tp.syncListeners());
reapply_item.setEnabled(def_str.length() > 0);
if (templates.size() > 0) {
new MenuItem(ttemp_menu, SWT.SEPARATOR);
for (final String template_name : templates) {
Menu t_menu = new Menu(ttemp_menu.getShell(), SWT.DROP_DOWN);
MenuItem t_item = new MenuItem(ttemp_menu, SWT.CASCADE);
t_item.setText(template_name);
t_item.setMenu(t_menu);
boolean r_selected = false;
for (int i = 0; i < 3; i++) {
final MenuItem sel_item = new MenuItem(t_menu, SWT.CHECK);
final String key = (i == 0 ? "m" : (i == 1 ? "r" : "x")) + ":" + template_name;
sel_item.setText(i == 0 ? str_merge : (i == 1 ? str_replace : str_remove));
boolean is_sel = selected.contains(key);
r_selected |= is_sel;
sel_item.setSelection(is_sel);
sel_item.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
if (sel_item.getSelection()) {
selected.add(key);
} else {
selected.remove(key);
}
Utils.getOffOfSWTThread(new AERunnable() {
@Override
public void runSupport() {
tp.setStringList(selected.toArray(new String[selected.size()]));
}
});
}
});
}
if (r_selected) {
Utils.setMenuItemImage(t_item, "graytick");
}
new MenuItem(t_menu, SWT.SEPARATOR);
MenuItem edit_item = new MenuItem(t_menu, SWT.PUSH);
Messages.setLanguageText(edit_item, "wizard.multitracker.edit");
edit_item.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
new MultiTrackerEditor(props_menu.getShell(), template_name, tut.getMultiTrackers().get(template_name), new TrackerEditorListener() {
@Override
public void trackersChanged(String oldName, String newName, List<List<String>> trackers) {
if (oldName != null && !oldName.equals(newName)) {
tut.removeMultiTracker(oldName);
}
tut.addMultiTracker(newName, trackers);
}
});
}
});
MenuItem del_item = new MenuItem(t_menu, SWT.PUSH);
Messages.setLanguageText(del_item, "FileItem.delete");
Utils.setMenuItemImage(del_item, "delete");
del_item.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
MessageBoxShell mb = new MessageBoxShell(MessageText.getString("message.confirm.delete.title"), MessageText.getString("message.confirm.delete.text", new String[] { template_name }), new String[] { MessageText.getString("Button.yes"), MessageText.getString("Button.no") }, 1);
mb.open(new UserPrompterResultListener() {
@Override
public void prompterClosed(int result) {
if (result == 0) {
tut.removeMultiTracker(template_name);
}
}
});
}
});
}
}
} else {
String[] val = tp.getStringList();
String def_str;
String msg_str = null;
if (val == null || val.length == 0) {
def_str = "";
} else {
def_str = "";
for (String v : val) {
if (def_str.length() > 100 && msg_str == null) {
msg_str = def_str + "...";
}
def_str += (def_str.length() == 0 ? "" : ", ") + v;
}
}
if (msg_str == null) {
msg_str = def_str;
}
MenuItem set_item = new MenuItem(props_menu, SWT.PUSH);
set_item.setText(tp.getName(true) + (msg_str.length() == 0 ? "" : (" (" + msg_str + ") ")) + "...");
final String f_def_str = def_str;
set_item.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
String msg = MessageText.getString("UpdateProperty.list.message", new String[] { tp.getName(true) });
SimpleTextEntryWindow entryWindow = new SimpleTextEntryWindow("UpdateProperty.title", "!" + msg + "!");
entryWindow.setPreenteredText(f_def_str, false);
entryWindow.selectPreenteredText(true);
entryWindow.prompt(new UIInputReceiverListener() {
@Override
public void UIInputReceiverClosed(UIInputReceiver entryWindow) {
if (!entryWindow.hasSubmittedInput()) {
return;
}
try {
String text = entryWindow.getSubmittedInput().trim();
if (text.length() == 0) {
tp.setStringList(null);
} else {
text = text.replace(';', ',');
text = text.replace(' ', ',');
text = text.replaceAll("[,]+", ",");
String[] bits = text.split(",");
List<String> vals = new ArrayList<>();
for (String bit : bits) {
bit = bit.trim();
if (bit.length() > 0) {
vals.add(bit);
}
}
if (vals.size() == 0) {
tp.setStringList(null);
} else {
tp.setStringList(vals.toArray(new String[vals.size()]));
}
}
} catch (Throwable e) {
Debug.out(e);
}
}
});
}
});
}
} else if (tp.getType() == TagFeatureProperties.PT_BOOLEAN) {
final MenuItem set_item = new MenuItem(props_menu, SWT.CHECK);
set_item.setText(tp.getName(true));
Boolean val = tp.getBoolean();
set_item.setSelection(val != null && val);
set_item.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
tp.setBoolean(set_item.getSelection());
}
});
} else {
Debug.out("Unknown property");
}
}
}
use of com.biglybt.pif.ui.UIInputReceiver in project BiglyBT by BiglySoftware.
the class ViewUtils method getManualSpeedValue.
public static void getManualSpeedValue(final Shell shell, boolean for_download, final manualSpeedValueListener l) {
String kbps_str = MessageText.getString("MyTorrentsView.dialog.setNumber.inKbps", new String[] { DisplayFormatters.getRateUnit(DisplayFormatters.UNIT_KB) });
String set_num_str = MessageText.getString("MyTorrentsView.dialog.setNumber." + ((for_download) ? "download" : "upload"));
final SimpleTextEntryWindow entryWindow = new SimpleTextEntryWindow();
entryWindow.initTexts("MyTorrentsView.dialog.setSpeed.title", new String[] { set_num_str }, "MyTorrentsView.dialog.setNumber.text", new String[] { kbps_str, set_num_str });
entryWindow.prompt(new UIInputReceiverListener() {
@Override
public void UIInputReceiverClosed(UIInputReceiver receiver) {
if (!receiver.hasSubmittedInput()) {
l.manualSpeedValueResult(-1);
return;
}
String sReturn = receiver.getSubmittedInput();
if (sReturn == null) {
l.manualSpeedValueResult(-1);
return;
}
try {
int result = (int) (Double.valueOf(sReturn).doubleValue() * DisplayFormatters.getKinB());
if (DisplayFormatters.isRateUsingBits()) {
result /= 8;
}
if (result <= 0) {
l.error("non-positive number entered");
return;
}
l.manualSpeedValueResult(result);
} catch (NumberFormatException er) {
MessageBox mb = new MessageBox(shell, SWT.ICON_ERROR | SWT.OK);
mb.setText(MessageText.getString("MyTorrentsView.dialog.NumberError.title"));
mb.setMessage(MessageText.getString("MyTorrentsView.dialog.NumberError.text"));
mb.open();
l.manualSpeedValueResult(-1);
}
}
});
}
use of com.biglybt.pif.ui.UIInputReceiver in project BiglyBT by BiglySoftware.
the class BuddyPluginViewInstance method addBuddyTable.
private Comparator<BuddyPluginBuddy> addBuddyTable(Composite child1) {
buddy_table = new Table(child1, SWT.MULTI | SWT.BORDER | SWT.FULL_SELECTION | SWT.VIRTUAL);
final String[] headers = { "azbuddy.ui.table.name", "azbuddy.ui.table.online", "azbuddy.ui.table.lastseen", "azbuddy.ui.table.last_ygm", "azbuddy.ui.table.last_msg", "azbuddy.ui.table.loc_cat", "azbuddy.ui.table.rem_cat", "azbuddy.ui.table.read_cat", "azbuddy.ui.table.con", "azbuddy.ui.table.track", "azbuddy.ui.table.msg_in", "azbuddy.ui.table.msg_out", "azbuddy.ui.table.msg_queued", "label.bytesIn", "label.bytesOut", "azbuddy.ui.table.ss" };
int[] sizes = { 250, 100, 100, 100, 200, 100, 100, 100, 75, 75, 75, 75, 75, 75, 75, 40 };
int[] aligns = { SWT.LEFT, SWT.CENTER, SWT.CENTER, SWT.CENTER, SWT.CENTER, SWT.LEFT, SWT.LEFT, SWT.LEFT, SWT.LEFT, SWT.CENTER, SWT.CENTER, SWT.CENTER, SWT.CENTER, SWT.CENTER, SWT.CENTER, SWT.CENTER };
for (int i = 0; i < headers.length; i++) {
TableColumn tc = new TableColumn(buddy_table, aligns[i]);
tc.setWidth(Utils.adjustPXForDPI(sizes[i]));
Messages.setLanguageText(tc, headers[i]);
}
buddy_table.setHeaderVisible(true);
TableColumn[] columns = buddy_table.getColumns();
columns[0].setData(new Integer(FilterComparator.FIELD_NAME));
columns[1].setData(new Integer(FilterComparator.FIELD_ONLINE));
columns[2].setData(new Integer(FilterComparator.FIELD_LAST_SEEN));
columns[3].setData(new Integer(FilterComparator.FIELD_YGM));
columns[4].setData(new Integer(FilterComparator.FIELD_LAST_MSG));
columns[5].setData(new Integer(FilterComparator.FIELD_LOC_CAT));
columns[6].setData(new Integer(FilterComparator.FIELD_REM_CAT));
columns[7].setData(new Integer(FilterComparator.FIELD_READ_CAT));
columns[8].setData(new Integer(FilterComparator.FIELD_CON));
columns[9].setData(new Integer(FilterComparator.FIELD_TRACK));
columns[10].setData(new Integer(FilterComparator.FIELD_MSG_IN));
columns[11].setData(new Integer(FilterComparator.FIELD_MSG_OUT));
columns[12].setData(new Integer(FilterComparator.FIELD_QUEUED));
columns[13].setData(new Integer(FilterComparator.FIELD_BYTES_IN));
columns[14].setData(new Integer(FilterComparator.FIELD_BYTES_OUT));
columns[15].setData(new Integer(FilterComparator.FIELD_SS));
final FilterComparator comparator = new FilterComparator();
Listener sort_listener = new Listener() {
@Override
public void handleEvent(Event e) {
TableColumn tc = (TableColumn) e.widget;
int field = ((Integer) tc.getData()).intValue();
comparator.setField(field);
Collections.sort(buddies, comparator);
updateTable();
}
};
for (int i = 0; i < columns.length; i++) {
columns[i].addListener(SWT.Selection, sort_listener);
}
GridData gridData = new GridData(GridData.FILL_BOTH);
gridData.heightHint = buddy_table.getHeaderHeight() * 3;
Utils.setLayoutData(buddy_table, gridData);
buddy_table.addListener(SWT.SetData, new Listener() {
@Override
public void handleEvent(Event event) {
TableItem item = (TableItem) event.item;
int index = buddy_table.indexOf(item);
if (index < 0 || index >= buddies.size()) {
return;
}
BuddyPluginBuddy buddy = (BuddyPluginBuddy) buddies.get(index);
item.setText(0, buddy.getName());
int os;
if (buddy.isOnline(false)) {
os = buddy.getOnlineStatus();
} else {
os = BuddyPlugin.STATUS_APPEAR_OFFLINE;
}
if (os == BuddyPlugin.STATUS_APPEAR_OFFLINE) {
item.setText(1, "");
} else {
item.setText(1, plugin.getOnlineStatus(os));
}
long lo = buddy.getLastTimeOnline();
item.setText(2, lo == 0 ? "" : new SimpleDateFormat().format(new Date(lo)));
long last_ygm = buddy.getLastMessagePending();
item.setText(3, last_ygm == 0 ? "" : new SimpleDateFormat().format(new Date(last_ygm)));
String lm = buddy.getLastMessageReceived();
item.setText(4, lm == null ? "" : lm);
String loc_cat = buddy.getLocalAuthorisedRSSTagsOrCategoriesAsString();
if (loc_cat == null) {
loc_cat = "";
}
item.setText(5, "" + loc_cat);
String rem_cat = buddy.getRemoteAuthorisedRSSTagsOrCategoriesAsString();
if (rem_cat == null) {
rem_cat = "";
}
item.setText(6, "" + rem_cat);
String read_cat = buddy.getLocalReadTagsOrCategoriesAsString();
if (read_cat == null) {
read_cat = "";
}
item.setText(7, "" + read_cat);
item.setText(8, "" + buddy.getConnectionsString());
item.setText(9, "" + tracker.getTrackingStatus(buddy));
String in_frag = buddy.getMessageInFragmentDetails();
item.setText(10, "" + buddy.getMessageInCount() + (in_frag.length() == 0 ? "" : ("+" + in_frag)));
item.setText(11, "" + buddy.getMessageOutCount());
item.setText(12, "" + buddy.getMessageHandler().getMessageCount());
item.setText(13, "" + DisplayFormatters.formatByteCountToKiBEtc(buddy.getBytesInCount()));
item.setText(14, "" + DisplayFormatters.formatByteCountToKiBEtc(buddy.getBytesOutCount()));
item.setText(15, "" + buddy.getSubsystem() + " v" + buddy.getVersion());
item.setData(buddy);
}
});
final Listener tt_label_listener = new Listener() {
@Override
public void handleEvent(Event event) {
Label label = (Label) event.widget;
Shell shell = label.getShell();
switch(event.type) {
case SWT.MouseDown:
Event e = new Event();
e.item = (TableItem) label.getData("_TABLEITEM");
buddy_table.setSelection(new TableItem[] { (TableItem) e.item });
buddy_table.notifyListeners(SWT.Selection, e);
// fall through
case SWT.MouseExit:
shell.dispose();
break;
}
}
};
Listener tt_table_listener = new Listener() {
private Shell tip = null;
private Label label = null;
@Override
public void handleEvent(Event event) {
switch(event.type) {
case SWT.Dispose:
case SWT.KeyDown:
case SWT.MouseMove:
{
if (tip == null)
break;
tip.dispose();
tip = null;
label = null;
break;
}
case SWT.MouseHover:
{
Point mouse_position = new Point(event.x, event.y);
TableItem item = buddy_table.getItem(mouse_position);
if (item != null) {
if (tip != null && !tip.isDisposed()) {
tip.dispose();
tip = null;
}
int index = buddy_table.indexOf(item);
if (index < 0 || index >= buddies.size()) {
return;
}
BuddyPluginBuddy buddy = (BuddyPluginBuddy) buddies.get(index);
int item_index = 0;
for (int i = 0; i < headers.length; i++) {
Rectangle bounds = item.getBounds(i);
if (bounds.contains(mouse_position)) {
item_index = i;
break;
}
}
if (item_index != 0) {
return;
}
tip = new Shell(buddy_table.getShell(), SWT.ON_TOP | SWT.TOOL);
tip.setLayout(new FillLayout());
label = new Label(tip, SWT.NONE);
label.setForeground(buddy_table.getDisplay().getSystemColor(SWT.COLOR_INFO_FOREGROUND));
label.setBackground(buddy_table.getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND));
label.setData("_TABLEITEM", item);
label.setText(getToolTip(buddy));
label.addListener(SWT.MouseExit, tt_label_listener);
label.addListener(SWT.MouseDown, tt_label_listener);
Point size = tip.computeSize(SWT.DEFAULT, SWT.DEFAULT);
Rectangle rect = item.getBounds(item_index);
Point pt = buddy_table.toDisplay(rect.x, rect.y);
tip.setBounds(pt.x, pt.y, size.x, size.y);
tip.setVisible(true);
}
}
}
}
protected String getToolTip(BuddyPluginBuddy buddy) {
List<InetAddress> addresses = buddy.getAdjustedIPs();
InetAddress ip = buddy.getIP();
InetAddress adj = buddy.getAdjustedIP();
String str = "";
if (ip == null) {
str = "<none>";
} else if (ip == adj) {
str = ip.getHostAddress();
} else {
str = ip.getHostAddress() + "{";
for (int i = 0; i < addresses.size(); i++) {
str += (i == 0 ? "" : "/") + addresses.get(i).getHostAddress();
}
str += "}";
}
return ("ip=" + str + ",tcp=" + buddy.getTCPPort() + ",udp=" + buddy.getUDPPort());
}
};
buddy_table.addListener(SWT.Dispose, tt_table_listener);
buddy_table.addListener(SWT.KeyDown, tt_table_listener);
buddy_table.addListener(SWT.MouseMove, tt_table_listener);
buddy_table.addListener(SWT.MouseHover, tt_table_listener);
buddy_table.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent event) {
if (event.stateMask == SWT.MOD1) {
int key = event.character;
if (key <= 26 && key > 0) {
key += 'a' - 1;
}
if (key == 'a') {
buddy_table.selectAll();
event.doit = false;
}
} else if (event.stateMask == 0 && event.keyCode == SWT.DEL) {
TableItem[] selection = buddy_table.getSelection();
String str = "";
for (int i = 0; i < selection.length; i++) {
BuddyPluginBuddy buddy = (BuddyPluginBuddy) selection[i].getData();
str += (str.isEmpty() ? "" : ", ") + buddy.getName();
}
MessageBoxShell mb = new MessageBoxShell(MessageText.getString("message.confirm.delete.title"), MessageText.getString("message.confirm.delete.text", new String[] { str }), new String[] { MessageText.getString("Button.yes"), MessageText.getString("Button.no") }, 1);
mb.open(new UserPrompterResultListener() {
@Override
public void prompterClosed(int result) {
if (result == 0) {
for (int i = 0; i < selection.length; i++) {
BuddyPluginBuddy buddy = (BuddyPluginBuddy) selection[i].getData();
buddy.remove();
}
buddy_table.setSelection(new int[0]);
}
}
});
event.doit = false;
}
}
});
final Menu menu = new Menu(buddy_table);
final MenuItem remove_item = new MenuItem(menu, SWT.PUSH);
remove_item.setText(lu.getLocalisedMessageText("azbuddy.ui.menu.remove"));
remove_item.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
TableItem[] selection = buddy_table.getSelection();
for (int i = 0; i < selection.length; i++) {
BuddyPluginBuddy buddy = (BuddyPluginBuddy) selection[i].getData();
buddy.remove();
}
}
});
// get public key
final MenuItem get_pk_item = new MenuItem(menu, SWT.PUSH);
get_pk_item.setText(lu.getLocalisedMessageText("azbuddy.ui.menu.copypk"));
get_pk_item.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
TableItem[] selection = buddy_table.getSelection();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < selection.length; i++) {
BuddyPluginBuddy buddy = (BuddyPluginBuddy) selection[i].getData();
sb.append(buddy.getPublicKey()).append("\r\n");
}
if (sb.length() > 0) {
writeToClipboard(sb.toString());
}
}
});
// disconnect message
final MenuItem disconnect_msg_item;
if (Constants.isCVSVersion()) {
disconnect_msg_item = new MenuItem(menu, SWT.PUSH);
disconnect_msg_item.setText(lu.getLocalisedMessageText("azbuddy.ui.menu.disconnect"));
disconnect_msg_item.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
TableItem[] selection = buddy_table.getSelection();
for (int i = 0; i < selection.length; i++) {
BuddyPluginBuddy buddy = (BuddyPluginBuddy) selection[i].getData();
buddy.disconnect();
}
}
});
} else {
disconnect_msg_item = null;
}
// send message
final MenuItem send_msg_item = new MenuItem(menu, SWT.PUSH);
send_msg_item.setText(lu.getLocalisedMessageText("azbuddy.ui.menu.send"));
send_msg_item.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
final TableItem[] selection = buddy_table.getSelection();
UIInputReceiver prompter = ui_instance.getInputReceiver();
prompter.setLocalisedTitle(lu.getLocalisedMessageText("azbuddy.ui.menu.send"));
prompter.setLocalisedMessage(lu.getLocalisedMessageText("azbuddy.ui.menu.send_msg"));
try {
prompter.prompt(new UIInputReceiverListener() {
@Override
public void UIInputReceiverClosed(UIInputReceiver prompter) {
String text = prompter.getSubmittedInput();
if (text != null) {
for (int i = 0; i < selection.length; i++) {
BuddyPluginBuddy buddy = (BuddyPluginBuddy) selection[i].getData();
plugin.getAZ2Handler().sendAZ2Message(buddy, text);
}
}
}
});
} catch (Throwable e) {
}
}
});
// chat
final MenuItem chat_item = new MenuItem(menu, SWT.PUSH);
chat_item.setText(lu.getLocalisedMessageText("azbuddy.ui.menu.chat"));
chat_item.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
TableItem[] selection = buddy_table.getSelection();
BuddyPluginBuddy[] buddies = new BuddyPluginBuddy[selection.length];
for (int i = 0; i < selection.length; i++) {
BuddyPluginBuddy buddy = (BuddyPluginBuddy) selection[i].getData();
buddies[i] = buddy;
}
plugin.getAZ2Handler().createChat(buddies);
}
});
// ping
final MenuItem ping_item = new MenuItem(menu, SWT.PUSH);
ping_item.setText(lu.getLocalisedMessageText("azbuddy.ui.menu.ping"));
ping_item.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
TableItem[] selection = buddy_table.getSelection();
for (int i = 0; i < selection.length; i++) {
BuddyPluginBuddy buddy = (BuddyPluginBuddy) selection[i].getData();
try {
buddy.ping();
} catch (Throwable e) {
print("Ping failed", e);
}
}
}
});
// ygm
final MenuItem ygm_item = new MenuItem(menu, SWT.PUSH);
ygm_item.setText(lu.getLocalisedMessageText("azbuddy.ui.menu.ygm"));
ygm_item.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
TableItem[] selection = buddy_table.getSelection();
for (int i = 0; i < selection.length; i++) {
BuddyPluginBuddy buddy = (BuddyPluginBuddy) selection[i].getData();
try {
buddy.setMessagePending();
} catch (Throwable e) {
print("YGM failed", e);
}
}
}
});
// encrypt
final MenuItem encrypt_item = new MenuItem(menu, SWT.PUSH);
encrypt_item.setText(lu.getLocalisedMessageText("azbuddy.ui.menu.enc"));
encrypt_item.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
TableItem[] selection = buddy_table.getSelection();
String str = readFromClipboard();
if (str != null) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < selection.length; i++) {
BuddyPluginBuddy buddy = (BuddyPluginBuddy) selection[i].getData();
try {
byte[] contents = str.getBytes("UTF-8");
BuddyPlugin.cryptoResult result = buddy.encrypt(contents);
sb.append("key: ");
sb.append(plugin.getPublicKey());
sb.append("\r\n");
sb.append("hash: ");
sb.append(Base32.encode(result.getChallenge()));
sb.append("\r\n");
sb.append("payload: ");
sb.append(Base32.encode(result.getPayload()));
sb.append("\r\n\r\n");
} catch (Throwable e) {
print("YGM failed", e);
}
}
writeToClipboard(sb.toString());
}
}
});
// decrypt
final MenuItem decrypt_item = new MenuItem(menu, SWT.PUSH);
decrypt_item.setText(lu.getLocalisedMessageText("azbuddy.ui.menu.dec"));
decrypt_item.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
String str = readFromClipboard();
if (str != null) {
String[] bits = str.split("\n");
StringBuilder sb = new StringBuilder();
BuddyPluginBuddy buddy = null;
byte[] hash = null;
for (int i = 0; i < bits.length; i++) {
String bit = bits[i].trim();
if (bit.length() > 0) {
int pos = bit.indexOf(':');
if (pos == -1) {
continue;
}
String lhs = bit.substring(0, pos).trim();
String rhs = bit.substring(pos + 1).trim();
if (lhs.equals("key")) {
buddy = plugin.getBuddyFromPublicKey(rhs);
} else if (lhs.equals("hash")) {
hash = Base32.decode(rhs);
} else if (lhs.equals("payload")) {
byte[] payload = Base32.decode(rhs);
if (buddy != null) {
try {
BuddyPlugin.cryptoResult result = buddy.decrypt(payload);
byte[] sha1 = new SHA1Simple().calculateHash(result.getChallenge());
sb.append("key: ");
sb.append(buddy.getPublicKey());
sb.append("\r\n");
sb.append("hash_ok: ").append(Arrays.equals(hash, sha1));
sb.append("\r\n");
sb.append("payload: ");
sb.append(new String(result.getPayload(), "UTF-8"));
sb.append("\r\n\r\n");
} catch (Throwable e) {
print("decrypt failed", e);
}
}
}
}
}
if (sb.length() > 0) {
writeToClipboard(sb.toString());
}
}
}
});
// sign
final MenuItem sign_item = new MenuItem(menu, SWT.PUSH);
sign_item.setText(lu.getLocalisedMessageText("azbuddy.ui.menu.sign"));
sign_item.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
String str = readFromClipboard();
if (str != null) {
StringBuilder sb = new StringBuilder();
try {
sb.append("key: ");
sb.append(plugin.getPublicKey());
sb.append("\r\n");
byte[] payload = str.getBytes("UTF-8");
sb.append("data: ");
sb.append(Base32.encode(payload));
sb.append("\r\n");
byte[] sig = plugin.sign(payload);
sb.append("sig: ");
sb.append(Base32.encode(sig));
sb.append("\r\n");
} catch (Throwable e) {
print("sign failed", e);
}
if (sb.length() > 0) {
writeToClipboard(sb.toString());
}
}
}
});
// verify
final MenuItem verify_item = new MenuItem(menu, SWT.PUSH);
verify_item.setText(lu.getLocalisedMessageText("azbuddy.ui.menu.verify"));
verify_item.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
String str = readFromClipboard();
if (str != null) {
String[] bits = str.split("\n");
StringBuilder sb = new StringBuilder();
String pk = null;
byte[] data = null;
for (int i = 0; i < bits.length; i++) {
String bit = bits[i].trim();
if (bit.length() > 0) {
int pos = bit.indexOf(':');
if (pos == -1) {
continue;
}
String lhs = bit.substring(0, pos).trim();
String rhs = bit.substring(pos + 1).trim();
if (lhs.equals("key")) {
pk = rhs;
} else if (lhs.equals("data")) {
data = Base32.decode(rhs);
} else if (lhs.equals("sig")) {
byte[] sig = Base32.decode(rhs);
if (pk != null && data != null) {
try {
sb.append("key: ");
sb.append(pk);
sb.append("\r\n");
boolean ok = plugin.verify(pk, data, sig);
sb.append("sig_ok: ").append(ok);
sb.append("\r\n");
sb.append("data: ");
sb.append(new String(data, "UTF-8"));
sb.append("\r\n\r\n");
} catch (Throwable e) {
print("decrypt failed", e);
}
}
}
}
}
if (sb.length() > 0) {
writeToClipboard(sb.toString());
}
}
}
});
// cats
Menu cat_menu = new Menu(menu.getShell(), SWT.DROP_DOWN);
MenuItem cat_item = new MenuItem(menu, SWT.CASCADE);
Messages.setLanguageText(cat_item, "azbuddy.ui.menu.cat");
cat_item.setMenu(cat_menu);
// cats - share
final MenuItem cat_share_item = new MenuItem(cat_menu, SWT.PUSH);
cat_share_item.setText(lu.getLocalisedMessageText("azbuddy.ui.menu.cat.share"));
cat_share_item.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
UIInputReceiver prompter = ui_instance.getInputReceiver();
prompter.setLocalisedTitle(lu.getLocalisedMessageText("azbuddy.ui.menu.cat.set"));
prompter.setLocalisedMessage(lu.getLocalisedMessageText("azbuddy.ui.menu.cat.set_msg"));
prompter.prompt(new UIInputReceiverListener() {
@Override
public void UIInputReceiverClosed(UIInputReceiver prompter) {
String cats = prompter.getSubmittedInput();
if (cats != null) {
cats = cats.trim();
if (cats.equalsIgnoreCase("None")) {
cats = "";
}
TableItem[] selection = buddy_table.getSelection();
for (int i = 0; i < selection.length; i++) {
BuddyPluginBuddy buddy = (BuddyPluginBuddy) selection[i].getData();
buddy.setLocalAuthorisedRSSTagsOrCategories(cats);
}
}
}
});
}
});
// cats - subscribe
final Menu cat_subs_menu = new Menu(cat_menu.getShell(), SWT.DROP_DOWN);
final MenuItem cat_subs_item = new MenuItem(cat_menu, SWT.CASCADE);
Messages.setLanguageText(cat_subs_item, "azbuddy.ui.menu.cat_subs");
cat_subs_item.setMenu(cat_subs_menu);
cat_subs_menu.addMenuListener(new MenuListener() {
@Override
public void menuShown(MenuEvent arg0) {
MenuItem[] items = cat_subs_menu.getItems();
for (int i = 0; i < items.length; i++) {
items[i].dispose();
}
final TableItem[] selection = buddy_table.getSelection();
Set<String> avail_cats = new TreeSet<>();
for (int i = 0; i < selection.length; i++) {
BuddyPluginBuddy buddy = (BuddyPluginBuddy) selection[i].getData();
Set<String> cats = buddy.getRemoteAuthorisedRSSTagsOrCategories();
if (cats != null) {
avail_cats.addAll(cats);
}
}
for (final String cat : avail_cats) {
final MenuItem subs_item = new MenuItem(cat_subs_menu, SWT.PUSH);
subs_item.setText(cat);
subs_item.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
for (int i = 0; i < selection.length; i++) {
BuddyPluginBuddy buddy = (BuddyPluginBuddy) selection[i].getData();
if (buddy.isRemoteRSSTagOrCategoryAuthorised(cat)) {
try {
buddy.subscribeToCategory(cat);
} catch (Throwable e) {
print("Failed", e);
}
}
}
}
});
}
}
@Override
public void menuHidden(MenuEvent arg0) {
}
});
// done with menus
buddy_table.setMenu(menu);
menu.addMenuListener(new MenuListener() {
@Override
public void menuShown(MenuEvent arg0) {
boolean available = plugin.isAvailable();
TableItem[] selection = buddy_table.getSelection();
remove_item.setEnabled(selection.length > 0);
get_pk_item.setEnabled(available && selection.length > 0);
if (disconnect_msg_item != null) {
disconnect_msg_item.setEnabled(selection.length > 0);
}
send_msg_item.setEnabled(available && selection.length > 0);
chat_item.setEnabled(available && selection.length > 0);
ping_item.setEnabled(available && selection.length > 0);
ygm_item.setEnabled(available && selection.length > 0);
encrypt_item.setEnabled(selection.length > 0);
decrypt_item.setEnabled(true);
sign_item.setEnabled(true);
verify_item.setEnabled(true);
cat_item.setEnabled(selection.length > 0);
}
@Override
public void menuHidden(MenuEvent arg0) {
}
});
return (comparator);
}
use of com.biglybt.pif.ui.UIInputReceiver in project BiglyBT by BiglySoftware.
the class BuddyPluginView method buildMenu.
private void buildMenu(final Set<ChatInstance> current_instances) {
if (menu_items.size() == 0 || !menu_latest_instances.equals(current_instances)) {
for (MenuItem mi : menu_items) {
mi.remove();
}
menu_items.clear();
final MenuManager menu_manager = plugin.getPluginInterface().getUIManager().getMenuManager();
MenuContext mc = beta_status.getMenuContext();
for (final ChatInstance chat : sortChats(current_instances)) {
String short_name = chat.getShortName();
MenuItem mi = menu_manager.addMenuItem(mc, "!" + short_name + "!");
mi.addListener(new MenuItemListener() {
@Override
public void selected(MenuItem menu, Object target) {
try {
openChat(chat.getClone());
} catch (Throwable e) {
Debug.out(e);
}
}
});
menu_items.add(mi);
}
boolean need_sep = true;
if (current_instances.size() > 1) {
MenuItem mi = menu_manager.addMenuItem(mc, "sep1");
need_sep = false;
mi.setStyle(MenuItem.STYLE_SEPARATOR);
menu_items.add(mi);
mi = menu_manager.addMenuItem(mc, "label.open.all");
mi.addListener(new MenuItemListener() {
@Override
public void selected(MenuItem menu, Object target) {
for (ChatInstance chat : current_instances) {
try {
openChat(chat.getClone());
} catch (Throwable e) {
Debug.out(e);
}
}
}
});
menu_items.add(mi);
}
if (need_sep) {
MenuItem mi = menu_manager.addMenuItem(mc, "sep2");
mi.setStyle(MenuItem.STYLE_SEPARATOR);
menu_items.add(mi);
}
// create channel
MenuItem mi = menu_manager.addMenuItem(mc, "chat.view.create.chat");
mi.setStyle(MenuItem.STYLE_MENU);
menu_items.add(mi);
mi.addFillListener(new com.biglybt.pif.ui.menus.MenuItemFillListener() {
@Override
public void menuWillBeShown(MenuItem menu, Object data) {
menu.removeAllChildItems();
MenuItem mi = menu_manager.addMenuItem(menu, "!" + MessageText.getString("label.public") + "...!");
mi.addListener(new MenuItemListener() {
@Override
public void selected(MenuItem menu, Object target) {
SimpleTextEntryWindow entryWindow = new SimpleTextEntryWindow("chat.view.enter.key.title", "chat.view.enter.key.msg");
entryWindow.prompt(new UIInputReceiverListener() {
@Override
public void UIInputReceiverClosed(UIInputReceiver receiver) {
if (!receiver.hasSubmittedInput()) {
return;
}
String key = receiver.getSubmittedInput().trim();
BuddyPluginUtils.createBetaChat(AENetworkClassifier.AT_PUBLIC, key, null);
}
});
}
});
mi = menu_manager.addMenuItem(menu, "!" + MessageText.getString("label.anon") + "...!");
mi.addListener(new MenuItemListener() {
@Override
public void selected(MenuItem menu, Object target) {
if (plugin.getBeta().isI2PAvailable()) {
SimpleTextEntryWindow entryWindow = new SimpleTextEntryWindow("chat.view.enter.key.title", "chat.view.enter.key.msg");
entryWindow.prompt(new UIInputReceiverListener() {
@Override
public void UIInputReceiverClosed(UIInputReceiver receiver) {
if (!receiver.hasSubmittedInput()) {
return;
}
String key = receiver.getSubmittedInput().trim();
BuddyPluginUtils.createBetaChat(AENetworkClassifier.AT_I2P, key, null);
}
});
} else {
I2PHelpers.installI2PHelper(null, null, null);
}
}
});
if (I2PHelpers.isInstallingI2PHelper()) {
mi.setEnabled(false);
mi.setText(mi.getText() + " (" + MessageText.getString("PeersView.state.pending") + ")");
}
}
});
// chat overview
mi = menu_manager.addMenuItem(mc, "!" + MessageText.getString("chats.view.heading") + "...!");
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_CHAT);
}
}
});
menu_items.add(mi);
mi = menu_manager.addMenuItem(mc, "sep3");
mi.setStyle(MenuItem.STYLE_SEPARATOR);
menu_items.add(mi);
// options
mi = menu_manager.addMenuItem(mc, "MainWindow.menu.view.configuration");
mi.addListener(new MenuItemListener() {
@Override
public void selected(MenuItem menu, Object target) {
ui_instance.openView(UISWTInstance.VIEW_MAIN, VIEW_ID, null);
}
});
menu_items.add(mi);
menu_latest_instances = current_instances;
}
}
Aggregations