コード例 #1
0
  /** Returns a FigureEnumeration of connectionfigures attached to this figure */
  public FigureEnumeration getConnectionFigures(Figure inFigure) {
    // If no figure or figure is non connectable, just return null
    if (inFigure == null || !inFigure.canConnect()) {
      return null;
    }

    // if (inFigure instanceof ConnectionFigure)
    //  return null;

    List result = CollectionsFactory.current().createList(5);
    FigureEnumeration figures = drawing().figures();

    // Find all connection figures
    while (figures.hasNextFigure()) {
      Figure f = figures.nextFigure();

      if ((f instanceof ConnectionFigure) && !(isFigureSelected(f))) {
        ConnectionFigure cf = (ConnectionFigure) f;

        if (cf.startFigure().includes(inFigure) || cf.endFigure().includes(inFigure)) {
          result.add(f);
        }
      }
    }

    return new FigureEnumerator(result);
  }
コード例 #2
0
  /**
   * Inserts a FigureEnumeration of figures and translates them by the given offset. This function
   * is used to insert figures from clipboards (cut/copy)
   *
   * @return enumeration which has been added to the drawing. The figures in the enumeration can
   *     have changed during adding them (e.g. they could have been decorated).
   */
  public FigureEnumeration insertFigures(FigureEnumeration fe, int dx, int dy, boolean bCheck) {
    if (fe == null) {
      return FigureEnumerator.getEmptyEnumeration();
    }

    List vCF = CollectionsFactory.current().createList(10);
    InsertIntoDrawingVisitor visitor = new InsertIntoDrawingVisitor(drawing());

    while (fe.hasNextFigure()) {
      Figure figure = fe.nextFigure();
      if (figure instanceof ConnectionFigure) {
        vCF.add(figure);
      } else if (figure != null) {
        figure.moveBy(dx, dy);
        figure.visit(visitor);
      }
    }

    FigureEnumeration ecf = new FigureEnumerator(vCF);

    while (ecf.hasNextFigure()) {
      ConnectionFigure cf = (ConnectionFigure) ecf.nextFigure();
      Figure sf = cf.startFigure();
      Figure ef = cf.endFigure();

      if (figureExists(sf, drawing().figures())
          && figureExists(ef, drawing().figures())
          && (!bCheck || cf.canConnect(sf, ef))) {

        if (bCheck) {
          Point sp = sf.center();
          Point ep = ef.center();
          Connector fStartConnector = cf.startFigure().connectorAt(ep.x, ep.y);
          Connector fEndConnector = cf.endFigure().connectorAt(sp.x, sp.y);

          if (fEndConnector != null && fStartConnector != null) {
            cf.connectStart(fStartConnector);
            cf.connectEnd(fEndConnector);
            cf.updateConnection();
          }
        }

        cf.visit(visitor);
      }
    }

    addToSelectionAll(visitor.getInsertedFigures());
    return visitor.getInsertedFigures();
  }