Users can share rides now but can't see shared ones yet
This commit is contained in:
@@ -94,11 +94,10 @@ public class AddTripController extends Controller{
|
||||
}
|
||||
Trip trip = new Trip(tripName.getText() ,stops, direction.getValue(), ride.getValue(), days, boolReoccur, date);
|
||||
System.out.println(trip);
|
||||
Optional<ButtonType> result = popUp(Alert.AlertType.WARNING, "Warning!", "Crucial Information missing", failure, ButtonSets.YesNo);
|
||||
Optional<ButtonType> result = popUp(Alert.AlertType.CONFIRMATION, "Success!", "Trip Added", String.format("Your Trip %1s has been added successfully!\n\nWould you like to add another trip?", tripName.getText()), ButtonSets.YesNo);
|
||||
parent.getSession().getDataManager().addTrip(trip);
|
||||
if (result.get() == ButtonTypes.No){
|
||||
System.out.println("My Trips page to show up and impletmeneted");//TODO implement here.
|
||||
//changeScene(SceneCode.MY_TRIPS);
|
||||
changeScene(SceneCode.MY_TRIPS);
|
||||
} else{
|
||||
changeScene(SceneCode.ADD_TRIP);
|
||||
}
|
||||
|
||||
@@ -53,6 +53,10 @@ public class BaseController extends Controller {
|
||||
changeScene(SceneCode.MY_TRIPS);
|
||||
}
|
||||
|
||||
public void shareRide() throws Exception{
|
||||
changeScene(SceneCode.MY_TRIPS);
|
||||
}
|
||||
|
||||
public void setContent(Parent parent1){
|
||||
//remove all children that do not belong to the original fxml
|
||||
while (base.getChildren().size() > childNum) {
|
||||
|
||||
@@ -23,8 +23,8 @@ public abstract class Controller implements Initializable {
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
public void changeScene(SceneCode scene) throws Exception {
|
||||
parent.replaceSceneContent(scene);
|
||||
public Controller changeScene(SceneCode scene) throws Exception {
|
||||
return parent.replaceSceneContent(scene);
|
||||
}
|
||||
|
||||
public void runLater(){
|
||||
|
||||
@@ -72,7 +72,7 @@ public class Main extends Application {
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public void replaceSceneContent(SceneCode fxml) throws Exception {
|
||||
public Controller replaceSceneContent(SceneCode fxml) throws Exception {
|
||||
FXMLLoader loader = new FXMLLoader();
|
||||
InputStream in = getClass().getClassLoader().getResourceAsStream(fxml.getPath());
|
||||
Parent page;
|
||||
@@ -101,6 +101,7 @@ public class Main extends Application {
|
||||
controller.setParent(this);
|
||||
controller.runLater();
|
||||
}
|
||||
return controller;
|
||||
}
|
||||
|
||||
public Session getSession() {
|
||||
|
||||
@@ -2,16 +2,14 @@ package controllers;
|
||||
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.control.ListView;
|
||||
import javafx.scene.control.TableView;
|
||||
import javafx.scene.control.*;
|
||||
import javafx.scene.layout.Background;
|
||||
import javafx.scene.layout.BackgroundFill;
|
||||
import javafx.scene.paint.Color;
|
||||
import model.Trip;
|
||||
import model.TripStop;
|
||||
import model.*;
|
||||
|
||||
import java.net.URL;
|
||||
import java.util.Optional;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
/**
|
||||
@@ -33,6 +31,10 @@ public class MyTripsController extends Controller{
|
||||
@FXML
|
||||
private Label fridayLabel;
|
||||
@FXML
|
||||
private Label saturdayLabel;
|
||||
@FXML
|
||||
private Label sundayLabel;
|
||||
@FXML
|
||||
private Label reoccuringLabel;
|
||||
@FXML
|
||||
private Label endDateLabel;
|
||||
@@ -40,10 +42,16 @@ public class MyTripsController extends Controller{
|
||||
private TableView<TripStop> stopsList;
|
||||
@FXML
|
||||
private ListView<Trip> tripsList;
|
||||
@FXML
|
||||
private ObservableList<Trip> trips;
|
||||
@FXML
|
||||
private TableColumn<TripStop, String> stopTimeColumn;
|
||||
@FXML
|
||||
private TableColumn<TripStop, String> stopNameColumn;
|
||||
@FXML
|
||||
private TextField seatsAvailable;
|
||||
private Trip selectedTrip;
|
||||
|
||||
public void setRideDays(Label day, boolean travelling){
|
||||
private void setRideDays(Label day, boolean travelling){
|
||||
if (travelling){
|
||||
day.setTextFill(Color.GREEN);
|
||||
}else{
|
||||
@@ -51,24 +59,53 @@ public class MyTripsController extends Controller{
|
||||
}
|
||||
}
|
||||
|
||||
public void shareThisRide(){
|
||||
if (selectedTrip != null && seatsAvailable.getText() != null && seatsAvailable.getText() != ""){
|
||||
int seats;
|
||||
try{
|
||||
seats = Integer.parseInt(seatsAvailable.getText());
|
||||
}catch(NumberFormatException e){
|
||||
popUp(Alert.AlertType.WARNING, "WARNING!", "Error in Seats Available Input.", "Seats Input must be an Integer.");
|
||||
return;
|
||||
}
|
||||
if (selectedTrip.ride.getNumSeats() < 0){
|
||||
Optional<ButtonType> result = popUp(Alert.AlertType.WARNING, "WARNING!", "Seats less than 0.", "This will make all seats unavailable is this what you want?", ButtonSets.YesNo);
|
||||
if (result.get() == ButtonTypes.No){
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (selectedTrip.ride.getNumSeats() > seats){
|
||||
parent.getSession().getDataManager().addSharedTrip(new SharedTrip(selectedTrip));
|
||||
popUp(Alert.AlertType.CONFIRMATION, "SUCCESS!", "Trip has been successfully shared", "The trip can now be seen by other users when there are seats available.");
|
||||
//TODO change scene
|
||||
} else{
|
||||
popUp(Alert.AlertType.WARNING, "WARNING!", "Error in Seats Available Input.", "You cannot share more seats than you have available (remember you need one for you to drive in).");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runLater(){
|
||||
//fill tables etc;
|
||||
trips = parent.getSession().getDataManager().getTrips();
|
||||
tripsList.setItems(trips);
|
||||
stopTimeColumn.setCellValueFactory(p -> p.getValue().nameProperty());
|
||||
stopNameColumn.setCellValueFactory(p -> p.getValue().nameProperty());
|
||||
tripsList.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> {
|
||||
Trip trip = tripsList.getSelectionModel().getSelectedItem();
|
||||
stopsList.setItems(trip.route);
|
||||
rideLabel.setText(trip.ride.toString());
|
||||
directionLabel.setText(trip.direction);
|
||||
setRideDays(mondayLabel, trip.days[Trip.MONDAY]);
|
||||
setRideDays(tuesdayLabel, trip.days[Trip.TUESDAY]);
|
||||
setRideDays(wednesdayLabel, trip.days[Trip.WEDNESDAY]);
|
||||
setRideDays(thursdayLabel, trip.days[Trip.THURSDAY]);
|
||||
setRideDays(fridayLabel, trip.days[Trip.FRIDAY]);
|
||||
if (trip.reoccur){
|
||||
selectedTrip = tripsList.getSelectionModel().getSelectedItem();
|
||||
stopsList.setItems(selectedTrip.route);
|
||||
rideLabel.setText(selectedTrip.ride.toString());
|
||||
directionLabel.setText(selectedTrip.direction);
|
||||
setRideDays(mondayLabel, selectedTrip.days[Trip.MONDAY]);
|
||||
setRideDays(tuesdayLabel, selectedTrip.days[Trip.TUESDAY]);
|
||||
setRideDays(wednesdayLabel, selectedTrip.days[Trip.WEDNESDAY]);
|
||||
setRideDays(thursdayLabel, selectedTrip.days[Trip.THURSDAY]);
|
||||
setRideDays(fridayLabel, selectedTrip.days[Trip.FRIDAY]);
|
||||
setRideDays(saturdayLabel, selectedTrip.days[Trip.SATURDAY]);
|
||||
setRideDays(sundayLabel, selectedTrip.days[Trip.SUNDAY]);
|
||||
if (selectedTrip.reoccur){
|
||||
reoccuringLabel.setText("Yes");
|
||||
endDateLabel.setText(trip.endDate);
|
||||
endDateLabel.setText(selectedTrip.endDate);
|
||||
}else{
|
||||
reoccuringLabel.setText("No");
|
||||
endDateLabel.setText("-");
|
||||
|
||||
@@ -16,16 +16,18 @@ public class DataManager {
|
||||
private ObservableList<Stop> stops;
|
||||
private ObservableList<Route> routes;
|
||||
private ObservableList<Trip> trips;
|
||||
private ObservableList<SharedTrip> sharedTrips;
|
||||
|
||||
public DataManager(List rides, List stops, List routes, List trips){
|
||||
public DataManager(List rides, List stops, List routes, List trips, List sharedTrips){
|
||||
this.rides = FXCollections.observableArrayList(rides);
|
||||
this.stops = FXCollections.observableArrayList(stops);
|
||||
this.routes = FXCollections.observableArrayList(routes);
|
||||
this.trips = FXCollections.observableArrayList(trips);
|
||||
this.sharedTrips = FXCollections.observableArrayList(sharedTrips);
|
||||
}
|
||||
|
||||
public DataManager(){
|
||||
this(FXCollections.observableArrayList(), FXCollections.observableArrayList(), FXCollections.observableArrayList(), FXCollections.observableArrayList());
|
||||
this(FXCollections.observableArrayList(), FXCollections.observableArrayList(), FXCollections.observableArrayList(), FXCollections.observableArrayList(), FXCollections.observableArrayList());
|
||||
}
|
||||
|
||||
public ObservableList<Ride> getRides() {
|
||||
@@ -86,4 +88,18 @@ public class DataManager {
|
||||
return true;
|
||||
}
|
||||
|
||||
public ObservableList<SharedTrip> getSharedTrips() {
|
||||
return sharedTrips;
|
||||
}
|
||||
|
||||
public boolean addSharedTrip(SharedTrip sharedTrip){
|
||||
for (SharedTrip t: sharedTrips){
|
||||
if (sharedTrip.equals(t)){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
sharedTrips.add(sharedTrip);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -17,6 +17,25 @@ public class Ride {
|
||||
this.numSeats = numSeats;
|
||||
}
|
||||
|
||||
public String getModel() {
|
||||
return model;
|
||||
}
|
||||
|
||||
public String getColour() {
|
||||
return colour;
|
||||
}
|
||||
|
||||
public String getLicensePlate() {
|
||||
return licensePlate;
|
||||
}
|
||||
|
||||
public int getYear() {
|
||||
return year;
|
||||
}
|
||||
|
||||
public int getNumSeats() {
|
||||
return numSeats;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(){
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
package model;
|
||||
|
||||
/**
|
||||
* Created by Gondr on 28/05/2017.
|
||||
*/
|
||||
public class SharedTrip extends Trip {
|
||||
|
||||
public SharedTrip (Trip trip){
|
||||
super(trip.name, trip.route, trip.direction, trip.ride, trip.days, trip.reoccur, trip.endDate);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -30,11 +30,13 @@ public class DataManagerSerialiser extends Serialiser {
|
||||
ArrayList<Stop> stops = new ArrayList<>(dataManager.getStops());
|
||||
ArrayList<Route> routes = new ArrayList<>(dataManager.getRoutes());
|
||||
ArrayList<Trip> trips = new ArrayList<>(dataManager.getTrips());
|
||||
ArrayList<SharedTrip> sharedTrips = new ArrayList<>(dataManager.getSharedTrips());
|
||||
boolean serialRidesSuccess = serialise(rides, "serialisation/rides.json");
|
||||
boolean serialStopsSuccess = serialise(stops, "serialisation/stops.json");
|
||||
boolean serialRoutesSuccess = serialiseRoutes(routes, "serialisation/routes.json");
|
||||
boolean serialTripsSuccess = serialiseTrips(trips, "serialisation/trips.json");
|
||||
return (serialRidesSuccess && serialStopsSuccess && serialRoutesSuccess && serialTripsSuccess);
|
||||
boolean serialSharedTripsSuccess = serialiseSharedTrips(sharedTrips, "serialisation/sharedtrips.json");
|
||||
return (serialRidesSuccess && serialStopsSuccess && serialRoutesSuccess && serialTripsSuccess && serialSharedTripsSuccess);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -81,6 +83,29 @@ public class DataManagerSerialiser extends Serialiser {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Serialises trips
|
||||
* @param trips Trips to be serialised
|
||||
* @param filepath File path to serialise it to.
|
||||
* @return
|
||||
*/
|
||||
public boolean serialiseSharedTrips(ArrayList<SharedTrip> trips, String filepath){
|
||||
for (Trip trip: trips){
|
||||
trip.serialise();
|
||||
}
|
||||
try{
|
||||
String path = getClass().getClassLoader().getResource(filepath).getPath();
|
||||
Writer writer = new OutputStreamWriter(new FileOutputStream(path), "UTF-8");
|
||||
gson.toJson(trips, writer);
|
||||
writer.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* loads the data manager from file
|
||||
* @return whether the data was loaded properly or not
|
||||
@@ -115,7 +140,15 @@ public class DataManagerSerialiser extends Serialiser {
|
||||
trip.deserialise();
|
||||
}
|
||||
|
||||
return new DataManager(rides, stops, routes, trips);
|
||||
Reader reader5 = new InputStreamReader(getClass().getClassLoader().getResourceAsStream("serialisation/trips.json"), "UTF-8");
|
||||
ArrayList<SharedTrip> sharedTrips = gson.fromJson(reader4, new TypeToken<ArrayList<SharedTrip>>(){}.getType());
|
||||
reader5.close();
|
||||
|
||||
for (SharedTrip trip: sharedTrips){
|
||||
trip.deserialise();
|
||||
}
|
||||
|
||||
return new DataManager(rides, stops, routes, trips, sharedTrips);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import javafx.scene.text.*?>
|
||||
<?import javafx.geometry.*?>
|
||||
<?import javafx.scene.control.*?>
|
||||
<?import java.lang.*?>
|
||||
@@ -9,7 +10,7 @@
|
||||
<children>
|
||||
<GridPane fx:id="base" layoutX="56.0" layoutY="75.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
|
||||
<columnConstraints>
|
||||
<ColumnConstraints hgrow="SOMETIMES" maxWidth="200.0" minWidth="200.0" prefWidth="200.0" />
|
||||
<ColumnConstraints hgrow="SOMETIMES" maxWidth="200.0" prefWidth="200.0" />
|
||||
<ColumnConstraints hgrow="SOMETIMES" maxWidth="1.7976931348623157E308" minWidth="10.0" />
|
||||
</columnConstraints>
|
||||
<rowConstraints>
|
||||
@@ -17,7 +18,7 @@
|
||||
<RowConstraints maxHeight="30.0" minHeight="30.0" prefHeight="30.0" vgrow="SOMETIMES" />
|
||||
</rowConstraints>
|
||||
<children>
|
||||
<Accordion GridPane.rowSpan="2">
|
||||
<Accordion maxWidth="200.0" minWidth="200.0" prefWidth="200.0" GridPane.rowSpan="2">
|
||||
<panes>
|
||||
<TitledPane animated="false" text="User Profile">
|
||||
<content>
|
||||
@@ -65,10 +66,36 @@
|
||||
</columnConstraints>
|
||||
<rowConstraints>
|
||||
<RowConstraints minHeight="10.0" vgrow="SOMETIMES" />
|
||||
<RowConstraints />
|
||||
</rowConstraints>
|
||||
<children>
|
||||
<VBox>
|
||||
<children>
|
||||
<AnchorPane>
|
||||
<children>
|
||||
<Label alignment="CENTER" contentDisplay="CENTER" text="Actions" textAlignment="CENTER" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0">
|
||||
<font>
|
||||
<Font name="System Bold" size="14.0" />
|
||||
</font>
|
||||
</Label>
|
||||
</children>
|
||||
</AnchorPane>
|
||||
<Separator prefWidth="200.0" />
|
||||
<AnchorPane>
|
||||
<children>
|
||||
<Button mnemonicParsing="false" onAction="#shareRide" text="Share Ride" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" />
|
||||
</children>
|
||||
</AnchorPane>
|
||||
<AnchorPane>
|
||||
<children>
|
||||
<Label alignment="CENTER" text="Add Information" textAlignment="JUSTIFY" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0">
|
||||
<font>
|
||||
<Font name="System Bold" size="14.0" />
|
||||
</font>
|
||||
</Label>
|
||||
</children>
|
||||
</AnchorPane>
|
||||
<Separator prefWidth="200.0" />
|
||||
<AnchorPane>
|
||||
<children>
|
||||
<Button mnemonicParsing="false" onAction="#addRide" text="Add Ride" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" GridPane.hgrow="ALWAYS" GridPane.valignment="TOP" GridPane.vgrow="ALWAYS" />
|
||||
|
||||
@@ -38,8 +38,8 @@
|
||||
</Label>
|
||||
<TableView fx:id="stopsList" prefHeight="200.0" prefWidth="200.0" GridPane.columnIndex="1" GridPane.rowIndex="2">
|
||||
<columns>
|
||||
<TableColumn prefWidth="104.0" text="Time" />
|
||||
<TableColumn prefWidth="95.0" text="Stop" />
|
||||
<TableColumn fx:id="stopTimeColumn" prefWidth="104.0" text="Time" />
|
||||
<TableColumn fx:id="stopNameColumn" prefWidth="95.0" text="Stop" />
|
||||
</columns>
|
||||
</TableView>
|
||||
<Label text="Information" GridPane.columnIndex="2" GridPane.halignment="CENTER" GridPane.rowIndex="1">
|
||||
@@ -58,6 +58,8 @@
|
||||
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
|
||||
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
|
||||
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
|
||||
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
|
||||
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
|
||||
</rowConstraints>
|
||||
<children>
|
||||
<Label text="Ride:" />
|
||||
@@ -71,6 +73,11 @@
|
||||
<Label fx:id="endDateLabel" text="Label" GridPane.columnIndex="1" GridPane.rowIndex="4" />
|
||||
<HBox alignment="CENTER_LEFT" prefHeight="100.0" prefWidth="200.0" GridPane.columnIndex="1" GridPane.halignment="CENTER" GridPane.rowIndex="2" GridPane.valignment="CENTER">
|
||||
<children>
|
||||
<Label fx:id="sundayLabel" style="-fx-border-color: #F0F0F0; -fx-border-width: 1;" text="S">
|
||||
<padding>
|
||||
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
|
||||
</padding>
|
||||
</Label>
|
||||
<Label fx:id="mondayLabel" style="-fx-border-color: #F0F0F0; -fx-border-width: 1;" text="M" AnchorPane.bottomAnchor="23.0" AnchorPane.topAnchor="22.0">
|
||||
<HBox.margin>
|
||||
<Insets />
|
||||
@@ -99,11 +106,23 @@
|
||||
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
|
||||
</padding>
|
||||
</Label>
|
||||
<Label fx:id="saturdayLabel" style="-fx-border-color: #F0F0F0; -fx-border-width: 1;" text="S">
|
||||
<padding>
|
||||
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
|
||||
</padding>
|
||||
</Label>
|
||||
</children>
|
||||
</HBox>
|
||||
<AnchorPane GridPane.columnSpan="2" GridPane.rowIndex="6">
|
||||
<children>
|
||||
<Button mnemonicParsing="false" onAction="#shareThisRide" text="Share This Ride" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" GridPane.rowIndex="5" />
|
||||
</children>
|
||||
</AnchorPane>
|
||||
<TextField fx:id="seatsAvailable" text="0" GridPane.columnIndex="1" GridPane.rowIndex="5" />
|
||||
<Label text="Seats Available:" GridPane.rowIndex="5" />
|
||||
</children>
|
||||
<GridPane.margin>
|
||||
<Insets left="10.0" />
|
||||
<Insets left="10.0" right="10.0" />
|
||||
</GridPane.margin>
|
||||
</GridPane>
|
||||
</children>
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
[]
|
||||
Reference in New Issue
Block a user