Chore/conform ui to checkstyle #184
@@ -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.
|
||||
* <p>
|
||||
* Standardkonstruktor für die Anwendung.
|
||||
* Entry point for the Casono client application. Handles client startup and connection parameters.
|
||||
*
|
||||
* <p>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[] {});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
* <p>
|
||||
* Standardkonstruktor für die Anwendung.
|
||||
*
|
||||
* <p>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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
* <p>
|
||||
* Standardkonstruktor für die Anwendung.
|
||||
*
|
||||
* <p>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) {
|
||||
|
||||
+20
-32
@@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+33
-20
@@ -1,32 +1,41 @@
|
||||
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.
|
||||
@@ -34,14 +43,15 @@ public class LobbyButtonGridManager {
|
||||
* @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 -> {
|
||||
btn.setGraphic(
|
||||
new ImageView(new Image(getClass().getResourceAsStream(BUTTON_IMAGE_PATH))));
|
||||
btn.setOnAction(
|
||||
e -> {
|
||||
Integer lobbyId = translationManager.getLobbyIdForButton(buttonId);
|
||||
if (lobbyId != null)
|
||||
if (lobbyId != null) {
|
||||
joinLobby(lobbyId);
|
||||
}
|
||||
});
|
||||
int row = index / cols;
|
||||
int col = index % cols;
|
||||
int row = index / COLS;
|
||||
int col = index % COLS;
|
||||
gridPane.add(btn, col, row);
|
||||
index++;
|
||||
}
|
||||
@@ -75,8 +88,8 @@ public class LobbyButtonGridManager {
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -87,7 +100,7 @@ public class LobbyButtonGridManager {
|
||||
*/
|
||||
public void joinLobby(int lobbyId) {
|
||||
// TODO: Replace with actual join logic
|
||||
System.out.println("Joining lobby: " + lobbyId);
|
||||
LOGGER.info("Joining lobby: {}", lobbyId);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+12
-6
@@ -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<Integer, Integer> buttonIdToLobbyId = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Konstruktor: initialisiert die Zuordnung leer.
|
||||
*/
|
||||
/** Konstruktor: initialisiert die Zuordnung leer. */
|
||||
public LobbyButtonTranslationManager() {
|
||||
// Zuordnung bleibt leer beim Start
|
||||
}
|
||||
|
||||
/**
|
||||
* Prüft, ob das Grid voll ist (MAX_BUTTONS erreicht).
|
||||
*
|
||||
* @return true, wenn Grid voll; sonst false
|
||||
*/
|
||||
public boolean isFull() {
|
||||
@@ -30,17 +30,21 @@ public class LobbyButtonTranslationManager {
|
||||
|
||||
/**
|
||||
* Fügt eine Zuordnung ButtonID → LobbyID hinzu.
|
||||
*
|
||||
* @param buttonId Die ID des Buttons
|
||||
* @param lobbyId Die ID der Lobby
|
||||
* @throws Exception wenn das Grid voll ist
|
||||
*/
|
||||
public void addLobbyButton(int buttonId, int lobbyId) throws Exception {
|
||||
if (isFull()) throw new Exception("Grid is full!");
|
||||
if (isFull()) {
|
||||
throw new Exception("Grid is full!");
|
||||
}
|
||||
buttonIdToLobbyId.put(buttonId, lobbyId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Entfernt eine Zuordnung für die gegebene ButtonID.
|
||||
*
|
||||
* @param buttonId Die ID des zu entfernenden Buttons
|
||||
*/
|
||||
public void removeLobbyButton(int buttonId) {
|
||||
@@ -49,6 +53,7 @@ public class LobbyButtonTranslationManager {
|
||||
|
||||
/**
|
||||
* Gibt die LobbyID für eine gegebene ButtonID zurück.
|
||||
*
|
||||
* @param buttonId Die ButtonID
|
||||
* @return Die zugehoerige LobbyID oder null, falls nicht vorhanden
|
||||
*/
|
||||
@@ -58,6 +63,7 @@ public class LobbyButtonTranslationManager {
|
||||
|
||||
/**
|
||||
* Gibt die gesamte Zuordnung ButtonID → LobbyID zurück.
|
||||
*
|
||||
* @return Map aller Zuordnungen
|
||||
*/
|
||||
public Map<Integer, Integer> getButtonIdToLobbyId() {
|
||||
|
||||
+2
-2
@@ -1,10 +1,10 @@
|
||||
package ch.unibas.dmi.dbis.cs108.casono.client.ui.lobbyui;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import javafx.scene.layout.GridPane;
|
||||
import org.junit.jupiter.api.*;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class LobbyButtonGridManagerTest {
|
||||
LobbyButtonGridManager gridManager;
|
||||
LobbyButtonTranslationManager translationManager;
|
||||
|
||||
+3
-3
@@ -1,10 +1,10 @@
|
||||
package ch.unibas.dmi.dbis.cs108.casono.client.ui.lobbyui;
|
||||
|
||||
import org.junit.jupiter.api.*;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import java.util.Map;
|
||||
import org.junit.jupiter.api.*;
|
||||
|
||||
class LobbyButtonTranslationManagerTest {
|
||||
LobbyButtonTranslationManager manager;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user