Fixed a bug that race view doesn't fit in decorator.

- recreated a new stage and decorator to fix the bug as decorator might
not be able to be reused.

#story[1245]
This commit is contained in:
Haoming Yin
2017-09-11 23:42:08 +12:00
parent 0d7201e235
commit d49e84e6d2
3 changed files with 41 additions and 13 deletions
@@ -10,6 +10,7 @@ import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader; import javafx.fxml.FXMLLoader;
import javafx.geometry.Point2D; import javafx.geometry.Point2D;
import javafx.scene.Scene; import javafx.scene.Scene;
import javafx.scene.SubScene;
import javafx.scene.chart.LineChart; import javafx.scene.chart.LineChart;
import javafx.scene.chart.NumberAxis; import javafx.scene.chart.NumberAxis;
import javafx.scene.chart.XYChart; import javafx.scene.chart.XYChart;
@@ -176,7 +177,16 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
updateOrder(raceState.getPlayerPositions()); updateOrder(raceState.getPlayerPositions());
gameView = new GameView3D(); gameView = new GameView3D();
// gameView.setFrameRateFXText(fpsDisplay); // gameView.setFrameRateFXText(fpsDisplay);
Platform.runLater(() -> contentAnchorPane.getChildren().add(0, gameView.getAssets())); Platform.runLater(() -> {
contentAnchorPane.getChildren().add(0, gameView.getAssets());
((SubScene) gameView.getAssets()).widthProperty()
.bind(ViewManager.getInstance().getStage().widthProperty());
((SubScene) gameView.getAssets()).heightProperty()
.bind(ViewManager.getInstance().getStage().heightProperty());
System.out.println(((SubScene) gameView.getAssets()).getHeight());
System.out.println(((SubScene) gameView.getAssets()).getWidth());
});
gameView.setBoats(new ArrayList<>(participants.values())); gameView.setBoats(new ArrayList<>(participants.values()));
gameView.updateBorder(raceData.getCourseLimit()); gameView.updateBorder(raceData.getCourseLimit());
gameView.updateTokens(raceData.getTokens()); gameView.updateTokens(raceData.getTokens());
@@ -34,6 +34,11 @@ public class ViewManager {
private HashMap<String, String> properties; //TODO is this the best way to do this?? private HashMap<String, String> properties; //TODO is this the best way to do this??
private ObservableList<String> playerList; private ObservableList<String> playerList;
private Logger logger = LoggerFactory.getLogger(ViewManager.class); private Logger logger = LoggerFactory.getLogger(ViewManager.class);
public Stage getStage() {
return stage;
}
private Stage stage; private Stage stage;
private ViewManager() { private ViewManager() {
@@ -170,21 +175,31 @@ public class ViewManager {
Platform.runLater(() -> { Platform.runLater(() -> {
try { try {
stage.close(); stage.close();
stage = new Stage();
Scene scene = new Scene(loader.load()); JFXDecorator decorator = new JFXDecorator(stage, loader.load(), false, true, true);
decorator.setCustomMaximize(true);
decorator.applyCss();
decorator.getStylesheets()
.add(getClass().getResource("/css/master.css").toExternalForm());
Scene scene = new Scene(decorator);
// set key press event to catch key stoke // set key press event to catch key stoke
scene.setOnKeyPressed(gameClient::keyPressed); scene.setOnKeyPressed(gameClient::keyPressed);
scene.setOnKeyReleased(gameClient::keyReleased); scene.setOnKeyReleased(gameClient::keyReleased);
Rectangle2D visualBounds = Screen.getPrimary().getVisualBounds(); // uncomment to make it full screen
stage = new Stage(); // Rectangle2D visualBounds = Screen.getPrimary().getVisualBounds();
// stage.setX(visualBounds.getMinX());
// stage.setY(visualBounds.getMinY());
// stage.setWidth(visualBounds.getWidth());
// stage.setHeight(visualBounds.getHeight());
// stage.setMaximized(true);
// stage.setFullScreen(true);
stage.setMinHeight(500);
stage.setMinWidth(800);
stage.setOnCloseRequest(e -> closeAll()); stage.setOnCloseRequest(e -> closeAll());
stage.setX(visualBounds.getMinX());
stage.setY(visualBounds.getMinY());
stage.setWidth(visualBounds.getWidth());
stage.setHeight(visualBounds.getHeight());
stage.setMaximized(true);
stage.setFullScreen(true);
stage.setScene(scene); stage.setScene(scene);
stage.show(); stage.show();
} catch (Exception e) { } catch (Exception e) {
+6 -3
View File
@@ -5,12 +5,15 @@
<?import javafx.scene.layout.*?> <?import javafx.scene.layout.*?>
<AnchorPane fx:id="rvAnchorPane" maxHeight="1.7976931348623157E308" <AnchorPane fx:id="rvAnchorPane" maxHeight="1.7976931348623157E308"
maxWidth="1.7976931348623157E308" minHeight="-Infinity" minWidth="-Infinity" prefHeight="600.0" maxWidth="1.7976931348623157E308" minHeight="-Infinity" minWidth="-Infinity" prefHeight="800.0"
prefWidth="800.0" style="-fx-background-color: skyblue;" xmlns="http://javafx.com/javafx/8" prefWidth="1200.0" style="-fx-background-color: skyblue;" xmlns="http://javafx.com/javafx/8"
xmlns:fx="http://javafx.com/fxml/1" xmlns:fx="http://javafx.com/fxml/1"
fx:controller="seng302.visualiser.controllers.RaceViewController"> fx:controller="seng302.visualiser.controllers.RaceViewController">
<children> <children>
<StackPane fx:id="contentAnchorPane" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0"> <StackPane fx:id="contentAnchorPane" maxHeight="1.7976931348623157E308"
maxWidth="1.7976931348623157E308" prefHeight="800.0" prefWidth="1200.0"
AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0"
AnchorPane.topAnchor="0.0">
</StackPane> </StackPane>
<GridPane AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0"> <GridPane AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">