Exemplo n.º 1
0
  /*
   * (non-Javadoc)
   *
   * @see gui.observer.Observer#update(gui.observer.Observable)
   */
  @Override
  public void update(Observable observable) {

    if (observable instanceof JComponent) {

      JComponent component = (JComponent) observable;
      String scaledPositionMessage = "Scaled position (px): ";
      scaledPositionMessage +=
          "x = " + component.getLocation().x + ", y = " + component.getLocation().y + ".";
      String actualPositionMessage = "Actual position (px): ";
      actualPositionMessage +=
          "x = "
              + (int) (component.getLocation().x / scalingRatioToFitContainer)
              + ", y = "
              + (int) (component.getLocation().y / scalingRatioToFitContainer)
              + ".";
      String messageToDisplay = scaledPositionMessage + " " + actualPositionMessage;

      parent.setStatus(messageToDisplay);
    }
  }
Exemplo n.º 2
0
  /**
   * Getter for <code>RoomMap</code> object with all its properties, including <code>Receiver</code>
   * s and <code>CoordinateZeroMarkerView</code>s .
   *
   * @return the map
   * @see Receiver
   * @see ReceiverView
   * @see CoordinateZeroMarkerView
   */
  public RoomMap getMap() {

    // set zero coordinate marker positions
    int lowerLeftMarkerOffsetXInPixels =
        (int) (lowerLeftMarker.getLocation().getX() / scalingRatioToFitContainer);
    int lowerLeftMarkerOffsetYInPixels =
        (int) (lowerLeftMarker.getLocation().getY() / scalingRatioToFitContainer)
            + (CoordinateZeroMarkerView.ZERO_COORDINATE_MARKER_VIEW_HEIGHT);
    map.setLowerLeftMarkerOffsetXInPixels(lowerLeftMarkerOffsetXInPixels);
    map.setLowerLeftMarkerOffsetYInPixels(lowerLeftMarkerOffsetYInPixels);

    int upperRightMarkerOffsetXInPixels =
        (int) (upperRightMarker.getLocation().getX() / scalingRatioToFitContainer)
            + (CoordinateZeroMarkerView.ZERO_COORDINATE_MARKER_VIEW_WIDTH);
    int upperRightMarkerOffsetYInPixels =
        (int) (upperRightMarker.getLocation().getY() / scalingRatioToFitContainer);
    map.setUpperRightMarkerOffsetXInPixels(upperRightMarkerOffsetXInPixels);
    map.setUpperRightMarkerOffsetYInPixels(upperRightMarkerOffsetYInPixels);

    // set room width and height in meters
    double roomWidthInMeters = parent.getRoomWidthInMeters();
    double roomHeightInMeters = parent.getRoomHeightInMeters();
    map.setWidthInMeters(roomWidthInMeters);
    map.setHeightInMeters(roomHeightInMeters);

    // set width and height ratios
    int mapWidthInPixels = upperRightMarkerOffsetXInPixels - lowerLeftMarkerOffsetXInPixels;
    int mapHeightInPixels = lowerLeftMarkerOffsetYInPixels - upperRightMarkerOffsetYInPixels;

    double mapWidthRatio = (mapWidthInPixels) / roomWidthInMeters;
    double mapHeightRatio = (mapHeightInPixels) / roomHeightInMeters;

    map.setRatioWidth(mapWidthRatio);
    map.setRatioHeight(mapHeightRatio);

    // set receiver positions in meters
    map.getReceivers().clear(); // first we remove all present receivers
    for (ReceiverView receiverView : receiverViews) {

      int receiverViewXInPixels =
          ((int) (receiverView.getLocation().getX() / scalingRatioToFitContainer))
              + (ReceiverView.RECEIVER_ITEM_WIDTH / 2);
      int receiverViewYInPixels =
          ((int) (receiverView.getLocation().getY() / scalingRatioToFitContainer))
              + (ReceiverView.RECEIVER_ITEM_HEIGHT / 2);

      double receiverPositionInMetersX =
          calculateReceiverPositionInMetersX(
              lowerLeftMarkerOffsetXInPixels, receiverViewXInPixels, mapWidthRatio);
      double receiverPositionInMetersY =
          calculateReceiverPositionInMetersY(
              lowerLeftMarkerOffsetYInPixels, receiverViewYInPixels, mapHeightRatio);

      receiverView.getReceiver().setxPos(receiverPositionInMetersX);
      receiverView.getReceiver().setyPos(receiverPositionInMetersY);

      map.addReceiver(receiverView.getReceiver());
    }

    // set map title
    String titleFromInput = parent.getRoomTitle();
    map.setTitle(titleFromInput.equals("") ? "Unkown" : titleFromInput);

    // set map xFrom, xTo, yFrom and yTo values
    map.setxFrom(0);
    map.setxTo(map.getWidthInMeters());
    map.setyFrom(0);
    map.setyTo(map.getHeightInMeters());

    Application.getApplication().setRoomMap(map);

    return map;
  }
Exemplo n.º 3
0
 /**
  * Sets the status message. Call is delegated to <code>AddMapDialog</code>.
  *
  * @param message <code>String</code> new status message
  * @see AddMapDialog
  */
 public void setStatus(String message) {
   // delegate call to AddMapDialog instance
   parent.setStatus(message);
 }