Ejemplo n.º 1
0
  // reloads the element on all open panels and adds it to the custom element panel if not already
  // there.
  private void updateElement(Entity element) {

    //		if a new element has been created add it to current diagram
    if (this.originalElement == null) {
      DiagramHandler current = null;
      DrawPanel c = Umlet.getInstance().getGUI().getCurrentDiagram();
      if (c == null) {
        Umlet.getInstance().doNew();
        current = Umlet.getInstance().getGUI().getCurrentDiagram().getHandler();
      } else current = c.getHandler();

      Vector<Entity> ents = current.getDrawPanel().getAllEntities();
      // set location for element
      int x = 10, y = 10;
      for (Entity e : ents) {
        if (e.getY() + e.getHeight() + 10 > y) y = e.getY() + e.getHeight() + 10;
      }

      Rectangle bounds = new Rectangle(x, y, element.getWidth(), element.getHeight());
      this.addElementToDiagram(element, current, true, bounds, element.getState());
    } else { // replace edited element (and ONLY edited element)
      this.originalElement.getHandler().getDrawPanel().remove(this.originalElement);
      this.addElementToDiagram(
          element,
          this.originalElement.getHandler(),
          true,
          this.originalElement.getBounds(),
          this.originalElement.getState());
    }
  }
Ejemplo n.º 2
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;
  }