use of com.biglybt.ui.swt.views.utils.TagButtonsUI in project BiglyBT by BiglySoftware.
the class TaggingView 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);
sc.setLayoutData(gd);
} else if (parentLayout instanceof FormLayout) {
sc.setLayoutData(Utils.getFilledFormData());
}
cMainComposite = new Composite(sc, SWT.NONE);
sc.setContent(cMainComposite);
} else {
Utils.disposeComposite(cMainComposite, false);
}
cMainComposite.setLayout(new GridLayout(1, false));
TagManager tm = TagManagerFactory.getTagManager();
int[] tagTypesWanted = { TagType.TT_DOWNLOAD_MANUAL // TagType.TT_DOWNLOAD_CATEGORY
};
tagButtonsUI = new TagButtonsUI();
List<Tag> listAllTags = new ArrayList<>();
for (int tagType : tagTypesWanted) {
TagType tt = tm.getTagType(tagType);
List<Tag> tags = tt.getTags();
listAllTags.addAll(tags);
}
tagButtonsUI.buildTagGroup(listAllTags, cMainComposite, new TagButtonTrigger() {
@Override
public void tagButtonTriggered(Tag tag, boolean doTag) {
for (Taggable taggable : taggables) {
if (doTag) {
tag.addTaggable(taggable);
} else {
tag.removeTaggable(taggable);
}
swt_updateFields();
}
}
});
Button buttonAdd = new Button(cMainComposite, SWT.PUSH);
buttonAdd.setLayoutData(new GridData(SWT.CENTER, SWT.FILL, false, false));
Messages.setLanguageText(buttonAdd, "label.add.tag");
buttonAdd.addSelectionListener(new SelectionListener() {
@Override
public void widgetSelected(SelectionEvent e) {
TagUIUtils.createManualTag(new TagReturner() {
@Override
public void returnedTags(Tag[] tags) {
if (taggables == null) {
return;
}
for (Tag tag : tags) {
for (Taggable taggable : taggables) {
tag.addTaggable(taggable);
}
}
}
});
}
@Override
public void widgetDefaultSelected(SelectionEvent e) {
}
});
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();
Rectangle r = sc.getClientArea();
Point size = cMainComposite.computeSize(r.width, SWT.DEFAULT);
sc.setMinSize(size);
}
use of com.biglybt.ui.swt.views.utils.TagButtonsUI in project BiglyBT by BiglySoftware.
the class TagUIUtilsV3 method showTagSelectionDialog.
public static void showTagSelectionDialog(List<Tag> tags, List<Tag> selected_tags, boolean disable_auto, TagSelectionListener listener) {
final SkinnedDialog dialog = new SkinnedDialog("skin3_dlg_selecttags", "shell", SWT.DIALOG_TRIM | SWT.RESIZE);
SWTSkin skin = dialog.getSkin();
SWTSkinObject so = skin.getSkinObject("main-area");
if (so instanceof SWTSkinObjectContainer) {
Composite main = ((SWTSkinObjectContainer) so).getComposite();
main.setLayout(new GridLayout(1, true));
Composite comp = Utils.createScrolledComposite(main);
comp.setLayout(new FillLayout());
comp.setLayoutData(new GridData(GridData.FILL_BOTH));
TagButtonsUI tagButtonsUI = new TagButtonsUI();
tagButtonsUI.setDisableAuto(disable_auto);
tagButtonsUI.buildTagGroup(tags, comp, false, new TagCanvas.TagButtonTrigger() {
@Override
public Boolean tagSelectedOverride(Tag tag) {
return null;
}
@Override
public void tagButtonTriggered(TagPainter painter, int stateMask, boolean longPress) {
boolean doTag = !painter.isSelected();
painter.setSelected(doTag);
}
});
tagButtonsUI.setSelectedTags(selected_tags);
SWTSkinObject soButtonArea = skin.getSkinObject("bottom-area");
if (soButtonArea instanceof SWTSkinObjectContainer) {
StandardButtonsArea buttonsArea = new StandardButtonsArea() {
@Override
protected void clicked(int buttonValue) {
if (buttonValue == SWT.OK) {
listener.selected(tagButtonsUI.getSelectedTags());
}
dialog.close();
}
};
buttonsArea.setButtonIDs(new String[] { MessageText.getString("Button.ok"), MessageText.getString("Button.cancel") });
buttonsArea.setButtonVals(new Integer[] { SWT.OK, SWT.CANCEL });
buttonsArea.swt_createButtons(((SWTSkinObjectContainer) soButtonArea).getComposite());
}
}
dialog.open("skin3_dlg_selecttags", true);
}
use of com.biglybt.ui.swt.views.utils.TagButtonsUI in project BiglyBT by BiglySoftware.
the class TaggingView method rebuildComposite.
private void rebuildComposite() {
if (mainComposite == null || mainComposite.isDisposed()) {
if (parent == null || parent.isDisposed()) {
return;
}
mainComposite = new Composite(parent, SWT.NONE);
mainComposite.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
GridLayout layout = new GridLayout();
layout.marginHeight = layout.marginWidth = layout.verticalSpacing = 0;
mainComposite.setLayout(layout);
Layout parentLayout = parent.getLayout();
if (parentLayout instanceof GridLayout) {
GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
mainComposite.setLayoutData(gd);
} else if (parentLayout instanceof FormLayout) {
mainComposite.setLayoutData(Utils.getFilledFormData());
}
} else {
Utils.disposeComposite(mainComposite, false);
}
tagButtonsUI = new TagButtonsUI();
List<Tag> listAllTags = getTags();
boolean hasGroup = false;
for (Tag tag : listAllTags) {
String group = tag.getGroup();
if (group != null && group.length() > 0) {
hasGroup = true;
break;
}
}
// / Buttons
Composite buttonComp = new Composite(mainComposite, SWT.NONE);
GridData layoutData = new GridData(SWT.FILL, SWT.CENTER, true, false);
buttonComp.setLayoutData(layoutData);
GridLayout bcLayout = new GridLayout(hasGroup ? 7 : 6, false);
bcLayout.marginHeight = 0;
buttonComp.setLayout(bcLayout);
GridData gridData;
Button buttonAdd = new Button(buttonComp, SWT.PUSH);
gridData = new GridData(SWT.LEFT, SWT.CENTER, false, false);
buttonAdd.setLayoutData(gridData);
Messages.setLanguageText(buttonAdd, "label.add.tag");
buttonAdd.addListener(SWT.Selection, event -> askForNewTag());
buttonCopy = new Button(buttonComp, SWT.PUSH);
gridData = new GridData(SWT.LEFT, SWT.CENTER, false, false);
buttonCopy.setLayoutData(gridData);
Messages.setLanguageText(buttonCopy, "label.copy");
Messages.setLanguageTooltip(buttonCopy, "tags.copy.tooltip");
buttonCopy.addListener(SWT.Selection, event -> {
if (taggables == null) {
return;
}
TagManager tm = TagManagerFactory.getTagManager();
copied_tag_assignment.clear();
for (Taggable taggable : taggables) {
List<Tag> has_tags = tm.getTagsForTaggable(TagType.TT_DOWNLOAD_MANUAL, taggable);
for (Tag tag : has_tags) {
boolean[] auto = tag.isTagAuto();
if (!auto[0] && !auto[1]) {
copied_tag_assignment.add(tag);
}
}
}
for (Consumer<String> c : cta_listeners) {
c.accept("");
}
});
buttonPaste = new Button(buttonComp, SWT.PUSH);
gridData = new GridData(SWT.LEFT, SWT.CENTER, false, false);
buttonPaste.setLayoutData(gridData);
Messages.setLanguageText(buttonPaste, "label.paste");
Messages.setLanguageTooltip(buttonPaste, "tags.paste.tooltip");
buttonPaste.addListener(SWT.Selection, event -> {
if (taggables == null) {
return;
}
TagManager tm = TagManagerFactory.getTagManager();
for (Taggable taggable : taggables) {
for (Tag t : tm.getTagType(TagType.TT_DOWNLOAD_MANUAL).getTags()) {
boolean[] auto = t.isTagAuto();
if (!auto[0] && !auto[1]) {
if (!copied_tag_assignment.contains(t)) {
if (t.hasTaggable(taggable)) {
t.removeTaggable(taggable);
}
}
}
}
for (Tag t : copied_tag_assignment) {
if (!t.hasTaggable(taggable)) {
t.addTaggable(taggable);
}
}
}
});
cta_listeners.add(new Consumer<String>() {
@Override
public void accept(String t) {
if (buttonPaste.isDisposed()) {
cta_listeners.remove(this);
} else {
buttonPaste.setEnabled(!copied_tag_assignment.isEmpty());
}
}
});
buttonPaste.setEnabled(!copied_tag_assignment.isEmpty());
buttonClear = new Button(buttonComp, SWT.PUSH);
gridData = new GridData(SWT.LEFT, SWT.CENTER, false, false);
buttonClear.setLayoutData(gridData);
Messages.setLanguageText(buttonClear, "Button.clear");
Messages.setLanguageTooltip(buttonClear, "tags.clear.tooltip");
buttonClear.addListener(SWT.Selection, event -> {
if (taggables == null) {
return;
}
TagManager tm = TagManagerFactory.getTagManager();
for (Taggable taggable : taggables) {
List<Tag> has_tags = tm.getTagsForTaggable(TagType.TT_DOWNLOAD_MANUAL, taggable);
for (Tag tag : has_tags) {
boolean[] auto = tag.isTagAuto();
if (!auto[0] && !auto[1]) {
tag.removeTaggable(taggable);
}
}
}
});
buttonInvert = new Button(buttonComp, SWT.PUSH);
gridData = new GridData(SWT.LEFT, SWT.CENTER, false, false);
buttonInvert.setLayoutData(gridData);
Messages.setLanguageText(buttonInvert, "label.invert");
Messages.setLanguageTooltip(buttonInvert, "tags.invert.tooltip");
buttonInvert.addListener(SWT.Selection, event -> {
if (taggables == null) {
return;
}
TagManager tm = TagManagerFactory.getTagManager();
List<Tag> all_tags = new ArrayList<>();
for (Tag t : tm.getTagType(TagType.TT_DOWNLOAD_MANUAL).getTags()) {
boolean[] auto = t.isTagAuto();
if (!auto[0] && !auto[1]) {
all_tags.add(t);
}
}
for (Taggable taggable : taggables) {
List<Tag> has_tags = tm.getTagsForTaggable(TagType.TT_DOWNLOAD_MANUAL, taggable);
Set<Tag> tags_to_add = new HashSet<>(all_tags);
for (Tag tag : has_tags) {
boolean[] auto = tag.isTagAuto();
if (!auto[0] && !auto[1]) {
tag.removeTaggable(taggable);
tags_to_add.remove(tag);
}
}
for (Tag tag : tags_to_add) {
tag.addTaggable(taggable);
}
}
});
buttonExplain = new Button(buttonComp, SWT.PUSH);
gridData = new GridData(SWT.LEFT, SWT.CENTER, false, false);
buttonExplain.setLayoutData(gridData);
Messages.setLanguageText(buttonExplain, "button.explain");
buttonExplain.addListener(SWT.Selection, event -> explain());
Utils.makeButtonsEqualWidth(buttonCopy, buttonPaste, buttonClear, buttonInvert);
Utils.makeButtonsEqualWidth(buttonAdd, buttonInvert, buttonExplain);
if (hasGroup) {
int layoutStyle = tagButtonsUI.getLayoutStyle();
ToolBar toolBar = new ToolBar(buttonComp, SWT.NONE);
gridData = new GridData(SWT.RIGHT, SWT.CENTER, true, false);
toolBar.setLayoutData(gridData);
ToolItem buttonRowMode = new ToolItem(toolBar, SWT.RADIO);
if (layoutStyle == SWT.HORIZONTAL) {
buttonRowMode.setSelection(true);
}
ToolItem buttonColumnMode = new ToolItem(toolBar, SWT.RADIO);
if (layoutStyle == SWT.VERTICAL) {
buttonColumnMode.setSelection(true);
}
ToolItem buttonRowCompactMode = new ToolItem(toolBar, SWT.RADIO);
if (layoutStyle == (SWT.HORIZONTAL | SWT.FILL)) {
buttonRowCompactMode.setSelection(true);
}
ImageLoader.getInstance().setToolItemImage(buttonRowMode, "row_mode");
buttonRowMode.addListener(SWT.Selection, event -> tagButtonsUI.setLayoutStyle(SWT.HORIZONTAL));
ImageLoader.getInstance().setToolItemImage(buttonColumnMode, "column_mode");
buttonColumnMode.addListener(SWT.Selection, event -> tagButtonsUI.setLayoutStyle(SWT.VERTICAL));
ImageLoader.getInstance().setToolItemImage(buttonRowCompactMode, "row_compact_mode");
buttonRowCompactMode.addListener(SWT.Selection, event -> tagButtonsUI.setLayoutStyle(SWT.HORIZONTAL | SWT.FILL));
}
// /
sc = new ScrolledComposite(mainComposite, SWT.V_SCROLL);
GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
sc.setLayoutData(gd);
sc.setExpandHorizontal(true);
sc.setExpandVertical(true);
sc.getVerticalBar().setIncrement(16);
Composite cTagComposite = new Composite(sc, SWT.NONE);
GridLayout layout = new GridLayout(1, false);
layout.marginHeight = layout.marginWidth = 0;
cTagComposite.setLayout(layout);
sc.setContent(cTagComposite);
Composite tagArea = tagButtonsUI.buildTagGroup(listAllTags, cTagComposite, true, new TagButtonTrigger() {
@Override
public void tagButtonTriggered(TagPainter painter, int stateMask, boolean longPress) {
if (taggables == null || longPress) {
return;
}
Tag tag = painter.getTag();
boolean doTag = !(painter.isSelected() && !painter.isGrayed());
try {
tag.addTaggableBatch(true);
for (Taggable taggable : taggables) {
if (doTag) {
tag.addTaggable(taggable);
} else {
tag.removeTaggable(taggable);
}
painter.setSelected(doTag);
}
} finally {
tag.addTaggableBatch(false);
}
}
@Override
public Boolean tagSelectedOverride(Tag tag) {
return null;
}
});
tagArea.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
sc.addControlListener(new ControlAdapter() {
@Override
public void controlResized(ControlEvent e) {
Rectangle r = sc.getClientArea();
Point size = cTagComposite.computeSize(r.width, SWT.DEFAULT);
sc.setMinSize(size);
}
});
swt_updateFields();
Rectangle r = sc.getClientArea();
Point size = cTagComposite.computeSize(r.width, SWT.DEFAULT);
sc.setMinSize(size);
}
Aggregations