Search in sources :

Example 36 with Tag

use of com.biglybt.core.tag.Tag in project BiglyBT by BiglySoftware.

the class ColumnTagType method refresh.

@Override
public void refresh(TableCell cell) {
    Tag tag = (Tag) cell.getDataSource();
    TagType sortVal = null;
    if (tag != null) {
        sortVal = tag.getTagType();
    }
    if (!cell.setSortValue(sortVal == null ? 0 : sortVal.getTagType()) && cell.isValid()) {
        return;
    }
    if (!cell.isShown()) {
        return;
    }
    cell.setText(sortVal == null ? "" : sortVal.getTagTypeName(true));
}
Also used : TagType(com.biglybt.core.tag.TagType) Tag(com.biglybt.core.tag.Tag)

Example 37 with Tag

use of com.biglybt.core.tag.Tag in project BiglyBT by BiglySoftware.

the class ColumnTagUpTotal method refresh.

@Override
public void refresh(TableCell cell) {
    Tag tag = (Tag) cell.getDataSource();
    if (tag instanceof TagFeatureRateLimit) {
        TagFeatureRateLimit rl = (TagFeatureRateLimit) tag;
        if (rl.supportsTagRates()) {
            long[] up = rl.getTagUploadTotal();
            if (up != null) {
                long tot = 0;
                for (long l : up) {
                    tot += l;
                }
                if (!cell.setSortValue(tot) && cell.isValid()) {
                    return;
                }
                if (!cell.isShown()) {
                    return;
                }
                cell.setText(DisplayFormatters.formatByteCountToKiBEtc(tot));
            }
        }
    }
}
Also used : TagFeatureRateLimit(com.biglybt.core.tag.TagFeatureRateLimit) Tag(com.biglybt.core.tag.Tag)

Example 38 with Tag

use of com.biglybt.core.tag.Tag in project BiglyBT by BiglySoftware.

the class DeviceManagerUI method addTagSubMenu.

private static void addTagSubMenu(MenuManager menu_manager, MenuItem menu, final DeviceMediaRenderer device) {
    menu.removeAllChildItems();
    TagManager tm = TagManagerFactory.getTagManager();
    List<Tag> tags = tm.getTagType(TagType.TT_DOWNLOAD_MANUAL).getTags();
    tags = TagUIUtils.sortTags(tags);
    long tag_id = device.getAutoShareToTagID();
    Tag assigned_tag = tm.lookupTagByUID(tag_id);
    MenuItem m = menu_manager.addMenuItem(menu, "label.no.tag");
    m.setStyle(MenuItem.STYLE_RADIO);
    m.setData(Boolean.valueOf(assigned_tag == null));
    m.addListener(new MenuItemListener() {

        @Override
        public void selected(MenuItem menu, Object target) {
            device.setAutoShareToTagID(-1);
        }
    });
    m = menu_manager.addMenuItem(menu, "sep1");
    m.setStyle(MenuItem.STYLE_SEPARATOR);
    List<String> menu_names = new ArrayList<>();
    Map<String, Tag> menu_name_map = new IdentityHashMap<>();
    for (Tag t : tags) {
        if (!t.isTagAuto()[0]) {
            String name = t.getTagName(true);
            menu_names.add(name);
            menu_name_map.put(name, t);
        }
    }
    List<Object> menu_structure = MenuBuildUtils.splitLongMenuListIntoHierarchy(menu_names, TagUIUtils.MAX_TOP_LEVEL_TAGS_IN_MENU);
    for (Object obj : menu_structure) {
        List<Tag> bucket_tags = new ArrayList<>();
        MenuItem parent_menu;
        if (obj instanceof String) {
            parent_menu = menu;
            bucket_tags.add(menu_name_map.get((String) obj));
        } else {
            Object[] entry = (Object[]) obj;
            List<String> tag_names = (List<String>) entry[1];
            boolean has_selected = false;
            for (String name : tag_names) {
                Tag tag = menu_name_map.get(name);
                bucket_tags.add(tag);
                if (assigned_tag == tag) {
                    has_selected = true;
                }
            }
            parent_menu = menu_manager.addMenuItem(menu, "!" + (String) entry[0] + (has_selected ? " (*)" : "") + "!");
            parent_menu.setStyle(MenuItem.STYLE_MENU);
        }
        for (final Tag tag : bucket_tags) {
            m = menu_manager.addMenuItem(parent_menu, tag.getTagName(false));
            m.setStyle(MenuItem.STYLE_RADIO);
            m.setData(Boolean.valueOf(assigned_tag == tag));
            m.addListener(new MenuItemListener() {

                @Override
                public void selected(MenuItem menu, Object target) {
                    device.setAutoShareToTagID(tag.getTagUID());
                }
            });
        }
    }
    m = menu_manager.addMenuItem(menu, "sep2");
    m.setStyle(MenuItem.STYLE_SEPARATOR);
    m = menu_manager.addMenuItem(menu, "label.add.tag");
    m.addListener(new MenuItemListener() {

        @Override
        public void selected(MenuItem menu, Object target) {
            TagUIUtils.createManualTag(new UIFunctions.TagReturner() {

                @Override
                public void returnedTags(Tag[] tags) {
                    if (tags != null) {
                        for (Tag new_tag : tags) {
                            device.setAutoShareToTagID(new_tag.getTagUID());
                        }
                    }
                }
            });
        }
    });
}
Also used : TableContextMenuItem(com.biglybt.pif.ui.tables.TableContextMenuItem) MenuItem(com.biglybt.pif.ui.menus.MenuItem) TagManager(com.biglybt.core.tag.TagManager) MenuItemListener(com.biglybt.pif.ui.menus.MenuItemListener) List(java.util.List) Tag(com.biglybt.core.tag.Tag)

Example 39 with Tag

use of com.biglybt.core.tag.Tag in project BiglyBT by BiglySoftware.

the class SBC_DevicesView method addTagsSubMenu.

private void addTagsSubMenu(Menu menu_tags, final TranscodeFile[] files) {
    MenuItem[] items = menu_tags.getItems();
    for (int i = 0; i < items.length; i++) {
        items[i].dispose();
    }
    TagManager tm = TagManagerFactory.getTagManager();
    List<Tag> all_tags = tm.getTagType(TagType.TT_DOWNLOAD_MANUAL).getTags();
    all_tags = TagUIUtils.sortTags(all_tags);
    if (all_tags.size() > 0) {
        Set<String> shared_tags = null;
        boolean some_tags_assigned = false;
        for (TranscodeFile file : files) {
            Set<String> file_tags = new HashSet<>();
            file_tags.addAll(Arrays.asList(file.getTags(true)));
            if (file_tags.size() > 0) {
                some_tags_assigned = true;
            }
            if (shared_tags == null) {
                shared_tags = file_tags;
            } else {
                if (shared_tags.size() != file_tags.size()) {
                    shared_tags.clear();
                    break;
                } else {
                    if (!shared_tags.equals(file_tags)) {
                        shared_tags.clear();
                        break;
                    }
                }
            }
        }
        if (some_tags_assigned) {
            final MenuItem mi_no_tag = new MenuItem(menu_tags, SWT.PUSH);
            mi_no_tag.setText(MessageText.getString("label.no.tag"));
            mi_no_tag.addListener(SWT.Selection, new Listener() {

                @Override
                public void handleEvent(Event event) {
                    for (TranscodeFile file : files) {
                        file.setTags(new String[0]);
                    }
                }
            });
            new MenuItem(menu_tags, SWT.SEPARATOR);
        }
        List<String> menu_names = new ArrayList<>();
        Map<String, Tag> menu_name_map = new IdentityHashMap<>();
        for (Tag t : all_tags) {
            if (!t.isTagAuto()[0]) {
                String name = t.getTagName(true);
                menu_names.add(name);
                menu_name_map.put(name, t);
            }
        }
        List<Object> menu_structure = MenuBuildUtils.splitLongMenuListIntoHierarchy(menu_names, TagUIUtils.MAX_TOP_LEVEL_TAGS_IN_MENU);
        for (Object obj : menu_structure) {
            List<Tag> bucket_tags = new ArrayList<>();
            Menu parent_menu;
            if (obj instanceof String) {
                parent_menu = menu_tags;
                bucket_tags.add(menu_name_map.get((String) obj));
            } else {
                Object[] entry = (Object[]) obj;
                List<String> tag_names = (List<String>) entry[1];
                boolean sub_all_selected = true;
                boolean sub_some_selected = false;
                for (String name : tag_names) {
                    Tag sub_tag = menu_name_map.get(name);
                    if (shared_tags != null && shared_tags.contains(name)) {
                        sub_some_selected = true;
                    } else {
                        sub_all_selected = false;
                    }
                    bucket_tags.add(sub_tag);
                }
                String mod;
                if (sub_all_selected) {
                    mod = " (*)";
                } else if (sub_some_selected) {
                    mod = " (+)";
                } else {
                    mod = "";
                }
                Menu menu_bucket = new Menu(menu_tags.getShell(), SWT.DROP_DOWN);
                MenuItem bucket_item = new MenuItem(menu_tags, SWT.CASCADE);
                bucket_item.setText((String) entry[0] + mod);
                bucket_item.setMenu(menu_bucket);
                parent_menu = menu_bucket;
            }
            for (final Tag t : bucket_tags) {
                final MenuItem t_i = new MenuItem(parent_menu, SWT.CHECK);
                String tag_name = t.getTagName(true);
                t_i.setText(tag_name);
                boolean selected = shared_tags != null && shared_tags.contains(tag_name);
                t_i.setSelection(selected);
                t_i.addListener(SWT.Selection, new Listener() {

                    @Override
                    public void handleEvent(Event event) {
                        boolean selected = t_i.getSelection();
                        String tag_uid = String.valueOf(t.getTagUID());
                        for (TranscodeFile file : files) {
                            Set<String> uids = new TreeSet<>();
                            uids.addAll(Arrays.asList(file.getTags(false)));
                            boolean update = false;
                            if (selected) {
                                if (!uids.contains(tag_uid)) {
                                    uids.add(tag_uid);
                                    update = true;
                                }
                            } else {
                                if (uids.contains(tag_uid)) {
                                    uids.remove(tag_uid);
                                    update = true;
                                }
                            }
                            if (update) {
                                file.setTags(uids.toArray(new String[uids.size()]));
                            }
                        }
                    }
                });
            }
        }
    }
    new MenuItem(menu_tags, SWT.SEPARATOR);
    MenuItem item_create = new MenuItem(menu_tags, SWT.PUSH);
    Messages.setLanguageText(item_create, "label.add.tag");
    item_create.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event event) {
            TagUIUtilsV3.showCreateTagDialog(new UIFunctions.TagReturner() {

                @Override
                public void returnedTags(Tag[] tags) {
                    if (tags != null) {
                        for (Tag new_tag : tags) {
                            if (new_tag != null) {
                                String[] tagUIDs = new String[] { String.valueOf(new_tag.getTagUID()) };
                                for (TranscodeFile file : files) {
                                    file.setTags(tagUIDs);
                                }
                                COConfigurationManager.setParameter("Library.TagInSideBar", true);
                            }
                        }
                    }
                }
            });
        }
    });
}
Also used : TagReturner(com.biglybt.ui.UIFunctions.TagReturner) UserPrompterResultListener(com.biglybt.ui.UserPrompterResultListener) UIPluginViewToolBarListener(com.biglybt.pif.ui.UIPluginViewToolBarListener) TableViewSWTMenuFillListener(com.biglybt.ui.swt.views.table.TableViewSWTMenuFillListener) TableColumnCreationListener(com.biglybt.pif.ui.tables.TableColumnCreationListener) CoreRunningListener(com.biglybt.core.CoreRunningListener) KeyListener(org.eclipse.swt.events.KeyListener) List(java.util.List) TagManager(com.biglybt.core.tag.TagManager) KeyEvent(org.eclipse.swt.events.KeyEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) SWTSkinObject(com.biglybt.ui.swt.skin.SWTSkinObject) Tag(com.biglybt.core.tag.Tag)

Example 40 with Tag

use of com.biglybt.core.tag.Tag in project BiglyBT by BiglySoftware.

the class TagAddedToDateItem method refresh.

@Override
public void refresh(TableCell cell, long timestamp) {
    DownloadManager dm = (DownloadManager) cell.getDataSource();
    TableView<?> tv = cell.getTableRow().getView();
    TableViewCreator tvc = tv == null ? null : cell.getTableRow().getView().getTableViewCreator();
    if (dm != null && tvc instanceof MyTorrentsView) {
        MyTorrentsView mtv = (MyTorrentsView) tvc;
        Tag[] tags = mtv.getCurrentTags();
        if (tags != null && tags.length == 1) {
            long time = tags[0].getTaggableAddedTime(dm);
            super.refresh(cell, time);
            return;
        }
    }
    super.refresh(cell, -1);
}
Also used : TableViewCreator(com.biglybt.ui.common.table.TableViewCreator) Tag(com.biglybt.core.tag.Tag) MyTorrentsView(com.biglybt.ui.swt.views.MyTorrentsView) DownloadManager(com.biglybt.core.download.DownloadManager)

Aggregations

Tag (com.biglybt.core.tag.Tag)55 DownloadManager (com.biglybt.core.download.DownloadManager)15 TagFeatureRateLimit (com.biglybt.core.tag.TagFeatureRateLimit)12 File (java.io.File)9 TagManager (com.biglybt.core.tag.TagManager)8 TagType (com.biglybt.core.tag.TagType)8 ArrayList (java.util.ArrayList)8 List (java.util.List)5 Core (com.biglybt.core.Core)4 CoreRunningListener (com.biglybt.core.CoreRunningListener)4 PEPeerManager (com.biglybt.core.peer.PEPeerManager)4 TagFeatureFileLocation (com.biglybt.core.tag.TagFeatureFileLocation)4 Point (org.eclipse.swt.graphics.Point)4 Category (com.biglybt.core.category.Category)3 DiskManagerFileInfo (com.biglybt.core.disk.DiskManagerFileInfo)3 DownloadManagerInitialisationAdapter (com.biglybt.core.download.DownloadManagerInitialisationAdapter)3 DownloadManagerState (com.biglybt.core.download.DownloadManagerState)3 TOTorrent (com.biglybt.core.torrent.TOTorrent)3 Download (com.biglybt.pif.download.Download)3 GlobalManager (com.biglybt.core.global.GlobalManager)2