Search in sources :

Example 1 with AERunnableBoolean

use of com.biglybt.core.util.AERunnableBoolean 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 AERunnableBoolean

use of com.biglybt.core.util.AERunnableBoolean in project BiglyBT by BiglySoftware.

the class SWTSkinUtils method slide.

public static void slide(final SWTSkinObject skinObject, final FormData fd, final Point destSize, final Runnable runOnCompletion) {
    final Control control = skinObject.getControl();
    // System.out.println("slide to " + size + " via "+ Debug.getCompressedStackTrace());
    Boolean exit = Utils.execSWTThreadWithBool("slide", new AERunnableBoolean() {

        @Override
        public boolean runSupport() {
            boolean exit = control.getData("slide.active") != null;
            Runnable oldROC = (Runnable) control.getData("slide.runOnCompletion");
            if (oldROC != null) {
                oldROC.run();
            }
            control.setData("slide.destSize", destSize);
            control.setData("slide.runOnCompletion", runOnCompletion);
            if (destSize.y > 0) {
                skinObject.setVisible(true);
            }
            return exit;
        }
    }, 1000);
    if (exit == null || exit) {
        return;
    }
    AERunnable runnable = new AERunnable() {

        boolean firstTime = true;

        float pct = 0.4f;

        @Override
        public void runSupport() {
            if (control.isDisposed()) {
                return;
            }
            Point size = (Point) control.getData("slide.destSize");
            if (size == null) {
                return;
            }
            if (firstTime) {
                firstTime = false;
                control.setData("slide.active", "1");
            }
            int newWidth = (int) (fd.width + (size.x - fd.width) * pct);
            int h = fd.height >= 0 ? fd.height : control.getSize().y;
            int newHeight = (int) (h + (size.y - h) * pct);
            pct += 0.01;
            if (newWidth == fd.width && newHeight == h) {
                fd.width = size.x;
                fd.height = size.y;
                // System.out.println(control + "] side to " + size.y + " done" + size.x);
                control.setLayoutData(fd);
                Utils.relayout(control);
                control.getParent().layout();
                control.setData("slide.active", null);
                control.setData("slide.destSize", null);
                if (newHeight == 0) {
                    skinObject.setVisible(false);
                    Utils.relayout(control);
                }
                Runnable oldROC = (Runnable) control.getData("slide.runOnCompletion");
                if (oldROC != null) {
                    control.setData("slide.runOnCompletion", null);
                    oldROC.run();
                }
            } else {
                fd.width = newWidth;
                fd.height = newHeight;
                control.setLayoutData(fd);
                // Utils.relayout(control, false);
                control.getParent().layout();
                Utils.execSWTThreadLater(20, this);
            }
        }
    };
    control.getDisplay().asyncExec(runnable);
}
Also used : AERunnableBoolean(com.biglybt.core.util.AERunnableBoolean) AERunnable(com.biglybt.core.util.AERunnable) AERunnable(com.biglybt.core.util.AERunnable) Point(org.eclipse.swt.graphics.Point) AERunnableBoolean(com.biglybt.core.util.AERunnableBoolean) Point(org.eclipse.swt.graphics.Point)

Aggregations

AERunnableBoolean (com.biglybt.core.util.AERunnableBoolean)2 DownloadManager (com.biglybt.core.download.DownloadManager)1 GlobalManager (com.biglybt.core.global.GlobalManager)1 AERunnable (com.biglybt.core.util.AERunnable)1 ToolBarItem (com.biglybt.ui.common.ToolBarItem)1 TableView (com.biglybt.ui.common.table.TableView)1 SWTSkinObject (com.biglybt.ui.swt.skin.SWTSkinObject)1 Clipboard (org.eclipse.swt.dnd.Clipboard)1 Point (org.eclipse.swt.graphics.Point)1