Story 7 is done

main
Fan-Wu Yang 9 years ago
parent f0fe89be00
commit 434017c558

@ -37,6 +37,10 @@ public class BaseController extends Controller {
changeScene(SceneCode.MY_STOPS); changeScene(SceneCode.MY_STOPS);
} }
public void searchStops() throws Exception{
changeScene(SceneCode.SEARCH_STOPS);
}
public void addRoute() throws Exception{ public void addRoute() throws Exception{
changeScene(SceneCode.ADD_ROUTE); changeScene(SceneCode.ADD_ROUTE);
} }

@ -0,0 +1,60 @@
package controllers;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.control.ListView;
import javafx.scene.control.TextField;
import model.Stop;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.ResourceBundle;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* Created by Gondr on 1/06/2017.
*/
public class SearchStopsController extends Controller {
@FXML
ListView<Stop> stopsList;
@FXML
TextField stopAddress;
@FXML
TextField stopSuburb;
private List<Stop> listOfAllStops;
private ObservableList<Stop> shownStops;
public void search(){
shownStops.remove(0, shownStops.size());
Pattern addressPattern = Pattern.compile(".*", Pattern.CASE_INSENSITIVE);
if (stopAddress.getText() != "" && stopAddress.getText() != null){
addressPattern = Pattern.compile(".*"+stopAddress.getText()+".*", Pattern.CASE_INSENSITIVE);
}
for (Stop stop:listOfAllStops){
if (addressPattern.matcher(stop.getAddress()).matches()){
shownStops.add(stop);
}
}
}
@Override
public void runLater() {
listOfAllStops = new ArrayList<>(parent.getSession().getDataManager().getStops());
shownStops = FXCollections.observableArrayList(listOfAllStops);
stopsList.setItems(shownStops);
stopAddress.textProperty().addListener(e->{
search();
});
}
@Override
public void initialize(URL location, ResourceBundle resources) {
}
}

@ -7,12 +7,15 @@ import javafx.fxml.FXML;
import javafx.scene.control.ComboBox; import javafx.scene.control.ComboBox;
import javafx.scene.control.TableColumn; import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView; import javafx.scene.control.TableView;
import javafx.scene.control.TextField;
import model.SharedTrip; import model.SharedTrip;
import model.Stop; import model.Stop;
import model.TripStop; import model.TripStop;
import java.net.URL; import java.net.URL;
import java.util.HashMap;
import java.util.ResourceBundle; import java.util.ResourceBundle;
import java.util.regex.Pattern;
/** /**
* Created by Gondr on 28/05/2017. * Created by Gondr on 28/05/2017.
@ -28,25 +31,38 @@ public class SharedTripsController extends Controller{
@FXML @FXML
private TableColumn<SharedTrip, String> daysColumn; private TableColumn<SharedTrip, String> daysColumn;
@FXML @FXML
private ComboBox<Stop> stopsFilter; private ComboBox<TripStop> stopsFilter;
@FXML @FXML
private ObservableList<SharedTrip> sharedTrips; private ObservableList<SharedTrip> sharedTrips;
@FXML
private TextField stopName;
public void resetSearch(){
stopsFilter.getSelectionModel().select(0);
}
public void search(){ public void search(){
sharedTrips.removeAll();
sharedTrips.remove(0, sharedTrips.size()); sharedTrips.remove(0, sharedTrips.size());
boolean ignoreStopFilter = stopsFilter.getSelectionModel().getSelectedIndex() == 0;
boolean ignoreStopNameSearch = stopName.getText().equals("") || stopName.getText() == null;
Pattern stopNamePattern = Pattern.compile(".*"+stopName.getText()+".*", Pattern.CASE_INSENSITIVE);
for(SharedTrip sharedTrip: parent.getSession().getDataManager().getSharedTrips()){ for(SharedTrip sharedTrip: parent.getSession().getDataManager().getSharedTrips()){
//stops are equal //stops are equal
boolean added = false; boolean added = false;
for (TripStop stop : sharedTrip.route) { for (TripStop stop : sharedTrip.route) {
if (stop.equals(stopsFilter.getValue())){ if (stop.equals(stopsFilter.getValue()) || ignoreStopFilter) {
sharedTrips.add(sharedTrip);
added = true;
break;
}
if (stopNamePattern.matcher(stop.getName()).matches()){
sharedTrips.add(sharedTrip); sharedTrips.add(sharedTrip);
added = true; added = true;
break; break;
} }
} }
if (added){ if (added){
continue; continue;//for other filters later
} }
} }
} }
@ -58,10 +74,23 @@ public class SharedTripsController extends Controller{
tripNameColumn.setCellValueFactory(p -> new SimpleStringProperty(p.getValue().name)); tripNameColumn.setCellValueFactory(p -> new SimpleStringProperty(p.getValue().name));
directionColumn.setCellValueFactory(p -> new SimpleStringProperty(p.getValue().direction)); directionColumn.setCellValueFactory(p -> new SimpleStringProperty(p.getValue().direction));
daysColumn.setCellValueFactory(p -> new SimpleStringProperty(p.getValue().getDays())); daysColumn.setCellValueFactory(p -> new SimpleStringProperty(p.getValue().getDays()));
stopsFilter.setItems(parent.getSession().getDataManager().getStops()); //add all stops that have shared trips with them. TODO only display visible ones.
ObservableList<TripStop> stops = FXCollections.observableArrayList();
stops.add(new TripStop("None", ""));
HashMap<TripStop, Boolean> stopAdded = new HashMap<>();
for (SharedTrip trip:sharedTrips){
for(TripStop stop: trip.route){
if (!stopAdded.containsKey(stop)) {
stops.add(stop);
stopAdded.put(stop, true);
}
}
}
stopsFilter.setItems(stops);
stopsFilter.valueProperty().addListener( e ->{ stopsFilter.valueProperty().addListener( e ->{
search(); search();
}); });
stopName.textProperty().addListener(e-> search());
} }
@Override @Override

@ -15,7 +15,7 @@ public enum SceneCode {
MAIN("main", false), BASE("base", false), MAIN("main", false), BASE("base", false),
//screens after login //screens after login
HOME("home"),ADD_RIDE("addride"),MY_RIDES("myrides"), ADD_STOPS("addstops"), MY_STOPS("mystops"), ADD_ROUTE("addroute"), HOME("home"),ADD_RIDE("addride"),MY_RIDES("myrides"), ADD_STOPS("addstops"), MY_STOPS("mystops"), ADD_ROUTE("addroute"),
MY_ROUTES("myroutes"), ADD_TRIP("addtrip"), MY_TRIPS("mytrips"), SHARED_RIDES("sharedtrips"); MY_ROUTES("myroutes"), ADD_TRIP("addtrip"), MY_TRIPS("mytrips"), SHARED_RIDES("sharedtrips"), SEARCH_STOPS("searchstops");
private String path; private String path;
private boolean loadMenu; private boolean loadMenu;

@ -58,4 +58,8 @@ public class TripStop{
time = new SimpleStringProperty(serialiseTime); time = new SimpleStringProperty(serialiseTime);
name = new SimpleStringProperty(serialiseName); name = new SimpleStringProperty(serialiseName);
} }
public String toString(){
return getName();
}
} }

@ -57,6 +57,11 @@
<Button mnemonicParsing="false" onAction="#sharedRides" text="Shared Rides" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" /> <Button mnemonicParsing="false" onAction="#sharedRides" text="Shared Rides" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" />
</children> </children>
</AnchorPane> </AnchorPane>
<AnchorPane prefHeight="200.0" prefWidth="200.0">
<children>
<Button mnemonicParsing="false" onAction="#searchStops" text="Search Stops" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" />
</children>
</AnchorPane>
</children> </children>
</VBox> </VBox>
</children> </children>

@ -11,14 +11,16 @@
<columnConstraints> <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 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> </columnConstraints>
<rowConstraints> <rowConstraints>
<RowConstraints maxHeight="50.0" minHeight="50.0" prefHeight="50.0" vgrow="SOMETIMES" /> <RowConstraints maxHeight="50.0" minHeight="50.0" prefHeight="50.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="348.0" vgrow="SOMETIMES" /> <RowConstraints minHeight="10.0" prefHeight="348.0" vgrow="SOMETIMES" />
</rowConstraints> </rowConstraints>
<children> <children>
<ListView fx:id="stopsList" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" prefHeight="200.0" prefWidth="200.0" GridPane.rowIndex="1" /> <ListView fx:id="stopsList" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" prefHeight="200.0" prefWidth="200.0" GridPane.columnSpan="2" GridPane.rowIndex="1" />
<Label text="My Stops" GridPane.columnSpan="2" GridPane.halignment="CENTER"> <Label text="My Stops" GridPane.columnSpan="4" GridPane.halignment="CENTER">
<font> <font>
<Font size="18.0" /> <Font size="18.0" />
</font> </font>

@ -0,0 +1,36 @@
<?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.SearchStopsController">
<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 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="stopsList" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" prefHeight="200.0" prefWidth="200.0" GridPane.columnSpan="2" GridPane.rowIndex="2" />
<Label text="Search Stops" GridPane.columnSpan="4" GridPane.halignment="CENTER">
<font>
<Font size="18.0" />
</font>
</Label>
<Label text="Address" GridPane.rowIndex="1" />
<TextField fx:id="stopAddress" GridPane.columnIndex="1" GridPane.rowIndex="1" />
<Label text="Suburb:" GridPane.columnIndex="2" GridPane.rowIndex="1" />
<TextField fx:id="stopSuburb" GridPane.columnIndex="3" GridPane.rowIndex="1" />
</children>
</GridPane>
</children>
</AnchorPane>

@ -22,6 +22,7 @@
<RowConstraints maxHeight="20.0" minHeight="20.0" prefHeight="20.0" vgrow="SOMETIMES" /> <RowConstraints maxHeight="20.0" minHeight="20.0" prefHeight="20.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="5.0" minHeight="5.0" prefHeight="5.0" vgrow="SOMETIMES" /> <RowConstraints maxHeight="5.0" minHeight="5.0" prefHeight="5.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 maxHeight="40.0" minHeight="40.0" prefHeight="40.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="348.0" vgrow="SOMETIMES" /> <RowConstraints minHeight="10.0" prefHeight="348.0" vgrow="SOMETIMES" />
</rowConstraints> </rowConstraints>
<children> <children>
@ -30,7 +31,7 @@
<Font size="18.0" /> <Font size="18.0" />
</font> </font>
</Label> </Label>
<TableView fx:id="sharedTripsTable" prefHeight="200.0" prefWidth="200.0" GridPane.columnSpan="6" GridPane.rowIndex="4"> <TableView fx:id="sharedTripsTable" prefHeight="200.0" prefWidth="200.0" GridPane.columnSpan="6" GridPane.rowIndex="5">
<columns> <columns>
<TableColumn fx:id="tripNameColumn" prefWidth="75.0" text="Trip Name" /> <TableColumn fx:id="tripNameColumn" prefWidth="75.0" text="Trip Name" />
<TableColumn fx:id="directionColumn" prefWidth="75.0" text="Direction" /> <TableColumn fx:id="directionColumn" prefWidth="75.0" text="Direction" />
@ -41,6 +42,13 @@
<Separator prefWidth="200.0" GridPane.columnSpan="6" GridPane.rowIndex="2" /> <Separator prefWidth="200.0" GridPane.columnSpan="6" GridPane.rowIndex="2" />
<Label text="Stops:" GridPane.rowIndex="3" /> <Label text="Stops:" GridPane.rowIndex="3" />
<ComboBox fx:id="stopsFilter" prefWidth="150.0" GridPane.columnIndex="1" GridPane.rowIndex="3" /> <ComboBox fx:id="stopsFilter" prefWidth="150.0" GridPane.columnIndex="1" GridPane.rowIndex="3" />
<Label text="Stop Name:" GridPane.columnIndex="2" GridPane.rowIndex="3" />
<TextField fx:id="stopName" GridPane.columnIndex="3" GridPane.rowIndex="3" />
<AnchorPane GridPane.columnIndex="2" GridPane.columnSpan="2" GridPane.rowIndex="4">
<children>
<Button fx:id="resetSearch" mnemonicParsing="false" text="Reset Search" AnchorPane.bottomAnchor="8.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="7.0" GridPane.columnIndex="2" GridPane.columnSpan="2" GridPane.rowIndex="4" GridPane.valignment="CENTER" />
</children>
</AnchorPane>
</children> </children>
</GridPane> </GridPane>
</children> </children>

@ -57,6 +57,11 @@
<Button mnemonicParsing="false" onAction="#sharedRides" text="Shared Rides" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" /> <Button mnemonicParsing="false" onAction="#sharedRides" text="Shared Rides" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" />
</children> </children>
</AnchorPane> </AnchorPane>
<AnchorPane prefHeight="200.0" prefWidth="200.0">
<children>
<Button mnemonicParsing="false" onAction="#searchStops" text="Search Stops" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" />
</children>
</AnchorPane>
</children> </children>
</VBox> </VBox>
</children> </children>

@ -11,14 +11,16 @@
<columnConstraints> <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 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> </columnConstraints>
<rowConstraints> <rowConstraints>
<RowConstraints maxHeight="50.0" minHeight="50.0" prefHeight="50.0" vgrow="SOMETIMES" /> <RowConstraints maxHeight="50.0" minHeight="50.0" prefHeight="50.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="348.0" vgrow="SOMETIMES" /> <RowConstraints minHeight="10.0" prefHeight="348.0" vgrow="SOMETIMES" />
</rowConstraints> </rowConstraints>
<children> <children>
<ListView fx:id="stopsList" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" prefHeight="200.0" prefWidth="200.0" GridPane.rowIndex="1" /> <ListView fx:id="stopsList" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" prefHeight="200.0" prefWidth="200.0" GridPane.columnSpan="2" GridPane.rowIndex="1" />
<Label text="My Stops" GridPane.columnSpan="2" GridPane.halignment="CENTER"> <Label text="My Stops" GridPane.columnSpan="4" GridPane.halignment="CENTER">
<font> <font>
<Font size="18.0" /> <Font size="18.0" />
</font> </font>

@ -0,0 +1,36 @@
<?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.SearchStopsController">
<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 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="stopsList" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" prefHeight="200.0" prefWidth="200.0" GridPane.columnSpan="2" GridPane.rowIndex="2" />
<Label text="Search Stops" GridPane.columnSpan="4" GridPane.halignment="CENTER">
<font>
<Font size="18.0" />
</font>
</Label>
<Label text="Address" GridPane.rowIndex="1" />
<TextField fx:id="stopAddress" GridPane.columnIndex="1" GridPane.rowIndex="1" />
<Label text="Suburb:" GridPane.columnIndex="2" GridPane.rowIndex="1" />
<TextField fx:id="stopSuburb" GridPane.columnIndex="3" GridPane.rowIndex="1" />
</children>
</GridPane>
</children>
</AnchorPane>

@ -22,6 +22,7 @@
<RowConstraints maxHeight="20.0" minHeight="20.0" prefHeight="20.0" vgrow="SOMETIMES" /> <RowConstraints maxHeight="20.0" minHeight="20.0" prefHeight="20.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="5.0" minHeight="5.0" prefHeight="5.0" vgrow="SOMETIMES" /> <RowConstraints maxHeight="5.0" minHeight="5.0" prefHeight="5.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 maxHeight="40.0" minHeight="40.0" prefHeight="40.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="348.0" vgrow="SOMETIMES" /> <RowConstraints minHeight="10.0" prefHeight="348.0" vgrow="SOMETIMES" />
</rowConstraints> </rowConstraints>
<children> <children>
@ -30,7 +31,7 @@
<Font size="18.0" /> <Font size="18.0" />
</font> </font>
</Label> </Label>
<TableView fx:id="sharedTripsTable" prefHeight="200.0" prefWidth="200.0" GridPane.columnSpan="6" GridPane.rowIndex="4"> <TableView fx:id="sharedTripsTable" prefHeight="200.0" prefWidth="200.0" GridPane.columnSpan="6" GridPane.rowIndex="5">
<columns> <columns>
<TableColumn fx:id="tripNameColumn" prefWidth="75.0" text="Trip Name" /> <TableColumn fx:id="tripNameColumn" prefWidth="75.0" text="Trip Name" />
<TableColumn fx:id="directionColumn" prefWidth="75.0" text="Direction" /> <TableColumn fx:id="directionColumn" prefWidth="75.0" text="Direction" />
@ -41,6 +42,13 @@
<Separator prefWidth="200.0" GridPane.columnSpan="6" GridPane.rowIndex="2" /> <Separator prefWidth="200.0" GridPane.columnSpan="6" GridPane.rowIndex="2" />
<Label text="Stops:" GridPane.rowIndex="3" /> <Label text="Stops:" GridPane.rowIndex="3" />
<ComboBox fx:id="stopsFilter" prefWidth="150.0" GridPane.columnIndex="1" GridPane.rowIndex="3" /> <ComboBox fx:id="stopsFilter" prefWidth="150.0" GridPane.columnIndex="1" GridPane.rowIndex="3" />
<Label text="Stop Name:" GridPane.columnIndex="2" GridPane.rowIndex="3" />
<TextField fx:id="stopName" GridPane.columnIndex="3" GridPane.rowIndex="3" />
<AnchorPane GridPane.columnIndex="2" GridPane.columnSpan="2" GridPane.rowIndex="4">
<children>
<Button fx:id="resetSearch" mnemonicParsing="false" text="Reset Search" AnchorPane.bottomAnchor="8.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="7.0" GridPane.columnIndex="2" GridPane.columnSpan="2" GridPane.rowIndex="4" GridPane.valignment="CENTER" />
</children>
</AnchorPane>
</children> </children>
</GridPane> </GridPane>
</children> </children>

Loading…
Cancel
Save