Esempio n. 1
0
  /**
   * Returns the first entity under a point of the map, in the specified layer.
   *
   * @param layer the layer
   * @param x x of the point
   * @param y y of the point
   * @return the entity found, or null if there is no entity here
   */
  public MapEntity getEntityAt(Layer layer, int x, int y) {

    MapEntities entities = allEntities[layer.getId()];
    ListIterator<MapEntity> iterator = entities.listIterator(entities.size());
    while (iterator.hasPrevious()) {

      MapEntity entity = iterator.previous();
      if (entity.containsPoint(x, y)) {
        return entity;
      }
    }

    return null;
  }
Esempio n. 2
0
  /**
   * Brings the specified entities to the front, keeping their layer. The order of the specified
   * entities in the map is unchanged.
   *
   * @param entities the entities to move
   */
  public void bringToFront(List<MapEntity> entities) {

    List<MapEntity> sortedEntities = getSortedEntities(entities);

    // bring to front each entity from sortedEntities
    ListIterator<MapEntity> iterator = sortedEntities.listIterator(0);
    while (iterator.hasNext()) {

      MapEntity entity = iterator.next();
      Layer layer = entity.getLayer();
      allEntities[layer.getId()].remove(entity);
      allEntities[layer.getId()].addLast(entity);
    }

    setChanged();
    notifyObservers();
  }
Esempio n. 3
0
  /**
   * Brings the specified entities to the back, keeping their layer. The order of the specified
   * entities in the map is unchanged.
   *
   * @param entities the entities to move
   */
  public void bringToBack(List<MapEntity> entities) {

    List<MapEntity> sortedEntities = getSortedEntities(entities);

    // bring to back each entity from sortedEntities
    ListIterator<MapEntity> iterator = sortedEntities.listIterator(sortedEntities.size());
    while (iterator.hasPrevious()) {

      MapEntity entity = iterator.previous();
      Layer layer = entity.getLayer();
      allEntities[layer.getId()].remove(entity);
      allEntities[layer.getId()].addFirst(entity);
    }

    setChanged();
    notifyObservers();
  }