Files
Progetto-ingegneria-del-sof…/deliverables/Coverage/htmReport/ns-12/sources/source-2.html
T
2026-06-19 22:57:43 +02:00

395 lines
16 KiB
HTML

<!DOCTYPE html>
<html id="htmlId">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>Coverage Report > GUI</title>
<style type="text/css">
@import "../../css/coverage.css";
@import "../../css/idea.min.css";
</style>
<script type="text/javascript" src="../../js/highlight.min.js"></script>
<script type="text/javascript" src="../../js/highlightjs-line-numbers.min.js"></script>
</head>
<body>
<div class="content">
<div class="breadCrumbs">
Current scope: <a href="../../index.html">all classes</a>
<span class="separator">|</span>
<a href="../index.html">it.polimi.ingsw.gc14.View.GUI</a>
</div>
<h1>Coverage Summary for Class: GUI (it.polimi.ingsw.gc14.View.GUI)</h1>
<table class="coverageStats">
<tr>
<th class="name">Class</th>
<th class="coverageStat
">
Class, %
</th>
<th class="coverageStat
">
Method, %
</th>
<th class="coverageStat
">
Branch, %
</th>
<th class="coverageStat
">
Line, %
</th>
</tr>
<tr>
<td class="name">GUI</td>
<td class="coverageStat">
<span class="percent">
0%
</span>
<span class="absValue">
(0/1)
</span>
</td>
<td class="coverageStat">
<span class="percent">
0%
</span>
<span class="absValue">
(0/16)
</span>
</td>
<td class="coverageStat">
<span class="percent">
0%
</span>
<span class="absValue">
(0/22)
</span>
</td>
<td class="coverageStat">
<span class="percent">
0%
</span>
<span class="absValue">
(0/110)
</span>
</td>
</tr>
</table>
<br/>
<br/>
<pre>
<code class="sourceCode" id="sourceCode">&nbsp;package it.polimi.ingsw.gc14.View.GUI;
&nbsp;
&nbsp;import it.polimi.ingsw.gc14.Controller.ClientController;
&nbsp;import it.polimi.ingsw.gc14.ErrorType;
&nbsp;import it.polimi.ingsw.gc14.Model.MiniModel;
&nbsp;import it.polimi.ingsw.gc14.View.IView;
&nbsp;import javafx.animation.FadeTransition;
&nbsp;import javafx.application.Application;
&nbsp;import javafx.application.Platform;
&nbsp;import javafx.fxml.FXMLLoader;
&nbsp;import javafx.geometry.Rectangle2D;
&nbsp;import javafx.scene.Parent;
&nbsp;import javafx.scene.Scene;
&nbsp;import javafx.scene.input.KeyCode;
&nbsp;import javafx.scene.input.KeyEvent;
&nbsp;import javafx.scene.input.KeyCombination;
&nbsp;import javafx.scene.layout.StackPane;
&nbsp;
&nbsp;import javafx.scene.paint.Color;
&nbsp;import javafx.scene.shape.Rectangle;
&nbsp;import javafx.stage.Screen;
&nbsp;import javafx.stage.Stage;
&nbsp;import javafx.util.Duration;
&nbsp;
&nbsp;import static it.polimi.ingsw.gc14.Model.GamePackage.GameStages.ENDED;
&nbsp;import static it.polimi.ingsw.gc14.Model.GamePackage.GameStages.TOTEM_CHOICE;
&nbsp;
&nbsp;/**
&nbsp; * JavaFX-based GUI implementation of {@link it.polimi.ingsw.gc14.View.IView IView}.
&nbsp; *
&nbsp; * &lt;p&gt;Manages the primary stage and switches between the login, totem choice,
&nbsp; * main game, and leaderboard scenes based on the current game state.
&nbsp; */
<b class="nc">&nbsp;public class GUI extends Application implements IView {</b>
&nbsp; /** The primary JavaFX stage. */
&nbsp; private Stage primaryStage;
&nbsp; /** Latest mini model received from the server. */
&nbsp; private volatile MiniModel miniModel;
&nbsp; /** FXML loader for the login scene. */
&nbsp; private FXMLLoader loaderLogin;
&nbsp; /** The login scene. */
&nbsp; private Scene loginScene;
&nbsp; /** Controller for the login FXML scene. */
&nbsp; private LoginFXMLController controllerLogin;
&nbsp; /** FXML loader for the totem selection scene. */
&nbsp; private FXMLLoader loaderTotem;
&nbsp; /** The totem selection scene. */
&nbsp; private Scene totemScene;
&nbsp; /** Controller for the totem FXML scene. */
&nbsp; private TotemFXMLController controllerTotem;
&nbsp; /** FXML loader for the main game scene. */
&nbsp; private FXMLLoader loaderMain;
&nbsp; /** The main game scene. */
&nbsp; private Scene mainScene;
&nbsp; /** Controller for the main FXML scene. */
&nbsp; private MainFXMLController controllerMain;
&nbsp; /** FXML loader for the leaderboard scene. */
&nbsp; private FXMLLoader loaderLeaderboard;
&nbsp; /** The end-of-game leaderboard scene. */
&nbsp; private Scene leaderboardScene;
&nbsp; /** Controller for the leaderboard FXML scene. */
&nbsp; private LeaderboardFXMLController controllerLeaderboard;
&nbsp; /** Client controller injected before JavaFX startup. */
&nbsp; private ClientController controller;
&nbsp; /** When {@code true}, the app re-enters fullscreen automatically after ESC is pressed. */
<b class="nc">&nbsp; private boolean autoReenterFullscreen = true;</b>
&nbsp; /** Guards against overlapping fade transitions. */
<b class="nc">&nbsp; private boolean isFading = false;</b>
&nbsp;
&nbsp;
&nbsp; /**
&nbsp; * JavaFX entry point: loads all FXML scenes, wires up controllers,
&nbsp; * configures fullscreen behavior, and shows the login scene.
&nbsp; *
&nbsp; * @param stage the primary stage provided by the JavaFX runtime.
&nbsp; * @throws Exception if any FXML resource cannot be loaded.
&nbsp; */
&nbsp; @Override
&nbsp; public void start(Stage stage) throws Exception {
<b class="nc">&nbsp; this.primaryStage = stage;</b>
<b class="nc">&nbsp; loaderLogin = new FXMLLoader(getClass().getResource(&quot;/GUIScene/login.fxml&quot;));</b>
<b class="nc">&nbsp; loginScene = new Scene(loaderLogin.load());</b>
<b class="nc">&nbsp; controllerLogin = loaderLogin.getController();</b>
<b class="nc">&nbsp; controllerLogin.setController(controller);</b>
&nbsp;
&nbsp;
<b class="nc">&nbsp; loaderTotem = new FXMLLoader(getClass().getResource(&quot;/GUIScene/totem.fxml&quot;));</b>
<b class="nc">&nbsp; totemScene = new Scene(loaderTotem.load());</b>
<b class="nc">&nbsp; controllerTotem = loaderTotem.getController();</b>
<b class="nc">&nbsp; controllerTotem.setController(controller);</b>
&nbsp;
&nbsp;
<b class="nc">&nbsp; loaderMain = new FXMLLoader(getClass().getResource(&quot;/GUIScene/main.fxml&quot;));</b>
<b class="nc">&nbsp; mainScene = new Scene(loaderMain.load());</b>
<b class="nc">&nbsp; controllerMain = loaderMain.getController();</b>
<b class="nc">&nbsp; controllerMain.setController(controller);</b>
&nbsp;
<b class="nc">&nbsp; loaderLeaderboard = new FXMLLoader(getClass().getResource(&quot;/GUIScene/standing.fxml&quot;));</b>
<b class="nc">&nbsp; leaderboardScene = new Scene(loaderLeaderboard.load());</b>
<b class="nc">&nbsp; controllerLeaderboard = loaderLeaderboard.getController();</b>
<b class="nc">&nbsp; controllerLeaderboard.setController(controller, () -&gt; {</b>
<b class="nc">&nbsp; controllerLogin.updateLoginButton(true);</b>
<b class="nc">&nbsp; controllerLogin.showError(&quot;&quot;);</b>
<b class="nc">&nbsp; fadeToScene(loginScene);</b>
&nbsp; });
&nbsp;
&nbsp;
&nbsp;
&nbsp;
&nbsp;
<b class="nc">&nbsp; wrapScene(loginScene);</b>
<b class="nc">&nbsp; wrapScene(totemScene);</b>
<b class="nc">&nbsp; wrapScene(mainScene);</b>
<b class="nc">&nbsp; wrapScene(leaderboardScene);</b>
&nbsp;
<b class="nc">&nbsp; FireParticleSystem fireParticles = new FireParticleSystem(mainScene);</b>
<b class="nc">&nbsp; ((StackPane) mainScene.getRoot()).getChildren().add(fireParticles.getPane());</b>
<b class="nc">&nbsp; fireParticles.start();</b>
&nbsp;
<b class="nc">&nbsp; primaryStage.setScene(loginScene);</b>
<b class="nc">&nbsp; Rectangle2D tmp = Screen.getPrimary().getVisualBounds();</b>
<b class="nc">&nbsp; primaryStage.setWidth(tmp.getWidth());</b>
<b class="nc">&nbsp; primaryStage.setHeight(tmp.getHeight());</b>
<b class="nc">&nbsp; primaryStage.setX(tmp.getMinX());</b>
<b class="nc">&nbsp; primaryStage.setY(tmp.getMinY());</b>
<b class="nc">&nbsp; primaryStage.setResizable(false);</b>
<b class="nc">&nbsp; primaryStage.setFullScreenExitHint(&quot;&quot;);</b>
<b class="nc">&nbsp; primaryStage.setFullScreenExitKeyCombination(KeyCombination.NO_MATCH);</b>
&nbsp;
<b class="nc">&nbsp; primaryStage.fullScreenProperty().addListener((obs, was, isNow) -&gt; {</b>
<b class="nc">&nbsp; if (!isNow &amp;&amp; autoReenterFullscreen) {</b>
<b class="nc">&nbsp; Platform.runLater(() -&gt; primaryStage.setFullScreen(true));</b>
&nbsp; }
&nbsp; });
&nbsp;
<b class="nc">&nbsp; primaryStage.addEventFilter(KeyEvent.KEY_PRESSED, e -&gt; {</b>
<b class="nc">&nbsp; if (e.getCode() == KeyCode.ESCAPE) {</b>
<b class="nc">&nbsp; autoReenterFullscreen = false;</b>
<b class="nc">&nbsp; primaryStage.setFullScreen(false);</b>
<b class="nc">&nbsp; e.consume();</b>
<b class="nc">&nbsp; } else if (e.getCode() == KeyCode.F11) {</b>
<b class="nc">&nbsp; autoReenterFullscreen = true;</b>
<b class="nc">&nbsp; primaryStage.setFullScreen(true);</b>
<b class="nc">&nbsp; e.consume();</b>
&nbsp; }
&nbsp; });
&nbsp;
<b class="nc">&nbsp; primaryStage.setTitle(&quot;Mesos&quot;);</b>
<b class="nc">&nbsp; primaryStage.setOnCloseRequest(e -&gt; {</b>
<b class="nc">&nbsp; Platform.exit();</b>
<b class="nc">&nbsp; System.exit(0);</b>
&nbsp; });
<b class="nc">&nbsp; primaryStage.show();</b>
<b class="nc">&nbsp; Platform.runLater(() -&gt; primaryStage.setFullScreen(true));</b>
&nbsp;
&nbsp; }
&nbsp;
&nbsp;
&nbsp; /**
&nbsp; * Updates the local mini model reference used by the GUI.
&nbsp; *
&nbsp; * @param miniModel the latest mini model received from the server.
&nbsp; */
&nbsp; @Override
&nbsp; public void setModel(MiniModel miniModel) {
<b class="nc">&nbsp; this.miniModel = miniModel;</b>
&nbsp; }
&nbsp;
&nbsp; /**
&nbsp; * Injects the client controller into this GUI.
&nbsp; *
&nbsp; * @param controller the client controller to use.
&nbsp; */
&nbsp; public void setController(ClientController controller) {
<b class="nc">&nbsp; this.controller=controller;</b>
&nbsp; }
&nbsp;
&nbsp; /**
&nbsp; * Re-renders the GUI on the JavaFX application thread, switching to the
&nbsp; * appropriate scene based on the current game stage.
&nbsp; */
&nbsp; public void render() {
<b class="nc">&nbsp; Platform.runLater(() -&gt; {</b>
<b class="nc">&nbsp; if (miniModel == null) return;</b>
<b class="nc">&nbsp; if (controller.getMiniModel().currentState.getGameStage() == TOTEM_CHOICE) {</b>
<b class="nc">&nbsp; controllerTotem.render();</b>
<b class="nc">&nbsp; fadeToScene(totemScene);</b>
<b class="nc">&nbsp; } else if (controller.getMiniModel().currentState.getGameStage() == ENDED) {</b>
<b class="nc">&nbsp; controllerLeaderboard.render();</b>
<b class="nc">&nbsp; fadeToScene(leaderboardScene);</b>
&nbsp; } else {
<b class="nc">&nbsp; controllerMain.render();</b>
<b class="nc">&nbsp; fadeToScene(mainScene);</b>
&nbsp; }
&nbsp; });
&nbsp; }
&nbsp; /**
&nbsp; * Wraps the current root of {@code scene} in a {@link StackPane} so that
&nbsp; * fade overlay rectangles can be layered over it during scene transitions.
&nbsp; *
&nbsp; * @param scene the scene whose root to wrap.
&nbsp; */
&nbsp; private void wrapScene(Scene scene) {
<b class="nc">&nbsp; Parent root = scene.getRoot();</b>
<b class="nc">&nbsp; scene.setRoot(new StackPane(root));</b>
&nbsp; }
&nbsp; /**
&nbsp; * Performs a black-overlay crossfade from the current scene to {@code newScene}.
&nbsp; * No-op if already fading or if {@code newScene} is already displayed.
&nbsp; *
&nbsp; * @param newScene the scene to transition to.
&nbsp; */
&nbsp; private void fadeToScene(Scene newScene) {
<b class="nc">&nbsp; Scene currentScene = primaryStage.getScene();</b>
<b class="nc">&nbsp; if (currentScene == newScene || isFading) return;</b>
<b class="nc">&nbsp; isFading = true;</b>
&nbsp;
<b class="nc">&nbsp; StackPane currentRoot = (StackPane) currentScene.getRoot();</b>
<b class="nc">&nbsp; Rectangle overlay = new Rectangle();</b>
<b class="nc">&nbsp; overlay.setFill(Color.BLACK);</b>
<b class="nc">&nbsp; overlay.setOpacity(0);</b>
<b class="nc">&nbsp; overlay.widthProperty().bind(currentRoot.widthProperty());</b>
<b class="nc">&nbsp; overlay.heightProperty().bind(currentRoot.heightProperty());</b>
<b class="nc">&nbsp; currentRoot.getChildren().add(overlay);</b>
&nbsp;
<b class="nc">&nbsp; FadeTransition fadeOut = new FadeTransition(Duration.millis(500), overlay);</b>
<b class="nc">&nbsp; fadeOut.setFromValue(0);</b>
<b class="nc">&nbsp; fadeOut.setToValue(1);</b>
<b class="nc">&nbsp; fadeOut.setOnFinished(e -&gt; {</b>
<b class="nc">&nbsp; currentRoot.getChildren().remove(overlay);</b>
&nbsp;
<b class="nc">&nbsp; StackPane newRoot = (StackPane) newScene.getRoot();</b>
<b class="nc">&nbsp; Rectangle newOverlay = new Rectangle();</b>
<b class="nc">&nbsp; newOverlay.setFill(Color.BLACK);</b>
<b class="nc">&nbsp; newOverlay.setOpacity(1);</b>
<b class="nc">&nbsp; newOverlay.widthProperty().bind(newRoot.widthProperty());</b>
<b class="nc">&nbsp; newOverlay.heightProperty().bind(newRoot.heightProperty());</b>
<b class="nc">&nbsp; newRoot.getChildren().add(newOverlay);</b>
&nbsp;
<b class="nc">&nbsp; primaryStage.setScene(newScene);</b>
&nbsp;
<b class="nc">&nbsp; FadeTransition fadeIn = new FadeTransition(Duration.millis(500), newOverlay);</b>
<b class="nc">&nbsp; fadeIn.setFromValue(1);</b>
<b class="nc">&nbsp; fadeIn.setToValue(0);</b>
<b class="nc">&nbsp; fadeIn.setOnFinished(ev -&gt; {</b>
<b class="nc">&nbsp; newRoot.getChildren().remove(newOverlay);</b>
<b class="nc">&nbsp; isFading = false;</b>
&nbsp; });
<b class="nc">&nbsp; fadeIn.play();</b>
&nbsp; });
<b class="nc">&nbsp; fadeOut.play();</b>
&nbsp; }
&nbsp;
&nbsp; /**
&nbsp; * Displays an error on the JavaFX application thread.
&nbsp; *
&nbsp; * &lt;p&gt;If the server crashed, returns to the login scene and re-enables the login button.
&nbsp; * Otherwise, delegates to the active scene&#39;s error display.
&nbsp; *
&nbsp; * @param error the error type.
&nbsp; * @param message a human-readable description of the error.
&nbsp; */
&nbsp; @Override
&nbsp; public void showError(ErrorType error,String message) {
<b class="nc">&nbsp; Platform.runLater(() -&gt; {</b>
<b class="nc">&nbsp; if (error == ErrorType.SERVER_CRASHED) {</b>
<b class="nc">&nbsp; controllerLogin.updateLoginButton(true);</b>
<b class="nc">&nbsp; controllerLogin.showError(error);</b>
<b class="nc">&nbsp; fadeToScene(loginScene);</b>
&nbsp; } else {
<b class="nc">&nbsp; if (miniModel == null) return;</b>
<b class="nc">&nbsp; controllerMain.setError(true);</b>
<b class="nc">&nbsp; controllerMain.render();</b>
&nbsp; }
&nbsp; });
&nbsp; }
&nbsp;
&nbsp;}
</code>
</pre>
</div>
<script type="text/javascript">
(function() {
var msie = false, msie9 = false;
/*@cc_on
msie = true;
@if (@_jscript_version >= 9)
msie9 = true;
@end
@*/
if (!msie || msie && msie9) {
hljs.highlightAll()
hljs.initLineNumbersOnLoad();
}
})();
</script>
<div class="footer">
<div style="float:right;">generated on 2026-06-19 22:53</div>
</div>
</body>
</html>