forked from j62/ctbrec
53 lines
1.5 KiB
Java
53 lines
1.5 KiB
Java
package ctbrec.ui.settings;
|
|
|
|
import java.io.IOException;
|
|
import java.util.HashSet;
|
|
import java.util.Set;
|
|
|
|
import ctbrec.recorder.postprocessing.PostProcessor;
|
|
import ctbrec.ui.settings.api.Preferences;
|
|
import ctbrec.ui.settings.api.PreferencesStorage;
|
|
import ctbrec.ui.settings.api.Setting;
|
|
import javafx.beans.property.Property;
|
|
import javafx.scene.Node;
|
|
import javafx.scene.control.TextField;
|
|
|
|
public abstract class AbstractPostProcessingPaneFactory {
|
|
|
|
private PostProcessor pp;
|
|
Set<Property<?>> properties = new HashSet<>();
|
|
|
|
public abstract Preferences doCreatePostProcessorPane(PostProcessor pp);
|
|
|
|
public Preferences createPostProcessorPane(PostProcessor pp) {
|
|
this.pp = pp;
|
|
return doCreatePostProcessorPane(pp);
|
|
}
|
|
|
|
class MapPreferencesStorage implements PreferencesStorage {
|
|
|
|
@Override
|
|
public void save(Preferences preferences) throws IOException {
|
|
for (Property<?> property : properties) {
|
|
String key = property.getName();
|
|
Object value = preferences.getSetting(key).get().getProperty().getValue();
|
|
pp.getConfig().put(key, value.toString());
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void load(Preferences preferences) {
|
|
// no op
|
|
}
|
|
|
|
@SuppressWarnings("unchecked")
|
|
@Override
|
|
public Node createGui(Setting setting) throws Exception {
|
|
TextField input = new TextField();
|
|
input.textProperty().bindBidirectional(setting.getProperty());
|
|
return input;
|
|
}
|
|
|
|
}
|
|
}
|