diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/casono/client/ClientApp.java b/src/main/java/ch/unibas/dmi/dbis/cs108/casono/client/ClientApp.java index 76dc06d..a8667fa 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/casono/client/ClientApp.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/casono/client/ClientApp.java @@ -1,26 +1,25 @@ package ch.unibas.dmi.dbis.cs108.casono.client; /** - * Entry point for the Casono client application. - * Handles client startup and connection parameters. + * Entry point for the Casono client application. Handles client startup and connection parameters. */ import ch.unibas.dmi.dbis.cs108.casono.client.ui.Launcher; + /** - * Entry point for the Casono client application. - * Handles client startup and connection parameters. - *
- * Standardkonstruktor für die Anwendung. + * Entry point for the Casono client application. Handles client startup and connection parameters. + * + *
Standardkonstruktor für die Anwendung. */ public class ClientApp { - /** - * Standardkonstruktor. - */ + /** Standardkonstruktor. */ public ClientApp() { // Standardkonstruktor } + /** * Starts the client application with the given address. + * * @param arg Address in the format "ip:port". * @throws IllegalArgumentException if the address format is invalid. */ @@ -32,7 +31,8 @@ public class ClientApp { String host = parts[0]; int port = Integer.parseInt(parts[1]); - System.out.println("You've selected the client. It will connect port " + port + " at host " + host); - Launcher.main(new String[]{}); + System.out.println( + "You've selected the client. It will connect port " + port + " at host " + host); + Launcher.main(new String[] {}); } } diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/casono/client/ui/Launcher.java b/src/main/java/ch/unibas/dmi/dbis/cs108/casono/client/ui/Launcher.java index c687abf..f4d4069 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/casono/client/ui/Launcher.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/casono/client/ui/Launcher.java @@ -1,26 +1,26 @@ package ch.unibas.dmi.dbis.cs108.casono.client.ui; +import ch.unibas.dmi.dbis.cs108.casono.client.ui.lobbyui.Casinomainui; import javafx.application.Application; /** * Launcher for the Casono main UI. - *
- * Standardkonstruktor für die Anwendung. + * + *
Standardkonstruktor für die Anwendung. */ public class Launcher { - /** - * Standardkonstruktor. - */ + /** Standardkonstruktor. */ public Launcher() { // Standardkonstruktor } + /** * Main entry point for launching the UI. + * * @param args Command line arguments */ public static void main(String[] args) { - Application.launch(ch.unibas.dmi.dbis.cs108.casono.client.ui.lobbyui.Casinomainui.class, args); + Application.launch(Casinomainui.class, args); } } - \ No newline at end of file diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/casono/client/ui/lobbyui/Casinomainui.java b/src/main/java/ch/unibas/dmi/dbis/cs108/casono/client/ui/lobbyui/Casinomainui.java index 169da1d..959c8d3 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/casono/client/ui/lobbyui/Casinomainui.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/casono/client/ui/lobbyui/Casinomainui.java @@ -1,41 +1,43 @@ package ch.unibas.dmi.dbis.cs108.casono.client.ui.lobbyui; -/** - * Main UI application for Casono. - * Loads the main FXML layout and sets up the stage. - */ +/** Main UI application for Casono. Loads the main FXML layout and sets up the stage. */ +import java.io.IOException; import javafx.application.Application; import javafx.fxml.FXMLLoader; import javafx.scene.Scene; import javafx.stage.Stage; -import java.io.IOException; - /** * JavaFX Application class for the Casono main UI. - *
- * Standardkonstruktor für die Anwendung. + * + *
Standardkonstruktor für die Anwendung.
*/
public class Casinomainui extends Application {
- /**
- * Standardkonstruktor.
- */
+ /** Standardkonstruktor. */
public Casinomainui() {
// Standardkonstruktor
}
+
+ private static final int SCENE_WIDTH = 1200;
+ private static final int SCENE_HEIGHT = 800;
+
@Override
/**
* Starts the JavaFX application and loads the main UI.
+ *
* @param stage The primary stage for this application.
* @throws IOException If loading the FXML fails.
*/
public void start(Stage stage) throws IOException {
- FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/ui-structure/Casinomainui.fxml"));
- Scene scene = new Scene(fxmlLoader.load(), 1200, 800);
+ FXMLLoader fxmlLoader =
+ new FXMLLoader(getClass().getResource("/ui-structure/Casinomainui.fxml"));
+ Scene scene = new Scene(fxmlLoader.load(), SCENE_WIDTH, SCENE_HEIGHT);
stage.setTitle("Casono");
-
- stage.getIcons().add(new javafx.scene.image.Image(getClass().getResource("/images/logoinverted.png").toExternalForm()));
+ javafx.scene.image.Image icon =
+ new javafx.scene.image.Image(
+ getClass().getResource("/images/logoinverted.png").toExternalForm());
+ stage.getIcons().add(icon);
stage.setScene(scene);
stage.setFullScreen(true);
stage.show();
@@ -43,6 +45,7 @@ public class Casinomainui extends Application {
/**
* Main entry point for launching the application.
+ *
* @param args Command line arguments
*/
public static void main(String[] args) {
diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/casono/client/ui/lobbyui/CasinomainuiController.java b/src/main/java/ch/unibas/dmi/dbis/cs108/casono/client/ui/lobbyui/CasinomainuiController.java
index 5c235cf..56fe07e 100644
--- a/src/main/java/ch/unibas/dmi/dbis/cs108/casono/client/ui/lobbyui/CasinomainuiController.java
+++ b/src/main/java/ch/unibas/dmi/dbis/cs108/casono/client/ui/lobbyui/CasinomainuiController.java
@@ -2,34 +2,27 @@ package ch.unibas.dmi.dbis.cs108.casono.client.ui.lobbyui;
import javafx.application.Platform;
import javafx.fxml.FXML;
-import javafx.scene.control.Label;
import javafx.scene.control.Button;
+import javafx.scene.control.Label;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.VBox;
import javafx.scene.shape.Rectangle;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
-/**
- * Controller for the Casono main UI lobby.
- * Handles UI initialization and user actions.
- */
+/** Controller for the Casono main UI lobby. Handles UI initialization and user actions. */
public class CasinomainuiController {
+ private static final Logger LOGGER = LogManager.getLogger(CasinomainuiController.class);
- @FXML
- private AnchorPane rootPane;
- @FXML
- private Label titleLabel;
- @FXML
- private Label subtitleLabel;
- @FXML
- private ImageView logoView;
- @FXML
- private Rectangle greenBox;
- @FXML
- private Button exitbutton;
- @FXML
- private VBox casinoTable;
+ @FXML private AnchorPane rootPane;
+ @FXML private Label titleLabel;
+ @FXML private Label subtitleLabel;
+ @FXML private ImageView logoView;
+ @FXML private Rectangle greenBox;
+ @FXML private Button exitbutton;
+ @FXML private VBox casinoTable;
private LobbyButtonTranslationManager translationManager;
private LobbyButtonGridManager gridManager;
@@ -39,9 +32,7 @@ public class CasinomainuiController {
// Default constructor
}
- /**
- * Initializes the UI components and sets default values.
- */
+ /** Initializes the UI components and sets default values. */
@FXML
public void initialize() {
titleLabel.setText("Casono");
@@ -49,37 +40,34 @@ public class CasinomainuiController {
logoView.setImage(new Image(getClass().getResource("/images/logo.png").toExternalForm()));
translationManager = new LobbyButtonTranslationManager();
- gridManager = new LobbyButtonGridManager(new javafx.scene.layout.GridPane(), translationManager);
+ gridManager =
+ new LobbyButtonGridManager(new javafx.scene.layout.GridPane(), translationManager);
casinoTable.getChildren().clear();
casinoTable.getChildren().add(gridManager.getGridPane());
gridManager.renderLobbyButtons();
}
- /**
- * Handles the exit button action to close the application.
- */
+ /** Handles the exit button action to close the application. */
@FXML
public void handleexitbutton() {
Platform.exit();
}
- /**
- * Handles creation of a new lobby button.
- */
+ /** Handles creation of a new lobby button. */
@FXML
public void handleCreateLobbyButton() {
if (translationManager.isFull()) {
- System.out.println("Grid voll! Keine weiteren Lobbys moeglich.");
+ LOGGER.warn("Grid voll! Keine weiteren Lobbys moeglich.");
return;
}
int buttonId = nextButtonId++;
int lobbyId = gridManager.createLobby();
try {
translationManager.addLobbyButton(buttonId, lobbyId);
- System.out.println("ButtonID: " + buttonId + ", LobbyID: " + lobbyId);
+ LOGGER.info("ButtonID: {}, LobbyID: {}", buttonId, lobbyId);
gridManager.renderLobbyButtons();
} catch (Exception e) {
- System.out.println("Fehler beim Hinzufügen: " + e.getMessage());
+ LOGGER.error("Fehler beim Hinzufügen: {}", e.getMessage());
}
}
}
diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/casono/client/ui/lobbyui/LobbyButtonGridManager.java b/src/main/java/ch/unibas/dmi/dbis/cs108/casono/client/ui/lobbyui/LobbyButtonGridManager.java
index 6add82d..03259a7 100644
--- a/src/main/java/ch/unibas/dmi/dbis/cs108/casono/client/ui/lobbyui/LobbyButtonGridManager.java
+++ b/src/main/java/ch/unibas/dmi/dbis/cs108/casono/client/ui/lobbyui/LobbyButtonGridManager.java
@@ -1,47 +1,57 @@
package ch.unibas.dmi.dbis.cs108.casono.client.ui.lobbyui;
/**
- * Manages the grid for lobby buttons and rendering.
- * Uses LobbyButtonTranslationManager for mapping ButtonID to LobbyID.
+ * Manages the grid for lobby buttons and rendering. Uses LobbyButtonTranslationManager for mapping
+ * ButtonID to LobbyID.
*/
-
+import java.util.Map;
import javafx.scene.control.Button;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.GridPane;
-import java.util.Map;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
/**
- * Manages the grid for lobby buttons and rendering.
- * Uses LobbyButtonTranslationManager for mapping ButtonID to LobbyID.
+ * Manages the grid for lobby buttons and rendering. Uses LobbyButtonTranslationManager for mapping
+ * ButtonID to LobbyID.
*/
public class LobbyButtonGridManager {
+ private static final Logger LOGGER = LogManager.getLogger(LobbyButtonGridManager.class);
/** GridPane for the button grid. */
private final GridPane gridPane;
+
/** Manager for mapping ButtonID to LobbyID. */
private final LobbyButtonTranslationManager translationManager;
+
/** Number of rows in the grid. */
- private final int rows = 2;
+ private static final int ROWS = 2;
+
/** Number of columns in the grid. */
- private final int cols = 4;
+ private static final int COLS = 4;
+
/** Path to the button image. */
- private final String buttonImagePath = "/images/logo.png";
+ private static final String BUTTON_IMAGE_PATH = "/images/logo.png";
+
+ /** Max random lobby id. */
+ private static final int MAX_RANDOM_LOBBY_ID = 10000;
/**
* Constructor for the GridManager.
- *
- * @param gridPane the GridPane for rendering
+ *
+ * @param gridPane the GridPane for rendering
* @param translationManager the manager for mapping ButtonID to LobbyID
*/
- public LobbyButtonGridManager(GridPane gridPane, LobbyButtonTranslationManager translationManager) {
+ public LobbyButtonGridManager(
+ GridPane gridPane, LobbyButtonTranslationManager translationManager) {
this.gridPane = gridPane;
this.translationManager = translationManager;
}
/**
- * Renders all lobby buttons in the grid.
- * Creates a button for each mapping with image and event handler.
+ * Renders all lobby buttons in the grid. Creates a button for each mapping with image and event
+ * handler.
*/
public void renderLobbyButtons() {
gridPane.getChildren().clear();
@@ -55,14 +65,17 @@ public class LobbyButtonGridManager {
int buttonId = entry.getKey();
Button btn = new Button();
btn.setId("lobbyBtn-" + buttonId);
- btn.setGraphic(new ImageView(new Image(getClass().getResourceAsStream(buttonImagePath))));
- btn.setOnAction(e -> {
- Integer lobbyId = translationManager.getLobbyIdForButton(buttonId);
- if (lobbyId != null)
- joinLobby(lobbyId);
- });
- int row = index / cols;
- int col = index % cols;
+ btn.setGraphic(
+ new ImageView(new Image(getClass().getResourceAsStream(BUTTON_IMAGE_PATH))));
+ btn.setOnAction(
+ e -> {
+ Integer lobbyId = translationManager.getLobbyIdForButton(buttonId);
+ if (lobbyId != null) {
+ joinLobby(lobbyId);
+ }
+ });
+ int row = index / COLS;
+ int col = index % COLS;
gridPane.add(btn, col, row);
index++;
}
@@ -70,29 +83,29 @@ public class LobbyButtonGridManager {
/**
* Placeholder for lobby creation logic. Returns a generated lobbyId.
- *
+ *
* @return The generated lobbyId
*/
public int createLobby() {
// TODO: Replace with actual lobby creation logic
- int lobbyId = (int) (Math.random() * 10000 + 1);
- System.out.println("Lobby created: " + lobbyId);
+ int lobbyId = (int) (Math.random() * MAX_RANDOM_LOBBY_ID + 1);
+ LOGGER.info("Lobby created: {}", lobbyId);
return lobbyId;
}
/**
* Placeholder for joining a lobby.
- *
+ *
* @param lobbyId The lobbyId to join
*/
public void joinLobby(int lobbyId) {
// TODO: Replace with actual join logic
- System.out.println("Joining lobby: " + lobbyId);
+ LOGGER.info("Joining lobby: {}", lobbyId);
}
/**
* Getter for the GridPane.
- *
+ *
* @return The GridPane for the button grid
*/
public javafx.scene.layout.GridPane getGridPane() {
diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/casono/client/ui/lobbyui/LobbyButtonTranslationManager.java b/src/main/java/ch/unibas/dmi/dbis/cs108/casono/client/ui/lobbyui/LobbyButtonTranslationManager.java
index e3dd72e..19af19e 100644
--- a/src/main/java/ch/unibas/dmi/dbis/cs108/casono/client/ui/lobbyui/LobbyButtonTranslationManager.java
+++ b/src/main/java/ch/unibas/dmi/dbis/cs108/casono/client/ui/lobbyui/LobbyButtonTranslationManager.java
@@ -4,24 +4,24 @@ import java.util.HashMap;
import java.util.Map;
/**
- * Verwaltet das Mapping zwischen Button-IDs und Lobby-IDs rein im Speicher.
- * Keine Dateioperationen, nur Laufzeitdatenstruktur.
+ * Verwaltet das Mapping zwischen Button-IDs und Lobby-IDs rein im Speicher. Keine Dateioperationen,
+ * nur Laufzeitdatenstruktur.
*/
public class LobbyButtonTranslationManager {
/** Maximale Anzahl an Buttons/Lobbys */
private static final int MAX_BUTTONS = 8;
+
/** Zuordnung ButtonID → LobbyID */
private final Map