コード例 #1
0
  /**
   * @param g the graphics object intialized in paint method which is used to draw on the panel
   *     <p>loops from the minimum cell (getSlam2().getMap().getmap.getMinPoint()()) explored of the
   *     environment to the maximum cell (map.getMaxPoint())
   */
  public void gridDraw(Graphics g) {

    x = 0;
    y = 0;

    cellSize = calculateCellSize();

    for (int i = (int) map.getMinPoint().getX(); i <= map.getMaxPoint().getX(); i++) {
      x++;
      y = 0;
      for (int j = (int) map.getMinPoint().getY(); j <= map.getMaxPoint().getY(); j++) {
        y++;
        cellDraw(i, j, g);
      }
    }
    try {
      Thread.sleep(25);
    } catch (InterruptedException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
コード例 #2
0
  /**
   * @param a the width of the panel
   * @param b the height of the panel
   * @param s the slam object to be used
   */
  public EvaulationMapPanel(double a, double b, EvaluationGUI frameUI) {

    setSize((int) a, (int) b);
    percentageZoom = 1;
    // System.out.println(getHeight());

    map = frameUI.getSlam2().getMap();

    frame = frameUI;

    main = frame.getSlam2();

    mapSize =
        new Point(getSlam2().getMap().getGrid()[0].length, getSlam2().getMap().getGrid().length);

    currentCell = new Point(getSlam2().getCurrentIndexX(), getSlam2().getCurrentIndexY());

    totalCells = 0;

    cellsVisited = 0;

    if (map.getMaxPoint() == null) {
      map.setMaxPoint(new Point(currentCell.getX() + 1, currentCell.getY() + 1));
    }

    if (map.getMinPoint() == null) {
      map.setMinPoint(new Point(currentCell.getX() - 1, currentCell.getY() - 1));
    }

    if (map.getMapPoint() == null) {
      map.setMapPoint(
          new Point(this.getWidth() / calculateCellSize(), this.getHeight() / calculateCellSize()));
    }

    setAutoscrolls(true);

    mouseListener mouse = new mouseListener();
    addMouseWheelListener(mouse);
  }
コード例 #3
0
  /** method to draw the map */
  public void paint(Graphics g) {

    super.paintComponent(g);

    this.setBackground(new Color(172, 158, 158));
    moveX =
        (int)
            ((int)
                    (map.getMapPoint().getX()
                        - (map.getMaxPoint().getX() - map.getMinPoint().getX()))
                / 2);
    moveY =
        (int)
            ((int)
                    (map.getMapPoint().getY()
                        - (map.getMaxPoint().getY() - map.getMinPoint().getY()))
                / 2);
    resetSize();
    getCurrentCell();
    refreshMaxMin();
    gridDraw(g);
  }
コード例 #4
0
  public void refreshMaxMin() {
    xCoordinate = (int) currentCell.getX();
    yCoordiante = (int) currentCell.getY();

    if (map.getMapPoint().getY() > map.getMaxPoint().getY() - map.getMinPoint().getY()
        && map.getMapPoint().getX() > map.getMaxPoint().getX() - map.getMinPoint().getX()) {

      if (yCoordiante - 1 < map.getMinPoint().getY()) {
        map.getMinPoint().setY(yCoordiante - 1);
      }
      if (xCoordinate - 1 < map.getMinPoint().getX()) {
        map.getMinPoint().setX(xCoordinate - 1);
      }

      if (yCoordiante + 1 > map.getMaxPoint().getY()) {

        map.getMaxPoint().setY(yCoordiante + 1);

        // System.out.println("doing it");

      }
      if (xCoordinate + 1 > map.getMaxPoint().getX()) {

        map.getMaxPoint().setX(xCoordinate + 1);
      }

    } else {

      if (map.getMapPoint().getX() < map.getGrid()[0].length) {

        setPreferredSize(
            new Dimension((int) (20 * calculateCellSize()) + this.getWidth(), this.getHeight()));

        this.repaint();

        map.getMapPoint().setX(map.getMapPoint().getX() + 20);

        frame.panelSize.setX(this.getWidth() + (int) (20 * calculateCellSize()));
      }

      if (map.getMapPoint().getY() < map.getGrid().length) {

        frame.panelSize.setY(this.getHeight() + (int) (20 * calculateCellSize()));
        setPreferredSize(
            new Dimension(this.getWidth(), this.getHeight() + (int) (20 * calculateCellSize())));

        map.getMapPoint().setY(map.getMapPoint().getY() + 10);
        this.repaint();
      }
    }
  }