Skip to content
This repository was archived by the owner on May 8, 2023. It is now read-only.
Merged

Lars #28

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions JUnit/MainTest.java → JUnit/StarterTest.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import files.Main;
import files.Starter;
import org.junit.jupiter.api.Test;

class MainTest {
class StarterTest {

MainTest(){
Main main = new Main();
StarterTest(){
Starter main = new Starter();
}

@Test
Expand Down
Binary file modified out/production/PathfindingProject/Files/Controller.class
Binary file not shown.
Binary file removed out/production/PathfindingProject/Files/Main.class
Binary file not shown.
Binary file modified out/production/PathfindingProject/Files/View.class
Binary file not shown.
Binary file modified out/production/PathfindingProject/module-info.class
Binary file not shown.
Binary file removed out/test/PathfindingProject/MainTest.class
Binary file not shown.
16 changes: 14 additions & 2 deletions src/files/Controller.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,31 @@
import files.models.Graph;

public class Controller {
private static boolean created = false;
private final Model model;
private final View view;
private final Input input;

Controller(Model model, View view){
this.onlyOneInstance();
this.model = model;
this.view = view;
this.input = new Input(model,view);
start();
this.run();
}

private void onlyOneInstance (){
if (created) {
System.err.println("You can only create one instance of the Controller class");
System.exit(0);
} else {
created = true;
System.out.println("Controller Created");
}
}

// ON Start
private void start(){
private void run(){
Graph graph = model.getGraph();
view.getUI().getGraphic().setGraph(graph);
view.getUI().getGraphic().draw();
Expand Down
26 changes: 0 additions & 26 deletions src/files/Main.java

This file was deleted.

17 changes: 15 additions & 2 deletions src/files/Model.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,30 @@
* It also handles logic and algorithms such as path finding
*/
public class Model {
private static boolean created = false;
private int tempVertices;
private Graph graph;

public Model(){
this.onlyOneInstance(); // Limit to only 1 instance of the Model class
Environment environment = new Environment();
Pathfinding pathfinding = new Pathfinding();

graph = new Graph(6);
graph.graphTest(6);
//graph = new Graph(6);
//graph.graphTest(6);
}

private void onlyOneInstance (){
if (created) {
System.err.println("You can only create one instance of the Model class");
System.exit(0);
} else {
created = true;
System.out.println("Model Created");
}
}



public Graph getGraph() {
return graph;
Expand Down
30 changes: 30 additions & 0 deletions src/files/Starter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package files;

import javafx.application.Application;
import javafx.stage.Stage;

// Application setup and main file (start of program)
// Model View Controller Design Pattern
// This is the Main file (renamed to Controller)
// The controller manages the interaction between input, model, logic and view.

// Model - Data and Logic (Calculations and Path Finding) - Can be considered as a cook
// View - Graphics and UI - Root node of Application - Can be considered as a customer
// Controller - Communicates with the model and view - Can be considered as a servant
public class Starter extends Application {
public static void main(String[] args) {
launch(args);
}

// Initialize Application Scene
public void start(Stage stage) {
stage.setTitle("Pathfinding Project 2019");

// Model-View-Controller Architectural Pattern
Model model = new Model(); // Model logic seperated from the controller and view
View view = new View(stage); // View logic seperated from the controller and model
Controller controller = new Controller(model,view); // Controller is dependant on the model and view

stage.show(); // Show Stage
}
}
73 changes: 64 additions & 9 deletions src/files/View.java
Original file line number Diff line number Diff line change
@@ -1,26 +1,85 @@
package files;

import files.views.UserInterface;
import javafx.fxml.FXMLLoader;
import javafx.scene.Group;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.stage.Stage;

// View manages the graphics
// This is the Root node of Application
public class View extends Group {
private final Stage stage;
private final UserInterface UI;
private static boolean created = false; // if created
private UserInterface UI;
private Stage stage;

// Settings
private int sceneWidth = 640;
private int sceneHeight = 480;
private String viewFXMLLink = "View.fxml";
private Node fxml;


View(Stage stage){
this.onlyOneInstance(); // Limit to only 1 instance of the Model class
this.stage = stage;
this.setScene(stage);
UI = new UserInterface(this);
this.stage.setTitle("Pathfinding Project"); // Add Title

this.getChildren().add(UI);
this.stage.setScene(new Scene(this,800,600)); // Setup Scene
addUI();
}

private void onlyOneInstance (){
if (created) {
System.err.println("You can only create one instance of the View class");
System.exit(0);
} else {
created = true;
System.out.println("View Created");
}
}

private void loadFXML(){
try {
this.fxml = FXMLLoader.load(getClass().getResource(this.viewFXMLLink));
this.convertFXMLToNodes();
} catch (Exception exception){
System.err.println(exception);
System.err.println("FXML couldnt load...");
System.exit(0);
}
}

private void convertFXMLToNodes(){
try {
/*
selectFrom = (ComboBox) this.fxml.lookup("#selectFrom");
selectTo = (ComboBox) this.fxml.lookup("#selectTo");
selectTime = (ComboBox) this.fxml.lookup("#selectTime");
departure = (RadioButton) this.fxml.lookup("#departure");
arrival = (RadioButton) this.fxml.lookup("#arrival");
button = (Button) this.fxml.lookup("#seeDepartures");
tableView = (TableView) this.fxml.lookup("#tableView");
message = (Label) this.fxml.lookup("#message");
*/
} catch(Exception exception){
System.err.println(exception);
System.err.println("Couldnt convert FXML to Nodes. Check if Type is correct.");
System.exit(0);
}
}


private void setScene(Stage stage){
ScrollPane scrollPane = new ScrollPane(); // ScrollPane
scrollPane.setContent(this.fxml);
scrollPane.setStyle("-fx-alignment: center");
stage.setScene(new Scene(scrollPane, sceneWidth, sceneHeight)); // Scene with ScrollPane
}


public UserInterface getUI(){
return UI;
}
Expand All @@ -29,10 +88,6 @@ private void addUI(){

}

public Stage getStage(){
return this.stage;
}

public void setMaximized(Boolean bool){
this.stage.setMaximized(bool);
}
Expand Down
4 changes: 1 addition & 3 deletions src/files/views/UserInterface.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import javafx.scene.layout.Pane;
import javafx.scene.text.Font;
import javafx.scene.text.Text;
import javafx.stage.Stage;

import java.util.ArrayList;

Expand All @@ -25,7 +24,7 @@ public class UserInterface extends Group {
public UserInterface(View view) {
this.view = view;
pane = new Pane();
//pane.setStyle("-fx-background-color: lightblue");
pane.setStyle("-fx-background-color: lightblue");
this.getChildren().add(pane);

addCanvas();
Expand All @@ -38,7 +37,6 @@ public ArrayList<Node> getEventNodes(){
}

private void addCanvas(){
Stage stage = this.view.getStage();
//System.out.println((int)Math.round(stage.getWidth()));
Canvas canvas = new Canvas(800, 600);

Expand Down
1 change: 1 addition & 0 deletions src/module-info.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module PathfindingProject {
requires javafx.graphics;
requires javafx.controls;
requires javafx.fxml;

opens files;
}