Esempio n. 1
0
  /**
   * Instantiates a new <code>MapPreviewPanel</code>. This constructor is used when we open <code>
   * AddMapDialog</code> in <code>AddMapDialogMode.EDIT</code> mode.
   *
   * @param map <code>RoomMap</code> object
   * @param parent <code>AddMapDialog</code> parent object
   * @see AddMapDialog
   * @see gui.enumeration.AddMapDialogMode
   */
  public MapPreviewPanel(RoomMap map, AddMapDialog parent) {

    receiverViews = new ArrayList<ReceiverView>();
    scalingRatioToFitContainer = 1.0;
    this.map = map;
    // TODO: added code
    Application.getApplication().setRoomMap(this.map);
    this.originalBackgroundImage = Utilities.deepCopy((BufferedImage) map.getImage());
    this.backgroundImage = Utilities.deepCopy((BufferedImage) map.getImage());
    this.parent = parent;
    initializeGui();
  }
Esempio n. 2
0
  /**
   * Gets the validation error messages.
   *
   * @return <code>List</code> of validation error messages
   */
  public List<String> getValidationErrorMessages() {

    ArrayList<String> validationErrors = new ArrayList<>();
    // check if map has an image
    if (map.getImage() == null) {
      validationErrors.add(NO_IMAGE_ERROR_MESSAGE);
    }
    // check if map markers are in valid positions

    // we take the lower left corner of the lowerLeftMarker as the marker position point
    int lowerLeftMarkerPositionX =
        (int) (lowerLeftMarker.getLocation().getX() / scalingRatioToFitContainer);
    int lowerLeftMarkerPositionY =
        (int) (lowerLeftMarker.getLocation().getY() / scalingRatioToFitContainer)
            + (CoordinateZeroMarkerView.ZERO_COORDINATE_MARKER_VIEW_HEIGHT);

    // we take the upper right corner of the upperRightMarker as the marker position point
    int upperRightMarkerPositionX =
        (int) (upperRightMarker.getLocation().getX() / scalingRatioToFitContainer)
            + (CoordinateZeroMarkerView.ZERO_COORDINATE_MARKER_VIEW_WIDTH);
    int upperRightMarkerPositionY =
        (int) (upperRightMarker.getLocation().getY() / scalingRatioToFitContainer);

    if ((lowerLeftMarkerPositionX > upperRightMarkerPositionX)
        || (lowerLeftMarkerPositionY < upperRightMarkerPositionY)) {
      validationErrors.add(INVALID_POSITION_OF_MARKERS_ERROR_MESSAGE);
    }

    // check if receivers are outside the map
    for (ReceiverView receiverView : receiverViews) {
      // we take the middle point of receiverView as the receiver position point
      int receiverViewLocationX =
          (int) (receiverView.getLocation().getX() / scalingRatioToFitContainer)
              + (ReceiverView.RECEIVER_ITEM_WIDTH / 2);
      int receiverViewLocationY =
          (int) (receiverView.getLocation().getY() / scalingRatioToFitContainer)
              + (ReceiverView.RECEIVER_ITEM_HEIGHT / 2);

      if ((receiverViewLocationX < lowerLeftMarkerPositionX)
          || (receiverViewLocationX > upperRightMarkerPositionX)
          || (receiverViewLocationY > lowerLeftMarkerPositionY)
          || (receiverViewLocationY < upperRightMarkerPositionY)) {
        validationErrors.add(
            RECEIVERS_OUT_OF_MAP_ERROR_MESSAGE
                + " Please check receiver "
                + receiverView.getReceiver().getID());
        break;
      }
    }

    return validationErrors;
  }