|
|
|
|
@ -10,6 +10,7 @@ import javafx.scene.control.TableView;
|
|
|
|
|
import javafx.scene.control.TextField;
|
|
|
|
|
import model.SharedTrip;
|
|
|
|
|
import model.Stop;
|
|
|
|
|
import model.Trip;
|
|
|
|
|
import model.TripStop;
|
|
|
|
|
|
|
|
|
|
import java.net.URL;
|
|
|
|
|
@ -36,6 +37,12 @@ public class SharedTripsController extends Controller{
|
|
|
|
|
private ObservableList<SharedTrip> sharedTrips;
|
|
|
|
|
@FXML
|
|
|
|
|
private TextField stopName;
|
|
|
|
|
@FXML
|
|
|
|
|
private ComboBox<String> directionBox;
|
|
|
|
|
|
|
|
|
|
public void showDetails(){
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void resetSearch(){
|
|
|
|
|
stopsFilter.getSelectionModel().select(0);
|
|
|
|
|
@ -43,26 +50,35 @@ public class SharedTripsController extends Controller{
|
|
|
|
|
|
|
|
|
|
public void search(){
|
|
|
|
|
sharedTrips.remove(0, sharedTrips.size());
|
|
|
|
|
//ignore stop
|
|
|
|
|
boolean ignoreStopFilter = stopsFilter.getSelectionModel().getSelectedIndex() == 0;
|
|
|
|
|
boolean ignoreStopNameSearch = stopName.getText().equals("") || stopName.getText() == null;
|
|
|
|
|
boolean ignoreStopSearch = ignoreStopFilter && ignoreStopNameSearch;
|
|
|
|
|
Pattern stopNamePattern = Pattern.compile(".*"+stopName.getText()+".*", Pattern.CASE_INSENSITIVE);
|
|
|
|
|
//ignore direction
|
|
|
|
|
boolean ignoreDirection = directionBox.getSelectionModel().isSelected(0);
|
|
|
|
|
for(SharedTrip sharedTrip: parent.getSession().getDataManager().getSharedTrips()){
|
|
|
|
|
//stops are equal
|
|
|
|
|
boolean added = false;
|
|
|
|
|
boolean add = false;
|
|
|
|
|
for (TripStop stop : sharedTrip.route) {
|
|
|
|
|
if (stop.equals(stopsFilter.getValue()) || ignoreStopFilter) {
|
|
|
|
|
sharedTrips.add(sharedTrip);
|
|
|
|
|
added = true;
|
|
|
|
|
if (ignoreStopSearch){
|
|
|
|
|
add = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (stop.equals(stopsFilter.getValue())) {
|
|
|
|
|
add = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (stopNamePattern.matcher(stop.getName()).matches()){
|
|
|
|
|
sharedTrips.add(sharedTrip);
|
|
|
|
|
added = true;
|
|
|
|
|
add = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (added){
|
|
|
|
|
continue;//for other filters later
|
|
|
|
|
if (!ignoreDirection) {
|
|
|
|
|
add = sharedTrip.direction.equals(directionBox.getValue());
|
|
|
|
|
}
|
|
|
|
|
if (add){
|
|
|
|
|
sharedTrips.add(sharedTrip);//for other filters later
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -76,7 +92,7 @@ public class SharedTripsController extends Controller{
|
|
|
|
|
daysColumn.setCellValueFactory(p -> new SimpleStringProperty(p.getValue().getDays()));
|
|
|
|
|
//add all stops that have shared trips with them. TODO only display visible ones.
|
|
|
|
|
ObservableList<TripStop> stops = FXCollections.observableArrayList();
|
|
|
|
|
stops.add(new TripStop("None", ""));
|
|
|
|
|
stops.add(new TripStop("Any", ""));
|
|
|
|
|
HashMap<TripStop, Boolean> stopAdded = new HashMap<>();
|
|
|
|
|
for (SharedTrip trip:sharedTrips){
|
|
|
|
|
for(TripStop stop: trip.route){
|
|
|
|
|
@ -91,10 +107,13 @@ public class SharedTripsController extends Controller{
|
|
|
|
|
search();
|
|
|
|
|
});
|
|
|
|
|
stopName.textProperty().addListener(e-> search());
|
|
|
|
|
directionBox.valueProperty().addListener(e->search());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void initialize(URL location, ResourceBundle resources) {
|
|
|
|
|
|
|
|
|
|
ObservableList<String> directions = FXCollections.observableArrayList();
|
|
|
|
|
directions.addAll("Any", Trip.TO_UNI, Trip.TO_HOME);
|
|
|
|
|
directionBox.setItems(directions);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|