File Selection

This commit is contained in:
2024-04-16 10:56:40 +02:00
parent 7725d27ecc
commit 5acaf6df16
9 changed files with 87 additions and 44 deletions

1
.gitignore vendored
View File

@ -36,3 +36,4 @@ build/
### Mac OS ###
.DS_Store
/.idea/

View File

@ -90,7 +90,7 @@
<!-- Default configuration for running with: mvn clean javafx:run -->
<id>default-cli</id>
<configuration>
<mainClass>fabrik.simulator.pic16f84/fabrik.simulator.pic16f84.HelloApplication</mainClass>
<mainClass>fabrik.simulator.pic16f84/fabrik.simulator.pic16f84.CreateWindow</mainClass>
<launcher>app</launcher>
<jlinkZipName>app</jlinkZipName>
<jlinkImageName>app</jlinkImageName>

View File

@ -7,12 +7,12 @@ import javafx.stage.Stage;
import java.io.IOException;
public class HelloApplication extends Application {
public class CreateWindow extends Application {
@Override
public void start(Stage stage) throws IOException {
FXMLLoader fxmlLoader = new FXMLLoader(HelloApplication.class.getResource("hello-view.fxml"));
Scene scene = new Scene(fxmlLoader.load(), 320, 240);
stage.setTitle("Hello!");
FXMLLoader fxmlLoader = new FXMLLoader(CreateWindow.class.getResource("FileSelector.fxml"));
Scene scene = new Scene(fxmlLoader.load(), 1200, 800);
stage.setTitle("PIC16F84-Simulator Datei auswählen");
stage.setScene(scene);
stage.show();
}

View File

@ -0,0 +1,36 @@
package fabrik.simulator.pic16f84;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.stage.FileChooser;
import javafx.stage.Stage;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
public class FileSelect {
@FXML
protected void selectFileLST(ActionEvent event) throws IOException {
FileChooser fileChooser = new FileChooser();
fileChooser.setTitle("Open LST File");
fileChooser.getExtensionFilters().addAll(
new FileChooser.ExtensionFilter("LST-Dateien", "*.LST", "*.lst"),
new FileChooser.ExtensionFilter("Alle Dateien", "*.*"));
File selectedFile = fileChooser.showOpenDialog(new Stage());
if (selectedFile != null) {
int [] prog = ParseFile.parseTestDatei(selectedFile.getAbsolutePath());
System.out.println(Arrays.toString(prog));
Stage stage = (Stage) ((Node) event.getSource()).getScene().getWindow();
FXMLLoader fxmlLoader = new FXMLLoader(CreateWindow.class.getResource("MainBody.fxml"));
Scene scene = new Scene(fxmlLoader.load(), 1200, 800);
stage.setTitle("PIC16F84-Simulator Hauptseite");
stage.setScene(scene);
stage.show();
}
}
}

View File

@ -0,0 +1,4 @@
package fabrik.simulator.pic16f84;
public class MainBody {
}

View File

@ -6,21 +6,7 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class stringTObefehl {
public static void main(String[] args) {
String dateiPfad = "C:\\CloudStation\\Eigene Daten\\DHBW-Studium\\Simulator_git\\src\\main\\java\\fabrik\\simulator\\pic16f84\\TPicSim1.LST"; // Pfad zur Testdatei ---> hier musst du deine Variable einfügen Paul
int[] programmspeicher = parseTestDatei(dateiPfad);
// Programmspeicher
System.out.println("Programmspeicher wird ausgegebene:");
for (int i = 0; i < programmspeicher.length; i++) {
if (programmspeicher[i] != 0) {
System.out.printf("0x%04X: 0x%04X%n", i, programmspeicher[i]);
}
}
}
public class ParseFile {
public static int[] parseTestDatei(String dateiPfad) {
List<String> zeilen = new ArrayList<>();
@ -36,12 +22,12 @@ public class stringTObefehl {
}
// Initialisierung des Programmspeichers mit 1024 Speicherplätzen
int[] programmspeicher = new int[1024]; // Wie viele Programmspeicherplätze gibt es? --> 1024
int[] programmspeicher = new int[1024]; // Wie viele Programmspeicherplätze gibt es? 1024
// Adresse und Befehle werden ignoriert und nur die Befehle werden in den Programmspeicher gespeichert
for (String zeile : zeilen) {
String[] teile = zeile.split("\\s+"); // Spaltenweise werden die einzelnen Befehle getrennen
String[] teile = zeile.split("\\s+"); // Spaltenweise werden die einzelnen Befehle getrennt
if (teile.length >= 2) {
try {
int adresse = Integer.parseInt(teile[0], 16); // Adresse in Hexadezimal umwandeln
@ -52,9 +38,8 @@ public class stringTObefehl {
programmspeicher[adresse] = befehl; // Befehl im Programmspeicher speichern
} catch (NumberFormatException e) {
// Wenn ein Fehler aufkommt wird diese Zeile ignoriert funktioniert
// Wenn ein Fehler aufkommt, wird diese Zeile ignoriert funktioniert
System.err.println("Fehler beim Parsen einer Zeile: " + zeile);
continue;
}
}
}

View File

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<AnchorPane prefHeight="500.0" prefWidth="500.0" xmlns="http://javafx.com/javafx/17.0.2-ea"
xmlns:fx="http://javafx.com/fxml/1" fx:controller="fabrik.simulator.pic16f84.FileSelect">
<VBox alignment="CENTER" prefHeight="500.0" prefWidth="500.0" AnchorPane.bottomAnchor="0.0"
AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<Label text="Willkommen beim PIC-Simulator!" textAlignment="CENTER">
<padding>
<Insets bottom="10.0"/>
</padding>
<VBox.margin>
<Insets bottom="10.0"/>
</VBox.margin>
</Label>
<Button mnemonicParsing="false" onAction="#selectFileLST" text="Datei auswählen!"/>
</VBox>
</AnchorPane>

View File

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.*?>
<AnchorPane prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/17.0.2-ea" xmlns:fx="http://javafx.com/fxml/1" fx:controller="fabrik.simulator.pic16f84.MainBody">
<children>
<VBox alignment="CENTER" prefHeight="400.0" prefWidth="600.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<children>
<Text strokeType="OUTSIDE" strokeWidth="0.0" text="Hauptseite" />
</children>
</VBox>
</children>
</AnchorPane>

View File

@ -1,19 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<VBox alignment="CENTER" spacing="20.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/17.0.2-ea" fx:controller="fabrik.simulator.pic16f84.HelloController">
<padding>
<Insets bottom="20.0" left="20.0" right="20.0" top="20.0" />
</padding>
<TitledPane animated="false" text="untitled">
<content>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0" />
</content>
</TitledPane>
<Label fx:id="welcomeText" />
<Button onAction="#onHelloButtonClick" text="Hello!" />
</VBox>