Search in sources :

Example 1 with Parameter

use of com.biglybt.ui.swt.config.Parameter in project BiglyBT by BiglySoftware.

the class BasicPluginConfigImpl method configSectionCreate.

@Override
public Composite configSectionCreate(final Composite parent) {
    int userMode = COConfigurationManager.getIntParameter("User Mode");
    // main tab set up
    Composite main_tab = new Composite(parent, SWT.NULL);
    GridData main_gridData = new GridData(GridData.VERTICAL_ALIGN_FILL | GridData.HORIZONTAL_ALIGN_FILL);
    Utils.setLayoutData(main_tab, main_gridData);
    GridLayout layout = new GridLayout();
    layout.numColumns = 2;
    layout.marginHeight = 0;
    main_tab.setLayout(layout);
    final Map comp_map = new HashMap();
    Composite current_composite = main_tab;
    Map<ParameterGroupImpl, Composite> group_map = new HashMap<>();
    Map<ParameterTabFolderImpl, CTabFolder> tab_folder_map = new HashMap<>();
    Map<ParameterGroupImpl, Composite> tab_map = new HashMap<>();
    BasicPluginConfigModel model = model_ref.get();
    if (model == null) {
        return (main_tab);
    }
    com.biglybt.pif.ui.config.Parameter[] parameters = model.getParameters();
    List<Button> buttons = new ArrayList<>();
    for (int i = 0; i < parameters.length; i++) {
        final ParameterImpl param = (ParameterImpl) parameters[i];
        if (param.getMinimumRequiredUserMode() > userMode) {
            continue;
        }
        ParameterGroupImpl pg = param.getGroup();
        if (pg == null) {
            current_composite = main_tab;
        } else {
            ParameterTabFolderImpl tab_folder = pg.getTabFolder();
            if (tab_folder != null) {
                ParameterGroupImpl tab_group = tab_folder.getGroup();
                CTabFolder tf = tab_folder_map.get(tab_folder);
                if (tf == null) {
                    Composite tab_parent = current_composite;
                    if (tab_group != null) {
                        String tg_resource = tab_group.getResourceName();
                        if (tg_resource != null) {
                            tab_parent = group_map.get(tab_group);
                            if (tab_parent == null) {
                                tab_parent = new Group(current_composite, SWT.NULL);
                                Messages.setLanguageText(tab_parent, tg_resource);
                                GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
                                gridData.horizontalSpan = 2;
                                if (tab_group.getMinimumRequiredUserMode() > userMode) {
                                    tab_parent.setVisible(false);
                                    gridData.widthHint = 0;
                                    gridData.heightHint = 0;
                                }
                                Utils.setLayoutData(tab_parent, gridData);
                                layout = new GridLayout();
                                layout.numColumns = tab_group.getNumberColumns() * 2;
                                tab_parent.setLayout(layout);
                                group_map.put(tab_group, tab_parent);
                            }
                        }
                    }
                    tf = new CTabFolder(tab_parent, SWT.LEFT);
                    tf.setBorderVisible(tab_group == null);
                    tf.setTabHeight(20);
                    GridData grid_data = new GridData(GridData.FILL_HORIZONTAL);
                    grid_data.horizontalSpan = 2;
                    if (tab_folder.getMinimumRequiredUserMode() > userMode) {
                        tf.setVisible(false);
                        grid_data.widthHint = 0;
                        grid_data.heightHint = 0;
                    }
                    Utils.setLayoutData(tf, grid_data);
                    tab_folder_map.put(tab_folder, tf);
                }
                Composite tab_composite = tab_map.get(pg);
                if (tab_composite == null) {
                    CTabItem tab_item = new CTabItem(tf, SWT.NULL);
                    String tab_name = pg.getResourceName();
                    if (tab_name != null) {
                        Messages.setLanguageText(tab_item, tab_name);
                    }
                    tab_composite = new Composite(tf, SWT.NONE);
                    tab_item.setControl(tab_composite);
                    layout = new GridLayout();
                    layout.numColumns = 2;
                    tab_composite.setLayout(layout);
                    GridData grid_data = new GridData(GridData.FILL_BOTH);
                    if (pg.getMinimumRequiredUserMode() > userMode) {
                        tab_composite.setVisible(false);
                        grid_data.widthHint = 0;
                        grid_data.heightHint = 0;
                    }
                    Utils.setLayoutData(tab_composite, grid_data);
                    if (tf.getItemCount() == 1) {
                        tf.setSelection(tab_item);
                    }
                    tab_map.put(pg, tab_composite);
                }
                current_composite = tab_composite;
            }
            Composite comp = group_map.get(pg);
            if (comp == null) {
                boolean nested = pg.getGroup() != null || tab_folder != null;
                Composite group_parent = nested ? current_composite : main_tab;
                String resource_name = pg.getResourceName();
                boolean use_composite = resource_name == null || tab_folder != null;
                current_composite = use_composite ? new Composite(group_parent, SWT.NONE) : new Group(group_parent, SWT.NULL);
                if (!use_composite) {
                    Messages.setLanguageText(current_composite, resource_name);
                }
                GridData grid_data = new GridData(GridData.VERTICAL_ALIGN_FILL | GridData.HORIZONTAL_ALIGN_FILL);
                grid_data.grabExcessHorizontalSpace = true;
                grid_data.horizontalSpan = 2;
                if (pg.getMinimumRequiredUserMode() > userMode) {
                    current_composite.setVisible(false);
                    grid_data.widthHint = 0;
                    grid_data.heightHint = 0;
                }
                Utils.setLayoutData(current_composite, grid_data);
                layout = new GridLayout();
                layout.numColumns = pg.getNumberColumns() * 2;
                current_composite.setLayout(layout);
                group_map.put(pg, current_composite);
            } else {
                current_composite = comp;
            }
        }
        Label label = null;
        String label_key = param.getLabelKey();
        String label_text = label_key == null ? param.getLabelText() : MessageText.getString(label_key);
        if (label_text.indexOf('\n') != -1 || label_text.indexOf('\t') != -1 || !(param instanceof BooleanParameterImpl)) {
            String hyperlink = null;
            if (param instanceof HyperlinkParameterImpl) {
                hyperlink = ((HyperlinkParameterImpl) param).getHyperlink();
            }
            label = new Label(current_composite, (param instanceof LabelParameterImpl) ? SWT.WRAP : SWT.NULL);
            boolean add_copy;
            if (label_key == null) {
                label.setText(param.getLabelText());
                add_copy = true;
            } else {
                Messages.setLanguageText(label, label_key);
                add_copy = label_key.startsWith("!");
            }
            if (add_copy) {
                final Label f_label = label;
                ClipboardCopy.addCopyToClipMenu(label, new ClipboardCopy.copyToClipProvider() {

                    @Override
                    public String getText() {
                        return (f_label.getText().trim());
                    }
                });
            }
            if (hyperlink != null) {
                LinkLabel.makeLinkedLabel(label, hyperlink);
            }
            if (param instanceof HyperlinkParameterImpl) {
                final Label f_label = label;
                param.addListener(new ParameterListener() {

                    @Override
                    public void parameterChanged(com.biglybt.pif.ui.config.Parameter p) {
                        if (f_label.isDisposed()) {
                            param.removeListener(this);
                        } else {
                            final String hyperlink = ((HyperlinkParameterImpl) param).getHyperlink();
                            if (hyperlink != null) {
                                Utils.execSWTThread(new Runnable() {

                                    @Override
                                    public void run() {
                                        LinkLabel.updateLinkedLabel(f_label, hyperlink);
                                    }
                                });
                            }
                        }
                    }
                });
            }
        }
        String key = param.getKey();
        // System.out.println( "key = " + key );
        final Parameter swt_param;
        if (param instanceof BooleanParameterImpl) {
            if (label == null) {
                swt_param = new BooleanParameter(current_composite, key, ((BooleanParameterImpl) param).getDefaultValue(), param.getLabelKey());
            } else {
                swt_param = new BooleanParameter(current_composite, key, ((BooleanParameterImpl) param).getDefaultValue());
            }
            GridData data = new GridData();
            data.horizontalSpan = label == null ? 2 : 1;
            swt_param.setLayoutData(data);
            param.addListener(new ParameterListener() {

                @Override
                public void parameterChanged(com.biglybt.pif.ui.config.Parameter p) {
                    if (swt_param.getControls()[0].isDisposed()) {
                        param.removeListener(this);
                    } else {
                        ((BooleanParameter) swt_param).setSelected(((BooleanParameterImpl) param).getValue());
                    }
                }
            });
        } else if (param instanceof IntParameterImpl) {
            IntParameterImpl int_param = (IntParameterImpl) param;
            swt_param = new IntParameter(current_composite, key, int_param.getDefaultValue());
            if (int_param.isLimited()) {
                ((IntParameter) swt_param).setMinimumValue(int_param.getMinValue());
                ((IntParameter) swt_param).setMaximumValue(int_param.getMaxValue());
            }
            param.addListener(new ParameterListener() {

                @Override
                public void parameterChanged(com.biglybt.pif.ui.config.Parameter p) {
                    if (swt_param.getControls()[0].isDisposed()) {
                        param.removeListener(this);
                    } else {
                        ((IntParameter) swt_param).setValue(((IntParameterImpl) param).getValue());
                    }
                }
            });
            GridData gridData = new GridData();
            if (!Constants.isUnix) {
                gridData.widthHint = 100;
            }
            swt_param.setLayoutData(gridData);
        } else if (param instanceof ColorParameterImpl) {
            final Composite area = new Composite(current_composite, SWT.NULL);
            // GridData gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.FILL_HORIZONTAL );
            GridData gridData = new GridData();
            Utils.setLayoutData(area, gridData);
            layout = new GridLayout();
            layout.numColumns = 2;
            layout.marginHeight = 0;
            layout.marginWidth = 0;
            area.setLayout(layout);
            final ButtonParameter[] reset_button_holder = new ButtonParameter[1];
            final ColorParameterImpl color_param = (ColorParameterImpl) param;
            swt_param = new com.biglybt.ui.swt.config.ColorParameter(area, key, color_param.getRedValue(), color_param.getGreenValue(), color_param.getBlueValue()) {

                @Override
                public void newColorSet(RGB newColor) {
                    color_param.reloadParamDataFromConfig(true);
                    if (reset_button_holder[0] == null) {
                        return;
                    }
                    reset_button_holder[0].getControl().setEnabled(true);
                }
            };
            // Reuse the same label as defined for UI reset buttons.
            reset_button_holder[0] = new ButtonParameter(area, "ConfigView.section.style.colorOverrides.reset");
            reset_button_holder[0].getControl().setEnabled(color_param.isOverridden());
            reset_button_holder[0].getControl().addListener(SWT.Selection, new Listener() {

                @Override
                public void handleEvent(Event event) {
                    reset_button_holder[0].getControl().setEnabled(false);
                    color_param.resetToDefault();
                    color_param.reloadParamDataFromConfig(false);
                }
            });
            gridData = new GridData();
            gridData.widthHint = 50;
            swt_param.setLayoutData(gridData);
        } else if (param instanceof StringParameterImpl) {
            GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
            gridData.widthHint = 150;
            StringParameterImpl s_param = (StringParameterImpl) param;
            int num_lines = s_param.getMultiLine();
            if (num_lines <= 1) {
                swt_param = new StringParameter(current_composite, key, s_param.getDefaultValue(), s_param.getGenerateIntermediateEvents());
                swt_param.setLayoutData(gridData);
            } else {
                StringAreaParameter sa_param = new StringAreaParameter(current_composite, key, s_param.getDefaultValue());
                swt_param = sa_param;
                gridData.heightHint = sa_param.getPreferredHeight(num_lines);
                swt_param.setLayoutData(gridData);
            }
        } else if (param instanceof InfoParameterImpl) {
            GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
            gridData.widthHint = 150;
            swt_param = new InfoParameter(current_composite, key, "");
            swt_param.setLayoutData(gridData);
        } else if (param instanceof StringListParameterImpl) {
            StringListParameterImpl sl_param = (StringListParameterImpl) param;
            GridData gridData = new GridData();
            gridData.widthHint = 150;
            swt_param = new StringListParameter(current_composite, key, sl_param.getDefaultValue(), sl_param.getLabels(), sl_param.getValues());
            swt_param.setLayoutData(gridData);
        } else if (param instanceof PasswordParameterImpl) {
            GridData gridData = new GridData();
            gridData.widthHint = 150;
            swt_param = new PasswordParameter(current_composite, key, ((PasswordParameterImpl) param).getEncodingType());
            swt_param.setLayoutData(gridData);
        } else if (param instanceof DirectoryParameterImpl || param instanceof com.biglybt.pifimpl.local.ui.config.FileParameter) {
            Composite area = new Composite(current_composite, SWT.NULL);
            GridData gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.FILL_HORIZONTAL);
            Utils.setLayoutData(area, gridData);
            layout = new GridLayout();
            layout.numColumns = 2;
            layout.marginHeight = 0;
            layout.marginWidth = 0;
            area.setLayout(layout);
            if (param instanceof DirectoryParameterImpl) {
                swt_param = new DirectoryParameter(area, key, ((DirectoryParameterImpl) param).getDefaultValue());
            } else {
                com.biglybt.pifimpl.local.ui.config.FileParameter fp = (com.biglybt.pifimpl.local.ui.config.FileParameter) param;
                swt_param = new com.biglybt.ui.swt.config.FileParameter(area, key, fp.getDefaultValue(), fp.getFileExtensions());
            }
        } else if (param instanceof ActionParameterImpl) {
            ActionParameterImpl _param = (ActionParameterImpl) param;
            if (_param.getStyle() == ActionParameter.STYLE_BUTTON) {
                ButtonParameter bp = new ButtonParameter(current_composite, _param.getActionResource());
                swt_param = bp;
                buttons.add(bp.getButton());
            } else {
                swt_param = new LinkParameter(current_composite, _param.getActionResource());
            }
            swt_param.addChangeListener(new ParameterChangeAdapter() {

                @Override
                public void parameterChanged(Parameter p, boolean caused_internally) {
                    try {
                        param.parameterChanged("");
                    } catch (Throwable t) {
                        Debug.out(t);
                    }
                }
            });
        } else if (param instanceof UIParameterImpl) {
            if (((UIParameterImpl) param).getContext() instanceof UISWTParameterContext) {
                UISWTParameterContext context = (UISWTParameterContext) ((UIParameterImpl) param).getContext();
                Composite internal_composite = new Composite(current_composite, SWT.NULL);
                GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
                Utils.setLayoutData(internal_composite, gridData);
                boolean initialised_component = true;
                try {
                    context.create(internal_composite);
                } catch (Exception e) {
                    Debug.printStackTrace(e);
                    initialised_component = false;
                }
                if (initialised_component) {
                    swt_param = new UISWTParameter(internal_composite, param.getKey());
                } else {
                    swt_param = null;
                    // so we don't care that this text is not localised.
                    if (label != null) {
                        label.setText("Error while generating UI component.");
                    }
                }
            } else {
                swt_param = null;
            }
        } else if (param instanceof UITextAreaImpl) {
            swt_param = new TextAreaParameter(current_composite, ((UITextAreaImpl) param));
            GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
            gridData.horizontalSpan = 2;
            gridData.heightHint = 100;
            swt_param.setLayoutData(gridData);
        } else {
            // label
            GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
            gridData.horizontalSpan = 2;
            // for wrap to work
            gridData.widthHint = 300;
            Utils.setLayoutData(label, gridData);
            swt_param = null;
        }
        if (swt_param == null) {
            if (label == null) {
                comp_map.put(param, new Object[] { null });
            } else {
                comp_map.put(param, new Object[] { null, label });
            }
        } else {
            Control[] c = swt_param.getControls();
            Object[] moo = new Object[c.length + (label == null ? 1 : 2)];
            int pos = 1;
            moo[0] = swt_param;
            if (label != null) {
                moo[pos++] = label;
            }
            System.arraycopy(c, 0, moo, 0 + pos, c.length);
            comp_map.put(param, moo);
        }
    }
    if (buttons.size() > 1) {
        Utils.makeButtonsEqualWidth(buttons);
    }
    // Only need one instance
    ParameterImplListener parameterImplListener = new ParameterImplListener() {

        @Override
        public void enabledChanged(final ParameterImpl p) {
            final Object[] stuff = (Object[]) comp_map.get(p);
            if (stuff != null) {
                if (stuff[1] != null && ((Control) stuff[1]).isDisposed()) {
                    // lazy tidyup
                    p.removeImplListener(this);
                } else {
                    Utils.execSWTThread(new AERunnable() {

                        @Override
                        public void runSupport() {
                            {
                                for (int k = 1; k < stuff.length; k++) {
                                    if (stuff[k] instanceof Control)
                                        ((Control) stuff[k]).setEnabled(p.isEnabled());
                                }
                            }
                        }
                    });
                }
            }
        }

        @Override
        public void labelChanged(final ParameterImpl p, final String text, final boolean bIsKey) {
            final Object[] stuff = (Object[]) comp_map.get(p);
            if (stuff == null)
                return;
            Label lbl;
            if (stuff[1] instanceof Label)
                lbl = (Label) stuff[1];
            else if (stuff[0] instanceof Label)
                lbl = (Label) stuff[0];
            else
                return;
            if (lbl.isDisposed()) {
                // lazy tidyup
                p.removeImplListener(this);
            } else {
                final Label finalLabel = lbl;
                Utils.execSWTThread(new AERunnable() {

                    @Override
                    public void runSupport() {
                        if (bIsKey)
                            Messages.setLanguageText(finalLabel, text);
                        else {
                            finalLabel.setData("");
                            finalLabel.setText(text);
                        }
                        finalLabel.getParent().layout(true);
                    }
                });
            }
        }
    };
    for (int i = 0; i < parameters.length; i++) {
        final ParameterImpl param = (ParameterImpl) parameters[i];
        param.addImplListener(parameterImplListener);
        if (!param.isEnabled()) {
            Object[] stuff = (Object[]) comp_map.get(param);
            if (stuff != null) {
                for (int k = 1; k < stuff.length; k++) {
                    ((Control) stuff[k]).setEnabled(false);
                }
            }
        }
        if (!param.isVisible()) {
            Object[] stuff = (Object[]) comp_map.get(param);
            if (stuff != null) {
                for (int k = 1; k < stuff.length; k++) {
                    Control con = (Control) stuff[k];
                    con.setVisible(false);
                    con.setSize(0, 0);
                    GridData gridData = new GridData();
                    gridData.heightHint = 0;
                    gridData.verticalSpan = 0;
                    gridData.grabExcessVerticalSpace = false;
                    con.setLayoutData(gridData);
                }
            }
        }
        if (param instanceof EnablerParameter) {
            List controlsToEnable = new ArrayList();
            Iterator iter = param.getEnabledOnSelectionParameters().iterator();
            while (iter.hasNext()) {
                ParameterImpl enable_param = (ParameterImpl) iter.next();
                Object[] stuff = (Object[]) comp_map.get(enable_param);
                if (stuff != null) {
                    controlsToEnable.addAll(Arrays.asList(stuff).subList(1, stuff.length));
                }
            }
            List controlsToDisable = new ArrayList();
            iter = param.getDisabledOnSelectionParameters().iterator();
            while (iter.hasNext()) {
                ParameterImpl disable_param = (ParameterImpl) iter.next();
                Object[] stuff = (Object[]) comp_map.get(disable_param);
                if (stuff != null) {
                    controlsToDisable.addAll(Arrays.asList(stuff).subList(1, stuff.length));
                }
            }
            Control[] ce = new Control[controlsToEnable.size()];
            Control[] cd = new Control[controlsToDisable.size()];
            if (ce.length + cd.length > 0) {
                IAdditionalActionPerformer ap = new DualChangeSelectionActionPerformer((Control[]) controlsToEnable.toArray(ce), (Control[]) controlsToDisable.toArray(cd));
                Object[] data = (Object[]) comp_map.get(param);
                if (data != null) {
                    BooleanParameter target = (BooleanParameter) data[0];
                    target.setAdditionalActionPerformer(ap);
                }
            }
        }
    }
    return (main_tab);
}
Also used : AERunnable(com.biglybt.core.util.AERunnable) CTabFolder(org.eclipse.swt.custom.CTabFolder) LinkLabel(com.biglybt.ui.swt.components.LinkLabel) CTabItem(org.eclipse.swt.custom.CTabItem) List(java.util.List) RGB(org.eclipse.swt.graphics.RGB) UISWTParameterContext(com.biglybt.ui.swt.pif.UISWTParameterContext) IntParameter(com.biglybt.ui.swt.config.IntParameter) DirectoryParameter(com.biglybt.ui.swt.config.DirectoryParameter) GridLayout(org.eclipse.swt.layout.GridLayout) PasswordParameter(com.biglybt.ui.swt.config.PasswordParameter) InfoParameter(com.biglybt.ui.swt.config.InfoParameter) StringParameter(com.biglybt.ui.swt.config.StringParameter) ClipboardCopy(com.biglybt.ui.swt.mainwindow.ClipboardCopy) BooleanParameter(com.biglybt.ui.swt.config.BooleanParameter) StringListParameter(com.biglybt.ui.swt.config.StringListParameter) AERunnable(com.biglybt.core.util.AERunnable) GridData(org.eclipse.swt.layout.GridData) BooleanParameter(com.biglybt.ui.swt.config.BooleanParameter) PasswordParameter(com.biglybt.ui.swt.config.PasswordParameter) StringParameter(com.biglybt.ui.swt.config.StringParameter) InfoParameter(com.biglybt.ui.swt.config.InfoParameter) StringListParameter(com.biglybt.ui.swt.config.StringListParameter) DirectoryParameter(com.biglybt.ui.swt.config.DirectoryParameter) IntParameter(com.biglybt.ui.swt.config.IntParameter) Parameter(com.biglybt.ui.swt.config.Parameter) com.biglybt.ui.swt.config(com.biglybt.ui.swt.config) com.biglybt.pifimpl.local.ui.config(com.biglybt.pifimpl.local.ui.config) com.biglybt.pif.ui.config(com.biglybt.pif.ui.config) BasicPluginConfigModel(com.biglybt.pif.ui.model.BasicPluginConfigModel)

Example 2 with Parameter

use of com.biglybt.ui.swt.config.Parameter in project BiglyBT by BiglySoftware.

the class ViewQuickConfig method initialize.

private void initialize(Composite ooparent) {
    GridLayout layout = new GridLayout(1, false);
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    ooparent.setLayout(layout);
    // if you put the border on the scrolled composite parent then on every resize the computedSize
    // grows by 4 pixels :( So stick in extra composite for the border
    final Composite oparent = new Composite(ooparent, SWT.BORDER);
    GridData gridData = new GridData(GridData.FILL_BOTH);
    Utils.setLayoutData(oparent, gridData);
    layout = new GridLayout(1, false);
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    oparent.setLayout(layout);
    final Composite parent = new Composite(oparent, SWT.NULL);
    gridData = new GridData(GridData.FILL_BOTH);
    Utils.setLayoutData(parent, gridData);
    layout = new GridLayout(1, false);
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    parent.setLayout(layout);
    final ScrolledComposite sc = new ScrolledComposite(parent, SWT.V_SCROLL);
    sc.setExpandHorizontal(true);
    sc.setExpandVertical(true);
    sc.addListener(SWT.Resize, new Listener() {

        @Override
        public void handleEvent(Event event) {
            int width = sc.getClientArea().width;
            Point size = parent.computeSize(width, SWT.DEFAULT);
            sc.setMinSize(size);
        }
    });
    gridData = new GridData(GridData.FILL_BOTH);
    Utils.setLayoutData(sc, gridData);
    composite = new Composite(sc, SWT.NULL);
    sc.setContent(composite);
    gridData = new GridData(GridData.FILL_BOTH);
    Utils.setLayoutData(composite, gridData);
    layout = new GridLayout(4, false);
    composite.setLayout(layout);
    // done downloading - 2
    ConfigSectionStartShutdown.addDoneDownloadingOption(composite, false);
    // max simul down - 2
    Label label = new Label(composite, SWT.NULL);
    gridData = new GridData();
    gridData.horizontalIndent = 8;
    Utils.setLayoutData(label, gridData);
    Messages.setLanguageText(label, "ConfigView.label.maxdownloads.short");
    IntParameter maxDLs = new IntParameter(composite, "max downloads");
    maxDLs.addChangeListener(new ParameterChangeAdapter() {

        @Override
        public void parameterChanged(Parameter p, boolean caused_internally) {
            COConfigurationManager.setDirty();
        }
    });
    addTemporaryRates(composite);
    addTemporaryData(composite);
    Utils.execSWTThreadLater(100, new Runnable() {

        @Override
        public void run() {
            composite.traverse(SWT.TRAVERSE_TAB_NEXT);
        }
    });
}
Also used : UISWTViewCoreEventListener(com.biglybt.ui.swt.pifimpl.UISWTViewCoreEventListener) CoreRunningListener(com.biglybt.core.CoreRunningListener) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) BufferedLabel(com.biglybt.ui.swt.components.BufferedLabel) ParameterChangeAdapter(com.biglybt.ui.swt.config.ParameterChangeAdapter) Point(org.eclipse.swt.graphics.Point) GridLayout(org.eclipse.swt.layout.GridLayout) GridData(org.eclipse.swt.layout.GridData) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) UISWTViewEvent(com.biglybt.ui.swt.pif.UISWTViewEvent) TimerEvent(com.biglybt.core.util.TimerEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) IntParameter(com.biglybt.ui.swt.config.IntParameter) Parameter(com.biglybt.ui.swt.config.Parameter) IntParameter(com.biglybt.ui.swt.config.IntParameter)

Example 3 with Parameter

use of com.biglybt.ui.swt.config.Parameter in project BiglyBT by BiglySoftware.

the class ViewQuickConfig method addTemporaryRates.

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

        private CoreLifecycleAdapter listener;

        private TimerEventPeriodic event;

        private boolean auto_up_enabled;

        private boolean auto_up_seeding_enabled;

        private boolean seeding_limits_enabled;

        private int up_limit;

        private int down_limit;

        private long end_time;

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

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

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

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

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

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

Example 4 with Parameter

use of com.biglybt.ui.swt.config.Parameter in project BiglyBT by BiglySoftware.

the class ViewQuickConfig method addTemporaryData.

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

        private CoreLifecycleAdapter listener;

        private TimerEventPeriodic event;

        private long end_upload;

        private long end_download;

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

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

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

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

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

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

Example 5 with Parameter

use of com.biglybt.ui.swt.config.Parameter in project BiglyBT by BiglySoftware.

the class BuddyPluginViewInstance method createBeta.

private void createBeta(Composite main) {
    Utils.disposeComposite(main, false);
    final BuddyPluginBeta plugin_beta = plugin.getBeta();
    GridLayout layout = new GridLayout();
    layout.numColumns = 3;
    main.setLayout(layout);
    GridData grid_data = new GridData(GridData.FILL_BOTH);
    Utils.setLayoutData(main, grid_data);
    beta_enabled = plugin.isBetaEnabled();
    if (!beta_enabled) {
        Label control_label = new Label(main, SWT.NULL);
        control_label.setText(lu.getLocalisedMessageText("azbuddy.disabled"));
        Label label = new Label(main, SWT.NULL);
        grid_data = new GridData(GridData.FILL_HORIZONTAL);
        label.setLayoutData(grid_data);
        final Button config_button = new Button(main, SWT.NULL);
        config_button.setText(lu.getLocalisedMessageText("plugins.basicview.config"));
        config_button.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                plugin.showConfig();
            }
        });
        return;
    }
    final BuddyPluginBeta beta = plugin.getBeta();
    boolean i2p_enabled = plugin_beta.isI2PAvailable();
    // info
    Composite info_area = new Composite(main, SWT.NULL);
    layout = new GridLayout();
    layout.numColumns = 4;
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    info_area.setLayout(layout);
    grid_data = new GridData(GridData.FILL_HORIZONTAL);
    grid_data.horizontalSpan = 3;
    Utils.setLayoutData(info_area, grid_data);
    Label label = new Label(info_area, SWT.NULL);
    label.setText(lu.getLocalisedMessageText("azbuddy.dchat.info"));
    new LinkLabel(info_area, "ConfigView.label.please.visit.here", lu.getLocalisedMessageText("azbuddy.dchat.link.url"));
    label = new Label(info_area, SWT.NULL);
    grid_data = new GridData(GridData.FILL_HORIZONTAL);
    label.setLayoutData(grid_data);
    final Button config_button = new Button(info_area, SWT.NULL);
    config_button.setText(lu.getLocalisedMessageText("plugins.basicview.config"));
    config_button.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            plugin.showConfig();
        }
    });
    // install plugin
    label = new Label(info_area, SWT.NULL);
    label.setText(MessageText.getString("azmsgsync.install.text"));
    plugin_install_button = new Button(info_area, SWT.NULL);
    plugin_install_button.setText(MessageText.getString("UpdateWindow.columns.install"));
    plugin_install_button.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            plugin_install_button.setEnabled(false);
            new AEThread2("installer") {

                @Override
                public void run() {
                    boolean ok = false;
                    String msg;
                    try {
                        installMsgSyncPlugin();
                        msg = MessageText.getString("azmsgsync.install.ok.msg");
                        ok = true;
                    } catch (Throwable e) {
                        msg = MessageText.getString("azmsgsync.install.fail.msg", new String[] { Debug.getNestedExceptionMessage(e) });
                    } finally {
                        if (!checkMsgSyncPlugin()) {
                            if (ok) {
                                // something weird happened
                                ok = false;
                                msg = MessageText.getString("azmsgsync.install.fail.msg", new String[] { "Unexpected error, check logs" });
                            }
                        }
                    }
                    plugin.getPluginInterface().getUIManager().showMessageBox(ok ? "aztorplugin.browser.install.ok" : "aztorplugin.browser.install.fail", "!" + msg + "!", UIManagerEvent.MT_OK);
                }
            }.start();
        }
    });
    label = new Label(info_area, SWT.NULL);
    grid_data = new GridData(GridData.FILL_HORIZONTAL);
    grid_data.horizontalSpan = 2;
    label.setLayoutData(grid_data);
    checkMsgSyncPlugin();
    // UI
    final Group ui_area = new Group(main, SWT.NULL);
    layout = new GridLayout();
    layout.numColumns = 3;
    ui_area.setLayout(layout);
    grid_data = new GridData(GridData.FILL_HORIZONTAL);
    grid_data.horizontalSpan = 3;
    Utils.setLayoutData(ui_area, grid_data);
    ui_area.setText(lu.getLocalisedMessageText("ConfigView.section.style"));
    // shared public nick
    label = new Label(ui_area, SWT.NULL);
    label.setText(lu.getLocalisedMessageText("azbuddy.dchat.public.nick"));
    public_nickname = new Text(ui_area, SWT.BORDER);
    grid_data = new GridData();
    grid_data.widthHint = 200;
    Utils.setLayoutData(public_nickname, grid_data);
    public_nickname.setText(plugin_beta.getSharedPublicNickname());
    public_nickname.addListener(SWT.FocusOut, new Listener() {

        @Override
        public void handleEvent(Event event) {
            plugin_beta.setSharedPublicNickname(public_nickname.getText().trim());
        }
    });
    label = new Label(ui_area, SWT.NULL);
    // shared anon nick
    label = new Label(ui_area, SWT.NULL);
    label.setText(lu.getLocalisedMessageText("azbuddy.dchat.anon.nick"));
    anon_nickname = new Text(ui_area, SWT.BORDER);
    grid_data = new GridData();
    grid_data.widthHint = 200;
    Utils.setLayoutData(anon_nickname, grid_data);
    anon_nickname.setText(plugin_beta.getSharedAnonNickname());
    anon_nickname.addListener(SWT.FocusOut, new Listener() {

        @Override
        public void handleEvent(Event event) {
            plugin_beta.setSharedAnonNickname(anon_nickname.getText().trim());
        }
    });
    label = new Label(ui_area, SWT.NULL);
    // max lines
    label = new Label(ui_area, SWT.NULL);
    label.setText(lu.getLocalisedMessageText("azbuddy.dchat.ui.max.lines"));
    final IntParameter max_lines = new IntParameter(ui_area, "azbuddy.chat.temp.ui.max.lines", 128, Integer.MAX_VALUE);
    max_lines.setValue(beta.getMaxUILines());
    max_lines.addChangeListener(new ParameterChangeAdapter() {

        @Override
        public void parameterChanged(Parameter p, boolean caused_internally) {
            beta.setMaxUILines(max_lines.getValue());
        }
    });
    label = new Label(ui_area, SWT.NULL);
    // max chars
    label = new Label(ui_area, SWT.NULL);
    label.setText(lu.getLocalisedMessageText("azbuddy.dchat.ui.max.kb"));
    final IntParameter max_chars = new IntParameter(ui_area, "azbuddy.chat.temp.ui.max.chars", 1, 512);
    max_chars.setValue(beta.getMaxUICharsKB());
    max_chars.addChangeListener(new ParameterChangeAdapter() {

        @Override
        public void parameterChanged(Parameter p, boolean caused_internally) {
            beta.setMaxUICharsKB(max_chars.getValue());
        }
    });
    label = new Label(ui_area, SWT.NULL);
    // hide ratings
    final Button hide_ratings = new Button(ui_area, SWT.CHECK);
    hide_ratings.setText(lu.getLocalisedMessageText("azbuddy.dchat.ui.hide.ratings"));
    hide_ratings.setSelection(plugin_beta.getHideRatings());
    hide_ratings.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent ev) {
            plugin_beta.setHideRatings(hide_ratings.getSelection());
        }
    });
    label = new Label(ui_area, SWT.NULL);
    grid_data = new GridData();
    grid_data.horizontalSpan = 2;
    Utils.setLayoutData(label, grid_data);
    // hide search/subcriptions
    final Button hide_search_subs = new Button(ui_area, SWT.CHECK);
    hide_search_subs.setText(lu.getLocalisedMessageText("azbuddy.dchat.ui.hide.search_subs"));
    hide_search_subs.setSelection(plugin_beta.getHideSearchSubs());
    hide_search_subs.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent ev) {
            plugin_beta.setHideSearchSubs(hide_search_subs.getSelection());
        }
    });
    label = new Label(ui_area, SWT.NULL);
    grid_data = new GridData();
    grid_data.horizontalSpan = 2;
    Utils.setLayoutData(label, grid_data);
    // standalone windows
    final Button stand_alone = new Button(ui_area, SWT.CHECK);
    stand_alone.setText(lu.getLocalisedMessageText("azbuddy.dchat.ui.standalone.windows"));
    stand_alone.setSelection(plugin_beta.getStandAloneWindows());
    stand_alone.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent ev) {
            plugin_beta.setStandAloneWindows(stand_alone.getSelection());
        }
    });
    label = new Label(ui_area, SWT.NULL);
    grid_data = new GridData();
    grid_data.horizontalSpan = 2;
    Utils.setLayoutData(label, grid_data);
    // popout windows -> sidebar
    final Button windows_to_sidebar = new Button(ui_area, SWT.CHECK);
    windows_to_sidebar.setText(lu.getLocalisedMessageText("azbuddy.dchat.ui.windows.to.sidebar"));
    windows_to_sidebar.setSelection(plugin_beta.getWindowsToSidebar());
    windows_to_sidebar.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent ev) {
            plugin_beta.setWindowsToSidebar(windows_to_sidebar.getSelection());
        }
    });
    // notifications
    final Group noti_area = new Group(main, SWT.NULL);
    layout = new GridLayout();
    layout.numColumns = 4;
    noti_area.setLayout(layout);
    grid_data = new GridData(GridData.FILL_HORIZONTAL);
    grid_data.horizontalSpan = 3;
    Utils.setLayoutData(noti_area, grid_data);
    noti_area.setText(lu.getLocalisedMessageText("v3.MainWindow.tab.events"));
    final Button sound_enable = new Button(noti_area, SWT.CHECK);
    sound_enable.setText(lu.getLocalisedMessageText("azbuddy.dchat.noti.sound"));
    boolean sound_enabled = plugin_beta.getSoundEnabled();
    sound_enable.setSelection(sound_enabled);
    sound_enable.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent ev) {
            plugin_beta.setSoundEnabled(sound_enable.getSelection());
        }
    });
    final Text noti_file = new Text(noti_area, SWT.BORDER);
    grid_data = new GridData();
    grid_data.widthHint = 400;
    Utils.setLayoutData(noti_file, grid_data);
    String sound_file = plugin_beta.getSoundFile();
    if (sound_file.length() == 0) {
        sound_file = "<default>";
    }
    noti_file.setText(sound_file);
    noti_file.addListener(SWT.FocusOut, new Listener() {

        @Override
        public void handleEvent(Event event) {
            String val = noti_file.getText().trim();
            if (val.length() == 0 || val.startsWith("<")) {
                noti_file.setText("<default>");
                val = "";
            }
            if (!val.equals(plugin_beta.getSoundFile())) {
                plugin_beta.setSoundFile(val);
            }
        }
    });
    final Button noti_browse = new Button(noti_area, SWT.PUSH);
    final ImageLoader imageLoader = ImageLoader.getInstance();
    final Image imgOpenFolder = imageLoader.getImage("openFolderButton");
    noti_area.addDisposeListener(new DisposeListener() {

        @Override
        public void widgetDisposed(DisposeEvent e) {
            imageLoader.releaseImage("openFolderButton");
        }
    });
    noti_browse.setImage(imgOpenFolder);
    imgOpenFolder.setBackground(noti_browse.getBackground());
    noti_browse.setToolTipText(MessageText.getString("ConfigView.button.browse"));
    noti_browse.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event event) {
            FileDialog dialog = new FileDialog(noti_area.getShell(), SWT.APPLICATION_MODAL);
            dialog.setFilterExtensions(new String[] { "*.wav" });
            dialog.setFilterNames(new String[] { "*.wav" });
            dialog.setText(MessageText.getString("ConfigView.section.interface.wavlocation"));
            String path = dialog.open();
            if (path != null) {
                path = path.trim();
                if (path.startsWith("<")) {
                    path = "";
                }
                plugin_beta.setSoundFile(path.trim());
            }
            view.playSound();
        }
    });
    label = new Label(noti_area, SWT.WRAP);
    label.setText(MessageText.getString("ConfigView.section.interface.wavlocation.info"));
    if (!sound_enabled) {
        noti_file.setEnabled(false);
        noti_browse.setEnabled(false);
    }
    final Button flash_enable = new Button(noti_area, SWT.CHECK);
    flash_enable.setText(lu.getLocalisedMessageText("azbuddy.dchat.noti.flash"));
    flash_enable.setSelection(plugin_beta.getFlashEnabled());
    flash_enable.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent ev) {
            plugin_beta.setFlashEnabled(flash_enable.getSelection());
        }
    });
    // private chats
    Group private_chat_area = new Group(main, SWT.NULL);
    layout = new GridLayout();
    layout.numColumns = 3;
    // layout.marginHeight = 0;
    // layout.marginWidth = 0;
    private_chat_area.setLayout(layout);
    grid_data = new GridData(GridData.FILL_HORIZONTAL);
    grid_data.horizontalSpan = 3;
    Utils.setLayoutData(private_chat_area, grid_data);
    private_chat_area.setText(lu.getLocalisedMessageText("label.private.chat"));
    label = new Label(private_chat_area, SWT.NULL);
    label.setText(lu.getLocalisedMessageText("azbuddy.dchat.pc.enable"));
    final Button private_chat_enable = new Button(private_chat_area, SWT.CHECK);
    label = new Label(private_chat_area, SWT.NULL);
    grid_data = new GridData(GridData.FILL_HORIZONTAL);
    Utils.setLayoutData(label, grid_data);
    private_chat_enable.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent ev) {
            plugin_beta.setPrivateChatState(private_chat_enable.getSelection() ? BuddyPluginBeta.PRIVATE_CHAT_ENABLED : BuddyPluginBeta.PRIVATE_CHAT_DISABLED);
        }
    });
    final Label pc_pinned_only = new Label(private_chat_area, SWT.NULL);
    pc_pinned_only.setText(lu.getLocalisedMessageText("azbuddy.dchat.pc.pinned.only"));
    final Button private_chat_pinned = new Button(private_chat_area, SWT.CHECK);
    label = new Label(private_chat_area, SWT.NULL);
    grid_data = new GridData(GridData.FILL_HORIZONTAL);
    Utils.setLayoutData(label, grid_data);
    private_chat_pinned.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent ev) {
            plugin_beta.setPrivateChatState(private_chat_pinned.getSelection() ? BuddyPluginBeta.PRIVATE_CHAT_PINNED_ONLY : BuddyPluginBeta.PRIVATE_CHAT_ENABLED);
        }
    });
    int pc_state = plugin_beta.getPrivateChatState();
    private_chat_enable.setSelection(pc_state != BuddyPluginBeta.PRIVATE_CHAT_DISABLED);
    private_chat_pinned.setSelection(pc_state == BuddyPluginBeta.PRIVATE_CHAT_PINNED_ONLY);
    private_chat_pinned.setEnabled(pc_state != BuddyPluginBeta.PRIVATE_CHAT_DISABLED);
    pc_pinned_only.setEnabled(pc_state != BuddyPluginBeta.PRIVATE_CHAT_DISABLED);
    // import
    Group import_area = new Group(main, SWT.NULL);
    layout = new GridLayout();
    layout.numColumns = 3;
    import_area.setLayout(layout);
    grid_data = new GridData(GridData.FILL_HORIZONTAL);
    grid_data.horizontalSpan = 3;
    Utils.setLayoutData(import_area, grid_data);
    import_area.setText(lu.getLocalisedMessageText("azbuddy.dchat.cannel.import"));
    label = new Label(import_area, SWT.NULL);
    label.setText(lu.getLocalisedMessageText("azbuddy.dchat.import.data"));
    final Text import_data = new Text(import_area, SWT.BORDER);
    grid_data = new GridData();
    grid_data.widthHint = 400;
    Utils.setLayoutData(import_data, grid_data);
    final Button import_button = new Button(import_area, SWT.NULL);
    import_button.setText(lu.getLocalisedMessageText("br.restore"));
    import_button.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent ev) {
            import_button.setEnabled(false);
            final Display display = composite.getDisplay();
            final String data = import_data.getText().trim();
            new AEThread2("async") {

                @Override
                public void run() {
                    if (display.isDisposed()) {
                        return;
                    }
                    try {
                        final BuddyPluginBeta.ChatInstance inst = plugin_beta.importChat(data);
                        display.asyncExec(new Runnable() {

                            @Override
                            public void run() {
                                if (!display.isDisposed()) {
                                    BuddyPluginViewBetaChat.createChatWindow(view, plugin, inst);
                                    import_button.setEnabled(true);
                                }
                            }
                        });
                    } catch (Throwable e) {
                        display.asyncExec(new Runnable() {

                            @Override
                            public void run() {
                                if (!import_button.isDisposed()) {
                                    import_button.setEnabled(true);
                                }
                            }
                        });
                        Debug.out(e);
                    }
                }
            }.start();
        }
    });
    // Advanced
    Group adv_area = new Group(main, SWT.NULL);
    adv_area.setText(lu.getLocalisedMessageText("MyTorrentsView.menu.advancedmenu"));
    layout = new GridLayout();
    layout.numColumns = 3;
    adv_area.setLayout(layout);
    grid_data = new GridData(GridData.FILL_HORIZONTAL);
    grid_data.horizontalSpan = 3;
    Utils.setLayoutData(adv_area, grid_data);
    // shared endpoint
    label = new Label(adv_area, SWT.NULL);
    label.setText(lu.getLocalisedMessageText("azbuddy.dchat.anon.share.endpoint"));
    final Button shared_endpoint = new Button(adv_area, SWT.CHECK);
    shared_endpoint.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent ev) {
            plugin_beta.setSharedAnonEndpoint(shared_endpoint.getSelection());
        }
    });
    shared_endpoint.setSelection(plugin_beta.getSharedAnonEndpoint());
    label = new Label(adv_area, SWT.NULL);
    label.setText(lu.getLocalisedMessageText("azbuddy.dchat.anon.share.endpoint.info"));
    grid_data = new GridData(GridData.FILL_HORIZONTAL);
    Utils.setLayoutData(label, grid_data);
    // testing
    Group test_area = new Group(main, SWT.NULL);
    test_area.setText(lu.getLocalisedMessageText("br.test"));
    layout = new GridLayout();
    layout.numColumns = 4;
    test_area.setLayout(layout);
    grid_data = new GridData(GridData.FILL_HORIZONTAL);
    grid_data.horizontalSpan = 3;
    Utils.setLayoutData(test_area, grid_data);
    // public beta channel
    label = new Label(test_area, SWT.NULL);
    label.setText(lu.getLocalisedMessageText("azbuddy.dchat.public.beta"));
    Button beta_button = new Button(test_area, SWT.NULL);
    setupButton(beta_button, lu.getLocalisedMessageText("Button.open"), AENetworkClassifier.AT_PUBLIC, new String[] { BuddyPluginBeta.BETA_CHAT_KEY, BuddyPluginBeta.LEGACY_BETA_CHAT_KEY });
    label = new Label(test_area, SWT.NULL);
    grid_data = new GridData(GridData.FILL_HORIZONTAL);
    grid_data.horizontalSpan = 2;
    Utils.setLayoutData(label, grid_data);
    // anonymous beta channel
    label = new Label(test_area, SWT.NULL);
    label.setText(lu.getLocalisedMessageText("azbuddy.dchat.anon.beta"));
    Button beta_i2p_button = new Button(test_area, SWT.NULL);
    setupButton(beta_i2p_button, lu.getLocalisedMessageText("Button.open"), AENetworkClassifier.AT_I2P, new String[] { BuddyPluginBeta.BETA_CHAT_KEY, BuddyPluginBeta.LEGACY_BETA_CHAT_KEY });
    beta_i2p_button.setEnabled(i2p_enabled);
    label = new Label(test_area, SWT.NULL);
    grid_data = new GridData(GridData.FILL_HORIZONTAL);
    grid_data.horizontalSpan = 2;
    Utils.setLayoutData(label, grid_data);
    // create custom channel
    label = new Label(test_area, SWT.NULL);
    label.setText(lu.getLocalisedMessageText("azbuddy.dchat.create.join.key"));
    final Text channel_key = new Text(test_area, SWT.BORDER);
    grid_data = new GridData();
    grid_data.widthHint = 200;
    Utils.setLayoutData(channel_key, grid_data);
    final Button create_i2p_button = new Button(test_area, SWT.CHECK);
    create_i2p_button.setText(lu.getLocalisedMessageText("label.anon.i2p"));
    create_i2p_button.setEnabled(i2p_enabled);
    final Button create_button = new Button(test_area, SWT.NULL);
    create_button.setText(lu.getLocalisedMessageText("Button.open"));
    create_button.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent ev) {
            create_button.setEnabled(false);
            final Display display = composite.getDisplay();
            final String network = create_i2p_button.getSelection() ? AENetworkClassifier.AT_I2P : AENetworkClassifier.AT_PUBLIC;
            final String key = channel_key.getText().trim();
            new AEThread2("async") {

                @Override
                public void run() {
                    if (display.isDisposed()) {
                        return;
                    }
                    try {
                        final BuddyPluginBeta.ChatInstance inst = plugin_beta.getChat(network, key);
                        display.asyncExec(new Runnable() {

                            @Override
                            public void run() {
                                if (!display.isDisposed()) {
                                    BuddyPluginViewBetaChat.createChatWindow(view, plugin, inst);
                                    create_button.setEnabled(true);
                                }
                            }
                        });
                    } catch (Throwable e) {
                        display.asyncExec(new Runnable() {

                            @Override
                            public void run() {
                                if (!create_button.isDisposed()) {
                                    create_button.setEnabled(true);
                                }
                            }
                        });
                        Debug.out(e);
                    }
                }
            }.start();
        }
    });
    // end of UI
    List<Button> buttons = new ArrayList<>();
    buttons.add(create_button);
    buttons.add(beta_button);
    buttons.add(beta_i2p_button);
    buttons.add(import_button);
    Utils.makeButtonsEqualWidth(buttons);
    plugin.addListener(new BuddyPluginAdapter() {

        @Override
        public void updated() {
            if (public_nickname.isDisposed()) {
                plugin.removeListener(this);
            } else {
                public_nickname.getDisplay().asyncExec(new Runnable() {

                    @Override
                    public void run() {
                        if (public_nickname.isDisposed()) {
                            return;
                        }
                        String nick = plugin_beta.getSharedPublicNickname();
                        if (!public_nickname.getText().equals(nick)) {
                            public_nickname.setText(nick);
                        }
                        nick = plugin_beta.getSharedAnonNickname();
                        if (!anon_nickname.getText().equals(nick)) {
                            anon_nickname.setText(nick);
                        }
                        shared_endpoint.setSelection(plugin_beta.getSharedAnonEndpoint());
                        int pc_state = plugin_beta.getPrivateChatState();
                        private_chat_enable.setSelection(pc_state != BuddyPluginBeta.PRIVATE_CHAT_DISABLED);
                        private_chat_pinned.setSelection(pc_state == BuddyPluginBeta.PRIVATE_CHAT_PINNED_ONLY);
                        private_chat_pinned.setEnabled(pc_state != BuddyPluginBeta.PRIVATE_CHAT_DISABLED);
                        pc_pinned_only.setEnabled(pc_state != BuddyPluginBeta.PRIVATE_CHAT_DISABLED);
                        String str = plugin_beta.getSoundFile();
                        if (str.length() == 0) {
                            noti_file.setText("<default>");
                        } else {
                            noti_file.setText(str);
                        }
                        boolean se = plugin_beta.getSoundEnabled();
                        noti_file.setEnabled(se);
                        noti_browse.setEnabled(se);
                    }
                });
            }
        }
    });
}
Also used : UserPrompterResultListener(com.biglybt.ui.UserPrompterResultListener) UIInputReceiverListener(com.biglybt.pif.ui.UIInputReceiverListener) LinkLabel(com.biglybt.ui.swt.components.LinkLabel) Image(org.eclipse.swt.graphics.Image) ParameterChangeAdapter(com.biglybt.ui.swt.config.ParameterChangeAdapter) StyledText(org.eclipse.swt.custom.StyledText) MessageText(com.biglybt.core.internat.MessageText) Point(org.eclipse.swt.graphics.Point) LinkLabel(com.biglybt.ui.swt.components.LinkLabel) UIManagerEvent(com.biglybt.pif.ui.UIManagerEvent) IntParameter(com.biglybt.ui.swt.config.IntParameter) Parameter(com.biglybt.ui.swt.config.Parameter) ImageLoader(com.biglybt.ui.swt.imageloader.ImageLoader) IntParameter(com.biglybt.ui.swt.config.IntParameter)

Aggregations

IntParameter (com.biglybt.ui.swt.config.IntParameter)7 Parameter (com.biglybt.ui.swt.config.Parameter)7 ParameterChangeAdapter (com.biglybt.ui.swt.config.ParameterChangeAdapter)6 GridData (org.eclipse.swt.layout.GridData)6 GridLayout (org.eclipse.swt.layout.GridLayout)6 Point (org.eclipse.swt.graphics.Point)4 TimerEvent (com.biglybt.core.util.TimerEvent)3 BufferedLabel (com.biglybt.ui.swt.components.BufferedLabel)3 SelectionEvent (org.eclipse.swt.events.SelectionEvent)3 Core (com.biglybt.core.Core)2 CoreLifecycleAdapter (com.biglybt.core.CoreLifecycleAdapter)2 AERunnable (com.biglybt.core.util.AERunnable)2 TimerEventPerformer (com.biglybt.core.util.TimerEventPerformer)2 TimerEventPeriodic (com.biglybt.core.util.TimerEventPeriodic)2 UserPrompterResultListener (com.biglybt.ui.UserPrompterResultListener)2 LinkLabel (com.biglybt.ui.swt.components.LinkLabel)2 BooleanParameter (com.biglybt.ui.swt.config.BooleanParameter)2 ParameterChangeListener (com.biglybt.ui.swt.config.ParameterChangeListener)2 StringParameter (com.biglybt.ui.swt.config.StringParameter)2 ImageLoader (com.biglybt.ui.swt.imageloader.ImageLoader)2