Commit 34621ab4 authored by pudi9346's avatar pudi9346

copying Uebung7Gui.java to TWI.gruppe2/src/main/java/org/uebung7/gui

parent 76236008
Pipeline #2834 skipped
package org.uebung7.gui;
/*
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
......@@ -15,6 +15,7 @@ import javafx.geometry.Pos;
* @author mariabarbatei
*
*/
/*
@SuppressWarnings("restriction")
public class Uebung7Gui extends Application implements EventHandler<ActionEvent> {
......@@ -57,4 +58,309 @@ public class Uebung7Gui extends Application implements EventHandler<ActionEvent>
}
*/
import java.util.Scanner;
import javafx.application.Application;
import java.awt.Desktop;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.event.EventHandler;
import javafx.event.ActionEvent;
import javafx.geometry.Insets;
import javafx.geometry.Orientation;
import javafx.geometry.Pos;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import javafx.scene.input.MouseEvent;
import javafx.scene.Scene;
import javafx.scene.control.*;
/*import javafx.scene.control.Label;
import javafx.scene.control.ScrollBar;
import javafx.scene.control.TextField;
import javafx.scene.control.TreeItem;
import javafx.scene.control.TreeView;*/
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.stage.DirectoryChooser;
import javafx.stage.FileChooser;
import javafx.stage.Stage;
import javafx.scene.text.Text;
/**
*
*/
@SuppressWarnings("restriction")
public class Uebung7Gui extends Application {
// Für den einfach Zugriff mit statischen globalen Variablen gelöst
static TextField centertextfield = new TextField();
TreeView<String> tree;
static TreeItem<String> root = new TreeItem<String>();
static TreeItem<String> tmp_id = new TreeItem<String>();
static TreeItem<String> tmp_prop = new TreeItem<String>();
private String arztbrief = "";
private Desktop desktop = Desktop.getDesktop();
public static void main( String[] args )
{
launch(args); // Für das Window
// Surpress logging via log4J
org.apache.log4j.Logger.getRootLogger().setLevel(org.apache.log4j.Level.OFF);
}
@Override
public void start(Stage primaryStage) {
//Root von vornherein ausgeklappt darstellen
root.setExpanded(true);
//Baum erstellen und Wurzel verstecken
tree = new TreeView<>(root);
tree.setShowRoot(false);
//Baum interaktiv gestalten (Blätter können angegklickt werden)
tree.getSelectionModel().selectedItemProperty()
.addListener((v, oldValue, newValue) -> {
if (newValue != null)
// Aktion beim Ankicken des jeweiligen Blattes
System.out.println(newValue.getValue()); // Zum Testen Value des Blatts ausgeben
});
// Allgemeines
primaryStage.setTitle("Übungsblatt 7+8 - Gruppe 2"); // Titel des Windows
BorderPane bp = new BorderPane(); // BorderPane initialisieren
bp.setPadding(new Insets(10, 20, 10, 20));
final FileChooser fileChooser = new FileChooser();
final Button btnBrowse = new Button("Durchsuchen");
final Button btnJSON = new Button("Als JSON exportieren");
final Button btnAnalyze = new Button("Analysieren");
final ComboBox pfadComboBox = new ComboBox();
pfadComboBox.setEditable(true);
pfadComboBox.valueProperty().addListener(new ChangeListener<String>() {
@Override
public void changed(ObservableValue ov, String t, String t1) {
arztbrief = t1;
}
});
btnBrowse.setOnAction(
new EventHandler<ActionEvent>() {
@Override
public void handle(final ActionEvent e) {
configureFileChooser(fileChooser);
File file = fileChooser.showOpenDialog(primaryStage);
if (file != null) {
pfadComboBox.getItems().addAll(
file.getPath()
);
pfadComboBox.setValue(file.getPath());
}
}
});
btnAnalyze.setOnAction(
new EventHandler<ActionEvent>() {
@Override
public void handle(final ActionEvent e) {
//Arztbrief ans Backend übergeben
System.out.println(arztbrief);
}
});
btnJSON.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
FileChooser fileChooser = new FileChooser();
fileChooser.setInitialDirectory(
new File(System.getProperty("user.home"))
);
//Nur .json Dateien als Möglichkeit festlegen
FileChooser.ExtensionFilter extFilter = new FileChooser.ExtensionFilter("JSON-Dateien (*.json)", "*.json");
fileChooser.getExtensionFilters().add(extFilter);
//Speicherdialog anzeigen
File file = fileChooser.showSaveDialog(primaryStage);
if(file != null){
//Datei als JSON speichern
SaveFile(file);
}
}
});
// Elemente des TopPanes initialisieren
Insets standardabstand = new Insets (10, 10, 10, 10);
Label toplabel = new Label("Arztbrief auswählen:");
Label emptylabel = new Label("");
//toplabel.setPadding(standardabstand);
btnAnalyze.setAlignment(toplabel.getAlignment());
HBox topbox1 = new HBox(20);
topbox1.setPadding(standardabstand);
HBox topbox2 = new HBox(20);
topbox2.setPadding(standardabstand);
HBox topbox3 = new HBox(20);
topbox2.setPadding(standardabstand);
VBox main_topbox = new VBox(1);
topbox1.getChildren().setAll(toplabel, pfadComboBox, btnBrowse);
topbox2.getChildren().setAll(btnAnalyze);
topbox3.getChildren().setAll(emptylabel);
main_topbox.getChildren().setAll(topbox1, topbox2, topbox3);
bp.setTop(main_topbox);
// Elemente der TreeView (LeftPane) initialisieren
VBox leftbox = new VBox();
Label treelabel = new Label("Gefundene Diagnosen");
leftbox.getChildren().setAll(treelabel, tree);
bp.setLeft(leftbox);
// Elemente für Standardausgabe (CenterPane) in JSON initialisieren
VBox centerbox_main = new VBox();
Label centerlabel = new Label("Weitere Informationen zur Diagnose (wikidata zeugs)");
centertextfield.setPadding(new Insets(10, 10, 10, 10));
centertextfield.setPrefSize(510, 400);
centertextfield.setMaxSize(510, 400);
centertextfield.setEditable(false);
centerbox_main.getChildren().setAll(centerlabel, centertextfield);
centerbox_main.setTranslateX(55);
bp.setCenter(centerbox_main);
Scene scene = new Scene(bp, 900, 600);
primaryStage.setScene(scene);
primaryStage.show();
pfadComboBox.setMaxWidth(scene.getWidth()*0.6);
pfadComboBox.setMinWidth(scene.getWidth()*0.6);
//Elemente der BottomPane initialisieren
bp.setBottom(btnJSON);
}
/* handle wird aufgerufen sobald ein Button geklickt wird
@Override
public void handle(ActionEvent event) {
if (event.getSource() == btnJSON) {
}
}
*/
private static void configureFileChooser(
final FileChooser fileChooser) {
fileChooser.setTitle("Arztbrief auswählen");
fileChooser.setInitialDirectory(
new File(System.getProperty("user.home"))
);
fileChooser.getExtensionFilters().addAll(
//new FileChooser.ExtensionFilter("All Images", "*.*"),
new FileChooser.ExtensionFilter("Textdokumente (.txt)", "*.txt")
);
}
public static void CreateTree (String ID) {
// tmp beinhaltet immer die aktuelle ID zu der die Properties als Blätter hinzugefügt werden
tmp_id = makeBranch(ID, root);
}
public static void AddToTree (String ID ) {
tmp_prop = makeBranch(ID, tmp_id);
}
//Create branches
static public TreeItem<String> makeBranch(String title, TreeItem<String> parent) {
TreeItem<String> item = new TreeItem<>(title);
item.setExpanded(false);
parent.getChildren().add(item);
return item;
}
private void SaveFile(File file){
try {
FileWriter fileWriter = new FileWriter(file);
//TEST STRING!
String content = "GET JSON STRING VOM BACKEND_____";
fileWriter.write(content);
fileWriter.close();
} catch (IOException ex) {
Logger.getLogger(Uebung7Gui.class.getName()).log(Level.SEVERE, null, ex);
}
}
// GETTER-Methode um den ausgewählten Arztbrief ans Backend zu übergeben (als Pfad)
public String GetArztbrief () {
return arztbrief;
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment