Search in sources :

Example 26 with MenuItem

use of com.biglybt.pif.ui.menus.MenuItem in project BiglyBT by BiglySoftware.

the class DeviceManagerUI method buildCategories.

private void buildCategories(boolean full) {
    if (full) {
        MenuManager menu_manager = ui_manager.getMenuManager();
        // renderers
        categoryView renderers_category = addDeviceCategory(Device.DT_MEDIA_RENDERER, "device.renderer.view.title", "image.sidebar.device.renderer");
        categories.add(renderers_category);
        MenuItem re_menu_item = menu_manager.addMenuItem("sidebar." + renderers_category.getKey(), "device.show");
        re_menu_item.setDisposeWithUIDetach(UIInstance.UIT_SWT);
        re_menu_item.addListener(show_listener);
        re_menu_item.addFillListener(show_fill_listener);
        re_menu_item = menu_manager.addMenuItem("sidebar." + renderers_category.getKey(), "sep_re");
        re_menu_item.setDisposeWithUIDetach(UIInstance.UIT_SWT);
        re_menu_item.setStyle(MenuItem.STYLE_SEPARATOR);
        re_menu_item = menu_manager.addMenuItem("sidebar." + renderers_category.getKey(), "device.renderer.remove_all");
        re_menu_item.setDisposeWithUIDetach(UIInstance.UIT_SWT);
        re_menu_item.addListener(new MenuItemListener() {

            @Override
            public void selected(MenuItem menu, Object target) {
                new AEThread2("doit") {

                    @Override
                    public void run() {
                        UIManager ui_manager = StaticUtilities.getUIManager(120 * 1000);
                        long res = ui_manager.showMessageBox("device.mediaserver.remove_all.title", "device.renderer.remove_all.desc", UIManagerEvent.MT_YES | UIManagerEvent.MT_NO);
                        if (res == UIManagerEvent.MT_YES) {
                            Device[] devices = device_manager.getDevices();
                            for (Device d : devices) {
                                if (d.getType() == Device.DT_MEDIA_RENDERER) {
                                    if (d.canRemove()) {
                                        d.remove();
                                    }
                                }
                            }
                        }
                    }
                }.start();
            }
        });
        // media servers
        categoryView media_servers_category = addDeviceCategory(Device.DT_CONTENT_DIRECTORY, "device.mediaserver.view.title", "image.sidebar.device.mediaserver");
        categories.add(media_servers_category);
        MenuItem ms_menu_item = menu_manager.addMenuItem("sidebar." + media_servers_category.getKey(), "device.show");
        ms_menu_item.setDisposeWithUIDetach(UIInstance.UIT_SWT);
        ms_menu_item.addListener(show_listener);
        ms_menu_item.addFillListener(show_fill_listener);
        ms_menu_item = menu_manager.addMenuItem("sidebar." + media_servers_category.getKey(), "device.mediaserver.configure");
        ms_menu_item.setDisposeWithUIDetach(UIInstance.UIT_SWT);
        ms_menu_item.addListener(new MenuItemListener() {

            @Override
            public void selected(MenuItem menu, Object target) {
                UIFunctions uif = UIFunctionsManager.getUIFunctions();
                if (uif != null) {
                    uif.getMDI().showEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_CONFIG, "upnpmediaserver.name");
                }
            }
        });
        ms_menu_item = menu_manager.addMenuItem("sidebar." + media_servers_category.getKey(), "sep_ms");
        ms_menu_item.setDisposeWithUIDetach(UIInstance.UIT_SWT);
        ms_menu_item.setStyle(MenuItem.STYLE_SEPARATOR);
        ms_menu_item = menu_manager.addMenuItem("sidebar." + media_servers_category.getKey(), "device.mediaserver.remove_all");
        ms_menu_item.setDisposeWithUIDetach(UIInstance.UIT_SWT);
        ms_menu_item.addListener(new MenuItemListener() {

            @Override
            public void selected(MenuItem menu, Object target) {
                new AEThread2("doit") {

                    @Override
                    public void run() {
                        UIManager ui_manager = StaticUtilities.getUIManager(120 * 1000);
                        long res = ui_manager.showMessageBox("device.mediaserver.remove_all.title", "device.mediaserver.remove_all.desc", UIManagerEvent.MT_YES | UIManagerEvent.MT_NO);
                        if (res == UIManagerEvent.MT_YES) {
                            Device[] devices = device_manager.getDevices();
                            for (Device d : devices) {
                                if (d.getType() == Device.DT_CONTENT_DIRECTORY) {
                                    if (d.canRemove()) {
                                        d.remove();
                                    }
                                }
                            }
                        }
                    }
                }.start();
            }
        });
        // routers
        categoryView routers_category = addDeviceCategory(Device.DT_INTERNET_GATEWAY, "device.router.view.title", "image.sidebar.device.router");
        categories.add(routers_category);
        MenuItem rt_menu_item = menu_manager.addMenuItem("sidebar." + routers_category.getKey(), "device.show");
        rt_menu_item.setDisposeWithUIDetach(UIInstance.UIT_SWT);
        rt_menu_item.addListener(show_listener);
        rt_menu_item.addFillListener(show_fill_listener);
        rt_menu_item = menu_manager.addMenuItem("sidebar." + routers_category.getKey(), "device.router.configure");
        rt_menu_item.setDisposeWithUIDetach(UIInstance.UIT_SWT);
        rt_menu_item.addListener(new MenuItemListener() {

            @Override
            public void selected(MenuItem menu, Object target) {
                UIFunctions uif = UIFunctionsManager.getUIFunctions();
                if (uif != null) {
                    uif.getMDI().showEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_CONFIG, "UPnP");
                }
            }
        });
    }
    // internet
    categoryView internet_category = addDeviceCategory(Device.DT_INTERNET, "MainWindow.about.section.internet", "image.sidebar.device.internet");
    categories.add(internet_category);
}
Also used : UnassociatedDevice(com.biglybt.core.devices.DeviceManager.UnassociatedDevice) UPnPRootDevice(com.biglybt.net.upnp.UPnPRootDevice) UPnPDevice(com.biglybt.net.upnp.UPnPDevice) UIFunctions(com.biglybt.ui.UIFunctions) TableContextMenuItem(com.biglybt.pif.ui.tables.TableContextMenuItem) MenuItem(com.biglybt.pif.ui.menus.MenuItem)

Example 27 with MenuItem

use of com.biglybt.pif.ui.menus.MenuItem in project BiglyBT by BiglySoftware.

the class DeviceManagerUI method setupEntry.

private void setupEntry(deviceItem new_di, final Device device, String parent) {
    synchronized (DeviceManagerUI.this) {
        if (new_di.isDestroyed()) {
            return;
        }
        deviceView view = new deviceView(parent, device);
        new_di.setView(view);
        String key = parent + "/" + device.getID() + ":" + nextSidebarID();
        final MdiEntry entry;
        int device_type = device.getType();
        if (device_type == Device.DT_MEDIA_RENDERER) {
            entry = mdi.createEntryFromSkinRef(parent, key, "devicerendererview", device.getName(), view, null, false, null);
        } else {
            // Hack so first view gets pre-initialized device object, and new
            // views (pop-out) get a newly built instance.
            UISWTViewBuilderCore builder = new UISWTViewBuilderCore(key, null, view).setParentEntryID(parent).setInitialDatasource(new Object[] { parent, device }).setListenerInstantiator(true, (Builder, swtView) -> new deviceView(parent, device));
            entry = mdi.createEntry(builder, false);
            entry.setExpanded(true);
        }
        entry.setDatasource(device);
        entry.addListener(new MdiCloseListener() {

            @Override
            public void mdiEntryClosed(MdiEntry entry, boolean userClosed) {
                if (device != null) {
                    device.setTransientProperty(DEVICE_IVIEW_KEY, null);
                }
            }
        });
        new_di.setMdiEntry(entry);
        setStatus(device, new_di);
        if (device instanceof TranscodeTarget) {
            entry.addListener(new MdiEntryDropListener() {

                @Override
                public boolean mdiEntryDrop(MdiEntry entry, Object payload) {
                    return handleDrop((TranscodeTarget) device, payload);
                }
            });
        }
        final MenuManager menu_manager = ui_manager.getMenuManager();
        boolean need_sep = false;
        if (device instanceof TranscodeTarget) {
            need_sep = true;
            MenuItem explore_menu_item = menu_manager.addMenuItem("sidebar." + key, "v3.menu.device.exploreTranscodes");
            explore_menu_item.setDisposeWithUIDetach(UIInstance.UIT_SWT);
            explore_menu_item.addListener(new MenuItemListener() {

                @Override
                public void selected(MenuItem menu, Object target) {
                    ManagerUtils.open(((TranscodeTarget) device).getWorkingDirectory());
                }
            });
        }
        if (device instanceof DeviceMediaRenderer) {
            need_sep = true;
            // filter view
            final DeviceMediaRenderer renderer = (DeviceMediaRenderer) device;
            if (renderer.canFilterFilesView()) {
                MenuItem filterfiles_menu_item = menu_manager.addMenuItem("sidebar." + key, "devices.xcode.only.show");
                filterfiles_menu_item.setDisposeWithUIDetach(UIInstance.UIT_SWT);
                filterfiles_menu_item.setStyle(MenuItem.STYLE_CHECK);
                filterfiles_menu_item.addFillListener(new MenuItemFillListener() {

                    @Override
                    public void menuWillBeShown(MenuItem menu, Object data) {
                        menu.setData(Boolean.valueOf(renderer.getFilterFilesView()));
                    }
                });
                filterfiles_menu_item.addListener(new MenuItemListener() {

                    @Override
                    public void selected(MenuItem menu, Object target) {
                        renderer.setFilterFilesView((Boolean) menu.getData());
                    }
                });
            }
            if (renderer.canShowCategories()) {
                MenuItem showcat_menu_item = menu_manager.addMenuItem("sidebar." + key, "devices.xcode.show.cat");
                showcat_menu_item.setDisposeWithUIDetach(UIInstance.UIT_SWT);
                showcat_menu_item.setStyle(MenuItem.STYLE_CHECK);
                showcat_menu_item.addFillListener(new MenuItemFillListener() {

                    @Override
                    public void menuWillBeShown(MenuItem menu, Object data) {
                        menu.setData(Boolean.valueOf(renderer.getShowCategories()));
                    }
                });
                showcat_menu_item.addListener(new MenuItemListener() {

                    @Override
                    public void selected(MenuItem menu, Object target) {
                        renderer.setShowCategories((Boolean) menu.getData());
                    }
                });
            }
            if (!DISABLED_TRANSCODING) {
                MenuItem alwayscache_menu_item = menu_manager.addMenuItem("sidebar." + key, "devices.always.cache");
                alwayscache_menu_item.setDisposeWithUIDetach(UIInstance.UIT_SWT);
                alwayscache_menu_item.setStyle(MenuItem.STYLE_CHECK);
                alwayscache_menu_item.addFillListener(new MenuItemFillListener() {

                    @Override
                    public void menuWillBeShown(MenuItem menu, Object data) {
                        menu.setData(Boolean.valueOf(renderer.getAlwaysCacheFiles()));
                    }
                });
                alwayscache_menu_item.addListener(new MenuItemListener() {

                    @Override
                    public void selected(MenuItem menu, Object target) {
                        renderer.setAlwaysCacheFiles((Boolean) menu.getData());
                    }
                });
            }
        }
        if (need_sep) {
            MenuItem menu_item = menu_manager.addMenuItem("sidebar." + key, "1");
            menu_item.setStyle(MenuItem.STYLE_SEPARATOR);
            menu_item.setDisposeWithUIDetach(UIInstance.UIT_SWT);
        }
        need_sep = false;
        if (device instanceof DeviceMediaRenderer) {
            final DeviceMediaRenderer renderer = (DeviceMediaRenderer) device;
            if (renderer.canCopyToFolder()) {
                need_sep = true;
                MenuItem autocopy_menu_item = menu_manager.addMenuItem("sidebar." + key, "devices.xcode.autoCopy");
                autocopy_menu_item.setDisposeWithUIDetach(UIInstance.UIT_SWT);
                autocopy_menu_item.setStyle(MenuItem.STYLE_CHECK);
                autocopy_menu_item.addFillListener(new MenuItemFillListener() {

                    @Override
                    public void menuWillBeShown(MenuItem menu, Object data) {
                        menu.setData(Boolean.valueOf(renderer.getAutoCopyToFolder()));
                    }
                });
                autocopy_menu_item.addListener(new MenuItemListener() {

                    @Override
                    public void selected(MenuItem menu, Object target) {
                        renderer.setAutoCopyToFolder((Boolean) menu.getData());
                    }
                });
                final MenuItem mancopy_menu_item = menu_manager.addMenuItem("sidebar." + key, "devices.xcode.mancopy");
                mancopy_menu_item.setDisposeWithUIDetach(UIInstance.UIT_SWT);
                mancopy_menu_item.setStyle(MenuItem.STYLE_PUSH);
                mancopy_menu_item.addListener(new MenuItemListener() {

                    @Override
                    public void selected(MenuItem menu, Object target) {
                        try {
                            renderer.manualCopy();
                        } catch (Throwable e) {
                            Debug.out(e);
                        }
                    }
                });
                mancopy_menu_item.addFillListener(new MenuItemFillListener() {

                    @Override
                    public void menuWillBeShown(MenuItem menu, Object data) {
                        boolean enabled = false;
                        if (!renderer.getAutoCopyToFolder()) {
                            File target = renderer.getCopyToFolder();
                            if (target != null && target.exists()) {
                                enabled = renderer.getCopyToFolderPending() > 0;
                            }
                        }
                        mancopy_menu_item.setEnabled(enabled);
                    }
                });
                MenuItem setcopyto_menu_item = menu_manager.addMenuItem("sidebar." + key, "devices.xcode.setcopyto");
                setcopyto_menu_item.setDisposeWithUIDetach(UIInstance.UIT_SWT);
                setcopyto_menu_item.setStyle(MenuItem.STYLE_PUSH);
                setcopyto_menu_item.addListener(new MenuItemListener() {

                    @Override
                    public void selected(MenuItem menu, Object target) {
                        Shell shell = Utils.findAnyShell();
                        DirectoryDialog dd = new DirectoryDialog(shell);
                        File existing = renderer.getCopyToFolder();
                        if (existing != null) {
                            dd.setFilterPath(existing.getAbsolutePath());
                        }
                        dd.setText(MessageText.getString("devices.xcode.setcopyto.title"));
                        String path = dd.open();
                        if (path != null) {
                            renderer.setCopyToFolder(new File(path));
                        }
                    }
                });
            }
            if (renderer.canCopyToDevice()) {
                need_sep = true;
                MenuItem autocopy_menu_item = menu_manager.addMenuItem("sidebar." + key, "devices.xcode.autoCopy.device");
                autocopy_menu_item.setDisposeWithUIDetach(UIInstance.UIT_SWT);
                autocopy_menu_item.setStyle(MenuItem.STYLE_CHECK);
                autocopy_menu_item.addFillListener(new MenuItemFillListener() {

                    @Override
                    public void menuWillBeShown(MenuItem menu, Object data) {
                        menu.setData(Boolean.valueOf(renderer.getAutoCopyToDevice()));
                    }
                });
                autocopy_menu_item.addListener(new MenuItemListener() {

                    @Override
                    public void selected(MenuItem menu, Object target) {
                        renderer.setAutoCopyToDevice((Boolean) menu.getData());
                    }
                });
                final MenuItem mancopy_menu_item = menu_manager.addMenuItem("sidebar." + key, "devices.xcode.mancopy");
                mancopy_menu_item.setDisposeWithUIDetach(UIInstance.UIT_SWT);
                mancopy_menu_item.setStyle(MenuItem.STYLE_PUSH);
                mancopy_menu_item.addListener(new MenuItemListener() {

                    @Override
                    public void selected(MenuItem menu, Object target) {
                        try {
                            renderer.manualCopy();
                        } catch (Throwable e) {
                            Debug.out(e);
                        }
                    }
                });
                mancopy_menu_item.addFillListener(new MenuItemFillListener() {

                    @Override
                    public void menuWillBeShown(MenuItem menu, Object data) {
                        boolean enabled = false;
                        if (!renderer.getAutoCopyToDevice()) {
                            enabled = renderer.getCopyToDevicePending() > 0;
                        }
                        mancopy_menu_item.setEnabled(enabled);
                    }
                });
            }
            if (renderer.canAutoStartDevice()) {
                need_sep = true;
                MenuItem autostart_menu_item = menu_manager.addMenuItem("sidebar." + key, "devices.xcode.autoStart");
                autostart_menu_item.setDisposeWithUIDetach(UIInstance.UIT_SWT);
                autostart_menu_item.setStyle(MenuItem.STYLE_CHECK);
                autostart_menu_item.addFillListener(new MenuItemFillListener() {

                    @Override
                    public void menuWillBeShown(MenuItem menu, Object data) {
                        menu.setData(Boolean.valueOf(renderer.getAutoStartDevice()));
                    }
                });
                autostart_menu_item.addListener(new MenuItemListener() {

                    @Override
                    public void selected(MenuItem menu, Object target) {
                        renderer.setAutoStartDevice((Boolean) menu.getData());
                    }
                });
            }
            if (renderer.canAssociate()) {
                need_sep = true;
                final MenuItem menu_associate = menu_manager.addMenuItem("sidebar." + key, "devices.associate");
                menu_associate.setDisposeWithUIDetach(UIInstance.UIT_SWT);
                menu_associate.setStyle(MenuItem.STYLE_MENU);
                menu_associate.addFillListener(new MenuItemFillListener() {

                    @Override
                    public void menuWillBeShown(MenuItem menu, Object data) {
                        menu_associate.removeAllChildItems();
                        if (renderer.isAlive()) {
                            InetAddress a = renderer.getAddress();
                            String address = a == null ? "" : a.getHostAddress();
                            MenuItem menu_none = menu_manager.addMenuItem(menu_associate, "!" + MessageText.getString("devices.associate.already") + ": " + address + "!");
                            menu_none.setEnabled(false);
                            menu_associate.setEnabled(true);
                        } else {
                            UnassociatedDevice[] unassoc = device_manager.getUnassociatedDevices();
                            if (unassoc.length == 0) {
                                menu_associate.setEnabled(false);
                            } else {
                                menu_associate.setEnabled(true);
                                for (final UnassociatedDevice un : unassoc) {
                                    MenuItem menu_un = menu_manager.addMenuItem(menu_associate, "!" + un.getAddress().getHostAddress() + ": " + un.getDescription() + "!");
                                    menu_un.addListener(new MenuItemListener() {

                                        @Override
                                        public void selected(MenuItem menu, Object target) {
                                            renderer.associate(un);
                                        }
                                    });
                                }
                            }
                        }
                    }
                });
            }
            if (true) {
                need_sep = true;
                final MenuItem menu_ra = menu_manager.addMenuItem("sidebar." + key, "menu.add.file");
                menu_ra.setDisposeWithUIDetach(UIInstance.UIT_SWT);
                menu_ra.addListener(new MenuItemListener() {

                    @Override
                    public void selected(MenuItem menu, Object target) {
                        Utils.execSWTThread(() -> {
                            FileDialog dialog = new FileDialog(Utils.findAnyShell(), SWT.SYSTEM_MODAL | SWT.OPEN | SWT.MULTI);
                            String filter_path = TorrentOpener.getFilterPathData();
                            dialog.setFilterPath(filter_path);
                            dialog.setText(MessageText.getString("wizard.maketorrent.choosefile"));
                            String str = dialog.open();
                            String path = TorrentOpener.setFilterPathData(str);
                            if (path != null) {
                                String[] paths;
                                String[] names = dialog.getFileNames();
                                if (names != null && names.length > 0) {
                                    filter_path = dialog.getFilterPath();
                                    paths = new String[names.length];
                                    for (int i = 0; i < names.length; i++) {
                                        paths[i] = filter_path + File.separator + names[i];
                                    }
                                } else {
                                    paths = new String[] { path };
                                }
                                handleDrop(renderer, paths);
                            }
                        });
                    }
                });
            }
            if (renderer.canRestrictAccess()) {
                need_sep = true;
                final MenuItem menu_ra = menu_manager.addMenuItem("sidebar." + key, "devices.restrict_access");
                menu_ra.setDisposeWithUIDetach(UIInstance.UIT_SWT);
                menu_ra.addListener(new MenuItemListener() {

                    @Override
                    public void selected(MenuItem menu, Object target) {
                        if (target instanceof MdiEntry) {
                            UISWTInputReceiver entry = (UISWTInputReceiver) swt_ui.getInputReceiver();
                            entry.setMessage("devices.restrict_access.msg");
                            entry.setPreenteredText(renderer.getAccessRestriction(), false);
                            entry.maintainWhitespace(false);
                            entry.allowEmptyInput(true);
                            entry.setLocalisedTitle(MessageText.getString("devices.restrict_access.prompt", new String[] { device.getName() }));
                            entry.prompt(new UIInputReceiverListener() {

                                @Override
                                public void UIInputReceiverClosed(UIInputReceiver entry) {
                                    if (!entry.hasSubmittedInput()) {
                                        return;
                                    }
                                    String input = entry.getSubmittedInput().trim();
                                    renderer.setAccessRestriction(input);
                                }
                            });
                        }
                    }
                });
            }
            final TranscodeProfile[] transcodeProfiles = renderer.getTranscodeProfiles();
            if (transcodeProfiles.length > 0) {
                Arrays.sort(transcodeProfiles, new Comparator<TranscodeProfile>() {

                    @Override
                    public int compare(TranscodeProfile o1, TranscodeProfile o2) {
                        int i1 = o1.getIconIndex();
                        int i2 = o2.getIconIndex();
                        if (i1 == i2) {
                            return o1.getName().compareToIgnoreCase(o2.getName());
                        } else {
                            return (i1 - i2);
                        }
                    }
                });
                need_sep = true;
                MenuItem menu_default_profile = menu_manager.addMenuItem("sidebar." + key, "v3.menu.device.defaultprofile");
                menu_default_profile.setDisposeWithUIDetach(UIInstance.UIT_SWT);
                menu_default_profile.setStyle(MenuItem.STYLE_MENU);
                MenuItem menu_profile_never = menu_manager.addMenuItem(menu_default_profile, "v3.menu.device.defaultprofile.never");
                menu_profile_never.setStyle(MenuItem.STYLE_CHECK);
                menu_profile_never.setData(Boolean.TRUE);
                menu_profile_never.addListener(new MenuItemListener() {

                    @Override
                    public void selected(MenuItem menu, Object target) {
                        renderer.setTranscodeRequirement(((Boolean) menu.getData()) ? TranscodeTarget.TRANSCODE_NEVER : TranscodeTarget.TRANSCODE_WHEN_REQUIRED);
                    }
                });
                menu_profile_never.addFillListener(new MenuItemFillListener() {

                    @Override
                    public void menuWillBeShown(MenuItem menu, Object data) {
                        boolean never = renderer.getTranscodeRequirement() == TranscodeTarget.TRANSCODE_NEVER;
                        menu.setData(never);
                    }
                });
                MenuItem menu_profile_none = menu_manager.addMenuItem(menu_default_profile, "option.askeverytime");
                menu_profile_none.setStyle(MenuItem.STYLE_RADIO);
                menu_profile_none.setData(Boolean.FALSE);
                menu_profile_none.addListener(new MenuItemListener() {

                    @Override
                    public void selected(MenuItem menu, Object target) {
                        renderer.setDefaultTranscodeProfile(null);
                    }
                });
                menu_profile_none.addFillListener(new MenuItemFillListener() {

                    @Override
                    public void menuWillBeShown(MenuItem menu, Object data) {
                        if (transcodeProfiles.length <= 1) {
                            menu.setData(Boolean.FALSE);
                            menu.setEnabled(false);
                        } else {
                            TranscodeProfile profile = null;
                            try {
                                profile = renderer.getDefaultTranscodeProfile();
                            } catch (TranscodeException e) {
                            }
                            menu.setData((profile == null) ? Boolean.TRUE : Boolean.FALSE);
                            menu.setEnabled(renderer.getTranscodeRequirement() != TranscodeTarget.TRANSCODE_NEVER);
                        }
                    }
                });
                for (final TranscodeProfile profile : transcodeProfiles) {
                    MenuItem menuItem = menu_manager.addMenuItem(menu_default_profile, "!" + profile.getName() + "!");
                    menuItem.setStyle(MenuItem.STYLE_RADIO);
                    menuItem.setData(Boolean.FALSE);
                    menuItem.addListener(new MenuItemListener() {

                        @Override
                        public void selected(MenuItem menu, Object target) {
                            renderer.setDefaultTranscodeProfile(profile);
                        }
                    });
                    menuItem.addFillListener(new MenuItemFillListener() {

                        @Override
                        public void menuWillBeShown(MenuItem menu, Object data) {
                            if (transcodeProfiles.length <= 1) {
                                menu.setData(Boolean.TRUE);
                                menu.setEnabled(false);
                            } else {
                                TranscodeProfile dprofile = null;
                                try {
                                    dprofile = renderer.getDefaultTranscodeProfile();
                                } catch (TranscodeException e) {
                                }
                                menu.setData((profile.equals(dprofile)) ? Boolean.TRUE : Boolean.FALSE);
                                menu.setEnabled(renderer.getTranscodeRequirement() != TranscodeTarget.TRANSCODE_NEVER);
                            }
                        }
                    });
                }
            }
            if (true) {
                need_sep = true;
                final MenuItem rss_menu_item = menu_manager.addMenuItem("sidebar." + key, "devices.xcode.rsspub");
                rss_menu_item.setDisposeWithUIDetach(UIInstance.UIT_SWT);
                rss_menu_item.setStyle(MenuItem.STYLE_CHECK);
                rss_menu_item.addFillListener(new MenuItemFillListener() {

                    @Override
                    public void menuWillBeShown(MenuItem menu, Object data) {
                        rss_menu_item.setEnabled(device_manager.isRSSPublishEnabled());
                        menu.setData(Boolean.valueOf(device_manager.isRSSPublishEnabled() && renderer.isRSSPublishEnabled()));
                    }
                });
                rss_menu_item.addListener(new MenuItemListener() {

                    @Override
                    public void selected(MenuItem menu, Object target) {
                        renderer.setRSSPublishEnabled((Boolean) menu.getData());
                    }
                });
                rss_menu_item.setEnabled(device_manager.isRSSPublishEnabled());
            }
            if (true) {
                need_sep = true;
                final MenuItem aswt_menu_item = menu_manager.addMenuItem("sidebar." + key, "devices.xcode.tagshare");
                aswt_menu_item.setDisposeWithUIDetach(UIInstance.UIT_SWT);
                aswt_menu_item.setStyle(MenuItem.STYLE_MENU);
                aswt_menu_item.addFillListener(new MenuItemFillListener() {

                    @Override
                    public void menuWillBeShown(MenuItem menu, Object data) {
                        addTagSubMenu(menu_manager, menu, renderer);
                    }
                });
            }
        }
        if (device.isBrowsable()) {
            need_sep = true;
            MenuItem browse_menu_item = menu_manager.addMenuItem("sidebar." + key, "device.browse");
            browse_menu_item.setDisposeWithUIDetach(UIInstance.UIT_SWT);
            browse_menu_item.setStyle(MenuItem.STYLE_MENU);
            browse_menu_item.addFillListener(will_browse_listener);
        }
        if (need_sep) {
            MenuItem menu_item = menu_manager.addMenuItem("sidebar." + key, "s2");
            menu_item.setDisposeWithUIDetach(UIInstance.UIT_SWT);
            menu_item.setStyle(MenuItem.STYLE_SEPARATOR);
        }
        // rename
        MenuItem rename_menu_item = menu_manager.addMenuItem("sidebar." + key, "MyTorrentsView.menu.rename");
        rename_menu_item.setDisposeWithUIDetach(UIInstance.UIT_SWT);
        rename_menu_item.addListener(rename_listener);
        if (device.isExportable()) {
            MenuItem export_item = menu_manager.addMenuItem("sidebar." + key, "Subscription.menu.export");
            export_item.setDisposeWithUIDetach(UIInstance.UIT_SWT);
            export_item.addListener(export_listener);
        }
        // hide
        MenuItem hide_menu_item = menu_manager.addMenuItem("sidebar." + key, "device.hide");
        hide_menu_item.setDisposeWithUIDetach(UIInstance.UIT_SWT);
        hide_menu_item.addListener(hide_listener);
        // tag
        MenuItem tag_menu_item = menu_manager.addMenuItem("sidebar." + key, "device.tag");
        tag_menu_item.setDisposeWithUIDetach(UIInstance.UIT_SWT);
        tag_menu_item.setStyle(MenuItem.STYLE_CHECK);
        tag_menu_item.addFillListener(will_tag_listener);
        tag_menu_item.addListener(tag_listener);
        // remove
        MenuItem remove_menu_item = menu_manager.addMenuItem("sidebar." + key, "MySharesView.menu.remove");
        remove_menu_item.setDisposeWithUIDetach(UIInstance.UIT_SWT);
        remove_menu_item.addFillListener(will_remove_listener);
        remove_menu_item.addListener(remove_listener);
        // sep
        MenuItem menu_item_sep = menu_manager.addMenuItem("sidebar." + key, "s3");
        menu_item_sep.setStyle(MenuItem.STYLE_SEPARATOR);
        menu_item_sep.setDisposeWithUIDetach(UIInstance.UIT_SWT);
        final URL wiki_url = device.getWikiURL();
        if (wiki_url != null) {
            MenuItem wiki_menu_item = menu_manager.addMenuItem("sidebar." + key, "device.wiki");
            wiki_menu_item.setDisposeWithUIDetach(UIInstance.UIT_SWT);
            wiki_menu_item.addListener(new MenuItemListener() {

                @Override
                public void selected(MenuItem menu, Object target) {
                    Utils.launch(wiki_url.toExternalForm());
                }
            });
        }
        // props
        MenuItem menu_item = menu_manager.addMenuItem("sidebar." + key, "Subscription.menu.properties");
        menu_item.setDisposeWithUIDetach(UIInstance.UIT_SWT);
        menu_item.addListener(properties_listener);
    }
}
Also used : DiskManagerFileInfoURL(com.biglybt.core.download.DiskManagerFileInfoURL) URL(java.net.URL) MessageBoxShell(com.biglybt.ui.swt.shells.MessageBoxShell) UnassociatedDevice(com.biglybt.core.devices.DeviceManager.UnassociatedDevice) UISWTViewBuilderCore(com.biglybt.ui.swt.pifimpl.UISWTViewBuilderCore) TableContextMenuItem(com.biglybt.pif.ui.tables.TableContextMenuItem) MenuItem(com.biglybt.pif.ui.menus.MenuItem) Point(org.eclipse.swt.graphics.Point) VuzeFile(com.biglybt.core.vuzefile.VuzeFile) File(java.io.File) DiskManagerFileInfoFile(com.biglybt.core.download.DiskManagerFileInfoFile) InetAddress(java.net.InetAddress)

Example 28 with MenuItem

use of com.biglybt.pif.ui.menus.MenuItem in project BiglyBT by BiglySoftware.

the class PMSWTImpl method initialise.

@Override
public void initialise(final PluginInterface pi, final BooleanParameter icon_enable) {
    final NetworkAdmin na = NetworkAdmin.getSingleton();
    na.addPropertyChangeListener(new NetworkAdminPropertyChangeListener() {

        @Override
        public void propertyChanged(String property) {
            if (property == NetworkAdmin.PR_NETWORK_INTERFACES) {
                updateLocalAddresses(na);
            }
        }
    });
    updateLocalAddresses(na);
    pi.getUIManager().addUIListener(new UIManagerListener() {

        @Override
        public void UIAttached(final UIInstance instance) {
            if (instance instanceof UISWTInstance) {
                ui_attached = true;
                UIFunctions uif = UIFunctionsManager.getUIFunctions();
                if (uif != null) {
                    uiUpdaterListener = new UIUpdaterListener() {

                        @Override
                        public void updateComplete(int count) {
                            last_update_count = count;
                            updateStatus(true);
                        }
                    };
                    uif.getUIUpdater().addListener(uiUpdaterListener);
                }
                Utils.execSWTThread(new AERunnable() {

                    @Override
                    public void runSupport() {
                        ImageLoader imageLoader = ImageLoader.getInstance();
                        icon_idle = imageLoader.getImage("pair_sb_idle");
                        icon_green = imageLoader.getImage("pair_sb_green");
                        icon_red = imageLoader.getImage("pair_sb_red");
                        UISWTInstance ui_instance = (UISWTInstance) instance;
                        status = ui_instance.createStatusEntry();
                        last_tooltip_text = MessageText.getString("pairing.ui.icon.tip");
                        Utils.setTT(status, last_tooltip_text);
                        status.setImageEnabled(true);
                        status.setImage(icon_idle);
                        last_image = icon_idle;
                        boolean is_visible = icon_enable.getValue();
                        status.setVisible(is_visible);
                        if (is_visible) {
                            updateStatus(false);
                        }
                        final MenuItem mi_show = pi.getUIManager().getMenuManager().addMenuItem(status.getMenuContext(), "pairing.ui.icon.show");
                        mi_show.setStyle(MenuItem.STYLE_CHECK);
                        mi_show.setData(Boolean.valueOf(is_visible));
                        mi_show.addListener(new MenuItemListener() {

                            @Override
                            public void selected(MenuItem menu, Object target) {
                                icon_enable.setValue(false);
                            }
                        });
                        iconEnableListener = new ParameterListener() {

                            @Override
                            public void parameterChanged(Parameter param) {
                                boolean is_visible = icon_enable.getValue();
                                status.setVisible(is_visible);
                                mi_show.setData(Boolean.valueOf(is_visible));
                                if (is_visible) {
                                    updateStatus(false);
                                }
                            }
                        };
                        icon_enable.addListener(iconEnableListener);
                        MenuItem mi_pairing = pi.getUIManager().getMenuManager().addMenuItem(status.getMenuContext(), "MainWindow.menu.pairing");
                        mi_pairing.addListener(new MenuItemListener() {

                            @Override
                            public void selected(MenuItem menu, Object target) {
                                UIFunctions uif = UIFunctionsManager.getUIFunctions();
                                if (uif == null) {
                                    Debug.out("UIFunctions not available, can't open remote pairing window");
                                } else {
                                    uif.openRemotePairingWindow();
                                }
                            }
                        });
                        MenuItem mi_sep = pi.getUIManager().getMenuManager().addMenuItem(status.getMenuContext(), "");
                        mi_sep.setStyle(MenuItem.STYLE_SEPARATOR);
                        MenuItem mi_options = pi.getUIManager().getMenuManager().addMenuItem(status.getMenuContext(), "MainWindow.menu.view.configuration");
                        mi_options.addListener(new MenuItemListener() {

                            @Override
                            public void selected(MenuItem menu, Object target) {
                                UIFunctions uif = UIFunctionsManager.getUIFunctions();
                                if (uif != null) {
                                    uif.getMDI().showEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_CONFIG, PairingManager.CONFIG_SECTION_ID);
                                }
                            }
                        });
                        UISWTStatusEntryListener click_listener = new UISWTStatusEntryListener() {

                            @Override
                            public void entryClicked(UISWTStatusEntry entry) {
                                UIFunctions uif = UIFunctionsManager.getUIFunctions();
                                if (uif != null) {
                                    uif.getMDI().showEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_CONFIG, PairingManager.CONFIG_SECTION_ID);
                                }
                            }
                        };
                        status.setListener(click_listener);
                    }
                });
            }
        }

        @Override
        public void UIDetached(UIInstance instance) {
            if (instance instanceof UISWTInstance) {
                ui_attached = false;
                UIFunctions uif = UIFunctionsManager.getUIFunctions();
                if (uif != null && uiUpdaterListener != null) {
                    uif.getUIUpdater().removeListener(uiUpdaterListener);
                    uiUpdaterListener = null;
                }
                if (status != null) {
                    // menu items get destroyed with this call
                    status.destroy();
                    status = null;
                }
                if (icon_enable != null && iconEnableListener != null) {
                    icon_enable.removeListener(iconEnableListener);
                    iconEnableListener = null;
                }
            }
        }
    });
}
Also used : UIUpdaterListener(com.biglybt.ui.common.updater.UIUpdater.UIUpdaterListener) UISWTStatusEntryListener(com.biglybt.ui.swt.pif.UISWTStatusEntryListener) MenuItem(com.biglybt.pif.ui.menus.MenuItem) NetworkAdminPropertyChangeListener(com.biglybt.core.networkmanager.admin.NetworkAdminPropertyChangeListener) NetworkAdmin(com.biglybt.core.networkmanager.admin.NetworkAdmin) UIFunctions(com.biglybt.ui.UIFunctions) UISWTStatusEntry(com.biglybt.ui.swt.pif.UISWTStatusEntry) ParameterListener(com.biglybt.pif.ui.config.ParameterListener) BooleanParameter(com.biglybt.pif.ui.config.BooleanParameter) Parameter(com.biglybt.pif.ui.config.Parameter) MenuItemListener(com.biglybt.pif.ui.menus.MenuItemListener) UISWTInstance(com.biglybt.ui.swt.pif.UISWTInstance) UIManagerListener(com.biglybt.pif.ui.UIManagerListener) ImageLoader(com.biglybt.ui.swt.imageloader.ImageLoader) UIInstance(com.biglybt.pif.ui.UIInstance)

Example 29 with MenuItem

use of com.biglybt.pif.ui.menus.MenuItem in project BiglyBT by BiglySoftware.

the class ColumnDateSizer method init.

private void init() {
    final TableContextMenuItem menuShowTime = addContextMenuItem("TableColumn.menu.date_added.time", MENU_STYLE_HEADER);
    menuShowTime.setStyle(TableContextMenuItem.STYLE_CHECK);
    menuShowTime.addFillListener(new MenuItemFillListener() {

        @Override
        public void menuWillBeShown(MenuItem menu, Object data) {
            menu.setData(showTime);
        }
    });
    menuShowTime.addListener(new MenuItemListener() {

        @Override
        public void selected(MenuItem menu, Object target) {
            showTime = !showTime;
            setUserData("showTime", new Long(showTime ? 1 : 0));
            maxWidthUsed = new int[TimeFormatter.DATEFORMATS_DESC.length];
            maxWidthDate = new Date[TimeFormatter.DATEFORMATS_DESC.length];
            curFormat = -1;
            recalcWidth(new Date(), null);
            if (curFormat < 0) {
                curFormat = TimeFormatter.DATEFORMATS_DESC.length - 1;
            }
        }
    });
    configDateFormatListener = new ParameterListener() {

        @Override
        public void parameterChanged(String parameterName) {
            tableFormatOverride = COConfigurationManager.getStringParameter("Table.column.dateformat", "");
            if (tableFormatOverride == null) {
                tableFormatOverride = "";
            }
            curFormat = -1;
            if (tableFormatOverride.length() == 0) {
                recalcWidth(new Date(), null);
                if (curFormat < 0) {
                    curFormat = TimeFormatter.DATEFORMATS_DESC.length - 1;
                }
                menuShowTime.setVisible(true);
            } else {
                invalidateCells();
                menuShowTime.setVisible(false);
            }
        }
    };
    COConfigurationManager.addAndFireParameterListener("Table.column.dateformat", configDateFormatListener);
    cdf = ViewUtils.addCustomDateFormat(this);
}
Also used : MenuItemFillListener(com.biglybt.pif.ui.menus.MenuItemFillListener) ParameterListener(com.biglybt.core.config.ParameterListener) MenuItem(com.biglybt.pif.ui.menus.MenuItem) MenuItemListener(com.biglybt.pif.ui.menus.MenuItemListener) Date(java.util.Date)

Example 30 with MenuItem

use of com.biglybt.pif.ui.menus.MenuItem in project BiglyBT by BiglySoftware.

the class ChatMDIEntry method setupMdiEntry.

private void setupMdiEntry(UIManager ui_manager) {
    mdi_entry.setViewTitleInfo(this);
    MdiEntryDropListener drop_listener = new MdiEntryDropListener() {

        @Override
        public boolean mdiEntryDrop(MdiEntry entry, Object payload) {
            if (payload instanceof String[]) {
                String[] derp = (String[]) payload;
                if (derp.length > 0) {
                    payload = derp[0];
                }
            }
            if (!(payload instanceof String)) {
                return false;
            }
            MultipleDocumentInterface mdi = UIFunctionsManager.getUIFunctions().getMDI();
            if (mdi != null) {
                String drop = (String) payload;
                if (view == null) {
                    drop_outstanding = drop;
                } else {
                    view.handleDrop(drop);
                }
                mdi.showEntry(mdi_entry);
                return (true);
            } else {
                return (false);
            }
        }
    };
    mdi_entry.addListener(drop_listener);
    mdi_entry.addListener(new MdiCloseListener() {

        @Override
        public void mdiEntryClosed(MdiEntry entry, boolean user) {
            chat.removeListener(adapter);
            chat.destroy();
        }
    });
    String menu_key = "sidebar." + mdi_entry.getViewID();
    MenuManager menu_manager = ui_manager.getMenuManager();
    MenuItem menu_item = menu_manager.addMenuItem(menu_key, "iconBar.remove");
    Utils.setMenuItemImage(menu_item, "delete");
    menu_item.setDisposeWithUIDetach(UIInstance.UIT_SWT);
    menu_item.addListener(new MenuItemListener() {

        @Override
        public void selected(MenuItem menu, Object target) {
            chat.remove();
        }
    });
    menu_item = menu_manager.addMenuItem(menu_key, "sep");
    menu_item.setStyle(MenuItem.STYLE_SEPARATOR);
    mdi_entry.setImageLeftID("image.sidebar.chat-overview");
    chat.addListener(adapter);
}
Also used : MdiEntry(com.biglybt.ui.mdi.MdiEntry) MenuManager(com.biglybt.pif.ui.menus.MenuManager) MenuItem(com.biglybt.pif.ui.menus.MenuItem) MenuItemListener(com.biglybt.pif.ui.menus.MenuItemListener) MultipleDocumentInterface(com.biglybt.ui.mdi.MultipleDocumentInterface) MdiCloseListener(com.biglybt.ui.mdi.MdiCloseListener) MdiEntryDropListener(com.biglybt.ui.mdi.MdiEntryDropListener)

Aggregations

MenuItem (com.biglybt.pif.ui.menus.MenuItem)32 MenuItemListener (com.biglybt.pif.ui.menus.MenuItemListener)19 TableContextMenuItem (com.biglybt.pif.ui.tables.TableContextMenuItem)11 ChatInstance (com.biglybt.plugin.net.buddy.BuddyPluginBeta.ChatInstance)9 UIFunctions (com.biglybt.ui.UIFunctions)9 PluginInterface (com.biglybt.pif.PluginInterface)8 MenuManager (com.biglybt.pif.ui.menus.MenuManager)8 Download (com.biglybt.pif.download.Download)7 UIManager (com.biglybt.pif.ui.UIManager)7 MenuItemFillListener (com.biglybt.pif.ui.menus.MenuItemFillListener)7 List (java.util.List)7 UIInstance (com.biglybt.pif.ui.UIInstance)6 ViewTitleInfo (com.biglybt.ui.common.viewtitleinfo.ViewTitleInfo)6 MultipleDocumentInterface (com.biglybt.ui.mdi.MultipleDocumentInterface)6 ParameterListener (com.biglybt.core.config.ParameterListener)5 UnassociatedDevice (com.biglybt.core.devices.DeviceManager.UnassociatedDevice)5 URL (java.net.URL)5 DownloadManager (com.biglybt.core.download.DownloadManager)4 UPnPDevice (com.biglybt.net.upnp.UPnPDevice)4 UPnPRootDevice (com.biglybt.net.upnp.UPnPRootDevice)4