Exemplo n.º 1
0
  @Override
  public boolean contains(Point p) {
    Rectangle bounds = this.getVisibleRect();
    if (!bounds.contains(p)) return false;

    Vector<Entity> entities = this.handler.getDrawPanel().getNotInGroupEntitiesOnPanel();
    for (Entity other : entities) {
      if (other instanceof Relation) { // a relation is always on top
        // move point to coordinate system of other entity
        Point other_p =
            new Point(p.x + this.getX() - other.getX(), p.y + this.getY() - other.getY());
        if (other.contains(other_p)) return false;
      }

      // If the this visibleRect is equal to the other VisibleRect, true will be returned. Otherwise
      // we need to check further
      else if (!this.getVisibleRect().equals(other.getVisibleRect())) {
        Rectangle other_bounds = other.getVisibleRect();
        // move bounds to coordinate system of this component
        other_bounds.x += other.getX() - this.getX();
        other_bounds.y += other.getY() - this.getY();
        if (other_bounds.contains(
            p)) { // the selected element has to be in front except if the other element is totally
          // contained!
          if (bounds.contains(other_bounds)
              || (other.isSelected() && !other_bounds.contains(bounds))) return false;
        }
      }
    }
    return true;
  }