/** Called when route values changes and the fields should be refreshed */
 private void updateFields() {
   if (!readOnlyRoute) {
     route.calcValues(true);
     route.calcAllWpEta();
   }
   inrouteTxT.setText(Formatter.formatTime(route.getRouteTtg()));
   distanceTxT.setText(Formatter.formatDistNM(route.getRouteDtg()));
   routeTableModel.fireTableDataChanged();
 }
  /** 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;
  }
Exemplo n.º 3
0
 /**
  * Constructor
  *
  * @param text
  */
 public ChatMessageLabel(String text, boolean ownMessage) {
   super(
       String.format(
           "<html><div align='%s'>%s</div></html>",
           ownMessage ? "right" : "left", Formatter.formatHtml(text)));
   setFont(getFont().deriveFont(10f));
 }
Exemplo n.º 4
0
  @Override
  public synchronized String getStatusHtml() {
    StringBuilder buf = new StringBuilder();
    buf.append("Contact: " + status.name() + "<br/>");
    if (status == Status.ERROR) {
      buf.append("Last error: " + Formatter.formatLongDateTime(lastFailed) + "<br/>");
      buf.append("Error message: " + lastException.getMessage());
      if (lastException.getExtraMessage() != null) {
        buf.append(": " + lastException.getExtraMessage());
      }
    } else {
      buf.append("Last contact: " + Formatter.formatLongDateTime(lastContact));
    }

    return buf.toString();
  }
  /**
   * 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);
  }
Exemplo n.º 6
0
  /** Updates the chat message panel in the Swing event thread */
  public void updateChatMessagePanel() {
    // Ensure that we operate in the Swing event thread
    if (!SwingUtilities.isEventDispatchThread()) {
      SwingUtilities.invokeLater(
          new Runnable() {
            @Override
            public void run() {
              updateChatMessagePanel();
            }
          });
      return;
    }

    // Set the title header
    titleHeader.setText(
        chatData != null ? NameUtils.getName(chatData.getId(), NameFormat.MEDIUM) : " ");
    titleHeader.setVisible(chatData != null);

    // Only enable send-function when there is chat data, and hence a target
    sendBtn.setEnabled(chatData != null);
    messageText.setEditable(chatData != null);

    // Remove all components from the messages panel
    messagesPanel.removeAll();

    Insets insets = new Insets(0, 2, 2, 2);
    Insets insets2 = new Insets(6, 2, 0, 2);

    if (chatData != null && chatData.getMessageCount() > 0) {

      // First, add a filler component
      int y = 0;
      messagesPanel.add(
          new JLabel(""),
          new GridBagConstraints(0, y++, 1, 1, 0.0, 1.0, NORTH, VERTICAL, insets, 0, 0));

      // Add the messages
      long lastMessageTime = 0;
      for (EPDChatMessage message : chatData.getMessages()) {

        // Check if we need to add a time label
        if (message.getSendDate().getTime() - lastMessageTime > PRINT_DATE_INTERVAL) {
          JLabel dateLabel =
              new JLabel(
                  String.format(
                      message.isOwnMessage() ? "Sent to %s" : "Received %s",
                      Formatter.formatShortDateTimeNoTz(
                          new Date(message.getSendDate().getTime()))));
          dateLabel.setFont(dateLabel.getFont().deriveFont(9.0f).deriveFont(Font.PLAIN));
          dateLabel.setHorizontalAlignment(SwingConstants.CENTER);
          dateLabel.setForeground(Color.LIGHT_GRAY);
          messagesPanel.add(
              dateLabel,
              new GridBagConstraints(0, y++, 1, 1, 1.0, 0.0, NORTH, HORIZONTAL, insets2, 0, 0));
        }

        // Add a chat message field
        JPanel msg = new JPanel();
        msg.setBorder(new ChatMessageBorder(message));
        JLabel msgLabel = new ChatMessageLabel(message.getMsg(), message.isOwnMessage());
        msg.add(msgLabel);
        messagesPanel.add(
            msg, new GridBagConstraints(0, y++, 1, 1, 1.0, 0.0, NORTH, HORIZONTAL, insets, 0, 0));

        lastMessageTime = message.getSendDate().getTime();
      }

      // Scroll to the bottom
      validate();
      scrollPane.getVerticalScrollBar().setValue(scrollPane.getVerticalScrollBar().getMaximum());
      messagesPanel.repaint();

    } else if (chatData == null && noDataComponent != null) {
      // The noDataComponent may e.g. be a message
      messagesPanel.add(
          noDataComponent, new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0, NORTH, BOTH, insets, 0, 0));
    }
  }
Exemplo n.º 7
0
 public synchronized void markContactError(ShoreServiceException e) {
   lastFailed = new Date();
   status = Status.ERROR;
   this.lastException = e;
   shortStatusText = "Last failed shore contact: " + Formatter.formatLongDateTime(lastFailed);
 }
Exemplo n.º 8
0
  /**
   * Overriding function for setting the behavior when a coordinate is received
   *
   * @param llp point including lat and lon
   */
  @Override
  public void receiveCoord(LatLonPoint llp) {

    statusItems.get("LAT").setText(" LAT  " + Formatter.latToPrintable(llp.getLatitude()));
    statusItems.get("LON").setText(" LON " + Formatter.lonToPrintable(llp.getLongitude()));
  }