use of com.biglybt.core.tag.TagFeatureProperties.TagProperty in project BiglyBT by BiglySoftware.
the class TagUIUtils method createTFProperitesMenuItems.
private static void createTFProperitesMenuItems(Menu menu, Tag tag) {
TagFeatureProperties props = (TagFeatureProperties) tag;
TagProperty[] tps = props.getSupportedProperties();
if (tps.length > 0) {
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);
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, new Listener() {
@Override
public void handleEvent(Event 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;
if (val == null || val.length == 0) {
def_str = "";
} else {
def_str = "";
for (String v : val) {
def_str += (def_str.length() == 0 ? "" : ", ") + v;
}
}
MenuItem set_item = new MenuItem(props_menu, SWT.PUSH);
set_item.setText(tp.getName(true) + (def_str.length() == 0 ? "" : (" (" + def_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.core.tag.TagFeatureProperties.TagProperty in project BiglyBT by BiglySoftware.
the class TagUIUtils method addShareWithFriendsMenuItems.
private static void addShareWithFriendsMenuItems(Menu menu, Tag tag, TagType tag_type) {
PluginInterface bpi = PluginInitializer.getDefaultInterface().getPluginManager().getPluginInterfaceByClass(BuddyPlugin.class);
if (tag_type.getTagType() == TagType.TT_DOWNLOAD_MANUAL && bpi != null) {
TagFeatureProperties props = (TagFeatureProperties) tag;
TagProperty tp = props.getProperty(TagFeatureProperties.PR_UNTAGGED);
Boolean is_ut = tp == null ? null : tp.getBoolean();
if (is_ut == null || !is_ut) {
final BuddyPlugin buddy_plugin = (BuddyPlugin) bpi.getPlugin();
if (buddy_plugin.isClassicEnabled()) {
final Menu share_menu = new Menu(menu.getShell(), SWT.DROP_DOWN);
final MenuItem share_item = new MenuItem(menu, SWT.CASCADE);
Messages.setLanguageText(share_item, "azbuddy.ui.menu.cat.share");
// nasty hack to fix nastyness on windows
share_item.setText(share_item.getText() + " ");
share_item.setMenu(share_menu);
List<BuddyPluginBuddy> buddies = buddy_plugin.getBuddies();
if (buddies.size() == 0) {
final MenuItem item = new MenuItem(share_menu, SWT.CHECK);
item.setText(MessageText.getString("general.add.friends"));
item.setEnabled(false);
} else {
final String tag_name = tag.getTagName(true);
final boolean is_public = buddy_plugin.isPublicTagOrCategory(tag_name);
final MenuItem itemPubCat = new MenuItem(share_menu, SWT.CHECK);
Messages.setLanguageText(itemPubCat, "general.all.friends");
itemPubCat.setSelection(is_public);
itemPubCat.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
if (is_public) {
buddy_plugin.removePublicTagOrCategory(tag_name);
} else {
buddy_plugin.addPublicTagOrCategory(tag_name);
}
}
});
new MenuItem(share_menu, SWT.SEPARATOR);
for (final BuddyPluginBuddy buddy : buddies) {
if (buddy.getNickName() == null) {
continue;
}
final boolean auth = buddy.isLocalRSSTagOrCategoryAuthorised(tag_name);
final MenuItem itemShare = new MenuItem(share_menu, SWT.CHECK);
itemShare.setText(buddy.getName());
itemShare.setSelection(auth || is_public);
if (is_public) {
itemShare.setEnabled(false);
}
itemShare.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
if (auth) {
buddy.removeLocalAuthorisedRSSTagOrCategory(tag_name);
} else {
buddy.addLocalAuthorisedRSSTagOrCategory(tag_name);
}
}
});
}
}
}
}
}
}
use of com.biglybt.core.tag.TagFeatureProperties.TagProperty in project BiglyBT by BiglySoftware.
the class TagUIUtils method createNonAutoMenuItems.
private static void createNonAutoMenuItems(final Menu menu, final Tag tag, final TagType tag_type, Menu[] menuShowHide) {
if (tag_type.hasTagTypeFeature(TagFeature.TF_PROPERTIES)) {
TagFeatureProperties props = (TagFeatureProperties) tag;
boolean has_ut = props.getProperty(TagFeatureProperties.PR_UNTAGGED) != null;
if (has_ut) {
has_ut = false;
for (Tag t : tag_type.getTags()) {
props = (TagFeatureProperties) t;
TagProperty prop = props.getProperty(TagFeatureProperties.PR_UNTAGGED);
if (prop != null) {
Boolean b = prop.getBoolean();
if (b != null && b) {
has_ut = true;
break;
}
}
}
if (!has_ut) {
if (menuShowHide[0] == null) {
menuShowHide[0] = new Menu(menu.getShell(), SWT.DROP_DOWN);
MenuItem showhideitem = new MenuItem(menu, SWT.CASCADE);
showhideitem.setText(MessageText.getString("label.showhide.tag"));
showhideitem.setMenu(menuShowHide[0]);
} else {
new MenuItem(menuShowHide[0], SWT.SEPARATOR);
}
MenuItem showAll = new MenuItem(menuShowHide[0], SWT.PUSH);
Messages.setLanguageText(showAll, "label.untagged");
showAll.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
try {
String tag_name = MessageText.getString("label.untagged");
Tag ut_tag = tag_type.getTag(tag_name, true);
if (ut_tag == null) {
ut_tag = tag_type.createTag(tag_name, true);
}
TagFeatureProperties tp = (TagFeatureProperties) ut_tag;
tp.getProperty(TagFeatureProperties.PR_UNTAGGED).setBoolean(true);
} catch (TagException e) {
Debug.out(e);
}
}
});
}
}
}
/*
MenuItem item_create = new MenuItem( menu, SWT.PUSH);
Messages.setLanguageText(item_create, "label.add.tag");
item_create.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event event) {
createManualTag(null);
}
});
*/
/* Seldom Used: Color can be set in Tags Overview
MenuItem itemSetColor = new MenuItem(menu, SWT.PUSH);
itemSetColor.setText( MessageText.getString( "label.color") + "..." );
itemSetColor.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event event) {
int[] existing = tag.getColor();
RGB e_rg = existing==null?null:new RGB(existing[0],existing[1],existing[2]);
RGB rgb = Utils.showColorDialog( menu.getShell(), e_rg );
if ( rgb != null ){
tag.setColor( new int[]{ rgb.red, rgb.green, rgb.blue });
}
}
});
*/
MenuItem itemGroup = new MenuItem(menu, SWT.PUSH);
Messages.setLanguageText(itemGroup, "MyTorrentsView.menu.group");
itemGroup.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
SimpleTextEntryWindow entryWindow = new SimpleTextEntryWindow("TagGroupWindow.title", "TagGroupWindow.message");
String group = tag.getGroup();
if (group == null) {
group = "";
}
entryWindow.setPreenteredText(group, false);
entryWindow.selectPreenteredText(true);
entryWindow.prompt(new UIInputReceiverListener() {
@Override
public void UIInputReceiverClosed(UIInputReceiver entryWindow) {
if (!entryWindow.hasSubmittedInput()) {
return;
}
try {
String group = entryWindow.getSubmittedInput().trim();
if (group.length() == 0) {
group = null;
}
tag.setGroup(group);
} catch (Throwable e) {
Debug.out(e);
}
}
});
}
});
MenuItem itemDelete = new MenuItem(menu, SWT.PUSH);
Utils.setMenuItemImage(itemDelete, "delete");
Messages.setLanguageText(itemDelete, "FileItem.delete");
itemDelete.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
tag.removeTag();
}
});
}
use of com.biglybt.core.tag.TagFeatureProperties.TagProperty in project BiglyBT by BiglySoftware.
the class TagPropertyConstraintHandler method tagAdded.
public void tagAdded(Tag tag) {
TagFeatureProperties tfp = (TagFeatureProperties) tag;
TagProperty prop = tfp.getProperty(TagFeatureProperties.PR_CONSTRAINT);
if (prop != null) {
prop.addListener(new TagPropertyListener() {
@Override
public void propertyChanged(TagProperty property) {
handleProperty(property);
}
@Override
public void propertySync(TagProperty property) {
}
});
handleProperty(prop);
}
tag.addTagListener(new TagListener() {
@Override
public void taggableSync(Tag tag) {
}
@Override
public void taggableRemoved(Tag tag, Taggable tagged) {
apply((DownloadManager) tagged, tag, true);
}
@Override
public void taggableAdded(Tag tag, Taggable tagged) {
apply((DownloadManager) tagged, tag, true);
}
}, false);
}
use of com.biglybt.core.tag.TagFeatureProperties.TagProperty in project BiglyBT by BiglySoftware.
the class TagPropertyTrackerTemplateHandler method taggableAdded.
@Override
public void taggableAdded(Tag tag, Taggable tagged) {
TagFeatureProperties tfp = (TagFeatureProperties) tag;
TagProperty prop = tfp.getProperty(TagFeatureProperties.PR_TRACKER_TEMPLATES);
if (prop != null) {
String[] bits = getPropertyBits(prop);
if (bits == null) {
return;
}
Set<Taggable> taggables = new HashSet<>();
taggables.add(tagged);
handleStuff(bits, taggables);
}
}
Aggregations