Beispiel #1
0
  public void renderInJGraph() {
    /** the real renderer */
    ConnectionSet cs = new ConnectionSet();
    Map<Object, AttributeMap> attributes = new Hashtable<Object, AttributeMap>();
    for (DefaultEdge linkEdge : retrieveLinks()) {
      DefaultPort srcPort = (DefaultPort) linkEdge.getSource();
      DefaultPort trgtPort = (DefaultPort) linkEdge.getTarget();
      DefaultGraphCell sourceCell = (DefaultGraphCell) srcPort.getParent();
      DefaultGraphCell targetCell = (DefaultGraphCell) trgtPort.getParent();

      AttributeMap lineStyle = linkEdge.getAttributes();
      AttributeMap sourceNodeCellAttribute = null;
      if (sourceCell != null) sourceNodeCellAttribute = sourceCell.getAttributes();
      AttributeMap targetNodeCellAttribute = null;
      if (targetCell != null) targetNodeCellAttribute = targetCell.getAttributes();

      Object sourceNode = srcPort.getUserObject();
      Object targetNode = trgtPort.getUserObject();
      try {
        if (sourceNode instanceof DefaultMappableTreeNode) {
          if ((targetNode instanceof DefaultMappableTreeNode)) {
            // change target node
            DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) targetNode;
            adjustToNewPosition(treeNode, targetNodeCellAttribute);
          }
          // change source node
          DefaultMutableTreeNode srcNode = (DefaultMutableTreeNode) sourceNode;
          adjustToNewPosition(srcNode, sourceNodeCellAttribute);
        }
        if (sourceNodeCellAttribute != null
            && targetNodeCellAttribute
                != null) { // put in attribute if and only if it is constructed.
          attributes.put(sourceCell, sourceNodeCellAttribute);
          attributes.put(targetCell, targetNodeCellAttribute);
          attributes.put(linkEdge, lineStyle);
          // cs.connect(linkEdge, sourceCell.getChildAt(0), targetCell.getChildAt(0));
          // Log.logInfo(this, "Drew line for : " + mappingComponent.toString());
        }
      } catch (Throwable e) {
        e.printStackTrace();
        // Log.logInfo(this, "Did not draw line for : " + mappingComponent.toString(true));
      }
    } // end of for
    getGraph().getGraphLayoutCache().edit(attributes, cs, null, null);
    getGraph().getGraphLayoutCache().setSelectsAllInsertedCells(false);
  }
Beispiel #2
0
 // Connection logic.
 // The deletion is acceptable if the resulting relationship is valid.
 // selected are the nodes to removed.
 public boolean acceptRemove(GraphCell[] selected) {
   // All roles considered in the relationship.
   List roles = this.getOrderedRoles();
   // Valid deletion.
   boolean ok = true;
   // Check all roles.
   for (int i = 0; i < roles.size(); i++) {
     String roleName = (String) roles.get(i);
     Integer minAllowedTimes = this.getArity(roleName, true);
     Integer maxAllowedTimes = this.getArity(roleName, false);
     // Objects playing roleName in this relationship.
     GraphCell[] roleObjects = this.getObjects(roleName);
     // newUse is roleObjects number minus those objects in selected (which will be removed).
     int currentUse = roleObjects.length;
     for (int j = 0; j < roleObjects.length; j++)
       for (int k = 0; k < selected.length; k++) {
         // Object to be compared with roleObjects.
         Object object = null;
         // Default Edge.
         if (selected[k] instanceof DefaultEdge) {
           DefaultPort targetPort = (DefaultPort) ((DefaultEdge) selected[k]).getTarget();
           object = targetPort.getParent();
           // Vertex
         } else if ((selected[k] instanceof DefaultGraphCell)
             && !(selected[k] instanceof DefaultPort)) {
           object = selected[k];
         }
         // If the object is in the deleted list, there is one less object playing the role.
         if (roleObjects[j].equals(object)) currentUse--;
       }
     // Check the role for the deletion.
     ok =
         ok
             && (minAllowedTimes.intValue() <= currentUse)
             && (currentUse <= maxAllowedTimes.intValue());
   }
   return ok;
 }