Skip to content

Commit

Permalink
[feat] Änderungen für AnalyseClient (#33)
Browse files Browse the repository at this point in the history
* [feat] getter in TrialData

* [fix] datetime

* [fix] startTime can be null

* [feat] AbsScene und Log hinzugefügt

* [fix] stage

* [fix] resourcs directory name

* [fix] controller name

* [fix] log size

Co-authored-by: TheDarkDesync <82680013+TheDarkDesync@users.noreply.github.com>
  • Loading branch information
joshuajeschek and philipkbh authored Jan 16, 2022
1 parent a620961 commit 4a29e46
Show file tree
Hide file tree
Showing 8 changed files with 371 additions and 2 deletions.
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@
<artifactId>javafx-controls</artifactId>
<version>17</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>17</version>
</dependency>

</dependencies>

Expand Down
19 changes: 18 additions & 1 deletion src/main/java/github/weichware10/util/data/TrialData.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
* @since v0.2
*/
public class TrialData {

public final ToolType toolType;
public final String trialId;
public final String configId;
Expand Down Expand Up @@ -109,6 +110,22 @@ public void setAnswer(String answer) {
this.answer = answer;
}

public ToolType getToolType() {
return toolType;
}

public String getTrialId() {
return trialId;
}

public String getConfigId() {
return configId;
}

public DateTime getStartTime() {
return startTime;
}

/**
* Add a DataPoint for CodeCharts.
*
Expand Down Expand Up @@ -224,7 +241,7 @@ public String toString() {
toolType.toString(),
trialId,
configId,
startTime.toString(),
startTime != null ? startTime.toString() : "null",
answer,
dataPoints.size());
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/github/weichware10/util/db/Trials.java
Original file line number Diff line number Diff line change
Expand Up @@ -332,11 +332,12 @@ public List<TrialData> getList(String configId, ToolType toolType,
st = conn.createStatement();
rs = st.executeQuery(query);
while (rs.next()) {
Timestamp ts = rs.getTimestamp("starttime");
TrialData td = new TrialData(
ToolType.valueOf(rs.getString("tooltype")),
rs.getString("trialid"),
rs.getString("configid"),
new DateTime(rs.getTimestamp("starttime")),
ts != null ? new DateTime(ts) : null,
rs.getString("answer"),
Arrays.asList()); // leere Liste

Expand Down
111 changes: 111 additions & 0 deletions src/main/java/github/weichware10/util/gui/AbsScene.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
package github.weichware10.util.gui;

import github.weichware10.util.Logger;
import java.net.URL;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.MenuBar;
import javafx.scene.image.Image;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;

/**
* Abstrakte Klasse, von der alle Szenen erben. Diese Klasse lädt vorallem FXML-Dateien.
*/
public abstract class AbsScene {

/**
* lädt die Szene intern und gibt die root-Instanz zurück.
*
* @param fxml - URL der FXML-Datei
* @return das geladene Parent Objekt und die Controller-Instanz.
*/
protected static InitResult initialize(URL fxml) {

FXMLLoader loader = new FXMLLoader(fxml);

Parent root = null;
try {
root = loader.load();
} catch (Exception e) {
Logger.error("Error when loading " + fxml, e, true);
System.exit(-1);
}

AbsSceneController controller = loader.getController();

return new InitResult(root, controller);
}

/**
* Setzt die MenuBar, falls das in initialize geladene root-Objekt BorderPane ist.
*
* @param menuBar - die zu setzende Menüleiste
*/
public static void setMenuBar(MenuBar menuBar, Parent root) {
if (root != null && root instanceof BorderPane) {
BorderPane borderPane = (BorderPane) root;
borderPane.setTop(menuBar);
}
}

/**
* Zeigt die Szene an.
*
* @param primaryStage - das Hauptfenster
* @return das Initialisierungsergebniss
*/
public static InitResult start(Stage primaryStage, URL fxml, Parent root,
AbsSceneController controller, String title, MenuBar menuBar,
Integer width, Integer height, String icon) {
if (primaryStage == null || title == null || fxml == null) {
throw new NullPointerException(
String.format("Stage primaryStage (%s), ",
(primaryStage != null) ? primaryStage.toString() : "null")
+ String.format("String title (%s), ",
(title != null) ? title : "null")
+ String.format("and URL fxml (%s) are required",
(fxml != null) ? fxml.toString() : "null"));
}
if (root == null) {
InitResult ir = initialize(fxml);
root = ir.root;
controller = ir.controller;
}
// Menüleiste setzen
if (menuBar != null) {
setMenuBar(menuBar, root);
}
// Größe einstellen
if (width != null && height != null) {
primaryStage.setWidth(width);
primaryStage.setHeight(height);
}
// auf primaryStage setzen
Scene existingScene = root.getScene();
if (existingScene != null) {
primaryStage.setScene(existingScene);
} else {
primaryStage.setScene(new Scene(root));
}
if (icon != null) {
primaryStage.getIcons().add(new Image(icon));
}
primaryStage.setTitle(title);
return new InitResult(root, controller);
}

/**
* root und controller des Lade-Vorgangs.
*/
public static class InitResult {
public final Parent root;
public final AbsSceneController controller;

protected InitResult(Parent root, AbsSceneController controller) {
this.root = root;
this.controller = controller;
}
}
}
21 changes: 21 additions & 0 deletions src/main/java/github/weichware10/util/gui/AbsSceneController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package github.weichware10.util.gui;

import java.net.URL;
import java.util.ResourceBundle;
import javafx.fxml.FXML;


/**
* abstrakte Klasse für Controller-Klassen.
*/
public abstract class AbsSceneController {

@FXML
protected ResourceBundle resources;
@FXML
protected URL location;

@FXML
protected abstract void initialize();

}
87 changes: 87 additions & 0 deletions src/main/java/github/weichware10/util/gui/Log.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package github.weichware10.util.gui;

import github.weichware10.util.Logger;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.value.ObservableBooleanValue;
import javafx.scene.Parent;
import javafx.stage.Stage;

/**
* Dialog zum Darstellen der Log Infos.
*/
public class Log extends AbsScene {

private static Stage logStage;
private static Parent root;

private static SimpleBooleanProperty visibleProperty = new SimpleBooleanProperty(false);
public static ObservableBooleanValue visible = visibleProperty;

/**
* Startet das Log.
*/
public static void start(String icon) {
Integer width = null;
Integer height = null;
if (logStage == null) {
logStage = new Stage();
width = 750;
height = 500;
}
root = start(logStage,
Log.class.getResource("Log.fxml"),
root,
null,
"Toolbox - Log",
null,
width,
height,
icon).root;
}

public static boolean isVisible() {
return visible.get();
}

public static void show() {
logStage.show();
visibleProperty.set(true);
}

public static void hide() {
logStage.hide();
visibleProperty.set(false);
}

public static void close() {
logStage.close();
}

/**
* Loggt den Inhalt (falls vorhanden) mit dem gegebenen Typ.
*
* @param content - zu loggender Inhalt
* @param type - "DEBUG", "INFO", "WARN" oder "ERROR"
*/
public static void log(String content, String type) {
if (content.length() == 0) {
return;
}
switch (type) {
case "DEBUG":
Logger.debug(content);
break;
case "INFO":
Logger.info(content);
break;
case "WARN":
Logger.warn(content);
break;
case "ERROR":
Logger.error(content);
break;
default:
break;
}
}
}
75 changes: 75 additions & 0 deletions src/main/java/github/weichware10/util/gui/LogController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package github.weichware10.util.gui;

import github.weichware10.util.Logger;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.MenuButton;
import javafx.scene.control.MenuItem;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import javafx.scene.layout.Pane;

/**
* Controller für {@link Log}.
*/
public class LogController extends AbsSceneController {

@FXML
private ResourceBundle resources;
@FXML
private URL location;


@FXML
private TextField logInput;
@FXML
private TextArea logArea;
@FXML
private Pane logPane;
@FXML
private MenuButton logMenuButton;

@FXML
protected void initialize() {
assert logArea != null
: "fx:id=\"logArea\" not injected: check 'Log.fxml'.";
assert logPane != null
: "fx:id=\"logPane\" not injected: check 'Log.fxml'.";
assert logInput != null
: "fx:id=\"logInput\" not injected: check 'Log.fxml'.";
assert logMenuButton != null
: "fx:id=\"logMenuButton\" not injected: check 'Log.fxml'.";
logArea.minHeightProperty().bind(logPane.heightProperty());
logArea.minWidthProperty().bind(logPane.widthProperty());
Logger.setLogArea(logArea);
}

@FXML
void setLogType(ActionEvent event) {
Logger.info("log:content Setting log type");
// mit try/catch, da Abfrage nach Klasse von event.getSource() nicht gut funktioniert
try {
MenuItem type = (MenuItem) event.getSource();
logMenuButton.setText(type.getText());
} catch (Exception e) {
Logger.error("an error occured while changing the log type");
}
}

@FXML
void inputKeyPress(KeyEvent event) {
if (event.getCode() == KeyCode.ENTER) {
log();
}
}

@FXML
void log() {
Log.log(logInput.getText(), logMenuButton.getText());
logInput.clear();
}
}
Loading

0 comments on commit 4a29e46

Please sign in to comment.