-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[feat] Änderungen für AnalyseClient (#33)
* [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
1 parent
a620961
commit 4a29e46
Showing
8 changed files
with
371 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 111 additions & 0 deletions
111
src/main/java/github/weichware10/util/gui/AbsScene.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
21
src/main/java/github/weichware10/util/gui/AbsSceneController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
75
src/main/java/github/weichware10/util/gui/LogController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
Oops, something went wrong.