Search in sources :

Example 1 with ParameterListener

use of com.biglybt.core.config.ParameterListener in project BiglyBT by BiglySoftware.

the class SideBar method createSideBar.

private void createSideBar() {
    if (soSideBarList == null) {
        return;
    }
    Composite parent = (Composite) soSideBarList.getControl();
    tree = new Tree(parent, SWT.FULL_SELECTION | SWT.V_SCROLL | SWT.DOUBLE_BUFFERED | SWT.NO_SCROLL);
    tree.setHeaderVisible(false);
    new SideBarToolTips(this, tree);
    tree.setLayoutData(Utils.getFilledFormData());
    SWTSkinProperties skinProperties = skin.getSkinProperties();
    bg = skinProperties.getColor("color.sidebar.bg");
    fg = skinProperties.getColor("color.sidebar.fg");
    configBGColorListener = new ParameterListener() {

        @Override
        public void parameterChanged(String parameterName) {
            Utils.execSWTThread(new Runnable() {

                @Override
                public void run() {
                    swt_updateSideBarColors();
                }
            });
        }
    };
    COConfigurationManager.addParameterListener("config.skin.color.sidebar.bg", configBGColorListener);
    tree.setBackground(bg);
    tree.setForeground(fg);
    FontData[] fontData = tree.getFont().getFontData();
    int fontHeight;
    if (Utils.isGTK3) {
        fontHeight = fontData[0].getHeight();
    } else {
        fontHeight = (Constants.isOSX ? 11 : 12) + (tree.getItemHeight() > 18 ? tree.getItemHeight() - 18 : 0);
        if (Constants.isUnix && tree.getItemHeight() >= 38) {
            fontHeight = 13;
        }
    }
    fontData[0].setStyle(SWT.BOLD);
    FontUtils.getFontHeightFromPX(tree.getDisplay(), fontData, null, fontHeight);
    fontHeader = new Font(tree.getDisplay(), fontData);
    font = FontUtils.getFontWithHeight(tree.getFont(), null, fontHeight);
    tree.setFont(font);
    // after a scroll we need to recalculate the hit areas as they will have moved!
    tree.getVerticalBar().addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            if (e.detail == SWT.None) {
                SideBarEntrySWT[] sideBarEntries = getEntries(new SideBarEntrySWT[0]);
                swt_updateSideBarHitAreasY(sideBarEntries);
            }
        }
    });
    Listener treeListener = new Listener() {

        TreeItem lastTopItem = null;

        boolean mouseDowned = false;

        Rectangle lastCloseAreaClicked = null;

        private boolean wasExpanded;

        @Override
        public void handleEvent(final Event event) {
            if (Utils.isDisplayDisposed()) {
                if (event.type == SWT.Dispose) {
                    saveCloseables();
                }
                return;
            }
            TreeItem treeItem = (TreeItem) event.item;
            Tree tree = getTree();
            try {
                switch(event.type) {
                    case SWT.MeasureItem:
                        {
                            int clientWidth = tree.getClientArea().width;
                            String text = treeItem.getText(event.index);
                            Point size = event.gc.textExtent(text);
                            if (event.x + event.width < clientWidth) {
                                // tree.getClientArea().width;
                                event.width = size.x + event.x;
                                event.x = 0;
                            }
                            if (Constants.isWindows) {
                                event.width = clientWidth - event.x;
                            }
                            event.height = 20;
                            break;
                        }
                    case SWT.PaintItem:
                        {
                            SideBarEntrySWT entry = (SideBarEntrySWT) treeItem.getData("MdiEntry");
                            // System.out.println("PaintItem: " + event.item + ";" + event.index + ";" + event.detail + ";" + event.getBounds() + ";" + event.gc.getClipping());
                            if (entry != null) {
                                boolean selected = currentEntry == entry && entry.isSelectable();
                                if (!selected) {
                                    event.detail &= ~SWT.SELECTED;
                                } else {
                                    event.detail |= SWT.SELECTED;
                                }
                                entry.swt_paintSideBar(event);
                            }
                            break;
                        }
                    case SWT.Paint:
                        {
                            // System.out.println("Paint: " + event.getBounds() + ";" + event.detail + ";" + event.index + ";" + event.gc.getClipping());// + "  " + Debug.getCompressedStackTrace());
                            if (!USE_PAINT) {
                                return;
                            }
                            Rectangle bounds = event.getBounds();
                            int indent = END_INDENT ? tree.getClientArea().width - 1 : 0;
                            int y = event.y + 1;
                            treeItem = tree.getItem(new Point(indent, y));
                            while (treeItem != null) {
                                SideBarEntrySWT entry = (SideBarEntrySWT) treeItem.getData("MdiEntry");
                                Rectangle itemBounds = entry == null ? null : entry.swt_getBounds();
                                // happened once, so let's check..
                                if (itemBounds != null && entry != null) {
                                    event.item = treeItem;
                                    boolean selected = currentEntry == entry && entry.isSelectable();
                                    event.detail = selected ? SWT.SELECTED : SWT.NONE;
                                    Rectangle newClip = bounds.intersection(itemBounds);
                                    // System.out.println("Paint " + id + " @ " + newClip);
                                    event.setBounds(newClip);
                                    Utils.setClipping(event.gc, newClip);
                                    entry.swt_paintSideBar(event);
                                    y = itemBounds.y + itemBounds.height + 1;
                                } else {
                                    y += tree.getItemHeight();
                                }
                                if (y > bounds.y + bounds.height) {
                                    break;
                                }
                                TreeItem oldTreeItem = treeItem;
                                treeItem = tree.getItem(new Point(indent, y));
                                if (oldTreeItem == treeItem) {
                                    break;
                                }
                            }
                            if (tree.getTopItem() != lastTopItem) {
                                lastTopItem = tree.getTopItem();
                                SideBarEntrySWT[] sideBarEntries = getEntries(new SideBarEntrySWT[0]);
                                swt_updateSideBarHitAreasY(sideBarEntries);
                            }
                            break;
                        }
                    case SWT.EraseItem:
                        {
                            SideBarEntrySWT entry = (SideBarEntrySWT) treeItem.getData("MdiEntry");
                            if (entry == null) {
                                event.detail = 0;
                            }
                            // event.detail &= ~SWT.FOREGROUND;
                            // event.detail &= ~(SWT.FOREGROUND | SWT.BACKGROUND);
                            event.doit = true;
                            break;
                        }
                    case SWT.Resize:
                        {
                            tree.redraw();
                            break;
                        }
                    case SWT.Selection:
                        {
                            if (treeItem == null) {
                                return;
                            }
                            SideBarEntrySWT entry = (SideBarEntrySWT) treeItem.getData("MdiEntry");
                            if (entry != null && entry.isSelectable()) {
                                Point cursorLocation = tree.toControl(event.display.getCursorLocation());
                                if (lastCloseAreaClicked != null && lastCloseAreaClicked.contains(cursorLocation.x, cursorLocation.y)) {
                                    return;
                                }
                                showEntry(entry);
                            } else if (currentEntry != null) {
                                TreeItem topItem = tree.getTopItem();
                                // prevent "jumping" in the case where selection is off screen
                                // setSelection would jump the item on screen, and then
                                // showItem would jump back to where the user was.
                                tree.setRedraw(false);
                                TreeItem ti = ((SideBarEntrySWT) currentEntry).getTreeItem();
                                if (ti != null) {
                                    tree.setSelection(ti);
                                }
                                tree.setTopItem(topItem);
                                tree.setRedraw(true);
                                event.doit = false;
                            }
                            break;
                        }
                    case SWT.MouseMove:
                        {
                            int indent = END_INDENT ? tree.getClientArea().width - 1 : 0;
                            treeItem = tree.getItem(new Point(indent, event.y));
                            SideBarEntrySWT entry = (SideBarEntrySWT) ((treeItem == null || treeItem.isDisposed()) ? null : treeItem.getData("MdiEntry"));
                            int cursorNo = SWT.CURSOR_ARROW;
                            if (treeItem != null) {
                                Rectangle closeArea = (Rectangle) treeItem.getData("closeArea");
                                if (closeArea != null && closeArea.contains(event.x, event.y)) {
                                    cursorNo = SWT.CURSOR_HAND;
                                } else if (entry != null && !entry.isCollapseDisabled() && treeItem.getItemCount() > 0) {
                                    cursorNo = SWT.CURSOR_HAND;
                                } else if (entry != null) {
                                    MdiEntryVitalityImage[] vitalityImages = entry.getVitalityImages();
                                    for (int i = 0; i < vitalityImages.length; i++) {
                                        SideBarVitalityImageSWT vitalityImage = (SideBarVitalityImageSWT) vitalityImages[i];
                                        if (vitalityImage == null || !vitalityImage.isVisible()) {
                                            continue;
                                        }
                                        Rectangle hitArea = vitalityImage.getHitArea();
                                        if (hitArea == null) {
                                            continue;
                                        }
                                        // setHitArea needs it relative to entry
                                        Rectangle itemBounds = entry.swt_getBounds();
                                        int relY = event.y - (itemBounds == null ? 0 : itemBounds.y);
                                        if (hitArea.contains(event.x, relY)) {
                                            if (vitalityImage.hasListeners()) {
                                                cursorNo = SWT.CURSOR_HAND;
                                            }
                                        }
                                    }
                                }
                            }
                            Cursor cursor = event.display.getSystemCursor(cursorNo);
                            if (tree.getCursor() != cursor) {
                                tree.setCursor(cursor);
                            }
                            if (treeItem != null) {
                                wasExpanded = entry != null && entry.isExpanded();
                            } else {
                                wasExpanded = false;
                            }
                            break;
                        }
                    case SWT.MouseDown:
                        {
                            mouseDowned = true;
                            lastCloseAreaClicked = null;
                            if (tree.getItemCount() == 0 || event.button != 1) {
                                return;
                            }
                            int indent = END_INDENT ? tree.getClientArea().width - 1 : 0;
                            treeItem = tree.getItem(new Point(indent, event.y));
                            if (treeItem == null) {
                                return;
                            }
                            Rectangle closeArea = (Rectangle) treeItem.getData("closeArea");
                            if (closeArea != null && closeArea.contains(event.x, event.y)) {
                                lastCloseAreaClicked = closeArea;
                                treeItem.dispose();
                                // pretend we don't have a mouse down, so we don't process a showEntry
                                mouseDowned = false;
                            }
                            break;
                        }
                    case SWT.MouseUp:
                        {
                            if (!mouseDowned) {
                                return;
                            }
                            mouseDowned = false;
                            if (tree.getItemCount() == 0 || event.button != 1) {
                                return;
                            }
                            int indent = END_INDENT ? tree.getClientArea().width - 1 : 0;
                            treeItem = tree.getItem(new Point(indent, event.y));
                            if (treeItem == null) {
                                return;
                            }
                            SideBarEntrySWT entry = (SideBarEntrySWT) treeItem.getData("MdiEntry");
                            Rectangle closeArea = (Rectangle) treeItem.getData("closeArea");
                            if (closeArea != null && closeArea.contains(event.x, event.y)) {
                                // treeItem.dispose();
                                return;
                            } else if (currentEntry != entry && Constants.isOSX) {
                                showEntry(entry);
                            }
                            if (entry != null) {
                                MdiEntryVitalityImage[] vitalityImages = entry.getVitalityImages();
                                for (int i = 0; i < vitalityImages.length; i++) {
                                    SideBarVitalityImageSWT vitalityImage = (SideBarVitalityImageSWT) vitalityImages[i];
                                    if (vitalityImage == null || !vitalityImage.isVisible()) {
                                        continue;
                                    }
                                    Rectangle hitArea = vitalityImage.getHitArea();
                                    if (hitArea == null) {
                                        continue;
                                    }
                                    // setHitArea needs it relative to entry
                                    Rectangle itemBounds = entry.swt_getBounds();
                                    int relY = event.y - (itemBounds == null ? 0 : itemBounds.y);
                                    if (hitArea.contains(event.x, relY)) {
                                        vitalityImage.triggerClickedListeners(event.x, relY);
                                        return;
                                    }
                                }
                                if (!entry.isCollapseDisabled() && treeItem.getItemCount() > 0) {
                                    if (!entry.isSelectable() || event.x < 20) {
                                        // Note: On Windows, user can expand row by clicking the invisible area where the OS twisty would be
                                        MdiEntry currentEntry = getCurrentEntry();
                                        if (currentEntry != null && entry.getId().equals(currentEntry.getParentID())) {
                                            showEntryByID(SIDEBAR_SECTION_LIBRARY);
                                        }
                                        entry.setExpanded(!wasExpanded);
                                        wasExpanded = !wasExpanded;
                                    }
                                }
                            }
                            break;
                        }
                    case SWT.Dispose:
                        {
                            fontHeader.dispose();
                            font.dispose();
                            if (dropTarget != null && !dropTarget.isDisposed()) {
                                dropTarget.dispose();
                            }
                            saveCloseables();
                            break;
                        }
                    case SWT.Collapse:
                        {
                            SideBarEntrySWT entry = (SideBarEntrySWT) treeItem.getData("MdiEntry");
                            if (entry.isCollapseDisabled()) {
                                tree.setRedraw(false);
                                Display.getDefault().asyncExec(new Runnable() {

                                    @Override
                                    public void run() {
                                        ((TreeItem) event.item).setExpanded(true);
                                        getTree().setRedraw(true);
                                    }
                                });
                            } else {
                                MdiEntry currentEntry = getCurrentEntry();
                                if (currentEntry != null && entry.getId().equals(currentEntry.getParentID())) {
                                    showEntryByID(SIDEBAR_SECTION_LIBRARY);
                                }
                            }
                            break;
                        }
                }
            } catch (Exception e) {
                Debug.out(e);
            }
        }
    };
    tree.addListener(SWT.Resize, treeListener);
    if (USE_PAINT) {
        tree.addListener(SWT.Paint, treeListener);
    }
    tree.addListener(SWT.MeasureItem, treeListener);
    tree.addListener(SWT.PaintItem, treeListener);
    tree.addListener(SWT.EraseItem, treeListener);
    tree.addListener(SWT.Selection, treeListener);
    tree.addListener(SWT.Dispose, treeListener);
    // For icons
    tree.addListener(SWT.MouseUp, treeListener);
    tree.addListener(SWT.MouseDown, treeListener);
    // For cursor
    tree.addListener(SWT.MouseMove, treeListener);
    // to disable collapsing
    tree.addListener(SWT.Collapse, treeListener);
    dropTarget = new DropTarget(tree, DND.DROP_DEFAULT | DND.DROP_MOVE | DND.DROP_COPY | DND.DROP_LINK | DND.DROP_TARGET_MOVE);
    dropTarget.setTransfer(new Transfer[] { FixedHTMLTransfer.getInstance(), FixedURLTransfer.getInstance(), FileTransfer.getInstance(), TextTransfer.getInstance() });
    dropTarget.addDropListener(new DropTargetAdapter() {

        @Override
        public void dropAccept(DropTargetEvent event) {
            event.currentDataType = FixedURLTransfer.pickBestType(event.dataTypes, event.currentDataType);
        }

        @Override
        public void dragEnter(DropTargetEvent event) {
        }

        @Override
        public void dragOperationChanged(DropTargetEvent event) {
        }

        // @see org.eclipse.swt.dnd.DropTargetAdapter#dragOver(org.eclipse.swt.dnd.DropTargetEvent)
        @Override
        public void dragOver(DropTargetEvent event) {
            TreeItem treeItem = (event.item instanceof TreeItem) ? (TreeItem) event.item : null;
            if (treeItem != null) {
                SideBarEntrySWT entry = (SideBarEntrySWT) treeItem.getData("MdiEntry");
                draggingOver = entry;
            } else {
                draggingOver = null;
            }
            if (draggingOver == null || !draggingOver.hasDropListeners()) {
                boolean isTorrent = TorrentOpener.doesDropHaveTorrents(event);
                if (isTorrent) {
                    event.detail = DND.DROP_COPY;
                } else {
                    event.detail = DND.DROP_NONE;
                }
                draggingOver = null;
            } else if ((event.operations & DND.DROP_LINK) > 0)
                event.detail = DND.DROP_LINK;
            else if ((event.operations & DND.DROP_COPY) > 0)
                event.detail = DND.DROP_COPY;
            else if ((event.operations & DND.DROP_DEFAULT) > 0)
                event.detail = DND.DROP_COPY;
            if (Constants.isOSX) {
                tree.redraw();
            }
            event.feedback = DND.FEEDBACK_SELECT | DND.FEEDBACK_SCROLL | DND.FEEDBACK_EXPAND;
        }

        // @see org.eclipse.swt.dnd.DropTargetAdapter#dragLeave(org.eclipse.swt.dnd.DropTargetEvent)
        @Override
        public void dragLeave(DropTargetEvent event) {
            draggingOver = null;
            tree.redraw();
        }

        @Override
        public void drop(DropTargetEvent event) {
            draggingOver = null;
            tree.redraw();
            if (!(event.item instanceof TreeItem)) {
                defaultDrop(event);
                return;
            }
            TreeItem treeItem = (TreeItem) event.item;
            SideBarEntrySWT entry = (SideBarEntrySWT) treeItem.getData("MdiEntry");
            boolean handled = entry != null && entry.triggerDropListeners(event.data);
            if (!handled) {
                defaultDrop(event);
            }
        }
    });
    final Menu menuTree = new Menu(tree);
    tree.setMenu(menuTree);
    menuTree.addMenuListener(new MenuListener() {

        boolean bShown = false;

        @Override
        public void menuHidden(MenuEvent e) {
            bShown = false;
            if (Constants.isOSX) {
                return;
            }
            // Must dispose in an asyncExec, otherwise SWT.Selection doesn't
            // get fired (async workaround provided by Eclipse Bug #87678)
            Utils.execSWTThreadLater(0, new AERunnable() {

                @Override
                public void runSupport() {
                    if (bShown || menuTree.isDisposed()) {
                        return;
                    }
                    Utils.disposeSWTObjects(menuTree.getItems());
                }
            });
        }

        @Override
        public void menuShown(MenuEvent e) {
            Utils.disposeSWTObjects(menuTree.getItems());
            bShown = true;
            Point ptMouse = tree.toControl(e.display.getCursorLocation());
            int indent = END_INDENT ? tree.getClientArea().width - 1 : 0;
            TreeItem treeItem = tree.getItem(new Point(indent, ptMouse.y));
            if (treeItem == null) {
                return;
            }
            SideBarEntrySWT entry = (SideBarEntrySWT) treeItem.getData("MdiEntry");
            fillMenu(menuTree, entry, "sidebar");
            if (menuTree.getItemCount() == 0) {
                Utils.execSWTThreadLater(0, new AERunnable() {

                    @Override
                    public void runSupport() {
                        menuTree.setVisible(false);
                    }
                });
            }
        }
    });
    if (soSideBarPopout != null) {
        SWTSkinObject soDropDown = skin.getSkinObject("sidebar-dropdown");
        if (soDropDown != null) {
            final Menu menuDropDown = new Menu(soDropDown.getControl());
            menuDropDown.addMenuListener(new MenuListener() {

                boolean bShown = false;

                @Override
                public void menuHidden(MenuEvent e) {
                    bShown = false;
                    if (Constants.isOSX) {
                        return;
                    }
                    // Must dispose in an asyncExec, otherwise SWT.Selection doesn't
                    // get fired (async workaround provided by Eclipse Bug #87678)
                    Utils.execSWTThreadLater(0, new AERunnable() {

                        @Override
                        public void runSupport() {
                            if (bShown || menuDropDown.isDisposed()) {
                                return;
                            }
                            Utils.disposeSWTObjects(menuDropDown.getItems());
                        }
                    });
                }

                @Override
                public void menuShown(MenuEvent e) {
                    Utils.disposeSWTObjects(menuDropDown.getItems());
                    bShown = true;
                    fillDropDownMenu(menuDropDown, tree.getItems(), 0);
                }
            });
            dropDownSelectionListener = new SelectionListener() {

                @Override
                public void widgetSelected(SelectionEvent e) {
                    String id = (String) e.widget.getData("Plugin.viewID");
                    showEntryByID(id);
                }

                @Override
                public void widgetDefaultSelected(SelectionEvent e) {
                }
            };
            SWTSkinButtonUtility btnDropDown = new SWTSkinButtonUtility(soDropDown);
            btnDropDown.addSelectionListener(new SWTSkinButtonUtility.ButtonListenerAdapter() {

                @Override
                public void pressed(SWTSkinButtonUtility buttonUtility, SWTSkinObject skinObject, int stateMask) {
                    Control c = buttonUtility.getSkinObject().getControl();
                    menuDropDown.setLocation(c.getDisplay().getCursorLocation());
                    menuDropDown.setVisible(!menuDropDown.getVisible());
                }
            });
        }
        SWTSkinObject soExpand = skin.getSkinObject("sidebar-expand");
        if (soExpand != null) {
            SWTSkinButtonUtility btnExpand = new SWTSkinButtonUtility(soExpand);
            btnExpand.addSelectionListener(new SWTSkinButtonUtility.ButtonListenerAdapter() {

                @Override
                public void pressed(SWTSkinButtonUtility buttonUtility, SWTSkinObject skinObject, int stateMask) {
                    flipSideBarVisibility();
                }
            });
        }
    }
}
Also used : MenuItemListener(com.biglybt.pif.ui.menus.MenuItemListener) ParameterListener(com.biglybt.core.config.ParameterListener) MenuItemFillListener(com.biglybt.pif.ui.menus.MenuItemFillListener) UISWTViewEventListener(com.biglybt.ui.swt.pif.UISWTViewEventListener) SWTViewListener(com.biglybt.ui.swt.pifimpl.UISWTInstanceImpl.SWTViewListener) PluginUISWTSkinObject(com.biglybt.ui.swt.pif.PluginUISWTSkinObject) BaseMdiEntry(com.biglybt.ui.swt.mdi.BaseMdiEntry) MdiEntry(com.biglybt.ui.mdi.MdiEntry) ParameterListener(com.biglybt.core.config.ParameterListener) UISWTViewEvent(com.biglybt.ui.swt.pif.UISWTViewEvent)

Example 2 with ParameterListener

use of com.biglybt.core.config.ParameterListener in project BiglyBT by BiglySoftware.

the class ConfigSectionTrackerServer method configSectionCreate.

@Override
public Composite configSectionCreate(final Composite parent) {
    GridData gridData;
    GridLayout layout;
    Label label;
    // main tab set up
    Composite gMainTab = new Composite(parent, SWT.NULL);
    gridData = new GridData(GridData.VERTICAL_ALIGN_FILL | GridData.HORIZONTAL_ALIGN_FILL);
    gMainTab.setLayoutData(gridData);
    layout = new GridLayout();
    layout.numColumns = 4;
    gMainTab.setLayout(layout);
    int userMode = COConfigurationManager.getIntParameter("User Mode");
    if (userMode < REQUIRED_MODE) {
        label = new Label(gMainTab, SWT.WRAP);
        gridData = new GridData();
        label.setLayoutData(gridData);
        final String[] modeKeys = { "ConfigView.section.mode.beginner", "ConfigView.section.mode.intermediate", "ConfigView.section.mode.advanced" };
        String param1, param2;
        if (REQUIRED_MODE < modeKeys.length)
            param1 = MessageText.getString(modeKeys[REQUIRED_MODE]);
        else
            param1 = String.valueOf(REQUIRED_MODE);
        if (userMode < modeKeys.length)
            param2 = MessageText.getString(modeKeys[userMode]);
        else
            param2 = String.valueOf(userMode);
        label.setText(MessageText.getString("ConfigView.notAvailableForMode", new String[] { param1, param2 }));
        return gMainTab;
    }
    if (userMode > 0) {
        // XXX
        label = new Label(gMainTab, SWT.NULL);
        Messages.setLanguageText(label, "ConfigView.section.tracker.ip");
        final StringParameter tracker_ip = new StringParameter(gMainTab, "Tracker IP", "");
        gridData = new GridData();
        gridData.widthHint = 120;
        tracker_ip.setLayoutData(gridData);
        Button check_button = new Button(gMainTab, SWT.PUSH);
        gridData = new GridData();
        gridData.horizontalSpan = 2;
        check_button.setLayoutData(gridData);
        // $NON-NLS-1$
        Messages.setLanguageText(check_button, "ConfigView.section.tracker.checkip");
        final Display display = gMainTab.getDisplay();
        check_button.addListener(SWT.Selection, new Listener() {

            @Override
            public void handleEvent(Event event) {
                IpCheckerWizard wizard = new IpCheckerWizard();
                wizard.setIpSetterCallBack(new IpSetterCallBack() {

                    @Override
                    public void setIp(final String ip) {
                        if (display == null || display.isDisposed())
                            return;
                        display.asyncExec(new AERunnable() {

                            @Override
                            public void runSupport() {
                                if (tracker_ip != null)
                                    tracker_ip.setValue(ip);
                            }
                        });
                    }
                });
            // setIPSetterCallback
            }
        });
        // row
        final BooleanParameter nonsslEnable = new BooleanParameter(gMainTab, "Tracker Port Enable", "ConfigView.section.tracker.port");
        IntParameter tracker_port = new IntParameter(gMainTab, "Tracker Port", 0, 65535);
        gridData = new GridData();
        tracker_port.setLayoutData(gridData);
        final StringParameter tracker_port_backup = new StringParameter(gMainTab, "Tracker Port Backups", "");
        gridData = new GridData();
        gridData.widthHint = 100;
        tracker_port_backup.setLayoutData(gridData);
        Label tracker_port_backup_label = new Label(gMainTab, SWT.NULL);
        Messages.setLanguageText(tracker_port_backup_label, "ConfigView.section.tracker.portbackup");
        // row
        final BooleanParameter sslEnable = new BooleanParameter(gMainTab, "Tracker Port SSL Enable", "ConfigView.section.tracker.sslport");
        IntParameter tracker_port_ssl = new IntParameter(gMainTab, "Tracker Port SSL", 0, 65535);
        gridData = new GridData();
        tracker_port_ssl.setLayoutData(gridData);
        final StringParameter tracker_port_ssl_backup = new StringParameter(gMainTab, "Tracker Port SSL Backups", "");
        gridData = new GridData();
        gridData.widthHint = 100;
        tracker_port_ssl_backup.setLayoutData(gridData);
        Label tracker_port_ssl_backup_label = new Label(gMainTab, SWT.NULL);
        Messages.setLanguageText(tracker_port_ssl_backup_label, "ConfigView.section.tracker.portbackup");
        // create cert row
        Label cert_label = new Label(gMainTab, SWT.NULL);
        Messages.setLanguageText(cert_label, "ConfigView.section.tracker.createcert");
        Button cert_button = new Button(gMainTab, SWT.PUSH);
        Messages.setLanguageText(cert_button, "ConfigView.section.tracker.createbutton");
        cert_button.addListener(SWT.Selection, new Listener() {

            @Override
            public void handleEvent(Event event) {
                new CertificateCreatorWindow();
            }
        });
        Label ssl_faq_label = new Label(gMainTab, SWT.NULL);
        gridData = new GridData();
        gridData.horizontalSpan = 2;
        ssl_faq_label.setLayoutData(gridData);
        Messages.setLanguageText(ssl_faq_label, "ConfigView.section.tracker.sslport.info");
        final String linkFAQ = Constants.PLUGINS_WEB_SITE + "faq.php#19";
        ssl_faq_label.setCursor(ssl_faq_label.getDisplay().getSystemCursor(SWT.CURSOR_HAND));
        ssl_faq_label.setData(linkFAQ);
        ssl_faq_label.setForeground(Colors.blue);
        ssl_faq_label.addMouseListener(new MouseAdapter() {

            @Override
            public void mouseDoubleClick(MouseEvent arg0) {
                Utils.launch(linkFAQ);
            }

            @Override
            public void mouseDown(MouseEvent arg0) {
                Utils.launch(linkFAQ);
            }
        });
        ClipboardCopy.addCopyToClipMenu(ssl_faq_label);
        Control[] ssl_controls = { tracker_port_ssl.getControl(), tracker_port_ssl_backup.getControl(), tracker_port_ssl_backup_label, ssl_faq_label, cert_label, cert_button };
        sslEnable.setAdditionalActionPerformer(new ChangeSelectionActionPerformer(ssl_controls));
        // enable I2P
        gridData = new GridData();
        gridData.horizontalSpan = 1;
        final BooleanParameter i2p_enable = new BooleanParameter(gMainTab, "Tracker I2P Enable", "label.enable.i2p");
        i2p_enable.setLayoutData(gridData);
        final Label i2p_dest = label = new Label(gMainTab, SWT.NULL);
        gridData = new GridData();
        gridData.horizontalSpan = 3;
        label.setLayoutData(gridData);
        ClipboardCopy.addCopyToClipMenu(i2p_dest);
        COConfigurationManager.addAndFireParameterListener("Tracker I2P Host Port", new ParameterListener() {

            ParameterListener l = this;

            @Override
            public void parameterChanged(String parameterName) {
                Utils.execSWTThread(new Runnable() {

                    @Override
                    public void run() {
                        if (i2p_dest.isDisposed()) {
                            COConfigurationManager.removeParameterListener(parameterName, l);
                        } else {
                            String val = "http://" + COConfigurationManager.getStringParameter(parameterName) + "/announce";
                            i2p_dest.setText(val);
                            i2p_dest.setData(val);
                            i2p_dest.getParent().layout(true, true);
                        }
                    }
                });
            }
        });
        // enable Tor
        gridData = new GridData();
        gridData.horizontalSpan = 1;
        final BooleanParameter tor_enable = new BooleanParameter(gMainTab, "Tracker Tor Enable", "label.enable.tor");
        i2p_enable.setLayoutData(gridData);
        final Label tor_dest = label = new Label(gMainTab, SWT.NULL);
        gridData = new GridData();
        gridData.horizontalSpan = 3;
        label.setLayoutData(gridData);
        ClipboardCopy.addCopyToClipMenu(tor_dest);
        COConfigurationManager.addAndFireParameterListener("Tracker Tor Host Port", new ParameterListener() {

            ParameterListener l = this;

            @Override
            public void parameterChanged(String parameterName) {
                Utils.execSWTThread(new Runnable() {

                    @Override
                    public void run() {
                        if (tor_dest.isDisposed()) {
                            COConfigurationManager.removeParameterListener(parameterName, l);
                        } else {
                            String val = "http://" + COConfigurationManager.getStringParameter(parameterName) + "/announce";
                            tor_dest.setText(val);
                            tor_dest.setData(val);
                            tor_dest.getParent().layout(true, true);
                        }
                    }
                });
            }
        });
        Control[] non_ssl_controls = new Control[5];
        non_ssl_controls[0] = tracker_port.getControl();
        non_ssl_controls[1] = tracker_port_backup.getControl();
        non_ssl_controls[2] = tracker_port_backup_label;
        non_ssl_controls[3] = i2p_enable.getControl();
        non_ssl_controls[4] = tor_enable.getControl();
        nonsslEnable.setAdditionalActionPerformer(new ChangeSelectionActionPerformer(non_ssl_controls));
        // row
        gridData = new GridData();
        gridData.horizontalSpan = 1;
        new BooleanParameter(gMainTab, "Tracker Public Enable", "ConfigView.section.tracker.publicenable").setLayoutData(gridData);
        label = new Label(gMainTab, SWT.NULL);
        Messages.setLanguageText(label, "ConfigView.section.tracker.publicenable.info");
        gridData = new GridData();
        gridData.horizontalSpan = 3;
        label.setLayoutData(gridData);
        // row
        BooleanParameter forcePortDetails = new BooleanParameter(gMainTab, "Tracker Port Force External", "ConfigView.section.tracker.forceport");
        label = new Label(gMainTab, SWT.NULL);
        gridData = new GridData();
        gridData.horizontalSpan = 3;
        label.setLayoutData(gridData);
        Control[] f_controls = new Control[1];
        f_controls[0] = forcePortDetails.getControl();
        IAdditionalActionPerformer f_enabler = new GenericActionPerformer(f_controls) {

            @Override
            public void performAction() {
                boolean selected = nonsslEnable.isSelected() || sslEnable.isSelected();
                controls[0].setEnabled(selected);
            }
        };
        nonsslEnable.setAdditionalActionPerformer(f_enabler);
        sslEnable.setAdditionalActionPerformer(f_enabler);
        // row
        // add announce urls to hosted torrents
        BooleanParameter hostAddURLs = new BooleanParameter(gMainTab, "Tracker Host Add Our Announce URLs", "ConfigView.section.tracker.host.addurls");
        gridData = new GridData();
        gridData.horizontalSpan = 2;
        hostAddURLs.setLayoutData(gridData);
        label = new Label(gMainTab, SWT.NULL);
        gridData = new GridData();
        gridData.horizontalSpan = 2;
        label.setLayoutData(gridData);
        // row
        gridData = new GridData();
        gridData.horizontalSpan = 1;
        final BooleanParameter passwordEnableWeb = new BooleanParameter(gMainTab, "Tracker Password Enable Web", "ConfigView.section.tracker.passwordenableweb");
        passwordEnableWeb.setLayoutData(gridData);
        gridData = new GridData();
        gridData.horizontalSpan = 3;
        final BooleanParameter passwordWebHTTPSOnly = new BooleanParameter(gMainTab, "Tracker Password Web HTTPS Only", "ConfigView.section.tracker.passwordwebhttpsonly");
        passwordWebHTTPSOnly.setLayoutData(gridData);
        IAdditionalActionPerformer web_https_enabler = new GenericActionPerformer(passwordWebHTTPSOnly.getControls()) {

            @Override
            public void performAction() {
                boolean selected = passwordEnableWeb.isSelected() && sslEnable.isSelected();
                for (int i = 0; i < controls.length; i++) {
                    controls[i].setEnabled(selected);
                }
            }
        };
        passwordEnableWeb.setAdditionalActionPerformer(web_https_enabler);
        sslEnable.setAdditionalActionPerformer(web_https_enabler);
        // row
        final BooleanParameter passwordEnableTorrent = new BooleanParameter(gMainTab, "Tracker Password Enable Torrent", "ConfigView.section.tracker.passwordenabletorrent");
        label = new Label(gMainTab, SWT.NULL);
        Messages.setLanguageText(label, "ConfigView.section.tracker.passwordenabletorrent.info");
        gridData = new GridData();
        gridData.horizontalSpan = 3;
        label.setLayoutData(gridData);
        // row
        label = new Label(gMainTab, SWT.NULL);
        Messages.setLanguageText(label, "ConfigView.section.tracker.username");
        final StringParameter tracker_username = new StringParameter(gMainTab, "Tracker Username", "");
        gridData = new GridData();
        gridData.widthHint = 100;
        tracker_username.setLayoutData(gridData);
        label = new Label(gMainTab, SWT.NULL);
        label = new Label(gMainTab, SWT.NULL);
        // row
        label = new Label(gMainTab, SWT.NULL);
        Messages.setLanguageText(label, "ConfigView.section.tracker.password");
        final PasswordParameter tracker_password = new PasswordParameter(gMainTab, "Tracker Password");
        gridData = new GridData();
        gridData.widthHint = 100;
        tracker_password.setLayoutData(gridData);
        label = new Label(gMainTab, SWT.NULL);
        label = new Label(gMainTab, SWT.NULL);
        Control[] x_controls = new Control[2];
        x_controls[0] = tracker_username.getControl();
        x_controls[1] = tracker_password.getControl();
        IAdditionalActionPerformer enabler = new GenericActionPerformer(x_controls) {

            @Override
            public void performAction() {
                boolean selected = passwordEnableWeb.isSelected() || passwordEnableTorrent.isSelected();
                for (int i = 0; i < controls.length; i++) {
                    controls[i].setEnabled(selected);
                }
            }
        };
        passwordEnableWeb.setAdditionalActionPerformer(enabler);
        passwordEnableTorrent.setAdditionalActionPerformer(enabler);
        // Poll Group //
        Group gPollStuff = new Group(gMainTab, SWT.NULL);
        Messages.setLanguageText(gPollStuff, "ConfigView.section.tracker.pollinterval");
        gridData = new GridData(GridData.VERTICAL_ALIGN_FILL | GridData.HORIZONTAL_ALIGN_FILL);
        gridData.horizontalSpan = 4;
        gPollStuff.setLayoutData(gridData);
        layout = new GridLayout();
        layout.numColumns = 4;
        gPollStuff.setLayout(layout);
        label = new Label(gPollStuff, SWT.NULL);
        Messages.setLanguageText(label, "ConfigView.section.tracker.pollintervalmin");
        gridData = new GridData();
        label.setLayoutData(gridData);
        IntParameter pollIntervalMin = new IntParameter(gPollStuff, "Tracker Poll Interval Min");
        gridData = new GridData();
        pollIntervalMin.setLayoutData(gridData);
        label = new Label(gPollStuff, SWT.NULL);
        Messages.setLanguageText(label, "ConfigView.section.tracker.pollintervalmax");
        gridData = new GridData();
        label.setLayoutData(gridData);
        IntParameter pollIntervalMax = new IntParameter(gPollStuff, "Tracker Poll Interval Max");
        gridData = new GridData();
        pollIntervalMax.setLayoutData(gridData);
        // row
        label = new Label(gPollStuff, SWT.NULL);
        Messages.setLanguageText(label, "ConfigView.section.tracker.pollintervalincby");
        gridData = new GridData();
        label.setLayoutData(gridData);
        IntParameter pollIntervalIncBy = new IntParameter(gPollStuff, "Tracker Poll Inc By");
        gridData = new GridData();
        pollIntervalIncBy.setLayoutData(gridData);
        label = new Label(gPollStuff, SWT.NULL);
        Messages.setLanguageText(label, "ConfigView.section.tracker.pollintervalincper");
        gridData = new GridData();
        label.setLayoutData(gridData);
        IntParameter pollIntervalIncPer = new IntParameter(gPollStuff, "Tracker Poll Inc Per");
        gridData = new GridData();
        pollIntervalIncPer.setLayoutData(gridData);
        // scrape + cache group
        Group gScrapeCache = new Group(gMainTab, SWT.NULL);
        Messages.setLanguageText(gScrapeCache, "ConfigView.section.tracker.scrapeandcache");
        gridData = new GridData(GridData.VERTICAL_ALIGN_FILL | GridData.HORIZONTAL_ALIGN_FILL);
        gridData.horizontalSpan = 4;
        gScrapeCache.setLayoutData(gridData);
        layout = new GridLayout();
        layout.numColumns = 4;
        gScrapeCache.setLayout(layout);
        // row
        label = new Label(gScrapeCache, SWT.NULL);
        Messages.setLanguageText(label, "ConfigView.section.tracker.announcescrapepercentage");
        IntParameter scrapeannouncepercentage = new IntParameter(gScrapeCache, "Tracker Scrape Retry Percentage");
        gridData = new GridData();
        scrapeannouncepercentage.setLayoutData(gridData);
        label = new Label(gScrapeCache, SWT.NULL);
        Messages.setLanguageText(label, "ConfigView.section.tracker.scrapecacheperiod");
        gridData = new GridData();
        label.setLayoutData(gridData);
        IntParameter scrapeCachePeriod = new IntParameter(gScrapeCache, "Tracker Scrape Cache");
        gridData = new GridData();
        scrapeCachePeriod.setLayoutData(gridData);
        // row
        label = new Label(gScrapeCache, SWT.NULL);
        Messages.setLanguageText(label, "ConfigView.section.tracker.announcecacheminpeers");
        IntParameter announceCacheMinPeers = new IntParameter(gScrapeCache, "Tracker Announce Cache Min Peers");
        gridData = new GridData();
        announceCacheMinPeers.setLayoutData(gridData);
        label = new Label(gScrapeCache, SWT.NULL);
        Messages.setLanguageText(label, "ConfigView.section.tracker.announcecacheperiod");
        gridData = new GridData();
        label.setLayoutData(gridData);
        IntParameter announceCachePeriod = new IntParameter(gScrapeCache, "Tracker Announce Cache");
        gridData = new GridData();
        announceCachePeriod.setLayoutData(gridData);
        // main tab again
        // row
        label = new Label(gMainTab, SWT.NULL);
        Messages.setLanguageText(label, "ConfigView.section.tracker.maxpeersreturned");
        gridData = new GridData();
        label.setLayoutData(gridData);
        IntParameter maxPeersReturned = new IntParameter(gMainTab, "Tracker Max Peers Returned");
        gridData = new GridData();
        maxPeersReturned.setLayoutData(gridData);
        label = new Label(gMainTab, SWT.NULL);
        label = new Label(gMainTab, SWT.NULL);
        // seed retention limit
        label = new Label(gMainTab, SWT.NULL);
        Messages.setLanguageText(label, "ConfigView.section.tracker.seedretention");
        gridData = new GridData();
        label.setLayoutData(gridData);
        IntParameter seedRetentionLimit = new IntParameter(gMainTab, "Tracker Max Seeds Retained");
        gridData = new GridData();
        seedRetentionLimit.setLayoutData(gridData);
        label = new Label(gMainTab, SWT.NULL);
        Messages.setLanguageText(label, "ConfigView.section.tracker.seedretention.info");
        gridData = new GridData();
        gridData.horizontalSpan = 2;
        label.setLayoutData(gridData);
        // row
        gridData = new GridData();
        gridData.horizontalSpan = 2;
        new BooleanParameter(gMainTab, "Tracker NAT Check Enable", "ConfigView.section.tracker.natcheckenable").setLayoutData(gridData);
        Composite gNATDetails = new Composite(gMainTab, SWT.NULL);
        gridData = new GridData(GridData.VERTICAL_ALIGN_FILL | GridData.HORIZONTAL_ALIGN_FILL);
        gridData.horizontalSpan = 2;
        gNATDetails.setLayoutData(gridData);
        layout = new GridLayout();
        layout.numColumns = 2;
        layout.marginHeight = 0;
        layout.marginWidth = 0;
        gNATDetails.setLayout(layout);
        // row
        label = new Label(gNATDetails, SWT.NULL);
        Messages.setLanguageText(label, "ConfigView.section.tracker.natchecktimeout");
        gridData = new GridData();
        label.setLayoutData(gridData);
        IntParameter NATTimeout = new IntParameter(gNATDetails, "Tracker NAT Check Timeout");
        gridData = new GridData();
        NATTimeout.setLayoutData(gridData);
        // row
        gridData = new GridData();
        gridData.horizontalSpan = 4;
        new BooleanParameter(gMainTab, "Tracker Send Peer IDs", "ConfigView.section.tracker.sendpeerids").setLayoutData(gridData);
        // row
        gridData = new GridData();
        gridData.horizontalSpan = 4;
        BooleanParameter enable_udp = new BooleanParameter(gMainTab, "Tracker Port UDP Enable", "ConfigView.section.tracker.enableudp");
        enable_udp.setLayoutData(gridData);
        // row
        Label udp_version_label = new Label(gMainTab, SWT.NULL);
        Messages.setLanguageText(udp_version_label, "ConfigView.section.tracker.udpversion");
        gridData = new GridData();
        IntParameter udp_version = new IntParameter(gMainTab, "Tracker Port UDP Version");
        udp_version.setLayoutData(gridData);
        label = new Label(gMainTab, SWT.NULL);
        label = new Label(gMainTab, SWT.NULL);
        enable_udp.setAdditionalActionPerformer(new ChangeSelectionActionPerformer(new Control[] { udp_version_label, udp_version.getControl() }));
        // row
        gridData = new GridData();
        gridData.horizontalSpan = 4;
        new BooleanParameter(gMainTab, "Tracker Compact Enable", "ConfigView.section.tracker.enablecompact").setLayoutData(gridData);
        // row
        gridData = new GridData();
        gridData.horizontalSpan = 4;
        BooleanParameter log_enable = new BooleanParameter(gMainTab, "Tracker Log Enable", "ConfigView.section.tracker.logenable");
        log_enable.setLayoutData(gridData);
        if (userMode > 1) {
            // XXX
            // row
            gridData = new GridData();
            gridData.horizontalSpan = 4;
            new BooleanParameter(gMainTab, "Tracker Key Enable Server", "ConfigView.section.tracker.enablekey").setLayoutData(gridData);
            // banned peers
            Label banned_peers_label = new Label(gMainTab, SWT.NULL);
            Messages.setLanguageText(banned_peers_label, "ConfigView.section.tracker.banned.clients");
            gridData = new GridData(GridData.FILL_HORIZONTAL);
            gridData.horizontalSpan = 3;
            new StringParameter(gMainTab, "Tracker Banned Clients", "").setLayoutData(gridData);
            // Networks Group //
            Group networks_group = new Group(gMainTab, SWT.NULL);
            Messages.setLanguageText(networks_group, "ConfigView.section.tracker.server.group.networks");
            GridData networks_layout = new GridData(GridData.VERTICAL_ALIGN_FILL | GridData.HORIZONTAL_ALIGN_FILL);
            networks_layout.horizontalSpan = 4;
            networks_group.setLayoutData(networks_layout);
            layout = new GridLayout();
            layout.numColumns = 2;
            networks_group.setLayout(layout);
            label = new Label(networks_group, SWT.NULL);
            Messages.setLanguageText(label, "ConfigView.section.tracker.server.group.networks.info");
            GridData grid_data = new GridData();
            grid_data.horizontalSpan = 2;
            label.setLayoutData(grid_data);
            for (int i = 0; i < AENetworkClassifier.AT_NETWORKS.length; i++) {
                String nn = AENetworkClassifier.AT_NETWORKS[i];
                String config_name = "Tracker Network Selection Default." + nn;
                String msg_text = "ConfigView.section.connection.networks." + nn;
                BooleanParameter network = new BooleanParameter(networks_group, config_name, msg_text);
                grid_data = new GridData();
                grid_data.horizontalSpan = 2;
                network.setLayoutData(grid_data);
            }
            // processing limits group //
            Group gProcessing = new Group(gMainTab, SWT.NULL);
            Messages.setLanguageText(gProcessing, "ConfigView.section.tracker.processinglimits");
            gridData = new GridData(GridData.VERTICAL_ALIGN_FILL | GridData.HORIZONTAL_ALIGN_FILL);
            gridData.horizontalSpan = 4;
            gProcessing.setLayoutData(gridData);
            layout = new GridLayout();
            layout.numColumns = 3;
            gProcessing.setLayout(layout);
            // row annouce/scrape max process time
            label = new Label(gProcessing, SWT.NULL);
            Messages.setLanguageText(label, "ConfigView.section.tracker.maxgettime");
            gridData = new GridData();
            label.setLayoutData(gridData);
            IntParameter maxGetTime = new IntParameter(gProcessing, "Tracker Max GET Time");
            gridData = new GridData();
            maxGetTime.setLayoutData(gridData);
            label = new Label(gProcessing, SWT.NULL);
            Messages.setLanguageText(label, "ConfigView.section.tracker.maxgettime.info");
            // row post multiplier
            label = new Label(gProcessing, SWT.NULL);
            Messages.setLanguageText(label, "ConfigView.section.tracker.maxposttimemultiplier");
            gridData = new GridData();
            label.setLayoutData(gridData);
            IntParameter maxPostTimeMultiplier = new IntParameter(gProcessing, "Tracker Max POST Time Multiplier");
            gridData = new GridData();
            maxPostTimeMultiplier.setLayoutData(gridData);
            label = new Label(gProcessing, SWT.NULL);
            Messages.setLanguageText(label, "ConfigView.section.tracker.maxposttimemultiplier.info");
            // row max threads
            label = new Label(gProcessing, SWT.NULL);
            Messages.setLanguageText(label, "ConfigView.section.tracker.maxthreads");
            gridData = new GridData();
            label.setLayoutData(gridData);
            IntParameter maxThreadsTime = new IntParameter(gProcessing, "Tracker Max Threads");
            maxThreadsTime.setMinimumValue(1);
            maxThreadsTime.setMaximumValue(4096);
            gridData = new GridData();
            maxThreadsTime.setLayoutData(gridData);
            label = new Label(gProcessing, SWT.NULL);
            // non-blocking tracker group //
            Group gNBTracker = new Group(gMainTab, SWT.NULL);
            Messages.setLanguageText(gNBTracker, "ConfigView.section.tracker.nonblocking");
            gridData = new GridData(GridData.VERTICAL_ALIGN_FILL | GridData.HORIZONTAL_ALIGN_FILL);
            gridData.horizontalSpan = 4;
            gNBTracker.setLayoutData(gridData);
            layout = new GridLayout();
            layout.numColumns = 3;
            gNBTracker.setLayout(layout);
            // row
            gridData = new GridData();
            gridData.horizontalSpan = 3;
            BooleanParameter nb_enable = new BooleanParameter(gNBTracker, "Tracker TCP NonBlocking", "ConfigView.section.tracker.tcpnonblocking");
            nb_enable.setLayoutData(gridData);
            // row max conc connections
            label = new Label(gNBTracker, SWT.NULL);
            Messages.setLanguageText(label, "ConfigView.section.tracker.nonblockingconcmax");
            gridData = new GridData();
            label.setLayoutData(gridData);
            IntParameter maxConcConn = new IntParameter(gNBTracker, "Tracker TCP NonBlocking Conc Max");
            gridData = new GridData();
            maxConcConn.setLayoutData(gridData);
            label = new Label(gNBTracker, SWT.NULL);
            nb_enable.setAdditionalActionPerformer(new ChangeSelectionActionPerformer(maxConcConn.getControls()));
        }
    }
    return gMainTab;
}
Also used : AERunnable(com.biglybt.core.util.AERunnable) ParameterListener(com.biglybt.core.config.ParameterListener) GridLayout(org.eclipse.swt.layout.GridLayout) IpSetterCallBack(com.biglybt.ui.swt.ipchecker.IpSetterCallBack) MouseEvent(org.eclipse.swt.events.MouseEvent) CertificateCreatorWindow(com.biglybt.ui.swt.auth.CertificateCreatorWindow) IpCheckerWizard(com.biglybt.ui.swt.ipchecker.IpCheckerWizard) MouseAdapter(org.eclipse.swt.events.MouseAdapter) AERunnable(com.biglybt.core.util.AERunnable) GridData(org.eclipse.swt.layout.GridData) MouseEvent(org.eclipse.swt.events.MouseEvent) ParameterListener(com.biglybt.core.config.ParameterListener)

Example 3 with ParameterListener

use of com.biglybt.core.config.ParameterListener in project BiglyBT by BiglySoftware.

the class ConfigSectionInterface method configSectionCreate.

@Override
public Composite configSectionCreate(final Composite parent) {
    GridData gridData;
    GridLayout layout;
    Label label;
    Composite cDisplay = new Composite(parent, SWT.NULL);
    gridData = new GridData(GridData.VERTICAL_ALIGN_FILL | GridData.HORIZONTAL_ALIGN_FILL);
    Utils.setLayoutData(cDisplay, gridData);
    layout = new GridLayout();
    layout.numColumns = 1;
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    cDisplay.setLayout(layout);
    final PlatformManager platform = PlatformManagerFactory.getPlatformManager();
    // ***** auto open group
    Group gAutoOpen = new Group(cDisplay, SWT.NULL);
    Messages.setLanguageText(gAutoOpen, "ConfigView.label.autoopen");
    layout = new GridLayout(3, false);
    gAutoOpen.setLayout(layout);
    Utils.setLayoutData(gAutoOpen, new GridData(GridData.FILL_HORIZONTAL));
    label = new Label(gAutoOpen, SWT.NULL);
    Messages.setLanguageText(label, "ConfigView.label.autoopen.detailstab");
    new BooleanParameter(gAutoOpen, "Open Details", "ConfigView.label.autoopen.dl");
    new BooleanParameter(gAutoOpen, "Open Seeding Details", "ConfigView.label.autoopen.cd");
    label = new Label(gAutoOpen, SWT.NULL);
    Messages.setLanguageText(label, "ConfigView.label.autoopen.downloadbars");
    new BooleanParameter(gAutoOpen, "Open Bar Incomplete", "ConfigView.label.autoopen.dl");
    new BooleanParameter(gAutoOpen, "Open Bar Complete", "ConfigView.label.autoopen.cd");
    if (!Constants.isOSX) {
        new BooleanParameter(cDisplay, "Show Status In Window Title", "ConfigView.label.info.in.window.title");
    }
    new BooleanParameter(cDisplay, "Remember transfer bar location", "ConfigView.label.transferbar.remember_location");
    Composite gBarTrans = new Composite(cDisplay, SWT.NULL);
    layout = new GridLayout(4, false);
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    gBarTrans.setLayout(layout);
    gridData = new GridData(GridData.FILL_HORIZONTAL);
    gridData.horizontalIndent = 25;
    Utils.setLayoutData(gBarTrans, gridData);
    label = new Label(gBarTrans, SWT.NULL);
    Messages.setLanguageText(label, "label.bar.trans");
    new IntParameter(gBarTrans, "Bar Transparency", 0, 100);
    label = new Label(gBarTrans, SWT.NULL);
    Messages.setLanguageText(label, "label.show.icon.area");
    new BooleanParameter(gBarTrans, "Transfer Bar Show Icon Area");
    {
        // sys tray
        Group gSysTray = new Group(cDisplay, SWT.NULL);
        Messages.setLanguageText(gSysTray, "ConfigView.label.systray");
        layout = new GridLayout();
        layout.numColumns = 2;
        gSysTray.setLayout(layout);
        Utils.setLayoutData(gSysTray, new GridData(GridData.FILL_HORIZONTAL));
        BooleanParameter est = new BooleanParameter(gSysTray, "Enable System Tray", "ConfigView.section.interface.enabletray");
        est.addChangeListener(new ParameterChangeAdapter() {

            @Override
            public void booleanParameterChanging(Parameter p, boolean toValue) {
                if (toValue) {
                    SystemTraySWT.getTray();
                } else {
                    SystemTraySWT.getTray().dispose();
                }
            }
        });
        BooleanParameter stdo = new BooleanParameter(gSysTray, "System Tray Disabled Override", "ConfigView.label.closetotrayoverride");
        BooleanParameter ctt = new BooleanParameter(gSysTray, "Close To Tray", "ConfigView.label.closetotray");
        gridData = new GridData(GridData.FILL_HORIZONTAL);
        gridData.horizontalSpan = 2;
        ctt.setLayoutData(gridData);
        BooleanParameter mtt = new BooleanParameter(gSysTray, "Minimize To Tray", "ConfigView.label.minimizetotray");
        gridData = new GridData(GridData.FILL_HORIZONTAL);
        gridData.horizontalSpan = 2;
        mtt.setLayoutData(gridData);
        BooleanParameter esttt = new BooleanParameter(gSysTray, "ui.systray.tooltip.enable", "ConfigView.label.enableSystrayToolTip");
        gridData = new GridData(GridData.FILL_HORIZONTAL);
        gridData.horizontalSpan = 2;
        esttt.setLayoutData(gridData);
        BooleanParameter estttd = new BooleanParameter(gSysTray, "ui.systray.tooltip.next.eta.enable", "ConfigView.label.enableSystrayToolTipNextETA");
        gridData = new GridData(GridData.FILL_HORIZONTAL);
        gridData.horizontalSpan = 2;
        gridData.horizontalIndent = 25;
        estttd.setLayoutData(gridData);
        est.setAdditionalActionPerformer(new ChangeSelectionActionPerformer(stdo.getControls(), true));
        IAdditionalActionPerformer st_enabler = new GenericActionPerformer(new Control[] {}) {

            @Override
            public void performAction() {
                boolean st_enabled = est.isSelected();
                boolean override = stdo.isSelected();
                boolean dl_stats = esttt.isSelected();
                ctt.setEnabled(st_enabled || override);
                mtt.setEnabled(st_enabled || override);
                esttt.setEnabled(st_enabled);
                estttd.setEnabled(st_enabled && dl_stats);
            }
        };
        est.setAdditionalActionPerformer(st_enabler);
        stdo.setAdditionalActionPerformer(st_enabler);
        esttt.setAdditionalActionPerformer(st_enabler);
    }
    /**
     * Default download / upload limits available in the UI.
     */
    Group limit_group = new Group(cDisplay, SWT.NULL);
    Messages.setLanguageText(limit_group, "ConfigView.label.set_ui_transfer_speeds");
    layout = new GridLayout();
    layout.numColumns = 2;
    limit_group.setLayout(layout);
    Utils.setLayoutData(limit_group, new GridData(GridData.FILL_HORIZONTAL));
    Label limit_group_label = new Label(limit_group, SWT.WRAP);
    Utils.setLayoutData(limit_group_label, Utils.getWrappableLabelGridData(2, GridData.GRAB_HORIZONTAL));
    Messages.setLanguageText(limit_group_label, "ConfigView.label.set_ui_transfer_speeds.description");
    String[] limit_types = new String[] { "download", "upload" };
    final String limit_type_prefix = "config.ui.speed.partitions.manual.";
    for (int i = 0; i < limit_types.length; i++) {
        final BooleanParameter bp = new BooleanParameter(limit_group, limit_type_prefix + limit_types[i] + ".enabled", false, "ConfigView.label.set_ui_transfer_speeds.description." + limit_types[i]);
        final StringParameter sp = new StringParameter(limit_group, limit_type_prefix + limit_types[i] + ".values", "");
        IAdditionalActionPerformer iaap = new GenericActionPerformer(new Control[] {}) {

            @Override
            public void performAction() {
                sp.getControl().setEnabled(bp.isSelected());
            }
        };
        gridData = new GridData();
        gridData.widthHint = 150;
        sp.setLayoutData(gridData);
        iaap.performAction();
        bp.setAdditionalActionPerformer(iaap);
    }
    // send version
    new BooleanParameter(cDisplay, "Send Version Info", "ConfigView.label.allowSendVersion");
    Composite cArea = new Composite(cDisplay, SWT.NULL);
    layout = new GridLayout();
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    layout.numColumns = 2;
    cArea.setLayout(layout);
    Utils.setLayoutData(cArea, new GridData(GridData.FILL_HORIZONTAL));
    new LinkLabel(cArea, "ConfigView.label.version.info.link", Constants.URL_WIKI + "w/Version.azureusplatform.com");
    if (!Constants.isOSX) {
        BooleanParameter confirm = new BooleanParameter(cArea, "confirmationOnExit", "ConfigView.section.style.confirmationOnExit");
        gridData = new GridData();
        gridData.horizontalSpan = 2;
        confirm.setLayoutData(gridData);
    }
    cArea = new Composite(cDisplay, SWT.NULL);
    layout = new GridLayout();
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    layout.numColumns = 2;
    cArea.setLayout(layout);
    Utils.setLayoutData(cArea, new GridData(GridData.FILL_HORIZONTAL));
    // clear remembered decisions
    final Label clear_label = new Label(cArea, SWT.NULL);
    Messages.setLanguageText(clear_label, "ConfigView.section.interface.cleardecisions");
    final Button clear_decisions = new Button(cArea, SWT.PUSH);
    Messages.setLanguageText(clear_decisions, "ConfigView.section.interface.cleardecisionsbutton");
    clear_decisions.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event event) {
            RememberedDecisionsManager.clearAll();
        }
    });
    final Label clear_tracker_label = new Label(cArea, SWT.NULL);
    Messages.setLanguageText(clear_tracker_label, "ConfigView.section.interface.cleartrackers");
    final Button clear_tracker_button = new Button(cArea, SWT.PUSH);
    Messages.setLanguageText(clear_tracker_button, "ConfigView.section.interface.cleartrackersbutton");
    clear_tracker_button.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event event) {
            TrackersUtil.getInstance().clearAllTrackers(true);
        }
    });
    final Label clear_save_path_label = new Label(cArea, SWT.NULL);
    Messages.setLanguageText(clear_save_path_label, "ConfigView.section.interface.clearsavepaths");
    final Button clear_save_path_button = new Button(cArea, SWT.PUSH);
    Messages.setLanguageText(clear_save_path_button, "ConfigView.section.interface.clearsavepathsbutton");
    clear_save_path_button.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event event) {
            COConfigurationManager.setParameter("saveTo_list", new ArrayList());
        }
    });
    decisions_parameter_listener = new ParameterListener() {

        @Override
        public void parameterChanged(String parameterName) {
            if (clear_decisions.isDisposed()) {
                // tidy up from previous incarnations
                COConfigurationManager.removeParameterListener("MessageBoxWindow.decisions", this);
            } else {
                boolean enabled = COConfigurationManager.getMapParameter("MessageBoxWindow.decisions", new HashMap()).size() > 0;
                clear_label.setEnabled(enabled);
                clear_decisions.setEnabled(enabled);
            }
        }
    };
    decisions_parameter_listener.parameterChanged(null);
    COConfigurationManager.addParameterListener("MessageBoxWindow.decisions", decisions_parameter_listener);
    if (platform.hasCapability(PlatformManagerCapabilities.RegisterFileAssociations)) {
        Composite cResetAssoc = new Composite(cArea, SWT.NULL);
        layout = new GridLayout();
        layout.marginHeight = 0;
        layout.marginWidth = 0;
        layout.numColumns = 2;
        cResetAssoc.setLayout(layout);
        Utils.setLayoutData(cResetAssoc, new GridData());
        label = new Label(cResetAssoc, SWT.NULL);
        Messages.setLanguageText(label, "ConfigView.section.interface.resetassoc");
        Button reset = new Button(cResetAssoc, SWT.PUSH);
        Messages.setLanguageText(reset, // $NON-NLS-1$
        "ConfigView.section.interface.resetassocbutton");
        reset.addListener(SWT.Selection, new Listener() {

            @Override
            public void handleEvent(Event event) {
                try {
                    platform.registerApplication();
                } catch (PlatformManagerException e) {
                    Logger.log(new LogAlert(LogAlert.UNREPEATABLE, "Failed to register application", e));
                }
            }
        });
        new BooleanParameter(cArea, "config.interface.checkassoc", "ConfigView.section.interface.checkassoc");
    }
    return cDisplay;
}
Also used : PlatformManager(com.biglybt.platform.PlatformManager) ParameterListener(com.biglybt.core.config.ParameterListener) HashMap(java.util.HashMap) LinkLabel(com.biglybt.ui.swt.components.LinkLabel) ArrayList(java.util.ArrayList) GridLayout(org.eclipse.swt.layout.GridLayout) LogAlert(com.biglybt.core.logging.LogAlert) LinkLabel(com.biglybt.ui.swt.components.LinkLabel) GridData(org.eclipse.swt.layout.GridData) ParameterListener(com.biglybt.core.config.ParameterListener) PlatformManagerException(com.biglybt.pif.platform.PlatformManagerException)

Example 4 with ParameterListener

use of com.biglybt.core.config.ParameterListener in project BiglyBT by BiglySoftware.

the class ConfigSectionInterfaceTables method configSectionCreate.

@Override
public Composite configSectionCreate(final Composite parent) {
    int userMode = COConfigurationManager.getIntParameter("User Mode");
    boolean isAZ3 = COConfigurationManager.getStringParameter("ui").equals("az3");
    // "Display" Sub-Section:
    // ----------------------
    // Any Look & Feel settings that don't really change the way the user
    // normally interacts
    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);
    {
        Group cGeneral = new Group(cSection, SWT.NULL);
        Messages.setLanguageText(cGeneral, "ConfigView.section.global");
        layout = new GridLayout();
        layout.numColumns = 2;
        cGeneral.setLayout(layout);
        Utils.setLayoutData(cGeneral, new GridData(GridData.FILL_HORIZONTAL));
        label = new Label(cGeneral, SWT.NULL);
        Messages.setLanguageText(label, "ConfigView.section.style.defaultSortOrder");
        int[] sortOrderValues = { 0, 1, 2, 3 };
        String[] sortOrderLabels = { MessageText.getString("ConfigView.section.style.defaultSortOrder.asc"), MessageText.getString("ConfigView.section.style.defaultSortOrder.desc"), MessageText.getString("ConfigView.section.style.defaultSortOrder.flip"), MessageText.getString("ConfigView.section.style.defaultSortOrder.same") };
        new IntListParameter(cGeneral, "config.style.table.defaultSortOrder", sortOrderLabels, sortOrderValues);
        if (userMode > 0) {
            label = new Label(cGeneral, 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(cGeneral, "GUI Refresh", 1000, labels, values);
            label = new Label(cGeneral, SWT.NULL);
            Messages.setLanguageText(label, "ConfigView.section.style.graphicsUpdate");
            gridData = new GridData();
            IntParameter graphicUpdate = new IntParameter(cGeneral, "Graphics Update", 1, Integer.MAX_VALUE);
            graphicUpdate.setLayoutData(gridData);
            label = new Label(cGeneral, SWT.NULL);
            Messages.setLanguageText(label, "ConfigView.section.style.reOrderDelay");
            gridData = new GridData();
            IntParameter reorderDelay = new IntParameter(cGeneral, "ReOrder Delay");
            reorderDelay.setLayoutData(gridData);
            new BooleanParameter(cGeneral, "NameColumn.showProgramIcon", "ConfigView.section.style.showProgramIcon").setLayoutData(new GridData(SWT.FILL, SWT.LEFT, true, false, 2, 1));
            // //
            new BooleanParameter(cGeneral, "Table.extendedErase", "ConfigView.section.style.extendedErase").setLayoutData(new GridData(SWT.FILL, SWT.LEFT, true, false, 2, 1));
            // //
            boolean hhEnabled = COConfigurationManager.getIntParameter("Table.headerHeight") > 0;
            Button chkHeaderHeight = new Button(cGeneral, SWT.CHECK);
            Messages.setLanguageText(chkHeaderHeight, "ConfigView.section.style.enableHeaderHeight");
            chkHeaderHeight.setSelection(hhEnabled);
            final IntParameter paramHH = new IntParameter(cGeneral, "Table.headerHeight", 0, 100);
            paramHH.setEnabled(hhEnabled);
            chkHeaderHeight.addSelectionListener(new SelectionListener() {

                @Override
                public void widgetSelected(SelectionEvent e) {
                    if (((Button) e.widget).getSelection()) {
                        COConfigurationManager.setParameter("Table.headerHeight", 16);
                        paramHH.setEnabled(true);
                    } else {
                        COConfigurationManager.setParameter("Table.headerHeight", 0);
                        paramHH.setEnabled(false);
                    }
                }

                @Override
                public void widgetDefaultSelected(SelectionEvent e) {
                }
            });
            // ///
            boolean cdEnabled = COConfigurationManager.getStringParameter("Table.column.dateformat", "").length() > 0;
            Button chkCustomDate = new Button(cGeneral, SWT.CHECK);
            Messages.setLanguageText(chkCustomDate, "ConfigView.section.style.customDateFormat");
            chkCustomDate.setSelection(cdEnabled);
            final StringParameter paramCustomDate = new StringParameter(cGeneral, "Table.column.dateformat", "");
            paramCustomDate.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
            paramCustomDate.setEnabled(cdEnabled);
            paramCustomDate.addChangeListener(new ParameterChangeAdapter() {

                @Override
                public void parameterChanged(Parameter p, boolean caused_internally) {
                    String s = (String) p.getValueObject();
                    boolean ok = false;
                    try {
                        SimpleDateFormat temp = new SimpleDateFormat(s);
                        temp.format(new Date());
                        ok = true;
                    } catch (Exception e) {
                    // probably illegalargumentexception
                    }
                    p.getControl().setBackground(ok ? null : Colors.colorErrorBG);
                }
            });
            chkCustomDate.addSelectionListener(new SelectionListener() {

                @Override
                public void widgetSelected(SelectionEvent e) {
                    if (((Button) e.widget).getSelection()) {
                        COConfigurationManager.setParameter("Table.column.dateformat", "yyyy/MM/dd");
                        paramCustomDate.setEnabled(true);
                    } else {
                        COConfigurationManager.setParameter("Table.column.dateformat", "");
                        paramCustomDate.setEnabled(false);
                    }
                }

                @Override
                public void widgetDefaultSelected(SelectionEvent e) {
                }
            });
            new BooleanParameter(cGeneral, "Table.tooltip.disable", "ConfigView.section.table.disable.tooltips").setLayoutData(new GridData(SWT.FILL, SWT.LEFT, true, false, 2, 1));
        }
    }
    {
        Group cLibrary = new Group(cSection, SWT.NULL);
        Messages.setLanguageText(cLibrary, "ConfigView.section.style.library");
        layout = new GridLayout();
        layout.numColumns = 2;
        cLibrary.setLayout(layout);
        Utils.setLayoutData(cLibrary, new GridData(GridData.FILL_HORIZONTAL));
        // User tree
        new BooleanParameter(cLibrary, "Table.useTree", "ConfigView.section.style.useTree").setLayoutData(new GridData(SWT.FILL, SWT.LEFT, true, false, 2, 1));
        if (userMode > 1) {
            new BooleanParameter(cLibrary, "DND Always In Incomplete", "ConfigView.section.style.DNDalwaysInIncomplete").setLayoutData(new GridData(SWT.FILL, SWT.LEFT, true, false, 2, 1));
        }
        if (isAZ3) {
            new BooleanParameter(cLibrary, "Library.EnableSimpleView", "ConfigView.section.style.EnableSimpleView").setLayoutData(new GridData(SWT.FILL, SWT.LEFT, true, false, 2, 1));
            new BooleanParameter(cLibrary, "Library.CatInSideBar", "ConfigView.section.style.CatInSidebar").setLayoutData(new GridData(SWT.FILL, SWT.LEFT, true, false, 2, 1));
        }
        new BooleanParameter(cLibrary, "Library.ShowCatButtons", "ConfigView.section.style.ShowCatButtons").setLayoutData(new GridData(SWT.FILL, SWT.LEFT, true, false, 2, 1));
        if (isAZ3) {
            new BooleanParameter(cLibrary, "Library.TagInSideBar", "ConfigView.section.style.TagInSidebar").setLayoutData(new GridData(SWT.FILL, SWT.LEFT, true, false, 2, 1));
        }
        BooleanParameter show_tag = new BooleanParameter(cLibrary, "Library.ShowTagButtons", "ConfigView.section.style.ShowTagButtons");
        show_tag.setLayoutData(new GridData(SWT.FILL, SWT.LEFT, true, false, 2, 1));
        BooleanParameter show_tag_comp_only = new BooleanParameter(cLibrary, "Library.ShowTagButtons.CompOnly", "ConfigView.section.style.ShowTagButtons.CompOnly");
        gridData = new GridData(SWT.FILL, SWT.LEFT, true, false, 2, 1);
        gridData.horizontalIndent = 25;
        show_tag_comp_only.setLayoutData(gridData);
        show_tag.setAdditionalActionPerformer(new ChangeSelectionActionPerformer(show_tag_comp_only));
        if (isAZ3) {
            new BooleanParameter(cLibrary, "Library.ShowTabsInTorrentView", "ConfigView.section.style.ShowTabsInTorrentView").setLayoutData(new GridData(SWT.FILL, SWT.LEFT, true, false, 2, 1));
        }
        new BooleanParameter(cLibrary, "Library.showFancyMenu", true, "ConfigView.section.style.ShowFancyMenu").setLayoutData(new GridData(SWT.FILL, SWT.LEFT, true, false, 2, 1));
        // double-click
        label = new Label(cLibrary, SWT.NULL);
        Messages.setLanguageText(label, "ConfigView.label.dm.dblclick");
        String[] dblclickOptions = { "ConfigView.option.dm.dblclick.play", "ConfigView.option.dm.dblclick.details", "ConfigView.option.dm.dblclick.show", "ConfigView.option.dm.dblclick.launch", "ConfigView.option.dm.dblclick.launch.qv", "ConfigView.option.dm.dblclick.open.browser" };
        String[] dblclickLabels = new String[dblclickOptions.length];
        String[] dblclickValues = new String[dblclickOptions.length];
        for (int i = 0; i < dblclickOptions.length; i++) {
            dblclickLabels[i] = MessageText.getString(dblclickOptions[i]);
            dblclickValues[i] = "" + i;
        }
        new StringListParameter(cLibrary, "list.dm.dblclick", dblclickLabels, dblclickValues);
        // always open websites in browser
        Composite cLaunchWeb = new Composite(cLibrary, SWT.NULL);
        layout = new GridLayout();
        layout.numColumns = 4;
        cLaunchWeb.setLayout(layout);
        gridData = new GridData(GridData.FILL_HORIZONTAL);
        gridData.horizontalSpan = 2;
        gridData.horizontalIndent = 25;
        Utils.setLayoutData(cLaunchWeb, gridData);
        BooleanParameter web_in_browser = new BooleanParameter(cLaunchWeb, "Library.LaunchWebsiteInBrowser", "library.launch.web.in.browser");
        BooleanParameter web_in_browser_anon = new BooleanParameter(cLaunchWeb, "Library.LaunchWebsiteInBrowserAnon", "library.launch.web.in.browser.anon");
        web_in_browser.setAdditionalActionPerformer(new ChangeSelectionActionPerformer(web_in_browser_anon));
        // enter action
        label = new Label(cLibrary, SWT.NULL);
        Messages.setLanguageText(label, "ConfigView.label.dm.enteraction");
        String[] enterOptions = { "ConfigView.option.dm.enter.sameasdblclick", "ConfigView.option.dm.dblclick.play", "ConfigView.option.dm.dblclick.details", "ConfigView.option.dm.dblclick.show", "ConfigView.option.dm.dblclick.launch", "ConfigView.option.dm.dblclick.launch.qv", "ConfigView.option.dm.dblclick.open.browser" };
        String[] enterLabels = new String[enterOptions.length];
        String[] enterValues = new String[enterOptions.length];
        for (int i = 0; i < enterOptions.length; i++) {
            enterLabels[i] = MessageText.getString(enterOptions[i]);
            enterValues[i] = "" + (i - 1);
        }
        new StringListParameter(cLibrary, "list.dm.enteraction", enterLabels, enterValues);
        // Launch helpers
        Group cLaunch = new Group(cLibrary, SWT.NULL);
        Messages.setLanguageText(cLaunch, "ConfigView.section.style.launch");
        layout = new GridLayout();
        layout.numColumns = 5;
        cLaunch.setLayout(layout);
        gridData = new GridData(GridData.FILL_HORIZONTAL);
        gridData.horizontalSpan = 2;
        Utils.setLayoutData(cLaunch, gridData);
        Label info_label = new Label(cLaunch, SWT.WRAP);
        Messages.setLanguageText(info_label, "ConfigView.label.lh.info");
        gridData = Utils.getWrappableLabelGridData(5, GridData.HORIZONTAL_ALIGN_FILL);
        Utils.setLayoutData(info_label, gridData);
        for (int i = 0; i < 4; i++) {
            label = new Label(cLaunch, SWT.NULL);
            Messages.setLanguageText(label, "ConfigView.label.lh.ext");
            StringParameter exts = new StringParameter(cLaunch, "Table.lh" + i + ".exts", "");
            gridData = new GridData();
            gridData.widthHint = 200;
            exts.setLayoutData(gridData);
            label = new Label(cLaunch, SWT.NULL);
            Messages.setLanguageText(label, "ConfigView.label.lh.prog");
            final FileParameter prog = new FileParameter(cLaunch, "Table.lh" + i + ".prog", "", new String[0]);
            gridData = new GridData();
            gridData.widthHint = 400;
            prog.getControls()[0].setLayoutData(gridData);
            if (Constants.isOSX) {
                if (configOSX != null) {
                    configOSX = new ParameterListener() {

                        private boolean changing = false;

                        private String last_changed = "";

                        @Override
                        public void parameterChanged(String parameter_name) {
                            if (prog.isDisposed()) {
                                COConfigurationManager.removeParameterListener(parameter_name, this);
                            } else if (changing) {
                                return;
                            } else {
                                final String value = COConfigurationManager.getStringParameter(parameter_name);
                                if (value.equals(last_changed)) {
                                    return;
                                }
                                if (value.endsWith(".app")) {
                                    Utils.execSWTThreadLater(1, new Runnable() {

                                        @Override
                                        public void run() {
                                            last_changed = value;
                                            try {
                                                changing = true;
                                                File file = new File(value);
                                                String app_name = file.getName();
                                                int pos = app_name.lastIndexOf(".");
                                                app_name = app_name.substring(0, pos);
                                                String new_value = value + "/Contents/MacOS/" + app_name;
                                                if (new File(new_value).exists()) {
                                                    prog.setValue(new_value);
                                                }
                                            } finally {
                                                changing = false;
                                            }
                                        }
                                    });
                                }
                            }
                        }
                    };
                }
                COConfigurationManager.addParameterListener("Table.lh" + i + ".prog", configOSX);
            }
        }
    }
    {
        Group cSeachSubs = new Group(cSection, SWT.NULL);
        Messages.setLanguageText(cSeachSubs, "ConfigView.section.style.searchsubs");
        layout = new GridLayout();
        layout.numColumns = 2;
        cSeachSubs.setLayout(layout);
        Utils.setLayoutData(cSeachSubs, new GridData(GridData.FILL_HORIZONTAL));
        new BooleanParameter(cSeachSubs, "Search View Is Web View", "ConfigView.section.style.search.is.web.view").setLayoutData(new GridData(SWT.FILL, SWT.LEFT, true, false, 2, 1));
        new BooleanParameter(cSeachSubs, "Search View Switch Hidden", "ConfigView.section.style.search.hide.view.switch").setLayoutData(new GridData(SWT.FILL, SWT.LEFT, true, false, 2, 1));
        label = new Label(cSeachSubs, SWT.NULL);
        Messages.setLanguageText(label, "ConfigView.section.style.searchsubs.row.height");
        gridData = new GridData();
        IntParameter graphicUpdate = new IntParameter(cSeachSubs, "Search Subs Row Height", 16, 64);
        graphicUpdate.setLayoutData(gridData);
    }
    return cSection;
}
Also used : Group(org.eclipse.swt.widgets.Group) Label(org.eclipse.swt.widgets.Label) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Composite(org.eclipse.swt.widgets.Composite) Date(java.util.Date) GridData(org.eclipse.swt.layout.GridData) ParameterListener(com.biglybt.core.config.ParameterListener) SimpleDateFormat(java.text.SimpleDateFormat) File(java.io.File) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 5 with ParameterListener

use of com.biglybt.core.config.ParameterListener in project BiglyBT by BiglySoftware.

the class DeviceManagerImpl method initWithCore.

void initWithCore(final Core _core) {
    synchronized (this) {
        if (core != null) {
            return;
        }
        core = _core;
    }
    try {
        od_manual_ta = PluginInitializer.getDefaultInterface().getTorrentManager().getPluginAttribute("device.manager.od.ta.manual");
        rss_publisher = new DeviceManagerRSSFeed(this);
        // need to pick up auto-search early on
        COConfigurationManager.addAndFireParameterListeners(new String[] { AUTO_SEARCH_CONFIG_KEY, AUTO_HIDE_OLD_CONFIG_KEY }, new ParameterListener() {

            @Override
            public void parameterChanged(String name) {
                auto_search = COConfigurationManager.getBooleanParameter(AUTO_SEARCH_CONFIG_KEY, true);
                auto_hide_old_days = COConfigurationManager.getIntParameter(AUTO_HIDE_OLD_CONFIG_KEY, AUTO_HIDE_OLD_DAYS_DEFAULT);
            }
        });
        // init tivo before upnp as upnp init completion starts up tivo
        tivo_manager = new DeviceTivoManager(this);
        upnp_manager = new DeviceManagerUPnPImpl(this);
        loadConfig();
        new DeviceiTunesManager(this);
        drive_manager = new DeviceDriveManager(this);
        transcode_manager = new TranscodeManagerImpl(this);
        transcode_manager.initialise();
        core.addLifecycleListener(new CoreLifecycleAdapter() {

            @Override
            public void stopping(Core core) {
                synchronized (DeviceManagerImpl.this) {
                    if (config_dirty || config_unclean) {
                        saveConfig();
                    }
                    closing = true;
                    transcode_manager.close();
                    DeviceImpl[] devices = getDevices();
                    for (DeviceImpl device : devices) {
                        device.close();
                    }
                }
            }
        });
        upnp_manager.initialise();
        SimpleTimer.addPeriodicEvent("DeviceManager:update", DEVICE_UPDATE_PERIOD, new TimerEventPerformer() {

            private int tick_count = 0;

            @Override
            public void perform(TimerEvent event) {
                List<DeviceImpl> copy;
                tick_count++;
                transcode_manager.updateStatus(tick_count);
                synchronized (DeviceManagerImpl.this) {
                    if (device_list.size() == 0) {
                        return;
                    }
                    copy = new ArrayList<>(device_list);
                }
                for (DeviceImpl device : copy) {
                    device.updateStatus(tick_count);
                }
                if (auto_hide_old_days > 0 && tick_count % DEVICE_AUTO_HIDE_CHECK_TICKS == 0) {
                    long now = SystemTime.getCurrentTime();
                    int num_hidden = 0;
                    for (DeviceImpl device : copy) {
                        if (device.isLivenessDetectable() && !device.isTagged()) {
                            int type = device.getType();
                            if (type == Device.DT_CONTENT_DIRECTORY) {
                            } else if (type == Device.DT_MEDIA_RENDERER) {
                                DeviceMediaRenderer rend = (DeviceMediaRenderer) device;
                                if (rend.getRendererSpecies() != DeviceMediaRenderer.RS_OTHER) {
                                    continue;
                                }
                            } else {
                                continue;
                            }
                            long age = now - device.getLastSeen();
                            if (age > auto_hide_old_days * 24 * 60 * 60 * 1000L) {
                                if (!device.isHidden()) {
                                    log("Auto-hiding '" + device.getName() + "'");
                                    device.setHidden(true);
                                    device.setAutoHidden(true);
                                    num_hidden++;
                                }
                            } else {
                                if (device.isHidden() && device.isAutoHidden()) {
                                    log("Auto-showing '" + device.getName() + "'");
                                    device.setAutoHidden(false);
                                    device.setHidden(false);
                                }
                            }
                        }
                    }
                    if (num_hidden > 0) {
                        Logger.log(new LogAlert(true, LogAlert.AT_INFORMATION, MessageText.getString("device.autohide.alert", new String[] { String.valueOf(num_hidden), String.valueOf(auto_hide_old_days) })));
                    }
                }
            }
        });
        initialized = true;
        listeners.dispatch(LT_INITIALIZED, null);
        core.addPowerManagementListener(this);
    } finally {
        init_sem.releaseForever();
    }
}
Also used : CoreLifecycleAdapter(com.biglybt.core.CoreLifecycleAdapter) LogAlert(com.biglybt.core.logging.LogAlert) ParameterListener(com.biglybt.core.config.ParameterListener) Core(com.biglybt.core.Core)

Aggregations

ParameterListener (com.biglybt.core.config.ParameterListener)43 CoreRunningListener (com.biglybt.core.CoreRunningListener)5 LogAlert (com.biglybt.core.logging.LogAlert)5 PriorityParameterListener (com.biglybt.core.config.PriorityParameterListener)4 LogEvent (com.biglybt.core.logging.LogEvent)4 MenuItemListener (com.biglybt.pif.ui.menus.MenuItemListener)4 ArrayList (java.util.ArrayList)4 Core (com.biglybt.core.Core)3 ConfigurationManager (com.biglybt.core.config.impl.ConfigurationManager)3 GlobalManager (com.biglybt.core.global.GlobalManager)3 GlobalManagerAdapter (com.biglybt.core.global.GlobalManagerAdapter)3 GridData (org.eclipse.swt.layout.GridData)3 GridLayout (org.eclipse.swt.layout.GridLayout)3 DownloadManager (com.biglybt.core.download.DownloadManager)2 GlobalManagerListener (com.biglybt.core.global.GlobalManagerListener)2 TOTorrent (com.biglybt.core.torrent.TOTorrent)2 AERunnable (com.biglybt.core.util.AERunnable)2 MenuItem (com.biglybt.pif.ui.menus.MenuItem)2 MenuItemFillListener (com.biglybt.pif.ui.menus.MenuItemFillListener)2 DelayedTask (com.biglybt.pif.utils.DelayedTask)2