Changes to code to use new controller structure.
- renamed javadoc referencing old controllers - keybindings no longer need to be static - finished lobby and lobbyhost controllers #story[1261]
This commit is contained in:
@@ -15,7 +15,7 @@ import java.util.ResourceBundle;
|
||||
/**
|
||||
* Controls the connection that the VIsualiser can connect to.
|
||||
*/
|
||||
public class ConnectionController extends Controller2 {
|
||||
public class ConnectionController extends Controller {
|
||||
@FXML AnchorPane connectionWrapper;
|
||||
@FXML TableView<RaceConnection> connectionTable;
|
||||
@FXML TableColumn<RaceConnection, String> hostnameColumn;
|
||||
|
||||
+3
-3
@@ -15,7 +15,7 @@ import java.io.IOException;
|
||||
* Abstract controller class to give each subclass the functionality to load
|
||||
* a new scene into the existing stage, or create a new popup window.
|
||||
*/
|
||||
public abstract class Controller2 {
|
||||
public abstract class Controller {
|
||||
Stage stage = App.getStage();
|
||||
|
||||
protected void loadTitleScreen() throws IOException {
|
||||
@@ -33,7 +33,7 @@ public abstract class Controller2 {
|
||||
* @return the controller of the new scene
|
||||
* @throws IOException if there is an issue with the fxmlUrl
|
||||
*/
|
||||
protected Controller2 loadScene(String fxmlUrl) throws IOException {
|
||||
protected Controller loadScene(String fxmlUrl) throws IOException {
|
||||
// load the correct fxml file
|
||||
FXMLLoader loader = new FXMLLoader();
|
||||
loader.setLocation(getClass().getResource
|
||||
@@ -66,7 +66,7 @@ public abstract class Controller2 {
|
||||
* @return the controller of the new scene
|
||||
* @throws IOException if there is an issue with the fxmlUrl
|
||||
*/
|
||||
protected Controller2 loadPopupScene(String fxmlUrl, String title, Modality
|
||||
protected Controller loadPopupScene(String fxmlUrl, String title, Modality
|
||||
modality) throws IOException {
|
||||
// load the correct fxml scene
|
||||
FXMLLoader loader = new FXMLLoader();
|
||||
@@ -3,9 +3,6 @@ package visualiser.Controllers;
|
||||
import javafx.application.Platform;
|
||||
import javafx.event.EventHandler;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.scene.Parent;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.ListView;
|
||||
import javafx.scene.input.KeyCode;
|
||||
@@ -21,12 +18,10 @@ import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static visualiser.app.App.keyFactory;
|
||||
|
||||
/**
|
||||
* Controller for the scene used to display and update current key bindings.
|
||||
*/
|
||||
public class KeyBindingsController extends Controller2 {
|
||||
public class KeyBindingsController extends Controller {
|
||||
private @FXML Button btnSave;
|
||||
private @FXML Button btnCancel;
|
||||
private @FXML Button btnReset;
|
||||
@@ -34,12 +29,15 @@ public class KeyBindingsController extends Controller2 {
|
||||
private @FXML ListView lstKey;
|
||||
private @FXML ListView lstDescription;
|
||||
private @FXML AnchorPane anchor;
|
||||
private KeyFactory existingKeyFactory;
|
||||
private KeyFactory newKeyFactory;
|
||||
private Boolean changed = false; // keyBindings have been modified
|
||||
private Button currentButton = null; // last button clicked
|
||||
|
||||
public void initialize(){
|
||||
// create new key factory to modify, keeping the existing one safe
|
||||
existingKeyFactory = new KeyFactory();
|
||||
existingKeyFactory.load();
|
||||
newKeyFactory = copyExistingFactory();
|
||||
initializeTable();
|
||||
populateTable();
|
||||
@@ -106,7 +104,7 @@ public class KeyBindingsController extends Controller2 {
|
||||
*/
|
||||
public KeyFactory copyExistingFactory(){
|
||||
newKeyFactory = new KeyFactory();
|
||||
Map<String, ControlKey> oldKeyState = keyFactory.getKeyState();
|
||||
Map<String, ControlKey> oldKeyState = existingKeyFactory.getKeyState();
|
||||
Map<String, ControlKey> newKeyState = new HashMap<>();
|
||||
|
||||
// copy over commands and their keys
|
||||
@@ -204,10 +202,10 @@ public class KeyBindingsController extends Controller2 {
|
||||
*/
|
||||
public void save(){
|
||||
if (isFactoryValid()) {
|
||||
keyFactory = newKeyFactory;
|
||||
existingKeyFactory = newKeyFactory;
|
||||
newKeyFactory = new KeyFactory();
|
||||
changed = false;
|
||||
keyFactory.save(); // save persistently
|
||||
existingKeyFactory.save(); // save persistently
|
||||
loadNotification("Key bindings were successfully saved.", false);
|
||||
} else {
|
||||
loadNotification("One or more key bindings are missing. " +
|
||||
@@ -251,22 +249,14 @@ public class KeyBindingsController extends Controller2 {
|
||||
* @param warning true if the message to be displayed is due to user error
|
||||
*/
|
||||
public void loadNotification(String message, Boolean warning){
|
||||
Parent root = null;
|
||||
FXMLLoader loader = new FXMLLoader(getClass().getResource
|
||||
("/visualiser/scenes/notification.fxml"));
|
||||
try {
|
||||
root = loader.load();
|
||||
NotificationController nc = (NotificationController)
|
||||
loadPopupScene("notification.fxml",
|
||||
"", Modality.APPLICATION_MODAL);
|
||||
nc.setMessage(message, warning);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
NotificationController controller = loader.getController();
|
||||
Stage stage = new Stage();
|
||||
stage.setScene(new Scene(root));
|
||||
stage.centerOnScreen();
|
||||
stage.initModality(Modality.APPLICATION_MODAL);
|
||||
stage.show();
|
||||
// displays given message in the window
|
||||
controller.setMessage(message, warning);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ import java.net.Socket;
|
||||
/**
|
||||
* Controller for the Lobby for entering games
|
||||
*/
|
||||
public class LobbyController extends Controller2 {
|
||||
public class LobbyController extends Controller {
|
||||
private @FXML TableView<RaceConnection> lobbyTable;
|
||||
private @FXML TableColumn<RaceConnection, String> gameNameColumn;
|
||||
private @FXML TableColumn<RaceConnection, String> hostNameColumn;
|
||||
|
||||
@@ -28,7 +28,7 @@ import java.util.logging.Logger;
|
||||
/**
|
||||
* Controller for Hosting a game.
|
||||
*/
|
||||
public class LobbyHostingController extends Controller2 {
|
||||
public class LobbyHostingController extends Controller {
|
||||
private @FXML ImageView imageView;
|
||||
private @FXML AnchorPane imagePane;
|
||||
private @FXML SplitPane splitPane;
|
||||
|
||||
@@ -9,7 +9,7 @@ import javafx.stage.Stage;
|
||||
/**
|
||||
* Controller for a popup notification regarding user activity.
|
||||
*/
|
||||
public class NotificationController {
|
||||
public class NotificationController extends Controller{
|
||||
private @FXML Label lblDescription;
|
||||
private @FXML Text txtMessage;
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ import visualiser.model.VisualiserBoat;
|
||||
/**
|
||||
* Finish Screen for when the race finishes.
|
||||
*/
|
||||
public class RaceFinishController extends Controller2 {
|
||||
public class RaceFinishController extends Controller {
|
||||
private @FXML TableView<VisualiserBoat> boatInfoTable;
|
||||
private @FXML TableColumn<VisualiserBoat, String> boatRankColumn;
|
||||
private @FXML TableColumn<VisualiserBoat, String> boatNameColumn;
|
||||
|
||||
@@ -22,7 +22,7 @@ import java.util.logging.Logger;
|
||||
/**
|
||||
* Controller to for waiting for the race to start.
|
||||
*/
|
||||
public class RaceStartController extends Controller2 {
|
||||
public class RaceStartController extends Controller {
|
||||
private @FXML Label raceTitleLabel;
|
||||
private @FXML Label raceStartLabel;
|
||||
private @FXML Label timeZoneTime;
|
||||
|
||||
@@ -32,7 +32,7 @@ import java.util.logging.Logger;
|
||||
/**
|
||||
* Controller used to display a running race.
|
||||
*/
|
||||
public class RaceViewController extends Controller2 {
|
||||
public class RaceViewController extends Controller {
|
||||
private VisualiserRaceEvent visualiserRace;
|
||||
private VisualiserRaceState raceState;
|
||||
private ControllerClient controllerClient;
|
||||
|
||||
@@ -12,7 +12,7 @@ import java.io.IOException;
|
||||
* burger-boat and comic sans styling to allure and entice users into playing
|
||||
* the game.
|
||||
*/
|
||||
public class TitleController extends Controller2 {
|
||||
public class TitleController extends Controller {
|
||||
private @FXML RadioButton dayModeRD;
|
||||
private @FXML RadioButton nightModeRD;
|
||||
|
||||
|
||||
@@ -27,19 +27,16 @@ import javafx.stage.StageStyle;
|
||||
import javafx.stage.WindowEvent;
|
||||
import javafx.util.Duration;
|
||||
import mock.app.Event;
|
||||
import visualiser.gameController.Keys.KeyFactory;
|
||||
|
||||
public class App extends Application {
|
||||
|
||||
private static Stage stage;
|
||||
public static Event game;
|
||||
private Pane splashLayout;
|
||||
private ProgressBar loadProgress;
|
||||
private Label progressText;
|
||||
private static final int SPLASH_WIDTH = 676;
|
||||
private static final int SPLASH_HEIGHT = 227;
|
||||
public static KeyFactory keyFactory;
|
||||
public static App app = new App();
|
||||
public static Event game;
|
||||
|
||||
|
||||
/**
|
||||
* Entry point for running the programme
|
||||
@@ -51,10 +48,6 @@ public class App extends Application {
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
// load the user's personalised key bindings
|
||||
keyFactory = new KeyFactory();
|
||||
keyFactory.load();
|
||||
|
||||
ImageView splash = new ImageView(new Image(
|
||||
getClass().getClassLoader().getResourceAsStream("images/splashScreen.png")
|
||||
));
|
||||
|
||||
@@ -3,15 +3,14 @@ package visualiser.gameController;
|
||||
import javafx.animation.AnimationTimer;
|
||||
import javafx.scene.Scene;
|
||||
import visualiser.gameController.Keys.ControlKey;
|
||||
|
||||
import visualiser.gameController.Keys.KeyFactory;
|
||||
import java.util.HashMap;
|
||||
|
||||
import static visualiser.app.App.keyFactory;
|
||||
|
||||
/**
|
||||
* Class for checking what keys are currently being used
|
||||
*/
|
||||
public class InputChecker {
|
||||
private KeyFactory keyFactory;
|
||||
private HashMap<String, Boolean> currentlyActiveKeys = new HashMap<>();
|
||||
|
||||
/**
|
||||
@@ -19,7 +18,8 @@ public class InputChecker {
|
||||
* @param scene Scene the controller is to run in parallel with.
|
||||
*/
|
||||
public void runWithScene(Scene scene){
|
||||
// KeyFactory keyFactory = KeyFactory.getFactory();
|
||||
KeyFactory keyFactory = new KeyFactory();
|
||||
keyFactory.load();
|
||||
|
||||
scene.setOnKeyPressed(event -> {
|
||||
String codeString = event.getCode().toString();
|
||||
|
||||
@@ -15,7 +15,7 @@ import java.util.Map;
|
||||
* Class that processes user selected annotation visibility options to
|
||||
* display the requested information on the
|
||||
* {@link ResizableRaceCanvas}. These are displayed
|
||||
* via the {@link visualiser.Controllers.RaceController}. <br>
|
||||
* via the {@link visualiser.Controllers.RaceViewController}. <br>
|
||||
* Annotation options for a {@link VisualiserBoat} include: its name,
|
||||
* abbreviation, speed, the time since it passed the last
|
||||
* {@link shared.model.Mark}, estimated time to the next marker,
|
||||
|
||||
@@ -18,7 +18,7 @@ import java.util.List;
|
||||
/**
|
||||
* This JavaFX Canvas is used to update and display details for a
|
||||
* {@link RaceMap} via the
|
||||
* {@link visualiser.Controllers.RaceController}.<br>
|
||||
* {@link visualiser.Controllers.RaceViewController}.<br>
|
||||
* It fills it's parent and cannot be downsized. <br>
|
||||
* Details displayed include:
|
||||
* {@link VisualiserBoat}s (and their
|
||||
|
||||
@@ -21,7 +21,7 @@ import java.util.Map;
|
||||
* placing position as they complete each {@link shared.model.Leg} by
|
||||
* passing a course {@link shared.model.Mark}. <br>
|
||||
* This sparkline is displayed using the
|
||||
* {@link visualiser.Controllers.RaceController}.
|
||||
* {@link visualiser.Controllers.RaceViewController}.
|
||||
*/
|
||||
public class Sparkline {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user