Search in sources :

Example 1 with ToolBarItem

use of com.biglybt.ui.common.ToolBarItem in project BiglyBT by BiglySoftware.

the class ToolBarView method setupToolBarItems.

private void setupToolBarItems(boolean uiClassic) {
    ToolBarItem item;
    {
        // always add these items, whether they are shown or not is decided later
        // ==OPEN
        item = createItem(this, "open", "image.toolbar.open", "Button.add.torrent");
        item.setDefaultActivationListener(new UIToolBarActivationListener() {

            @Override
            public boolean toolBarItemActivated(ToolBarItem item, long activationType, Object datasource) {
                if (activationType != ACTIVATIONTYPE_NORMAL) {
                    Boolean result = Utils.execSWTThreadWithBool("open", new AERunnableBoolean() {

                        @Override
                        public boolean runSupport() {
                            Clipboard clipboard = new Clipboard(Display.getDefault());
                            try {
                                String text = (String) clipboard.getContents(TextTransfer.getInstance());
                                if (text != null && text.length() <= 2048) {
                                    if (TorrentOpener.openTorrentsFromClipboard(text)) {
                                        return (true);
                                    }
                                }
                            } finally {
                                clipboard.dispose();
                            }
                            return false;
                        }
                    }, 1000);
                    return (result != null && result);
                }
                UIFunctionsManagerSWT.getUIFunctionsSWT().openTorrentWindow();
                return true;
            }
        });
        item.setAlwaysAvailable(true);
        item.setGroupID("classic");
        tbm.addToolBarItem(item, false);
        // ==SEARCH
        item = createItem(this, "search", "search", "Button.search");
        item.setDefaultActivationListener(new UIToolBarActivationListener() {

            @Override
            public boolean toolBarItemActivated(ToolBarItem item, long activationType, Object datasource) {
                if (activationType != ACTIVATIONTYPE_NORMAL) {
                    return false;
                }
                UIFunctionsManagerSWT.getUIFunctionsSWT().promptForSearch();
                return true;
            }
        });
        item.setAlwaysAvailable(true);
        item.setGroupID("classic");
        tbm.addToolBarItem(item, false);
    }
    if (!uiClassic) {
        // ==play
        item = createItem(this, "play", "image.button.play", "iconBar.play");
        item.setDefaultActivationListener(new UIToolBarActivationListener() {

            @Override
            public boolean toolBarItemActivated(ToolBarItem item, long activationType, Object datasource) {
                if (activationType != ACTIVATIONTYPE_NORMAL) {
                    return false;
                }
                ISelectedContent[] sc = SelectedContentManager.getCurrentlySelectedContent();
                if (sc != null && sc.length > 0) {
                    if (PlayUtils.canStreamDS(sc[0], sc[0].getFileIndex(), true)) {
                        TorrentListViewsUtils.playOrStreamDataSource(sc[0], DLReferals.DL_REFERAL_TOOLBAR, true, false);
                    } else {
                        TorrentListViewsUtils.playOrStreamDataSource(sc[0], DLReferals.DL_REFERAL_TOOLBAR, false, true);
                    }
                }
                return false;
            }
        });
        tbm.addToolBarItem(item, false);
    }
    // ==run
    item = createItem(this, "run", "image.toolbar.run", "iconBar.run");
    item.setDefaultActivationListener(new UIToolBarActivationListener() {

        @Override
        public boolean toolBarItemActivated(ToolBarItem item, long activationType, Object datasource) {
            if (activationType != ACTIVATIONTYPE_NORMAL) {
                return false;
            }
            TableView tv = SelectedContentManager.getCurrentlySelectedTableView();
            Object[] ds;
            if (tv != null) {
                ds = tv.getSelectedDataSources().toArray();
            } else {
                ds = SelectedContentManager.getDMSFromSelectedContent();
            }
            if (ds != null) {
                TorrentUtil.runDataSources(ds);
                return true;
            }
            return false;
        }
    });
    tbm.addToolBarItem(item, false);
    if (uiClassic) {
        // ==TOP
        item = createItem(this, "top", "image.toolbar.top", "iconBar.top");
        item.setDefaultActivationListener(new UIToolBarActivationListener() {

            @Override
            public boolean toolBarItemActivated(ToolBarItem item, long activationType, Object datasource) {
                if (activationType == ACTIVATIONTYPE_NORMAL) {
                    return moveTop();
                }
                return false;
            }
        });
        tbm.addToolBarItem(item, false);
    }
    // ==UP
    item = createItem(this, "up", "image.toolbar.up", "iconBar.up");
    item.setDefaultActivationListener(new UIToolBarActivationListener() {

        @Override
        public boolean toolBarItemActivated(ToolBarItem item, long activationType, Object datasource) {
            if (activationType == ACTIVATIONTYPE_NORMAL) {
                if (!CoreFactory.isCoreRunning()) {
                    return false;
                }
                DownloadManager[] dms = SelectedContentManager.getDMSFromSelectedContent();
                if (dms != null) {
                    Arrays.sort(dms, new Comparator<DownloadManager>() {

                        @Override
                        public int compare(DownloadManager a, DownloadManager b) {
                            return a.getPosition() - b.getPosition();
                        }
                    });
                    GlobalManager gm = CoreFactory.getSingleton().getGlobalManager();
                    for (int i = 0; i < dms.length; i++) {
                        DownloadManager dm = dms[i];
                        if (gm.isMoveableUp(dm)) {
                            gm.moveUp(dm);
                        }
                    }
                }
            } else if (activationType == ACTIVATIONTYPE_HELD) {
                return moveTop();
            }
            return false;
        }
    });
    tbm.addToolBarItem(item, false);
    // ==down
    item = createItem(this, "down", "image.toolbar.down", "iconBar.down");
    item.setDefaultActivationListener(new UIToolBarActivationListener() {

        @Override
        public boolean toolBarItemActivated(ToolBarItem item, long activationType, Object datasource) {
            if (activationType == ACTIVATIONTYPE_NORMAL) {
                if (!CoreFactory.isCoreRunning()) {
                    return false;
                }
                GlobalManager gm = CoreFactory.getSingleton().getGlobalManager();
                DownloadManager[] dms = SelectedContentManager.getDMSFromSelectedContent();
                if (dms != null) {
                    Arrays.sort(dms, new Comparator<DownloadManager>() {

                        @Override
                        public int compare(DownloadManager a, DownloadManager b) {
                            return b.getPosition() - a.getPosition();
                        }
                    });
                    for (int i = 0; i < dms.length; i++) {
                        DownloadManager dm = dms[i];
                        if (gm.isMoveableDown(dm)) {
                            gm.moveDown(dm);
                        }
                    }
                    return true;
                }
            } else if (activationType == ACTIVATIONTYPE_HELD) {
                return moveBottom();
            }
            return false;
        }
    });
    tbm.addToolBarItem(item, false);
    if (uiClassic) {
        // ==BOTTOM
        item = createItem(this, "bottom", "image.toolbar.bottom", "iconBar.bottom");
        item.setDefaultActivationListener(new UIToolBarActivationListener() {

            @Override
            public boolean toolBarItemActivated(ToolBarItem item, long activationType, Object datasource) {
                if (activationType != ACTIVATIONTYPE_NORMAL) {
                    return false;
                }
                return moveBottom();
            }
        });
        tbm.addToolBarItem(item, false);
    }
    // ==start
    item = createItem(this, "start", "image.toolbar.startstop.start", "iconBar.start");
    item.setDefaultActivationListener(new UIToolBarActivationListener_OffSWT() {

        @Override
        public void toolBarItemActivated_OffSWT(ToolBarItem item, long activationType, Object datasource) {
            ISelectedContent[] selected = SelectedContentManager.getCurrentlySelectedContent();
            TorrentUtil.queueDataSources(selected, true, activationType == ACTIVATIONTYPE_HELD);
        }
    });
    tbm.addToolBarItem(item, false);
    // ==stop
    item = createItem(this, "stop", "image.toolbar.startstop.stop", "iconBar.stop");
    item.setDefaultActivationListener(new UIToolBarActivationListener_OffSWT() {

        @Override
        public void toolBarItemActivated_OffSWT(ToolBarItem item, long activationType, Object datasource) {
            ISelectedContent[] selected = SelectedContentManager.getCurrentlySelectedContent();
            TorrentUtil.stopDataSources(selected, activationType == ACTIVATIONTYPE_HELD);
        }
    });
    tbm.addToolBarItem(item, false);
    // ==startstop
    item = createItem(this, "startstop", "image.toolbar.startstop.start", "iconBar.startstop");
    item.setDefaultActivationListener(new UIToolBarActivationListener_OffSWT() {

        @Override
        public void toolBarItemActivated_OffSWT(ToolBarItem item, long activationType, Object datasource) {
            ISelectedContent[] selected = SelectedContentManager.getCurrentlySelectedContent();
            TorrentUtil.stopOrStartDataSources(selected, activationType == ACTIVATIONTYPE_HELD);
        }
    });
    tbm.addToolBarItem(item, false);
    // ==remove
    item = createItem(this, "remove", "image.toolbar.remove", "iconBar.remove");
    item.setDefaultActivationListener(new UIToolBarActivationListener_OffSWT(UIToolBarActivationListener.ACTIVATIONTYPE_NORMAL) {

        @Override
        public void toolBarItemActivated_OffSWT(ToolBarItem item, long activationType, Object datasource) {
            ISelectedContent[] selected = SelectedContentManager.getCurrentlySelectedContent();
            TorrentUtil.removeDataSources(selected);
        }
    });
    tbm.addToolBarItem(item, false);
    if (COConfigurationManager.getBooleanParameter("Library.EnableSimpleView")) {
        // == mode big
        item = createItem(this, "modeBig", "image.toolbar.table_large", "v3.iconBar.view.big");
        item.setGroupID("views");
        tbm.addToolBarItem(item, false);
        // == mode small
        item = createItem(this, "modeSmall", "image.toolbar.table_normal", "v3.iconBar.view.small");
        item.setGroupID("views");
        tbm.addToolBarItem(item, false);
    }
}
Also used : AERunnableBoolean(com.biglybt.core.util.AERunnableBoolean) DownloadManager(com.biglybt.core.download.DownloadManager) GlobalManager(com.biglybt.core.global.GlobalManager) ToolBarItem(com.biglybt.ui.common.ToolBarItem) SWTSkinObject(com.biglybt.ui.swt.skin.SWTSkinObject) Clipboard(org.eclipse.swt.dnd.Clipboard) AERunnableBoolean(com.biglybt.core.util.AERunnableBoolean) TableView(com.biglybt.ui.common.table.TableView)

Example 2 with ToolBarItem

use of com.biglybt.ui.common.ToolBarItem in project BiglyBT by BiglySoftware.

the class ToolBarView method toolbarItemAdded.

@Override
public void toolbarItemAdded(final UIToolBarItem item) {
    if (isVisible()) {
        if (item instanceof ToolBarItem) {
            ToolBarItem toolBarItem = (ToolBarItem) item;
            toolBarItem.addToolBarItemListener(this);
        }
    }
    rebuild();
}
Also used : ToolBarItem(com.biglybt.ui.common.ToolBarItem)

Example 3 with ToolBarItem

use of com.biglybt.ui.common.ToolBarItem in project BiglyBT by BiglySoftware.

the class TorrentUtil method init.

public static synchronized void init() {
    if (initialised) {
        return;
    }
    initialised = true;
    for (String id : TU_ITEMS) {
        String key = "IconBar.visible." + id;
        if (!COConfigurationManager.hasParameter(key, false)) {
            COConfigurationManager.setParameter(key, false);
        }
    }
    UIManager ui_manager = CoreFactory.getSingleton().getPluginManager().getDefaultPluginInterface().getUIManager();
    ui_manager.addUIListener(new UIManagerListener() {

        private List<UIToolBarItem> items = new ArrayList<>();

        @Override
        public void UIAttached(UIInstance instance) {
            if (instance.getUIType().equals(UIInstance.UIT_SWT)) {
                UIToolBarManager tbm = instance.getToolBarManager();
                if (tbm != null) {
                    UIToolBarItem refresh_item = tbm.createToolBarItem(TU_ITEM_RECHECK);
                    refresh_item.setGroupID(TU_GROUP);
                    refresh_item.setImageID("recheck");
                    refresh_item.setToolTipID("MyTorrentsView.menu.recheck");
                    refresh_item.setDefaultActivationListener(new UIToolBarActivationListener() {

                        @Override
                        public boolean toolBarItemActivated(ToolBarItem item, long activationType, Object datasource) {
                            List<DownloadManager> dms = getDMs(datasource);
                            for (DownloadManager dm : dms) {
                                if (dm.canForceRecheck()) {
                                    dm.forceRecheck();
                                }
                            }
                            return (true);
                        }
                    });
                    addItem(tbm, refresh_item);
                    // check files exist
                    UIToolBarItem cfe_item = tbm.createToolBarItem(TU_ITEM_CHECK_FILES);
                    cfe_item.setGroupID(TU_GROUP);
                    cfe_item.setImageID("filesexist");
                    cfe_item.setToolTipID("MyTorrentsView.menu.checkfilesexist");
                    cfe_item.setDefaultActivationListener(new UIToolBarActivationListener() {

                        @Override
                        public boolean toolBarItemActivated(ToolBarItem item, long activationType, Object datasource) {
                            List<DownloadManager> dms = getDMs(datasource);
                            for (DownloadManager dm : dms) {
                                dm.filesExist(true);
                            }
                            return (true);
                        }
                    });
                    addItem(tbm, cfe_item);
                }
            }
        }

        private List<DownloadManager> getDMs(Object ds) {
            List<DownloadManager> result = new ArrayList<>();
            if (ds instanceof Download) {
                result.add(PluginCoreUtils.unwrap((Download) ds));
            } else if (ds instanceof Object[]) {
                Object[] objs = (Object[]) ds;
                for (Object obj : objs) {
                    if (obj instanceof Download) {
                        result.add(PluginCoreUtils.unwrap((Download) obj));
                    }
                }
            }
            return (result);
        }

        private void addItem(UIToolBarManager tbm, UIToolBarItem item) {
            items.add(item);
            tbm.addToolBarItem(item);
        }

        @Override
        public void UIDetached(UIInstance instance) {
            if (instance.getUIType().equals(UIInstance.UIT_SWT)) {
                UIToolBarManager tbm = instance.getToolBarManager();
                if (tbm != null) {
                    for (UIToolBarItem item : items) {
                        tbm.removeToolBarItem(item.getID());
                    }
                }
                items.clear();
            }
        }
    });
}
Also used : UIManager(com.biglybt.pif.ui.UIManager) DownloadManager(com.biglybt.core.download.DownloadManager) ToolBarItem(com.biglybt.ui.common.ToolBarItem) UIToolBarItem(com.biglybt.pif.ui.toolbar.UIToolBarItem) UIToolBarManager(com.biglybt.pif.ui.toolbar.UIToolBarManager) List(java.util.List) UIToolBarItem(com.biglybt.pif.ui.toolbar.UIToolBarItem) UIManagerListener(com.biglybt.pif.ui.UIManagerListener) UIToolBarActivationListener(com.biglybt.pif.ui.toolbar.UIToolBarActivationListener) Download(com.biglybt.pif.download.Download) UIInstance(com.biglybt.pif.ui.UIInstance)

Example 4 with ToolBarItem

use of com.biglybt.ui.common.ToolBarItem in project BiglyBT by BiglySoftware.

the class ToolBarView method bulkSetupItems.

private void bulkSetupItems(String groupID, String templatePrefix) {
    String[] idsByGroupAll = tbm.getToolBarIDsByGroup(groupID);
    SWTSkinObjectContainer groupSO = peekGroupSO(groupID);
    if (groupSO != null) {
        SWTSkinObject[] children = groupSO.getChildren();
        for (SWTSkinObject so : children) {
            so.dispose();
        }
    }
    List<String> idsByGroup = new ArrayList<>();
    for (String id : idsByGroupAll) {
        if (visible_items.contains(id)) {
            idsByGroup.add(id);
        }
    }
    int size = idsByGroup.size();
    if (size > 0) {
        // only peeked above, create now as group is required
        groupSO = getGroupSO(groupID);
        for (int i = 0; i < size; i++) {
            String itemID = idsByGroup.get(i);
            UIToolBarItem item = tbm.getToolBarItem(itemID);
            if (item instanceof ToolBarItem) {
                int position = 0;
                if (size == 1) {
                    position = SWT.SINGLE;
                } else if (i == 0) {
                    position = SWT.LEFT;
                } else if (i == size - 1) {
                    addSeperator(groupID);
                    position = SWT.RIGHT;
                } else {
                    addSeperator(groupID);
                }
                createItemSO((ToolBarItem) item, templatePrefix, position);
            }
        }
        addNonToolBar("toolbar.area.sitem.left2", groupID);
    }
}
Also used : SWTSkinObject(com.biglybt.ui.swt.skin.SWTSkinObject) SWTSkinObjectContainer(com.biglybt.ui.swt.skin.SWTSkinObjectContainer) ToolBarItem(com.biglybt.ui.common.ToolBarItem)

Example 5 with ToolBarItem

use of com.biglybt.ui.common.ToolBarItem in project BiglyBT by BiglySoftware.

the class ToolBarView method skinObjectShown.

// @see SkinView#skinObjectShown(SWTSkinObject, java.lang.Object)
@Override
public Object skinObjectShown(SWTSkinObject skinObject, Object params) {
    if (showCalled) {
        return null;
    }
    showCalled = true;
    Object object = super.skinObjectShown(skinObject, params);
    ToolBarItem[] allToolBarItems = tbm.getAllSWTToolBarItems();
    for (int i = 0; i < allToolBarItems.length; i++) {
        ToolBarItem toolBarItem = allToolBarItems[i];
        toolBarItem.addToolBarItemListener(this);
        uiFieldChanged(toolBarItem);
    }
    SelectedContentManager.addCurrentlySelectedContentListener(this);
    return object;
}
Also used : ToolBarItem(com.biglybt.ui.common.ToolBarItem) SWTSkinObject(com.biglybt.ui.swt.skin.SWTSkinObject)

Aggregations

ToolBarItem (com.biglybt.ui.common.ToolBarItem)7 SWTSkinObject (com.biglybt.ui.swt.skin.SWTSkinObject)4 DownloadManager (com.biglybt.core.download.DownloadManager)2 GlobalManager (com.biglybt.core.global.GlobalManager)1 AERunnableBoolean (com.biglybt.core.util.AERunnableBoolean)1 Download (com.biglybt.pif.download.Download)1 UIInstance (com.biglybt.pif.ui.UIInstance)1 UIManager (com.biglybt.pif.ui.UIManager)1 UIManagerListener (com.biglybt.pif.ui.UIManagerListener)1 UIToolBarActivationListener (com.biglybt.pif.ui.toolbar.UIToolBarActivationListener)1 UIToolBarItem (com.biglybt.pif.ui.toolbar.UIToolBarItem)1 UIToolBarManager (com.biglybt.pif.ui.toolbar.UIToolBarManager)1 TableView (com.biglybt.ui.common.table.TableView)1 SWTSkinButtonUtility (com.biglybt.ui.swt.skin.SWTSkinButtonUtility)1 SWTSkinObjectContainer (com.biglybt.ui.swt.skin.SWTSkinObjectContainer)1 SWTSkinObjectText (com.biglybt.ui.swt.skin.SWTSkinObjectText)1 List (java.util.List)1 Clipboard (org.eclipse.swt.dnd.Clipboard)1