Search in sources :

Example 1 with IntListParameter

use of com.biglybt.pif.ui.config.IntListParameter in project BiglyBT by BiglySoftware.

the class ConfigSectionMode method build.

@Override
public void build() {
    // final String[] messTexts =
    // {	"ConfigView.section.mode.beginner.wiki.definitions",
    // "ConfigView.section.mode.intermediate.wiki.host",
    // "ConfigView.section.mode.advanced.wiki.main",
    // };
    final String[] links = { Wiki.MODE_BEGINNER, Wiki.MODE_INTERMEDIATE, Wiki.MODE_ADVANCED };
    int userMode = COConfigurationManager.getIntParameter(ICFG_USER_MODE);
    int[] values = { Parameter.MODE_BEGINNER, Parameter.MODE_INTERMEDIATE, Parameter.MODE_ADVANCED };
    String[] labels = { MessageText.getString("ConfigView.section.mode.beginner"), MessageText.getString("ConfigView.section.mode.intermediate"), MessageText.getString("ConfigView.section.mode.advanced") };
    Map<Integer, String> mapInfos = new HashMap<>();
    mapInfos.put(Parameter.MODE_BEGINNER, "ConfigView.section.mode.beginner.text");
    mapInfos.put(Parameter.MODE_INTERMEDIATE, "ConfigView.section.mode.intermediate.text");
    mapInfos.put(Parameter.MODE_ADVANCED, "ConfigView.section.mode.advanced.text");
    IntListParameterImpl paramUserMode = new IntListParameterImpl(ICFG_USER_MODE, null, values, labels);
    paramUserMode.setListType(IntListParameter.TYPE_RADIO_COMPACT);
    add(paramUserMode);
    LabelParameterImpl paramInfo = new LabelParameterImpl("");
    add("mode.info", paramInfo);
    HyperlinkParameterImpl paramInfoLink = new HyperlinkParameterImpl("ConfigView.label.please.visit.here", links[userMode]);
    add(paramInfoLink);
    paramUserMode.addListener(param -> {
        int newUserMode = ((IntListParameter) param).getValue();
        paramInfoLink.setHyperlink(links[newUserMode]);
        String key = mapInfos.get(newUserMode);
        if (MessageText.keyExists(key + "1")) {
            key = key + "1";
        }
        paramInfo.setLabelText("-> " + MessageText.getString(key));
    });
    paramUserMode.fireParameterChanged();
    ParameterGroupImpl pgRadio = new ParameterGroupImpl("ConfigView.section.mode.title", paramUserMode, paramInfo, paramInfoLink);
    add("pgRadio", pgRadio);
    add("gap1", new LabelParameterImpl(""));
    add("gap2", new LabelParameterImpl(""));
    add("gap3", new LabelParameterImpl(""));
    // reset to defaults
    ActionParameterImpl reset_button = new ActionParameterImpl("ConfigView.section.mode.resetdefaults", "Button.reset");
    add(reset_button);
    reset_button.addListener(param -> {
        UIFunctions uiFunctions = UIFunctionsManager.getUIFunctions();
        if (uiFunctions == null) {
            resetAll();
            return;
        }
        UIFunctionsUserPrompter prompter = uiFunctions.getUserPrompter(MessageText.getString("resetconfig.warn.title"), MessageText.getString("resetconfig.warn"), new String[] { MessageText.getString("Button.ok"), MessageText.getString("Button.cancel") }, 1);
        if (prompter == null) {
            resetAll();
            return;
        }
        prompter.open(result -> {
            if (result != 0) {
                return;
            }
            resetAll();
        });
    });
}
Also used : HashMap(java.util.HashMap) UIFunctionsUserPrompter(com.biglybt.ui.UIFunctionsUserPrompter) IntListParameter(com.biglybt.pif.ui.config.IntListParameter) UIFunctions(com.biglybt.ui.UIFunctions)

Aggregations

IntListParameter (com.biglybt.pif.ui.config.IntListParameter)1 UIFunctions (com.biglybt.ui.UIFunctions)1 UIFunctionsUserPrompter (com.biglybt.ui.UIFunctionsUserPrompter)1 HashMap (java.util.HashMap)1