Added Story 3

main
Fan-Wu Yang 9 years ago
parent 83680c5752
commit dcb843943f

@ -0,0 +1,77 @@
package controllers;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.scene.control.*;
import model.*;
import java.net.URL;
import java.util.Optional;
import java.util.ResourceBundle;
/**
* Created by Gondr on 5/04/2017.
*/
public class AddRouteController extends Controller{
@FXML
ListView<Stop> stopsList;
@FXML
ListView<Stop> routeList;
@FXML
TextField routeName;
ObservableList<Stop> stops;
ObservableList<Stop> routeStops;
public void addStop(){
ObservableList<Stop> selected = FXCollections.observableArrayList(stopsList.getSelectionModel().getSelectedItems());
if(selected.size() > 0){
for (Stop stop: selected){
stops.remove(stop);
routeStops.add(stop);
}
}
}
public void removeStop(){
ObservableList<Stop> selected = FXCollections.observableArrayList(routeList.getSelectionModel().getSelectedItems());
if(selected.size() > 0){
for (Stop stop: selected){
stops.add(stop);
routeStops.remove(stop);
}
}
}
public void addRoute() throws Exception {
Route route = new Route(routeName.getText(), routeStops);
if (parent.getSession().getDataManager().addRoute(route)){
//alert
Optional<ButtonType> result = popUp(Alert.AlertType.CONFIRMATION, "Success!", "Route has been added.", "Would you like to add another route?", ButtonSets.YesNo);
if (result.get() == ButtonTypes.No){
changeScene(SceneCode.MY_ROUTES);
} else{
stops = FXCollections.observableArrayList(parent.getSession().getDataManager().getStops());
routeStops = FXCollections.observableArrayList();
}
} else {
popUp(Alert.AlertType.WARNING, "Warning!", "Duplicate Route", "You may have a route with the same name or same stops.");
}
}
@Override
public void runLater(){
stops = FXCollections.observableArrayList(parent.getSession().getDataManager().getStops());
routeStops = FXCollections.observableArrayList();
stopsList.setItems(stops);
routeList.setItems(routeStops);
stopsList.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
routeList.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
}
@Override
public void initialize(URL location, ResourceBundle resources) {
}
}

@ -37,6 +37,14 @@ public class BaseController extends Controller {
changeScene(SceneCode.MY_STOPS);
}
public void addRoute() throws Exception{
changeScene(SceneCode.ADD_ROUTE);
}
public void myRoutes() throws Exception{
changeScene(SceneCode.MY_ROUTES);
}
public void setContent(Parent parent1){
//remove all children that do not belong to the original fxml
while (base.getChildren().size() > childNum) {

@ -0,0 +1,41 @@
package controllers;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections;
import javafx.fxml.FXML;
import javafx.scene.control.ListView;
import model.Route;
import model.Stop;
import java.net.URL;
import java.util.ResourceBundle;
/**
* Created by Gondr on 5/04/2017.
*/
public class MyRoutesController extends Controller {
@FXML
ListView<Route> routesList;
@FXML
ListView<Stop> stopsList;
@Override
public void runLater(){
routesList.setItems(parent.getSession().getDataManager().getRoutes());
routesList.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<Route>(){
@Override
public void changed(ObservableValue<? extends Route> observable, Route oldValue, Route newValue) {
stopsList.setItems(FXCollections.observableArrayList(newValue.getStops()));
}
});
}
@Override
public void initialize(URL location, ResourceBundle resources) {
}
}

@ -13,10 +13,12 @@ import java.util.ArrayList;
public class DataManager {
private ObservableList<Ride> rides;
private ObservableList<Stop> stops;
private ObservableList<Route> routes;
public DataManager(){
rides = FXCollections.observableArrayList();
stops = FXCollections.observableArrayList();
routes = FXCollections.observableArrayList();
}
public ObservableList<Ride> getRides() {
@ -49,4 +51,18 @@ public class DataManager {
return true;
}
public ObservableList<Route> getRoutes() {
return routes;
}
public boolean addRoute(Route route){
for (Route r: routes){
if (route.equals(r)){
return false;
}
}
routes.add(route);
return true;
}
}

@ -0,0 +1,41 @@
package model;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
/**
* Created by Gondr on 5/04/2017.
*/
public class Route {
private String name;
private ObservableList<Stop> stops;
public Route(String name, ObservableList<Stop> stops){
this.name = name;
this.stops = FXCollections.observableArrayList(stops);
}
public String getName() {
return name;
}
public ObservableList<Stop> getStops() {
return stops;
}
public boolean equals(Route route){
if (this.name != route.getName()){
if (this.getStops().equals(route.getStops())){
//if the yhave a equivalent route somewhere.
return true;
}
return false;
}
return true;
}
public String toString(){
return this.name;
}
}

@ -14,7 +14,8 @@ public enum SceneCode {
//screens before log in
MAIN("main", false), BASE("base", false),
//screens after login
HOME("home"),ADD_RIDE("addride"),MY_RIDES("myrides"), ADD_STOPS("addstops"), MY_STOPS("mystops");
HOME("home"),ADD_RIDE("addride"),MY_RIDES("myrides"), ADD_STOPS("addstops"), MY_STOPS("mystops"), ADD_ROUTE("addroute"),
MY_ROUTES("myroutes");
private String path;
private boolean loadMenu;

@ -0,0 +1,69 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.*?>
<?import javafx.scene.*?>
<?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.AddRouteController">
<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" minWidth="10.0" prefWidth="300.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="300.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="300.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints maxHeight="50.0" minHeight="50.0" prefHeight="50.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="30.0" minHeight="30.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="30.0" minHeight="30.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="348.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<ListView fx:id="stopsList" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" prefHeight="200.0" prefWidth="200.0" GridPane.rowIndex="3" />
<Label text="Add Route" GridPane.columnSpan="3" GridPane.halignment="CENTER">
<font>
<Font size="18.0" />
</font>
</Label>
<ListView fx:id="routeList" prefHeight="200.0" prefWidth="200.0" GridPane.columnIndex="2" GridPane.rowIndex="3" />
<GridPane GridPane.columnIndex="1" GridPane.rowIndex="3">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints vgrow="SOMETIMES" />
<RowConstraints maxHeight="30.0" minHeight="30.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="30.0" minHeight="30.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints vgrow="SOMETIMES" />
</rowConstraints>
<children>
<AnchorPane layoutY="25.0" GridPane.rowIndex="1">
<children>
<Button mnemonicParsing="false" onAction="#addStop" text="&gt;&gt;&gt;" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" />
</children>
</AnchorPane>
<AnchorPane GridPane.rowIndex="2">
<children>
<Button mnemonicParsing="false" onAction="#removeStop" text="&lt;&lt;&lt;" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" />
</children>
</AnchorPane>
<AnchorPane GridPane.rowIndex="3">
<children>
<Button mnemonicParsing="false" onAction="#addRoute" text="Add Route" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" GridPane.rowIndex="3" />
</children>
</AnchorPane>
</children>
</GridPane>
<Label text="Route Name:" GridPane.columnIndex="1" GridPane.halignment="CENTER" GridPane.rowIndex="1">
<font>
<Font size="16.0" />
</font>
</Label>
<TextField fx:id="routeName" GridPane.columnIndex="1" GridPane.rowIndex="2" />
</children>
</GridPane>
</children>
</AnchorPane>

@ -41,6 +41,11 @@
<Button mnemonicParsing="false" onAction="#myStops" text="Stops" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" />
</children>
</AnchorPane>
<AnchorPane>
<children>
<Button mnemonicParsing="false" onAction="#myRoutes" text="Routes" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" />
</children>
</AnchorPane>
</children>
</VBox>
</children>
@ -69,6 +74,11 @@
<Button mnemonicParsing="false" onAction="#addStops" text="Add Stop" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" />
</children>
</AnchorPane>
<AnchorPane>
<children>
<Button mnemonicParsing="false" onAction="#addRoute" text="Add Route" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" />
</children>
</AnchorPane>
</children>
</VBox>
</children>

@ -0,0 +1,41 @@
<?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.MyRoutesController">
<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" minWidth="10.0" prefWidth="300.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="300.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 minHeight="10.0" prefHeight="348.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<ListView fx:id="routesList" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" prefHeight="200.0" prefWidth="200.0" GridPane.rowIndex="2" />
<Label text="My Routes" GridPane.columnSpan="2" GridPane.halignment="CENTER">
<font>
<Font size="18.0" />
</font>
</Label>
<ListView fx:id="stopsList" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" prefHeight="200.0" prefWidth="200.0" GridPane.columnIndex="1" GridPane.rowIndex="2" />
<Label text="Routes" GridPane.halignment="CENTER" GridPane.rowIndex="1">
<font>
<Font size="16.0" />
</font>
</Label>
<Label text="Stops" GridPane.columnIndex="1" GridPane.halignment="CENTER" GridPane.rowIndex="1">
<font>
<Font size="16.0" />
</font>
</Label>
</children>
</GridPane>
</children>
</AnchorPane>

Binary file not shown.

@ -0,0 +1,69 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.*?>
<?import javafx.scene.*?>
<?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.AddRouteController">
<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" minWidth="10.0" prefWidth="300.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="300.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="300.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints maxHeight="50.0" minHeight="50.0" prefHeight="50.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="30.0" minHeight="30.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="30.0" minHeight="30.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="348.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<ListView fx:id="stopsList" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" prefHeight="200.0" prefWidth="200.0" GridPane.rowIndex="3" />
<Label text="Add Route" GridPane.columnSpan="3" GridPane.halignment="CENTER">
<font>
<Font size="18.0" />
</font>
</Label>
<ListView fx:id="routeList" prefHeight="200.0" prefWidth="200.0" GridPane.columnIndex="2" GridPane.rowIndex="3" />
<GridPane GridPane.columnIndex="1" GridPane.rowIndex="3">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints vgrow="SOMETIMES" />
<RowConstraints maxHeight="30.0" minHeight="30.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="30.0" minHeight="30.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints vgrow="SOMETIMES" />
</rowConstraints>
<children>
<AnchorPane layoutY="25.0" GridPane.rowIndex="1">
<children>
<Button mnemonicParsing="false" onAction="#addStop" text="&gt;&gt;&gt;" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" />
</children>
</AnchorPane>
<AnchorPane GridPane.rowIndex="2">
<children>
<Button mnemonicParsing="false" onAction="#removeStop" text="&lt;&lt;&lt;" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" />
</children>
</AnchorPane>
<AnchorPane GridPane.rowIndex="3">
<children>
<Button mnemonicParsing="false" onAction="#addRoute" text="Add Route" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" GridPane.rowIndex="3" />
</children>
</AnchorPane>
</children>
</GridPane>
<Label text="Route Name:" GridPane.columnIndex="1" GridPane.halignment="CENTER" GridPane.rowIndex="1">
<font>
<Font size="16.0" />
</font>
</Label>
<TextField fx:id="routeName" GridPane.columnIndex="1" GridPane.rowIndex="2" />
</children>
</GridPane>
</children>
</AnchorPane>

@ -41,6 +41,11 @@
<Button mnemonicParsing="false" onAction="#myStops" text="Stops" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" />
</children>
</AnchorPane>
<AnchorPane>
<children>
<Button mnemonicParsing="false" onAction="#myRoutes" text="Routes" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" />
</children>
</AnchorPane>
</children>
</VBox>
</children>
@ -69,6 +74,11 @@
<Button mnemonicParsing="false" onAction="#addStops" text="Add Stop" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" />
</children>
</AnchorPane>
<AnchorPane>
<children>
<Button mnemonicParsing="false" onAction="#addRoute" text="Add Route" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" />
</children>
</AnchorPane>
</children>
</VBox>
</children>

@ -0,0 +1,41 @@
<?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.MyRoutesController">
<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" minWidth="10.0" prefWidth="300.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="300.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 minHeight="10.0" prefHeight="348.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<ListView fx:id="routesList" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" prefHeight="200.0" prefWidth="200.0" GridPane.rowIndex="2" />
<Label text="My Routes" GridPane.columnSpan="2" GridPane.halignment="CENTER">
<font>
<Font size="18.0" />
</font>
</Label>
<ListView fx:id="stopsList" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" prefHeight="200.0" prefWidth="200.0" GridPane.columnIndex="1" GridPane.rowIndex="2" />
<Label text="Routes" GridPane.halignment="CENTER" GridPane.rowIndex="1">
<font>
<Font size="16.0" />
</font>
</Label>
<Label text="Stops" GridPane.columnIndex="1" GridPane.halignment="CENTER" GridPane.rowIndex="1">
<font>
<Font size="16.0" />
</font>
</Label>
</children>
</GridPane>
</children>
</AnchorPane>
Loading…
Cancel
Save