/**
   * 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();
  }
 private void moveSelection(int dx, int dy) {
   FigureEnumeration figures = selection();
   while (figures.hasNextFigure()) {
     figures.nextFigure().moveBy(dx, dy);
   }
   checkDamage();
 }
  /** 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);
  }
Exemplo n.º 4
0
  private void setupAttributes() {
    Color frameColor = (Color) AttributeFigure.getDefaultAttribute("FrameColor");
    Color fillColor = (Color) AttributeFigure.getDefaultAttribute("FillColor");
    Color textColor = (Color) AttributeFigure.getDefaultAttribute("TextColor");
    Integer arrowMode = (Integer) AttributeFigure.getDefaultAttribute("ArrowMode");
    String fontName = (String) AttributeFigure.getDefaultAttribute("FontName");

    FigureEnumeration k = view().selectionElements();
    while (k.hasMoreElements()) {
      Figure f = k.nextFigure();
      frameColor = (Color) f.getAttribute("FrameColor");
      fillColor = (Color) f.getAttribute("FillColor");
      textColor = (Color) f.getAttribute("TextColor");
      arrowMode = (Integer) f.getAttribute("ArrowMode");
      fontName = (String) f.getAttribute("FontName");
    }

    fFrameColor.setSelectedIndex(ColorMap.colorIndex(frameColor));
    fFillColor.setSelectedIndex(ColorMap.colorIndex(fillColor));
    // fTextColor.select(ColorMap.colorIndex(textColor));
    if (arrowMode != null) {
      fArrowChoice.setSelectedIndex(arrowMode.intValue());
    }
    if (fontName != null) {
      fFontChoice.setSelectedItem(fontName);
    }
  }
Exemplo n.º 5
0
 private void setupAttributes() {
   Color frameColor =
       (Color) AttributeFigure.getDefaultAttribute(FigureAttributeConstant.FRAME_COLOR);
   Color fillColor =
       (Color) AttributeFigure.getDefaultAttribute(FigureAttributeConstant.FILL_COLOR);
   Integer arrowMode =
       (Integer) AttributeFigure.getDefaultAttribute(FigureAttributeConstant.ARROW_MODE);
   String fontName =
       (String) AttributeFigure.getDefaultAttribute(FigureAttributeConstant.FONT_NAME);
   FigureEnumeration fe = view().selection();
   while (fe.hasNextFigure()) {
     Figure f = fe.nextFigure();
     frameColor = (Color) f.getAttribute(FigureAttributeConstant.FRAME_COLOR);
     fillColor = (Color) f.getAttribute(FigureAttributeConstant.FILL_COLOR);
     arrowMode = (Integer) f.getAttribute(FigureAttributeConstant.ARROW_MODE);
     fontName = (String) f.getAttribute(FigureAttributeConstant.FONT_NAME);
   }
   fFrameColor.setSelectedIndex(ColorMap.colorIndex(frameColor));
   fFillColor.setSelectedIndex(ColorMap.colorIndex(fillColor));
   if (arrowMode != null) {
     fArrowChoice.setSelectedIndex(arrowMode.intValue());
   }
   if (fontName != null) {
     fFontChoice.setSelectedItem(fontName);
   }
 }
 /**
  * Return the size of the area occupied by the contained figures inside the drawing. This method
  * is called by checkMinimumSize().
  */
 protected Dimension getDrawingSize() {
   FigureEnumeration fe = drawing().figures();
   Dimension d = new Dimension(0, 0);
   while (fe.hasNextFigure()) {
     Rectangle r = fe.nextFigure().displayBox();
     d.width = Math.max(d.width, r.x + r.width);
     d.height = Math.max(d.height, r.y + r.height);
   }
   return d;
 }
  /** Check existance of figure in the drawing */
  public boolean figureExists(Figure inf, FigureEnumeration fe) {
    while (fe.hasNextFigure()) {
      Figure figure = fe.nextFigure();

      if (figure.includes(inf)) {
        return true;
      }
    }

    return false;
  }
  /**
   * Gets the currently selected figures in Z order.
   *
   * @see #selection
   * @return a FigureEnumeration with the selected figures. The enumeration represents a snapshot of
   *     the current selection.
   */
  public FigureEnumeration selectionZOrdered() {
    List result = CollectionsFactory.current().createList(selectionCount());
    FigureEnumeration figures = drawing().figures();

    while (figures.hasNextFigure()) {
      Figure f = figures.nextFigure();
      if (isFigureSelected(f)) {
        result.add(f);
      }
    }
    return new ReverseFigureEnumerator(result);
  }
 /** Gets an enumeration of the currently active handles. */
 protected HandleEnumeration selectionHandles() {
   if (fSelectionHandles == null) {
     fSelectionHandles = CollectionsFactory.current().createList();
     FigureEnumeration fe = selection();
     while (fe.hasNextFigure()) {
       Figure figure = fe.nextFigure();
       HandleEnumeration kk = figure.handles();
       while (kk.hasNextHandle()) {
         fSelectionHandles.add(kk.nextHandle());
       }
     }
   }
   return new HandleEnumerator(fSelectionHandles);
 }
Exemplo n.º 10
0
  /** Clears the current selection. */
  public void clearSelection() {
    // there is nothing selected - bug fix ID 628818
    if (selectionCount() == 0) {
      // avoid unnecessary selection changed event when nothing has to be cleared
      return;
    }

    FigureEnumeration fe = selection();
    while (fe.hasNextFigure()) {
      fe.nextFigure().invalidate();
    }
    fSelection = CollectionsFactory.current().createList();
    fSelectionHandles = null;
    fireSelectionChanged();
  }
Exemplo n.º 11
0
 /** Adds a FigureEnumeration to the current selection. */
 public void addToSelectionAll(FigureEnumeration fe) {
   while (fe.hasNextFigure()) {
     addToSelection(fe.nextFigure());
   }
 }
Exemplo n.º 12
0
 /** Adds a Collection of figures to the drawing. */
 public void addAll(Collection figures) {
   FigureEnumeration fe = new FigureEnumerator(figures);
   while (fe.hasNextFigure()) {
     add(fe.nextFigure());
   }
 }