mirror of
https://github.com/DanilaFe/abacus
synced 2024-12-22 07:20:09 -08:00
Switch the ToggleablePlugin class to Kotlin to avoid boilerplate.
This commit is contained in:
parent
fe92929856
commit
e71b037195
|
@ -216,7 +216,7 @@ public class AbacusController implements PluginListener {
|
|||
Callback<TableColumn<HistoryModel, String>, TableCell<HistoryModel, String>> cellFactory =
|
||||
param -> new CopyableCell<>();
|
||||
Callback<ListView<ToggleablePlugin>, ListCell<ToggleablePlugin>> pluginCellFactory =
|
||||
param -> new CheckBoxListCell<>(ToggleablePlugin::enabledProperty, new StringConverter<ToggleablePlugin>() {
|
||||
param -> new CheckBoxListCell<>(ToggleablePlugin::getEnabledProperty, new StringConverter<ToggleablePlugin>() {
|
||||
@Override
|
||||
public String toString(ToggleablePlugin object) {
|
||||
return object.getClassName().substring(object.getClassName().lastIndexOf('.') + 1);
|
||||
|
@ -224,7 +224,7 @@ public class AbacusController implements PluginListener {
|
|||
|
||||
@Override
|
||||
public ToggleablePlugin fromString(String string) {
|
||||
return new ToggleablePlugin(true, string);
|
||||
return new ToggleablePlugin(string, true);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -343,8 +343,8 @@ public class AbacusController implements PluginListener {
|
|||
numberImplementationBox.getSelectionModel().select(toSelect);
|
||||
for (Class<?> pluginClass : abacus.getPluginManager().getLoadedPluginClasses()) {
|
||||
String fullName = pluginClass.getName();
|
||||
ToggleablePlugin plugin = new ToggleablePlugin(!disabledPlugins.contains(fullName), fullName);
|
||||
plugin.enabledProperty().addListener(e -> changesMade = true);
|
||||
ToggleablePlugin plugin = new ToggleablePlugin(fullName, !disabledPlugins.contains(fullName));
|
||||
plugin.getEnabledProperty().addListener(e -> changesMade = true);
|
||||
enabledPlugins.add(plugin);
|
||||
}
|
||||
functionList.addAll(manager.getAllFunctions());
|
||||
|
|
|
@ -1,60 +0,0 @@
|
|||
package org.nwapw.abacus.fx;
|
||||
|
||||
import javafx.beans.property.BooleanProperty;
|
||||
import javafx.beans.property.SimpleBooleanProperty;
|
||||
|
||||
/**
|
||||
* Class that represents an entry in the plugin check box list.
|
||||
* The changes from this property are written to the config on application.
|
||||
*/
|
||||
public class ToggleablePlugin {
|
||||
|
||||
/**
|
||||
* The property that determines whether the plugin will be enabled.
|
||||
*/
|
||||
private final BooleanProperty enabled;
|
||||
/**
|
||||
* The name of the class this entry toggles.
|
||||
*/
|
||||
private final String className;
|
||||
|
||||
/**
|
||||
* Creates a new toggleable plugin with the given properties.
|
||||
*
|
||||
* @param enabled the enabled / disabled state at the beginning.
|
||||
* @param className the name of the class this plugin toggles.
|
||||
*/
|
||||
public ToggleablePlugin(boolean enabled, String className) {
|
||||
this.enabled = new SimpleBooleanProperty();
|
||||
this.enabled.setValue(enabled);
|
||||
this.className = className;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the enabled property of this plugin.
|
||||
*
|
||||
* @return the enabled property.
|
||||
*/
|
||||
public BooleanProperty enabledProperty() {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if this plugin entry should be enabled.
|
||||
*
|
||||
* @return whether this plugin will be enabled.
|
||||
*/
|
||||
public boolean isEnabled() {
|
||||
return enabled.get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the class name this plugin toggles.
|
||||
*
|
||||
* @return the class name that should be disabled.
|
||||
*/
|
||||
public String getClassName() {
|
||||
return className;
|
||||
}
|
||||
|
||||
}
|
13
src/main/kotlin/org/nwapw/abacus/fx/ToggleablePlugin.kt
Normal file
13
src/main/kotlin/org/nwapw/abacus/fx/ToggleablePlugin.kt
Normal file
|
@ -0,0 +1,13 @@
|
|||
package org.nwapw.abacus.fx
|
||||
|
||||
import javafx.beans.property.SimpleBooleanProperty
|
||||
|
||||
class ToggleablePlugin (val className: String, enabled: Boolean) {
|
||||
|
||||
val enabledProperty = SimpleBooleanProperty(enabled)
|
||||
|
||||
fun isEnabled(): Boolean {
|
||||
return enabledProperty.value
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user