/**
   * 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();
    }
  }
 /**
  * Retrieves list of Direction stops from Model and passes over to the View updateStops method
  *
  * @throws ServiceUnavailableException
  */
 private void updateDirectionStopsTable(Direction direction) throws ServiceUnavailableException {
   String[][] stopList =
       mainModel.getRouteStopsArray(
           FindStopsHelper.identifyStopsForDirection(direction, mainModel.getAllStopsList()));
   mainView.enableRefresh(stopsExist(stopList.length));
   mainView.updateStopsTable(stopList);
 }
  /**
   * 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);
    }
  }
  /**
   * Retrieves a list of all the RouteConfigs for specified Agency and stores the result in a
   * MainModel variable
   */
  public void processAllRouteConfigs() {
    mainView.updateStatus("Address search disabled until Route Configs loaded...");
    try {
      long current = System.currentTimeMillis();
      RouteList routeList = mainModel.getRouteList();
      Map<String, RouteConfig> allRouteConfigs =
          new HashMap<String, RouteConfig>(routeList.getRoutes().size());

      mainView.setupProgressBar(routeList.getRoutes().size());
      int progressLength = 1;

      for (Route route : routeList.getRoutes()) {
        RouteConfig routeConfig = mainModel.getRouteConfig(route);
        allRouteConfigs.put(route.getTag(), routeConfig);
        mainView.updateProgressBar(progressLength++);
        Thread.sleep(1);
      }

      mainModel.setAllRouteConfigs(allRouteConfigs);
      mainView.updateStatus(
          "It took " + (System.currentTimeMillis() - current) + " ms to get all routeConfigs.");
      Thread.sleep(5000);
      mainView.updateStatus(MainView.DEFAULT_STATUS);

    } catch (InterruptedException | ServiceUnavailableException e) {
      e.printStackTrace();
    }
  }
 @Override
 public void firstFetchItems() {
   checkAttached();
   mMainModel.setCurrSort(mMainView.getCurrSort());
   mMainModel.setCurrList(mMainView.getCurrList());
   mMainModel.setCurrTimeFrame(mMainView.getCurrTimeFrame());
   super.firstFetchItems();
 }
Exemple #6
0
 private void refreshIfNeeded() {
   Log.e(tag, "refreshing");
   if (MainModel.isChanged()) {
     clearFamilyStoryLines();
     clearLifeStory();
     clearSpouseLine();
     mMap.clear();
     mMap.setMapType(Settings.getMapType());
     showEvents();
   }
   MainModel.setChanged(false);
 }
 /**
  * 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);
    }
  }
Exemple #9
0
 private void showEvents() {
   for (String eventId : MainModel.events.keySet()) {
     if (MainModel.isEventVisible(eventId)) {
       showEvent(eventId);
     }
   }
 }
Exemple #10
0
  private void setUpMap() {
    mMap.setOnMarkerClickListener(
        new GoogleMap.OnMarkerClickListener() {
          @Override
          public boolean onMarkerClick(Marker marker) {
            //              Log.e(tag, "clicked on marker");
            String eventId = marker.getSnippet();
            setEvent(eventId);
            refreshIfNeeded();
            return false;
          }
        });

    mMap.setMapType(Settings.getMapType());

    computeMarkerColors();

    showEvents();

    selEventId = ((MapActivityInterface) getActivity()).getEventId();
    if (selEventId != null) {
      Log.e(tag, "Setting up initial event");
      setEvent(selEventId);
      Event e = MainModel.getEvent(selEventId);
      mMap.animateCamera(
          CameraUpdateFactory.newLatLngZoom(new LatLng(e.getLat(), e.getLng()), 12.0f));
    }
    //        mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(latitude,
    //              longitude), 12.0f));
  }
Exemple #11
0
  private void setEvent(String eventId) {
    Event e = MainModel.getEvent(eventId);
    Person p = MainModel.getPerson(e.getPersonId());
    String eventText =
        p.getFirstName()
            + " "
            + p.getLastName()
            + System.getProperty("line.separator")
            + e.fullDescription();
    //        Log.e(tag, "setting event text to " + eventText);
    event_text.setText(eventText);
    selPersonId = e.getPersonId();
    selEventId = eventId;
    updateLines();

    showGenderImage(p.getGender());
  }
Exemple #12
0
  private void recDrawFamilyStoryLines(Event event, int width) {
    //    Log.e(tag, "Called recDraw with event "+event.toString()+" width: "+width);
    Person p = event.getPerson();
    Person mother = MainModel.getPerson(p.getMotherId());
    Person father = MainModel.getPerson(p.getFatherId());
    if (mother != null) {
      Event firstMotherEvent = mother.getEarliestEvent();
      drawFamilyStoryLine(event, firstMotherEvent, width);
      ;
      recDrawFamilyStoryLines(firstMotherEvent, width - Settings.FAMILY_LINE_DEC);
    }

    if (father != null) {
      Event firstFatherEvent = father.getEarliestEvent();
      drawFamilyStoryLine(event, firstFatherEvent, width);
      recDrawFamilyStoryLines(firstFatherEvent, width - Settings.FAMILY_LINE_DEC);
    }
  }
Exemple #13
0
  private void updateSpouseLines() {
    clearSpouseLine();

    if (!Settings.isSpouseLinesEnabled()) return;

    Event selEvent = MainModel.getEvent(selEventId);
    Person p = selEvent.getPerson();
    Person spouse = MainModel.getPerson(p.getSpouseId());

    if (spouse == null || selEvent == null) return;

    Event firstSpouseEvent = spouse.getEarliestEvent();

    if (firstSpouseEvent == null) return;

    if (!MainModel.isEventVisible(selEvent.getId())
        || !MainModel.isEventVisible(firstSpouseEvent.getId())) return;
    spouseLine =
        drawLine(selEvent, firstSpouseEvent, SPOUSE_LINE_WIDTH, Settings.getSpouseLineColor());
  }
  /**
   * 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;
  }
Exemple #15
0
  private void updateLifeStory() {
    //      Log.e(tag, "updating life story");
    ArrayList<Event> events = MainModel.getPerson(selPersonId).getSortedEvents();
    ArrayList<Event> visibleEvents = new ArrayList<Event>();
    for (int i = 0; i < events.size(); i++) {
      Event curr_event = events.get(i);
      if (MainModel.isEventVisible(curr_event.getId())) {
        visibleEvents.add(curr_event);
        //                Log.e(tag, "visible event: "+curr_event.toString());
      }
    }

    clearLifeStory();
    if (!Settings.isLifeLinesEnabled()) return;

    for (int j = 1; j < visibleEvents.size(); j++) {
      Event event1 = visibleEvents.get(j - 1);
      Event event2 = visibleEvents.get(j);
      lifeStory.add(drawLine(event1, event2, LIFE_STORY_WIDTH, Settings.getLifeStoryColor()));
    }
  }
Exemple #16
0
 private void showEvent(String eventId) {
   Event e = MainModel.getEvent(eventId);
   LatLng pos =
       new LatLng(
           e.getLat() + Math.random() / MARKER_FUDGE_DENOM,
           e.getLng() + Math.random() / MARKER_FUDGE_DENOM);
   String description = e.getDescription();
   float event_color =
       (description_hues.containsKey(description))
           ? description_hues.get(description)
           : DEFAULT_MARKER_COLOR;
   mMap.addMarker(
       new MarkerOptions()
           .position(pos)
           .snippet(eventId)
           .icon(BitmapDescriptorFactory.defaultMarker(event_color)));
 }
  /**
   * Performs actions after specific Direction is selected.
   *
   * @param ae - Direction Object Tag value (String)
   * @throws ServiceUnavailableException
   */
  public void selectDirectionAction(ItemEvent ae) throws ServiceUnavailableException {
    Item item = (Item) ((JComboBox) ae.getSource()).getSelectedItem();
    String directionTag = item.getId();
    Direction direction = null;
    mainView.enableRefresh(false);
    this.lastItemEvent = ae;

    try {
      direction = mainModel.getDirection(directionTag);

      // Show Stops for Direction on Table
      updateDirectionStopsTable(direction);

      // Draw Stops on map
      drawMapStops(direction);
    } catch (NullPointerException npe) {
      mainView.clearStops();
    }
  }
 @Override
 public void detachView() {
   detachBaseView();
   mMainView = null;
   mMainModel.onDetach();
 }
 @Override
 public void fetchUserInfo() {
   checkAttached();
   mMainModel.fetchUserInfo();
 }
 @Override
 public void requestToken(AuthorizeInfo info) {
   checkAttached();
   mMainModel.requestToken(info);
 }
Exemple #21
0
 private void updateFamilyStoryLines() {
   clearFamilyStoryLines();
   if (!Settings.isFamilyLinesEnabled()) return;
   recDrawFamilyStoryLines(MainModel.getEvent(selEventId), Settings.START_FAMILY_LINE_WIDTH);
 }
 /**
  * Retrieves list of Route stops from Model and passes over to the View updateStops method
  *
  * @throws ServiceUnavailableException
  */
 private void updateRouteStopsTable(ArrayList<Stop> stopList) throws ServiceUnavailableException {
   mainView.updateStopsTable(mainModel.getRouteStopsArray(stopList));
 }
 /**
  * Accepts {@link Direction} object to draw stops on map for specific Direction.
  *
  * @param direction - Direction Object
  */
 private void drawMapStops(Direction direction) {
   // Uses the FindStops Helper to retrieve a list of stops specific to a Direction
   drawMapStops(FindStopsHelper.identifyStopsForDirection(direction, mainModel.getAllStopsList()));
 }
Exemple #24
0
 /**
  * If the source and target events are visible, draw a line between the source and target, and
  * save it in the map of lines. This is so that the lines can be removed when changing the
  * selected event.
  */
 private void drawFamilyStoryLine(Event source, Event target, int width) {
   if (source == null || target == null) return;
   if (MainModel.isEventVisible(source.getId()) && MainModel.isEventVisible(target.getId())) {
     familyLines.add(drawLine(source, target, width, Settings.getFamilyStoryColor()));
   }
 }