Java: how to work with user settings in plugins for my application?

I am currently working on an application that receives commands from other devices. I will give an interface that allows others to develop their own interpretation (plugin) of incoming commands. Each of the plugins developed by others can have any user settings that should be provided by users.

For example, a plugin called "KeyboardPlugin" may support settings for setting the delay between keystrokes, and also display a list of all supported keys for pressing. Another plugin can be called, for example, "MouseMovePlugin", where the user can select the accuracy of the mouse and its speed.

Now my problem is that the settings for each plugin should be 1. shown in the user interface, 2. after the settings have been selected by the user, they should be analyzed back to the plugin so that the plugin knows what the user has selected.

I work with Java and the user interface is developed in Swing. There is a parameter panel that shows parameters that are not directly related to the plugin, as general parameters. But in the same panel I want to show the settings provided by the plugin.

Plugin settings are as follows:

  • a) "Enter the delay between two keystrokes β†’ [Text field with Int as input] (from min. 1, max. 500).
  • b) "bla bla β†’ [Checkbox] (with boolean)"
  • c) "Bla bla 2 β†’ [Textbox] (with String values ​​as input; refers to setting b!)
  • d) " , " [ "a", "b", "c" ]

, , , int, boolean, string, d, . , ? , , , c b.

1) , , , , , ? , List , .

2) " ". , ?

, , : (DSL), : varName: type (min, max, default) "UI question" :

buttonDelay: boolean(false) "Enable button delay"
if(buttonDelay){
buttonDelayTime: int(1,500,25) "Choose delay between buttons"
}

DSL Java, , . , ( , / ), , Map, - varName ( : "buttonDelay" "buttonDelaytime" ). , , , , Integer, , .. , varName, :

public void initPluginSettings(Map<String,SettingsInterface> settingsMap){
BooleanSetting buttonDelay = settingsMap.get("buttonDelay"); 
IntegerSetting buttonDelayTime = settingsMap.get("buttonDelayTime");
}

- / ? ? , . DSL, .., " ". , , , .

!

+5
2

- :

interface Plugin {
  Map<String, String> getSettingsList();
  getPossibleValuesFor(String key);
  setValue(String key, .. value);
  .. getValue();
}

getSettingsList() ; getPossibleValuesFor() , . .

+2

- :

Interface Plugin extends Serializable
{
    // You don't know what the plugin is, the possible options, or how best to set them. Let plugin developers build their own settings UI, you just grab and display it in your own JPanel.
    public JPanel getOptionsPanel();

    // We don't know the types of data that can be returned from plugins, so build a map of the setting name to what the user set it to, and return that to the plugin itself.
    public Map<String, Object> getUserSettings();
}

, . . .

+1

All Articles