Search in sources :

Example 11 with AEThread2

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

the class MessageDispatcherSWT method dispatch.

// @see com.biglybt.ui.swt.browser.msg.MessageDispatcher#dispatch(com.biglybt.core.messenger.browser.BrowserMessage)
@Override
public void dispatch(final BrowserMessage message) {
    if (message == null) {
        return;
    }
    String referer = message.getReferer();
    if (referer != null && !UrlFilter.getInstance().urlCanRPC(referer)) {
        context.debug("blocked " + message + "\n  " + referer);
        return;
    }
    context.debug("Received " + message);
    if (browser != null && !browser.isDisposed() && Utils.isThisThreadSWT()) {
        context.debug("   browser url: " + browser.getUrl());
    }
    // handle messages for dispatcher and context regardless of sequence number
    String listenerId = message.getListenerId();
    if ("lightbox-browser".equals(listenerId)) {
        listenerId = "display";
    }
    final BrowserMessageListener listener = getListener(listenerId);
    if (listener == null) {
        context.debug("No listener registered with ID " + listenerId);
    } else {
        new AEThread2("dispatch for " + listenerId, true) {

            @Override
            public void run() {
                listener.handleMessage(message);
                message.complete(true, true, null);
            }
        }.start();
    }
}
Also used : AEThread2(com.biglybt.core.util.AEThread2) BrowserMessageListener(com.biglybt.core.messenger.browser.listeners.BrowserMessageListener)

Example 12 with AEThread2

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

the class AnimatedImage method start.

public void start() {
    running = true;
    AEThread2 runner = new AEThread2("image runner", true) {

        @Override
        public void run() {
            while (running) {
                try {
                    renderNextImage();
                    Thread.sleep(SPEED);
                } catch (Exception e) {
                    running = false;
                }
            }
        }
    };
    runner.start();
}
Also used : AEThread2(com.biglybt.core.util.AEThread2)

Example 13 with AEThread2

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

the class ExternalSeedPlugin method initialize.

@Override
public void initialize(PluginInterface _plugin_interface) {
    plugin_interface = _plugin_interface;
    dm_stats = plugin_interface.getDownloadManager().getStats();
    log = plugin_interface.getLogger().getTimeStampedChannel("External Seeds");
    final BasicPluginViewModel view_model = plugin_interface.getUIManager().createBasicPluginViewModel("Plugin.extseed.name");
    view_model.getActivity().setVisible(false);
    view_model.getProgress().setVisible(false);
    log.addListener(new LoggerChannelListener() {

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

        @Override
        public void messageLogged(String str, Throwable error) {
            if (str.length() > 0) {
                view_model.getLogArea().appendText(str + "\n");
            }
            StringWriter sw = new StringWriter();
            PrintWriter pw = new PrintWriter(sw);
            error.printStackTrace(pw);
            pw.flush();
            view_model.getLogArea().appendText(sw.toString() + "\n");
        }
    });
    status_field = view_model.getStatus();
    setStatus("Initialising");
    download_mon = plugin_interface.getUtilities().getMonitor();
    Utilities utilities = plugin_interface.getUtilities();
    final DelayedTask dt = plugin_interface.getUtilities().createDelayedTask(new Runnable() {

        @Override
        public void run() {
            AEThread2 t = new AEThread2("ExternalSeedInitialise", true) {

                @Override
                public void run() {
                    setStatus("Running");
                    plugin_interface.getDownloadManager().addListener(ExternalSeedPlugin.this);
                }
            };
            t.setPriority(Thread.MIN_PRIORITY);
            t.start();
        }
    });
    dt.queue();
    UTTimer timer = utilities.createTimer("ExternalPeerScheduler", true);
    timer.addPeriodicEvent(5000, new UTTimerEventPerformer() {

        @Override
        public void perform(UTTimerEvent event) {
            try {
                Iterator it = download_map.values().iterator();
                while (it.hasNext()) {
                    List peers = randomiseList((List) it.next());
                    for (int i = 0; i < peers.size(); i++) {
                        if (((ExternalSeedPeer) peers.get(i)).checkConnection()) {
                            break;
                        }
                    }
                }
            } catch (Throwable e) {
            // we do this without holding the monitor as doing so causes potential
            // deadlock between download_mon and the connection's connection_mon
            // so ignore possible errors here that may be caused by concurrent
            // modification to the download_map ans associated lists. We are only
            // reading the data so errors will only be transient
            }
        }
    });
}
Also used : LoggerChannelListener(com.biglybt.pif.logging.LoggerChannelListener) BasicPluginViewModel(com.biglybt.pif.ui.model.BasicPluginViewModel) AEThread2(com.biglybt.core.util.AEThread2) StringWriter(java.io.StringWriter) PrintWriter(java.io.PrintWriter)

Example 14 with AEThread2

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

the class ConfigSectionInterfaceAlerts method playSoundWhen.

private void playSoundWhen(final Composite cArea, Image imgOpenFolder, String announceEnableConfig, String announceKeyConfig, String announceResource, String playEnableConfig, String playKeyConfig, String playResource) {
    if (Constants.isOSX) {
        // download info
        new BooleanParameter(cArea, announceEnableConfig, announceResource);
        final StringParameter d_speechParameter = new StringParameter(cArea, announceKeyConfig);
        GridData gridData = new GridData();
        gridData.horizontalSpan = 3;
        gridData.widthHint = 150;
        d_speechParameter.setLayoutData(gridData);
        ((Text) d_speechParameter.getControl()).setTextLimit(40);
    }
    new BooleanParameter(cArea, playEnableConfig, playResource);
    // download info
    GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
    final StringParameter e_pathParameter = new StringParameter(cArea, playKeyConfig, "");
    if (e_pathParameter.getValue().length() == 0) {
        e_pathParameter.setValue("<default>");
    }
    e_pathParameter.setLayoutData(gridData);
    Button d_browse = new Button(cArea, SWT.PUSH);
    d_browse.setImage(imgOpenFolder);
    imgOpenFolder.setBackground(d_browse.getBackground());
    d_browse.setToolTipText(MessageText.getString("ConfigView.button.browse"));
    d_browse.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event event) {
            FileDialog dialog = new FileDialog(cArea.getShell(), SWT.APPLICATION_MODAL);
            dialog.setFilterExtensions(new String[] { "*.wav" });
            dialog.setFilterNames(new String[] { "*.wav" });
            dialog.setText(MessageText.getString("ConfigView.section.interface.wavlocation"));
            final String path = dialog.open();
            if (path != null) {
                e_pathParameter.setValue(path);
                new AEThread2("SoundTest") {

                    @Override
                    public void run() {
                        try {
                            Applet.newAudioClip(new File(path).toURI().toURL()).play();
                            Thread.sleep(2500);
                        } catch (Throwable e) {
                        }
                    }
                }.start();
            }
        }
    });
    Label d_sound_info = new Label(cArea, SWT.WRAP);
    Messages.setLanguageText(d_sound_info, "ConfigView.section.interface.wavlocation.info");
    gridData = new GridData(GridData.FILL_HORIZONTAL);
    gridData.widthHint = 100;
    Utils.setLayoutData(d_sound_info, gridData);
}
Also used : MessageText(com.biglybt.core.internat.MessageText) AEThread2(com.biglybt.core.util.AEThread2) GridData(org.eclipse.swt.layout.GridData) File(java.io.File)

Example 15 with AEThread2

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

the class ConfigSectionInterfaceDisplay method configSectionCreate.

@Override
public Composite configSectionCreate(final Composite parent) {
    int userMode = COConfigurationManager.getIntParameter("User Mode");
    boolean isAZ3 = COConfigurationManager.getStringParameter("ui").equals("az3");
    Label label;
    GridLayout layout;
    GridData gridData;
    Composite cSection = new Composite(parent, SWT.NULL);
    Utils.setLayoutData(cSection, new GridData(GridData.FILL_BOTH));
    layout = new GridLayout();
    layout.numColumns = 1;
    cSection.setLayout(layout);
    // various stuff
    Group gVarious = new Group(cSection, SWT.NULL);
    layout = new GridLayout();
    layout.numColumns = 1;
    gVarious.setLayout(layout);
    Utils.setLayoutData(gVarious, new GridData(GridData.FILL_HORIZONTAL));
    gVarious.setText(MessageText.getString("label.various"));
    new BooleanParameter(gVarious, "Show Download Basket", "ConfigView.section.style.showdownloadbasket");
    new BooleanParameter(gVarious, "suppress_file_download_dialog", "ConfigView.section.interface.display.suppress.file.download.dialog");
    new BooleanParameter(gVarious, "Suppress Sharing Dialog", "ConfigView.section.interface.display.suppress.sharing.dialog");
    new BooleanParameter(gVarious, "show_torrents_menu", "Menu.show.torrent.menu");
    if (!Constants.isUnix) {
        // TextWithHistory issues on Linux
        new BooleanParameter(gVarious, "mainwindow.search.history.enabled", "search.history.enable");
    }
    if (Constants.isWindowsXP) {
        final Button enableXPStyle = new Button(gVarious, SWT.CHECK);
        Messages.setLanguageText(enableXPStyle, "ConfigView.section.style.enableXPStyle");
        boolean enabled = false;
        boolean valid = false;
        try {
            File f = new File(System.getProperty("java.home") + "\\bin\\javaw.exe.manifest");
            if (f.exists()) {
                enabled = true;
            }
            f = FileUtil.getApplicationFile("javaw.exe.manifest");
            if (f.exists()) {
                valid = true;
            }
        } catch (Exception e) {
            Debug.printStackTrace(e);
            valid = false;
        }
        enableXPStyle.setEnabled(valid);
        enableXPStyle.setSelection(enabled);
        enableXPStyle.addListener(SWT.Selection, new Listener() {

            @Override
            public void handleEvent(Event arg0) {
                // In case we enable the XP Style
                if (enableXPStyle.getSelection()) {
                    try {
                        File fDest = new File(System.getProperty("java.home") + "\\bin\\javaw.exe.manifest");
                        File fOrigin = new File("javaw.exe.manifest");
                        if (!fDest.exists() && fOrigin.exists()) {
                            FileUtil.copyFile(fOrigin, fDest);
                        }
                    } catch (Exception e) {
                        Debug.printStackTrace(e);
                    }
                } else {
                    try {
                        File fDest = new File(System.getProperty("java.home") + "\\bin\\javaw.exe.manifest");
                        fDest.delete();
                    } catch (Exception e) {
                        Debug.printStackTrace(e);
                    }
                }
            }
        });
    }
    if (Constants.isOSX) {
        new BooleanParameter(gVarious, "enable_small_osx_fonts", "ConfigView.section.style.osx_small_fonts");
    }
    // Reuse the labels of the other menu actions.
    if (PlatformManagerFactory.getPlatformManager().hasCapability(PlatformManagerCapabilities.ShowFileInBrowser)) {
        BooleanParameter bp = new BooleanParameter(gVarious, "MyTorrentsView.menu.show_parent_folder_enabled", "ConfigView.section.style.use_show_parent_folder");
        Messages.setLanguageText(bp.getControl(), "ConfigView.section.style.use_show_parent_folder", new String[] { MessageText.getString("MyTorrentsView.menu.open_parent_folder"), MessageText.getString("MyTorrentsView.menu.explore") });
        if (Constants.isOSX) {
            new BooleanParameter(gVarious, "FileBrowse.usePathFinder", "ConfigView.section.style.usePathFinder");
        }
    }
    if (userMode > 0) {
        final BooleanParameter paramEnableForceDPI = new BooleanParameter(gVarious, "enable.ui.forceDPI", "ConfigView.section.style.forceDPI");
        paramEnableForceDPI.setLayoutData(new GridData());
        IntParameter forceDPI = new IntParameter(gVarious, "Force DPI", 0, Integer.MAX_VALUE);
        forceDPI.setLayoutData(new GridData());
        paramEnableForceDPI.setAdditionalActionPerformer(new ChangeSelectionActionPerformer(forceDPI.getControl()));
    }
    // toolbar
    {
        Group gToolBar = new Group(cSection, SWT.NULL);
        Messages.setLanguageText(gToolBar, "MainWindow.menu.view.iconbar");
        int gToolBarSpan = 6 + (isAZ3 ? 1 : 2);
        layout = new GridLayout();
        layout.numColumns = gToolBarSpan;
        gToolBar.setLayout(layout);
        Utils.setLayoutData(gToolBar, new GridData(GridData.FILL_HORIZONTAL));
        BooleanParameter enabled = null;
        if (!isAZ3) {
            enabled = new BooleanParameter(gToolBar, "IconBar.enabled", "ConfigView.section.style.showiconbar");
            GridData gd = new GridData();
            gd.horizontalSpan = gToolBarSpan;
            enabled.setLayoutData(gd);
        }
        if (isAZ3) {
            new BooleanParameter(gToolBar, "IconBar.visible.play", "iconBar.stream");
        }
        new BooleanParameter(gToolBar, "IconBar.visible.run", "iconBar.run");
        if (!isAZ3) {
            new BooleanParameter(gToolBar, "IconBar.visible.top", "iconBar.top");
        }
        new BooleanParameter(gToolBar, "IconBar.visible.up", "iconBar.up");
        new BooleanParameter(gToolBar, "IconBar.visible.down", "iconBar.down");
        if (!isAZ3) {
            new BooleanParameter(gToolBar, "IconBar.visible.bottom", "iconBar.bottom");
        }
        new BooleanParameter(gToolBar, "IconBar.visible." + TorrentUtil.TU_ITEM_RECHECK, "MyTorrentsView.menu.recheck");
        new BooleanParameter(gToolBar, "IconBar.visible." + TorrentUtil.TU_ITEM_CHECK_FILES, "MyTorrentsView.menu.checkfilesexist");
        BooleanParameter sss = new BooleanParameter(gToolBar, "IconBar.start.stop.separate", "ConfigView.section.style.start.stop.separate");
        GridData gd = new GridData();
        gd.horizontalSpan = gToolBarSpan;
        sss.setLayoutData(gd);
    }
    if (isAZ3) {
        Group gSideBar = new Group(cSection, SWT.NULL);
        Messages.setLanguageText(gSideBar, "v3.MainWindow.menu.view.sidebar");
        layout = new GridLayout();
        layout.numColumns = 2;
        gSideBar.setLayout(layout);
        Utils.setLayoutData(gSideBar, new GridData(GridData.FILL_HORIZONTAL));
        new BooleanParameter(gSideBar, "Show Side Bar", "sidebar.show");
        label = new Label(gSideBar, SWT.NULL);
        label = new Label(gSideBar, SWT.NULL);
        Messages.setLanguageText(label, "sidebar.top.level.gap");
        new IntParameter(gSideBar, "Side Bar Top Level Gap", 0, 5);
        new BooleanParameter(gSideBar, "Show Options In Side Bar", "sidebar.show.options");
        label = new Label(gSideBar, SWT.NULL);
        BooleanParameter showNew = new BooleanParameter(gSideBar, "Show New In Side Bar", "sidebar.show.new");
        label = new Label(gSideBar, SWT.NULL);
        showNew.addChangeListener(new ParameterChangeAdapter() {

            @Override
            public void parameterChanged(Parameter p, boolean caused_internally) {
                if (showNew.isSelected()) {
                    UIFunctionsManager.getUIFunctions().getMDI().loadEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_LIBRARY_UNOPENED, false);
                } else {
                    UIFunctionsManager.getUIFunctions().getMDI().closeEntry(MultipleDocumentInterface.SIDEBAR_SECTION_LIBRARY_UNOPENED);
                }
            }
        });
        BooleanParameter showDL = new BooleanParameter(gSideBar, "Show Downloading In Side Bar", "sidebar.show.downloading");
        label = new Label(gSideBar, SWT.NULL);
        showDL.addChangeListener(new ParameterChangeAdapter() {

            @Override
            public void parameterChanged(Parameter p, boolean caused_internally) {
                if (showDL.isSelected()) {
                    UIFunctionsManager.getUIFunctions().getMDI().loadEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_LIBRARY_DL, false);
                } else {
                    UIFunctionsManager.getUIFunctions().getMDI().closeEntry(MultipleDocumentInterface.SIDEBAR_SECTION_LIBRARY_DL);
                }
            }
        });
    }
    // status bar
    Group cStatusBar = new Group(cSection, SWT.NULL);
    Messages.setLanguageText(cStatusBar, "ConfigView.section.style.status");
    layout = new GridLayout();
    layout.numColumns = 1;
    cStatusBar.setLayout(layout);
    Utils.setLayoutData(cStatusBar, new GridData(GridData.FILL_HORIZONTAL));
    new BooleanParameter(cStatusBar, "Status Area Show SR", "ConfigView.section.style.status.show_sr");
    new BooleanParameter(cStatusBar, "Status Area Show NAT", "ConfigView.section.style.status.show_nat");
    new BooleanParameter(cStatusBar, "Status Area Show DDB", "ConfigView.section.style.status.show_ddb");
    new BooleanParameter(cStatusBar, "Status Area Show IPF", "ConfigView.section.style.status.show_ipf");
    new BooleanParameter(cStatusBar, "status.rategraphs", "ConfigView.section.style.status.show_rategraphs");
    if (userMode > 0) {
        Group cUnits = new Group(cSection, SWT.NULL);
        Messages.setLanguageText(cUnits, "ConfigView.section.style.units");
        layout = new GridLayout();
        layout.numColumns = 1;
        cUnits.setLayout(layout);
        Utils.setLayoutData(cUnits, new GridData(GridData.FILL_HORIZONTAL));
        new BooleanParameter(cUnits, "config.style.useSIUnits", "ConfigView.section.style.useSIUnits");
        new BooleanParameter(cUnits, "config.style.forceSIValues", "ConfigView.section.style.forceSIValues");
        new BooleanParameter(cUnits, "config.style.useUnitsRateBits", "ConfigView.section.style.useUnitsRateBits");
        new BooleanParameter(cUnits, "config.style.doNotUseGB", "ConfigView.section.style.doNotUseGB");
        new BooleanParameter(cUnits, "config.style.dataStatsOnly", "ConfigView.section.style.dataStatsOnly");
        new BooleanParameter(cUnits, "config.style.separateProtDataStats", "ConfigView.section.style.separateProtDataStats");
        new BooleanParameter(cUnits, "ui.scaled.graphics.binary.based", "ConfigView.section.style.scaleBinary");
    }
    if (userMode > 0) {
        Group formatters_group = new Group(cSection, SWT.NULL);
        Messages.setLanguageText(formatters_group, "ConfigView.label.general.formatters");
        layout = new GridLayout();
        formatters_group.setLayout(layout);
        Utils.setLayoutData(formatters_group, new GridData(GridData.FILL_HORIZONTAL));
        StringAreaParameter formatters = new StringAreaParameter(formatters_group, "config.style.formatOverrides");
        gridData = new GridData(GridData.FILL_HORIZONTAL);
        gridData.heightHint = formatters.getPreferredHeight(3);
        formatters.setLayoutData(gridData);
        Composite format_info = new Composite(formatters_group, SWT.NULL);
        layout = new GridLayout();
        layout.marginHeight = 0;
        layout.marginWidth = 0;
        layout.numColumns = 3;
        format_info.setLayout(layout);
        Utils.setLayoutData(format_info, new GridData(GridData.FILL_HORIZONTAL));
        new LinkLabel(format_info, "ConfigView.label.general.formatters.link", MessageText.getString("ConfigView.label.general.formatters.link.url"));
        label = new Label(format_info, SWT.NULL);
        Messages.setLanguageText(label, "GeneralView.label.status");
        InfoParameter info_param = new InfoParameter(format_info, "config.style.formatOverrides.status");
        gridData = new GridData(GridData.FILL_HORIZONTAL);
        info_param.setLayoutData(gridData);
    }
    if (userMode > 0) {
        Group gExternalBrowser = new Group(cSection, SWT.NULL);
        layout = new GridLayout();
        layout.numColumns = 1;
        gExternalBrowser.setLayout(layout);
        Utils.setLayoutData(gExternalBrowser, new GridData(GridData.FILL_HORIZONTAL));
        gExternalBrowser.setText(MessageText.getString("config.external.browser"));
        label = new Label(gExternalBrowser, SWT.WRAP);
        Messages.setLanguageText(label, "config.external.browser.info1");
        Utils.setLayoutData(label, Utils.getWrappableLabelGridData(1, 0));
        label = new Label(gExternalBrowser, SWT.WRAP);
        Messages.setLanguageText(label, "config.external.browser.info2");
        Utils.setLayoutData(label, Utils.getWrappableLabelGridData(1, 0));
        // browser selection
        final java.util.List<String[]> browser_choices = new ArrayList<>();
        browser_choices.add(new String[] { "system", MessageText.getString("external.browser.system") });
        browser_choices.add(new String[] { "manual", MessageText.getString("external.browser.manual") });
        java.util.List<PluginInterface> pis = CoreFactory.getSingleton().getPluginManager().getPluginsWithMethod("launchURL", new Class[] { URL.class, boolean.class, Runnable.class });
        String pi_names = "";
        for (PluginInterface pi : pis) {
            String pi_name = pi.getPluginName();
            pi_names += (pi_names.length() == 0 ? "" : "/") + pi_name;
            browser_choices.add(new String[] { "plugin:" + pi.getPluginID(), pi_name });
        }
        final Composite cEBArea = new Composite(gExternalBrowser, SWT.WRAP);
        gridData = new GridData(GridData.FILL_HORIZONTAL);
        Utils.setLayoutData(cEBArea, gridData);
        layout = new GridLayout();
        layout.numColumns = 2;
        layout.marginHeight = 0;
        cEBArea.setLayout(layout);
        label = new Label(cEBArea, SWT.WRAP);
        Messages.setLanguageText(label, "config.external.browser.select");
        final Composite cEB = new Group(cEBArea, SWT.WRAP);
        gridData = new GridData(GridData.FILL_HORIZONTAL);
        Utils.setLayoutData(cEB, gridData);
        layout = new GridLayout();
        layout.numColumns = browser_choices.size();
        layout.marginHeight = 0;
        cEB.setLayout(layout);
        java.util.List<Button> buttons = new ArrayList<>();
        for (int i = 0; i < browser_choices.size(); i++) {
            Button button = new Button(cEB, SWT.RADIO);
            button.setText(browser_choices.get(i)[1]);
            button.setData("index", String.valueOf(i));
            buttons.add(button);
        }
        String existing = COConfigurationManager.getStringParameter("browser.external.id", browser_choices.get(0)[0]);
        int existing_index = -1;
        for (int i = 0; i < browser_choices.size(); i++) {
            if (browser_choices.get(i)[0].equals(existing)) {
                existing_index = i;
                break;
            }
        }
        if (existing_index == -1) {
            existing_index = 0;
            COConfigurationManager.setParameter("browser.external.id", browser_choices.get(0)[0]);
        }
        buttons.get(existing_index).setSelection(true);
        Messages.setLanguageText(new Label(cEBArea, SWT.WRAP), "config.external.browser.prog");
        Composite manualArea = new Composite(cEBArea, SWT.NULL);
        layout = new GridLayout(2, false);
        layout.marginHeight = 0;
        layout.marginWidth = 0;
        manualArea.setLayout(layout);
        Utils.setLayoutData(manualArea, new GridData(GridData.FILL_HORIZONTAL));
        final Parameter manualProg = new FileParameter(manualArea, "browser.external.prog", "", new String[] {});
        manualProg.setEnabled(existing_index == 1);
        Listener radioListener = new Listener() {

            @Override
            public void handleEvent(Event event) {
                Button button = (Button) event.widget;
                if (button.getSelection()) {
                    Control[] children = cEB.getChildren();
                    for (int j = 0; j < children.length; j++) {
                        Control child = children[j];
                        if (child != button && child instanceof Button) {
                            Button b = (Button) child;
                            b.setSelection(false);
                        }
                    }
                    int index = Integer.parseInt((String) button.getData("index"));
                    COConfigurationManager.setParameter("browser.external.id", browser_choices.get(index)[0]);
                    manualProg.setEnabled(index == 1);
                }
            }
        };
        for (Button b : buttons) {
            b.addListener(SWT.Selection, radioListener);
        }
        if (pis.size() > 0) {
            Composite nonPubArea = new Composite(gExternalBrowser, SWT.NULL);
            layout = new GridLayout(2, false);
            layout.marginHeight = 0;
            nonPubArea.setLayout(layout);
            Utils.setLayoutData(nonPubArea, new GridData(GridData.FILL_HORIZONTAL));
            String temp = MessageText.getString("config.external.browser.non.pub", new String[] { pi_names });
            BooleanParameter non_pub = new BooleanParameter(nonPubArea, "browser.external.non.pub", true, "!" + temp + "!");
        }
        // test launch
        Composite testArea = new Composite(gExternalBrowser, SWT.NULL);
        layout = new GridLayout(4, false);
        layout.marginHeight = 0;
        testArea.setLayout(layout);
        Utils.setLayoutData(testArea, new GridData(GridData.FILL_HORIZONTAL));
        label = new Label(testArea, SWT.WRAP);
        Messages.setLanguageText(label, "config.external.browser.test");
        final Button test_button = new Button(testArea, SWT.PUSH);
        Messages.setLanguageText(test_button, "configureWizard.nat.test");
        final Text test_url = new Text(testArea, SWT.BORDER);
        Utils.setLayoutData(test_url, new GridData(GridData.FILL_HORIZONTAL));
        test_url.setText("http://www.vuze.com/");
        test_button.addListener(SWT.Selection, new Listener() {

            @Override
            public void handleEvent(Event event) {
                test_button.setEnabled(false);
                final String url_str = test_url.getText().trim();
                new AEThread2("async") {

                    @Override
                    public void run() {
                        try {
                            Utils.launch(url_str, true);
                        } finally {
                            Utils.execSWTThread(new Runnable() {

                                @Override
                                public void run() {
                                    if (!test_button.isDisposed()) {
                                        test_button.setEnabled(true);
                                    }
                                }
                            });
                        }
                    }
                }.start();
            }
        });
        label = new Label(testArea, SWT.NULL);
        Utils.setLayoutData(label, new GridData(GridData.FILL_HORIZONTAL));
    }
    if (userMode > 1) {
        Group gInternalBrowser = new Group(cSection, SWT.NULL);
        layout = new GridLayout();
        layout.numColumns = 1;
        gInternalBrowser.setLayout(layout);
        Utils.setLayoutData(gInternalBrowser, new GridData(GridData.FILL_HORIZONTAL));
        gInternalBrowser.setText(MessageText.getString("config.internal.browser"));
        label = new Label(gInternalBrowser, SWT.WRAP);
        gridData = Utils.getWrappableLabelGridData(1, GridData.FILL_HORIZONTAL);
        Utils.setLayoutData(label, gridData);
        Messages.setLanguageText(label, "config.internal.browser.info1");
        final BooleanParameter intbrow_disable = new BooleanParameter(gInternalBrowser, "browser.internal.disable", "config.browser.internal.disable");
        label = new Label(gInternalBrowser, SWT.WRAP);
        gridData = Utils.getWrappableLabelGridData(1, GridData.FILL_HORIZONTAL);
        gridData.horizontalIndent = 15;
        Utils.setLayoutData(label, gridData);
        Messages.setLanguageText(label, "config.browser.internal.disable.info");
        label = new Label(gInternalBrowser, SWT.WRAP);
        gridData = Utils.getWrappableLabelGridData(1, GridData.FILL_HORIZONTAL);
        Utils.setLayoutData(label, gridData);
        Messages.setLanguageText(label, "config.internal.browser.info3");
        java.util.List<PluginInterface> pis = AEProxyFactory.getPluginHTTPProxyProviders(true);
        final java.util.List<String[]> proxy_choices = new ArrayList<>();
        proxy_choices.add(new String[] { "none", MessageText.getString("label.none") });
        for (PluginInterface pi : pis) {
            proxy_choices.add(new String[] { "plugin:" + pi.getPluginID(), pi.getPluginName() });
        }
        final Composite cIPArea = new Composite(gInternalBrowser, SWT.WRAP);
        gridData = new GridData(GridData.FILL_HORIZONTAL);
        Utils.setLayoutData(cIPArea, gridData);
        layout = new GridLayout();
        layout.numColumns = 2;
        layout.marginHeight = 0;
        cIPArea.setLayout(layout);
        label = new Label(cIPArea, SWT.WRAP);
        gridData = Utils.getWrappableLabelGridData(1, GridData.FILL_HORIZONTAL);
        Utils.setLayoutData(label, gridData);
        Messages.setLanguageText(label, "config.internal.browser.proxy.select");
        final Composite cIP = new Group(cIPArea, SWT.WRAP);
        gridData = new GridData(GridData.FILL_HORIZONTAL);
        Utils.setLayoutData(cIP, gridData);
        layout = new GridLayout();
        layout.numColumns = proxy_choices.size();
        layout.marginHeight = 0;
        cIP.setLayout(layout);
        java.util.List<Button> buttons = new ArrayList<>();
        for (int i = 0; i < proxy_choices.size(); i++) {
            Button button = new Button(cIP, SWT.RADIO);
            button.setText(proxy_choices.get(i)[1]);
            button.setData("index", String.valueOf(i));
            buttons.add(button);
        }
        String existing = COConfigurationManager.getStringParameter("browser.internal.proxy.id", proxy_choices.get(0)[0]);
        int existing_index = -1;
        for (int i = 0; i < proxy_choices.size(); i++) {
            if (proxy_choices.get(i)[0].equals(existing)) {
                existing_index = i;
                break;
            }
        }
        if (existing_index == -1) {
            existing_index = 0;
            COConfigurationManager.setParameter("browser.internal.proxy.id", proxy_choices.get(0)[0]);
        }
        buttons.get(existing_index).setSelection(true);
        Listener radioListener = new Listener() {

            @Override
            public void handleEvent(Event event) {
                Button button = (Button) event.widget;
                if (button.getSelection()) {
                    Control[] children = cIP.getChildren();
                    for (int j = 0; j < children.length; j++) {
                        Control child = children[j];
                        if (child != button && child instanceof Button) {
                            Button b = (Button) child;
                            b.setSelection(false);
                        }
                    }
                    int index = Integer.parseInt((String) button.getData("index"));
                    COConfigurationManager.setParameter("browser.internal.proxy.id", proxy_choices.get(index)[0]);
                }
            }
        };
        for (Button b : buttons) {
            b.addListener(SWT.Selection, radioListener);
        }
    }
    // refresh
    Group gRefresh = new Group(cSection, SWT.NULL);
    gRefresh.setText(MessageText.getString("upnp.refresh.button"));
    layout = new GridLayout();
    layout.numColumns = 2;
    gRefresh.setLayout(layout);
    Utils.setLayoutData(gRefresh, new GridData(GridData.FILL_HORIZONTAL));
    label = new Label(gRefresh, SWT.NULL);
    Messages.setLanguageText(label, "ConfigView.section.style.guiUpdate");
    int[] values = { 10, 25, 50, 100, 250, 500, 1000, 2000, 5000, 10000, 15000 };
    String[] labels = { "10 ms", "25 ms", "50 ms", "100 ms", "250 ms", "500 ms", "1 s", "2 s", "5 s", "10 s", "15 s" };
    new IntListParameter(gRefresh, "GUI Refresh", 1000, labels, values);
    label = new Label(gRefresh, SWT.NULL);
    Messages.setLanguageText(label, "ConfigView.section.style.inactiveUpdate");
    gridData = new GridData();
    IntParameter inactiveUpdate = new IntParameter(gRefresh, "Refresh When Inactive", 1, Integer.MAX_VALUE);
    inactiveUpdate.setLayoutData(gridData);
    label = new Label(gRefresh, SWT.NULL);
    Messages.setLanguageText(label, "ConfigView.section.style.graphicsUpdate");
    gridData = new GridData();
    IntParameter graphicUpdate = new IntParameter(gRefresh, "Graphics Update", 1, Integer.MAX_VALUE);
    graphicUpdate.setLayoutData(gridData);
    return cSection;
}
Also used : LinkLabel(com.biglybt.ui.swt.components.LinkLabel) ArrayList(java.util.ArrayList) GridLayout(org.eclipse.swt.layout.GridLayout) PluginInterface(com.biglybt.pif.PluginInterface) MessageText(com.biglybt.core.internat.MessageText) AEThread2(com.biglybt.core.util.AEThread2) LinkLabel(com.biglybt.ui.swt.components.LinkLabel) GridData(org.eclipse.swt.layout.GridData) File(java.io.File)

Aggregations

AEThread2 (com.biglybt.core.util.AEThread2)20 File (java.io.File)6 PluginInterface (com.biglybt.pif.PluginInterface)5 Map (java.util.Map)5 GridData (org.eclipse.swt.layout.GridData)4 HashMap (java.util.HashMap)3 GridLayout (org.eclipse.swt.layout.GridLayout)3 DiskManagerFileInfoURL (com.biglybt.core.download.DiskManagerFileInfoURL)2 MessageText (com.biglybt.core.internat.MessageText)2 LogEvent (com.biglybt.core.logging.LogEvent)2 AESemaphore (com.biglybt.core.util.AESemaphore)2 PluginListener (com.biglybt.pif.PluginListener)2 IPCInterface (com.biglybt.pif.ipc.IPCInterface)2 Update (com.biglybt.pif.update.Update)2 ResourceDownloader (com.biglybt.pif.utils.resourcedownloader.ResourceDownloader)2 ResourceDownloaderAdapter (com.biglybt.pif.utils.resourcedownloader.ResourceDownloaderAdapter)2 PrintWriter (java.io.PrintWriter)2 StringWriter (java.io.StringWriter)2 URL (java.net.URL)2 Button (org.eclipse.swt.widgets.Button)2