parent
8b4ccfb350
commit
1f28bf2471
@ -0,0 +1,142 @@
|
||||
package controllers;
|
||||
|
||||
import javafx.beans.property.ReadOnlyStringWrapper;
|
||||
import javafx.beans.property.StringProperty;
|
||||
import javafx.beans.value.ChangeListener;
|
||||
import javafx.beans.value.ObservableValue;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.event.EventHandler;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.control.*;
|
||||
import javafx.scene.control.TableColumn.CellEditEvent;
|
||||
import javafx.scene.control.cell.PropertyValueFactory;
|
||||
import javafx.scene.control.cell.TextFieldTableCell;
|
||||
import javafx.util.Callback;
|
||||
import model.*;
|
||||
|
||||
import java.net.URL;
|
||||
import java.util.Optional;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
/**
|
||||
* Created by Gondr on 5/04/2017.
|
||||
*/
|
||||
public class AddTripController extends Controller{
|
||||
|
||||
@FXML
|
||||
ComboBox<Route> routeDropdown;
|
||||
@FXML
|
||||
ComboBox<Ride> ride;
|
||||
@FXML
|
||||
ComboBox<String> direction;
|
||||
@FXML
|
||||
TableView<TripStop> routeTable;
|
||||
@FXML
|
||||
TableColumn<TripStop, String> stopName;
|
||||
@FXML
|
||||
TableColumn<TripStop, String> stopTime;
|
||||
@FXML
|
||||
CheckBox mon;
|
||||
@FXML
|
||||
CheckBox tues;
|
||||
@FXML
|
||||
CheckBox wed;
|
||||
@FXML
|
||||
CheckBox thur;
|
||||
@FXML
|
||||
CheckBox fri;
|
||||
@FXML
|
||||
CheckBox sat;
|
||||
@FXML
|
||||
CheckBox sun;
|
||||
@FXML
|
||||
ComboBox<String> reoccur;
|
||||
@FXML
|
||||
DatePicker endDate;
|
||||
|
||||
ObservableList<TripStop> stops;
|
||||
|
||||
@FXML
|
||||
private void addTrip() throws Exception {
|
||||
boolean[] days = {mon.isSelected(), tues.isSelected(), wed.isSelected(), thur.isSelected(), fri.isSelected(),
|
||||
sat.isSelected(), sun.isSelected()};
|
||||
boolean boolReoccur = reoccur.getValue() == "Yes"? true: false;
|
||||
String failure = "";
|
||||
if (stops.size() == 0){
|
||||
failure += "You have not selected a route.\n";
|
||||
}
|
||||
if (ride.getValue() == null){
|
||||
failure += "You must select a ride (vehicle) for this trip.\n";
|
||||
}
|
||||
|
||||
if (failure != "") {
|
||||
Trip trip = new Trip(stops, direction.getValue(), ride.getValue(), days, boolReoccur, endDate.getValue().toString());
|
||||
System.out.println(trip);
|
||||
Optional<ButtonType> result = popUp(Alert.AlertType.WARNING, "Warning!", "Crucial Information missing", failure, ButtonSets.YesNo);
|
||||
if (result.get() == ButtonTypes.No){
|
||||
System.out.println("My Trips page to show up and impletmeneted");//TODO implement here.
|
||||
//changeScene(SceneCode.MY_TRIPS);
|
||||
} else{
|
||||
changeScene(SceneCode.ADD_TRIP);
|
||||
}
|
||||
}else{
|
||||
popUp(Alert.AlertType.WARNING, "Warning!", "Crucial Information missing", failure);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runLater(){
|
||||
routeDropdown.setItems(parent.getSession().getDataManager().getRoutes());
|
||||
ride.setItems(parent.getSession().getDataManager().getRides());
|
||||
stopName.setCellValueFactory(p -> p.getValue().nameProperty());
|
||||
stopTime.setCellFactory(TextFieldTableCell.forTableColumn());
|
||||
stopTime.setOnEditCommit(
|
||||
new EventHandler<CellEditEvent<TripStop, String>>() {
|
||||
@Override
|
||||
public void handle(CellEditEvent<TripStop, String> t) {
|
||||
((TripStop) t.getTableView().getItems().get(
|
||||
t.getTablePosition().getRow())
|
||||
).setTime(t.getNewValue());
|
||||
}
|
||||
}
|
||||
);
|
||||
routeDropdown.valueProperty().addListener(new ChangeListener<Route>() {
|
||||
@Override
|
||||
public void changed(ObservableValue<? extends Route> observable, Route oldValue, Route newValue) {
|
||||
for (Stop stop: newValue.getStops()){
|
||||
stops.add(new TripStop(stop.getAddress(), ""));
|
||||
}
|
||||
routeTable.setItems(stops);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(URL location, ResourceBundle resources) {
|
||||
String[] reoccurence = {"Yes","No"};
|
||||
ObservableList<String> reoccurs = FXCollections.observableArrayList(reoccurence);
|
||||
reoccur.setItems(reoccurs);
|
||||
reoccur.getSelectionModel().select(1);
|
||||
reoccur.valueProperty().addListener((observable, oldValue, newValue) -> {
|
||||
if (newValue == "Yes"){
|
||||
endDate.setDisable(false);
|
||||
}else{
|
||||
endDate.setDisable(true);
|
||||
}
|
||||
});
|
||||
|
||||
String[] dir = {"University","Home"};
|
||||
ObservableList<String> dirArr = FXCollections.observableArrayList(dir);
|
||||
direction.setItems(dirArr);
|
||||
direction.getSelectionModel().selectFirst();
|
||||
|
||||
stops = FXCollections.observableArrayList();
|
||||
|
||||
routeTable.setEditable(true);
|
||||
stopName.setEditable(false);
|
||||
stopTime.setEditable(true);
|
||||
|
||||
endDate.setDisable(true);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,39 @@
|
||||
package model;
|
||||
|
||||
import javafx.collections.ObservableList;
|
||||
|
||||
/**
|
||||
* Created by Gondr on 5/04/2017.
|
||||
*/
|
||||
public class Trip {
|
||||
|
||||
ObservableList<TripStop> route;
|
||||
String direction;
|
||||
Ride ride;
|
||||
boolean[] days;
|
||||
boolean reoccur;
|
||||
String endDate;
|
||||
|
||||
static int MONDAY = 0;
|
||||
static int TUESDAY = 1;
|
||||
static int WEDNESDAY = 2;
|
||||
static int THURSDAY = 3;
|
||||
static int FRIDAY = 4;
|
||||
static int SATURDAY = 5;
|
||||
static int SUNDAY = 6;
|
||||
|
||||
public Trip(ObservableList<TripStop> route, String direction, Ride ride, boolean[] days, boolean reoccur, String endDate){
|
||||
this.route = route;
|
||||
this.direction = direction;
|
||||
this.ride = ride;
|
||||
this.days = days;
|
||||
this.reoccur = reoccur;
|
||||
this.endDate = endDate;
|
||||
}
|
||||
|
||||
public String toString(){
|
||||
String tripString = String.format("This trip has %s stops and driven by %s.", route.size(), ride);
|
||||
return tripString;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,39 @@
|
||||
package model;
|
||||
|
||||
import javafx.beans.property.SimpleStringProperty;
|
||||
import javafx.beans.property.StringProperty;
|
||||
import javafx.collections.ObservableList;
|
||||
|
||||
/**
|
||||
* Created by Gondr on 5/04/2017.
|
||||
*/
|
||||
public class TripStop{
|
||||
|
||||
private StringProperty time;
|
||||
private StringProperty name;
|
||||
|
||||
public TripStop(String name, String time){
|
||||
this.name = new SimpleStringProperty(name);
|
||||
this.time = new SimpleStringProperty(time);
|
||||
}
|
||||
|
||||
public String getTime() {
|
||||
return time.get();
|
||||
}
|
||||
|
||||
public StringProperty timeProperty() {
|
||||
return time;
|
||||
}
|
||||
|
||||
public void setTime(String time) {
|
||||
this.time.set(time);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name.get();
|
||||
}
|
||||
|
||||
public StringProperty nameProperty() {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,93 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import javafx.scene.text.*?>
|
||||
<?import javafx.scene.control.*?>
|
||||
<?import java.lang.*?>
|
||||
<?import javafx.scene.layout.*?>
|
||||
|
||||
<AnchorPane prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="controllers.AddTripController">
|
||||
<children>
|
||||
<GridPane layoutX="213.0" layoutY="99.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
|
||||
<columnConstraints>
|
||||
<ColumnConstraints hgrow="SOMETIMES" prefWidth="150.0" />
|
||||
<ColumnConstraints hgrow="SOMETIMES" prefWidth="150.0" />
|
||||
<ColumnConstraints hgrow="SOMETIMES" prefWidth="150.0" />
|
||||
<ColumnConstraints hgrow="SOMETIMES" prefWidth="150.0" />
|
||||
</columnConstraints>
|
||||
<rowConstraints>
|
||||
<RowConstraints maxHeight="50.0" minHeight="50.0" prefHeight="50.0" vgrow="SOMETIMES" />
|
||||
<RowConstraints maxHeight="40.0" minHeight="40.0" prefHeight="40.0" vgrow="SOMETIMES" />
|
||||
<RowConstraints prefHeight="40.0" vgrow="SOMETIMES" />
|
||||
<RowConstraints prefHeight="348.0" vgrow="SOMETIMES" />
|
||||
<RowConstraints minHeight="40.0" prefHeight="40.0" vgrow="SOMETIMES" />
|
||||
</rowConstraints>
|
||||
<children>
|
||||
<Label text="Add Trip" GridPane.columnSpan="4" GridPane.halignment="CENTER">
|
||||
<font>
|
||||
<Font size="18.0" />
|
||||
</font>
|
||||
</Label>
|
||||
<Label text="Select Route:" GridPane.halignment="CENTER" GridPane.rowIndex="1">
|
||||
<font>
|
||||
<Font size="16.0" />
|
||||
</font>
|
||||
</Label>
|
||||
<Label text="Select Weekday for Trip" GridPane.columnIndex="2" GridPane.columnSpan="2" GridPane.halignment="CENTER" GridPane.rowIndex="2">
|
||||
<font>
|
||||
<Font size="16.0" />
|
||||
</font>
|
||||
</Label>
|
||||
<ComboBox fx:id="routeDropdown" prefWidth="150.0" GridPane.columnIndex="1" GridPane.rowIndex="1" />
|
||||
<TableView fx:id="routeTable" editable="true" prefHeight="200.0" prefWidth="200.0" GridPane.columnSpan="2" GridPane.rowIndex="3">
|
||||
<columns>
|
||||
<TableColumn fx:id="stopName" editable="false" maxWidth="-1.0" minWidth="150.0" prefWidth="150.0" resizable="false" text="Stop" />
|
||||
<TableColumn fx:id="stopTime" maxWidth="-1.0" minWidth="150.0" prefWidth="150.0" resizable="false" text="Time" />
|
||||
</columns>
|
||||
<columnResizePolicy>
|
||||
<TableView fx:constant="CONSTRAINED_RESIZE_POLICY" />
|
||||
</columnResizePolicy>
|
||||
</TableView>
|
||||
<GridPane GridPane.columnIndex="2" GridPane.columnSpan="2" GridPane.rowIndex="3">
|
||||
<columnConstraints>
|
||||
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
|
||||
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
|
||||
</columnConstraints>
|
||||
<rowConstraints>
|
||||
<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 minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
|
||||
</rowConstraints>
|
||||
<children>
|
||||
<CheckBox fx:id="mon" mnemonicParsing="false" text="Monday" />
|
||||
<CheckBox fx:id="fri" mnemonicParsing="false" text="Friday" GridPane.columnIndex="1" />
|
||||
<CheckBox fx:id="tues" mnemonicParsing="false" text="Tuesday" GridPane.rowIndex="1" />
|
||||
<CheckBox fx:id="sat" mnemonicParsing="false" text="Saturday" GridPane.columnIndex="1" GridPane.rowIndex="1" />
|
||||
<CheckBox fx:id="wed" mnemonicParsing="false" text="Wednesday" GridPane.rowIndex="2" />
|
||||
<CheckBox fx:id="sun" mnemonicParsing="false" text="Sunday" GridPane.columnIndex="1" GridPane.rowIndex="2" />
|
||||
<CheckBox fx:id="thur" mnemonicParsing="false" text="Thursday" GridPane.rowIndex="3" />
|
||||
<DatePicker fx:id="endDate" GridPane.columnIndex="1" GridPane.rowIndex="5" />
|
||||
<Label text="End Date:" GridPane.rowIndex="5" />
|
||||
<Label text="Reoccurence:" GridPane.rowIndex="4" />
|
||||
<ComboBox fx:id="reoccur" prefWidth="150.0" GridPane.columnIndex="1" GridPane.rowIndex="4" />
|
||||
</children>
|
||||
</GridPane>
|
||||
<Label text="Select Direction:" GridPane.halignment="CENTER" GridPane.rowIndex="2">
|
||||
<font>
|
||||
<Font size="16.0" />
|
||||
</font>
|
||||
</Label>
|
||||
<ComboBox fx:id="direction" prefWidth="150.0" GridPane.columnIndex="1" GridPane.rowIndex="2" />
|
||||
<Button mnemonicParsing="false" onAction="#addTrip" prefHeight="25.0" prefWidth="391.0" text="Add Trip" GridPane.columnSpan="4" GridPane.halignment="CENTER" GridPane.rowIndex="4" />
|
||||
<Label text="Select Car:" GridPane.columnIndex="2" GridPane.halignment="CENTER" GridPane.rowIndex="1">
|
||||
<font>
|
||||
<Font size="16.0" />
|
||||
</font>
|
||||
</Label>
|
||||
<ComboBox fx:id="ride" prefWidth="150.0" GridPane.columnIndex="3" GridPane.rowIndex="1" />
|
||||
</children>
|
||||
</GridPane>
|
||||
</children>
|
||||
</AnchorPane>
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,93 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import javafx.scene.text.*?>
|
||||
<?import javafx.scene.control.*?>
|
||||
<?import java.lang.*?>
|
||||
<?import javafx.scene.layout.*?>
|
||||
|
||||
<AnchorPane prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="controllers.AddTripController">
|
||||
<children>
|
||||
<GridPane layoutX="213.0" layoutY="99.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
|
||||
<columnConstraints>
|
||||
<ColumnConstraints hgrow="SOMETIMES" prefWidth="150.0" />
|
||||
<ColumnConstraints hgrow="SOMETIMES" prefWidth="150.0" />
|
||||
<ColumnConstraints hgrow="SOMETIMES" prefWidth="150.0" />
|
||||
<ColumnConstraints hgrow="SOMETIMES" prefWidth="150.0" />
|
||||
</columnConstraints>
|
||||
<rowConstraints>
|
||||
<RowConstraints maxHeight="50.0" minHeight="50.0" prefHeight="50.0" vgrow="SOMETIMES" />
|
||||
<RowConstraints maxHeight="40.0" minHeight="40.0" prefHeight="40.0" vgrow="SOMETIMES" />
|
||||
<RowConstraints prefHeight="40.0" vgrow="SOMETIMES" />
|
||||
<RowConstraints prefHeight="348.0" vgrow="SOMETIMES" />
|
||||
<RowConstraints minHeight="40.0" prefHeight="40.0" vgrow="SOMETIMES" />
|
||||
</rowConstraints>
|
||||
<children>
|
||||
<Label text="Add Trip" GridPane.columnSpan="4" GridPane.halignment="CENTER">
|
||||
<font>
|
||||
<Font size="18.0" />
|
||||
</font>
|
||||
</Label>
|
||||
<Label text="Select Route:" GridPane.halignment="CENTER" GridPane.rowIndex="1">
|
||||
<font>
|
||||
<Font size="16.0" />
|
||||
</font>
|
||||
</Label>
|
||||
<Label text="Select Weekday for Trip" GridPane.columnIndex="2" GridPane.columnSpan="2" GridPane.halignment="CENTER" GridPane.rowIndex="2">
|
||||
<font>
|
||||
<Font size="16.0" />
|
||||
</font>
|
||||
</Label>
|
||||
<ComboBox fx:id="routeDropdown" prefWidth="150.0" GridPane.columnIndex="1" GridPane.rowIndex="1" />
|
||||
<TableView fx:id="routeTable" editable="true" prefHeight="200.0" prefWidth="200.0" GridPane.columnSpan="2" GridPane.rowIndex="3">
|
||||
<columns>
|
||||
<TableColumn fx:id="stopName" editable="false" maxWidth="-1.0" minWidth="150.0" prefWidth="150.0" resizable="false" text="Stop" />
|
||||
<TableColumn fx:id="stopTime" maxWidth="-1.0" minWidth="150.0" prefWidth="150.0" resizable="false" text="Time" />
|
||||
</columns>
|
||||
<columnResizePolicy>
|
||||
<TableView fx:constant="CONSTRAINED_RESIZE_POLICY" />
|
||||
</columnResizePolicy>
|
||||
</TableView>
|
||||
<GridPane GridPane.columnIndex="2" GridPane.columnSpan="2" GridPane.rowIndex="3">
|
||||
<columnConstraints>
|
||||
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
|
||||
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
|
||||
</columnConstraints>
|
||||
<rowConstraints>
|
||||
<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 minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
|
||||
</rowConstraints>
|
||||
<children>
|
||||
<CheckBox fx:id="mon" mnemonicParsing="false" text="Monday" />
|
||||
<CheckBox fx:id="fri" mnemonicParsing="false" text="Friday" GridPane.columnIndex="1" />
|
||||
<CheckBox fx:id="tues" mnemonicParsing="false" text="Tuesday" GridPane.rowIndex="1" />
|
||||
<CheckBox fx:id="sat" mnemonicParsing="false" text="Saturday" GridPane.columnIndex="1" GridPane.rowIndex="1" />
|
||||
<CheckBox fx:id="wed" mnemonicParsing="false" text="Wednesday" GridPane.rowIndex="2" />
|
||||
<CheckBox fx:id="sun" mnemonicParsing="false" text="Sunday" GridPane.columnIndex="1" GridPane.rowIndex="2" />
|
||||
<CheckBox fx:id="thur" mnemonicParsing="false" text="Thursday" GridPane.rowIndex="3" />
|
||||
<DatePicker fx:id="endDate" GridPane.columnIndex="1" GridPane.rowIndex="5" />
|
||||
<Label text="End Date:" GridPane.rowIndex="5" />
|
||||
<Label text="Reoccurence:" GridPane.rowIndex="4" />
|
||||
<ComboBox fx:id="reoccur" prefWidth="150.0" GridPane.columnIndex="1" GridPane.rowIndex="4" />
|
||||
</children>
|
||||
</GridPane>
|
||||
<Label text="Select Direction:" GridPane.halignment="CENTER" GridPane.rowIndex="2">
|
||||
<font>
|
||||
<Font size="16.0" />
|
||||
</font>
|
||||
</Label>
|
||||
<ComboBox fx:id="direction" prefWidth="150.0" GridPane.columnIndex="1" GridPane.rowIndex="2" />
|
||||
<Button mnemonicParsing="false" onAction="#addTrip" prefHeight="25.0" prefWidth="391.0" text="Add Trip" GridPane.columnSpan="4" GridPane.halignment="CENTER" GridPane.rowIndex="4" />
|
||||
<Label text="Select Car:" GridPane.columnIndex="2" GridPane.halignment="CENTER" GridPane.rowIndex="1">
|
||||
<font>
|
||||
<Font size="16.0" />
|
||||
</font>
|
||||
</Label>
|
||||
<ComboBox fx:id="ride" prefWidth="150.0" GridPane.columnIndex="3" GridPane.rowIndex="1" />
|
||||
</children>
|
||||
</GridPane>
|
||||
</children>
|
||||
</AnchorPane>
|
||||
Loading…
Reference in new issue