Search in sources :

Example 31 with UIManager

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

the class TabbedMDI method addMenus.

private void addMenus(TabbedEntry entry, String id) {
    PluginManager pm = CoreFactory.getSingleton().getPluginManager();
    PluginInterface pi = pm.getDefaultPluginInterface();
    UIManager uim = pi.getUIManager();
    MenuManager menuManager = uim.getMenuManager();
    {
        if (!Utils.isAZ2UI()) {
            com.biglybt.pif.ui.menus.MenuItem menuItem = menuManager.addMenuItem(id + "._end_", "menu.add.to.dashboard");
            menuItem.setDisposeWithUIDetach(UIInstance.UIT_SWT);
            menuItem.addFillListener(new MenuItemFillListener() {

                @Override
                public void menuWillBeShown(com.biglybt.pif.ui.menus.MenuItem menu, Object data) {
                    // pick up the right target - due to the confusion of multiple tab instances registering
                    // the same menu entries the original registerer may well not be the one that should receive the event,
                    // rather the one specified in the event is
                    TabbedEntry target = entry;
                    if (data instanceof Object[]) {
                        Object[] odata = (Object[]) data;
                        if (odata.length == 1 && odata[0] instanceof TabbedEntry) {
                            target = (TabbedEntry) odata[0];
                        }
                    }
                    menu.setVisible(target.canBuildStandAlone());
                }
            });
            menuItem.addListener(new MenuItemListener() {

                @Override
                public void selected(com.biglybt.pif.ui.menus.MenuItem menu, Object data) {
                    TabbedEntry target = entry;
                    if (data instanceof Object[]) {
                        Object[] odata = (Object[]) data;
                        if (odata.length == 1 && odata[0] instanceof TabbedEntry) {
                            target = (TabbedEntry) odata[0];
                        }
                    } else if (data instanceof TabbedEntry) {
                        target = (TabbedEntry) data;
                    }
                    MainMDISetup.getSb_dashboard().addItem(target);
                }
            });
        }
    }
    {
        com.biglybt.pif.ui.menus.MenuItem menuItem = menuManager.addMenuItem(id + "._end_", "menu.pop.out");
        menuItem.setDisposeWithUIDetach(UIInstance.UIT_SWT);
        menuItem.addFillListener(new com.biglybt.pif.ui.menus.MenuItemFillListener() {

            @Override
            public void menuWillBeShown(com.biglybt.pif.ui.menus.MenuItem menu, Object data) {
                TabbedEntry target = entry;
                if (data instanceof Object[]) {
                    Object[] odata = (Object[]) data;
                    if (odata.length == 1 && odata[0] instanceof TabbedEntry) {
                        target = (TabbedEntry) odata[0];
                    }
                }
                menu.setVisible(target.canBuildStandAlone());
            }
        });
        menuItem.addListener(new com.biglybt.pif.ui.menus.MenuItemListener() {

            @Override
            public void selected(com.biglybt.pif.ui.menus.MenuItem menu, Object data) {
                TabbedEntry target = entry;
                if (data instanceof Object[]) {
                    Object[] odata = (Object[]) data;
                    if (odata.length == 1 && odata[0] instanceof TabbedEntry) {
                        target = (TabbedEntry) odata[0];
                    }
                } else if (data instanceof TabbedEntry) {
                    target = (TabbedEntry) data;
                }
                SkinnedDialog skinnedDialog = new SkinnedDialog("skin3_dlg_sidebar_popout", "shell", // standalone
                null, SWT.RESIZE | SWT.MAX | SWT.DIALOG_TRIM);
                SWTSkin skin = skinnedDialog.getSkin();
                SWTSkinObjectContainer cont = target.buildStandAlone((SWTSkinObjectContainer) skin.getSkinObject("content-area"));
                if (cont != null) {
                    Object ds = target.getDatasource();
                    if (ds instanceof Object[]) {
                        Object[] temp = (Object[]) ds;
                        if (temp.length > 0) {
                            ds = temp[0];
                        }
                    }
                    String ds_str = "";
                    if (ds instanceof Download) {
                        ds_str = ((Download) ds).getName();
                    } else if (ds instanceof DownloadManager) {
                        ds_str = ((DownloadManager) ds).getDisplayName();
                    }
                    skinnedDialog.setTitle(target.getTitle() + (ds_str.length() == 0 ? "" : (" - " + ds_str)));
                    skinnedDialog.open();
                } else {
                    skinnedDialog.close();
                }
            }
        });
    }
}
Also used : PluginInterface(com.biglybt.pif.PluginInterface) UIManager(com.biglybt.pif.ui.UIManager) DownloadManager(com.biglybt.core.download.DownloadManager) PluginManager(com.biglybt.pif.PluginManager) MenuItemFillListener(com.biglybt.pif.ui.menus.MenuItemFillListener) MenuManager(com.biglybt.pif.ui.menus.MenuManager) PluginUISWTSkinObject(com.biglybt.ui.swt.pif.PluginUISWTSkinObject) MenuItemListener(com.biglybt.pif.ui.menus.MenuItemListener) SkinnedDialog(com.biglybt.ui.swt.views.skin.SkinnedDialog) Download(com.biglybt.pif.download.Download)

Example 32 with UIManager

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

the class TorrentOpener method mergeFileIntoTorrentInfo.

/**
 * Creates a TorrentInfo from a file.  Prompts user if the file is invalid,
 * torrent already exists
 *
 * @param sFileName
 * @param sOriginatingLocation
 * @return
 * @since 5.0.0.1
 */
// TODO: i18n
public static boolean mergeFileIntoTorrentInfo(String sFileName, final String sOriginatingLocation, TorrentOpenOptions torrentOptions) {
    TOTorrent torrent = null;
    File torrentFile;
    boolean bDeleteFileOnCancel = false;
    // actually made a copy.
    try {
        if (sFileName.startsWith("file://localhost/")) {
            sFileName = UrlUtils.decode(sFileName.substring(16));
        }
        final File fOriginal = new File(sFileName);
        if (!fOriginal.isFile() || !fOriginal.exists()) {
            UIFunctionsManager.getUIFunctions().showErrorMessage("OpenTorrentWindow.mb.openError", fOriginal.toString(), new String[] { UrlUtils.decode(sOriginatingLocation), "Not a File" });
            return false;
        }
        if (fOriginal.length() > TorrentUtils.MAX_TORRENT_FILE_SIZE) {
            UIFunctionsManager.getUIFunctions().showErrorMessage("OpenTorrentWindow.mb.openError", fOriginal.toString(), new String[] { UrlUtils.decode(sOriginatingLocation), "Too large to be a torrent" });
            return false;
        }
        torrentFile = TorrentUtils.copyTorrentFileToSaveDir(fOriginal, true);
        bDeleteFileOnCancel = !fOriginal.equals(torrentFile);
    // TODO if the files are still equal, and it isn't in the save
    // dir, we should copy it to a temp file in case something
    // re-writes it.  No need to copy a torrent coming from the
    // downloader though..
    } catch (IOException e1) {
        // Use torrent in wherever it is and hope for the best
        // XXX Should error instead?
        Debug.out(e1);
        torrentFile = new File(sFileName);
    }
    VuzeFileHandler vfh = VuzeFileHandler.getSingleton();
    VuzeFile vf = vfh.loadVuzeFile(torrentFile);
    if (vf != null) {
        vfh.handleFiles(new VuzeFile[] { vf }, VuzeFileComponent.COMP_TYPE_NONE);
        return false;
    }
    if (RSSUtils.isRSSFeed(torrentFile)) {
        boolean done = false;
        try {
            URL url = new URL(sOriginatingLocation);
            UIManager ui_manager = StaticUtilities.getUIManager(10 * 1000);
            if (ui_manager != null) {
                String details = MessageText.getString("subscription.request.add.message", new String[] { sOriginatingLocation });
                long res = ui_manager.showMessageBox("subscription.request.add.title", "!" + details + "!", UIManagerEvent.MT_YES | UIManagerEvent.MT_NO);
                if (res == UIManagerEvent.MT_YES) {
                    SubscriptionManager sm = PluginInitializer.getDefaultInterface().getUtilities().getSubscriptionManager();
                    sm.requestSubscription(url);
                    done = true;
                }
            }
        } catch (Throwable e) {
            Debug.out(e);
        }
        if (done) {
            if (bDeleteFileOnCancel) {
                torrentFile.delete();
            }
            return false;
        }
    }
    // Do a quick check to see if it's a torrent
    if (!TorrentUtil.isFileTorrent(sOriginatingLocation, torrentFile, torrentFile.getName(), !torrentOptions.getHideErrors())) {
        if (bDeleteFileOnCancel) {
            torrentFile.delete();
        }
        return false;
    }
    // Load up the torrent, see it it's real
    try {
        torrent = TorrentUtils.readFromFile(torrentFile, false);
    } catch (final TOTorrentException e) {
        UIFunctionsManager.getUIFunctions().showErrorMessage("OpenTorrentWindow.mb.openError", Debug.getStackTrace(e), new String[] { sOriginatingLocation, e.getMessage() });
        if (bDeleteFileOnCancel)
            torrentFile.delete();
        return false;
    }
    if (bDeleteFileOnCancel) {
        torrentOptions.setDeleteFileOnCancel(bDeleteFileOnCancel);
    }
    torrentOptions.sFileName = torrentFile.getAbsolutePath();
    torrentOptions.setTorrent(torrent);
    torrentOptions.sOriginatingLocation = sOriginatingLocation;
    return torrentOptions.getTorrent() != null;
}
Also used : UIManager(com.biglybt.pif.ui.UIManager) IOException(java.io.IOException) SubscriptionManager(com.biglybt.pif.utils.subscriptions.SubscriptionManager) URL(java.net.URL) TOTorrentException(com.biglybt.core.torrent.TOTorrentException) TOTorrent(com.biglybt.core.torrent.TOTorrent) VuzeFile(com.biglybt.core.vuzefile.VuzeFile) VuzeFile(com.biglybt.core.vuzefile.VuzeFile) File(java.io.File) VuzeFileHandler(com.biglybt.core.vuzefile.VuzeFileHandler)

Example 33 with UIManager

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

the class PlatformManagerImpl method informUpdateRequired.

private boolean informUpdateRequired() {
    UIManager ui_manager = StaticUtilities.getUIManager(120 * 1000);
    long res = ui_manager.showMessageBox("update.now.title", "update.now.desc", UIManagerEvent.MT_OK | UIManagerEvent.MT_CANCEL);
    return (res == UIManagerEvent.MT_OK);
}
Also used : UIManager(com.biglybt.pif.ui.UIManager)

Example 34 with UIManager

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

the class PluginUpdatePlugin method initialize.

@Override
public void initialize(PluginInterface _plugin_interface) {
    plugin_interface = _plugin_interface;
    plugin_interface.getPluginProperties().setProperty("plugin.version", "1.0");
    plugin_interface.getPluginProperties().setProperty("plugin.name", "Plugin Updater");
    log = plugin_interface.getLogger().getChannel("Plugin Update");
    log.setDiagnostic();
    log.setForce(true);
    UIManager ui_manager = plugin_interface.getUIManager();
    final BasicPluginViewModel model = ui_manager.createBasicPluginViewModel(PLUGIN_RESOURCE_ID);
    final PluginConfig plugin_config = plugin_interface.getPluginconfig();
    boolean enabled = plugin_config.getPluginBooleanParameter("enable.update", true);
    model.setConfigSectionID(PLUGIN_CONFIGSECTION_ID);
    model.getStatus().setText(enabled ? "Running" : "Optional checks disabled");
    model.getActivity().setVisible(false);
    model.getProgress().setVisible(false);
    log.addListener(new LoggerChannelListener() {

        @Override
        public void messageLogged(int type, String message) {
            model.getLogArea().appendText(message + "\n");
        }

        @Override
        public void messageLogged(String str, Throwable error) {
            model.getLogArea().appendText(error.toString() + "\n");
        }
    });
    BasicPluginConfigModel config = ui_manager.createBasicPluginConfigModel(ConfigSection.SECTION_PLUGINS, PLUGIN_CONFIGSECTION_ID);
    config.addBooleanParameter2("enable.update", "Plugin.pluginupdate.enablecheck", true);
    plugin_interface.addEventListener(new PluginEventListener() {

        @Override
        public void handleEvent(PluginEvent ev) {
            if (ev.getType() == PluginEvent.PEV_ALL_PLUGINS_INITIALISED) {
                plugin_interface.removeEventListener(this);
                initComplete(plugin_config);
            }
        }
    });
}
Also used : LoggerChannelListener(com.biglybt.pif.logging.LoggerChannelListener) UIManager(com.biglybt.pif.ui.UIManager) BasicPluginViewModel(com.biglybt.pif.ui.model.BasicPluginViewModel) BasicPluginConfigModel(com.biglybt.pif.ui.model.BasicPluginConfigModel)

Example 35 with UIManager

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

the class SBC_ChatOverview method preInitialize.

public static void preInitialize() {
    UIManager ui_manager = PluginInitializer.getDefaultInterface().getUIManager();
    ui_manager.addUIListener(new UIManagerListener() {

        @Override
        public void UIAttached(UIInstance instance) {
            final MultipleDocumentInterface mdi = UIFunctionsManager.getUIFunctions().getMDI();
            if (mdi == null) {
                return;
            }
            mdi.registerEntry("Chat_.*", new MdiEntryCreationListener2() {

                @Override
                public MdiEntry createMDiEntry(MultipleDocumentInterface mdi, String id, Object datasource, Map<?, ?> params) {
                    ChatInstance chat = null;
                    if (datasource instanceof ChatInstance) {
                        chat = (ChatInstance) datasource;
                        try {
                            chat = chat.getClone();
                        } catch (Throwable e) {
                            chat = null;
                            Debug.out(e);
                        }
                    } else if (id.length() > 7) {
                        BuddyPluginBeta beta = BuddyPluginUtils.getBetaPlugin();
                        if (beta != null) {
                            try {
                                String[] bits = id.substring(5).split(":");
                                String network = AENetworkClassifier.internalise(bits[0]);
                                String key = new String(Base32.decode(bits[1]), "UTF-8");
                                chat = beta.getChat(network, key);
                            } catch (Throwable e) {
                                Debug.out(e);
                            }
                        }
                    }
                    if (chat != null) {
                        chat.setAutoNotify(true);
                        return (createChatMdiEntry(chat));
                    }
                    return (null);
                }
            });
        }

        @Override
        public void UIDetached(UIInstance instance) {
        }
    });
}
Also used : MdiEntryCreationListener2(com.biglybt.ui.mdi.MdiEntryCreationListener2) UIManager(com.biglybt.pif.ui.UIManager) SWTSkinObject(com.biglybt.ui.swt.skin.SWTSkinObject) MultipleDocumentInterface(com.biglybt.ui.mdi.MultipleDocumentInterface) BuddyPluginBeta(com.biglybt.plugin.net.buddy.BuddyPluginBeta) UIManagerListener(com.biglybt.pif.ui.UIManagerListener) Map(java.util.Map) TreeMap(java.util.TreeMap) UIInstance(com.biglybt.pif.ui.UIInstance)

Aggregations

UIManager (com.biglybt.pif.ui.UIManager)48 UIInstance (com.biglybt.pif.ui.UIInstance)14 PluginInterface (com.biglybt.pif.PluginInterface)13 UIManagerListener (com.biglybt.pif.ui.UIManagerListener)13 UISWTInstance (com.biglybt.ui.swt.pif.UISWTInstance)10 MenuItemListener (com.biglybt.pif.ui.menus.MenuItemListener)8 MenuItem (com.biglybt.pif.ui.menus.MenuItem)7 MenuManager (com.biglybt.pif.ui.menus.MenuManager)7 LoggerChannelListener (com.biglybt.pif.logging.LoggerChannelListener)6 DownloadManager (com.biglybt.core.download.DownloadManager)5 BasicPluginConfigModel (com.biglybt.pif.ui.model.BasicPluginConfigModel)5 URL (java.net.URL)5 TableManager (com.biglybt.pif.ui.tables.TableManager)4 TableColumnManager (com.biglybt.ui.common.table.impl.TableColumnManager)4 ArrayList (java.util.ArrayList)4 VuzeFile (com.biglybt.core.vuzefile.VuzeFile)3 PluginListener (com.biglybt.pif.PluginListener)3 MenuItemFillListener (com.biglybt.pif.ui.menus.MenuItemFillListener)3 BasicPluginViewModel (com.biglybt.pif.ui.model.BasicPluginViewModel)3 DelayedTask (com.biglybt.pif.utils.DelayedTask)3