Search in sources :

Example 6 with BufferedLabel

use of com.biglybt.ui.swt.components.BufferedLabel in project BiglyBT by BiglySoftware.

the class PrivacyView method initialize.

private void initialize() {
    if (cMainComposite == null || cMainComposite.isDisposed()) {
        if (parent == null || parent.isDisposed()) {
            return;
        }
        sc = new ScrolledComposite(parent, SWT.V_SCROLL);
        sc.setExpandHorizontal(true);
        sc.setExpandVertical(true);
        sc.getVerticalBar().setIncrement(16);
        Layout parentLayout = parent.getLayout();
        if (parentLayout instanceof GridLayout) {
            GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
            Utils.setLayoutData(sc, gd);
        } else if (parentLayout instanceof FormLayout) {
            Utils.setLayoutData(sc, Utils.getFilledFormData());
        }
        cMainComposite = new Composite(sc, SWT.NONE);
        sc.setContent(cMainComposite);
    } else {
        Utils.disposeComposite(cMainComposite, false);
    }
    GridLayout layout = new GridLayout(1, false);
    layout.horizontalSpacing = 0;
    layout.verticalSpacing = 0;
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    cMainComposite.setLayout(layout);
    GridData gd;
    // overview
    Composite overview_comp = new Composite(cMainComposite, SWT.NULL);
    overview_comp.setLayout(new GridLayout(3, false));
    gd = new GridData(GridData.FILL_HORIZONTAL);
    Utils.setLayoutData(overview_comp, gd);
    Label label = new Label(overview_comp, SWT.NULL);
    label.setText(MessageText.getString("privacy.view.intro"));
    LinkLabel link = new LinkLabel(overview_comp, "label.read.more", MessageText.getString("privacy.view.wiki.url"));
    // slider component
    Composite slider_comp = new Composite(cMainComposite, SWT.NULL);
    layout = new GridLayout(3, false);
    layout.horizontalSpacing = 0;
    layout.verticalSpacing = 0;
    layout.marginHeight = 0;
    // layout.marginWidth = 0;
    slider_comp.setLayout(layout);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    Utils.setLayoutData(slider_comp, gd);
    label = new Label(slider_comp, SWT.NULL);
    label.setText(MessageText.getString("privacy.view.level") + ":");
    Composite slider2_comp = new Composite(slider_comp, SWT.NULL);
    slider2_comp.setLayout(new GridLayout(6, true));
    gd = new GridData(GridData.FILL_HORIZONTAL);
    Utils.setLayoutData(slider2_comp, gd);
    label = new Label(slider2_comp, SWT.NULL);
    label.setText(MessageText.getString("privacy.view.public.only"));
    label = new Label(slider2_comp, SWT.NULL);
    label.setText(MessageText.getString("privacy.view.public.anon"));
    label.setAlignment(SWT.CENTER);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.horizontalSpan = 2;
    Utils.setLayoutData(label, gd);
    label = new Label(slider2_comp, SWT.NULL);
    label.setText(MessageText.getString("privacy.view.anon.only"));
    label.setAlignment(SWT.CENTER);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.horizontalSpan = 2;
    Utils.setLayoutData(label, gd);
    label = new Label(slider2_comp, SWT.NULL);
    label.setText(MessageText.getString("label.invalid"));
    gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.horizontalAlignment = SWT.END;
    Utils.setLayoutData(label, gd);
    privacy_scale = new Scale(slider2_comp, SWT.HORIZONTAL);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.horizontalSpan = 6;
    Utils.setLayoutData(privacy_scale, gd);
    privacy_scale.setMinimum(0);
    privacy_scale.setMaximum(30);
    final boolean[] slider_mouse_down = { false };
    privacy_scale.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseUp(MouseEvent e) {
            int pos = privacy_scale.getSelection();
            int level = ((pos + 5) / 10);
            if (level * 10 != pos) {
                privacy_scale.setSelection(level * 10);
            }
            setPrivacyLevel(level);
            slider_mouse_down[0] = false;
        }

        @Override
        public void mouseDown(MouseEvent e) {
            slider_mouse_down[0] = true;
        }
    });
    privacy_scale.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event event) {
            if (!slider_mouse_down[0]) {
                int pos = privacy_scale.getSelection();
                int level = ((pos + 5) / 10);
                setPrivacyLevel(level);
            }
        }
    });
    // network selection
    Composite network_comp = new Composite(slider_comp, SWT.NULL);
    gd = new GridData();
    Utils.setLayoutData(network_comp, gd);
    network_buttons = new Button[AENetworkClassifier.AT_NETWORKS.length];
    network_comp.setLayout(new GridLayout(1, false));
    label = new Label(network_comp, SWT.NULL);
    label.setText(MessageText.getString("ConfigView.section.connection.group.networks") + ":");
    for (int i = 0; i < network_buttons.length; i++) {
        final String nn = AENetworkClassifier.AT_NETWORKS[i];
        String msg_text = "ConfigView.section.connection.networks." + nn;
        Button button = new Button(network_comp, SWT.CHECK);
        Messages.setLanguageText(button, msg_text);
        network_buttons[i] = button;
        button.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                boolean selected = ((Button) e.widget).getSelection();
                if (current_dm != null) {
                    current_dm.getDownloadState().setNetworkEnabled(nn, selected);
                }
            }
        });
        GridData gridData = new GridData();
        Utils.setLayoutData(button, gridData);
    }
    label = new Label(slider_comp, SWT.NULL);
    final Composite tracker_webseed_comp = new Composite(slider_comp, SWT.NULL);
    layout = new GridLayout(2, true);
    layout.marginTop = layout.marginBottom = layout.marginLeft = layout.marginRight = 1;
    tracker_webseed_comp.setLayout(layout);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.horizontalSpan = 2;
    Utils.setLayoutData(tracker_webseed_comp, gd);
    tracker_webseed_comp.addPaintListener(new PaintListener() {

        @Override
        public void paintControl(PaintEvent e) {
            Rectangle client_area = tracker_webseed_comp.getClientArea();
            Rectangle rect = new Rectangle(0, 0, client_area.width - 1, client_area.height - 1);
            e.gc.setAlpha(50);
            e.gc.drawRectangle(rect);
        }
    });
    // Tracker Info
    Composite tracker_comp = new Composite(tracker_webseed_comp, SWT.NULL);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    Utils.setLayoutData(tracker_comp, gd);
    tracker_comp.setLayout(new GridLayout(2, false));
    label = new Label(tracker_comp, SWT.NULL);
    label.setText(MessageText.getString("label.trackers") + ":");
    tracker_info = new BufferedLabel(tracker_comp, SWT.DOUBLE_BUFFERED);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    Utils.setLayoutData(tracker_info, gd);
    // Webseed Info
    Composite webseed_comp = new Composite(tracker_webseed_comp, SWT.NULL);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    Utils.setLayoutData(webseed_comp, gd);
    webseed_comp.setLayout(new GridLayout(2, false));
    label = new Label(webseed_comp, SWT.NULL);
    label.setText(MessageText.getString("label.webseeds") + ":");
    webseed_info = new BufferedLabel(webseed_comp, SWT.DOUBLE_BUFFERED);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    Utils.setLayoutData(webseed_info, gd);
    // Peer Info
    // label = new Label( slider_comp, SWT.NULL );
    Composite peer_comp = new Composite(tracker_webseed_comp, SWT.NULL);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    Utils.setLayoutData(peer_comp, gd);
    peer_comp.setLayout(new GridLayout(2, false));
    label = new Label(peer_comp, SWT.NULL);
    label.setText(MessageText.getString("TableColumn.header.peers") + ":");
    peer_info = new BufferedLabel(peer_comp, SWT.DOUBLE_BUFFERED);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    Utils.setLayoutData(peer_info, gd);
    // I2P install state
    Group i2p_group = new Group(cMainComposite, SWT.NULL);
    i2p_group.setText("I2P");
    // Composite i2p_group = new Composite( cMainComposite, SWT.NULL );
    gd = new GridData(GridData.FILL_HORIZONTAL);
    Utils.setLayoutData(i2p_group, gd);
    i2p_group.setLayout(new GridLayout(4, false));
    label = new Label(i2p_group, SWT.NULL);
    label.setText(MessageText.getString("privacy.view.lookup.info"));
    gd = new GridData();
    gd.horizontalSpan = 2;
    Utils.setLayoutData(label, gd);
    label = new Label(i2p_group, SWT.NULL);
    label.setText(MessageText.getString("label.lookup.status") + ":");
    i2p_result_summary = new BufferedLabel(i2p_group, SWT.DOUBLE_BUFFERED);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    // gd.horizontalIndent = 4;
    Utils.setLayoutData(i2p_result_summary, gd);
    Composite i2p_button_comp = new Composite(i2p_group, SWT.NULL);
    i2p_button_comp.setLayout(new GridLayout(2, false));
    gd = new GridData(GridData.FILL_VERTICAL);
    Utils.setLayoutData(i2p_button_comp, gd);
    label = new Label(i2p_button_comp, SWT.NULL);
    label.setText(MessageText.getString("GeneralView.section.availability"));
    i2p_install_button = new Button(i2p_button_comp, SWT.PUSH);
    i2p_install_button.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent event) {
            final boolean[] result = { false };
            I2PHelpers.installI2PHelper(null, result, new Runnable() {

                @Override
                public void run() {
                    Utils.execSWTThread(new Runnable() {

                        @Override
                        public void run() {
                            updateI2PState();
                        }
                    });
                }
            });
        }
    });
    // I2P peer lookup
    i2p_lookup_comp = new Composite(i2p_group, SWT.BORDER);
    gd = new GridData();
    gd.widthHint = 300;
    gd.heightHint = 150;
    Utils.setLayoutData(i2p_lookup_comp, gd);
    i2p_lookup_comp.setBackground(Colors.white);
    // i2p results
    i2p_result_list = new Text(i2p_group, SWT.BORDER | SWT.READ_ONLY | SWT.V_SCROLL | SWT.WRAP | SWT.NO_FOCUS);
    gd = new GridData(GridData.FILL_BOTH);
    gd.horizontalSpan = 2;
    Utils.setLayoutData(i2p_result_list, gd);
    i2p_result_list.setEditable(false);
    // i2p lookup button
    label = new Label(i2p_button_comp, SWT.NULL);
    label.setText(MessageText.getString("button.lookup.peers"));
    i2p_lookup_button = new Button(i2p_button_comp, SWT.PUSH);
    i2p_lookup_button.setText(MessageText.getString("button.search.dht"));
    i2p_lookup_button.addSelectionListener(new SelectionAdapter() {

        private int search_count;

        @Override
        public void widgetSelected(SelectionEvent event) {
            Utils.disposeComposite(i2p_lookup_comp, false);
            i2p_result_summary.setText("");
            i2p_result_list.setText("");
            PluginInterface i2p_pi = CoreFactory.getSingleton().getPluginManager().getPluginInterfaceByID("azneti2phelper", true);
            if (i2p_pi != null) {
                IPCInterface ipc = i2p_pi.getIPC();
                Map<String, Object> options = new HashMap<>();
                options.put("server_id", "Scraper");
                options.put("server_id_transient", true);
                options.put("ui_composite", i2p_lookup_comp);
                final byte[] hash = (byte[]) i2p_lookup_button.getData("hash");
                search_count++;
                final int search_id = search_count;
                IPCInterface callback = new IPCInterface() {

                    @Override
                    public Object invoke(String methodName, final Object[] params) throws IPCException {
                        if (search_id != search_count) {
                            return (null);
                        }
                        if (methodName.equals("statusUpdate")) {
                            final int status = (Integer) params[0];
                            if (status != TrackerPeerSource.ST_INITIALISING && status != TrackerPeerSource.ST_UPDATING) {
                                Utils.execSWTThread(new Runnable() {

                                    @Override
                                    public void run() {
                                        if (i2p_lookup_button.isDisposed() || hash != i2p_lookup_button.getData("hash")) {
                                            return;
                                        }
                                        i2p_lookup_button.setEnabled(true);
                                        if (i2p_result_list.getText().length() == 0 && status != TrackerPeerSource.ST_UNAVAILABLE) {
                                            i2p_result_summary.setText(MessageText.getString("label.no.peers.found"));
                                        }
                                    }
                                });
                            }
                            if (params.length == 4) {
                                Utils.execSWTThread(new Runnable() {

                                    @Override
                                    public void run() {
                                        if (i2p_result_summary.isDisposed() || hash != i2p_lookup_button.getData("hash")) {
                                            return;
                                        }
                                        int seeds = (Integer) params[1];
                                        int leechers = (Integer) params[2];
                                        int peers = (Integer) params[3];
                                        i2p_result_summary.setText(MessageText.getString("privacy.view.lookup.msg", new String[] { String.valueOf(seeds), String.valueOf(leechers), String.valueOf(peers) }));
                                    }
                                });
                            }
                        } else if (methodName.equals("msgUpdate")) {
                            Utils.execSWTThread(new Runnable() {

                                @Override
                                public void run() {
                                    if (i2p_result_summary.isDisposed() || hash != i2p_lookup_button.getData("hash")) {
                                        return;
                                    }
                                    String msg = (String) params[0];
                                    i2p_result_summary.setText(msg);
                                }
                            });
                        } else if (methodName.equals("peerFound")) {
                            Utils.execSWTThread(new Runnable() {

                                @Override
                                public void run() {
                                    if (i2p_result_list.isDisposed() || hash != i2p_lookup_button.getData("hash")) {
                                        return;
                                    }
                                    String host = (String) params[0];
                                    int peer_type = (Integer) params[1];
                                    i2p_result_list.append(host + "\r\n");
                                }
                            });
                        }
                        return (null);
                    }

                    @Override
                    public boolean canInvoke(String methodName, Object[] params) {
                        return (true);
                    }
                };
                i2p_lookup_button.setEnabled(false);
                i2p_result_summary.setText(MessageText.getString("label.searching"));
                try {
                    ipc.invoke("lookupTorrent", new Object[] { "", hash, options, callback });
                } catch (Throwable e) {
                    i2p_lookup_button.setEnabled(true);
                    e.printStackTrace();
                }
            }
        }
    });
    Label i2p_options_info = new Label(i2p_button_comp, SWT.WRAP);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.horizontalSpan = 2;
    gd.widthHint = 150;
    Utils.setLayoutData(i2p_options_info, gd);
    i2p_options_info.setText(MessageText.getString("privacy.view.check.bw.info"));
    if (!COConfigurationManager.getBooleanParameter("privacy.view.check.bw.clicked", false)) {
        FontData fontData = i2p_options_info.getFont().getFontData()[0];
        final Font bold_font = new Font(i2p_options_info.getDisplay(), new FontData(fontData.getName(), fontData.getHeight(), SWT.BOLD));
        i2p_options_info.setFont(bold_font);
        i2p_options_info.addDisposeListener(new DisposeListener() {

            @Override
            public void widgetDisposed(DisposeEvent e) {
                bold_font.dispose();
            }
        });
    }
    i2p_options_link = new Label(i2p_button_comp, SWT.NULL);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.horizontalSpan = 2;
    Utils.setLayoutData(i2p_options_link, gd);
    i2p_options_link.setText(MessageText.getString("privacy.view.check.bw"));
    i2p_options_link.setCursor(i2p_options_link.getDisplay().getSystemCursor(SWT.CURSOR_HAND));
    i2p_options_link.setForeground(Colors.blue);
    i2p_options_link.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseDoubleClick(MouseEvent arg0) {
            openOptions();
        }

        @Override
        public void mouseUp(MouseEvent arg0) {
            openOptions();
        }

        private void openOptions() {
            COConfigurationManager.setParameter("privacy.view.check.bw.clicked", true);
            UIFunctions uif = UIFunctionsManager.getUIFunctions();
            if (uif != null) {
                uif.getMDI().showEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_CONFIG, "azi2phelper.name");
            }
        }
    });
    updateI2PState();
    Utils.makeButtonsEqualWidth(Arrays.asList(new Button[] { i2p_install_button, i2p_lookup_button }));
    label = new Label(i2p_button_comp, SWT.NULL);
    gd = new GridData(GridData.FILL_BOTH);
    gd.horizontalSpan = 2;
    Utils.setLayoutData(label, gd);
    Group bottom_comp = new Group(cMainComposite, SWT.NULL);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    Utils.setLayoutData(bottom_comp, gd);
    bottom_comp.setLayout(new GridLayout(2, false));
    // Torrent Info
    label = new Label(bottom_comp, SWT.NULL);
    label.setText(MessageText.getString("authenticator.torrent") + ":");
    Composite torrent_comp = new Composite(bottom_comp, SWT.NULL);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    Utils.setLayoutData(torrent_comp, gd);
    torrent_comp.setLayout(removeMarginsAndSpacing(new GridLayout(2, false)));
    torrent_info = new BufferedLabel(torrent_comp, SWT.DOUBLE_BUFFERED);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    Utils.setLayoutData(torrent_info, gd);
    // source selection
    label = new Label(bottom_comp, SWT.NULL);
    label.setText(MessageText.getString("ConfigView.section.connection.group.peersources") + ":");
    Composite sources_comp = new Composite(bottom_comp, SWT.NULL);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    Utils.setLayoutData(sources_comp, gd);
    source_buttons = new Button[PEPeerSource.PS_SOURCES.length];
    sources_comp.setLayout(removeMargins(new GridLayout(source_buttons.length + 1, false)));
    for (int i = 0; i < source_buttons.length; i++) {
        final String src = PEPeerSource.PS_SOURCES[i];
        String msg_text = "ConfigView.section.connection.peersource." + src;
        Button button = new Button(sources_comp, SWT.CHECK);
        Messages.setLanguageText(button, msg_text);
        source_buttons[i] = button;
        button.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                boolean selected = ((Button) e.widget).getSelection();
                if (current_dm != null) {
                    current_dm.getDownloadState().setPeerSourceEnabled(src, selected);
                }
            }
        });
        GridData gridData = new GridData();
        Utils.setLayoutData(button, gridData);
    }
    // IP Filter
    label = new Label(bottom_comp, SWT.NULL);
    label.setText(MessageText.getString("label.ip.filter") + ":");
    Composite ipfilter_comp = new Composite(bottom_comp, SWT.NULL);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    Utils.setLayoutData(ipfilter_comp, gd);
    ipfilter_comp.setLayout(removeMargins(new GridLayout(2, false)));
    ipfilter_enabled = new Button(ipfilter_comp, SWT.CHECK);
    ipfilter_enabled.setText(MessageText.getString("label.enabled"));
    ipfilter_enabled.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            current_dm.getDownloadState().setFlag(DownloadManagerState.FLAG_DISABLE_IP_FILTER, !ipfilter_enabled.getSelection());
        }
    });
    gd = new GridData(GridData.FILL_HORIZONTAL);
    Utils.setLayoutData(ipfilter_enabled, gd);
    // VPN Info
    label = new Label(bottom_comp, SWT.NULL);
    label.setText(MessageText.getString("label.vpn.status") + ":");
    Composite vpn_comp = new Composite(bottom_comp, SWT.NULL);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    Utils.setLayoutData(vpn_comp, gd);
    vpn_comp.setLayout(removeMargins(new GridLayout(2, false)));
    vpn_info = new BufferedLabel(vpn_comp, SWT.DOUBLE_BUFFERED);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    Utils.setLayoutData(vpn_info, gd);
    // SOCKS Info
    label = new Label(bottom_comp, SWT.NULL);
    label.setText(MessageText.getString("label.socks.status") + ":");
    Composite socks_comp = new Composite(bottom_comp, SWT.NULL);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    Utils.setLayoutData(socks_comp, gd);
    socks_comp.setLayout(removeMargins(new GridLayout(10, false)));
    label = new Label(socks_comp, SWT.NULL);
    label.setText(MessageText.getString("label.proxy") + ":");
    socks_state = new BufferedLabel(socks_comp, SWT.DOUBLE_BUFFERED);
    gd = new GridData();
    gd.widthHint = 120;
    Utils.setLayoutData(socks_state, gd);
    // current details
    label = new Label(socks_comp, SWT.NULL);
    label.setText(MessageText.getString("PeersView.state") + ":");
    socks_current = new BufferedLabel(socks_comp, SWT.DOUBLE_BUFFERED);
    gd = new GridData();
    gd.widthHint = 120;
    Utils.setLayoutData(socks_current, gd);
    // fail details
    label = new Label(socks_comp, SWT.NULL);
    label.setText(MessageText.getString("label.fails") + ":");
    socks_fails = new BufferedLabel(socks_comp, SWT.DOUBLE_BUFFERED);
    gd = new GridData();
    gd.widthHint = 120;
    Utils.setLayoutData(socks_fails, gd);
    // more info
    label = new Label(socks_comp, SWT.NULL);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING;
    socks_more = new Label(socks_comp, SWT.NULL);
    socks_more.setText(MessageText.getString("label.more") + "...");
    Utils.setLayoutData(socks_more, gd);
    socks_more.setCursor(socks_more.getDisplay().getSystemCursor(SWT.CURSOR_HAND));
    socks_more.setForeground(Colors.blue);
    socks_more.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseDoubleClick(MouseEvent arg0) {
            showSOCKSInfo();
        }

        @Override
        public void mouseUp(MouseEvent arg0) {
            showSOCKSInfo();
        }
    });
    // the rest
    sc.addControlListener(new ControlAdapter() {

        @Override
        public void controlResized(ControlEvent e) {
            Rectangle r = sc.getClientArea();
            Point size = cMainComposite.computeSize(r.width, SWT.DEFAULT);
            sc.setMinSize(size);
        }
    });
    swt_updateFields(null, current_dm);
    updatePeersEtc(current_dm);
    updateVPNSocks();
    Rectangle r = sc.getClientArea();
    Point size = cMainComposite.computeSize(r.width, SWT.DEFAULT);
    sc.setMinSize(size);
    Utils.relayout(cMainComposite);
}
Also used : TOTorrentAnnounceURLGroup(com.biglybt.core.torrent.TOTorrentAnnounceURLGroup) DownloadManagerStateAttributeListener(com.biglybt.core.download.DownloadManagerStateAttributeListener) UISWTViewCoreEventListener(com.biglybt.ui.swt.pifimpl.UISWTViewCoreEventListener) BufferedLabel(com.biglybt.ui.swt.components.BufferedLabel) BufferedLabel(com.biglybt.ui.swt.components.BufferedLabel) LinkLabel(com.biglybt.ui.swt.components.LinkLabel) Rectangle(org.eclipse.swt.graphics.Rectangle) Font(org.eclipse.swt.graphics.Font) UIFunctions(com.biglybt.ui.UIFunctions) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) IPCInterface(com.biglybt.pif.ipc.IPCInterface) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) PluginInterface(com.biglybt.pif.PluginInterface) FontData(org.eclipse.swt.graphics.FontData) IPCException(com.biglybt.pif.ipc.IPCException) MessageText(com.biglybt.core.internat.MessageText) Point(org.eclipse.swt.graphics.Point) Point(org.eclipse.swt.graphics.Point) LinkLabel(com.biglybt.ui.swt.components.LinkLabel) SWTRunnable(com.biglybt.ui.swt.utils.SWTRunnable) AERunnable(com.biglybt.core.util.AERunnable) UISWTViewEvent(com.biglybt.ui.swt.pif.UISWTViewEvent)

Example 7 with BufferedLabel

use of com.biglybt.ui.swt.components.BufferedLabel in project BiglyBT by BiglySoftware.

the class ScrapeInfoView method initialize.

private void initialize(Composite parent) {
    cParent = parent;
    Label label;
    GridData gridData;
    final Display display = parent.getDisplay();
    if (cScrapeInfoView == null || cScrapeInfoView.isDisposed()) {
        cScrapeInfoView = new Composite(parent, SWT.NONE);
    }
    gridData = new GridData(GridData.FILL_BOTH);
    cScrapeInfoView.setLayoutData(gridData);
    GridLayout layoutInfo = new GridLayout();
    layoutInfo.numColumns = 4;
    cScrapeInfoView.setLayout(layoutInfo);
    label = new Label(cScrapeInfoView, SWT.LEFT);
    // $NON-NLS-1$
    Messages.setLanguageText(label, "GeneralView.label.trackerurl");
    label.setCursor(display.getSystemCursor(SWT.CURSOR_HAND));
    label.setForeground(Colors.blue);
    label.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseDoubleClick(MouseEvent arg0) {
            String announce = trackerUrlValue.getText();
            if (announce != null && announce.length() != 0) {
                new Clipboard(display).setContents(new Object[] { announce }, new Transfer[] { TextTransfer.getInstance() });
            }
        }

        @Override
        public void mouseDown(MouseEvent arg0) {
            String announce = trackerUrlValue.getText();
            if (announce != null && announce.length() != 0) {
                new Clipboard(display).setContents(new Object[] { announce }, new Transfer[] { TextTransfer.getInstance() });
            }
        }
    });
    menuTracker = new Menu(parent.getShell(), SWT.POP_UP);
    itemSelect = new MenuItem(menuTracker, SWT.CASCADE);
    Messages.setLanguageText(itemSelect, "GeneralView.menu.selectTracker");
    MenuItem itemEdit = new MenuItem(menuTracker, SWT.NULL);
    Messages.setLanguageText(itemEdit, "MyTorrentsView.menu.editTracker");
    cScrapeInfoView.addDisposeListener(new DisposeListener() {

        @Override
        public void widgetDisposed(DisposeEvent e) {
            menuTracker.dispose();
        }
    });
    itemEdit.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event e) {
            final TOTorrent torrent = manager.getTorrent();
            if (torrent == null) {
                return;
            }
            List<List<String>> group = TorrentUtils.announceGroupsToList(torrent);
            new MultiTrackerEditor(null, null, group, new TrackerEditorListener() {

                @Override
                public void trackersChanged(String str, String str2, List<List<String>> _group) {
                    TorrentUtils.listToAnnounceGroups(_group, torrent);
                    try {
                        TorrentUtils.writeToFile(torrent);
                    } catch (Throwable e2) {
                        Debug.printStackTrace(e2);
                    }
                    TRTrackerAnnouncer tc = manager.getTrackerClient();
                    if (tc != null) {
                        tc.resetTrackerUrl(true);
                    }
                }
            }, true, true);
        }
    });
    TOTorrent torrent = manager == null ? null : manager.getTorrent();
    itemEdit.setEnabled(torrent != null && !TorrentUtils.isReallyPrivate(torrent));
    final Listener menuListener = new Listener() {

        @Override
        public void handleEvent(Event e) {
            if (e.widget instanceof MenuItem) {
                String text = ((MenuItem) e.widget).getText();
                TOTorrent torrent = manager.getTorrent();
                TorrentUtils.announceGroupsSetFirst(torrent, text);
                try {
                    TorrentUtils.writeToFile(torrent);
                } catch (TOTorrentException f) {
                    Debug.printStackTrace(f);
                }
                TRTrackerAnnouncer tc = manager.getTrackerClient();
                if (tc != null) {
                    tc.resetTrackerUrl(false);
                }
            }
        }
    };
    menuTracker.addListener(SWT.Show, new Listener() {

        @Override
        public void handleEvent(Event e) {
            Menu menuSelect = itemSelect.getMenu();
            if (menuSelect != null && !menuSelect.isDisposed()) {
                menuSelect.dispose();
            }
            if (manager == null || cScrapeInfoView == null || cScrapeInfoView.isDisposed()) {
                return;
            }
            List<List<String>> groups = TorrentUtils.announceGroupsToList(manager.getTorrent());
            menuSelect = new Menu(cScrapeInfoView.getShell(), SWT.DROP_DOWN);
            itemSelect.setMenu(menuSelect);
            for (List<String> trackers : groups) {
                MenuItem menuItem = new MenuItem(menuSelect, SWT.CASCADE);
                Messages.setLanguageText(menuItem, "wizard.multitracker.group");
                Menu menu = new Menu(cScrapeInfoView.getShell(), SWT.DROP_DOWN);
                menuItem.setMenu(menu);
                for (String url : trackers) {
                    MenuItem menuItemTracker = new MenuItem(menu, SWT.CASCADE);
                    menuItemTracker.setText(url);
                    menuItemTracker.addListener(SWT.Selection, menuListener);
                }
            }
        }
    });
    trackerUrlValue = new BufferedTruncatedLabel(cScrapeInfoView, SWT.LEFT, 70);
    trackerUrlValue.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseDown(MouseEvent event) {
            if (event.button == 3 || (event.button == 1 && event.stateMask == SWT.CONTROL)) {
                menuTracker.setVisible(true);
            } else if (event.button == 1) {
                String url = trackerUrlValue.getText();
                if (url.startsWith("http://") || url.startsWith("https://")) {
                    int pos = -1;
                    if ((pos = url.indexOf("/announce")) != -1) {
                        url = url.substring(0, pos + 1);
                    }
                    Utils.launch(url);
                }
            }
        }
    });
    gridData = new GridData(GridData.FILL_HORIZONTAL);
    gridData.horizontalSpan = 3;
    trackerUrlValue.setLayoutData(gridData);
    // //////////////////////
    label = new Label(cScrapeInfoView, SWT.LEFT);
    Messages.setLanguageText(label, "GeneralView.label.tracker");
    tracker_status = new BufferedTruncatedLabel(cScrapeInfoView, SWT.LEFT, 150);
    gridData = new GridData(GridData.FILL_HORIZONTAL);
    gridData.horizontalSpan = 3;
    tracker_status.setLayoutData(gridData);
    label = new Label(cScrapeInfoView, SWT.LEFT);
    Messages.setLanguageText(label, "GeneralView.label.updatein");
    trackerUpdateIn = new BufferedLabel(cScrapeInfoView, SWT.LEFT);
    gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_CENTER);
    trackerUpdateIn.setLayoutData(gridData);
    updateButton = new Button(cScrapeInfoView, SWT.PUSH);
    Messages.setLanguageText(updateButton, "GeneralView.label.trackerurlupdate");
    updateButton.setLayoutData(new GridData());
    updateButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent event) {
            new AEThread2("SIV:async") {

                @Override
                public void run() {
                    if (manager.getTrackerClient() != null) {
                        manager.requestTrackerAnnounce(false);
                    } else {
                        manager.requestTrackerScrape(true);
                    }
                }
            }.start();
        }
    });
    cScrapeInfoView.layout(true);
}
Also used : UISWTViewCoreEventListener(com.biglybt.ui.swt.pifimpl.UISWTViewCoreEventListener) TrackerEditorListener(com.biglybt.ui.swt.maketorrent.TrackerEditorListener) BufferedLabel(com.biglybt.ui.swt.components.BufferedLabel) BufferedTruncatedLabel(com.biglybt.ui.swt.components.BufferedTruncatedLabel) BufferedLabel(com.biglybt.ui.swt.components.BufferedLabel) BufferedTruncatedLabel(com.biglybt.ui.swt.components.BufferedTruncatedLabel) GridLayout(org.eclipse.swt.layout.GridLayout) List(java.util.List) TrackerEditorListener(com.biglybt.ui.swt.maketorrent.TrackerEditorListener) MultiTrackerEditor(com.biglybt.ui.swt.maketorrent.MultiTrackerEditor) TOTorrentException(com.biglybt.core.torrent.TOTorrentException) TRTrackerAnnouncer(com.biglybt.core.tracker.client.TRTrackerAnnouncer) TOTorrent(com.biglybt.core.torrent.TOTorrent) GridData(org.eclipse.swt.layout.GridData) TextTransfer(org.eclipse.swt.dnd.TextTransfer) Transfer(org.eclipse.swt.dnd.Transfer) UISWTViewEvent(com.biglybt.ui.swt.pif.UISWTViewEvent) Clipboard(org.eclipse.swt.dnd.Clipboard)

Example 8 with BufferedLabel

use of com.biglybt.ui.swt.components.BufferedLabel in project BiglyBT by BiglySoftware.

the class TorrentInfoView method initialize.

private void initialize(Composite composite) {
    this.parent = composite;
    if (download_manager == null) {
        return;
    }
    // I don't want to waste my time :) [tux]
    if (sc != null && !sc.isDisposed()) {
        sc.dispose();
    }
    sc = new ScrolledComposite(composite, SWT.V_SCROLL | SWT.H_SCROLL);
    sc.getVerticalBar().setIncrement(16);
    sc.setExpandHorizontal(true);
    sc.setExpandVertical(true);
    GridData gridData = new GridData(GridData.FILL, GridData.FILL, true, true, 1, 1);
    Utils.setLayoutData(sc, gridData);
    outer_panel = sc;
    Composite panel = new Composite(sc, SWT.NULL);
    sc.setContent(panel);
    GridLayout layout = new GridLayout();
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    layout.numColumns = 1;
    panel.setLayout(layout);
    // int userMode = COConfigurationManager.getIntParameter("User Mode");
    // header
    Composite cHeader = new Composite(panel, SWT.BORDER);
    GridLayout configLayout = new GridLayout();
    configLayout.marginHeight = 3;
    configLayout.marginWidth = 0;
    cHeader.setLayout(configLayout);
    gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_CENTER);
    Utils.setLayoutData(cHeader, gridData);
    Display d = panel.getDisplay();
    cHeader.setBackground(Colors.getSystemColor(d, SWT.COLOR_LIST_SELECTION));
    cHeader.setForeground(Colors.getSystemColor(d, SWT.COLOR_LIST_SELECTION_TEXT));
    Label lHeader = new Label(cHeader, SWT.NULL);
    lHeader.setBackground(Colors.getSystemColor(d, SWT.COLOR_LIST_SELECTION));
    lHeader.setForeground(Colors.getSystemColor(d, SWT.COLOR_LIST_SELECTION_TEXT));
    FontData[] fontData = lHeader.getFont().getFontData();
    fontData[0].setStyle(SWT.BOLD);
    int fontHeight = (int) (fontData[0].getHeight() * 1.2);
    fontData[0].setHeight(fontHeight);
    headerFont = new Font(d, fontData);
    lHeader.setFont(headerFont);
    lHeader.setText(" " + MessageText.getString("authenticator.torrent") + " : " + download_manager.getDisplayName().replaceAll("&", "&&"));
    gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_CENTER);
    Utils.setLayoutData(lHeader, gridData);
    Composite gTorrentInfo = new Composite(panel, SWT.NULL);
    gridData = new GridData(GridData.VERTICAL_ALIGN_FILL | GridData.HORIZONTAL_ALIGN_FILL);
    Utils.setLayoutData(gTorrentInfo, gridData);
    layout = new GridLayout();
    layout.numColumns = 2;
    gTorrentInfo.setLayout(layout);
    // torrent encoding
    Label label = new Label(gTorrentInfo, SWT.NULL);
    gridData = new GridData();
    Utils.setLayoutData(label, gridData);
    label.setText(MessageText.getString("TorrentInfoView.torrent.encoding") + ": ");
    TOTorrent torrent = download_manager.getTorrent();
    BufferedLabel blabel = new BufferedLabel(gTorrentInfo, SWT.NULL);
    gridData = new GridData();
    Utils.setLayoutData(blabel, gridData);
    blabel.setText(torrent == null ? "" : LocaleTorrentUtil.getCurrentTorrentEncoding(torrent));
    // trackers
    label = new Label(gTorrentInfo, SWT.NULL);
    gridData = new GridData();
    Utils.setLayoutData(label, gridData);
    label.setText(MessageText.getString("label.tracker") + ": ");
    String trackers = "";
    if (torrent != null) {
        TOTorrentAnnounceURLGroup group = torrent.getAnnounceURLGroup();
        TOTorrentAnnounceURLSet[] sets = group.getAnnounceURLSets();
        List<String> tracker_list = new ArrayList<>();
        URL url = torrent.getAnnounceURL();
        tracker_list.add(url.getHost() + (url.getPort() == -1 ? "" : (":" + url.getPort())));
        for (int i = 0; i < sets.length; i++) {
            TOTorrentAnnounceURLSet set = sets[i];
            URL[] urls = set.getAnnounceURLs();
            for (int j = 0; j < urls.length; j++) {
                url = urls[j];
                String str = url.getHost() + (url.getPort() == -1 ? "" : (":" + url.getPort()));
                if (!tracker_list.contains(str)) {
                    tracker_list.add(str);
                }
            }
        }
        TRTrackerAnnouncer announcer = download_manager.getTrackerClient();
        URL active_url = null;
        if (announcer != null) {
            active_url = announcer.getTrackerURL();
        } else {
            TRTrackerScraperResponse scrape = download_manager.getTrackerScrapeResponse();
            if (scrape != null) {
                active_url = scrape.getURL();
            }
        }
        if (active_url == null) {
            active_url = torrent.getAnnounceURL();
        }
        trackers = active_url.getHost() + (active_url.getPort() == -1 ? "" : (":" + active_url.getPort()));
        tracker_list.remove(trackers);
        if (tracker_list.size() > 0) {
            trackers += " (";
            for (int i = 0; i < tracker_list.size(); i++) {
                trackers += (i == 0 ? "" : ", ") + tracker_list.get(i);
            }
            trackers += ")";
        }
    }
    blabel = new BufferedLabel(gTorrentInfo, SWT.WRAP);
    Utils.setLayoutData(blabel, Utils.getWrappableLabelGridData(1, GridData.FILL_HORIZONTAL));
    blabel.setText(trackers);
    // columns
    Group gColumns = new Group(panel, SWT.NULL);
    Messages.setLanguageText(gColumns, "TorrentInfoView.columns");
    gridData = new GridData(GridData.FILL_BOTH);
    Utils.setLayoutData(gColumns, gridData);
    layout = new GridLayout();
    layout.numColumns = 4;
    gColumns.setLayout(layout);
    Map<String, FakeTableCell> usable_cols = new HashMap<>();
    TableColumnManager col_man = TableColumnManager.getInstance();
    TableColumnCore[][] cols_sets = { col_man.getAllTableColumnCoreAsArray(DownloadTypeIncomplete.class, TableManager.TABLE_MYTORRENTS_INCOMPLETE), col_man.getAllTableColumnCoreAsArray(DownloadTypeComplete.class, TableManager.TABLE_MYTORRENTS_COMPLETE) };
    for (int i = 0; i < cols_sets.length; i++) {
        TableColumnCore[] cols = cols_sets[i];
        for (int j = 0; j < cols.length; j++) {
            TableColumnCore col = cols[j];
            String id = col.getName();
            if (usable_cols.containsKey(id)) {
                continue;
            }
            FakeTableCell fakeTableCell = null;
            try {
                fakeTableCell = new FakeTableCell(col, download_manager);
                fakeTableCell.setOrentation(SWT.LEFT);
                fakeTableCell.setWrapText(false);
                col.invokeCellAddedListeners(fakeTableCell);
                // One refresh to see if it throws up
                fakeTableCell.refresh();
                usable_cols.put(id, fakeTableCell);
            } catch (Throwable t) {
                // System.out.println("not usable col: " + id + " - " + Debug.getCompressedStackTrace());
                try {
                    if (fakeTableCell != null) {
                        fakeTableCell.dispose();
                    }
                } catch (Throwable t2) {
                // ignore;
                }
            }
        }
    }
    Collection<FakeTableCell> values = usable_cols.values();
    cells = new FakeTableCell[values.size()];
    values.toArray(cells);
    Arrays.sort(cells, new Comparator<FakeTableCell>() {

        @Override
        public int compare(FakeTableCell o1, FakeTableCell o2) {
            TableColumnCore c1 = (TableColumnCore) o1.getTableColumn();
            TableColumnCore c2 = (TableColumnCore) o2.getTableColumn();
            String key1 = MessageText.getString(c1.getTitleLanguageKey());
            String key2 = MessageText.getString(c2.getTitleLanguageKey());
            return key1.compareToIgnoreCase(key2);
        }
    });
    for (int i = 0; i < cells.length; i++) {
        final FakeTableCell cell = cells[i];
        label = new Label(gColumns, SWT.NULL);
        gridData = new GridData();
        if (i % 2 == 1) {
            gridData.horizontalIndent = 16;
        }
        Utils.setLayoutData(label, gridData);
        String key = ((TableColumnCore) cell.getTableColumn()).getTitleLanguageKey();
        label.setText(MessageText.getString(key) + ": ");
        label.setToolTipText(MessageText.getString(key + ".info", ""));
        final Composite c = new Composite(gColumns, SWT.DOUBLE_BUFFERED);
        gridData = new GridData(GridData.FILL_HORIZONTAL);
        gridData.heightHint = 16;
        Utils.setLayoutData(c, gridData);
        cell.setControl(c);
        cell.invalidate();
        cell.refresh();
        c.addListener(SWT.MouseHover, new Listener() {

            @Override
            public void handleEvent(Event event) {
                Object toolTip = cell.getToolTip();
                if (toolTip instanceof String) {
                    String s = (String) toolTip;
                    c.setToolTipText(s);
                }
            }
        });
    }
    refresh();
    sc.setMinSize(panel.computeSize(SWT.DEFAULT, SWT.DEFAULT));
}
Also used : TOTorrentAnnounceURLGroup(com.biglybt.core.torrent.TOTorrentAnnounceURLGroup) BufferedLabel(com.biglybt.ui.swt.components.BufferedLabel) UIPluginViewToolBarListener(com.biglybt.pif.ui.UIPluginViewToolBarListener) UISWTViewCoreEventListener(com.biglybt.ui.swt.pifimpl.UISWTViewCoreEventListener) BufferedLabel(com.biglybt.ui.swt.components.BufferedLabel) TableColumnCore(com.biglybt.ui.common.table.TableColumnCore) FakeTableCell(com.biglybt.ui.swt.views.table.impl.FakeTableCell) Font(org.eclipse.swt.graphics.Font) TOTorrentAnnounceURLGroup(com.biglybt.core.torrent.TOTorrentAnnounceURLGroup) URL(java.net.URL) TableColumnManager(com.biglybt.ui.common.table.impl.TableColumnManager) GridLayout(org.eclipse.swt.layout.GridLayout) TRTrackerScraperResponse(com.biglybt.core.tracker.client.TRTrackerScraperResponse) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) FontData(org.eclipse.swt.graphics.FontData) DownloadTypeComplete(com.biglybt.pif.download.DownloadTypeComplete) TRTrackerAnnouncer(com.biglybt.core.tracker.client.TRTrackerAnnouncer) TOTorrent(com.biglybt.core.torrent.TOTorrent) GridData(org.eclipse.swt.layout.GridData) UISWTViewEvent(com.biglybt.ui.swt.pif.UISWTViewEvent) DownloadTypeIncomplete(com.biglybt.pif.download.DownloadTypeIncomplete) TOTorrentAnnounceURLSet(com.biglybt.core.torrent.TOTorrentAnnounceURLSet)

Example 9 with BufferedLabel

use of com.biglybt.ui.swt.components.BufferedLabel in project BiglyBT by BiglySoftware.

the class ViewQuickConfig method addTemporaryRates.

private void addTemporaryRates(Composite composite) {
    Group temp_rates = new Group(composite, SWT.NULL);
    Messages.setLanguageText(temp_rates, "label.temporary.rates");
    GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
    gridData.horizontalSpan = 4;
    Utils.setLayoutData(temp_rates, gridData);
    GridLayout layout = new GridLayout(10, false);
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    temp_rates.setLayout(layout);
    // label = new Label(temp_rates, SWT.NULL);
    // Messages.setLanguageText( label, "label.temporary.rates" );
    Label label = new Label(temp_rates, SWT.NULL);
    gridData = new GridData();
    gridData.horizontalIndent = 4;
    Utils.setLayoutData(label, gridData);
    Messages.setLanguageText(label, "label.upload.kbps", new String[] { DisplayFormatters.getRateUnit(DisplayFormatters.UNIT_KB) });
    final IntParameter tempULRate = new IntParameter(temp_rates, "global.download.rate.temp.kbps", 0, Integer.MAX_VALUE);
    label = new Label(temp_rates, SWT.NULL);
    Messages.setLanguageText(label, "label.download.kbps", new String[] { DisplayFormatters.getRateUnit(DisplayFormatters.UNIT_KB) });
    final IntParameter tempDLRate = new IntParameter(temp_rates, "global.upload.rate.temp.kbps", 0, Integer.MAX_VALUE);
    label = new Label(temp_rates, SWT.NULL);
    Messages.setLanguageText(label, "label.duration.mins");
    final IntParameter tempMins = new IntParameter(temp_rates, "global.rate.temp.min", 0, Integer.MAX_VALUE);
    final Button activate = new Button(temp_rates, SWT.TOGGLE);
    Messages.setLanguageText(activate, "label.activate");
    final BufferedLabel remLabel = new BufferedLabel(temp_rates, SWT.DOUBLE_BUFFERED);
    gridData = new GridData(GridData.FILL_HORIZONTAL);
    gridData.widthHint = 150;
    Utils.setLayoutData(remLabel, gridData);
    activate.addSelectionListener(new SelectionAdapter() {

        private CoreLifecycleAdapter listener;

        private TimerEventPeriodic event;

        private boolean auto_up_enabled;

        private boolean auto_up_seeding_enabled;

        private boolean seeding_limits_enabled;

        private int up_limit;

        private int down_limit;

        private long end_time;

        @Override
        public void widgetSelected(SelectionEvent e) {
            if (activate.getSelection()) {
                listener = new CoreLifecycleAdapter() {

                    @Override
                    public void stopping(Core core) {
                        deactivate(true);
                    }
                };
                CoreFactory.getSingleton().addLifecycleListener(listener);
                Messages.setLanguageText(activate, "FileView.BlockView.Active");
                tempDLRate.setEnabled(false);
                tempULRate.setEnabled(false);
                tempMins.setEnabled(false);
                auto_up_enabled = COConfigurationManager.getBooleanParameter(TransferSpeedValidator.AUTO_UPLOAD_ENABLED_CONFIGKEY);
                auto_up_seeding_enabled = COConfigurationManager.getBooleanParameter(TransferSpeedValidator.AUTO_UPLOAD_SEEDING_ENABLED_CONFIGKEY);
                seeding_limits_enabled = COConfigurationManager.getBooleanParameter(TransferSpeedValidator.UPLOAD_SEEDING_ENABLED_CONFIGKEY);
                up_limit = COConfigurationManager.getIntParameter(TransferSpeedValidator.UPLOAD_CONFIGKEY);
                down_limit = COConfigurationManager.getIntParameter(TransferSpeedValidator.DOWNLOAD_CONFIGKEY);
                COConfigurationManager.setParameter(TransferSpeedValidator.AUTO_UPLOAD_ENABLED_CONFIGKEY, false);
                COConfigurationManager.setParameter(TransferSpeedValidator.AUTO_UPLOAD_SEEDING_ENABLED_CONFIGKEY, false);
                COConfigurationManager.setParameter(TransferSpeedValidator.UPLOAD_SEEDING_ENABLED_CONFIGKEY, false);
                COConfigurationManager.setParameter(TransferSpeedValidator.UPLOAD_CONFIGKEY, tempULRate.getValue());
                COConfigurationManager.setParameter(TransferSpeedValidator.DOWNLOAD_CONFIGKEY, tempDLRate.getValue());
                end_time = SystemTime.getCurrentTime() + tempMins.getValue() * 60 * 1000;
                event = SimpleTimer.addPeriodicEvent("TempRates", 1000, new TimerEventPerformer() {

                    @Override
                    public void perform(TimerEvent e) {
                        Utils.execSWTThread(new Runnable() {

                            @Override
                            public void run() {
                                if (event == null) {
                                    return;
                                }
                                long now = SystemTime.getCurrentTime();
                                long rem = end_time - now;
                                if (rem < 1000 || composite.isDisposed()) {
                                    deactivate(false);
                                } else {
                                    remLabel.setText(MessageText.getString("TableColumn.header.remaining") + ": " + DisplayFormatters.formatTime(rem));
                                }
                            }
                        });
                    }
                });
            } else {
                deactivate(false);
            }
        }

        private void deactivate(boolean closing) {
            COConfigurationManager.setParameter(TransferSpeedValidator.AUTO_UPLOAD_ENABLED_CONFIGKEY, auto_up_enabled);
            COConfigurationManager.setParameter(TransferSpeedValidator.AUTO_UPLOAD_SEEDING_ENABLED_CONFIGKEY, auto_up_seeding_enabled);
            COConfigurationManager.setParameter(TransferSpeedValidator.UPLOAD_SEEDING_ENABLED_CONFIGKEY, seeding_limits_enabled);
            COConfigurationManager.setParameter(TransferSpeedValidator.UPLOAD_CONFIGKEY, up_limit);
            COConfigurationManager.setParameter(TransferSpeedValidator.DOWNLOAD_CONFIGKEY, down_limit);
            if (!closing) {
                if (listener != null) {
                    CoreFactory.getSingleton().removeLifecycleListener(listener);
                    listener = null;
                }
                if (!composite.isDisposed()) {
                    Messages.setLanguageText(activate, "label.activate");
                    activate.setSelection(false);
                    tempDLRate.setEnabled(true);
                    tempULRate.setEnabled(true);
                    tempMins.setEnabled(true);
                    remLabel.setText("");
                }
            }
            if (event != null) {
                event.cancel();
                event = null;
            }
        }
    });
    activate.setEnabled(tempMins.getValue() > 0);
    tempMins.addChangeListener(new ParameterChangeAdapter() {

        @Override
        public void parameterChanged(Parameter p, boolean caused_internally) {
            activate.setEnabled(tempMins.getValue() > 0);
        }
    });
}
Also used : TimerEventPeriodic(com.biglybt.core.util.TimerEventPeriodic) BufferedLabel(com.biglybt.ui.swt.components.BufferedLabel) CoreLifecycleAdapter(com.biglybt.core.CoreLifecycleAdapter) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) BufferedLabel(com.biglybt.ui.swt.components.BufferedLabel) ParameterChangeAdapter(com.biglybt.ui.swt.config.ParameterChangeAdapter) Point(org.eclipse.swt.graphics.Point) GridLayout(org.eclipse.swt.layout.GridLayout) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) TimerEventPerformer(com.biglybt.core.util.TimerEventPerformer) TimerEvent(com.biglybt.core.util.TimerEvent) IntParameter(com.biglybt.ui.swt.config.IntParameter) Parameter(com.biglybt.ui.swt.config.Parameter) IntParameter(com.biglybt.ui.swt.config.IntParameter) Core(com.biglybt.core.Core)

Example 10 with BufferedLabel

use of com.biglybt.ui.swt.components.BufferedLabel in project BiglyBT by BiglySoftware.

the class ViewQuickConfig method addTemporaryData.

private void addTemporaryData(Composite composite) {
    Group temp_rates = new Group(composite, SWT.NULL);
    Messages.setLanguageText(temp_rates, "label.temporary.data");
    GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
    gridData.horizontalSpan = 4;
    Utils.setLayoutData(temp_rates, gridData);
    GridLayout layout = new GridLayout(10, false);
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    temp_rates.setLayout(layout);
    // label = new Label(temp_rates, SWT.NULL);
    // Messages.setLanguageText( label, "label.temporary.rates" );
    Label label = new Label(temp_rates, SWT.NULL);
    gridData = new GridData();
    gridData.horizontalIndent = 4;
    Utils.setLayoutData(label, gridData);
    Messages.setLanguageText(label, "label.upload.mb", new String[] { DisplayFormatters.getUnit(DisplayFormatters.UNIT_MB) });
    final IntParameter tempULLimit = new IntParameter(temp_rates, "global.upload.limit.temp.mb", 0, Integer.MAX_VALUE);
    label = new Label(temp_rates, SWT.NULL);
    Messages.setLanguageText(label, "label.download.mb", new String[] { DisplayFormatters.getUnit(DisplayFormatters.UNIT_MB) });
    final IntParameter tempDLLimit = new IntParameter(temp_rates, "global.download.limit.temp.mb", 0, Integer.MAX_VALUE);
    final Button activate = new Button(temp_rates, SWT.TOGGLE);
    Messages.setLanguageText(activate, "label.activate");
    final BufferedLabel remLabel = new BufferedLabel(temp_rates, SWT.DOUBLE_BUFFERED);
    gridData = new GridData(GridData.FILL_HORIZONTAL);
    gridData.widthHint = 200;
    Utils.setLayoutData(remLabel, gridData);
    activate.addSelectionListener(new SelectionAdapter() {

        private CoreLifecycleAdapter listener;

        private TimerEventPeriodic event;

        private long end_upload;

        private long end_download;

        @Override
        public void widgetSelected(SelectionEvent e) {
            if (activate.getSelection()) {
                listener = new CoreLifecycleAdapter() {

                    @Override
                    public void stopping(Core core) {
                        deactivate(true);
                    }
                };
                Core core = CoreFactory.getSingleton();
                core.addLifecycleListener(listener);
                Messages.setLanguageText(activate, "FileView.BlockView.Active");
                final GlobalManagerStats stats = core.getGlobalManager().getStats();
                tempULLimit.setEnabled(false);
                tempDLLimit.setEnabled(false);
                long u_limit = tempULLimit.getValue();
                if (u_limit > 0) {
                    end_upload = stats.getTotalDataProtocolBytesSent() + u_limit * DisplayFormatters.getMinB();
                } else {
                    end_upload = 0;
                }
                long d_limit = tempDLLimit.getValue();
                if (d_limit > 0) {
                    end_download = stats.getTotalDataProtocolBytesReceived() + d_limit * DisplayFormatters.getMinB();
                } else {
                    end_download = 0;
                }
                event = SimpleTimer.addPeriodicEvent("TempData", 5000, new TimerEventPerformer() {

                    @Override
                    public void perform(TimerEvent e) {
                        Utils.execSWTThread(new Runnable() {

                            @Override
                            public void run() {
                                if (event == null) {
                                    return;
                                }
                                long rem_up = 0;
                                long rem_down = 0;
                                if (end_upload > 0) {
                                    rem_up = end_upload - stats.getTotalDataProtocolBytesSent();
                                }
                                if (end_download > 0) {
                                    rem_down = end_download - stats.getTotalDataProtocolBytesReceived();
                                }
                                if (end_upload > 0 && rem_up <= 0) {
                                    java.util.List<DownloadManager> dms = core.getGlobalManager().getDownloadManagers();
                                    for (DownloadManager dm : dms) {
                                        if (!dm.isForceStart()) {
                                            int state = dm.getState();
                                            if (state != DownloadManager.STATE_STOPPED && state != DownloadManager.STATE_ERROR && !dm.isPaused()) {
                                                ManagerUtils.stop(dm, null);
                                                dm.setStopReason(MessageText.getString("label.temporary.data"));
                                            }
                                        }
                                    }
                                }
                                if (end_download > 0 && rem_down <= 0) {
                                    java.util.List<DownloadManager> dms = core.getGlobalManager().getDownloadManagers();
                                    for (DownloadManager dm : dms) {
                                        if (!dm.isForceStart()) {
                                            int state = dm.getState();
                                            if (state != DownloadManager.STATE_STOPPED && state != DownloadManager.STATE_ERROR && !dm.isPaused()) {
                                                if (!dm.isDownloadComplete(false)) {
                                                    ManagerUtils.stop(dm, null);
                                                    dm.setStopReason(MessageText.getString("label.temporary.data"));
                                                }
                                            }
                                        }
                                    }
                                }
                                if ((rem_up <= 0 && rem_down <= 0) || composite.isDisposed()) {
                                    deactivate(false);
                                } else {
                                    remLabel.setText(MessageText.getString("TableColumn.header.remaining") + ": " + DisplayFormatters.formatByteCountToKiBEtc(rem_up < 0 ? 0 : rem_up) + "/" + DisplayFormatters.formatByteCountToKiBEtc(rem_down < 0 ? 0 : rem_down));
                                    temp_rates.layout(new Control[] { remLabel.getControl() });
                                }
                            }
                        });
                    }
                });
            } else {
                deactivate(false);
            }
        }

        private void deactivate(boolean closing) {
            if (!closing) {
                if (listener != null) {
                    CoreFactory.getSingleton().removeLifecycleListener(listener);
                    listener = null;
                }
                if (!composite.isDisposed()) {
                    Messages.setLanguageText(activate, "label.activate");
                    activate.setSelection(false);
                    tempULLimit.setEnabled(true);
                    tempDLLimit.setEnabled(true);
                    remLabel.setText("");
                    temp_rates.layout(true);
                }
            }
            if (event != null) {
                event.cancel();
                event = null;
            }
        }
    });
    activate.setEnabled(tempULLimit.getValue() > 0 || tempDLLimit.getValue() > 0);
    ParameterChangeAdapter adapter = new ParameterChangeAdapter() {

        @Override
        public void parameterChanged(Parameter p, boolean caused_internally) {
            activate.setEnabled(tempULLimit.getValue() > 0 || tempDLLimit.getValue() > 0);
        }
    };
    tempULLimit.addChangeListener(adapter);
    tempDLLimit.addChangeListener(adapter);
}
Also used : TimerEventPeriodic(com.biglybt.core.util.TimerEventPeriodic) BufferedLabel(com.biglybt.ui.swt.components.BufferedLabel) CoreLifecycleAdapter(com.biglybt.core.CoreLifecycleAdapter) BufferedLabel(com.biglybt.ui.swt.components.BufferedLabel) DownloadManager(com.biglybt.core.download.DownloadManager) GridLayout(org.eclipse.swt.layout.GridLayout) SelectionEvent(org.eclipse.swt.events.SelectionEvent) TimerEventPerformer(com.biglybt.core.util.TimerEventPerformer) TimerEvent(com.biglybt.core.util.TimerEvent) Core(com.biglybt.core.Core) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ParameterChangeAdapter(com.biglybt.ui.swt.config.ParameterChangeAdapter) GlobalManagerStats(com.biglybt.core.global.GlobalManagerStats) Point(org.eclipse.swt.graphics.Point) GridData(org.eclipse.swt.layout.GridData) IntParameter(com.biglybt.ui.swt.config.IntParameter) Parameter(com.biglybt.ui.swt.config.Parameter) IntParameter(com.biglybt.ui.swt.config.IntParameter)

Aggregations

BufferedLabel (com.biglybt.ui.swt.components.BufferedLabel)18 GridData (org.eclipse.swt.layout.GridData)15 GridLayout (org.eclipse.swt.layout.GridLayout)13 SelectionEvent (org.eclipse.swt.events.SelectionEvent)8 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)7 Label (org.eclipse.swt.widgets.Label)7 UISWTViewEvent (com.biglybt.ui.swt.pif.UISWTViewEvent)6 ScrolledComposite (org.eclipse.swt.custom.ScrolledComposite)6 Point (org.eclipse.swt.graphics.Point)6 Composite (org.eclipse.swt.widgets.Composite)5 UIFunctions (com.biglybt.ui.UIFunctions)4 UISWTViewCoreEventListener (com.biglybt.ui.swt.pifimpl.UISWTViewCoreEventListener)4 MouseAdapter (org.eclipse.swt.events.MouseAdapter)4 MouseEvent (org.eclipse.swt.events.MouseEvent)4 MessageText (com.biglybt.core.internat.MessageText)3 LinkLabel (com.biglybt.ui.swt.components.LinkLabel)3 Font (org.eclipse.swt.graphics.Font)3 FontData (org.eclipse.swt.graphics.FontData)3 Rectangle (org.eclipse.swt.graphics.Rectangle)3 Control (org.eclipse.swt.widgets.Control)3