zusammenfuegen

This commit is contained in:
2024-05-06 01:26:03 +02:00
parent 3590779e74
commit 68ddce74a8
4 changed files with 173 additions and 11 deletions

View File

@ -2,6 +2,8 @@ package fabrik.simulator.pic16f84;
import com.gluonhq.charm.glisten.control.ToggleButtonGroup;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
@ -23,6 +25,7 @@ import javafx.stage.Stage;
import java.util.Arrays;
import java.util.Objects;
public class Controller_Frontend {
@ -33,12 +36,13 @@ public class Controller_Frontend {
@FXML
private Button stepintoButton;
@FXML
private TableView<Table.DataEntry> tableView;
@FXML
private TextArea lstContentLabel;
private ListView<String> lstContentListView;
@FXML
private Label pclLabel;
@ -57,13 +61,126 @@ public class Controller_Frontend {
@FXML
private Button stepButton;
@FXML
private Button autoRunButton;
@FXML
private void autoRun(ActionEvent event) throws IOException {
if (lstContentListView.getItems().isEmpty()) {
// Datei ist nicht geladen oder leer
return;
}
// Aktuelle Zeile abrufen
int currentIndex = lstContentListView.getSelectionModel().getSelectedIndex();
currentIndex = (currentIndex == -1) ? 0 : currentIndex + 1;
// Durch das gesamte Programm laufen
while (currentIndex < lstContentListView.getItems().size()) {
// Scrollen zur ausgewählten Zeile
lstContentListView.scrollTo(currentIndex);
// CSS-Stil nur auf die Zellen der ausgewählten Zeile anwenden
String selectedRowStyle = "-fx-control-inner-background: red;";
int finalCurrentIndex = currentIndex;
lstContentListView.setCellFactory(column -> {
return new ListCell<String>() {
@Override
protected void updateItem(String item, boolean empty) {
super.updateItem(item, empty);
setText(item);
if (getIndex() == finalCurrentIndex) {
setStyle(selectedRowStyle);
} else {
setStyle(""); // Zurücksetzen des Stils für andere Zellen
}
}
};
});
// Befehle ausführen
Commands.decode(prog[DataRegister.getPC()]);
DataRegister.increasePC();
Table.refresh();
Stage stage = (Stage) autoRunButton.getScene().getWindow();
CreateWindow.refreshTable(stage);
try {
Thread.sleep(500); // Millisekunden
} catch (InterruptedException e) {
e.printStackTrace();
}
currentIndex++;
}
// Wenn das Ende der Datei erreicht ist, zeige eine Meldung an
System.out.println("End of file reached.");
}
@FXML
private void stepintoButton(ActionEvent event) throws IOException {
if (lstContentListView.getItems().isEmpty()) {
// Datei ist nicht geladen oder leer
return;
}
// Aktuelle Zeile abrufen
int currentIndex = lstContentListView.getSelectionModel().getSelectedIndex();
// Wenn keine Zeile ausgewählt ist, starte von der ersten Zeile
if (currentIndex == -1) {
currentIndex = 1;
} else {
// Gehe zur nächsten Zeile
currentIndex++;
}
// Überprüfen, ob currentIndex innerhalb der Grenzen liegt
if (currentIndex >= lstContentListView.getItems().size()) {
// Wenn das Ende der Datei erreicht ist, zeige eine Meldung an
System.out.println("End of file reached.");
return;
}
// Scrollen zur ausgewählten Zeile
lstContentListView.scrollTo(currentIndex);
// Zeile auswählen
lstContentListView.getSelectionModel().clearSelection();
lstContentListView.getSelectionModel().select(currentIndex);
String selectedRowStyle = "-fx-control-inner-background: red;";
int finalCurrentIndex = currentIndex + 1;
lstContentListView.setCellFactory(column -> {
return new ListCell<String>() {
@Override
protected void updateItem(String item, boolean empty) {
super.updateItem(item, empty);
setText(item);
if (getIndex() == finalCurrentIndex) {
setStyle(selectedRowStyle);
} else {
setStyle("");
}
}
};
});
// Befehle ausführen
Commands.decode(prog[DataRegister.getPC()]);
DataRegister.increasePC();
Table.refresh();
Stage stage = (Stage) stepintoButton.getScene().getWindow();
IOPorts.refreshUI(getTRISbuttons(), getPORTbuttons());
CreateWindow.refreshTable(stage);
}
@ -90,18 +207,47 @@ public class Controller_Frontend {
@FXML
private void displayLSTFileContent(File selectedFile) {
try (BufferedReader reader = new BufferedReader(new FileReader(selectedFile))) {
StringBuilder content = new StringBuilder();
ObservableList<String> contentList = FXCollections.observableArrayList();
String line;
while ((line = reader.readLine()) != null) {
content.append(line).append("\n");
contentList.add(line);
}
lstContentLabel.setText(content.toString());
}
catch (IOException e) {
lstContentListView.setItems(contentList);
} catch (IOException e) {
e.printStackTrace();
}
}
@FXML
private void stepThroughFile(ActionEvent event) {
if (lstContentListView.getItems().isEmpty()) {
// Datei ist nicht geladen oder leer
return;
}
// Aktuelle Zeile abrufen
int currentIndex = lstContentListView.getSelectionModel().getSelectedIndex();
// Wenn keine Zeile ausgewählt ist, starte von der ersten Zeile
if (currentIndex == -1) {
currentIndex = 1;
} else {
// Gehe zur nächsten Zeile
currentIndex++;
}
// Überprüfen, ob currentIndex innerhalb der Grenzen liegt
if (currentIndex >= lstContentListView.getItems().size()) {
// Wenn das Ende der Datei erreicht ist, zeige eine Meldung an
System.out.println("End of file reached.");
return;
}
// Zeile auswählen und anzeigen
lstContentListView.getSelectionModel().select(currentIndex + 1);
lstContentListView.scrollTo(currentIndex + 1);
}
@FXML
private ToggleButtonGroup bgTRISA0;
@FXML
@ -179,6 +325,10 @@ public class Controller_Frontend {
}
setTRISbuttons(allTRISButtons);
setPORTbuttons(allPORTButtons);
lstContentListView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
lstContentListView.getStylesheets().add(Objects.requireNonNull(getClass().getResource("styles.css")).toExternalForm());
}
private static void setTRISbuttons(ToggleButtonGroup[] allButtons) {

View File

@ -0,0 +1,4 @@
.list-cell:selected {
-fx-background-color: yellow;
}

View File

@ -19,11 +19,15 @@
<?import javafx.scene.text.Font?>
<?import javafx.scene.text.Text?>
<AnchorPane xmlns="http://javafx.com/javafx/21" xmlns:fx="http://javafx.com/fxml/1" fx:controller="fabrik.simulator.pic16f84.Controller_Frontend">
<?import javafx.scene.control.ListView?>
<AnchorPane xmlns="http://javafx.com/javafx/21" xmlns:fx="http://javafx.com/fxml/1" fx:controller="fabrik.simulator.pic16f84.Controller_Frontend" stylesheets="styles.css">
<ListView fx:id="lstContentListView" prefHeight="400.0" prefWidth="600.0" />
<children>
<TextArea fx:id="lstContentLabel" editable="false" layoutX="41.0" layoutY="128.0" prefHeight="653.0" prefWidth="758.0" wrapText="true" />
<Button fx:id="stepintoButton" layoutX="42.0" layoutY="78.0" mnemonicParsing="false" onAction="#stepintoButton" text="Step IN" />
<Button fx:id="stepintoButton" layoutX="42.0" layoutY="478.0" mnemonicParsing="false" onAction="#stepintoButton" text="Step IN" />
<Button fx:id="autoRunButton" layoutX="182.0" layoutY="478.0" text="Auto Run" onAction="#autoRun"/>
<HBox layoutX="807.0" layoutY="134.0" prefHeight="293.0" prefWidth="701.0">
<children>
<GridPane alignment="CENTER" gridLinesVisible="true" prefHeight="273.0" prefWidth="687.0">

View File

@ -0,0 +1,4 @@
.list-cell:selected {
-fx-background-color: red;
}