Fix: Checkstyle
This commit is contained in:
+65
-53
@@ -513,20 +513,7 @@ public class CasinoGameController {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Card> community = (s.communityCards != null) ? s.communityCards : List.of();
|
updateCards(s, players);
|
||||||
List<Card> myCards = getMyCards(players);
|
|
||||||
|
|
||||||
java.util.List<String> newCommunityKeys = cardKeys(community, TOTAL_SLOTS);
|
|
||||||
if (!newCommunityKeys.equals(lastCommunityKeys)) {
|
|
||||||
lastCommunityKeys = newCommunityKeys;
|
|
||||||
renderCommunityCards(community);
|
|
||||||
}
|
|
||||||
|
|
||||||
java.util.List<String> newMyCardKeys = cardKeys(myCards, PLAYER_SLOTS);
|
|
||||||
if (!newMyCardKeys.equals(lastMyCardKeys)) {
|
|
||||||
lastMyCardKeys = newMyCardKeys;
|
|
||||||
renderPlayerCards(myCards);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (s.pot != lastPot) {
|
if (s.pot != lastPot) {
|
||||||
lastPot = s.pot;
|
lastPot = s.pot;
|
||||||
@@ -556,6 +543,32 @@ public class CasinoGameController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the displayed community cards and the player's hole cards based on the current game
|
||||||
|
* state.
|
||||||
|
*
|
||||||
|
* @param s The current game state containing the community cards and the list of players, used
|
||||||
|
* to determine.
|
||||||
|
* @param players The list of players currently in the game, used to retrieve the player's hole
|
||||||
|
* cards for display. If null, it will be treated as an empty list.
|
||||||
|
*/
|
||||||
|
private void updateCards(GameState s, List<Player> players) {
|
||||||
|
List<Card> community = (s.communityCards != null) ? s.communityCards : List.of();
|
||||||
|
List<Card> myCards = getMyCards(players);
|
||||||
|
|
||||||
|
var newCommunityKeys = cardKeys(community, TOTAL_SLOTS);
|
||||||
|
if (!newCommunityKeys.equals(lastCommunityKeys)) {
|
||||||
|
lastCommunityKeys = newCommunityKeys;
|
||||||
|
renderCommunityCards(community);
|
||||||
|
}
|
||||||
|
|
||||||
|
var newMyCardKeys = cardKeys(myCards, PLAYER_SLOTS);
|
||||||
|
if (!newMyCardKeys.equals(lastMyCardKeys)) {
|
||||||
|
lastMyCardKeys = newMyCardKeys;
|
||||||
|
renderPlayerCards(myCards);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Synchronize the whisper chat targets with the current list of players.
|
* Synchronize the whisper chat targets with the current list of players.
|
||||||
*
|
*
|
||||||
@@ -733,7 +746,7 @@ public class CasinoGameController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
PlayerId pid = p.getId();
|
PlayerId pid = p.getId();
|
||||||
boolean isMe = myPlayerId != null && myPlayerId.equals(pid);
|
boolean isMe = myPlayerId != null && myPlayerId.equals(pid);
|
||||||
|
|
||||||
if (isMe) {
|
if (isMe) {
|
||||||
meFound = true;
|
meFound = true;
|
||||||
@@ -809,9 +822,7 @@ public class CasinoGameController {
|
|||||||
setTaskbarTurnHighlight(false);
|
setTaskbarTurnHighlight(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** Clear all visual highlights in the UI that indicate the active player's turn. */
|
||||||
* Clear all visual highlights in the UI that indicate the active player's turn.
|
|
||||||
*/
|
|
||||||
private void clearActiveTurnHighlights() {
|
private void clearActiveTurnHighlights() {
|
||||||
if (player1Controller != null) {
|
if (player1Controller != null) {
|
||||||
player1Controller.setTurnHighlighted(false);
|
player1Controller.setTurnHighlighted(false);
|
||||||
@@ -833,11 +844,11 @@ public class CasinoGameController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the visual highlight state of the player's hole cards to indicate whether it is
|
* Set the visual highlight state of the player's hole cards to indicate whether it is currently
|
||||||
* currently the player's turn in the game.
|
* the player's turn in the game.
|
||||||
*
|
*
|
||||||
* @param highlighted true to highlight the player's hole cards, indicating that it is their turn,
|
* @param highlighted true to highlight the player's hole cards, indicating that it is their
|
||||||
* or false to remove the highlight when it is not their turn.
|
* turn, or false to remove the highlight when it is not their turn.
|
||||||
*/
|
*/
|
||||||
private void setPlayerCardsTurnHighlighted(boolean highlighted) {
|
private void setPlayerCardsTurnHighlighted(boolean highlighted) {
|
||||||
if (playerCardsBox == null) {
|
if (playerCardsBox == null) {
|
||||||
@@ -852,12 +863,13 @@ public class CasinoGameController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update the visual highlights in the UI to indicate which player's turn it is based on the active.
|
* Update the visual highlights in the UI to indicate which player's turn it is based on the
|
||||||
|
* active.
|
||||||
*
|
*
|
||||||
* @param players The list of players currently in the game, used to identify the active
|
* @param players The list of players currently in the game, used to identify the active player
|
||||||
* player and update the turn highlights accordingly.
|
* and update the turn highlights accordingly.
|
||||||
* @param activePlayerIndex The index of the active player in the players list, which is used to determine
|
* @param activePlayerIndex The index of the active player in the players list, which is used to
|
||||||
* whose turn it is and update the UI highlights to reflect that.
|
* determine whose turn it is and update the UI highlights to reflect that.
|
||||||
*/
|
*/
|
||||||
private void updateActiveTurnHighlights(List<Player> players, int activePlayerIndex) {
|
private void updateActiveTurnHighlights(List<Player> players, int activePlayerIndex) {
|
||||||
clearActiveTurnHighlights();
|
clearActiveTurnHighlights();
|
||||||
@@ -892,8 +904,8 @@ public class CasinoGameController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the turn highlight state in the taskbar controller, which visually indicates whether
|
* Set the turn highlight state in the taskbar controller, which visually indicates whether it
|
||||||
* it is the current player's turn in the game.
|
* is the current player's turn in the game.
|
||||||
*
|
*
|
||||||
* @param highlighted true to highlight the turn in the taskbar, false to remove the highlight.
|
* @param highlighted true to highlight the turn in the taskbar, false to remove the highlight.
|
||||||
*/
|
*/
|
||||||
@@ -910,7 +922,7 @@ public class CasinoGameController {
|
|||||||
* @param players The list of players from which to retrieve the player at the specified index.
|
* @param players The list of players from which to retrieve the player at the specified index.
|
||||||
* @param index The index of the player to retrieve from the list.
|
* @param index The index of the player to retrieve from the list.
|
||||||
* @return The Player object at the specified index if it exists and is valid, or null if the
|
* @return The Player object at the specified index if it exists and is valid, or null if the
|
||||||
* index is out of bounds or if the players list is null or empty.
|
* index is out of bounds or if the players list is null or empty.
|
||||||
*/
|
*/
|
||||||
private Player getPlayerAtIndex(List<Player> players, int index) {
|
private Player getPlayerAtIndex(List<Player> players, int index) {
|
||||||
if (players == null || index < 0 || index >= players.size()) {
|
if (players == null || index < 0 || index >= players.size()) {
|
||||||
@@ -923,10 +935,10 @@ public class CasinoGameController {
|
|||||||
/**
|
/**
|
||||||
* Resolve the winner of the hand based on the game state.
|
* Resolve the winner of the hand based on the game state.
|
||||||
*
|
*
|
||||||
* @param s The current game state, which may contain information about the players,
|
* @param s The current game state, which may contain information about the players, their
|
||||||
* their states, and the winner index.
|
* states, and the winner index.
|
||||||
* @return The Player object representing the winner if it can be determined from the
|
* @return The Player object representing the winner if it can be determined from the game
|
||||||
* game state, or null if the winner cannot be resolved or if the game is still in progress.
|
* state, or null if the winner cannot be resolved or if the game is still in progress.
|
||||||
*/
|
*/
|
||||||
private Player resolveWinner(GameState s) {
|
private Player resolveWinner(GameState s) {
|
||||||
if (s == null || s.players == null || s.players.isEmpty()) {
|
if (s == null || s.players == null || s.players.isEmpty()) {
|
||||||
@@ -963,10 +975,10 @@ public class CasinoGameController {
|
|||||||
/**
|
/**
|
||||||
* Resolve the name of the winner based on the game state.
|
* Resolve the name of the winner based on the game state.
|
||||||
*
|
*
|
||||||
* @param s The current game state, which may contain information about the players,
|
* @param s The current game state, which may contain information about the players, their
|
||||||
* their states, and the winner index.
|
* states, and the winner index.
|
||||||
* @return The name of the winner if it can be determined from the game state,
|
* @return The name of the winner if it can be determined from the game state, or null if the
|
||||||
* or null if the winner cannot be resolved or if the game is still in progress.
|
* winner cannot be resolved or if the game is still in progress.
|
||||||
*/
|
*/
|
||||||
private String resolveWinnerName(GameState s) {
|
private String resolveWinnerName(GameState s) {
|
||||||
Player winner = resolveWinner(s);
|
Player winner = resolveWinner(s);
|
||||||
@@ -987,14 +999,15 @@ public class CasinoGameController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine if the game is in a finished state based on the game state and the presence of a winner name.
|
* Determine if the game is in a finished state based on the game state and the presence of a
|
||||||
|
* winner name.
|
||||||
*
|
*
|
||||||
* @param s The current game state, which may be null or contain information about the phase, players,
|
* @param s The current game state, which may be null or contain information about the phase,
|
||||||
* and winner index.
|
* players, and winner index.
|
||||||
* @param winnerName The name of the winner, which may be null or blank if the winner is not yet determined
|
* @param winnerName The name of the winner, which may be null or blank if the winner is not yet
|
||||||
* or if the game is still in progress.
|
* determined or if the game is still in progress.
|
||||||
* @return true if the game is considered finished based on the provided state and winner information,
|
* @return true if the game is considered finished based on the provided state and winner
|
||||||
* false otherwise.
|
* information, false otherwise.
|
||||||
*/
|
*/
|
||||||
private boolean isGameFinishedState(GameState s, String winnerName) {
|
private boolean isGameFinishedState(GameState s, String winnerName) {
|
||||||
if (s == null) {
|
if (s == null) {
|
||||||
@@ -1042,19 +1055,18 @@ public class CasinoGameController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine if the current phase of the game is a terminal phase, such as "FINISHED" or "SHOWDOWN".
|
* Determine if the current phase of the game is a terminal phase, such as "FINISHED" or
|
||||||
|
* "SHOWDOWN".
|
||||||
*
|
*
|
||||||
* @param phase The current phase of the game, which may be null or blank.
|
* @param phase The current phase of the game, which may be null or blank.
|
||||||
* @return true if the phase is considered terminal, indicating that the hand has ended
|
* @return true if the phase is considered terminal, indicating that the hand has ended and a
|
||||||
* and a winner can be declared, false otherwise.
|
* winner can be declared, false otherwise.
|
||||||
*/
|
*/
|
||||||
private boolean isTerminalPhase(String phase) {
|
private boolean isTerminalPhase(String phase) {
|
||||||
return "FINISHED".equalsIgnoreCase(phase) || "SHOWDOWN".equalsIgnoreCase(phase);
|
return "FINISHED".equalsIgnoreCase(phase) || "SHOWDOWN".equalsIgnoreCase(phase);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** Finish the game UI loop by stopping the timeline that updates the UI. */
|
||||||
* Finish the game UI loop by stopping the timeline that updates the UI.
|
|
||||||
*/
|
|
||||||
private void finishGameUiLoop() {
|
private void finishGameUiLoop() {
|
||||||
if (gameFinished) {
|
if (gameFinished) {
|
||||||
return;
|
return;
|
||||||
@@ -1070,8 +1082,8 @@ public class CasinoGameController {
|
|||||||
*
|
*
|
||||||
* @param node The JavaFX Node on which to toggle the style class.
|
* @param node The JavaFX Node on which to toggle the style class.
|
||||||
* @param styleClass The name of the CSS style class to toggle.
|
* @param styleClass The name of the CSS style class to toggle.
|
||||||
* @param active A boolean indicating whether to add (true)
|
* @param active A boolean indicating whether to add (true) or remove (false) the style class
|
||||||
* or remove (false) the style class from the node.
|
* from the node.
|
||||||
*/
|
*/
|
||||||
private void toggleStyleClass(Node node, String styleClass, boolean active) {
|
private void toggleStyleClass(Node node, String styleClass, boolean active) {
|
||||||
if (node == null || styleClass == null || styleClass.isBlank()) {
|
if (node == null || styleClass == null || styleClass.isBlank()) {
|
||||||
|
|||||||
+132
-104
@@ -11,13 +11,17 @@ import java.util.Map;
|
|||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import javafx.application.Platform;
|
import javafx.application.Platform;
|
||||||
|
import javafx.collections.FXCollections;
|
||||||
|
import javafx.collections.ObservableList;
|
||||||
import javafx.geometry.Insets;
|
import javafx.geometry.Insets;
|
||||||
import javafx.geometry.Pos;
|
import javafx.geometry.Pos;
|
||||||
import javafx.scene.Scene;
|
import javafx.scene.Scene;
|
||||||
import javafx.scene.control.Alert;
|
import javafx.scene.control.Alert;
|
||||||
import javafx.scene.control.Button;
|
import javafx.scene.control.Button;
|
||||||
import javafx.scene.control.ButtonType;
|
import javafx.scene.control.ButtonType;
|
||||||
|
import javafx.scene.control.ContextMenu;
|
||||||
import javafx.scene.control.Label;
|
import javafx.scene.control.Label;
|
||||||
|
import javafx.scene.control.MenuItem;
|
||||||
import javafx.scene.control.TextField;
|
import javafx.scene.control.TextField;
|
||||||
import javafx.scene.image.Image;
|
import javafx.scene.image.Image;
|
||||||
import javafx.scene.image.ImageView;
|
import javafx.scene.image.ImageView;
|
||||||
@@ -32,10 +36,6 @@ import javafx.scene.web.WebView;
|
|||||||
import javafx.stage.Stage;
|
import javafx.stage.Stage;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import javafx.collections.FXCollections;
|
|
||||||
import javafx.collections.ObservableList;
|
|
||||||
import javafx.scene.control.ContextMenu;
|
|
||||||
import javafx.scene.control.MenuItem;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Experimental embedded browser for Casono.
|
* Experimental embedded browser for Casono.
|
||||||
@@ -86,6 +86,7 @@ public class CasinoBrowserController {
|
|||||||
private static final int ALERT_HEIGHT = 300;
|
private static final int ALERT_HEIGHT = 300;
|
||||||
private static final String LOGO_PATH = "/images/logoinverted.png";
|
private static final String LOGO_PATH = "/images/logoinverted.png";
|
||||||
private static final String LOGO_PATH_MAIN = "/images/logo.png";
|
private static final String LOGO_PATH_MAIN = "/images/logo.png";
|
||||||
|
private static final int MAX_AUTOCOMPLETE_RESULTS = 5;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
CookieHandler.setDefault(COOKIE_MANAGER);
|
CookieHandler.setDefault(COOKIE_MANAGER);
|
||||||
@@ -112,43 +113,44 @@ public class CasinoBrowserController {
|
|||||||
TRUSTED_DOMAINS.add("startpage.com");
|
TRUSTED_DOMAINS.add("startpage.com");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** Aliases for common websites. */
|
||||||
* Aliases for common websites.
|
private static final java.util.Map<String, String> ALIASES =
|
||||||
*/
|
Map.ofEntries(
|
||||||
private static final java.util.Map<String, String> ALIASES = Map.ofEntries(
|
Map.entry("wiki", "wikipedia.org"),
|
||||||
Map.entry("wiki", "wikipedia.org"),
|
Map.entry("yt", "youtube.com"),
|
||||||
Map.entry("yt", "youtube.com"),
|
Map.entry("bra", "search.brave.com"),
|
||||||
Map.entry("bra", "search.brave.com"),
|
Map.entry("bs", "search.brave.com"),
|
||||||
Map.entry("bs", "search.brave.com"),
|
Map.entry("gh", "github.com"),
|
||||||
Map.entry("gh", "github.com"),
|
Map.entry("google", "google.com"),
|
||||||
Map.entry("google", "google.com"),
|
Map.entry("duck", "duckduckgo.com"),
|
||||||
Map.entry("duck", "duckduckgo.com"),
|
Map.entry("bing", "bing.com"),
|
||||||
Map.entry("bing", "bing.com"),
|
Map.entry("meta", "metager.de"),
|
||||||
Map.entry("meta", "metager.de"),
|
Map.entry("mojeek", "mojeek.com"),
|
||||||
Map.entry("mojeek", "mojeek.com"),
|
Map.entry("searx", "searx.be"),
|
||||||
Map.entry("searx", "searx.be"),
|
Map.entry("startpage", "startpage.com"),
|
||||||
Map.entry("startpage", "startpage.com"),
|
Map.entry("stack", "stackoverflow.com"),
|
||||||
Map.entry("stack", "stackoverflow.com"),
|
Map.entry("so", "stackoverflow.com"),
|
||||||
Map.entry("so", "stackoverflow.com"),
|
Map.entry("oracle", "oracle.com"),
|
||||||
Map.entry("oracle", "oracle.com"),
|
Map.entry("docs", "docs.oracle.com"),
|
||||||
Map.entry("docs", "docs.oracle.com"),
|
Map.entry("mdn", "developer.mozilla.org"),
|
||||||
Map.entry("mdn", "developer.mozilla.org"),
|
Map.entry("maven", "maven.apache.org"),
|
||||||
Map.entry("maven", "maven.apache.org"),
|
Map.entry("gradle", "gradle.org"),
|
||||||
Map.entry("gradle", "gradle.org"),
|
Map.entry("spring", "spring.io"),
|
||||||
Map.entry("spring", "spring.io"),
|
Map.entry("jetbrains", "jetbrains.com"),
|
||||||
Map.entry("jetbrains", "jetbrains.com"),
|
Map.entry("uni", "unibas.ch"));
|
||||||
Map.entry("uni", "unibas.ch")
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resolves user input into a valid URL.
|
* Resolves user input into a valid URL.
|
||||||
*
|
*
|
||||||
* @param input User input from the URL field, which can be a full URL, a domain name, or an alias.
|
* @param input User input from the URL field, which can be a full URL, a domain name, or an
|
||||||
* @return A properly formatted URL string that can be loaded by the browser, or the original input
|
* alias.
|
||||||
* if it cannot be resolved.
|
* @return A properly formatted URL string that can be loaded by the browser, or the original
|
||||||
|
* input if it cannot be resolved.
|
||||||
*/
|
*/
|
||||||
private static String resolveInputToUrl(String input) {
|
private static String resolveInputToUrl(String input) {
|
||||||
if (input == null || input.isBlank()) return input;
|
if (input == null || input.isBlank()) {
|
||||||
|
return input;
|
||||||
|
}
|
||||||
|
|
||||||
input = input.trim();
|
input = input.trim();
|
||||||
|
|
||||||
@@ -271,7 +273,7 @@ public class CasinoBrowserController {
|
|||||||
Alert alert = new Alert(Alert.AlertType.WARNING);
|
Alert alert = new Alert(Alert.AlertType.WARNING);
|
||||||
alert.setTitle("Popup blocked");
|
alert.setTitle("Popup blocked");
|
||||||
alert.setHeaderText(null);
|
alert.setHeaderText(null);
|
||||||
alert.setContentText("The Casono browser has detected a threat and successfully blocked it.");
|
alert.setContentText("Casono Browser blocked a security threat.");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
var stream = CasinoBrowserController.class.getResourceAsStream(LOGO_PATH);
|
var stream = CasinoBrowserController.class.getResourceAsStream(LOGO_PATH);
|
||||||
@@ -349,67 +351,90 @@ public class CasinoBrowserController {
|
|||||||
urlField.getStyleClass().add("gray-input-field");
|
urlField.getStyleClass().add("gray-input-field");
|
||||||
HBox.setHgrow(urlField, Priority.ALWAYS);
|
HBox.setHgrow(urlField, Priority.ALWAYS);
|
||||||
|
|
||||||
urlField.textProperty().addListener((obs, oldText, newText) -> {
|
urlField.textProperty()
|
||||||
if (newText == null || newText.isBlank()) {
|
.addListener(
|
||||||
autoCompleteMenu.hide();
|
(obs, oldText, newText) -> {
|
||||||
return;
|
if (newText == null || newText.isBlank()) {
|
||||||
}
|
autoCompleteMenu.hide();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
String input = newText.toLowerCase();
|
String input = newText.toLowerCase();
|
||||||
|
|
||||||
String aliasMatch = ALIASES.get(input);
|
String aliasMatch = ALIASES.get(input);
|
||||||
if (aliasMatch != null) {
|
if (aliasMatch != null) {
|
||||||
autoCompleteMenu.getItems().clear();
|
autoCompleteMenu.getItems().clear();
|
||||||
|
|
||||||
MenuItem item = new MenuItem(aliasMatch);
|
MenuItem item = new MenuItem(aliasMatch);
|
||||||
item.setOnAction(e -> {
|
item.setOnAction(
|
||||||
urlField.setText("https://" + aliasMatch);
|
e -> {
|
||||||
autoCompleteMenu.hide();
|
urlField.setText("https://" + aliasMatch);
|
||||||
});
|
autoCompleteMenu.hide();
|
||||||
|
});
|
||||||
|
|
||||||
autoCompleteMenu.getItems().add(item);
|
autoCompleteMenu.getItems().add(item);
|
||||||
autoCompleteMenu.show(urlField, javafx.geometry.Side.BOTTOM, 0, 0);
|
autoCompleteMenu.show(urlField, javafx.geometry.Side.BOTTOM, 0, 0);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
autoCompleteMenu.getItems().clear();
|
updateSuggestions(input, urlField);
|
||||||
|
|
||||||
URL_SUGGESTIONS.stream()
|
|
||||||
.filter(domain -> domain.toLowerCase().startsWith(input)
|
|
||||||
|| domain.toLowerCase().contains(input))
|
|
||||||
.sorted((a, b) -> {
|
|
||||||
boolean aStarts = a.startsWith(input);
|
|
||||||
boolean bStarts = b.startsWith(input);
|
|
||||||
return Boolean.compare(!aStarts, !bStarts);
|
|
||||||
})
|
|
||||||
.limit(5)
|
|
||||||
.forEach(domain -> {
|
|
||||||
MenuItem item = new MenuItem(domain);
|
|
||||||
|
|
||||||
item.setOnAction(e -> {
|
|
||||||
urlField.setText("https://" + domain);
|
|
||||||
autoCompleteMenu.hide();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
autoCompleteMenu.getItems().add(item);
|
urlField.focusedProperty()
|
||||||
});
|
.addListener(
|
||||||
|
(obs, oldVal, newVal) -> {
|
||||||
if (!autoCompleteMenu.getItems().isEmpty()) {
|
if (!newVal) {
|
||||||
autoCompleteMenu.show(urlField,
|
autoCompleteMenu.hide();
|
||||||
javafx.geometry.Side.BOTTOM,
|
}
|
||||||
0, 0);
|
});
|
||||||
} else {
|
|
||||||
autoCompleteMenu.hide();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
urlField.focusedProperty().addListener((obs, oldVal, newVal) -> {
|
|
||||||
if (!newVal) autoCompleteMenu.hide();
|
|
||||||
});
|
|
||||||
|
|
||||||
return urlField;
|
return urlField;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the autocomplete suggestions based on the current input in the URL field. Suggestions
|
||||||
|
* are filtered from the list of trusted domains and sorted to prioritize those that start with
|
||||||
|
* the input.
|
||||||
|
*
|
||||||
|
* @param input The current text input from the URL field, used to filter and sort suggestions.
|
||||||
|
* @param urlField The TextField for the URL input, used to position the autocomplete menu and
|
||||||
|
* update its content.
|
||||||
|
*/
|
||||||
|
private static void updateSuggestions(String input, TextField urlField) {
|
||||||
|
autoCompleteMenu.getItems().clear();
|
||||||
|
|
||||||
|
URL_SUGGESTIONS.stream()
|
||||||
|
.filter(
|
||||||
|
domain ->
|
||||||
|
domain.toLowerCase().startsWith(input)
|
||||||
|
|| domain.toLowerCase().contains(input))
|
||||||
|
.sorted(
|
||||||
|
(a, b) -> {
|
||||||
|
boolean aStarts = a.startsWith(input);
|
||||||
|
boolean bStarts = b.startsWith(input);
|
||||||
|
return Boolean.compare(!aStarts, !bStarts);
|
||||||
|
})
|
||||||
|
.limit(MAX_AUTOCOMPLETE_RESULTS)
|
||||||
|
.forEach(
|
||||||
|
domain -> {
|
||||||
|
MenuItem item = new MenuItem(domain);
|
||||||
|
|
||||||
|
item.setOnAction(
|
||||||
|
e -> {
|
||||||
|
urlField.setText("https://" + domain);
|
||||||
|
autoCompleteMenu.hide();
|
||||||
|
});
|
||||||
|
|
||||||
|
autoCompleteMenu.getItems().add(item);
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!autoCompleteMenu.getItems().isEmpty()) {
|
||||||
|
autoCompleteMenu.show(urlField, javafx.geometry.Side.BOTTOM, 0, 0);
|
||||||
|
} else {
|
||||||
|
autoCompleteMenu.hide();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Security Label
|
* Security Label
|
||||||
*
|
*
|
||||||
@@ -534,15 +559,16 @@ public class CasinoBrowserController {
|
|||||||
*/
|
*/
|
||||||
public static void configureUrlEvents(
|
public static void configureUrlEvents(
|
||||||
WebEngine engine, TextField urlField, Label securityLabel) {
|
WebEngine engine, TextField urlField, Label securityLabel) {
|
||||||
urlField.setOnKeyPressed(e -> {
|
urlField.setOnKeyPressed(
|
||||||
if (e.getCode() == KeyCode.ENTER) {
|
e -> {
|
||||||
if (!autoCompleteMenu.isShowing()) {
|
if (e.getCode() == KeyCode.ENTER) {
|
||||||
String resolved = resolveInputToUrl(urlField.getText());
|
if (!autoCompleteMenu.isShowing()) {
|
||||||
urlField.setText(resolved);
|
String resolved = resolveInputToUrl(urlField.getText());
|
||||||
loadUrlSafely(engine, resolved, securityLabel);
|
urlField.setText(resolved);
|
||||||
}
|
loadUrlSafely(engine, resolved, securityLabel);
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
});
|
||||||
engine.locationProperty().addListener((obs, o, n) -> urlField.setText(n));
|
engine.locationProperty().addListener((obs, o, n) -> urlField.setText(n));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -608,13 +634,14 @@ public class CasinoBrowserController {
|
|||||||
String scheme = uri.getScheme();
|
String scheme = uri.getScheme();
|
||||||
|
|
||||||
if ("file".equalsIgnoreCase(scheme)) {
|
if ("file".equalsIgnoreCase(scheme)) {
|
||||||
Path allowed = Paths.get(
|
Path allowed =
|
||||||
System.getProperty("user.dir"),
|
Paths.get(
|
||||||
"documents",
|
System.getProperty("user.dir"),
|
||||||
"docs",
|
"documents",
|
||||||
"game-engine",
|
"docs",
|
||||||
"manual.html"
|
"game-engine",
|
||||||
).normalize();
|
"manual.html")
|
||||||
|
.normalize();
|
||||||
|
|
||||||
Path requested = Paths.get(uri).normalize();
|
Path requested = Paths.get(uri).normalize();
|
||||||
|
|
||||||
@@ -638,8 +665,9 @@ public class CasinoBrowserController {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean trusted = TRUSTED_DOMAINS.stream()
|
boolean trusted =
|
||||||
.anyMatch(domain -> host.equals(domain) || host.endsWith("." + domain));
|
TRUSTED_DOMAINS.stream()
|
||||||
|
.anyMatch(domain -> host.equals(domain) || host.endsWith("." + domain));
|
||||||
|
|
||||||
if (!trusted) {
|
if (!trusted) {
|
||||||
if (!showUnknownWebsiteAlert(host)) {
|
if (!showUnknownWebsiteAlert(host)) {
|
||||||
|
|||||||
+7
-3
@@ -8,9 +8,9 @@ import javafx.fxml.FXML;
|
|||||||
import javafx.scene.control.Label;
|
import javafx.scene.control.Label;
|
||||||
import javafx.scene.image.Image;
|
import javafx.scene.image.Image;
|
||||||
import javafx.scene.image.ImageView;
|
import javafx.scene.image.ImageView;
|
||||||
|
import javafx.scene.layout.HBox;
|
||||||
import javafx.scene.layout.Pane;
|
import javafx.scene.layout.Pane;
|
||||||
import javafx.scene.layout.VBox;
|
import javafx.scene.layout.VBox;
|
||||||
import javafx.scene.layout.HBox;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Controller for displaying a player's status in the poker game, including their name, chip count
|
* Controller for displaying a player's status in the poker game, including their name, chip count
|
||||||
@@ -115,7 +115,10 @@ public class PlayerStatusController {
|
|||||||
* @return true if both represent the same player.
|
* @return true if both represent the same player.
|
||||||
*/
|
*/
|
||||||
public boolean hasPlayer(Player candidate) {
|
public boolean hasPlayer(Player candidate) {
|
||||||
if (player == null || candidate == null || player.getId() == null || candidate.getId() == null) {
|
if (player == null
|
||||||
|
|| candidate == null
|
||||||
|
|| player.getId() == null
|
||||||
|
|| candidate.getId() == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -147,7 +150,8 @@ public class PlayerStatusController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update the visual style of the player status box to indicate whether it's currently this player's turn.
|
* Update the visual style of the player status box to indicate whether it's currently this
|
||||||
|
* player's turn.
|
||||||
*/
|
*/
|
||||||
private void updateTurnHighlightStyle() {
|
private void updateTurnHighlightStyle() {
|
||||||
if (statusInnerBoxTop == null || statusInnerBoxBottom == null) {
|
if (statusInnerBoxTop == null || statusInnerBoxBottom == null) {
|
||||||
|
|||||||
+16
-14
@@ -8,6 +8,8 @@ import ch.unibas.dmi.dbis.cs108.casono.client.game.PlayerId;
|
|||||||
import ch.unibas.dmi.dbis.cs108.casono.client.game.PlayerState;
|
import ch.unibas.dmi.dbis.cs108.casono.client.game.PlayerState;
|
||||||
import ch.unibas.dmi.dbis.cs108.casono.client.network.LobbyClient;
|
import ch.unibas.dmi.dbis.cs108.casono.client.network.LobbyClient;
|
||||||
import ch.unibas.dmi.dbis.cs108.casono.client.ui.lobbyui.Casinomainui;
|
import ch.unibas.dmi.dbis.cs108.casono.client.ui.lobbyui.Casinomainui;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.Paths;
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
import javafx.scene.control.Alert;
|
import javafx.scene.control.Alert;
|
||||||
import javafx.scene.control.Button;
|
import javafx.scene.control.Button;
|
||||||
@@ -20,9 +22,6 @@ import javafx.scene.layout.HBox;
|
|||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
import java.nio.file.Path;
|
|
||||||
import java.nio.file.Paths;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Controller for the interactive taskbar within the poker UI.
|
* Controller for the interactive taskbar within the poker UI.
|
||||||
*
|
*
|
||||||
@@ -930,7 +929,8 @@ public class TaskbarController {
|
|||||||
/**
|
/**
|
||||||
* Calculates the scaled width of the taskbar node based on its current bounds and scale factor.
|
* Calculates the scaled width of the taskbar node based on its current bounds and scale factor.
|
||||||
*
|
*
|
||||||
* @return The scaled width of the taskbar node, ensuring it is non-negative and accounts for the current scale applied to the node.
|
* @return The scaled width of the taskbar node, ensuring it is non-negative and accounts for
|
||||||
|
* the current scale applied to the node.
|
||||||
*/
|
*/
|
||||||
private double scaledNodeWidth() {
|
private double scaledNodeWidth() {
|
||||||
double width = taskbar.getBoundsInLocal().getWidth();
|
double width = taskbar.getBoundsInLocal().getWidth();
|
||||||
@@ -941,9 +941,11 @@ public class TaskbarController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calculates the scaled height of the taskbar node based on its current bounds and scale factor.
|
* Calculates the scaled height of the taskbar node based on its current bounds and scale
|
||||||
|
* factor.
|
||||||
*
|
*
|
||||||
* @return The scaled height of the taskbar node, ensuring it is non-negative and accounts for the current scale applied to the node.
|
* @return The scaled height of the taskbar node, ensuring it is non-negative and accounts for
|
||||||
|
* the current scale applied to the node.
|
||||||
*/
|
*/
|
||||||
private double scaledNodeHeight() {
|
private double scaledNodeHeight() {
|
||||||
double height = taskbar.getBoundsInLocal().getHeight();
|
double height = taskbar.getBoundsInLocal().getHeight();
|
||||||
@@ -1141,18 +1143,18 @@ public class TaskbarController {
|
|||||||
/**
|
/**
|
||||||
* Opens the integrated Casono web browser.
|
* Opens the integrated Casono web browser.
|
||||||
*
|
*
|
||||||
* once the content for strategies and support is available.
|
* <p>once the content for strategies and support is available.
|
||||||
*/
|
*/
|
||||||
@FXML
|
@FXML
|
||||||
private void onBrowserButtonClick() {
|
private void onBrowserButtonClick() {
|
||||||
try {
|
try {
|
||||||
Path path = Paths.get(
|
Path path =
|
||||||
System.getProperty("user.dir"),
|
Paths.get(
|
||||||
"documents",
|
System.getProperty("user.dir"),
|
||||||
"docs",
|
"documents",
|
||||||
"game-engine",
|
"docs",
|
||||||
"manual.html" // Tippfehler korrigiert!
|
"game-engine",
|
||||||
);
|
"manual.html");
|
||||||
|
|
||||||
CasinoBrowserController.open(path.toUri().toString());
|
CasinoBrowserController.open(path.toUri().toString());
|
||||||
|
|
||||||
|
|||||||
+6
-5
@@ -12,8 +12,8 @@ import ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.response.ErrorRes
|
|||||||
import ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.response.dispatcher.ResponseDispatcher;
|
import ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.response.dispatcher.ResponseDispatcher;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.logging.Logger;
|
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
/** Handler for GET_GAME_STATE: returns pot, phase, community cards and per-player info. */
|
/** Handler for GET_GAME_STATE: returns pot, phase, community cards and per-player info. */
|
||||||
public class GetGameStateHandler extends CommandHandler<GetGameStateRequest> {
|
public class GetGameStateHandler extends CommandHandler<GetGameStateRequest> {
|
||||||
@@ -83,8 +83,7 @@ public class GetGameStateHandler extends CommandHandler<GetGameStateRequest> {
|
|||||||
responseDispatcher.dispatch(new GetGameStateResponse(request.getContext(), game, username));
|
responseDispatcher.dispatch(new GetGameStateResponse(request.getContext(), game, username));
|
||||||
|
|
||||||
if (game.getState().getPhase() == GamePhase.FINISHED) {
|
if (game.getState().getPhase() == GamePhase.FINISHED) {
|
||||||
CompletableFuture.delayedExecutor(
|
CompletableFuture.delayedExecutor(FINISHED_CLEANUP_DELAY_SECONDS, TimeUnit.SECONDS)
|
||||||
FINISHED_CLEANUP_DELAY_SECONDS, TimeUnit.SECONDS)
|
|
||||||
.execute(() -> cleanupLobby(lobby, lobbyId));
|
.execute(() -> cleanupLobby(lobby, lobbyId));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -104,8 +103,10 @@ public class GetGameStateHandler extends CommandHandler<GetGameStateRequest> {
|
|||||||
}
|
}
|
||||||
lobby.initGame(null);
|
lobby.initGame(null);
|
||||||
} catch (RuntimeException e) {
|
} catch (RuntimeException e) {
|
||||||
LOGGER.log(Level.WARNING,
|
LOGGER.log(
|
||||||
"Failed to cleanup lobby " + lobbyId + " during FINISHED state", e);
|
Level.WARNING,
|
||||||
|
"Failed to cleanup lobby " + lobbyId + " during FINISHED state",
|
||||||
|
e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user