/** * Performs actions after specific Route is selected. * * @param ae - Route Object Tag value (String) */ public void selectRouteAction(ItemEvent ae) { Item item = (Item) ((JComboBox) ae.getSource()).getSelectedItem(); String routeTag = item.getId(); Vector<Item> busDirectionItems = null; mainView.enableRefresh(false); try { busDirectionItems = mainModel.getBusDirectionItems(routeTag); if (busDirectionItems.size() > 0) { // Clear Out Bus Stops Table mainView.clearStops(); // Populate Directions Combobox updateMapDirections(busDirectionItems); // Populate Directions Hash Map mainModel.setDirectionsMap(routeTag); // Draw Route on map drawMapRoute(routeTag); } else { mainView.enableRouteDirections(false); } } catch (ServiceUnavailableException e) { mainView.notifyAndExit(MainView.NEXTBUS_SERVICE_UNAVAILABLE); } catch (NullPointerException npe) { resetAll(); // npe.printStackTrace(); } }
/** * Method called when the user inputs an address on the user interface and they want to see the * closes bus stops. * * @param address the user entered address */ public void searchPressedAction(String address) { mainView.enableRefresh(false); this.lastAddress = address; try { if (address != null && address.length() > 0) { // Get closest stops to address ArrayList<RouteStopGeoPositionDTO> closestStops = mainModel.getStopsForDisplay(address); // Get stops with next bus times added ArrayList<Stop> stopsList = mainModel.addNextBusTimes(closestStops); // Clear out Route and Stop Information resetAll(); // Update Stops Table with Closest Stops String[][] closestStopsArray = StopsToArray.convert(closestStops); mainView.enableRefresh(stopsExist(closestStopsArray.length)); mainView.updateStopsTable(closestStopsArray); // Draw Closest Stops on Map drawClosestMapStops(stopsList, address); // Update Status mainView.updateStatus(MainView.DEFAULT_STATUS); } } catch (ServiceUnavailableException e) { mainView.notifyAndExit(MainView.NEXTBUS_SERVICE_UNAVAILABLE); } catch (InvalidAddressException e) { mainView.updateStatus(MainView.INVALID_ADDRESS); } }
/** * Return the RouteList of bus routes that an Agency services. * * @param agency the {@link Agency} to which the RouteList applies * @return the list of Routes */ public Vector<Item> getRouteListItems() { Vector<Item> routeListItems = new Vector<Item>(); try { routeListItems = mainModel.getRouteListItems(); } catch (ServiceUnavailableException e) { mainView.notifyAndExit(MainView.NEXTBUS_SERVICE_UNAVAILABLE); } return routeListItems; }
/** * Accepts {@link Stop} List to draw stops on map for specific set of Stop objects. * * @param stopList - List of Stop objects */ private void drawClosestMapStops(List<Stop> stopList, String address) { try { mapControl = mainView.getMapControl(); mapControl.setCenterPosition(mainModel.getSearchGeoPosition(address)); mapControl.setZoom(2); mapControl.addWaypoint(getWayPoints(stopList), stopList); mapControl.addHomeWaypoint(mainModel.getSearchWayPoint(address)); mapControl.getStopsNearHome(); } catch (ServiceUnavailableException e) { mainView.notifyAndExit(MainView.NEXTBUS_SERVICE_UNAVAILABLE); } catch (InvalidAddressException e) { mainView.updateStatus(MainView.INVALID_ADDRESS); } }
/** * Accepts Route Tag value to retrieve Route object. Gets list of GeoPosition points using Route * object. Draws route on map based on retrieved GeoPosition points. * * @param routeTag - Route Object Tag value (String) */ private void drawMapRoute(String routeTag) { try { Route route = mainModel.getRoute(routeTag); RouteConfig routeConfig = mainModel.getRouteConfig(route); ArrayList<Path> ttfPaths = mainModel.getPathList(route); mapControl = mainView.getMapControl(); mapControl.drawRoute(routeConfig, ttfPaths); mapControl.getAllOverlays(); mainView.updateMapViewer(); } catch (ServiceUnavailableException e) { mainView.notifyAndExit(MainView.NEXTBUS_SERVICE_UNAVAILABLE); } }