示例#1
0
  /**
   * Creates a <code>ReceiverView</code> object from <code>Receiver</code> object and adds it to the
   * <code>MapPreviewPanel</code>.
   *
   * @param receiver <code>Receiver</code> object
   */
  public void addReceiverViewToMap(Receiver receiver) {

    ReceiverView receiverView = new ReceiverView(receiver, this);
    receiverViews.add(receiverView);
    this.add(receiverView);
    receiverView.setLocation((int) receiver.getXPos(), (int) receiver.getYPos());
    componentMover.registerComponent(receiverView);
    repaint();
  }
示例#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;
  }
示例#3
0
  /**
   * Rotates <code>ReceiverView</code> in focus.
   *
   * @param rotateAmount <code>double</code> rotate amount
   */
  public void rotateReceiverViewInFocus(double rotateAmount) {

    if (receiverViewInFocus == null) {
      return;
    } else {
      receiverViewInFocus.rotate(rotateAmount);
    }
  }
示例#4
0
  /**
   * Initializes graphical user interface. Layout of this panel is set to <code>null</code> (no
   * <code>LayoutManager</code>) so that <code>ReceiverView</code> items can be positioned
   * absolutely.
   *
   * @see ReceiverView
   * @see LayoutManager
   */
  private void initializeGui() {

    logger = Utilities.initializeLogger(this.getClass().getName());
    setSize(new Dimension(PANEL_WIDTH, PANEL_HEIGHT));
    setPreferredSize(new Dimension(PANEL_WIDTH, PANEL_HEIGHT));
    setBackground(new Color(GRAY_COLOUR, GRAY_COLOUR, GRAY_COLOUR));
    setLayout(null); // in order to position ReceiverViews absolutely
    refreshPreviewImage();
    // register all receiver views to the ComponentMover
    componentMover = new ComponentMover();
    // add zero coordinate marker views
    addCoordinateZeroMarkerViewsToMap();

    for (Receiver receiver : map.getReceivers()) {

      ReceiverView receiverView = new ReceiverView(receiver, this);
      receiverViews.add(receiverView);
      this.add(receiverView);
      // TODO: location should be calculated with offsets for scaling
      // the image and pixel/meter scaling

      double receiverPositionInMetersX = receiver.getXPos();
      double receiverPositionInMetersY = receiver.getYPos();
      double mapRatioWidth = map.getRatioWidth();
      double mapRatioHeight = map.getRatioHeight();
      int lowerLeftMarkerOffsetXInPixels = map.getLowerLeftMarkerOffsetXInPixels();
      int lowerLeftMarkerOffsetYInPixels = map.getLowerLeftMarkerOffsetYInPixels();

      int receiverPositionInPixelsX =
          calculateReceiverPositionInPixelsX(
              receiverPositionInMetersX, lowerLeftMarkerOffsetXInPixels, mapRatioWidth);
      int receiverPositionInPixelsY =
          calculateReceiverPositionInPixelsY(
              receiverPositionInMetersY, lowerLeftMarkerOffsetYInPixels, mapRatioHeight);

      receiverView.setLocation(receiverPositionInPixelsX, receiverPositionInPixelsY);
      componentMover.registerComponent(receiverView);
    }
  }
示例#5
0
  /**
   * Removes the <code>ReceiverView</code> object from <code>RoomMap</code>.
   *
   * @param receiver <code>Receiver</code> object
   */
  public void removeReceiverViewFromMap(Receiver receiver) {

    for (ReceiverView receiverView : receiverViews) {
      if (receiverView.getReceiver().getID() == receiver.getID()) {

        // remove receiver from map and receiverViews list
        this.remove(receiverView);
        receiverViews.remove(receiverView);
        componentMover.deregisterComponent(receiverView);
        repaint();

        // set receivers coordinates to 0,0
        for (Receiver receiverItem : map.getReceivers()) {
          if (receiverItem.getID() == receiver.getID()) {
            receiverItem.setOnMap(false);
            receiverItem.setxPos(0.0);
            receiverItem.setyPos(0.0);
          }
        }
        return;
      }
    }
  }
示例#6
0
  /**
   * Sets one of the <code>ReceiverView</code>s in focus. <code>ReceiverView</code> in focus is
   * denoted by black border around itself (<code>ReceiverView</code>s that are not in focus don't
   * have this border). When focused, <code>ReceiverView</code>'s <code>angle</code> property can be
   * changed through <code>ParametersPanel</code>.
   *
   * @param receiverViewInFocus <code>ReceiverView</code> object in focus
   * @see ReceiverView
   * @see ParametersPanel
   */
  public void focusReceiverView(ReceiverView receiverViewInFocus) {

    this.receiverViewInFocus = receiverViewInFocus;

    for (ReceiverView receiverView : receiverViews) {
      // remove border from all receiverViews
      receiverView.setBorder(BorderFactory.createLineBorder(Color.black, 0));
      receiverView.repaint();
      if (receiverView.equals(receiverViewInFocus)) {
        receiverView.setBorder(BorderFactory.createLineBorder(Color.black, 2));
        receiverView.repaint();
      }
    }
  }
示例#7
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;
  }