Search in sources :

Example 1 with TagPainter

use of com.biglybt.ui.swt.widgets.TagPainter in project BiglyBT by BiglySoftware.

the class TagsColumn method menuEventOccurred.

@Override
public void menuEventOccurred(TableCellMenuEvent e) {
    TableCell _cell = e.cell;
    if (!(_cell instanceof TableCellSWT)) {
        return;
    }
    TableCellSWT cell = (TableCellSWT) _cell;
    Map<TagPainter, Rectangle> tagMapping = (Map<TagPainter, Rectangle>) cell.getData(TAG_MAPPING_KEY);
    if (tagMapping == null) {
        return;
    }
    Object ev = e.baseEvent;
    if (ev instanceof MenuDetectEvent) {
        Object data = ((MenuDetectEvent) ev).getSource();
        if (data instanceof Control) {
            Point pt = new Point(e.x, e.y);
            Tag target = null;
            for (Map.Entry<TagPainter, Rectangle> entry : tagMapping.entrySet()) {
                if (entry.getValue().contains(pt)) {
                    target = entry.getKey().getTag();
                    break;
                }
            }
            if (target != null) {
                Menu menu = new Menu((Control) data);
                menu.addMenuListener(new MenuAdapter() {

                    @Override
                    public void menuHidden(MenuEvent e) {
                        // can't dispose immediately as it causes the menu hierarchy to be trashed
                        // before having the chance to fire a selected item
                        Utils.execSWTThreadLater(100, () -> {
                            menu.dispose();
                        });
                    }
                });
                org.eclipse.swt.widgets.MenuItem mi = new org.eclipse.swt.widgets.MenuItem(menu, SWT.PUSH);
                mi.setText(MessageText.getString("label.tag") + ": " + target.getTagName(true));
                mi.setEnabled(false);
                ;
                new org.eclipse.swt.widgets.MenuItem(menu, SWT.SEPARATOR);
                TagUIUtils.createSideBarMenuItems(menu, target);
                menu.setVisible(true);
                e.skipCoreFunctionality = true;
            }
        }
    }
}
Also used : TableCellSWT(com.biglybt.ui.swt.views.table.TableCellSWT) TagPainter(com.biglybt.ui.swt.widgets.TagPainter) MenuAdapter(org.eclipse.swt.events.MenuAdapter) Control(org.eclipse.swt.widgets.Control) MenuDetectEvent(org.eclipse.swt.events.MenuDetectEvent) Menu(org.eclipse.swt.widgets.Menu) MenuEvent(org.eclipse.swt.events.MenuEvent)

Example 2 with TagPainter

use of com.biglybt.ui.swt.widgets.TagPainter in project BiglyBT by BiglySoftware.

the class MyTorrentsView method buildCatAndTag.

/**
 * @since 3.1.1.1
 */
private void buildCatAndTag(List<Tag> tags) {
    if (tags.size() == 0 || cCategoriesAndTags == null || cCategoriesAndTags.isDisposed()) {
        return;
    }
    Label spacer = null;
    allTags = tags;
    if (buttonListener == null) {
        buttonListener = new TagButtonTrigger() {

            @Override
            public void tagButtonTriggered(TagPainter painter, int stateMask, boolean longPress) {
                Tag tag = painter.getTag();
                if (longPress) {
                    handleLongPress(painter, tag);
                    return;
                }
                boolean add = (stateMask & SWT.MOD1) != 0;
                boolean isSelected = painter.isSelected();
                if (isSelected) {
                    removeTagFromCurrent(tag);
                    painter.setSelected(!isSelected);
                } else {
                    if (add) {
                        Category catAll = CategoryManager.getCategory(Category.TYPE_ALL);
                        if (tag.equals(catAll)) {
                            setCurrentTags(catAll);
                        } else {
                            synchronized (currentTagsLock) {
                                Tag[] newTags = new Tag[_currentTags.length + 1];
                                System.arraycopy(_currentTags, 0, newTags, 0, _currentTags.length);
                                newTags[_currentTags.length] = tag;
                                newTags = (Tag[]) removeFromArray(newTags, catAll);
                                setCurrentTags(newTags);
                            }
                        }
                        painter.setSelected(!isSelected);
                    } else {
                        setCurrentTags(tag);
                        setSelection(painter.getControl().getParent());
                    }
                }
            }

            private void setSelection(Composite parent) {
                if (parent == null) {
                    return;
                }
                List<Tag> selectedTags = new ArrayList<>();
                Tag[] currentTags = getCurrentTags();
                if (currentTags != null) {
                    selectedTags.addAll(Arrays.asList(currentTags));
                }
                Control[] controls = parent.getChildren();
                for (Control control : controls) {
                    if (!(control instanceof TagCanvas)) {
                        continue;
                    }
                    TagPainter painter = ((TagCanvas) control).getTagPainter();
                    boolean selected = selectedTags.remove(painter.getTag());
                    painter.setSelected(selected);
                }
            }

            private void handleLongPress(TagPainter painter, Tag tag) {
                if (tv == null) {
                    return;
                }
                Object[] ds = tv.getSelectedDataSources().toArray();
                if (tag instanceof Category) {
                    TorrentUtil.assignToCategory(ds, (Category) tag);
                    return;
                }
                boolean doAdd = false;
                for (Object obj : ds) {
                    if (obj instanceof DownloadManager) {
                        DownloadManager dm = (DownloadManager) obj;
                        if (!tag.hasTaggable(dm)) {
                            doAdd = true;
                            break;
                        }
                    }
                }
                try {
                    tag.addTaggableBatch(true);
                    for (Object obj : ds) {
                        if (obj instanceof DownloadManager) {
                            DownloadManager dm = (DownloadManager) obj;
                            if (doAdd) {
                                tag.addTaggable(dm);
                            } else {
                                tag.removeTaggable(dm);
                            }
                        }
                    }
                } finally {
                    tag.addTaggableBatch(false);
                }
                // Quick Visual
                boolean wasSelected = painter.isSelected();
                painter.setGrayed(true);
                painter.setSelected(true);
                Utils.execSWTThreadLater(200, () -> {
                    painter.setGrayed(false);
                    painter.setSelected(wasSelected);
                });
            }

            @Override
            public Boolean tagSelectedOverride(Tag tag) {
                return null;
            }
        };
    }
    TagGroup currentGroup = null;
    for (final Tag tag : tags) {
        boolean isCat = (tag instanceof Category);
        TagGroup tg = tag.getGroupContainer();
        if (tg != currentGroup && currentGroup != null && !currentGroup.getTags().isEmpty()) {
            Divider div = new Divider(cCategoriesAndTags, SWT.NULL);
            RowData rd = new RowData();
            div.setLayoutData(rd);
        }
        currentGroup = tg;
        TagCanvas button = new TagCanvas(cCategoriesAndTags, tag, false, true);
        TagPainter painter = button.getTagPainter();
        button.setTrigger(buttonListener);
        painter.setCompact(true, COConfigurationManager.getBooleanParameter("Library.ShowTagButtons.ImageOverride"));
        if (isCat) {
            if (spacer == null) {
                spacer = new Label(cCategoriesAndTags, SWT.NONE);
                RowData rd = new RowData();
                rd.width = 8;
                spacer.setLayoutData(rd);
                spacer.moveAbove(null);
            }
            button.moveAbove(spacer);
        }
        button.addKeyListener(this);
        if (fontButton == null) {
            fontButton = FontUtils.cache(FontUtils.getFontWithStyle(button.getFont(), SWT.NONE, 0.8f));
        }
        button.setFont(fontButton);
        if (isCurrent(tag)) {
            painter.setSelected(true);
        }
        Menu menu = new Menu(button);
        button.setMenu(menu);
        if (isCat) {
            CategoryUIUtils.setupCategoryMenu(menu, (Category) tag);
        } else {
            TagUIUtils.createSideBarMenuItemsDelayed(menu, tag);
        }
    }
    cCategoriesAndTags.getParent().layout(true, true);
}
Also used : Category(com.biglybt.core.category.Category) TagPainter(com.biglybt.ui.swt.widgets.TagPainter) DownloadManager(com.biglybt.core.download.DownloadManager) TagCanvas(com.biglybt.ui.swt.widgets.TagCanvas) TagButtonTrigger(com.biglybt.ui.swt.widgets.TagCanvas.TagButtonTrigger) List(java.util.List)

Example 3 with TagPainter

use of com.biglybt.ui.swt.widgets.TagPainter 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);
}
Also used : Composite(org.eclipse.swt.widgets.Composite) TagPainter(com.biglybt.ui.swt.widgets.TagPainter) FillLayout(org.eclipse.swt.layout.FillLayout) GridLayout(org.eclipse.swt.layout.GridLayout) TagCanvas(com.biglybt.ui.swt.widgets.TagCanvas) GridData(org.eclipse.swt.layout.GridData) TagButtonsUI(com.biglybt.ui.swt.views.utils.TagButtonsUI) SkinnedDialog(com.biglybt.ui.swt.views.skin.SkinnedDialog) StandardButtonsArea(com.biglybt.ui.swt.views.skin.StandardButtonsArea)

Example 4 with TagPainter

use of com.biglybt.ui.swt.widgets.TagPainter 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);
}
Also used : ControlAdapter(org.eclipse.swt.events.ControlAdapter) ArrayList(java.util.ArrayList) Rectangle(org.eclipse.swt.graphics.Rectangle) GridLayout(org.eclipse.swt.layout.GridLayout) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) TagButtonsUI(com.biglybt.ui.swt.views.utils.TagButtonsUI) TagButtonTrigger(com.biglybt.ui.swt.widgets.TagCanvas.TagButtonTrigger) HashSet(java.util.HashSet) FormLayout(org.eclipse.swt.layout.FormLayout) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) TagPainter(com.biglybt.ui.swt.widgets.TagPainter) Point(org.eclipse.swt.graphics.Point) Point(org.eclipse.swt.graphics.Point) FormLayout(org.eclipse.swt.layout.FormLayout) GridLayout(org.eclipse.swt.layout.GridLayout) GridData(org.eclipse.swt.layout.GridData) ControlEvent(org.eclipse.swt.events.ControlEvent)

Example 5 with TagPainter

use of com.biglybt.ui.swt.widgets.TagPainter in project BiglyBT by BiglySoftware.

the class TagsColumn method cellPaint.

@Override
public void cellPaint(GC gc, TableCellSWT cell) {
    Object ds = cell.getDataSource();
    Taggable taggable = (ds instanceof Taggable) ? (Taggable) ds : null;
    Point cellSize = cell.getSize();
    Rectangle bounds = cell.getBounds();
    // adjust size to leave 1 pixel gaps left+right
    cellSize.x -= 3;
    bounds.x += 1;
    Font oldFont = gc.getFont();
    int maxLines = cell.getMaxLines();
    if (maxLines <= 1) {
        if (fontOneLine == null) {
            fontOneLine = FontUtils.getFontWithHeight(oldFont, (int) (FontUtils.getFontHeightInPX(oldFont) - 2), SWT.DEFAULT);
        }
        gc.setFont(fontOneLine);
    } else {
        if (fontMultiLine == null) {
            fontMultiLine = FontUtils.getFontWithHeight(gc.getFont(), ((cellSize.y - 2) / maxLines), SWT.DEFAULT);
        }
        gc.setFont(fontMultiLine);
    }
    List<Tag> tags = getTags(cell);
    tags = TagUtils.sortTags(tags);
    int x = 0;
    int y = 0;
    int lineHeight = 0;
    Map<TagPainter, Rectangle> mapTagPainting = new LinkedHashMap<>();
    for (Tag tag : tags) {
        TagPainter painter = new TagPainter(tag);
        painter.setCompact(true, false);
        painter.paddingContentY = 1;
        painter.paddingContentX0 = 2;
        painter.paddingContentX1 = 4;
        painter.setMinWidth(16);
        Point size = painter.getSize(gc);
        if (size == null) {
            continue;
        }
        int endX = x + size.x;
        if (endX > cellSize.x && y + lineHeight + (lineHeight * 0.8) <= cellSize.y) {
            x = 0;
            endX = size.x;
            y += lineHeight + 1;
            lineHeight = size.y;
        } else {
            lineHeight = Math.max(lineHeight, size.y);
        }
        if (y > cellSize.y) {
            break;
        }
        int clipW = endX > cellSize.x ? cellSize.x - x : size.x;
        int clipH = y + size.y > cellSize.y ? cellSize.y - y : size.y;
        mapTagPainting.put(painter, new Rectangle(bounds.x + x, bounds.y + y, clipW, clipH));
        x = endX + 1;
        if (x > cellSize.x) {
            break;
        }
    }
    Rectangle clipping = gc.getClipping();
    int endY = y + lineHeight;
    int yOfs = (cellSize.y - endY) / 2;
    if (yOfs < 0) {
        yOfs = 0;
    }
    for (TagPainter painter : mapTagPainting.keySet()) {
        Rectangle clip = mapTagPainting.get(painter);
        clip.y += yOfs;
        gc.setClipping(clip);
        painter.paint(taggable, gc, clip.x, clip.y);
        painter.dispose();
    }
    cell.setData(TAG_MAPPING_KEY, mapTagPainting);
    gc.setClipping(clipping);
    gc.setFont(oldFont);
}
Also used : TagPainter(com.biglybt.ui.swt.widgets.TagPainter)

Aggregations

TagPainter (com.biglybt.ui.swt.widgets.TagPainter)7 TagCanvas (com.biglybt.ui.swt.widgets.TagCanvas)4 TagButtonsUI (com.biglybt.ui.swt.views.utils.TagButtonsUI)2 TagButtonTrigger (com.biglybt.ui.swt.widgets.TagCanvas.TagButtonTrigger)2 ScrolledComposite (org.eclipse.swt.custom.ScrolledComposite)2 GridData (org.eclipse.swt.layout.GridData)2 GridLayout (org.eclipse.swt.layout.GridLayout)2 Category (com.biglybt.core.category.Category)1 DownloadManager (com.biglybt.core.download.DownloadManager)1 Tag (com.biglybt.core.tag.Tag)1 SkinnedDialog (com.biglybt.ui.swt.views.skin.SkinnedDialog)1 StandardButtonsArea (com.biglybt.ui.swt.views.skin.StandardButtonsArea)1 TableCellSWT (com.biglybt.ui.swt.views.table.TableCellSWT)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 List (java.util.List)1 ControlAdapter (org.eclipse.swt.events.ControlAdapter)1 ControlEvent (org.eclipse.swt.events.ControlEvent)1 MenuAdapter (org.eclipse.swt.events.MenuAdapter)1 MenuDetectEvent (org.eclipse.swt.events.MenuDetectEvent)1