Commit 09910ceb authored by Maria Barbatei's avatar Maria Barbatei

Moved Uebung7GUI1 in package uebung7.fin.gui

parent b764976f
Pipeline #2880 skipped
package org.uebung7.gui;
package uebung7.fin.gui;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.io.FileWriter;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.application.Application;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.Alert;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TreeItem;
......@@ -19,12 +21,12 @@ import javafx.scene.control.TreeView;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.text.Text;
import javafx.stage.FileChooser;
import javafx.stage.Stage;
import uebung7.fin.medReader.DBSearch;
import uebung7.fin.medReader.MedReportSplitter;
import javafx.scene.control.ComboBox;
@SuppressWarnings("restriction")
public class Uebung7GUI1 extends Application {
public static final int WIDTH_BORDERPANE = 800;
......@@ -49,7 +51,9 @@ public class Uebung7GUI1 extends Application {
private static TreeItem<String> root = new TreeItem<String>();
public static void main(String[] args) {
DBSearch.initDB(); // Initialize Hibernate
launch(args);
System.out.println("DBG: startGUI.java: running");
}
@Override
......@@ -61,19 +65,21 @@ public class Uebung7GUI1 extends Application {
Button buttonExportDiagnosenAsJson = new Button(DIAGNOSEN_EXPORTIEREN);
Label arztbriefAuswahlLbl = new Label(ARZTBRIEF_AUSWAEHLEN);
ComboBox<String> comboBoxForArztbriefPath = new ComboBox<String>();
final FileChooser fileChooser = new FileChooser();
treeViewUtils();
VBox topVBox = createTopVBox(buttonUploadBrief, buttonAnalyzeBrief, arztbriefAuswahlLbl, comboBoxForArztbriefPath);
VBox topVBox = createTopVBox(buttonUploadBrief, buttonAnalyzeBrief, arztbriefAuswahlLbl,
comboBoxForArztbriefPath);
VBox leftVBox = createLeftVBox();
HBox buttomHBox = createButtomHBox(buttonExportDiagnosenAsJson);
uploadFileToBeAnalyzed(buttonUploadBrief, fileChooser, primaryStage, comboBoxForArztbriefPath);
testMethodForShowingAlertDialog(buttonAnalyzeBrief);
analayzeArztbrief(buttonAnalyzeBrief);
exportDiagnoseAsJSONFile(buttonExportDiagnosenAsJson, primaryStage);
primaryStage.setTitle(FENSTER_TITEL);
primaryStage.setScene(new Scene(borderPane, WIDTH_BORDERPANE, HEIGHT_BORDERPANE));
......@@ -81,24 +87,55 @@ public class Uebung7GUI1 extends Application {
borderPane.setLeft(leftVBox);
borderPane.setBottom(buttomHBox);
// display box
primaryStage.show();
}
public static void testMethodForShowingAlertDialog(Button buttonAnalyzeBrief) {
public static void analayzeArztbrief(Button buttonAnalyzeBrief) {
buttonAnalyzeBrief.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
Alert alert = new Alert(AlertType.CONFIRMATION);
alert.setTitle("Mehrere Diagnosen wurden gefunden!");
alert.setHeaderText("Bitte waehlen Sie die gewuenschte Diagnose aus!");
alert.show();
// alert.setContentText("Choose your option.");
public void handle(final ActionEvent e) {
// Arztbrief ans Backend übergeben, wenn Auswahl getroffen wurde
// String arztbrief = Ausgewählter Pfad
if (arztBriefName == "") {
System.out.println("ERROR: startGUI.java - Bitte Datei auswählen!");
} else {
try {
// create new MedReportSplitter
// DEBUG:
MedReportSplitter reportSplit = new MedReportSplitter("Arztbrief1.txt");
// For FINAL VER
// MedReportSplitter reportSplit = new
// MedReportSplitter(arztbrief);
DBSearch search = new DBSearch(reportSplit.getDiagnosen());
// Get Diags found from Backend
System.out.println("DBG: startGUI.java Diagnosen Return: " + search.getDiagnosisList());
// ToDO: GUI: Selection of Diag etc...
} catch (IOException e1) {
// Error reading the file:
System.out.println("ERROR: startGUI.java - Datei konnte nicht geöffnet werden!");
}
}
}
// @Override
// public void handle(ActionEvent event) {
// Alert alert = new Alert(AlertType.CONFIRMATION);
// alert.setTitle("Mehrere Diagnosen wurden gefunden!");
// alert.setHeaderText("Bitte waehlen Sie die gewuenschte Diagnose
// aus!");
// alert.show();
// // alert.setContentText("Choose your option.");
// }
//
});
}
......@@ -109,7 +146,8 @@ public class Uebung7GUI1 extends Application {
* @param fileChooser
* @param primaryStage
*/
public static void uploadFileToBeAnalyzed(Button buttonUploadBrief, FileChooser fileChooser, Stage primaryStage, ComboBox<String > comboBoxForArztbriefPath) {
public static void uploadFileToBeAnalyzed(Button buttonUploadBrief, FileChooser fileChooser, Stage primaryStage,
ComboBox<String> comboBoxForArztbriefPath) {
buttonUploadBrief.setOnAction(new EventHandler<ActionEvent>() {
@Override
......@@ -117,9 +155,7 @@ public class Uebung7GUI1 extends Application {
configureFileChooser(fileChooser);
File file = fileChooser.showOpenDialog(primaryStage);
if (file != null) {
comboBoxForArztbriefPath.getItems().addAll(
file.getPath()
);
comboBoxForArztbriefPath.getItems().addAll(file.getPath());
comboBoxForArztbriefPath.setValue(file.getPath());
}
}
......@@ -127,24 +163,57 @@ public class Uebung7GUI1 extends Application {
});
}
public static void exportDiagnoseAsJSONFile(Button buttonExportDiagnosenAsJson, Stage primaryStage) {
buttonExportDiagnosenAsJson.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);
}
}
});
}
/**
* Creates a VBox for the upload & analyze button
*
* @return vBox
*/
public static VBox createTopVBox(Button buttonUploadBrief, Button buttonAnalyzeBrief,
Label arztbriefAuswahlLbl, ComboBox<String> comboBoxForArztbriefPath) {
public static VBox createTopVBox(Button buttonUploadBrief, Button buttonAnalyzeBrief, Label arztbriefAuswahlLbl,
ComboBox<String> comboBoxForArztbriefPath) {
topHBoxForUploadingArztBrief = new HBox(HBOX_DIMENSION);
HBox topHBoxForAnalyzeButton = new HBox(HBOX_DIMENSION);
VBox topVBoxForBothButtons = new VBox(VBOX_DIMENSION);
topHBoxForUploadingArztBrief.setPadding(standardDimensions);
topHBoxForAnalyzeButton.setPadding(standardDimensions);
comboBoxForArztbriefPath.setMaxWidth(WIDTH_BORDERPANE*0.6);
comboBoxForArztbriefPath.setMinWidth(HEIGHT_BORDERPANE*0.6);
topHBoxForUploadingArztBrief.getChildren().addAll(arztbriefAuswahlLbl, comboBoxForArztbriefPath, buttonUploadBrief);
comboBoxForArztbriefPath.setMaxWidth(WIDTH_BORDERPANE * 0.6);
comboBoxForArztbriefPath.setMinWidth(HEIGHT_BORDERPANE * 0.6);
comboBoxForArztbriefPath.valueProperty().addListener(new ChangeListener<String>() {
@Override
public void changed(ObservableValue ov, String t, String t1) {
arztBriefName = t1;
}
});
topHBoxForUploadingArztBrief.getChildren().addAll(arztbriefAuswahlLbl, comboBoxForArztbriefPath,
buttonUploadBrief);
topHBoxForAnalyzeButton.getChildren().add(buttonAnalyzeBrief);
topVBoxForBothButtons.getChildren().addAll(topHBoxForUploadingArztBrief, topHBoxForAnalyzeButton);
......@@ -188,8 +257,7 @@ public class Uebung7GUI1 extends Application {
private static void configureFileChooser(final FileChooser fileChooser) {
fileChooser.setTitle(ARZTBRIEF_AUSWAEHLEN);
fileChooser.setInitialDirectory(new File(System.getProperty("user.home")));
fileChooser.getExtensionFilters().add(
new FileChooser.ExtensionFilter("Textdokumente (.txt)", "*.txt"));
fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("Textdokumente (.txt)", "*.txt"));
}
/**
......@@ -206,4 +274,21 @@ public class Uebung7GUI1 extends Application {
});
}
public static 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(Uebung7GUI1.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
package uebung7.fin;
import uebung7.fin.medReader.*;
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 startGUI 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();
/** Main method:
* Launch Backend => Create Index
* Launch Frontend
* **/
public static void main(String[] args) {
DBSearch.initDB(); // Initialize Hibernate
launch(); // Comment to turn off Frontend
/* BackendDBG:
MedReportSplitter reportSplit = null;
try {
reportSplit = new MedReportSplitter("Arztbrief1.txt");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
DBSearch search = new DBSearch(reportSplit.getDiagnosen());
*/
//DEBUG
System.out.println("DBG: startGUI.java: running");
}
@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, wenn Auswahl getroffen wurde
// String arztbrief = Ausgewählter Pfad
if (arztbrief == "")
{System.out.println("ERROR: startGUI.java - Bitte Datei auswählen!");
}
else {
try {
// create new MedReportSplitter
// DEBUG:
MedReportSplitter reportSplit = new MedReportSplitter("Arztbrief1.txt");
// For FINAL VER
// MedReportSplitter reportSplit = new MedReportSplitter(arztbrief);
DBSearch search = new DBSearch(reportSplit.getDiagnosen());
// Get Diags found from Backend
System.out.println("DBG: startGUI.java Diagnosen Return: " + search.getDiagnosisList());
// ToDO: GUI: Selection of Diag etc...
} catch (IOException e1) {
// Error reading the file:
System.out.println("ERROR: startGUI.java - Datei konnte nicht geöffnet werden!");
}
}
}
});
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(startGUI.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;
}
}
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