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]
main
Jessica Syder 8 years ago
parent a5050b8ea8
commit 0dff85006a

@ -15,7 +15,7 @@ import java.util.ResourceBundle;
/** /**
* Controls the connection that the VIsualiser can connect to. * Controls the connection that the VIsualiser can connect to.
*/ */
public class ConnectionController extends Controller2 { public class ConnectionController extends Controller {
@FXML AnchorPane connectionWrapper; @FXML AnchorPane connectionWrapper;
@FXML TableView<RaceConnection> connectionTable; @FXML TableView<RaceConnection> connectionTable;
@FXML TableColumn<RaceConnection, String> hostnameColumn; @FXML TableColumn<RaceConnection, String> hostnameColumn;

@ -15,7 +15,7 @@ import java.io.IOException;
* Abstract controller class to give each subclass the functionality to load * Abstract controller class to give each subclass the functionality to load
* a new scene into the existing stage, or create a new popup window. * 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(); Stage stage = App.getStage();
protected void loadTitleScreen() throws IOException { protected void loadTitleScreen() throws IOException {
@ -33,7 +33,7 @@ public abstract class Controller2 {
* @return the controller of the new scene * @return the controller of the new scene
* @throws IOException if there is an issue with the fxmlUrl * @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 // load the correct fxml file
FXMLLoader loader = new FXMLLoader(); FXMLLoader loader = new FXMLLoader();
loader.setLocation(getClass().getResource loader.setLocation(getClass().getResource
@ -66,7 +66,7 @@ public abstract class Controller2 {
* @return the controller of the new scene * @return the controller of the new scene
* @throws IOException if there is an issue with the fxmlUrl * @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 { modality) throws IOException {
// load the correct fxml scene // load the correct fxml scene
FXMLLoader loader = new FXMLLoader(); FXMLLoader loader = new FXMLLoader();

@ -3,9 +3,6 @@ package visualiser.Controllers;
import javafx.application.Platform; import javafx.application.Platform;
import javafx.event.EventHandler; import javafx.event.EventHandler;
import javafx.fxml.FXML; 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.Button;
import javafx.scene.control.ListView; import javafx.scene.control.ListView;
import javafx.scene.input.KeyCode; import javafx.scene.input.KeyCode;
@ -21,12 +18,10 @@ import java.io.IOException;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import static visualiser.app.App.keyFactory;
/** /**
* Controller for the scene used to display and update current key bindings. * 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 btnSave;
private @FXML Button btnCancel; private @FXML Button btnCancel;
private @FXML Button btnReset; private @FXML Button btnReset;
@ -34,12 +29,15 @@ public class KeyBindingsController extends Controller2 {
private @FXML ListView lstKey; private @FXML ListView lstKey;
private @FXML ListView lstDescription; private @FXML ListView lstDescription;
private @FXML AnchorPane anchor; private @FXML AnchorPane anchor;
private KeyFactory existingKeyFactory;
private KeyFactory newKeyFactory; private KeyFactory newKeyFactory;
private Boolean changed = false; // keyBindings have been modified private Boolean changed = false; // keyBindings have been modified
private Button currentButton = null; // last button clicked private Button currentButton = null; // last button clicked
public void initialize(){ public void initialize(){
// create new key factory to modify, keeping the existing one safe // create new key factory to modify, keeping the existing one safe
existingKeyFactory = new KeyFactory();
existingKeyFactory.load();
newKeyFactory = copyExistingFactory(); newKeyFactory = copyExistingFactory();
initializeTable(); initializeTable();
populateTable(); populateTable();
@ -106,7 +104,7 @@ public class KeyBindingsController extends Controller2 {
*/ */
public KeyFactory copyExistingFactory(){ public KeyFactory copyExistingFactory(){
newKeyFactory = new KeyFactory(); newKeyFactory = new KeyFactory();
Map<String, ControlKey> oldKeyState = keyFactory.getKeyState(); Map<String, ControlKey> oldKeyState = existingKeyFactory.getKeyState();
Map<String, ControlKey> newKeyState = new HashMap<>(); Map<String, ControlKey> newKeyState = new HashMap<>();
// copy over commands and their keys // copy over commands and their keys
@ -204,10 +202,10 @@ public class KeyBindingsController extends Controller2 {
*/ */
public void save(){ public void save(){
if (isFactoryValid()) { if (isFactoryValid()) {
keyFactory = newKeyFactory; existingKeyFactory = newKeyFactory;
newKeyFactory = new KeyFactory(); newKeyFactory = new KeyFactory();
changed = false; changed = false;
keyFactory.save(); // save persistently existingKeyFactory.save(); // save persistently
loadNotification("Key bindings were successfully saved.", false); loadNotification("Key bindings were successfully saved.", false);
} else { } else {
loadNotification("One or more key bindings are missing. " + 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 * @param warning true if the message to be displayed is due to user error
*/ */
public void loadNotification(String message, Boolean warning){ public void loadNotification(String message, Boolean warning){
Parent root = null;
FXMLLoader loader = new FXMLLoader(getClass().getResource
("/visualiser/scenes/notification.fxml"));
try { try {
root = loader.load(); NotificationController nc = (NotificationController)
loadPopupScene("notification.fxml",
"", Modality.APPLICATION_MODAL);
nc.setMessage(message, warning);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); 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 * Controller for the Lobby for entering games
*/ */
public class LobbyController extends Controller2 { public class LobbyController extends Controller {
private @FXML TableView<RaceConnection> lobbyTable; private @FXML TableView<RaceConnection> lobbyTable;
private @FXML TableColumn<RaceConnection, String> gameNameColumn; private @FXML TableColumn<RaceConnection, String> gameNameColumn;
private @FXML TableColumn<RaceConnection, String> hostNameColumn; private @FXML TableColumn<RaceConnection, String> hostNameColumn;

@ -28,7 +28,7 @@ import java.util.logging.Logger;
/** /**
* Controller for Hosting a game. * Controller for Hosting a game.
*/ */
public class LobbyHostingController extends Controller2 { public class LobbyHostingController extends Controller {
private @FXML ImageView imageView; private @FXML ImageView imageView;
private @FXML AnchorPane imagePane; private @FXML AnchorPane imagePane;
private @FXML SplitPane splitPane; private @FXML SplitPane splitPane;

@ -9,7 +9,7 @@ import javafx.stage.Stage;
/** /**
* Controller for a popup notification regarding user activity. * Controller for a popup notification regarding user activity.
*/ */
public class NotificationController { public class NotificationController extends Controller{
private @FXML Label lblDescription; private @FXML Label lblDescription;
private @FXML Text txtMessage; private @FXML Text txtMessage;

@ -10,7 +10,7 @@ import visualiser.model.VisualiserBoat;
/** /**
* Finish Screen for when the race finishes. * Finish Screen for when the race finishes.
*/ */
public class RaceFinishController extends Controller2 { public class RaceFinishController extends Controller {
private @FXML TableView<VisualiserBoat> boatInfoTable; private @FXML TableView<VisualiserBoat> boatInfoTable;
private @FXML TableColumn<VisualiserBoat, String> boatRankColumn; private @FXML TableColumn<VisualiserBoat, String> boatRankColumn;
private @FXML TableColumn<VisualiserBoat, String> boatNameColumn; private @FXML TableColumn<VisualiserBoat, String> boatNameColumn;

@ -22,7 +22,7 @@ import java.util.logging.Logger;
/** /**
* Controller to for waiting for the race to start. * 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 raceTitleLabel;
private @FXML Label raceStartLabel; private @FXML Label raceStartLabel;
private @FXML Label timeZoneTime; private @FXML Label timeZoneTime;

@ -32,7 +32,7 @@ import java.util.logging.Logger;
/** /**
* Controller used to display a running race. * Controller used to display a running race.
*/ */
public class RaceViewController extends Controller2 { public class RaceViewController extends Controller {
private VisualiserRaceEvent visualiserRace; private VisualiserRaceEvent visualiserRace;
private VisualiserRaceState raceState; private VisualiserRaceState raceState;
private ControllerClient controllerClient; private ControllerClient controllerClient;

@ -12,7 +12,7 @@ import java.io.IOException;
* burger-boat and comic sans styling to allure and entice users into playing * burger-boat and comic sans styling to allure and entice users into playing
* the game. * the game.
*/ */
public class TitleController extends Controller2 { public class TitleController extends Controller {
private @FXML RadioButton dayModeRD; private @FXML RadioButton dayModeRD;
private @FXML RadioButton nightModeRD; private @FXML RadioButton nightModeRD;

@ -27,19 +27,16 @@ import javafx.stage.StageStyle;
import javafx.stage.WindowEvent; import javafx.stage.WindowEvent;
import javafx.util.Duration; import javafx.util.Duration;
import mock.app.Event; import mock.app.Event;
import visualiser.gameController.Keys.KeyFactory;
public class App extends Application { public class App extends Application {
private static Stage stage; private static Stage stage;
public static Event game;
private Pane splashLayout; private Pane splashLayout;
private ProgressBar loadProgress; private ProgressBar loadProgress;
private Label progressText; private Label progressText;
private static final int SPLASH_WIDTH = 676; private static final int SPLASH_WIDTH = 676;
private static final int SPLASH_HEIGHT = 227; 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 * Entry point for running the programme
@ -51,10 +48,6 @@ public class App extends Application {
@Override @Override
public void init() { public void init() {
// load the user's personalised key bindings
keyFactory = new KeyFactory();
keyFactory.load();
ImageView splash = new ImageView(new Image( ImageView splash = new ImageView(new Image(
getClass().getClassLoader().getResourceAsStream("images/splashScreen.png") getClass().getClassLoader().getResourceAsStream("images/splashScreen.png")
)); ));

@ -3,15 +3,14 @@ package visualiser.gameController;
import javafx.animation.AnimationTimer; import javafx.animation.AnimationTimer;
import javafx.scene.Scene; import javafx.scene.Scene;
import visualiser.gameController.Keys.ControlKey; import visualiser.gameController.Keys.ControlKey;
import visualiser.gameController.Keys.KeyFactory;
import java.util.HashMap; import java.util.HashMap;
import static visualiser.app.App.keyFactory;
/** /**
* Class for checking what keys are currently being used * Class for checking what keys are currently being used
*/ */
public class InputChecker { public class InputChecker {
private KeyFactory keyFactory;
private HashMap<String, Boolean> currentlyActiveKeys = new HashMap<>(); 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. * @param scene Scene the controller is to run in parallel with.
*/ */
public void runWithScene(Scene scene){ public void runWithScene(Scene scene){
// KeyFactory keyFactory = KeyFactory.getFactory(); KeyFactory keyFactory = new KeyFactory();
keyFactory.load();
scene.setOnKeyPressed(event -> { scene.setOnKeyPressed(event -> {
String codeString = event.getCode().toString(); String codeString = event.getCode().toString();

@ -15,7 +15,7 @@ import java.util.Map;
* Class that processes user selected annotation visibility options to * Class that processes user selected annotation visibility options to
* display the requested information on the * display the requested information on the
* {@link ResizableRaceCanvas}. These are displayed * {@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, * Annotation options for a {@link VisualiserBoat} include: its name,
* abbreviation, speed, the time since it passed the last * abbreviation, speed, the time since it passed the last
* {@link shared.model.Mark}, estimated time to the next marker, * {@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 * This JavaFX Canvas is used to update and display details for a
* {@link RaceMap} via the * {@link RaceMap} via the
* {@link visualiser.Controllers.RaceController}.<br> * {@link visualiser.Controllers.RaceViewController}.<br>
* It fills it's parent and cannot be downsized. <br> * It fills it's parent and cannot be downsized. <br>
* Details displayed include: * Details displayed include:
* {@link VisualiserBoat}s (and their * {@link VisualiserBoat}s (and their

@ -21,7 +21,7 @@ import java.util.Map;
* placing position as they complete each {@link shared.model.Leg} by * placing position as they complete each {@link shared.model.Leg} by
* passing a course {@link shared.model.Mark}. <br> * passing a course {@link shared.model.Mark}. <br>
* This sparkline is displayed using the * This sparkline is displayed using the
* {@link visualiser.Controllers.RaceController}. * {@link visualiser.Controllers.RaceViewController}.
*/ */
public class Sparkline { public class Sparkline {

Loading…
Cancel
Save