Search in sources :

Example 1 with BooleanParameter

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

the class ConfigSectionSeedingFirstPriority method configSectionCreate.

@Override
public Composite configSectionCreate(Composite parent) {
    // Seeding Automation Setup
    GridData gridData;
    GridLayout layout;
    Label label;
    Composite cArea, cArea1;
    Composite cFirstPriorityArea = new Composite(parent, SWT.NULL);
    layout = new GridLayout();
    layout.numColumns = 2;
    layout.marginHeight = 0;
    cFirstPriorityArea.setLayout(layout);
    gridData = new GridData(GridData.VERTICAL_ALIGN_FILL | GridData.HORIZONTAL_ALIGN_FILL);
    Utils.setLayoutData(cFirstPriorityArea, gridData);
    label = new Label(cFirstPriorityArea, SWT.WRAP);
    gridData = new GridData(GridData.FILL_HORIZONTAL);
    gridData.horizontalSpan = 2;
    gridData.widthHint = 300;
    Utils.setLayoutData(label, gridData);
    Messages.setLanguageText(label, "ConfigView.label.seeding.firstPriority.info");
    // ** Begin No Touch area
    // Group FP
    Composite cFP = new Group(cFirstPriorityArea, SWT.NULL);
    layout = new GridLayout();
    layout.numColumns = 2;
    layout.verticalSpacing = 6;
    cFP.setLayout(layout);
    gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.HORIZONTAL_ALIGN_FILL);
    Utils.setLayoutData(cFP, gridData);
    Messages.setLanguageText(cFP, "ConfigView.label.seeding.firstPriority.FP");
    // row
    cArea = new Composite(cFP, SWT.NULL);
    layout = new GridLayout();
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    layout.numColumns = 3;
    cArea.setLayout(layout);
    gridData = new GridData(GridData.VERTICAL_ALIGN_FILL | GridData.HORIZONTAL_ALIGN_FILL);
    gridData.horizontalSpan = 3;
    Utils.setLayoutData(cArea, gridData);
    label = new Label(cArea, SWT.NULL);
    Messages.setLanguageText(label, "ConfigView.label.seeding.firstPriority");
    String[] fpLabels = { MessageText.getString("ConfigView.text.all"), MessageText.getString("ConfigView.text.any") };
    int[] fpValues = { DefaultRankCalculator.FIRSTPRIORITY_ALL, DefaultRankCalculator.FIRSTPRIORITY_ANY };
    new IntListParameter(cArea, "StartStopManager_iFirstPriority_Type", fpLabels, fpValues);
    label = new Label(cArea, SWT.NULL);
    Messages.setLanguageText(label, "ConfigView.label.seeding.firstPriority.following");
    // row
    label = new Label(cFP, SWT.NULL);
    Messages.setLanguageText(label, "ConfigView.label.seeding.firstPriority.shareRatio");
    String[] minQueueLabels = new String[55];
    int[] minQueueValues = new int[55];
    minQueueLabels[0] = "1:2 (" + 0.5 + ")";
    minQueueValues[0] = 500;
    minQueueLabels[1] = "3:4 (" + 0.75 + ")";
    minQueueValues[1] = 750;
    minQueueLabels[2] = "1:1";
    minQueueValues[2] = 1000;
    minQueueLabels[3] = "5:4 (" + 1.25 + ")";
    minQueueValues[3] = 1250;
    minQueueLabels[4] = "3:2 (" + 1.50 + ")";
    minQueueValues[4] = 1500;
    minQueueLabels[5] = "7:4 (" + 1.75 + ")";
    minQueueValues[5] = 1750;
    for (int i = 6; i < minQueueLabels.length; i++) {
        minQueueLabels[i] = i - 4 + ":1";
        minQueueValues[i] = (i - 4) * 1000;
    }
    new IntListParameter(cFP, "StartStopManager_iFirstPriority_ShareRatio", minQueueLabels, minQueueValues);
    String sMinutes = MessageText.getString("ConfigView.text.minutes");
    String sHours = MessageText.getString("ConfigView.text.hours");
    // row
    label = new Label(cFP, SWT.NULL);
    Messages.setLanguageText(label, "ConfigView.label.seeding.firstPriority.DLMinutes");
    String[] dlTimeLabels = new String[15];
    int[] dlTimeValues = new int[15];
    dlTimeLabels[0] = MessageText.getString("ConfigView.text.ignore");
    dlTimeValues[0] = 0;
    for (int i = 1; i < dlTimeValues.length; i++) {
        dlTimeLabels[i] = "<= " + (i + 2) + " " + sHours;
        dlTimeValues[i] = (i + 2) * 60;
    }
    new IntListParameter(cFP, "StartStopManager_iFirstPriority_DLMinutes", dlTimeLabels, dlTimeValues);
    label = new Label(cFirstPriorityArea, SWT.WRAP);
    // row
    label = new Label(cFP, SWT.NULL);
    Messages.setLanguageText(label, "ConfigView.label.seeding.firstPriority.seedingMinutes");
    String[] seedTimeLabels = new String[15];
    int[] seedTimeValues = new int[15];
    seedTimeLabels[0] = MessageText.getString("ConfigView.text.ignore");
    seedTimeValues[0] = 0;
    seedTimeLabels[1] = "<= 90 " + sMinutes;
    seedTimeValues[1] = 90;
    for (int i = 2; i < seedTimeValues.length; i++) {
        seedTimeLabels[i] = "<= " + i + " " + sHours;
        seedTimeValues[i] = i * 60;
    }
    new IntListParameter(cFP, "StartStopManager_iFirstPriority_SeedingMinutes", seedTimeLabels, seedTimeValues);
    // Group Ignore FP
    Composite cIgnoreFP = new Group(cFirstPriorityArea, SWT.NULL);
    layout = new GridLayout();
    layout.numColumns = 2;
    layout.verticalSpacing = 6;
    cIgnoreFP.setLayout(layout);
    gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL);
    gridData.horizontalSpan = 2;
    Utils.setLayoutData(cIgnoreFP, gridData);
    Messages.setLanguageText(cIgnoreFP, "ConfigView.label.seeding.firstPriority.ignore");
    // Ignore S:P Ratio
    label = new Label(cIgnoreFP, SWT.NULL);
    Messages.setLanguageText(label, "ConfigView.label.seeding.firstPriority.ignoreSPRatio");
    String[] ignoreSPRatioLabels = new String[15];
    int[] ignoreSPRatioValues = new int[15];
    ignoreSPRatioLabels[0] = MessageText.getString("ConfigView.text.ignore");
    ignoreSPRatioValues[0] = 0;
    for (int i = 1; i < ignoreSPRatioLabels.length; i++) {
        ignoreSPRatioLabels[i] = i * 10 + " " + ":1";
        ignoreSPRatioValues[i] = i * 10;
    }
    new IntListParameter(cIgnoreFP, "StartStopManager_iFirstPriority_ignoreSPRatio", 0, ignoreSPRatioLabels, ignoreSPRatioValues);
    // Ignore 0 Peers
    new BooleanParameter(cIgnoreFP, "StartStopManager_bFirstPriority_ignore0Peer", "ConfigView.label.seeding.firstPriority.ignore0Peer");
    label = new Label(cIgnoreFP, SWT.NULL);
    // Ignore idle hours
    label = new Label(cIgnoreFP, SWT.NULL);
    Messages.setLanguageText(label, "ConfigView.label.seeding.firstPriority.ignoreIdleHours");
    int[] availIdleHours = { 2, 3, 4, 5, 6, 7, 8, 12, 18, 24, 48, 72, 168 };
    String[] ignoreIdleHoursLabels = new String[availIdleHours.length + 1];
    int[] ignoreIdleHoursValues = new int[availIdleHours.length + 1];
    ignoreIdleHoursLabels[0] = MessageText.getString("ConfigView.text.ignore");
    ignoreIdleHoursValues[0] = 0;
    for (int i = 0; i < availIdleHours.length; i++) {
        ignoreIdleHoursLabels[i + 1] = availIdleHours[i] + " " + sHours;
        ignoreIdleHoursValues[i + 1] = availIdleHours[i];
    }
    new IntListParameter(cIgnoreFP, "StartStopManager_iFirstPriority_ignoreIdleHours", 0, ignoreIdleHoursLabels, ignoreIdleHoursValues);
    // row
    cArea1 = new Composite(cIgnoreFP, SWT.NULL);
    layout = new GridLayout();
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    layout.numColumns = 2;
    cArea1.setLayout(layout);
    gridData = new GridData(GridData.VERTICAL_ALIGN_FILL | GridData.HORIZONTAL_ALIGN_FILL);
    gridData.horizontalSpan = 2;
    Utils.setLayoutData(cArea1, gridData);
    label = new Label(cArea1, SWT.NULL);
    Messages.setLanguageText(label, "ConfigView.label.seeding.firstPriority.ignore.info");
    new BooleanParameter(cFirstPriorityArea, "StartStopManager_bTagFirstPriority", "ConfigView.label.queue.tagfirstpriority");
    return cFirstPriorityArea;
}
Also used : Group(org.eclipse.swt.widgets.Group) GridLayout(org.eclipse.swt.layout.GridLayout) Composite(org.eclipse.swt.widgets.Composite) GridData(org.eclipse.swt.layout.GridData) Label(org.eclipse.swt.widgets.Label) IntListParameter(com.biglybt.ui.swt.config.IntListParameter) BooleanParameter(com.biglybt.ui.swt.config.BooleanParameter)

Example 2 with BooleanParameter

use of com.biglybt.ui.swt.config.BooleanParameter 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 3 with BooleanParameter

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

the class ConfigSectionInterfaceLegacy method configSectionCreate.

// @see com.biglybt.ui.swt.pif.UISWTConfigSection#configSectionCreate(org.eclipse.swt.widgets.Composite)
@Override
public Composite configSectionCreate(Composite parent) {
    GridData gridData;
    GridLayout layout;
    Label label;
    Composite cSection = new Composite(parent, SWT.NULL);
    gridData = new GridData(GridData.VERTICAL_ALIGN_FILL | GridData.HORIZONTAL_ALIGN_FILL);
    cSection.setLayoutData(gridData);
    layout = new GridLayout();
    layout.numColumns = 1;
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    cSection.setLayout(layout);
    int userMode = COConfigurationManager.getIntParameter("User Mode");
    if (userMode < REQUIRED_MODE) {
        label = new Label(cSection, SWT.WRAP);
        gridData = new GridData();
        gridData.horizontalSpan = 2;
        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 cSection;
    }
    /**
     * Old-style speed menus.
     */
    new BooleanParameter(cSection, "GUI_SWT_bOldSpeedMenu", "ConfigView.label.use_old_speed_menus");
    BooleanParameter bpCustomTab = new BooleanParameter(cSection, "useCustomTab", "ConfigView.section.style.useCustomTabs");
    Control cFancyTab = new BooleanParameter(cSection, "GUI_SWT_bFancyTab", "ConfigView.section.style.useFancyTabs").getControl();
    Control[] controls = { cFancyTab };
    bpCustomTab.setAdditionalActionPerformer(new ChangeSelectionActionPerformer(controls));
    return cSection;
}
Also used : GridLayout(org.eclipse.swt.layout.GridLayout) Control(org.eclipse.swt.widgets.Control) Composite(org.eclipse.swt.widgets.Composite) GridData(org.eclipse.swt.layout.GridData) Label(org.eclipse.swt.widgets.Label) ChangeSelectionActionPerformer(com.biglybt.ui.swt.config.ChangeSelectionActionPerformer) BooleanParameter(com.biglybt.ui.swt.config.BooleanParameter)

Example 4 with BooleanParameter

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

the class ConfigSectionInterfaceStart method configSectionCreate.

@Override
public Composite configSectionCreate(final Composite parent) {
    // "Start" Sub-Section
    // -------------------
    GridLayout layout;
    Composite cStart = new Composite(parent, SWT.NULL);
    cStart.setLayoutData(new GridData(GridData.FILL_BOTH));
    layout = new GridLayout();
    layout.numColumns = 1;
    cStart.setLayout(layout);
    int userMode = COConfigurationManager.getIntParameter("User Mode");
    boolean isAZ3 = COConfigurationManager.getStringParameter("ui").equals("az3");
    if (userMode >= 2) {
        new BooleanParameter(cStart, "ui.startfirst", "ConfigView.label.StartUIBeforeCore");
    }
    new BooleanParameter(cStart, "Show Splash", "ConfigView.label.showsplash");
    new BooleanParameter(cStart, "update.start", "ConfigView.label.checkonstart");
    new BooleanParameter(cStart, "update.periodic", "ConfigView.label.periodiccheck");
    BooleanParameter autoDownload = new BooleanParameter(cStart, "update.autodownload", "ConfigView.section.update.autodownload");
    BooleanParameter openDialog = new BooleanParameter(cStart, "update.opendialog", "ConfigView.label.opendialog");
    autoDownload.setAdditionalActionPerformer(new ChangeSelectionActionPerformer(new Control[] { openDialog.getControl() }, true));
    new BooleanParameter(cStart, "update.anonymous", "ConfigView.label.update.anonymous");
    new Label(cStart, SWT.NULL);
    new BooleanParameter(cStart, "Open Transfer Bar On Start", "ConfigView.label.open_transfer_bar_on_start");
    new BooleanParameter(cStart, "Start Minimized", "ConfigView.label.startminimized");
    if (Constants.isUnix) {
        new BooleanParameter(cStart, "ui.useGTK2", "ConfigView.label.useGTK2");
    }
    // UI switcher window.
    Composite cUISwitcher = new Composite(cStart, SWT.NONE);
    layout = new GridLayout(2, false);
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    cUISwitcher.setLayout(layout);
    final Label ui_switcher_label = new Label(cUISwitcher, SWT.NULL);
    Messages.setLanguageText(ui_switcher_label, "ConfigView.label.ui_switcher");
    final Button ui_switcher_button = new Button(cUISwitcher, SWT.PUSH);
    Messages.setLanguageText(ui_switcher_button, "ConfigView.label.ui_switcher_button");
    ui_switcher_button.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event event) {
            UISwitcherUtil.openSwitcherWindow();
        }
    });
    return cStart;
}
Also used : BooleanParameter(com.biglybt.ui.swt.config.BooleanParameter) GridLayout(org.eclipse.swt.layout.GridLayout) GridData(org.eclipse.swt.layout.GridData) ChangeSelectionActionPerformer(com.biglybt.ui.swt.config.ChangeSelectionActionPerformer)

Example 5 with BooleanParameter

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

the class ConfigSectionFileTorrentsDecoding method configSectionCreate.

@Override
public Composite configSectionCreate(final Composite parent) {
    GridData gridData;
    GridLayout layout;
    Label label;
    Composite cSection = new Composite(parent, SWT.NULL);
    gridData = new GridData(GridData.VERTICAL_ALIGN_FILL | GridData.HORIZONTAL_ALIGN_FILL);
    cSection.setLayoutData(gridData);
    layout = new GridLayout();
    layout.numColumns = 2;
    cSection.setLayout(layout);
    int userMode = COConfigurationManager.getIntParameter("User Mode");
    if (userMode < REQUIRED_MODE) {
        label = new Label(cSection, 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 cSection;
    }
    // locale decoder
    label = new Label(cSection, SWT.NULL);
    Messages.setLanguageText(label, "ConfigView.section.file.decoder.label");
    LocaleUtilDecoder[] decoders = LocaleUtil.getSingleton().getDecoders();
    String[] decoderLabels = new String[decoders.length + 1];
    String[] decoderValues = new String[decoders.length + 1];
    decoderLabels[0] = MessageText.getString("ConfigView.section.file.decoder.nodecoder");
    decoderValues[0] = "";
    for (int i = 1; i <= decoders.length; i++) {
        decoderLabels[i] = decoderValues[i] = decoders[i - 1].getName();
    }
    new StringListParameter(cSection, "File.Decoder.Default", "", decoderLabels, decoderValues);
    // locale always prompt
    gridData = new GridData();
    gridData.horizontalSpan = 2;
    new BooleanParameter(cSection, "File.Decoder.Prompt", "ConfigView.section.file.decoder.prompt").setLayoutData(gridData);
    // show lax decodings
    gridData = new GridData();
    gridData.horizontalSpan = 2;
    new BooleanParameter(cSection, "File.Decoder.ShowLax", "ConfigView.section.file.decoder.showlax").setLayoutData(gridData);
    // show all decoders
    gridData = new GridData();
    gridData.horizontalSpan = 2;
    new BooleanParameter(cSection, "File.Decoder.ShowAll", "ConfigView.section.file.decoder.showall").setLayoutData(gridData);
    return cSection;
}
Also used : StringListParameter(com.biglybt.ui.swt.config.StringListParameter) GridLayout(org.eclipse.swt.layout.GridLayout) Composite(org.eclipse.swt.widgets.Composite) LocaleUtilDecoder(com.biglybt.core.internat.LocaleUtilDecoder) GridData(org.eclipse.swt.layout.GridData) Label(org.eclipse.swt.widgets.Label) BooleanParameter(com.biglybt.ui.swt.config.BooleanParameter)

Aggregations

BooleanParameter (com.biglybt.ui.swt.config.BooleanParameter)7 GridData (org.eclipse.swt.layout.GridData)7 GridLayout (org.eclipse.swt.layout.GridLayout)7 ChangeSelectionActionPerformer (com.biglybt.ui.swt.config.ChangeSelectionActionPerformer)3 IntParameter (com.biglybt.ui.swt.config.IntParameter)3 Composite (org.eclipse.swt.widgets.Composite)3 Label (org.eclipse.swt.widgets.Label)3 AERunnable (com.biglybt.core.util.AERunnable)2 IntListParameter (com.biglybt.ui.swt.config.IntListParameter)2 Parameter (com.biglybt.ui.swt.config.Parameter)2 StringListParameter (com.biglybt.ui.swt.config.StringListParameter)2 StringParameter (com.biglybt.ui.swt.config.StringParameter)2 BackupManager (com.biglybt.core.backup.BackupManager)1 LocaleUtilDecoder (com.biglybt.core.internat.LocaleUtilDecoder)1 AEDiagnosticsLogger (com.biglybt.core.util.AEDiagnosticsLogger)1 com.biglybt.pif.ui.config (com.biglybt.pif.ui.config)1 BasicPluginConfigModel (com.biglybt.pif.ui.model.BasicPluginConfigModel)1 com.biglybt.pifimpl.local.ui.config (com.biglybt.pifimpl.local.ui.config)1 UserPrompterResultListener (com.biglybt.ui.UserPrompterResultListener)1 TextViewerWindow (com.biglybt.ui.swt.TextViewerWindow)1