Example #1
0
  private String getDescr(Fig f) {
    if (f == null) {
      return null;
    }
    String className = f.getClass().getName();
    StringBuffer descr = new StringBuffer(className.substring(className.lastIndexOf(".") + 1));
    //        descr.append(" - paints=").append(f.getPaintCount());
    //        descr.append(" - damages=").append(f.getDamageCount());
    descr.append(
        " - bounds=[" + f.getX() + "," + f.getY() + "," + f.getWidth() + "," + f.getHeight() + "]");
    if (!f.isVisible()) {
      descr.append(" - INVISIBLE");
    }
    if (f.isFilled()) {
      descr.append(" - FILLED");
    }
    descr.append(
        " - fill=["
            + f.getFillColor().getRed()
            + ","
            + f.getFillColor().getGreen()
            + ","
            + f.getFillColor().getBlue()
            + "]");
    if (f.getOwner() != null) {
      descr.append(" - owner=").append(f.getOwner());
    }
    if (f instanceof FigText) {
      descr.append(" \"").append(((FigText) f).getText()).append("\"");
    }

    descr.append(" - lay=").append(toString(f.getLayer()));
    descr.append(" - grp=").append(toString(f.getGroup()));
    return descr.toString();
  }
  /**
   * If the selected Fig is a FigAssociation (an edge) then convert it to a FigNodeAssociation.
   *
   * @param fig the select end Fig
   * @return the fig converted to a FigNode
   */
  private FigNode convertToFigNode(Fig fig) {
    if (fig instanceof FigEdgePort) {
      fig = fig.getGroup();
    }
    if (!(fig instanceof FigAssociation)) {
      return (FigNode) fig;
    }
    final FigAssociation figAssociation = (FigAssociation) fig;
    final int x = figAssociation.getEdgePort().getX();
    final int y = figAssociation.getEdgePort().getY();
    final Object association = fig.getOwner();
    final FigNode originalEdgePort = figAssociation.getEdgePort();

    // Detach any edges (such as comment edges) already attached
    // to the FigAssociation before the FigAssociation is removed.
    // They'll later be re-attached to the new FigNodeAssociation
    final Collection<FigEdge> existingEdges = originalEdgePort.getEdges();
    for (FigEdge edge : existingEdges) {
      originalEdgePort.removeFigEdge(edge);
    }
    figAssociation.removeFromDiagram();

    // Create the new FigNodeAssociation and locate it.
    final MutableGraphModel gm = (MutableGraphModel) editor.getGraphModel();
    gm.addNode(association);
    final LayerPerspective lay = (LayerPerspective) editor.getLayerManager().getActiveLayer();
    final List associationFigs = lay.presentationsFor(association);
    associationFigs.remove(figAssociation);
    final FigNodeAssociation figNode = (FigNodeAssociation) associationFigs.get(0);

    figNode.setLocation(x - figNode.getWidth() / 2, y - figNode.getHeight() / 2);
    editor.add(figNode);
    editor.getSelectionManager().deselectAll();

    // Add the association ends to the graph model
    final Collection<Object> associationEnds = Model.getFacade().getConnections(association);
    for (Object associationEnd : associationEnds) {
      gm.addEdge(associationEnd);
    }
    // Add the edges (such as comment edges) that were on the old
    // FigAssociation to our new FigNodeAssociation and make sure they are
    // positioned correctly.
    for (FigEdge edge : existingEdges) {
      if (edge.getDestFigNode() == originalEdgePort) {
        edge.setDestFigNode(figNode);
        edge.setDestPortFig(figNode);
      }
      if (edge.getSourceFigNode() == originalEdgePort) {
        edge.setSourceFigNode(figNode);
        edge.setSourcePortFig(figNode);
      }
    }
    figNode.updateEdges();

    return figNode;
  }
Example #3
0
 @Override
 public Object getOwner() {
   if (super.getOwner() != null) {
     return super.getOwner();
   }
   Fig group = this;
   while (group != null && !(group instanceof FigEdge)) {
     group = group.getGroup();
   }
   if (group == null) {
     return null;
   } else {
     return group.getOwner();
   }
 }