1
0
mirror of https://github.com/DanilaFe/abacus synced 2024-06-23 11:17:06 -07:00

Read delay input from input field, and kill delay thread.

This commit is contained in:
Danila Fedorin 2017-08-07 10:30:37 -07:00
parent c5ec521996
commit 314552f95a
2 changed files with 33 additions and 8 deletions

View File

@ -1,6 +1,8 @@
package org.nwapw.abacus.fx;
import javafx.application.Platform;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
@ -89,6 +91,8 @@ public class AbacusController implements PluginListener {
private ComboBox<String> numberImplementationBox;
@FXML
private ListView<ToggleablePlugin> enabledPluginView;
@FXML
private TextField computationLimitField;
/**
* The list of history entries, created by the users.
@ -130,12 +134,10 @@ public class AbacusController implements PluginListener {
private final Runnable TIMER_RUNNABLE = () -> {
try {
Configuration abacusConfig = abacus.getConfiguration();
if(abacusConfig.getComputationDelay() != 0)
if(abacusConfig.getComputationDelay() == 0) return;
Thread.sleep((long) (abacusConfig.getComputationDelay() * 1000));
} catch (InterruptedException e) {
e.printStackTrace();
}
performStop();
performStop();
} catch (InterruptedException e) { }
};
/**
* 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.
*/
@ -237,6 +240,15 @@ public class AbacusController implements PluginListener {
}
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;
reloadAlertShown = false;
@ -252,13 +264,20 @@ public class AbacusController implements PluginListener {
stopButton.setDisable(false);
calculationThread = new Thread(CALCULATION_RUNNABLE);
calculationThread.start();
new Thread(TIMER_RUNNABLE).start();
computationLimitThread = new Thread(TIMER_RUNNABLE);
computationLimitThread.start();
}
@FXML
private void performStop(){
if(calculationThread != null)
if(calculationThread != null) {
calculationThread.interrupt();
calculationThread = null;
}
if(computationLimitThread != null){
computationLimitThread.interrupt();
computationLimitThread = null;
}
}
@FXML
@ -284,6 +303,9 @@ public class AbacusController implements PluginListener {
for (ToggleablePlugin pluginEntry : enabledPlugins) {
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);
changesMade = false;
reloadAlertShown = false;
@ -310,4 +332,5 @@ public class AbacusController implements PluginListener {
enabledPlugins.clear();
numberImplementationOptions.clear();
}
}

View File

@ -50,7 +50,9 @@
<ListView fx:id="enabledPluginView"
GridPane.rowIndex="1" GridPane.columnIndex="0"
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">
<Button text="Apply" onAction="#performSave"/>
<Button text="Reload Plugins" onAction="#performReload"/>