Example #1
0
  /**
   * Constructor.
   *
   * @param edge the Edge to layout
   */
  public ClassdiagramEdge(FigEdge edge) {
    currentEdge = edge;
    underlyingFig = new FigPoly();
    underlyingFig.setLineColor(edge.getFig().getLineColor());

    destFigNode = edge.getDestFigNode();
    sourceFigNode = edge.getSourceFigNode();
  }
  /**
   * Find the Figs in the given layer that should be the source and destination and attach these to
   * either end of the FigEdge
   *
   * @param layer the layer to look for the FigNodes
   * @param newEdge The edge to attach
   */
  protected final void setPorts(Layer layer, FigEdge newEdge) {
    Object modelElement = newEdge.getOwner();
    if (newEdge.getSourcePortFig() == null) {
      Object source;
      if (modelElement instanceof CommentEdge) {
        source = ((CommentEdge) modelElement).getSource();
      } else {
        source = Model.getUmlHelper().getSource(modelElement);
      }
      FigNode sourceNode = getNodePresentationFor(layer, source);
      assert (sourceNode != null) : "No FigNode found for " + source;
      setSourcePort(newEdge, sourceNode);
    }

    if (newEdge.getDestPortFig() == null) {
      Object dest;
      if (modelElement instanceof CommentEdge) {
        dest = ((CommentEdge) modelElement).getDestination();
      } else {
        dest = Model.getUmlHelper().getDestination(newEdge.getOwner());
      }
      setDestPort(newEdge, getNodePresentationFor(layer, dest));
    }

    if (newEdge.getSourcePortFig() == null || newEdge.getDestPortFig() == null) {
      throw new IllegalStateException(
          "Edge of type "
              + newEdge.getClass().getName()
              + " created with no source or destination port");
    }
  }
  /**
   * 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;
  }
  protected void addEdge(Layer lay, FigEdge newEdge, Object edge) {
    if (newEdge == null) {
      throw new IllegalArgumentException(
          "Don't know how to create FigEdge for model type " + edge.getClass().getName());
    }

    setPorts(lay, newEdge);

    assert newEdge != null : "There has been no FigEdge created";

    //        newEdge.setDiElement(
    //            GraphChangeAdapter.getInstance().createElement(gm, edge));

    assert newEdge != null : "There has been no FigEdge created";
    assert (newEdge.getDestFigNode() != null) : "The FigEdge has no dest node";
    assert (newEdge.getDestPortFig() != null) : "The FigEdge has no dest port";
    assert (newEdge.getSourceFigNode() != null) : "The FigEdge has no source node";
    assert (newEdge.getSourcePortFig() != null) : "The FigEdge has no source port";

    lay.add(newEdge);
  }
 /**
  * Handle mouseDragged events.
  *
  * @param me The mouse event to process.
  * @see org.tigris.gef.base.ModeImpl#mouseDragged(java.awt.event.MouseEvent)
  */
 public void mouseDragged(MouseEvent me) {
   if (dragFig != null) {
     me = editor.translateMouseEvent(me);
     Point newPoint = me.getPoint();
     // Subtract the the offset of the click, to take account of user
     // having not initially clicked in the centre.
     newPoint.translate(-deltax, -deltay);
     PathItemPlacementStrategy pips = figEdge.getPathItemPlacementStrategy(dragFig);
     pips.setPoint(newPoint);
     newPoint = pips.getPoint();
     int dx = newPoint.x - dragBasePoint.x;
     int dy = newPoint.y - dragBasePoint.y;
     dragBasePoint.setLocation(newPoint);
     dragFig.translate(dx, dy);
     me.consume();
     editor.damaged(dragFig);
   }
 }
Example #6
0
 private void buildTree(Fig f, DefaultMutableTreeNode tn) {
   if (f instanceof FigGroup) {
     FigGroup fg = (FigGroup) f;
     for (int i = 0; i < fg.getFigCount(); ++i) {
       addNode(tn, fg.getFigAt(i));
     }
   } else if (f instanceof FigEdge) {
     FigEdge fe = (FigEdge) f;
     Fig lineFig = fe.getFig();
     addNode(tn, lineFig);
     addNode(tn, fe.getSourceFigNode());
     addNode(tn, fe.getSourcePortFig());
     addNode(tn, fe.getDestFigNode());
     addNode(tn, fe.getDestPortFig());
     for (Fig pathFig : (Vector<Fig>) fe.getPathItemFigs()) {
       addNode(tn, pathFig);
     }
   }
 }
  /**
   * Create an edge of the given type and connect it to the given nodes.
   *
   * @param graphModel the graph model in which to create the connection element
   * @param edgeType the UML object type of the connection
   * @param sourceFig the FigNode for the source element
   * @param destFig the FigNode for the destination element
   * @return The FigEdge representing the newly created model element
   */
  @Override
  protected FigEdge buildConnection(
      MutableGraphModel graphModel, Object edgeType, Fig sourceFig, Fig destFig) {
    try {
      Object associationEnd =
          Model.getUmlFactory()
              .buildConnection(
                  edgeType, sourceFig.getOwner(), null, destFig.getOwner(), null, null, null);

      final FigNode sourceFigNode = convertToFigNode(sourceFig);
      final FigNode destFigNode = convertToFigNode(destFig);

      graphModel.addEdge(associationEnd);

      setNewEdge(associationEnd);

      // Calling connect() will add the edge to the GraphModel and
      // any LayerPersectives on that GraphModel will get a
      // edgeAdded event and will add an appropriate FigEdge
      // (determined by the GraphEdgeRenderer).

      if (getNewEdge() != null) {
        sourceFigNode.damage();
        destFigNode.damage();
        Layer lay = editor.getLayerManager().getActiveLayer();
        FigEdge fe = (FigEdge) lay.presentationFor(getNewEdge());
        _newItem.setLineColor(Color.black);
        fe.setFig(_newItem);
        fe.setSourcePortFig(sourceFigNode);
        fe.setSourceFigNode(sourceFigNode);
        fe.setDestPortFig(destFigNode);
        fe.setDestFigNode(destFigNode);
        return fe;
      } else {
        return null;
      }
    } catch (IllegalModelElementConnectionException e) {
      // We have already confirmed the connection is valid
      return null;
    }
  }
 private void setDestPort(FigEdge edge, FigNode dest) {
   edge.setDestPortFig(dest);
   edge.setDestFigNode(dest);
 }
 private void setSourcePort(FigEdge edge, FigNode source) {
   edge.setSourcePortFig(source);
   edge.setSourceFigNode(source);
 }
Example #10
0
  /**
   * Sets the target of the style tab.
   *
   * @param t is the new target
   */
  public void setTarget(Object t) {
    if (target != null) {
      target.removePropertyChangeListener(this);
      if (target instanceof FigEdge) {
        // In this case, the bounds are determined by the FigEdge
        ((FigEdge) target).getFig().removePropertyChangeListener(this);
      }
      if (target instanceof FigAssociationClass) {
        // In this case, the bounds (of the box) are determined
        // by the FigClassAssociationClass
        FigClassAssociationClass ac = ((FigAssociationClass) target).getAssociationClass();
        // A newly created AssociationClass may not have all its parts
        // created by the time we are called
        if (ac != null) {
          ac.removePropertyChangeListener(this);
        }
      }
    }

    // TODO: Defer most of this work if the panel isn't visible - tfm

    // the responsibility of determining if the given target is a
    // correct one for this tab has been moved from the
    // DetailsPane to the member tabs of the details pane. Reason for
    // this is that the details pane is configurable and cannot
    // know what's the correct target for some tab.
    if (!(t instanceof Fig)) {
      if (Model.getFacade().isAModelElement(t)) {
        ArgoDiagram diagram = DiagramUtils.getActiveDiagram();
        if (diagram != null) {
          t = diagram.presentationFor(t);
        }
        if (!(t instanceof Fig)) {
          Project p = ProjectManager.getManager().getCurrentProject();
          Collection col = p.findFigsForMember(t);
          if (col == null || col.isEmpty()) {
            return;
          }
          t = col.iterator().next();
        }
        if (!(t instanceof Fig)) {
          return;
        }
      } else {
        return;
      }
    }

    target = (Fig) t;
    if (target != null) {
      target.addPropertyChangeListener(this);
      // TODO: This shouldn't know about the specific type of Fig that
      // is being displayed.  That couples it too strongly to things it
      // shouldn't need to know about - tfm - 20070924
      if (target instanceof FigEdge) {
        // In this case, the bounds are determined by the FigEdge
        ((FigEdge) target).getFig().addPropertyChangeListener(this);
      }
      if (target instanceof FigAssociationClass) {
        // In this case, the bounds (of the box) are determined
        // by the FigClassAssociationClass
        FigClassAssociationClass ac = ((FigAssociationClass) target).getAssociationClass();
        // A newly created AssociationClass may not have all its parts
        // created by the time we are called
        if (ac != null) {
          ac.addPropertyChangeListener(this);
        }
      }
    }
    if (lastPanel != null) {
      remove(lastPanel);
      if (lastPanel instanceof TargetListener) {
        removeTargetListener((TargetListener) lastPanel);
      }
    }
    if (t == null) {
      add(blankPanel, BorderLayout.NORTH);
      shouldBeEnabled = false;
      lastPanel = blankPanel;
      return;
    }
    shouldBeEnabled = true;
    stylePanel = null;
    Class targetClass = t.getClass();

    stylePanel = findPanelFor(targetClass);

    if (stylePanel != null) {
      removeTargetListener(stylePanel);
      addTargetListener(stylePanel);
      stylePanel.setTarget(target);
      add(stylePanel, BorderLayout.NORTH);
      shouldBeEnabled = true;
      lastPanel = stylePanel;
    } else {
      add(blankPanel, BorderLayout.NORTH);
      shouldBeEnabled = false;
      lastPanel = blankPanel;
    }
    validate();
    repaint();
  }