Search in sources :

Example 1 with SWTSkin

use of com.biglybt.ui.swt.skin.SWTSkin in project BiglyBT by BiglySoftware.

the class SB_Dashboard method build.

private Composite build(Composite sf, final DashboardItem item, boolean use_tabs) {
    Composite g = use_tabs ? new Composite(sf, SWT.NULL) : new Group(sf, SWT.NULL);
    g.setLayoutData(Utils.getFilledFormData());
    g.setLayout(new GridLayout());
    g.setData(Utils.RELAYOUT_UP_STOP_HERE, true);
    try {
        if (g instanceof Group) {
            ((Group) g).setText(item.getTitle());
        }
        Composite menu_comp = use_tabs ? sf : g;
        Menu menu = new Menu(menu_comp);
        org.eclipse.swt.widgets.MenuItem itemReload = new org.eclipse.swt.widgets.MenuItem(menu, SWT.PUSH);
        Messages.setLanguageText(itemReload, "Button.reload");
        final Runnable reload_action = new Runnable() {

            public void run() {
                if (Utils.isSWTThread()) {
                    if (!g.isDisposed()) {
                        Utils.disposeComposite(g, false);
                        SkinnedComposite skinned_comp = new SkinnedComposite(g);
                        SWTSkin skin = skinned_comp.getSkin();
                        BaseMdiEntry.importStandAlone((SWTSkinObjectContainer) skin.getSkinObject("content-area"), item.getState(), this);
                        Control c = ((SWTSkinObjectContainer) skin.getSkinObject("content-area")).getControl();
                        c.setLayoutData(Utils.getFilledFormData());
                        g.layout(true, true);
                    }
                } else {
                    Utils.execSWTThread(this);
                }
            }
        };
        sf.setData(reload_action);
        itemReload.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent arg0) {
                reload_action.run();
            }
        });
        org.eclipse.swt.widgets.MenuItem itemPop = new org.eclipse.swt.widgets.MenuItem(menu, SWT.PUSH);
        Messages.setLanguageText(itemPop, "menu.pop.out");
        itemPop.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent arg0) {
                SkinnedDialog skinnedDialog = new SkinnedDialog("skin3_dlg_sidebar_popout", "shell", // standalone
                null, SWT.RESIZE | SWT.MAX | SWT.DIALOG_TRIM);
                SWTSkin skin = skinnedDialog.getSkin();
                SWTSkinObjectContainer cont = BaseMdiEntry.importStandAlone((SWTSkinObjectContainer) skin.getSkinObject("content-area"), item.getState(), null);
                if (cont != null) {
                    skinnedDialog.setTitle(item.getTitle());
                    skinnedDialog.open();
                } else {
                    skinnedDialog.close();
                }
            }
        });
        new org.eclipse.swt.widgets.MenuItem(menu, SWT.SEPARATOR);
        org.eclipse.swt.widgets.MenuItem itemRemove = new org.eclipse.swt.widgets.MenuItem(menu, SWT.PUSH);
        Messages.setLanguageText(itemRemove, "MySharesView.menu.remove");
        Utils.setMenuItemImage(itemRemove, "delete");
        itemRemove.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent arg0) {
                item.remove();
            }
        });
        menu_comp.setMenu(menu);
        SkinnedComposite skinned_comp = new SkinnedComposite(g);
        SWTSkin skin = skinned_comp.getSkin();
        BaseMdiEntry.importStandAlone((SWTSkinObjectContainer) skin.getSkinObject("content-area"), item.getState(), reload_action);
        Control c = ((SWTSkinObjectContainer) skin.getSkinObject("content-area")).getControl();
        c.setLayoutData(Utils.getFilledFormData());
        c.addListener(SWT.Show, new Listener() {

            @Override
            public void handleEvent(Event arg0) {
                g.layout(true, true);
            }
        });
    } catch (Throwable e) {
        Debug.out(e);
    }
    return (g);
}
Also used : Group(org.eclipse.swt.widgets.Group) MenuItemListener(com.biglybt.pif.ui.menus.MenuItemListener) MdiListener(com.biglybt.ui.mdi.MdiListener) MdiEntryVitalityImageListener(com.biglybt.ui.mdi.MdiEntryVitalityImageListener) MenuItemFillListener(com.biglybt.pif.ui.menus.MenuItemFillListener) PaintListener(org.eclipse.swt.events.PaintListener) ControlListener(org.eclipse.swt.events.ControlListener) Listener(org.eclipse.swt.widgets.Listener) UIInputReceiverListener(com.biglybt.pif.ui.UIInputReceiverListener) MenuDetectListener(org.eclipse.swt.events.MenuDetectListener) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) MenuItem(com.biglybt.pif.ui.menus.MenuItem) SWTSkin(com.biglybt.ui.swt.skin.SWTSkin) GridLayout(org.eclipse.swt.layout.GridLayout) Control(org.eclipse.swt.widgets.Control) SWTSkinObjectContainer(com.biglybt.ui.swt.skin.SWTSkinObjectContainer) SelectionEvent(org.eclipse.swt.events.SelectionEvent) PaintEvent(org.eclipse.swt.events.PaintEvent) MouseEvent(org.eclipse.swt.events.MouseEvent) TimerEvent(com.biglybt.core.util.TimerEvent) MenuDetectEvent(org.eclipse.swt.events.MenuDetectEvent) Event(org.eclipse.swt.widgets.Event) ControlEvent(org.eclipse.swt.events.ControlEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Menu(org.eclipse.swt.widgets.Menu)

Example 2 with SWTSkin

use of com.biglybt.ui.swt.skin.SWTSkin in project BiglyBT by BiglySoftware.

the class DeviceTemplateChooser method open.

public void open(DeviceTemplateClosedListener l) {
    this.listener = l;
    skinnedDialog = new SkinnedDialog("skin3_dlg_deviceadd_mfchooser", "shell", SWT.TITLE | SWT.BORDER);
    skinnedDialog.addCloseListener(new SkinnedDialogClosedListener() {

        @Override
        public void skinDialogClosed(SkinnedDialog dialog) {
            if (listener != null) {
                listener.deviceTemplateChooserClosed(selectedDeviceTemplate);
            }
        }
    });
    SWTSkin skin = skinnedDialog.getSkin();
    SWTSkinObject so = skin.getSkinObject("list");
    if (so instanceof SWTSkinObjectContainer) {
        SWTSkinObjectContainer soList = (SWTSkinObjectContainer) so;
        createDeviceTemplateList2(soList);
    }
    skinnedDialog.open();
}
Also used : SWTSkinObject(com.biglybt.ui.swt.skin.SWTSkinObject) SWTSkinObjectContainer(com.biglybt.ui.swt.skin.SWTSkinObjectContainer) SkinnedDialog(com.biglybt.ui.swt.views.skin.SkinnedDialog) SkinnedDialogClosedListener(com.biglybt.ui.swt.views.skin.SkinnedDialog.SkinnedDialogClosedListener) SWTSkin(com.biglybt.ui.swt.skin.SWTSkin)

Example 3 with SWTSkin

use of com.biglybt.ui.swt.skin.SWTSkin in project BiglyBT by BiglySoftware.

the class DebugMenuHelper method createDebugMenuItem.

/**
 * Creates the Debug menu and its children
 * NOTE: This is a development only menu and so it's not modularized into separate menu items
 * because this menu is always rendered in its entirety
 * @param menu
 * @param mainWindow
 * @return
 */
public static MenuItem createDebugMenuItem(final Menu menuDebug) {
    MenuItem item;
    final UIFunctionsSWT uiFunctions = UIFunctionsManagerSWT.getUIFunctionsSWT();
    if (null == uiFunctions) {
        throw new IllegalStateException("UIFunctionsManagerSWT.getUIFunctionsSWT() is returning null");
    }
    item = new MenuItem(menuDebug, SWT.CASCADE);
    item.setText("Run GC");
    item.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event event) {
            System.gc();
        }
    });
    item = new MenuItem(menuDebug, SWT.PUSH);
    item.setText("&CoreReq");
    item.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event event) {
            CoreWaiterSWT.waitForCoreRunning(new CoreRunningListener() {

                @Override
                public void coreRunning(Core core) {
                    new MessageBoxShell(0, "Done", "Core Now Avail").open(null);
                }
            });
        }
    });
    /*
		item = new MenuItem(menuDebug, SWT.CASCADE);
		item.setText("Subscriptions");
		Menu menuSubscriptions = new Menu(menuDebug.getParent(), SWT.DROP_DOWN);
		item.setMenu(menuSubscriptions);

		item = new MenuItem(menuSubscriptions, SWT.NONE);
		item.setText("Create RSS Feed");
		item.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent e) {
				final Shell shell = new Shell(uiFunctions.getMainShell());
				shell.setLayout(new FormLayout());

				Label label = new Label(shell,SWT.NONE);
				label.setText("RSS Feed URL :");
				final Text urlText = new Text(shell,SWT.BORDER);
				urlText.setText(Utils.getLinkFromClipboard(shell.getDisplay(),false));
				Label separator = new Label(shell,SWT.SEPARATOR | SWT.HORIZONTAL);
				Button cancel = new Button(shell,SWT.PUSH);
				cancel.setText("Cancel");
				Button ok = new Button(shell,SWT.PUSH);
				ok.setText("Ok");

				FormData data;

				data = new FormData();
				data.left = new FormAttachment(0,5);
				data.right = new FormAttachment(100,-5);
				data.top = new FormAttachment(0,5);
				label.setLayoutData(data);

				data = new FormData();
				data.left = new FormAttachment(0,5);
				data.right = new FormAttachment(100,-5);
				data.top = new FormAttachment(label);
				data.width = 400;
				urlText.setLayoutData(data);

				data = new FormData();
				data.left = new FormAttachment(0,5);
				data.right = new FormAttachment(100,-5);
				data.top = new FormAttachment(urlText);
				separator.setLayoutData(data);

				data = new FormData();
				data.right = new FormAttachment(ok);
				data.width = 100;
				data.top = new FormAttachment(separator);
				cancel.setLayoutData(data);

				data = new FormData();
				data.right = new FormAttachment(100,-5);
				data.width = 100;
				data.top = new FormAttachment(separator);
				ok.setLayoutData(data);

				cancel.addListener(SWT.Selection, new Listener() {
					public void handleEvent(Event arg0) {
						shell.dispose();
					}
				});

				ok.addListener(SWT.Selection, new Listener() {
					public void handleEvent(Event arg0) {
						String url_str = urlText.getText();
						shell.dispose();

						try{
							URL	url = new URL( url_str );

							SubscriptionManagerFactory.getSingleton().createSingletonRSS( url_str, url, 120, true );

						}catch( Throwable e ){

							Debug.printStackTrace(e);
						}
					}
				});

				shell.pack();


				Utils.centerWindowRelativeTo(shell, uiFunctions.getMainShell());

				shell.open();
				shell.setFocus();
				urlText.setFocus();


			}
		});
		 */
    item = new MenuItem(menuDebug, SWT.CASCADE);
    item.setText("DW");
    Menu menuBrowserTB = new Menu(menuDebug.getParent(), SWT.DROP_DOWN);
    item.setMenu(menuBrowserTB);
    item = new MenuItem(menuBrowserTB, SWT.NONE);
    item.setText("popup check");
    item.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            boolean oldDebug = DonationWindow.DEBUG;
            DonationWindow.DEBUG = true;
            DonationWindow.checkForDonationPopup();
            DonationWindow.DEBUG = oldDebug;
        }
    });
    item = new MenuItem(menuBrowserTB, SWT.NONE);
    item.setText("show");
    item.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            boolean oldDebug = DonationWindow.DEBUG;
            DonationWindow.DEBUG = true;
            DonationWindow.open(true, "debug");
            DonationWindow.DEBUG = oldDebug;
        }
    });
    item = new MenuItem(menuDebug, SWT.NONE);
    item.setText("Alerts");
    item.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            String text = "This is a  long message with lots of information and " + "stuff you really should read.  Are you still reading? Good, because " + "reading <a href=\"http://moo.com\">stimulates</a> the mind.\n\nYeah Baby.";
            LogAlert logAlert = new LogAlert(true, LogAlert.AT_INFORMATION, "Simple");
            Logger.log(logAlert);
            logAlert = new LogAlert(true, LogAlert.AT_WARNING, text);
            logAlert.details = "Details: \n\n" + text;
            Logger.log(logAlert);
            logAlert = new LogAlert(true, LogAlert.AT_ERROR, "ShortText");
            logAlert.details = "Details";
            Logger.log(logAlert);
        }
    });
    item = new MenuItem(menuDebug, SWT.NONE);
    item.setText("MsgBox");
    item.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            VuzeMessageBox box = new VuzeMessageBox("Title", "Text", new String[] { "Ok", "Cancel" }, 0);
            box.setListener(new VuzeMessageBoxListener() {

                @Override
                public void shellReady(Shell shell, SWTSkinObjectContainer soExtra) {
                    SWTSkin skin = soExtra.getSkin();
                    skin.createSkinObject("dlg.generic.test", "dlg.generic.test", soExtra);
                    skin.layout(soExtra);
                    shell.layout(true, true);
                }
            });
            box.open(null);
        }
    });
    item = new MenuItem(menuDebug, SWT.CASCADE);
    item.setText("Size");
    Menu menuSize = new Menu(menuDebug.getParent(), SWT.DROP_DOWN);
    item.setMenu(menuSize);
    int[] sizes = { 640, 430, 800, 550, 1024, 718, 1280, 700, 1440, 850, 1600, 1050, 1920, 1150 };
    for (int i = 0; i < sizes.length; i += 2) {
        final int x = sizes[i];
        final int y = sizes[i + 1];
        item = new MenuItem(menuSize, SWT.NONE);
        item.setText("" + x + "," + y);
        item.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                UIFunctionsManagerSWT.getUIFunctionsSWT().getMainShell().setSize(x, y);
            }
        });
    }
    item = new MenuItem(menuDebug, SWT.NONE);
    item.setText("Obfuscated Shell Image");
    item.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent ev) {
            Display display = Display.getCurrent();
            java.util.List<Image> shell_images = UIDebugGenerator.getShellImages();
            Image biggest_image = null;
            long biggest_area = 0;
            for (Image image : shell_images) {
                Shell shell2 = new Shell(display);
                Rectangle bounds = image.getBounds();
                long area = bounds.width * bounds.height;
                if (area > biggest_area) {
                    biggest_image = image;
                }
                Point size = shell2.computeSize(bounds.width, bounds.height);
                shell2.setSize(size);
                shell2.setBackgroundImage(image);
                shell2.open();
            }
            if (biggest_image != null) {
                new Clipboard(display).setContents(new Object[] { biggest_image.getImageData() }, new Transfer[] { ImageTransfer.getInstance() });
            }
        }
    });
    return item;
}
Also used : VuzeMessageBoxListener(com.biglybt.ui.swt.views.skin.VuzeMessageBoxListener) CoreRunningListener(com.biglybt.core.CoreRunningListener) ObfuscateShell(com.biglybt.ui.swt.debug.ObfuscateShell) MessageBoxShell(com.biglybt.ui.swt.shells.MessageBoxShell) SWTSkinObjectContainer(com.biglybt.ui.swt.skin.SWTSkinObjectContainer) CoreRunningListener(com.biglybt.core.CoreRunningListener) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Core(com.biglybt.core.Core) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) MessageBoxShell(com.biglybt.ui.swt.shells.MessageBoxShell) UIFunctionsSWT(com.biglybt.ui.swt.UIFunctionsSWT) SWTSkin(com.biglybt.ui.swt.skin.SWTSkin) Transfer(org.eclipse.swt.dnd.Transfer) ImageTransfer(org.eclipse.swt.dnd.ImageTransfer) SelectionEvent(org.eclipse.swt.events.SelectionEvent) VuzeMessageBoxListener(com.biglybt.ui.swt.views.skin.VuzeMessageBoxListener) Clipboard(org.eclipse.swt.dnd.Clipboard) VuzeMessageBox(com.biglybt.ui.swt.views.skin.VuzeMessageBox)

Example 4 with SWTSkin

use of com.biglybt.ui.swt.skin.SWTSkin in project BiglyBT by BiglySoftware.

the class MainMenuV3 method buildSimpleViewMenu.

/**
 * @param viewMenu
 *
 * @since 4.5.0.3
 */
private void buildSimpleViewMenu(final Menu viewMenu, int accelerator) {
    try {
        MenuFactory.addMenuItem(viewMenu, SWT.CHECK, PREFIX_V3 + ".view.sidebar", new Listener() {

            @Override
            public void handleEvent(Event event) {
                SideBar sidebar = (SideBar) SkinViewManager.getByClass(SideBar.class);
                if (sidebar != null) {
                    sidebar.flipSideBarVisibility();
                }
            }
        });
        if (COConfigurationManager.getIntParameter("User Mode") > 1) {
            SWTSkin skin = SWTSkinFactory.getInstance();
            SWTSkinObject plugin_bar = skin.getSkinObject(SkinConstants.VIEWID_PLUGINBAR);
            if (plugin_bar != null) {
                MenuItem mi = MainMenuV3.createViewMenuItem(skin, viewMenu, "v3.MainWindow.menu.view." + SkinConstants.VIEWID_PLUGINBAR, SkinConstants.VIEWID_PLUGINBAR + ".visible", SkinConstants.VIEWID_PLUGINBAR, true, -1);
                if (accelerator != -1 && mi.getAccelerator() == accelerator) {
                    Listener[] listeners = mi.getListeners(SWT.Selection);
                    for (Listener l : listeners) {
                        try {
                            l.handleEvent(null);
                        } catch (Throwable e) {
                        }
                    }
                }
            }
        }
        MenuFactory.addViewToolbarMenuItem(viewMenu);
        // ///////
        MenuItem itemStatusBar = MenuFactory.createTopLevelMenuItem(viewMenu, "v3.MainWindow.menu.view.statusbar");
        itemStatusBar.setText(itemStatusBar.getText());
        Menu menuStatusBar = itemStatusBar.getMenu();
        final String[] statusAreaLangs = { "ConfigView.section.style.status.show_sr", "ConfigView.section.style.status.show_nat", "ConfigView.section.style.status.show_ddb", "ConfigView.section.style.status.show_ipf" };
        final String[] statusAreaConfig = { "Status Area Show SR", "Status Area Show NAT", "Status Area Show DDB", "Status Area Show IPF" };
        for (int i = 0; i < statusAreaConfig.length; i++) {
            final String configID = statusAreaConfig[i];
            String langID = statusAreaLangs[i];
            final MenuItem item = new MenuItem(menuStatusBar, SWT.CHECK);
            Messages.setLanguageText(item, langID);
            item.addListener(SWT.Selection, new Listener() {

                @Override
                public void handleEvent(Event event) {
                    COConfigurationManager.setParameter(configID, !COConfigurationManager.getBooleanParameter(configID));
                }
            });
            menuStatusBar.addListener(SWT.Show, new Listener() {

                @Override
                public void handleEvent(Event event) {
                    item.setSelection(COConfigurationManager.getBooleanParameter(configID));
                }
            });
        }
        if (Constants.isWindows) {
            MenuFactory.addSeparatorMenuItem(viewMenu);
        }
        boolean needsSep = false;
        boolean enabled = COConfigurationManager.getBooleanParameter("Beta Programme Enabled");
        if (enabled) {
            MenuFactory.addMenuItem(viewMenu, SWT.CHECK, PREFIX_V2 + ".view.beta", new Listener() {

                @Override
                public void handleEvent(Event event) {
                    MultipleDocumentInterface mdi = UIFunctionsManager.getUIFunctions().getMDI();
                    if (mdi != null) {
                        mdi.showEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_BETAPROGRAM);
                    }
                }
            });
            needsSep = true;
        }
        if (needsSep) {
            MenuFactory.addSeparatorMenuItem(viewMenu);
        }
        needsSep = PluginsMenuHelper.getInstance().buildViewMenu(viewMenu, viewMenu.getShell());
        if (COConfigurationManager.getBooleanParameter("Library.EnableSimpleView")) {
            if (needsSep) {
                MenuFactory.addSeparatorMenuItem(viewMenu);
            }
            // Ubuntu Unity (14.04) with SWT 4508 crashes when global View menu triggered as it appears
            // that radio menu items aren't supported
            // https://bugs.eclipse.org/bugs/show_bug.cgi?id=419729#c9
            int simple_advanced_menu_type = Constants.isLinux ? SWT.CHECK : SWT.RADIO;
            MenuFactory.addMenuItem(viewMenu, simple_advanced_menu_type, PREFIX_V3 + ".view.asSimpleList", new Listener() {

                @Override
                public void handleEvent(Event event) {
                    UIToolBarManager tb = UIToolBarManagerImpl.getInstance();
                    if (tb != null) {
                        UIToolBarItem item = tb.getToolBarItem("modeBig");
                        if (item != null) {
                            item.triggerToolBarItem(UIToolBarActivationListener.ACTIVATIONTYPE_NORMAL, SelectedContentManager.convertSelectedContentToObject(null));
                        }
                    }
                }
            });
            MenuFactory.addMenuItem(viewMenu, simple_advanced_menu_type, PREFIX_V3 + ".view.asAdvancedList", new Listener() {

                @Override
                public void handleEvent(Event event) {
                    UIToolBarManager tb = UIToolBarManagerImpl.getInstance();
                    if (tb != null) {
                        UIToolBarItem item = tb.getToolBarItem("modeSmall");
                        if (item != null) {
                            item.triggerToolBarItem(UIToolBarActivationListener.ACTIVATIONTYPE_NORMAL, SelectedContentManager.convertSelectedContentToObject(null));
                        }
                    }
                }
            });
        }
        viewMenu.addMenuListener(new MenuListener() {

            @Override
            public void menuShown(MenuEvent e) {
                MenuItem sidebarMenuItem = MenuFactory.findMenuItem(viewMenu, PREFIX_V3 + ".view.sidebar");
                if (sidebarMenuItem != null) {
                    MultipleDocumentInterface mdi = UIFunctionsManager.getUIFunctions().getMDI();
                    if (mdi != null) {
                        sidebarMenuItem.setSelection(mdi.isVisible());
                    }
                }
                if (COConfigurationManager.getBooleanParameter("Library.EnableSimpleView")) {
                    MenuItem itemShowAsSimple = MenuFactory.findMenuItem(viewMenu, PREFIX_V3 + ".view.asSimpleList");
                    if (itemShowAsSimple != null) {
                        UIToolBarManager tb = UIToolBarManagerImpl.getInstance();
                        if (tb != null) {
                            UIToolBarItem item = tb.getToolBarItem("modeBig");
                            long state = item == null ? 0 : item.getState();
                            itemShowAsSimple.setEnabled((state & UIToolBarItem.STATE_ENABLED) > 0);
                            itemShowAsSimple.setSelection((state & UIToolBarItem.STATE_DOWN) > 0);
                        }
                    }
                    MenuItem itemShowAsAdv = MenuFactory.findMenuItem(viewMenu, PREFIX_V3 + ".view.asAdvancedList");
                    if (itemShowAsAdv != null) {
                        UIToolBarManager tb = UIToolBarManagerImpl.getInstance();
                        if (tb != null) {
                            UIToolBarItem item = tb.getToolBarItem("modeSmall");
                            long state = item == null ? 0 : item.getState();
                            itemShowAsAdv.setEnabled((state & UIToolBarItem.STATE_ENABLED) > 0);
                            itemShowAsAdv.setSelection((state & UIToolBarItem.STATE_DOWN) > 0);
                        }
                    }
                }
            }

            @Override
            public void menuHidden(MenuEvent e) {
            }
        });
    } catch (Exception e) {
        Debug.out("Error creating View Menu", e);
    }
}
Also used : ParameterListener(com.biglybt.core.config.ParameterListener) UIToolBarActivationListener(com.biglybt.pif.ui.toolbar.UIToolBarActivationListener) MultipleDocumentInterface(com.biglybt.ui.mdi.MultipleDocumentInterface) SWTSkin(com.biglybt.ui.swt.skin.SWTSkin) UIException(com.biglybt.pif.ui.UIException) SWTSkinObject(com.biglybt.ui.swt.skin.SWTSkinObject) UIToolBarManager(com.biglybt.pif.ui.toolbar.UIToolBarManager) IMainMenu(com.biglybt.ui.swt.mainwindow.IMainMenu) UIToolBarItem(com.biglybt.pif.ui.toolbar.UIToolBarItem) SideBar(com.biglybt.ui.swt.views.skin.sidebar.SideBar)

Example 5 with SWTSkin

use of com.biglybt.ui.swt.skin.SWTSkin in project BiglyBT by BiglySoftware.

the class BaseMdiEntry method importStandAlone.

public static SWTSkinObjectContainer importStandAlone(SWTSkinObjectContainer soParent, Map<String, Object> map, Runnable callback) {
    String mdi_type = (String) map.get("mdi");
    String skin_ref = (String) map.get("skin_ref");
    String skin_id = (String) map.get("skin_id");
    SWTSkin skin = SWTSkinFactory.lookupSkin(skin_id);
    String parent_id = (String) map.get("parent_id");
    String id = (String) map.get("id");
    Object data_source = map.get("data_source");
    if (data_source != null) {
        if (data_source instanceof Map) {
            Map<String, Object> ds_map = (Map<String, Object>) data_source;
            if (ds_map != null) {
                ds_map = new HashMap<String, Object>(ds_map);
                ds_map.put("callback", callback);
            }
            data_source = ds_map == null ? null : DataSourceResolver.importDataSource(ds_map);
        } else if (data_source instanceof List) {
            List l = (List) data_source;
            String type = (String) l.get(0);
            Long value = (Long) l.get(1);
            if (type.equals("i")) {
                data_source = value.intValue();
            }
        }
    }
    int control_type = ((Number) map.get("control_type")).intValue();
    Map<String, Object> el_map = (Map<String, Object>) map.get("event_listener");
    UISWTViewEventListener event_listener = null;
    if (el_map != null) {
        try {
            String class_name = (String) el_map.get("name");
            if (class_name != null) {
                Class<? extends UISWTViewCoreEventListenerEx> cla = (Class<? extends UISWTViewCoreEventListenerEx>) Class.forName(class_name);
                List p_types = (List) el_map.get("p_types");
                List p_vals = (List) el_map.get("p_vals");
                if (p_types != null && !p_types.isEmpty()) {
                    List<Class> types = new ArrayList<>();
                    List<Object> args = new ArrayList<>();
                    for (int i = 0; i < p_types.size(); i++) {
                        String type = (String) p_types.get(i);
                        Object val = p_vals.get(i);
                        if (type.equals("bool")) {
                            types.add(boolean.class);
                            args.add(((Long) val) != 0);
                        } else if (type.equals("long")) {
                            types.add(long.class);
                            args.add((Long) val);
                        } else if (type.equals("string")) {
                            types.add(String.class);
                            args.add((String) val);
                        } else {
                            Debug.out("Unsupported type: " + type);
                        }
                    }
                    event_listener = cla.getConstructor(types.toArray(new Class<?>[types.size()])).newInstance(args.toArray(new Object[args.size()]));
                } else {
                    event_listener = cla.newInstance();
                }
            } else {
                String plugin_id = (String) el_map.get("plugin_id");
                PluginInterface pi = CoreFactory.getSingleton().getPluginManager().getPluginInterfaceByID(plugin_id);
                if (pi != null) {
                    String ipc_method = (String) el_map.get("ipc_method");
                    List p_types = (List) el_map.get("p_types");
                    List p_vals = (List) el_map.get("p_vals");
                    List<Object> args = new ArrayList<>();
                    if (p_types != null && !p_types.isEmpty()) {
                        List<Class> types = new ArrayList<>();
                        for (int i = 0; i < p_types.size(); i++) {
                            String type = (String) p_types.get(i);
                            Object val = p_vals.get(i);
                            if (type.equals("bool")) {
                                types.add(boolean.class);
                                args.add(((Long) val) != 0);
                            } else if (type.equals("long")) {
                                types.add(long.class);
                                args.add((Long) val);
                            } else if (type.equals("string")) {
                                types.add(String.class);
                                args.add((String) val);
                            } else {
                                Debug.out("Unsupported type: " + type);
                            }
                        }
                    }
                    event_listener = (UISWTViewEventListener) pi.getIPC().invoke(ipc_method, args.toArray(new Object[args.size()]));
                } else {
                    boolean try_install = false;
                    synchronized (installing_pids) {
                        if (!installing_pids.contains(plugin_id)) {
                            installing_pids.add(plugin_id);
                            try_install = true;
                        }
                    }
                    if (try_install) {
                        boolean went_async = false;
                        try {
                            UIFunctions uif = UIFunctionsManager.getUIFunctions();
                            String plugin_name = (String) el_map.get("plugin_name");
                            String remember_id = "basemdi.import.view.install." + plugin_id;
                            String title = MessageText.getString("plugin.required");
                            String text = MessageText.getString("plugin.required.info", new String[] { plugin_name });
                            UIFunctionsUserPrompter prompter = uif.getUserPrompter(title, text, new String[] { MessageText.getString("Button.yes"), MessageText.getString("Button.no") }, 0);
                            if (remember_id != null) {
                                prompter.setRemember(remember_id, false, MessageText.getString("MessageBoxWindow.nomoreprompting"));
                            }
                            prompter.setAutoCloseInMS(0);
                            prompter.open(null);
                            boolean install = prompter.waitUntilClosed() == 0;
                            if (install) {
                                went_async = true;
                                uif.installPlugin(plugin_id, "plugin.generic.install", new UIFunctions.actionListener() {

                                    @Override
                                    public void actionComplete(Object result) {
                                        try {
                                            if (callback != null) {
                                                if (result instanceof Boolean) {
                                                    if ((Boolean) result) {
                                                        callback.run();
                                                    }
                                                }
                                            }
                                        } finally {
                                            synchronized (installing_pids) {
                                                installing_pids.remove(plugin_id);
                                            }
                                        }
                                    }
                                });
                            }
                        } finally {
                            if (!went_async) {
                                synchronized (installing_pids) {
                                    installing_pids.remove(plugin_id);
                                }
                            }
                        }
                    }
                }
            }
        } catch (Throwable e) {
            Debug.out(e);
        }
    }
    if (mdi_type.equals("sidebar")) {
        return (SideBarEntrySWT.buildStandAlone(soParent, skin_ref, skin, parent_id, id, data_source, control_type, null, event_listener, true));
    } else {
        return (TabbedEntry.buildStandAlone(soParent, skin_ref, skin, parent_id, id, data_source, control_type, null, event_listener, true));
    }
}
Also used : UIFunctionsUserPrompter(com.biglybt.ui.UIFunctionsUserPrompter) UIFunctions(com.biglybt.ui.UIFunctions) List(java.util.List) PluginInterface(com.biglybt.pif.PluginInterface) UISWTViewEventListener(com.biglybt.ui.swt.pif.UISWTViewEventListener) SWTSkin(com.biglybt.ui.swt.skin.SWTSkin) SWTSkinObject(com.biglybt.ui.swt.skin.SWTSkinObject) PluginUISWTSkinObject(com.biglybt.ui.swt.pif.PluginUISWTSkinObject)

Aggregations

SWTSkin (com.biglybt.ui.swt.skin.SWTSkin)11 SWTSkinObjectContainer (com.biglybt.ui.swt.skin.SWTSkinObjectContainer)8 UserPrompterResultListener (com.biglybt.ui.UserPrompterResultListener)4 SWTSkinObject (com.biglybt.ui.swt.skin.SWTSkinObject)4 VuzeMessageBox (com.biglybt.ui.swt.views.skin.VuzeMessageBox)4 VuzeMessageBoxListener (com.biglybt.ui.swt.views.skin.VuzeMessageBoxListener)4 MessageBoxShell (com.biglybt.ui.swt.shells.MessageBoxShell)3 SWTSkinObjectText (com.biglybt.ui.swt.skin.SWTSkinObjectText)3 SkinnedDialogClosedListener (com.biglybt.ui.swt.views.skin.SkinnedDialog.SkinnedDialogClosedListener)3 SelectionEvent (org.eclipse.swt.events.SelectionEvent)3 UIFunctionsSWT (com.biglybt.ui.swt.UIFunctionsSWT)2 SkinnedDialog (com.biglybt.ui.swt.views.skin.SkinnedDialog)2 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)2 FormData (org.eclipse.swt.layout.FormData)2 RowLayout (org.eclipse.swt.layout.RowLayout)2 Shell (org.eclipse.swt.widgets.Shell)2 Core (com.biglybt.core.Core)1 CoreRunningListener (com.biglybt.core.CoreRunningListener)1 ParameterListener (com.biglybt.core.config.ParameterListener)1 DeviceManufacturer (com.biglybt.core.devices.DeviceManager.DeviceManufacturer)1