예제 #1
0
  /** @see IFigure#setConstraint(IFigure, Object) */
  public void setConstraint(IFigure child, Object constraint) {
    if (child.getParent() != this)
      throw new IllegalArgumentException("Figure must be a child"); // $NON-NLS-1$

    if (layoutManager != null) layoutManager.setConstraint(child, constraint);
    revalidate();
  }
예제 #2
0
 /**
  * Removes the given child Figure from this Figure's hierarchy and revalidates this Figure. The
  * child Figure's {@link #removeNotify()} method is also called.
  *
  * @param figure The Figure to remove
  */
 public void remove(IFigure figure) {
   if ((figure.getParent() != this))
     throw new IllegalArgumentException("Figure is not a child"); // $NON-NLS-1$
   if (getFlag(FLAG_REALIZED)) figure.removeNotify();
   if (layoutManager != null) layoutManager.remove(figure);
   // The updates in the UpdateManager *have* to be
   // done asynchronously, else will result in
   // incorrect dirty region corrections.
   figure.erase();
   figure.setParent(null);
   children.remove(figure);
   revalidate();
 }
예제 #3
0
  /** @see IFigure#add(IFigure, Object, int) */
  public void add(IFigure figure, Object constraint, int index) {
    if (children == Collections.EMPTY_LIST) children = new ArrayList(2);
    if (index < -1 || index > children.size())
      throw new IndexOutOfBoundsException("Index does not exist"); // $NON-NLS-1$

    // Check for Cycle in hierarchy
    for (IFigure f = this; f != null; f = f.getParent())
      if (figure == f)
        throw new IllegalArgumentException("Figure being added introduces cycle"); // $NON-NLS-1$

    // Detach the child from previous parent
    if (figure.getParent() != null) figure.getParent().remove(figure);

    if (index == -1) children.add(figure);
    else children.add(index, figure);
    figure.setParent(this);

    if (layoutManager != null) layoutManager.setConstraint(figure, constraint);

    revalidate();

    if (getFlag(FLAG_REALIZED)) figure.addNotify();
    figure.repaint();
  }