Story two implemented
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
package controllers;
|
||||
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.control.Alert;
|
||||
import javafx.scene.control.ButtonType;
|
||||
import javafx.scene.control.TextField;
|
||||
import model.ButtonSets;
|
||||
import model.ButtonTypes;
|
||||
import model.SceneCode;
|
||||
import model.Stop;
|
||||
|
||||
import java.net.URL;
|
||||
import java.util.Optional;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
/**
|
||||
* Created by Gondr on 5/04/2017.
|
||||
*/
|
||||
public class AddStopsController extends Controller{
|
||||
|
||||
@FXML
|
||||
TextField stopAddress;
|
||||
|
||||
public void addStop() throws Exception {
|
||||
Stop stop = new Stop(stopAddress.getText());
|
||||
if(parent.getSession().getDataManager().addStop(stop) == true){
|
||||
Optional<ButtonType> result = popUp(Alert.AlertType.CONFIRMATION, "Success!", "Stop has been successfully added.", "Would you like to add another stop?", ButtonSets.YesNo);
|
||||
if (result.get() == ButtonTypes.No){
|
||||
changeScene(SceneCode.MY_STOPS);
|
||||
} else{
|
||||
stopAddress.setText("");
|
||||
}
|
||||
}else{
|
||||
popUp(Alert.AlertType.WARNING, "Warning!", "Duplicate Entry", "You cannot add a duplicate stop.");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(URL location, ResourceBundle resources) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -19,7 +19,7 @@ public class BaseController extends Controller {
|
||||
@FXML
|
||||
Label loggedInAs;
|
||||
|
||||
private final int childNum = 3;//number of children before appending
|
||||
private int childNum = 0;//number of children before appending
|
||||
|
||||
public void addRide() throws Exception {
|
||||
changeScene(SceneCode.ADD_RIDE);
|
||||
@@ -29,6 +29,14 @@ public class BaseController extends Controller {
|
||||
changeScene(SceneCode.MY_RIDES);
|
||||
}
|
||||
|
||||
public void addStops() throws Exception {
|
||||
changeScene(SceneCode.ADD_STOPS);
|
||||
}
|
||||
|
||||
public void myStops() throws Exception{
|
||||
changeScene(SceneCode.MY_STOPS);
|
||||
}
|
||||
|
||||
public void setContent(Parent parent1){
|
||||
//remove all children that do not belong to the original fxml
|
||||
while (base.getChildren().size() > childNum) {
|
||||
@@ -44,5 +52,6 @@ public class BaseController extends Controller {
|
||||
|
||||
@Override
|
||||
public void initialize(URL location, ResourceBundle resources) {
|
||||
childNum = base.getChildren().size();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,16 +2,11 @@ package controllers;
|
||||
|
||||
|
||||
import javafx.fxml.Initializable;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.control.Alert;
|
||||
import javafx.scene.layout.VBox;
|
||||
import javafx.scene.text.Text;
|
||||
import javafx.stage.Modality;
|
||||
import javafx.stage.Stage;
|
||||
import javafx.scene.control.ButtonType;
|
||||
import model.SceneCode;
|
||||
|
||||
import java.net.URL;
|
||||
import java.util.ResourceBundle;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* Created by Gondr on 4/04/2017.
|
||||
@@ -36,12 +31,24 @@ public abstract class Controller implements Initializable {
|
||||
|
||||
}
|
||||
|
||||
public void popUp(Alert.AlertType alertType, String title, String header, String content){
|
||||
public Optional<ButtonType> popUp(Alert.AlertType alertType, String title, String header, String content, ButtonType[] buttons){
|
||||
Alert alert = new Alert(alertType);
|
||||
alert.setTitle(title);
|
||||
alert.setHeaderText(header);
|
||||
alert.setContentText(content);
|
||||
alert.showAndWait();
|
||||
alert.getButtonTypes().remove(0, alert.getButtonTypes().size()); // remove all buttons
|
||||
for (int i = 0; i < buttons.length; i ++){
|
||||
alert.getButtonTypes().add(buttons[i]);
|
||||
}
|
||||
return alert.showAndWait();
|
||||
}
|
||||
|
||||
public Optional<ButtonType> popUp(Alert.AlertType alertType, String title, String header, String content){
|
||||
Alert alert = new Alert(alertType);
|
||||
alert.setTitle(title);
|
||||
alert.setHeaderText(header);
|
||||
alert.setContentText(content);
|
||||
return alert.showAndWait();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
package controllers;
|
||||
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.control.ListView;
|
||||
import model.Stop;
|
||||
|
||||
import java.net.URL;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
/**
|
||||
* Created by Gondr on 5/04/2017.
|
||||
*/
|
||||
public class MyStopsController extends Controller{
|
||||
|
||||
@FXML
|
||||
ListView<Stop> stopsList;
|
||||
|
||||
@Override
|
||||
public void runLater(){
|
||||
stopsList.setItems(parent.getSession().getDataManager().getStops());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(URL location, ResourceBundle resources) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package model;
|
||||
|
||||
import javafx.scene.control.ButtonBar;
|
||||
import javafx.scene.control.ButtonType;
|
||||
|
||||
/**
|
||||
* Created by Gondr on 5/04/2017.
|
||||
*/
|
||||
public class ButtonSets {
|
||||
|
||||
public static ButtonType[] YesNo = {ButtonTypes.Yes, ButtonTypes.No};
|
||||
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package model;
|
||||
|
||||
import javafx.scene.control.ButtonBar;
|
||||
import javafx.scene.control.ButtonType;
|
||||
|
||||
/**
|
||||
* Created by Gondr on 5/04/2017.
|
||||
*/
|
||||
public class ButtonTypes {
|
||||
public static ButtonType Yes = new ButtonType("Yes", ButtonBar.ButtonData.OK_DONE);
|
||||
public static ButtonType No = new ButtonType("No", ButtonBar.ButtonData.CANCEL_CLOSE);
|
||||
}
|
||||
@@ -12,9 +12,11 @@ import java.util.ArrayList;
|
||||
*/
|
||||
public class DataManager {
|
||||
private ObservableList<Ride> rides;
|
||||
private ObservableList<Stop> stops;
|
||||
|
||||
public DataManager(){
|
||||
rides = FXCollections.observableArrayList();
|
||||
stops = FXCollections.observableArrayList();
|
||||
}
|
||||
|
||||
public ObservableList<Ride> getRides() {
|
||||
@@ -32,4 +34,19 @@ public class DataManager {
|
||||
public void removeRide(int i){
|
||||
rides.remove(i);
|
||||
}
|
||||
|
||||
public ObservableList<Stop> getStops() {
|
||||
return stops;
|
||||
}
|
||||
|
||||
public boolean addStop(Stop stop){
|
||||
for (int i = 0; i < stops.size(); i++){
|
||||
if (stop.equals(stops.get(i))){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
stops.add(stop);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ public enum SceneCode {
|
||||
//screens before log in
|
||||
MAIN("main", false), BASE("base", false),
|
||||
//screens after login
|
||||
HOME("home"),ADD_RIDE("addride"),MY_RIDES("myrides");
|
||||
HOME("home"),ADD_RIDE("addride"),MY_RIDES("myrides"), ADD_STOPS("addstops"), MY_STOPS("mystops");
|
||||
|
||||
private String path;
|
||||
private boolean loadMenu;
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
package model;
|
||||
|
||||
/**
|
||||
* Created by Gondr on 5/04/2017.
|
||||
*/
|
||||
public class Stop {
|
||||
|
||||
private String address;
|
||||
|
||||
public Stop(String address){
|
||||
this.address = address;
|
||||
}
|
||||
|
||||
public String getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
public void setAddress(String address) {
|
||||
this.address = address;
|
||||
}
|
||||
|
||||
public boolean equals(Stop stop){
|
||||
if (stop.getAddress().equals(this.address)){
|
||||
return true;
|
||||
} else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public String toString(){
|
||||
return address;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?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.AddStopsController">
|
||||
<children>
|
||||
<GridPane layoutX="287.0" layoutY="131.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
|
||||
<columnConstraints>
|
||||
<ColumnConstraints hgrow="SOMETIMES" />
|
||||
<ColumnConstraints hgrow="SOMETIMES" maxWidth="100.0" minWidth="100.0" prefWidth="100.0" />
|
||||
<ColumnConstraints hgrow="SOMETIMES" maxWidth="300.0" minWidth="300.0" prefWidth="300.0" />
|
||||
<ColumnConstraints hgrow="SOMETIMES" />
|
||||
</columnConstraints>
|
||||
<rowConstraints>
|
||||
<RowConstraints vgrow="SOMETIMES" />
|
||||
<RowConstraints maxHeight="40.0" minHeight="40.0" prefHeight="40.0" vgrow="SOMETIMES" />
|
||||
<RowConstraints maxHeight="40.0" minHeight="40.0" prefHeight="40.0" vgrow="SOMETIMES" />
|
||||
<RowConstraints maxHeight="40.0" minHeight="40.0" prefHeight="40.0" vgrow="SOMETIMES" />
|
||||
<RowConstraints vgrow="SOMETIMES" />
|
||||
</rowConstraints>
|
||||
<children>
|
||||
<Label text="Add Stop Point" GridPane.columnIndex="1" GridPane.columnSpan="2" GridPane.halignment="CENTER" GridPane.rowIndex="1">
|
||||
<font>
|
||||
<Font size="18.0" />
|
||||
</font>
|
||||
</Label>
|
||||
<Label text="Stop Address:" GridPane.columnIndex="1" GridPane.rowIndex="2" />
|
||||
<Button mnemonicParsing="false" onAction="#addStop" prefHeight="25.0" prefWidth="219.0" text="Add Stop Point" GridPane.columnIndex="1" GridPane.columnSpan="2" GridPane.halignment="CENTER" GridPane.rowIndex="3" />
|
||||
<TextField fx:id="stopAddress" GridPane.columnIndex="2" GridPane.rowIndex="2" />
|
||||
</children>
|
||||
</GridPane>
|
||||
</children>
|
||||
</AnchorPane>
|
||||
@@ -21,25 +21,30 @@
|
||||
<panes>
|
||||
<TitledPane animated="false" text="User Profile">
|
||||
<content>
|
||||
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0">
|
||||
<GridPane>
|
||||
<columnConstraints>
|
||||
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" />
|
||||
</columnConstraints>
|
||||
<rowConstraints>
|
||||
<RowConstraints minHeight="10.0" vgrow="SOMETIMES" />
|
||||
</rowConstraints>
|
||||
<children>
|
||||
<GridPane AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
|
||||
<columnConstraints>
|
||||
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
|
||||
</columnConstraints>
|
||||
<rowConstraints>
|
||||
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
|
||||
</rowConstraints>
|
||||
<VBox>
|
||||
<children>
|
||||
<AnchorPane>
|
||||
<children>
|
||||
<Button mnemonicParsing="false" onAction="#myRides" text="Rides" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" GridPane.hgrow="ALWAYS" GridPane.valignment="TOP" />
|
||||
</children>
|
||||
</AnchorPane>
|
||||
<AnchorPane>
|
||||
<children>
|
||||
<Button mnemonicParsing="false" onAction="#myStops" text="Stops" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" />
|
||||
</children>
|
||||
</AnchorPane>
|
||||
</children>
|
||||
</GridPane>
|
||||
</VBox>
|
||||
</children>
|
||||
</AnchorPane>
|
||||
</GridPane>
|
||||
</content>
|
||||
</TitledPane>
|
||||
<TitledPane text="User Controls">
|
||||
@@ -52,11 +57,20 @@
|
||||
<RowConstraints minHeight="10.0" vgrow="SOMETIMES" />
|
||||
</rowConstraints>
|
||||
<children>
|
||||
<AnchorPane>
|
||||
<VBox>
|
||||
<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" />
|
||||
<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" />
|
||||
</children>
|
||||
</AnchorPane>
|
||||
<AnchorPane>
|
||||
<children>
|
||||
<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>
|
||||
</children>
|
||||
</AnchorPane>
|
||||
</VBox>
|
||||
</children>
|
||||
</GridPane>
|
||||
</content>
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
<?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.MyStopsController">
|
||||
<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 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="1" />
|
||||
<Label text="My Stops" GridPane.columnSpan="2" GridPane.halignment="CENTER">
|
||||
<font>
|
||||
<Font size="18.0" />
|
||||
</font>
|
||||
</Label>
|
||||
</children>
|
||||
</GridPane>
|
||||
</children>
|
||||
</AnchorPane>
|
||||
Reference in New Issue
Block a user