Refactoring - Extract Method, Large Class

This commit is contained in:
2025-05-25 18:57:16 +02:00
parent 757e51f1db
commit 087b132362
3 changed files with 35 additions and 26 deletions

View File

@ -72,8 +72,6 @@ public class Controller_Frontend extends PICComponent implements FrontendControl
@FXML
private CheckBox wdtCheck;
private static volatile boolean isAutoRunActive = false;
private static volatile boolean isSleeping = false;
public Controller_Frontend() {
@ -82,21 +80,21 @@ public class Controller_Frontend extends PICComponent implements FrontendControl
}
public boolean isSleeping (){
return isSleeping;
}
//Refactoring
public void stopRunFromBackend(String message) {
isAutoRunActive = false;
ExecutionState.setAutoRunActive(false);
handleSleepOrReset();
showStopDialog(message);
}
private void handleSleepOrReset() {
if (isSleeping) {
wakeUpFromSleep();
if (ExecutionState.isSleeping()) {
ExecutionState.wakeUp();
} else {
dataRegister.resetPC();
}
@ -123,31 +121,26 @@ public class Controller_Frontend extends PICComponent implements FrontendControl
}
//Refactoring Ende
public void sleep() {
isSleeping = true;
}
public void wakeUpFromSleep() {
isSleeping = false;
}
@FXML
private void stopAutoRun(ActionEvent event) {
isAutoRunActive = false;
ExecutionState.setAutoRunActive(false);
}
@FXML
public void autoRunGUI(ActionEvent event) {
if (!isAutoRunActive) {
isAutoRunActive = true;
if (!ExecutionState.isAutoRunActive()) {
ExecutionState.setAutoRunActive(true) ;
}
Thread autoRunThread = new Thread(() -> {
try {
while (dataRegister.getPC() < prog.length && isAutoRunActive){
while (dataRegister.getPC() < prog.length && ExecutionState.isAutoRunActive()){
Platform.runLater(() -> {
try {
@ -167,6 +160,7 @@ public class Controller_Frontend extends PICComponent implements FrontendControl
}
private void updateExecutionTimeMultiplier() {
String selectedOption = executionTimeComboBox.getValue();
commands.setExecutionTimeMultiplier(selectedOption);
@ -181,7 +175,7 @@ public class Controller_Frontend extends PICComponent implements FrontendControl
int currentIndex;
// Aktuelle Zeile abrufen
if (!isSleeping)
if (!ExecutionState.isSleeping())
currentIndex = ind[dataRegister.getPC()];
else
currentIndex = ind[dataRegister.getPC()]-1;
@ -210,14 +204,14 @@ public class Controller_Frontend extends PICComponent implements FrontendControl
lstContentListView.getSelectionModel().select(currentIndex);
String selectedRowStyle;
if (!isSleeping)
if (!ExecutionState.isSleeping())
selectedRowStyle = "-fx-background-color: red; -fx-text-fill: white;";
else
selectedRowStyle = "-fx-background-color: teal; -fx-text-fill: white;";
markSelectedRow(currentIndex, selectedRowStyle);
if (!isSleeping) {
if (!ExecutionState.isSleeping()) {
commands.decode(prog[dataRegister.getPC()]);
dataRegister.increasePC();
}
@ -285,7 +279,7 @@ public class Controller_Frontend extends PICComponent implements FrontendControl
} catch (NullPointerException ignored) {}
}
programStack.reset();
wakeUpFromSleep();
ExecutionState.wakeUp();
breakpoints.clear();
ioPorts.refreshUI(getTRISbuttons(), getPORTbuttons());
commands.resetTotalExecutionTime();

View File

@ -0,0 +1,19 @@
package fabrik.simulator.pic16f84;
public class ExecutionState {
private static boolean isAutoRunActive = false;
private static boolean isSleeping = false;
private static double executionTimeMultiplier = 1;
public static boolean isAutoRunActive() { return isAutoRunActive; }
public static void setAutoRunActive(boolean active) { isAutoRunActive = active; }
public static boolean isSleeping() { return isSleeping; }
public static void sleep() { isSleeping = true; }
public static void wakeUp() { isSleeping = false; }
public static double getExecutionTimeMultiplier() { return executionTimeMultiplier; }
public static void setExecutionTimeMultiplier(double multiplier) { executionTimeMultiplier = multiplier; }
}

View File

@ -2,11 +2,7 @@ package fabrik.simulator.pic16f84.interfaces;
public interface FrontendControllerInterface extends PICComponentInterface {
void sleep();
void wakeUpFromSleep();
boolean isSleeping();
void stopRunFromBackend(String watchdogTimer);
}