Refactoring - Extract Method, Large Class
This commit is contained in:
@ -72,8 +72,6 @@ public class Controller_Frontend extends PICComponent implements FrontendControl
|
|||||||
@FXML
|
@FXML
|
||||||
private CheckBox wdtCheck;
|
private CheckBox wdtCheck;
|
||||||
|
|
||||||
private static volatile boolean isAutoRunActive = false;
|
|
||||||
private static volatile boolean isSleeping = false;
|
|
||||||
|
|
||||||
|
|
||||||
public Controller_Frontend() {
|
public Controller_Frontend() {
|
||||||
@ -82,21 +80,21 @@ public class Controller_Frontend extends PICComponent implements FrontendControl
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public boolean isSleeping (){
|
|
||||||
return isSleeping;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//Refactoring
|
//Refactoring
|
||||||
|
|
||||||
public void stopRunFromBackend(String message) {
|
public void stopRunFromBackend(String message) {
|
||||||
isAutoRunActive = false;
|
ExecutionState.setAutoRunActive(false);
|
||||||
|
|
||||||
handleSleepOrReset();
|
handleSleepOrReset();
|
||||||
showStopDialog(message);
|
showStopDialog(message);
|
||||||
|
|
||||||
}
|
}
|
||||||
private void handleSleepOrReset() {
|
private void handleSleepOrReset() {
|
||||||
if (isSleeping) {
|
if (ExecutionState.isSleeping()) {
|
||||||
wakeUpFromSleep();
|
ExecutionState.wakeUp();
|
||||||
} else {
|
} else {
|
||||||
dataRegister.resetPC();
|
dataRegister.resetPC();
|
||||||
}
|
}
|
||||||
@ -123,31 +121,26 @@ public class Controller_Frontend extends PICComponent implements FrontendControl
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//Refactoring Ende
|
//Refactoring Ende
|
||||||
|
|
||||||
public void sleep() {
|
|
||||||
isSleeping = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void wakeUpFromSleep() {
|
|
||||||
isSleeping = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private void stopAutoRun(ActionEvent event) {
|
private void stopAutoRun(ActionEvent event) {
|
||||||
isAutoRunActive = false;
|
ExecutionState.setAutoRunActive(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
public void autoRunGUI(ActionEvent event) {
|
public void autoRunGUI(ActionEvent event) {
|
||||||
if (!isAutoRunActive) {
|
if (!ExecutionState.isAutoRunActive()) {
|
||||||
isAutoRunActive = true;
|
ExecutionState.setAutoRunActive(true) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
Thread autoRunThread = new Thread(() -> {
|
Thread autoRunThread = new Thread(() -> {
|
||||||
try {
|
try {
|
||||||
while (dataRegister.getPC() < prog.length && isAutoRunActive){
|
while (dataRegister.getPC() < prog.length && ExecutionState.isAutoRunActive()){
|
||||||
|
|
||||||
Platform.runLater(() -> {
|
Platform.runLater(() -> {
|
||||||
try {
|
try {
|
||||||
@ -167,6 +160,7 @@ public class Controller_Frontend extends PICComponent implements FrontendControl
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private void updateExecutionTimeMultiplier() {
|
private void updateExecutionTimeMultiplier() {
|
||||||
String selectedOption = executionTimeComboBox.getValue();
|
String selectedOption = executionTimeComboBox.getValue();
|
||||||
commands.setExecutionTimeMultiplier(selectedOption);
|
commands.setExecutionTimeMultiplier(selectedOption);
|
||||||
@ -181,7 +175,7 @@ public class Controller_Frontend extends PICComponent implements FrontendControl
|
|||||||
|
|
||||||
int currentIndex;
|
int currentIndex;
|
||||||
// Aktuelle Zeile abrufen
|
// Aktuelle Zeile abrufen
|
||||||
if (!isSleeping)
|
if (!ExecutionState.isSleeping())
|
||||||
currentIndex = ind[dataRegister.getPC()];
|
currentIndex = ind[dataRegister.getPC()];
|
||||||
else
|
else
|
||||||
currentIndex = ind[dataRegister.getPC()]-1;
|
currentIndex = ind[dataRegister.getPC()]-1;
|
||||||
@ -210,14 +204,14 @@ public class Controller_Frontend extends PICComponent implements FrontendControl
|
|||||||
lstContentListView.getSelectionModel().select(currentIndex);
|
lstContentListView.getSelectionModel().select(currentIndex);
|
||||||
|
|
||||||
String selectedRowStyle;
|
String selectedRowStyle;
|
||||||
if (!isSleeping)
|
if (!ExecutionState.isSleeping())
|
||||||
selectedRowStyle = "-fx-background-color: red; -fx-text-fill: white;";
|
selectedRowStyle = "-fx-background-color: red; -fx-text-fill: white;";
|
||||||
else
|
else
|
||||||
selectedRowStyle = "-fx-background-color: teal; -fx-text-fill: white;";
|
selectedRowStyle = "-fx-background-color: teal; -fx-text-fill: white;";
|
||||||
|
|
||||||
markSelectedRow(currentIndex, selectedRowStyle);
|
markSelectedRow(currentIndex, selectedRowStyle);
|
||||||
|
|
||||||
if (!isSleeping) {
|
if (!ExecutionState.isSleeping()) {
|
||||||
commands.decode(prog[dataRegister.getPC()]);
|
commands.decode(prog[dataRegister.getPC()]);
|
||||||
dataRegister.increasePC();
|
dataRegister.increasePC();
|
||||||
}
|
}
|
||||||
@ -285,7 +279,7 @@ public class Controller_Frontend extends PICComponent implements FrontendControl
|
|||||||
} catch (NullPointerException ignored) {}
|
} catch (NullPointerException ignored) {}
|
||||||
}
|
}
|
||||||
programStack.reset();
|
programStack.reset();
|
||||||
wakeUpFromSleep();
|
ExecutionState.wakeUp();
|
||||||
breakpoints.clear();
|
breakpoints.clear();
|
||||||
ioPorts.refreshUI(getTRISbuttons(), getPORTbuttons());
|
ioPorts.refreshUI(getTRISbuttons(), getPORTbuttons());
|
||||||
commands.resetTotalExecutionTime();
|
commands.resetTotalExecutionTime();
|
||||||
|
|||||||
19
src/main/java/fabrik/simulator/pic16f84/ExecutionState.java
Normal file
19
src/main/java/fabrik/simulator/pic16f84/ExecutionState.java
Normal 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; }
|
||||||
|
}
|
||||||
|
|
||||||
@ -2,11 +2,7 @@ package fabrik.simulator.pic16f84.interfaces;
|
|||||||
|
|
||||||
public interface FrontendControllerInterface extends PICComponentInterface {
|
public interface FrontendControllerInterface extends PICComponentInterface {
|
||||||
|
|
||||||
void sleep();
|
|
||||||
|
|
||||||
void wakeUpFromSleep();
|
|
||||||
|
|
||||||
boolean isSleeping();
|
|
||||||
|
|
||||||
void stopRunFromBackend(String watchdogTimer);
|
void stopRunFromBackend(String watchdogTimer);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user