mirror of
https://github.com/DanilaFe/abacus
synced 2024-11-18 00:19:32 -08:00
Read delay input from input field, and kill delay thread.
This commit is contained in:
parent
b2fad93ce4
commit
ed7d60800b
|
@ -1,6 +1,8 @@
|
||||||
package org.nwapw.abacus.fx;
|
package org.nwapw.abacus.fx;
|
||||||
|
|
||||||
import javafx.application.Platform;
|
import javafx.application.Platform;
|
||||||
|
import javafx.beans.value.ChangeListener;
|
||||||
|
import javafx.beans.value.ObservableValue;
|
||||||
import javafx.collections.FXCollections;
|
import javafx.collections.FXCollections;
|
||||||
import javafx.collections.ObservableList;
|
import javafx.collections.ObservableList;
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
|
@ -89,6 +91,8 @@ public class AbacusController implements PluginListener {
|
||||||
private ComboBox<String> numberImplementationBox;
|
private ComboBox<String> numberImplementationBox;
|
||||||
@FXML
|
@FXML
|
||||||
private ListView<ToggleablePlugin> enabledPluginView;
|
private ListView<ToggleablePlugin> enabledPluginView;
|
||||||
|
@FXML
|
||||||
|
private TextField computationLimitField;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The list of history entries, created by the users.
|
* The list of history entries, created by the users.
|
||||||
|
@ -130,12 +134,10 @@ public class AbacusController implements PluginListener {
|
||||||
private final Runnable TIMER_RUNNABLE = () -> {
|
private final Runnable TIMER_RUNNABLE = () -> {
|
||||||
try {
|
try {
|
||||||
Configuration abacusConfig = abacus.getConfiguration();
|
Configuration abacusConfig = abacus.getConfiguration();
|
||||||
if(abacusConfig.getComputationDelay() != 0)
|
if(abacusConfig.getComputationDelay() == 0) return;
|
||||||
Thread.sleep((long) (abacusConfig.getComputationDelay() * 1000));
|
Thread.sleep((long) (abacusConfig.getComputationDelay() * 1000));
|
||||||
} catch (InterruptedException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
performStop();
|
performStop();
|
||||||
|
} catch (InterruptedException e) { }
|
||||||
};
|
};
|
||||||
/**
|
/**
|
||||||
* The runnable used to perform the calculation.
|
* The runnable used to perform the calculation.
|
||||||
|
@ -174,6 +176,7 @@ public class AbacusController implements PluginListener {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
private Thread computationLimitThread;
|
||||||
/**
|
/**
|
||||||
* The thread in which the computation runs.
|
* The thread in which the computation runs.
|
||||||
*/
|
*/
|
||||||
|
@ -237,6 +240,15 @@ public class AbacusController implements PluginListener {
|
||||||
}
|
}
|
||||||
abacusPluginManager.reload();
|
abacusPluginManager.reload();
|
||||||
|
|
||||||
|
computationLimitField.setText(Double.toString(abacus.getConfiguration().getComputationDelay()));
|
||||||
|
computationLimitField.textProperty().addListener((observable, oldValue, newValue) -> {
|
||||||
|
if(!newValue.matches("(\\d+(\\.\\d*)?)?")) {
|
||||||
|
computationLimitField.setText(oldValue);
|
||||||
|
} else {
|
||||||
|
changesMade = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
changesMade = false;
|
changesMade = false;
|
||||||
reloadAlertShown = false;
|
reloadAlertShown = false;
|
||||||
|
|
||||||
|
@ -252,13 +264,20 @@ public class AbacusController implements PluginListener {
|
||||||
stopButton.setDisable(false);
|
stopButton.setDisable(false);
|
||||||
calculationThread = new Thread(CALCULATION_RUNNABLE);
|
calculationThread = new Thread(CALCULATION_RUNNABLE);
|
||||||
calculationThread.start();
|
calculationThread.start();
|
||||||
new Thread(TIMER_RUNNABLE).start();
|
computationLimitThread = new Thread(TIMER_RUNNABLE);
|
||||||
|
computationLimitThread.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private void performStop(){
|
private void performStop(){
|
||||||
if(calculationThread != null)
|
if(calculationThread != null) {
|
||||||
calculationThread.interrupt();
|
calculationThread.interrupt();
|
||||||
|
calculationThread = null;
|
||||||
|
}
|
||||||
|
if(computationLimitThread != null){
|
||||||
|
computationLimitThread.interrupt();
|
||||||
|
computationLimitThread = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
|
@ -284,6 +303,9 @@ public class AbacusController implements PluginListener {
|
||||||
for (ToggleablePlugin pluginEntry : enabledPlugins) {
|
for (ToggleablePlugin pluginEntry : enabledPlugins) {
|
||||||
if (!pluginEntry.isEnabled()) disabledPlugins.add(pluginEntry.getClassName());
|
if (!pluginEntry.isEnabled()) disabledPlugins.add(pluginEntry.getClassName());
|
||||||
}
|
}
|
||||||
|
if(computationLimitField.getText().matches("\\d*(\\.\\d+)?") && computationLimitField.getText().length() != 0)
|
||||||
|
configuration.setComputationDelay(Double.parseDouble(computationLimitField.getText()));
|
||||||
|
System.out.println(configuration.getComputationDelay());
|
||||||
configuration.saveTo(CONFIG_FILE);
|
configuration.saveTo(CONFIG_FILE);
|
||||||
changesMade = false;
|
changesMade = false;
|
||||||
reloadAlertShown = false;
|
reloadAlertShown = false;
|
||||||
|
@ -310,4 +332,5 @@ public class AbacusController implements PluginListener {
|
||||||
enabledPlugins.clear();
|
enabledPlugins.clear();
|
||||||
numberImplementationOptions.clear();
|
numberImplementationOptions.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,7 +50,9 @@
|
||||||
<ListView fx:id="enabledPluginView"
|
<ListView fx:id="enabledPluginView"
|
||||||
GridPane.rowIndex="1" GridPane.columnIndex="0"
|
GridPane.rowIndex="1" GridPane.columnIndex="0"
|
||||||
GridPane.columnSpan="2" maxHeight="100"/>
|
GridPane.columnSpan="2" maxHeight="100"/>
|
||||||
<FlowPane GridPane.columnIndex="0" GridPane.columnSpan="2" GridPane.rowIndex="2" hgap="10"
|
<Text GridPane.columnIndex="0" GridPane.rowIndex="2" text="Computation Limit"/>
|
||||||
|
<TextField fx:id="computationLimitField" GridPane.columnIndex="1" GridPane.rowIndex="2"/>
|
||||||
|
<FlowPane GridPane.columnIndex="0" GridPane.columnSpan="2" GridPane.rowIndex="3" hgap="10"
|
||||||
vgap="10">
|
vgap="10">
|
||||||
<Button text="Apply" onAction="#performSave"/>
|
<Button text="Apply" onAction="#performSave"/>
|
||||||
<Button text="Reload Plugins" onAction="#performReload"/>
|
<Button text="Reload Plugins" onAction="#performReload"/>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user