/** Updates the dialog with the value of the current route */
  private void initValues() {

    // Should not trigger listeners
    quiescent = true;

    nameTxT.setText(route.getName());
    originTxT.setText(route.getDeparture());
    destinationTxT.setText(route.getDestination());

    etaCalculationTime.setSelectedItem(route.getEtaCalculationType());

    // Update the route start time and the start time-related fields
    adjustStartTime();

    cbVisible.setSelected(route.isVisible());

    if (route.getWaypoints().size() > 1) {
      allSpeeds.setText(Formatter.formatSpeed(route.getWaypoints().get(0).getOutLeg().getSpeed()));
    }

    updateButtonEnabledState();

    // Done
    quiescent = false;
  }
  /**
   * Handle action events
   *
   * @param evt the action event
   */
  @Override
  public void actionPerformed(ActionEvent evt) {
    // Check if we are in a quiescent state
    if (quiescent) {
      return;
    }

    if (evt.getSource() == btnZoomToRoute && chartPanel != null) {
      chartPanel.zoomToWaypoints(route.getWaypoints());

    } else if (evt.getSource() == btnZoomToWp && chartPanel != null) {
      chartPanel.goToPosition(route.getWaypoints().get(selectedWp).getPos());

    } else if (evt.getSource() == btnDelete) {
      onDelete();
      routeUpdated();

    } else if (evt.getSource() == btnActivate) {
      EPD.getInstance().getRouteManager().changeActiveWp(selectedWp);
      routeUpdated();

    } else if (evt.getSource() == btnClose) {
      dispose();

    } else if (evt.getSource() == cbVisible) {
      route.setVisible(cbVisible.isSelected());

      EPD.getInstance()
          .getRouteManager()
          .notifyListeners(RoutesUpdateEvent.ROUTE_VISIBILITY_CHANGED);

    } else if (evt.getSource() == etaCalculationTime) {
      route.setEtaCalculationType((EtaCalculationType) etaCalculationTime.getSelectedItem());
      adjustStartTime();
      routeUpdated();

    } else if (evt.getSource() == allSpeedsBtn) {
      double speed;
      try {
        speed = parseDouble(allSpeeds.getText());
        allSpeeds.setText(Formatter.formatSpeed(speed));
      } catch (FormatException e) {
        JOptionPane.showMessageDialog(
            this, "Error in speed", "Input error", JOptionPane.ERROR_MESSAGE);
        return;
      }
      for (int i = 0; i < route.getWaypoints().size(); i++) {
        RouteWaypoint wp = route.getWaypoints().get(i);
        if (wp.getOutLeg() != null && !locked[i]) {
          wp.getOutLeg().setSpeed(speed);
        }
      }
      adjustStartTime();
    }

    EPD.getInstance().getRouteManager().notifyListeners(RoutesUpdateEvent.ROUTE_CHANGED);
  }