Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/controller/GeneralController.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,18 @@ public void visualizzaLinea(String idLinea,boolean direction) {
}

public void visualizzaFermata(String stop_id) {

// 1. Reset dati precedenti
Set<MyWaypoint> waypoints = stopController.get_Waypoints();
mapController.clearWaypoint(waypoints);

// 2. Carica le informazioni della fermata
stopController.viewStopById(stop_id);
waypoints = stopController.get_Waypoints();

// 3. Aggiorna la mappa con la singola fermata
mapController.initStopspoint("", waypoints);

// 4. Mostra la fermata nella vista laterale
stopController.showFermata();
}
}
57 changes: 48 additions & 9 deletions src/controller/StopController.java
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
package controller;

import java.util.HashSet;
import java.util.Set;
import java.util.*;

import org.jxmapviewer.viewer.GeoPosition;

import service.DataRow;
import service.GTFSManager;
import service.Stop_Times;
import service.*;
import view.MainView;
import waypoint.MyWaypoint;

public class StopController {
private final GTFSManager gtfsManager;
private final MainView mainView;
private final Set<MyWaypoint> waypoints = new HashSet<>();
private final GTFSManager gtfsManager;
private final MainView mainView;
private final Set<MyWaypoint> waypoints = new HashSet<>();
private String stopId;
private String stopName;

public StopController(MainView mainView){
this.gtfsManager = GTFSManager.getInstance();
this.mainView = mainView;
}

public void loadStopWaypoint(String shape_id) {
public void loadStopWaypoint(String shape_id) {
for (Stop_Times item : Stop_Times.getStops_times()) {
MyWaypoint.PointType point;
DataRow row = gtfsManager.getStopById(item.getStop_id());
Expand Down Expand Up @@ -55,6 +54,46 @@ else if(item.getTimepoint().equals("1")) {
}
System.out.println("waypoints: " + waypoints.size());
}

public void viewStopById(String stop_id) {
this.stopId = stop_id;
waypoints.clear();
mainView.get_modelFermate().clear();
mainView.get_modelOrari().clear();

DataRow row = gtfsManager.getStopById(stop_id);
if (row == null) {
return;
}
this.stopName = row.get("stop_name");

MyWaypoint wayPoint = new MyWaypoint(0, stopName, MyWaypoint.PointType.STOPS,
mainView.get_event(),
new GeoPosition(Double.parseDouble(row.get("stop_lat")), Double.parseDouble(row.get("stop_lon"))));
waypoints.add(wayPoint);

List<Stop_Routes> stopRoutes = GTFSReader.filterStop_timesByStop_id(stop_id, gtfsManager);
if (stopRoutes != null) {
Stop_Routes.SetStopRoutes(stopRoutes);
Map<String, List<Stop_Routes>> routes = Stop_Routes.GetStopRoutes();
for (Map.Entry<String, List<Stop_Routes>> entry : routes.entrySet()) {
String route = entry.getKey();
Stop_Routes.setCurrentTimeIndex(route);
Integer idx = Stop_Routes.getCurrentTimeIndex(route);
if (idx != null) {
Stop_Routes sr = entry.getValue().get(idx);
mainView.get_modelOrari().addElement(route + " " + sr.getTrip_headsign() + " " + sr.getArrival_time());
}
}
}
}

public void showFermata() {
mainView.get_lblLinea().setText(stopName + " (" + stopId + ")");
mainView.get_btnInvertiDirezione().setVisible(false);
mainView.get_btnIndietro().setVisible(false);
mainView.get_scrollPanel().setViewportView(mainView.get_orariList());
}

public Set<MyWaypoint> get_Waypoints() {
return waypoints;
Expand Down