Skip to content

Commit 5d7ffe5

Browse files
joshuajeschekjustinexnerTheDarkDesync
committed
[feat] CodeChartsCoordinator Constructor
Co-authored-by: justinexner <justinexner@users.noreply.github.com> Co-authored-by: TheDarkDesync <TheDarkDesync@users.noreply.github.com>
1 parent a0b2798 commit 5d7ffe5

File tree

11 files changed

+123
-187
lines changed

11 files changed

+123
-187
lines changed

src/main/java/github/weichware10/toolbox/codecharts/CodeCharts.java

+12-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package github.weichware10.toolbox.codecharts;
22

33
import github.weichware10.toolbox.gui.End;
4+
import github.weichware10.toolbox.gui.dialogs.ImageNotFoundDialog;
45
import github.weichware10.util.Logger;
56
import github.weichware10.util.ToolType;
67
import github.weichware10.util.config.ConfigClient;
@@ -58,8 +59,17 @@ public CodeCharts(Stage primaryStage,
5859
Scene scene = new Scene(root, 300, 275);
5960
primaryStage.setScene(scene);
6061

61-
CodeChartsCoordinator coordinator = new CodeChartsCoordinator(configClient, trialData);
62-
int[] layoutGrid = coordinator.getDimensions();
62+
CodeChartsCoordinator coordinator = null;
63+
try {
64+
coordinator = new CodeChartsCoordinator(configClient, dataBaseClient, trialData,
65+
controller.getImageView(), controller.getStackPane());
66+
} catch (Exception e) {
67+
Logger.error("Error while loading image", e, false);
68+
primaryStage.close();
69+
new ImageNotFoundDialog().showImageNotFoundDialog(e);
70+
}
71+
coordinator.startTest();
72+
// endTest();
6373
}
6474

6575
/**

src/main/java/github/weichware10/toolbox/codecharts/CodeChartsBild.java

-15
This file was deleted.

src/main/java/github/weichware10/toolbox/codecharts/CodeChartsController.java

+6-14
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import github.weichware10.util.Logger;
44
import java.net.URL;
5-
import java.util.ArrayList;
65
import java.util.ResourceBundle;
76
import javafx.fxml.FXML;
87
import javafx.geometry.Rectangle2D;
@@ -36,16 +35,6 @@ void endTest() {
3635
codeCharts.endTest();
3736
}
3837

39-
40-
void setupTest() {
41-
double ratio = imageView.getImage().getWidth() / imageView.getImage().getHeight();
42-
double width = Math.min(imageView.getFitWidth(), imageView.getFitHeight() * ratio);
43-
double height = Math.min(imageView.getFitHeight(), imageView.getFitWidth() / ratio);
44-
CodeChartsPane ccPane = new CodeChartsPane(new ArrayList<>(), -1, -1, width, height);
45-
stackPane.getChildren().add(ccPane);
46-
ccPane.subdivide(5, 3);
47-
}
48-
4938
@FXML
5039
void initialize() {
5140
assert imageView != null
@@ -56,10 +45,13 @@ void initialize() {
5645
Rectangle2D screenBounds = Screen.getPrimary().getBounds();
5746
imageView.setFitWidth(screenBounds.getWidth() / 2);
5847
imageView.setFitHeight(screenBounds.getHeight() / 2);
48+
}
5949

60-
CodeChartsPane.defaultHorizontal = 2;
61-
CodeChartsPane.defaultVertical = 2;
50+
public ImageView getImageView() {
51+
return imageView;
52+
}
6253

63-
setupTest();
54+
public StackPane getStackPane() {
55+
return stackPane;
6456
}
6557
}
Original file line numberDiff line numberDiff line change
@@ -1,98 +1,91 @@
11
package github.weichware10.toolbox.codecharts;
22

3+
import github.weichware10.toolbox.Util;
4+
import github.weichware10.util.config.CodeChartsConfiguration;
35
import github.weichware10.util.config.ConfigClient;
46
import github.weichware10.util.data.TrialData;
7+
import github.weichware10.util.db.DataBaseClient;
8+
import java.io.FileNotFoundException;
9+
import java.io.IOException;
10+
import java.net.MalformedURLException;
11+
import java.util.ArrayList;
12+
import java.util.List;
13+
import javafx.scene.image.Image;
14+
import javafx.scene.image.ImageView;
15+
import javafx.scene.layout.StackPane;
516

617
/**
7-
* Steuert den Datenverkehr und gibt die BEfehle zum anzeigen.
18+
* Steuert den Datenverkehr und gibt die Befehle zum anzeigen.
819
* von Bild Raster und Eingabefenster.
920
*/
1021
public class CodeChartsCoordinator {
11-
ConfigClient configClient;
12-
protected TrialData trialData;
13-
// private long[] speed = new long[2];
14-
private static boolean isRelative;
15-
private int[] dimensions = new int[2];
16-
private static String[] strings;
17-
private boolean configData;
22+
private final TrialData trialData;
23+
private final ImageView imageView;
24+
private final CodeChartsPane rootPane;
25+
26+
private final List<String> usableStrings;
27+
private final List<String> currentStrings;
28+
29+
private final long[] timings;
30+
private final boolean relativeSize;
31+
private final boolean randomized;
32+
private final int maxDepth;
33+
private final int iterations;
1834

1935
/**
2036
* Konstruktor für den CodeChartsCoordinator.
2137
*
2238
* @param configClient - aus dem die Configuration geladen wird
39+
* @param dataBaseClient -
40+
* @throws IOException
41+
* @throws FileNotFoundException
42+
* @throws IllegalArgumentException
43+
* @throws MalformedURLException
2344
*/
24-
public CodeChartsCoordinator(ConfigClient configClient, TrialData trialData) {
25-
this.configClient = configClient;
45+
public CodeChartsCoordinator(ConfigClient configClient, DataBaseClient dataBaseClient,
46+
TrialData trialData, ImageView imageView, StackPane stackPane)
47+
throws MalformedURLException, IllegalArgumentException,
48+
FileNotFoundException, IOException {
2649
this.trialData = trialData;
27-
this.dimensions = configClient.getConfig().getCodeChartsConfiguration().getInitialSize();
28-
}
50+
this.imageView = imageView;
2951

30-
public CodeChartsCoordinator() {
52+
// BILD SETZEN
53+
String imageUrl = Util.saveImage(configClient.getConfig().getImageUrl());
54+
imageView.setImage(new Image(imageUrl));
55+
imageView.setVisible(false);
3156

32-
}
57+
// Konfiguration abspeichern
58+
CodeChartsConfiguration ccConfig = configClient.getConfig().getCodeChartsConfiguration();
59+
iterations = ccConfig.getInterations();
60+
maxDepth = ccConfig.getMaxDepth();
61+
randomized = ccConfig.getRandomized();
62+
relativeSize = ccConfig.getRandomized();
63+
timings = ccConfig.getTimings();
64+
// String-Listen initialisieren
65+
usableStrings = dataBaseClient.strings.get(ccConfig.getStringId());
66+
currentStrings = new ArrayList<>();
3367

34-
public int[] getDimensions() {
35-
return dimensions;
36-
}
68+
// Zukünftige Unterteilungen setzen (könnte auch null sein)
69+
CodeChartsPane.defaultHorizontal = ccConfig.getDefaultHorizontal();
70+
CodeChartsPane.defaultVertical = ccConfig.getDefaultVertical();
71+
CodeChartsPane.showGrid = ccConfig.getShowGrid();
3772

38-
public String[] getStrings() {
39-
return strings;
40-
}
73+
int horizontal = ccConfig.getInitialSize()[0];
74+
int vertical = ccConfig.getInitialSize()[1];
4175

42-
public boolean getIsRelative() {
43-
return isRelative;
44-
}
76+
// größ herausfinden (gleich wie Bild)
77+
double ratio = imageView.getImage().getWidth() / imageView.getImage().getHeight();
78+
double width = Math.min(imageView.getFitWidth(), imageView.getFitHeight() * ratio);
79+
double height = Math.min(imageView.getFitHeight(), imageView.getFitWidth() / ratio);
4580

46-
/**
47-
* Ruft alle Klassen und Funktionen in Reihenfolge auf in der CodeCharts durchgeführt wird.
48-
* Holt Daten aus der Config
49-
*/
50-
public void startCodeCharts() {
51-
loadConfigData();
52-
if (configData == false) {
53-
errorMessage();
54-
}
55-
// CodeChartsBild bild = new CodeChartsBild("location");
56-
// Speichert location in Data für Berechnung in Raster
57-
// CodeChartsRaste´´r raster = new CodeChartsRaster();
58-
// CodeChartsEingabefenster fenster = new CodeChartsEingabefenster();
59-
// bild.show();
60-
// wait(speed[0]);
61-
// bild.hide();
62-
// raster.show();
63-
// wait(speed[1]);
64-
// String string = fenster.show();
65-
// raster.setInput(string);
66-
// ...
67-
// raster.sendData();
81+
// ROOT PANE
82+
rootPane = new CodeChartsPane(new ArrayList<>(), -1, -1, width, height);
83+
rootPane.subdivide(horizontal, vertical);
84+
rootPane.setVisible(false);
85+
stackPane.getChildren().add(rootPane);
6886
}
6987

70-
/**
71-
* Gibt Fehlermeldung bei falscher Config data.
72-
*/
73-
private void errorMessage() {
88+
public void startTest() {
7489
;
7590
}
76-
77-
/**
78-
* Holt die Daten aus der Config.
79-
* Speichert die Daten.
80-
*
81-
* @return gibt zurück ob fertig geladen.
82-
*/
83-
protected boolean loadConfigData() {
84-
// if (data != vollständig) {
85-
// configData = false;
86-
// return configData;
87-
// } else {
88-
// configData = true;
89-
// }
90-
// speed => Umrechnung von float zu long
91-
// speed[0] = aus Config;
92-
// speed[1] = aus Config;
93-
// dimensions[0] = aus Config;
94-
// dimensions[1] = aus Config;
95-
// isRelative = aus Cofig;
96-
return configData;
97-
}
9891
}

src/main/java/github/weichware10/toolbox/codecharts/CodeChartsInput.java

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ public class CodeChartsInput {
1313

1414
public CodeChartsInput(CodeChartsCoordinator coordinator) {
1515
this.coordinator = coordinator;
16-
strings = coordinator.getStrings();
1716
}
1817

1918
/**

src/main/java/github/weichware10/toolbox/codecharts/CodeChartsPane.java

+9-5
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@ public class CodeChartsPane extends Pane {
2626
private List<int[]> globalId = new ArrayList<>();
2727
private int[] localId;
2828
private List<List<CodeChartsPane>> childPanes = new ArrayList<>();
29-
public static int defaultHorizontal = -1;
30-
public static int defaultVertical = -1;
29+
public static Integer defaultHorizontal = -1;
30+
public static Integer defaultVertical = -1;
31+
public static boolean showGrid = false;
3132

3233
/**
3334
* Erstellt eine neue CodeChartsPane.
@@ -58,7 +59,12 @@ public CodeChartsPane(List<int[]> parentIds,
5859

5960
// debug
6061
Logger.debug(String.format("created %s", toString()));
61-
enableDebugStyle();
62+
63+
if (showGrid) {
64+
setBorder(new Border(new BorderStroke(Color.BLACK,
65+
BorderStrokeStyle.SOLID, CornerRadii.EMPTY, BorderWidths.DEFAULT)));
66+
}
67+
// enableDebugStyle();
6268
setDebugSplitting(true);
6369
}
6470

@@ -181,8 +187,6 @@ private void enableDebugStyle() {
181187
Color color = Color.color(Math.random(), Math.random(), Math.random());
182188
setBackground(new Background(new BackgroundFill(color, null, null)));
183189
setOpacity(0.7);
184-
setBorder(new Border(new BorderStroke(Color.BLACK,
185-
BorderStrokeStyle.SOLID, CornerRadii.EMPTY, BorderWidths.DEFAULT)));
186190
setOnMouseEntered(leaf
187191
? e -> setBackground(
188192
new Background(new BackgroundFill(color.brighter(), null, null)))

src/main/java/github/weichware10/toolbox/gui/App.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -183,14 +183,13 @@ protected void createCodeChartsTestTrial(TextField trialIdInput) {
183183

184184
CodeChartsConfiguration codeChartsConfiguration = new CodeChartsConfiguration(
185185
"OBST", new int[]{ 3, 5 }, new long[]{ 300, 500 },
186-
false, true, true, 5,
186+
true, true, true, 5,
187187
15, -1, -1);
188188

189189
createTestTrial(new Configuration(
190190
"dunno yet",
191191
"Test Question?",
192-
/*Util.saveImage("https://scotchaddict.com/wp-content/uploads/2014/01/illusion-of-choice.jpg"),*/
193-
App.class.getClassLoader().getResource("test-image.jpg").toString(),
192+
"https://media.discordapp.net/attachments/707505654218358818/930115305852792932/geralt.jpg",
194193
"Welcome to this magnificent CodeCharts Trial",
195194
"Thanks for participating in this extraordinary CodeCharts Trial!",
196195
true,

src/main/resources/github/weichware10/toolbox/codecharts/CodeCharts.fxml

+10-15
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,14 @@
22

33
<?import javafx.scene.image.Image?>
44
<?import javafx.scene.image.ImageView?>
5-
<?import javafx.scene.layout.BorderPane?>
6-
<?import javafx.scene.layout.StackPane?>
5+
<?import javafx.scene.layout.Pane?>
76

8-
<BorderPane xmlns="http://javafx.com/javafx/17" xmlns:fx="http://javafx.com/fxml/1" fx:controller="github.weichware10.toolbox.codecharts.CodeChartsController">
9-
<center>
10-
<StackPane fx:id="stackPane" prefHeight="400.0" prefWidth="400.0">
11-
<children>
12-
<ImageView fx:id="imageView" fitHeight="500.0" fitWidth="500.0" pickOnBounds="true" preserveRatio="true">
13-
<image>
14-
<Image url="@geralt.jpg" />
15-
</image>
16-
</ImageView>
17-
</children>
18-
</StackPane>
19-
</center>
20-
</BorderPane>
7+
<Pane fx:id="codeChartsPane" prefHeight="151.0" prefWidth="150.0" xmlns="http://javafx.com/javafx/17" xmlns:fx="http://javafx.com/fxml/1" fx:controller="github.weichware10.toolbox.codecharts.CodeChartsController">
8+
<children>
9+
<ImageView fx:id="codeChartsImageView" fitHeight="150.0" fitWidth="200.0" pickOnBounds="true" preserveRatio="true">
10+
<image>
11+
<Image url="@geralt.jpg" />
12+
</image>
13+
</ImageView>
14+
</children>
15+
</Pane>

src/test/java/github/weichware10/toolbox/codecharts/CodeChartsBildTest.java

-16
This file was deleted.

0 commit comments

Comments
 (0)