Commit b764976f authored by Maria Barbatei's avatar Maria Barbatei

Adding current state of the refactorized GUI class

parent 3376e854
Pipeline #2879 skipped
package org.uebung7.gui;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import javafx.application.Application;
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;
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 javafx.scene.control.ComboBox;
@SuppressWarnings("restriction")
public class Uebung7GUI1 extends Application {
public static final int WIDTH_BORDERPANE = 800;
public static final int HEIGHT_BORDERPANE = 600;
public static final int HBOX_DIMENSION = 20;
public static final int VBOX_DIMENSION = 10;
public static Insets standardDimensions = new Insets(15, 12, 15, 12);
public static final String ARZTBRIEF_AUSWAEHLEN = "Arztbrief auswählen:";
public static final String SEARCH = "Durchsuchen";
public static final String ARZTBRIEF_ANALYSIEREN = "Arztbrief analysieren";
public static final String DIAGNOSEN_EXPORTIEREN = "Diagnosen als JSON exportieren";
public static final String HOCHGELADEN = " wurde hochgeladen.";
public static final String FENSTER_TITEL = "Uebungsblatt 7 + 8";
public static final String GEFUNDENE_DIAGNOSE = "Gefundene Diagnose";
private static String arztBriefName = "";
private static HBox topHBoxForUploadingArztBrief = null;
private static TreeView<String> tree;
private static TreeItem<String> root = new TreeItem<String>();
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) throws Exception {
// declaration and instantiations
BorderPane borderPane = new BorderPane();
Button buttonUploadBrief = new Button(SEARCH);
Button buttonAnalyzeBrief = new Button(ARZTBRIEF_ANALYSIEREN);
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 leftVBox = createLeftVBox();
HBox buttomHBox = createButtomHBox(buttonExportDiagnosenAsJson);
uploadFileToBeAnalyzed(buttonUploadBrief, fileChooser, primaryStage, comboBoxForArztbriefPath);
testMethodForShowingAlertDialog(buttonAnalyzeBrief);
primaryStage.setTitle(FENSTER_TITEL);
primaryStage.setScene(new Scene(borderPane, WIDTH_BORDERPANE, HEIGHT_BORDERPANE));
borderPane.setTop(topVBox);
borderPane.setLeft(leftVBox);
borderPane.setBottom(buttomHBox);
// display box
primaryStage.show();
}
public static void testMethodForShowingAlertDialog(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.");
}
});
}
/**
* Methode benutzt zum Hochladen eines Arztbriefes.
*
* @param buttonUploadBrief
* @param fileChooser
* @param primaryStage
*/
public static void uploadFileToBeAnalyzed(Button buttonUploadBrief, FileChooser fileChooser, Stage primaryStage, ComboBox<String > comboBoxForArztbriefPath) {
buttonUploadBrief.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
configureFileChooser(fileChooser);
File file = fileChooser.showOpenDialog(primaryStage);
if (file != null) {
comboBoxForArztbriefPath.getItems().addAll(
file.getPath()
);
comboBoxForArztbriefPath.setValue(file.getPath());
}
}
});
}
/**
* Creates a VBox for the upload & analyze button
*
* @return vBox
*/
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);
topHBoxForAnalyzeButton.getChildren().add(buttonAnalyzeBrief);
topVBoxForBothButtons.getChildren().addAll(topHBoxForUploadingArztBrief, topHBoxForAnalyzeButton);
return topVBoxForBothButtons;
}
/**
* Creates a HBox for the export button
*
* @return hBox
*/
public static HBox createButtomHBox(Button buttonExportDiagnosenAsJson) {
HBox buttomHBoxForExportButton = new HBox(HBOX_DIMENSION);
buttomHBoxForExportButton.setPadding(standardDimensions);
buttomHBoxForExportButton.getChildren().add(buttonExportDiagnosenAsJson);
return buttomHBoxForExportButton;
}
/**
* Create left VBox where the found diagnoses will be displayed in tree
* form.
*
* @return
*/
public static VBox createLeftVBox() {
VBox leftVBox = new VBox();
leftVBox.setPadding(standardDimensions);
Label foundDiagnose = new Label(GEFUNDENE_DIAGNOSE);
leftVBox.getChildren().addAll(foundDiagnose, tree);
return leftVBox;
}
/**
* Helper method used in order to successfully open a file
*
* @param fileChooser
*/
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"));
}
/**
* Helper method used in order to create the tree view
*
*/
public static void treeViewUtils() {
root.setExpanded(true);
tree = new TreeView<>(root);
tree.getSelectionModel().selectedItemProperty().addListener((v, oldValue, newValue) -> {
if (newValue != null)
System.out.println(newValue.getValue());
});
}
}
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