Implemented base UI and abstract controller for parent coupling
-Added Controller abstract class that all JavaFX controllers are to be a child of. -Added MainController in case in the future we need a menu. -Added mainpane.fxml as a base pane that we can mount the future menu on. -Added RaceController so where the race will be made and displayed. -Added racepane.fxml which includes a Canvas and a tableview -Added loadPane() function to the mainApp which will swap the pane the app is currently on. #story[9]
This commit is contained in:
@@ -1,11 +1,27 @@
|
||||
package seng302;
|
||||
|
||||
import javafx.application.Application;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.scene.Parent;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.layout.BorderPane;
|
||||
import javafx.stage.Stage;
|
||||
import seng302.Controllers.Controller;
|
||||
import seng302.Controllers.MainController;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class App
|
||||
public class App extends Application
|
||||
{
|
||||
Stage primaryStage;
|
||||
BorderPane mainContainer;
|
||||
Scene mainScene;
|
||||
|
||||
public static void main( String[] args )
|
||||
{
|
||||
launch(args);
|
||||
/* SPRINT 1 Leftovers
|
||||
int timescale = 0; // Scale 5 min to 1 min, 1min = 200 5 min = 1000
|
||||
|
||||
Scanner sc = new Scanner(System.in);
|
||||
@@ -40,6 +56,44 @@ public class App
|
||||
};
|
||||
|
||||
Race race = new ConstantVelocityRace(boats, marks, timescale);
|
||||
race.simulateRace();
|
||||
race.simulateRace();*/
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start(Stage primaryStage) throws Exception {
|
||||
this.primaryStage = primaryStage;
|
||||
|
||||
//load the first container
|
||||
try {
|
||||
FXMLLoader loader = new FXMLLoader();
|
||||
InputStream in = getClass().getClassLoader().getResourceAsStream("scenes//mainpane.fxml");
|
||||
mainContainer = (BorderPane) loader.load(in);
|
||||
mainScene = new Scene(mainContainer, 800, 600);
|
||||
primaryStage.setScene(mainScene);
|
||||
primaryStage.sizeToScene();
|
||||
MainController mainController = (MainController) loader.getController();
|
||||
mainController.setParent(this);
|
||||
in.close();
|
||||
//add the center
|
||||
loadPane("racepane.fxml");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
primaryStage.show();
|
||||
}
|
||||
|
||||
public void loadPane(String fxmlName) throws Exception{
|
||||
FXMLLoader loader = new FXMLLoader();
|
||||
InputStream in = getClass().getClassLoader().getResourceAsStream("scenes//"+fxmlName);
|
||||
Parent page;
|
||||
try {
|
||||
page = (Parent) loader.load(in);
|
||||
} finally {
|
||||
in.close();
|
||||
}
|
||||
mainContainer.getChildren().remove(mainContainer.getCenter());
|
||||
mainContainer.setCenter(page);
|
||||
Controller controller = (Controller) loader.getController();
|
||||
controller.setParent(this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
package seng302.Controllers;
|
||||
|
||||
import javafx.fxml.Initializable;
|
||||
import seng302.App;
|
||||
|
||||
import java.net.URL;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
/**
|
||||
* Created by Gondr on 15/03/2017.
|
||||
*/
|
||||
public abstract class Controller implements Initializable{
|
||||
protected App parent;
|
||||
|
||||
public void setParent(App parent){
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
public void loadPane(String fxmlName) throws Exception {
|
||||
this.parent.loadPane(fxmlName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public abstract void initialize(URL location, ResourceBundle resources);
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package seng302.Controllers;
|
||||
|
||||
import javafx.fxml.Initializable;
|
||||
|
||||
import java.net.URL;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
/**
|
||||
* Created by Gondr on 15/03/2017.
|
||||
*/
|
||||
public class MainController extends Controller {
|
||||
|
||||
@Override
|
||||
public void initialize(URL location, ResourceBundle resources) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package seng302.Controllers;
|
||||
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.canvas.Canvas;
|
||||
import javafx.scene.control.TableView;
|
||||
|
||||
import java.net.URL;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
/**
|
||||
* Created by Gondr on 15/03/2017.
|
||||
*/
|
||||
public class RaceController extends Controller{
|
||||
@FXML
|
||||
Canvas raceMap;
|
||||
@FXML
|
||||
TableView boatInfoTable;
|
||||
|
||||
|
||||
@Override
|
||||
public void initialize(URL location, ResourceBundle resources) {
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user