Search in sources :

Example 1 with SubscriptionResultFilter

use of com.biglybt.core.subs.SubscriptionResultFilter in project BiglyBT by BiglySoftware.

the class SBC_SubscriptionResultsView method skinObjectInitialShow.

@Override
public Object skinObjectInitialShow(SWTSkinObject skinObject, Object params) {
    CoreFactory.addCoreRunningListener(new CoreRunningListener() {

        @Override
        public void coreRunning(Core core) {
            initColumns(core);
        }
    });
    MultipleDocumentInterfaceSWT mdi = UIFunctionsManagerSWT.getUIFunctionsSWT().getMDISWT();
    if (mdi != null && ds != null) {
        String mdi_key = "Subscription_" + ByteFormatter.encodeString(ds.getPublicKey());
        mdi_entry = mdi.getEntry(mdi_key);
        if (mdi_entry != null) {
            mdi_entry.addToolbarEnabler(this);
        }
    }
    if (ds != null) {
        if ((ds.getViewOptions() & Subscription.VO_HIDE_HEADER) != 0) {
            SWTSkinObject top_area = getSkinObject("toparea");
            top_area.setVisible(false);
        }
        SWTSkinObjectText title = (SWTSkinObjectText) getSkinObject("title");
        if (title != null) {
            title.setText(MessageText.getString("subs.results.view.title", new String[] { ds.getName() }));
            Control control = title.getControl();
            final Menu menu = new Menu(control);
            control.setMenu(menu);
            final String menu_key = SubscriptionMDIEntry.setupMenus(ds, null);
            menu.addMenuListener(new MenuListener() {

                @Override
                public void menuShown(MenuEvent e) {
                    for (MenuItem mi : menu.getItems()) {
                        mi.dispose();
                    }
                    com.biglybt.pif.ui.menus.MenuItem[] menu_items = MenuItemManager.getInstance().getAllAsArray(menu_key);
                    MenuBuildUtils.addPluginMenuItems(menu_items, menu, true, true, new MenuBuildUtils.MenuItemPluginMenuControllerImpl(new Object[] { ds }));
                }

                @Override
                public void menuHidden(MenuEvent e) {
                // TODO Auto-generated method stub
                }
            });
        }
    }
    SWTSkinObjectTextbox soFilterBox = (SWTSkinObjectTextbox) getSkinObject("filterbox");
    if (soFilterBox != null) {
        txtFilter = soFilterBox.getTextControl();
    }
    final SWTSkinObject soFilterArea = getSkinObject("filterarea");
    if (soFilterArea != null) {
        SWTSkinObjectToggle soFilterButton = (SWTSkinObjectToggle) getSkinObject("filter-button");
        if (soFilterButton != null) {
            boolean toggled = COConfigurationManager.getBooleanParameter("Subscription View Filter Options Expanded", false);
            if (toggled) {
                soFilterButton.setToggled(true);
                soFilterArea.setVisible(true);
            }
            soFilterButton.addSelectionListener(new SWTSkinToggleListener() {

                @Override
                public void toggleChanged(SWTSkinObjectToggle so, boolean toggled) {
                    COConfigurationManager.setParameter("Subscription View Filter Options Expanded", toggled);
                    soFilterArea.setVisible(toggled);
                    Utils.relayout(soFilterArea.getControl().getParent());
                }
            });
        }
        Composite parent = (Composite) soFilterArea.getControl();
        Label label;
        FormData fd;
        GridLayout layout;
        int sepHeight = 20;
        Composite cFilters = new Composite(parent, SWT.NONE);
        fd = Utils.getFilledFormData();
        cFilters.setLayoutData(fd);
        layout = new GridLayout(1, true);
        layout.marginBottom = layout.marginTop = layout.marginLeft = layout.marginRight = 0;
        layout.marginWidth = layout.marginHeight = 0;
        cFilters.setLayout(layout);
        SubscriptionResultFilter filters = null;
        Runnable pFilterUpdater = null;
        if (ds != null && ds.isUpdateable()) {
            try {
                filters = ds.getFilters();
                Composite pFilters = new Composite(cFilters, SWT.NONE);
                pFilters.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
                layout = new GridLayout(1, false);
                layout.marginBottom = layout.marginTop = layout.marginLeft = layout.marginRight = 0;
                layout.marginWidth = layout.marginHeight = 0;
                pFilters.setLayout(layout);
                final Label pflabel = new Label(pFilters, SWT.NONE);
                pflabel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
                final SubscriptionResultFilter f_filters = filters;
                pFilterUpdater = new Runnable() {

                    @Override
                    public void run() {
                        long kInB = DisplayFormatters.getKinB();
                        long mInB = kInB * kInB;
                        long min_size = f_filters.getMinSze() / mInB;
                        long max_size = f_filters.getMaxSize() / mInB;
                        pflabel.setText(MessageText.getString("subs.persistent.filters", new String[] { getString(f_filters.getWithWords()), getString(f_filters.getWithoutWords()), String.valueOf(min_size < 0 ? 0 : min_size), String.valueOf(max_size < 0 ? 0 : max_size) }));
                    }
                };
                pFilterUpdater.run();
            } catch (Throwable e) {
                Debug.out(e);
            }
        }
        Composite vFilters = new Composite(cFilters, SWT.NONE);
        vFilters.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
        RowLayout rowLayout = new RowLayout(SWT.HORIZONTAL);
        rowLayout.spacing = 5;
        rowLayout.marginBottom = rowLayout.marginTop = rowLayout.marginLeft = rowLayout.marginRight = 0;
        rowLayout.center = true;
        vFilters.setLayout(rowLayout);
        // with/without keywords
        ImageLoader imageLoader = ImageLoader.getInstance();
        for (int i = 0; i < 2; i++) {
            final boolean with = i == 0;
            if (!with) {
                label = new Label(vFilters, SWT.VERTICAL | SWT.SEPARATOR);
                label.setLayoutData(new RowData(-1, sepHeight));
            }
            Composite cWithKW = new Composite(vFilters, SWT.NONE);
            layout = new GridLayout(2, false);
            layout.marginWidth = 0;
            layout.marginBottom = layout.marginTop = layout.marginLeft = layout.marginRight = 0;
            cWithKW.setLayout(layout);
            // Label lblWithKW = new Label(cWithKW, SWT.NONE);
            // lblWithKW.setText(MessageText.getString(with?"SubscriptionResults.filter.with.words":"SubscriptionResults.filter.without.words"));
            Label lblWithKWImg = new Label(cWithKW, SWT.NONE);
            lblWithKWImg.setImage(imageLoader.getImage(with ? "icon_filter_plus" : "icon_filter_minus"));
            final Text textWithKW = new Text(cWithKW, SWT.BORDER);
            textWithKW.setMessage(MessageText.getString(with ? "SubscriptionResults.filter.with.words" : "SubscriptionResults.filter.without.words"));
            GridData gd = new GridData();
            gd.widthHint = Utils.adjustPXForDPI(100);
            textWithKW.setLayoutData(gd);
            textWithKW.addModifyListener(new ModifyListener() {

                @Override
                public void modifyText(ModifyEvent e) {
                    String text = textWithKW.getText().toLowerCase(Locale.US);
                    String[] bits = text.split("\\s+");
                    Set<String> temp = new HashSet<>();
                    for (String bit : bits) {
                        bit = bit.trim();
                        if (bit.length() > 0) {
                            temp.add(bit);
                        }
                    }
                    String[] words = temp.toArray(new String[temp.size()]);
                    synchronized (filter_lock) {
                        if (with) {
                            with_keywords = words;
                        } else {
                            without_keywords = words;
                        }
                    }
                    refilter_dispatcher.dispatch();
                }
            });
        }
        // min size
        label = new Label(vFilters, SWT.VERTICAL | SWT.SEPARATOR);
        label.setLayoutData(new RowData(-1, sepHeight));
        Composite cMinSize = new Composite(vFilters, SWT.NONE);
        layout = new GridLayout(2, false);
        layout.marginWidth = 0;
        layout.marginBottom = layout.marginTop = layout.marginLeft = layout.marginRight = 0;
        cMinSize.setLayout(layout);
        Label lblMinSize = new Label(cMinSize, SWT.NONE);
        lblMinSize.setText(MessageText.getString("SubscriptionResults.filter.min_size"));
        Spinner spinMinSize = new Spinner(cMinSize, SWT.BORDER);
        spinMinSize.setMinimum(0);
        // 100 TB should do...
        spinMinSize.setMaximum(100 * 1024 * 1024);
        spinMinSize.setSelection(minSize);
        spinMinSize.addListener(SWT.Selection, new Listener() {

            @Override
            public void handleEvent(Event event) {
                minSize = ((Spinner) event.widget).getSelection();
                refilter_dispatcher.dispatch();
            }
        });
        // max size
        label = new Label(vFilters, SWT.VERTICAL | SWT.SEPARATOR);
        label.setLayoutData(new RowData(-1, sepHeight));
        Composite cMaxSize = new Composite(vFilters, SWT.NONE);
        layout = new GridLayout(2, false);
        layout.marginWidth = 0;
        layout.marginBottom = layout.marginTop = layout.marginLeft = layout.marginRight = 0;
        cMaxSize.setLayout(layout);
        Label lblMaxSize = new Label(cMaxSize, SWT.NONE);
        lblMaxSize.setText(MessageText.getString("SubscriptionResults.filter.max_size"));
        Spinner spinMaxSize = new Spinner(cMaxSize, SWT.BORDER);
        spinMaxSize.setMinimum(0);
        // 100 TB should do...
        spinMaxSize.setMaximum(100 * 1024 * 1024);
        spinMaxSize.setSelection(maxSize);
        spinMaxSize.addListener(SWT.Selection, new Listener() {

            @Override
            public void handleEvent(Event event) {
                maxSize = ((Spinner) event.widget).getSelection();
                refilter_dispatcher.dispatch();
            }
        });
        if (filters != null) {
            label = new Label(vFilters, SWT.VERTICAL | SWT.SEPARATOR);
            label.setLayoutData(new RowData(-1, sepHeight));
            final SubscriptionResultFilter f_filters = filters;
            final Runnable f_pFilterUpdater = pFilterUpdater;
            Button save = new Button(vFilters, SWT.PUSH);
            save.setText(MessageText.getString("ConfigView.button.save"));
            save.addListener(SWT.Selection, new Listener() {

                @Override
                public void handleEvent(Event event) {
                    try {
                        long kInB = DisplayFormatters.getKinB();
                        long mInB = kInB * kInB;
                        f_filters.update(with_keywords, without_keywords, minSize * mInB, maxSize * mInB);
                        f_pFilterUpdater.run();
                    } catch (Throwable e) {
                        Debug.out(e);
                    }
                }
            });
        }
        parent.layout(true);
    }
    return null;
}
Also used : TableViewSWTMenuFillListener(com.biglybt.ui.swt.views.table.TableViewSWTMenuFillListener) TableColumnCreationListener(com.biglybt.pif.ui.tables.TableColumnCreationListener) UIPluginViewToolBarListener(com.biglybt.pif.ui.UIPluginViewToolBarListener) SubscriptionListener(com.biglybt.core.subs.SubscriptionListener) CoreRunningListener(com.biglybt.core.CoreRunningListener) CoreRunningListener(com.biglybt.core.CoreRunningListener) MultipleDocumentInterfaceSWT(com.biglybt.ui.swt.mdi.MultipleDocumentInterfaceSWT) Core(com.biglybt.core.Core) MessageText(com.biglybt.core.internat.MessageText) SubscriptionResultFilter(com.biglybt.core.subs.SubscriptionResultFilter) ImageLoader(com.biglybt.ui.swt.imageloader.ImageLoader)

Aggregations

Core (com.biglybt.core.Core)1 CoreRunningListener (com.biglybt.core.CoreRunningListener)1 MessageText (com.biglybt.core.internat.MessageText)1 SubscriptionListener (com.biglybt.core.subs.SubscriptionListener)1 SubscriptionResultFilter (com.biglybt.core.subs.SubscriptionResultFilter)1 UIPluginViewToolBarListener (com.biglybt.pif.ui.UIPluginViewToolBarListener)1 TableColumnCreationListener (com.biglybt.pif.ui.tables.TableColumnCreationListener)1 ImageLoader (com.biglybt.ui.swt.imageloader.ImageLoader)1 MultipleDocumentInterfaceSWT (com.biglybt.ui.swt.mdi.MultipleDocumentInterfaceSWT)1 TableViewSWTMenuFillListener (com.biglybt.ui.swt.views.table.TableViewSWTMenuFillListener)1