Package com.mxgraph.model

Examples of com.mxgraph.model.mxCell


    // Creates a single shapes palette
    EditorPalette shapesPalette = insertPalette("Schema");
    graphOutline.setVisible(false);

    mxCell tableTemplate = new mxCell("New Table", new mxGeometry(0, 0,
        200, 280), null);
    tableTemplate.getGeometry().setAlternateBounds(
        new mxRectangle(0, 0, 140, 25));
    tableTemplate.setVertex(true);

    shapesPalette
        .addTemplate(
            "Table",
            new ImageIcon(
                GraphEditor.class
                    .getResource("/com/mxgraph/examples/swing/images/rectangle.png")),
            tableTemplate);

    getGraphComponent().getGraph().setCellsResizable(false);
    getGraphComponent().setConnectable(false);
    getGraphComponent().getGraphHandler().setCloneEnabled(false);
    getGraphComponent().getGraphHandler().setImagePreview(false);

    // Prefers default JComponent event-handling before mxCellHandler handling
    //getGraphComponent().getGraphHandler().setKeepOnTop(false);

    mxGraph graph = getGraphComponent().getGraph();
    Object parent = graph.getDefaultParent();
    graph.getModel().beginUpdate();
    try
    {
      mxCell v1 = (mxCell) graph.insertVertex(parent, null, "Customers",
          20, 20, 200, 280);
      v1.getGeometry().setAlternateBounds(new mxRectangle(0, 0, 140, 25));
      mxCell v2 = (mxCell) graph.insertVertex(parent, null, "Orders",
          280, 20, 200, 280);
      v2.getGeometry().setAlternateBounds(new mxRectangle(0, 0, 140, 25));
    }
    finally
    {
      graph.getModel().endUpdate();
    }
View Full Code Here


    }
  }
 
  protected boolean isBoundaryEvent(Object obj) {
    if (obj instanceof mxCell) {
      mxCell cell = (mxCell) obj;
      return cell.getId().startsWith("boundary-event-");
    }
    return false;
  }
View Full Code Here

  protected void handleBoundaryEvents() {
    for (BoundaryEvent boundaryEvent : boundaryEvents) {
      mxGeometry geometry = new mxGeometry(0.8, 1.0, eventSize, eventSize);
      geometry.setOffset(new mxPoint(-(eventSize/2), -(eventSize/2)));
      geometry.setRelative(true);
      mxCell boundaryPort = new mxCell(null, geometry, "shape=ellipse;perimter=ellipsePerimeter");
      boundaryPort.setId("boundary-event-" + boundaryEvent.getId());
      boundaryPort.setVertex(true);

      Object portParent = null;
      if (boundaryEvent.getAttachedToRefId() != null) {
        portParent = generatedVertices.get(boundaryEvent.getAttachedToRefId());
      } else if (boundaryEvent.getAttachedToRef() != null) {
View Full Code Here

          "=");
      styleMap.put(mxConstants.STYLE_FILLCOLOR, subShape2.getColor());
      style = mxVdxUtils.getStyleString(styleMap, "=");

      //Insert a new vertex in the graph
      mxCell v1 = (mxCell) graph.insertVertex(parent, null, t, o.getX(),
          o.getY(), d.getX(), d.getY(), style);

      return v1;
    }
    else
View Full Code Here

    }
    //Defines style
    String style = this.getStyleFromShape(parentHeight);

    //Insert a new vertex in the graph
    mxCell v1 = (mxCell) graph.insertVertex(parent, null, textLabel,
        cordenates.getX(), cordenates.getY(), dimentions.getX(),
        dimentions.getY(), style);
    return v1;
  }
View Full Code Here

      shapeIDList.add(new PageShapeIDKey(pageNumber, id));
      //If is a vertex shape
      if (shape.isVertexShape())
      {

        mxCell v1 = null;
        if (shape.isComplexShape())
        {
          v1 = shape.addComplexShapeToGraph(graph, parent,
              parentHeight);
        }
View Full Code Here

   * @return The new edge. null if not edge is added.
   */
  private static Object addConectedEdge(mxGraph graph, Element connect,
      Element sigConnect)
  {
    mxCell edge = null;

    //Retrieve edge Shape and Parent
    String shapeConnect = connect.getAttribute(mxVdxConstants.FROM_SHEET);

    mxVdxShape edgeShape = edgeShapeMap.get(new PageShapeIDKey(pageNumber,
        shapeConnect));
    edgeShapeMap.remove(new PageShapeIDKey(pageNumber, shapeConnect));

    if (edgeShape != null)
    {
      Object parent = parentsMap.get(new PageShapeIDKey(pageNumber,
          edgeShape.getId()));

      //Get Parent Height
      double parentHeight = pageHeight;

      mxCell parentCell = (mxCell) parent;

      if (parentCell != null)
      {
        mxGeometry parentGeometry = parentCell.getGeometry();

        if (parentGeometry != null)
        {
          parentHeight = parentGeometry.getHeight();
          parentHeight += pageHeight - actualPageHeight;
        }
      }

      //Get beginXY and endXY coordinates.
      mxPoint beginXY = edgeShape.getBeginXY(parentHeight);
      beginXY = calculateAbsolutePoint((mxCell) parent, graph, beginXY);

      mxPoint endXY = edgeShape.getEndXY(parentHeight);
      endXY = calculateAbsolutePoint((mxCell) parent, graph, endXY);

      //Declare variables.
      mxCell source = null;
      mxCell target = null;
      mxPoint fromConstraint = null;
      mxPoint toConstraint = null;

      //Defines text label
      String textLabel = edgeShape.getTextLabel();

      String from = connect.getAttribute(mxVdxConstants.TO_SHEET);
      mxVdxShape fromShape = vertexShapeMap.get(new PageShapeIDKey(
          pageNumber, from));

      //If the source is not defined.
      if (connect.getAttribute(mxVdxConstants.FROM_CELL).equals(
          mxVdxConstants.END_X)
          || fromShape == null)
      {
        //Only one side connected.
        source = (mxCell) graph.insertVertex(parent, null, null,
            beginXY.getX(), beginXY.getY(), 0, 0);
        fromConstraint = new mxPoint(0, 0);

        sigConnect = connect;
      }
      else
      {
        //Define Source vertex of the edge.
        source = vertexMap.get(new PageShapeIDKey(pageNumber, from));

        //Get dimentions of vertex
        mxPoint dimentionFrom = fromShape.getDimentions();

        //Get From shape origin and begin/end of edge in absolutes values.
        double height = pageHeight;

        if ((source.getParent() != null)
            && (source.getParent().getGeometry() != null))
        {
          height = source.getParent().getGeometry().getHeight();
          height += pageHeight - actualPageHeight;
        }

        mxPoint originFrom = fromShape.getOriginPoint(height);
        mxPoint absOriginFrom = calculateAbsolutePoint(
            (mxCell) source.getParent(), graph, originFrom);

        //Determines From Constraints (Connection point) of the edge.
        fromConstraint = new mxPoint(
            (beginXY.getX() - absOriginFrom.getX())
                / dimentionFrom.getX(),
            (beginXY.getY() - absOriginFrom.getY())
                / dimentionFrom.getY());

      }

      //If is connected in both sides.
      if (sigConnect != null)
      {
        String to = sigConnect.getAttribute(mxVdxConstants.TO_SHEET);
        mxVdxShape toShape = vertexShapeMap.get(new PageShapeIDKey(
            pageNumber, to));

        if (toShape != null)
        {

          target = vertexMap.get(new PageShapeIDKey(pageNumber, to));

          mxPoint dimentionTo = toShape.getDimentions();

          //Get To shape origin.
          double height = pageHeight;

          if ((target.getParent() != null)
              && (target.getParent().getGeometry() != null))
          {
            height = target.getParent().getGeometry().getHeight();
            height += pageHeight - actualPageHeight;
          }
          mxPoint originTo = toShape.getOriginPoint(height);

          mxPoint absOriginTo = calculateAbsolutePoint(
              (mxCell) target.getParent(), graph, originTo);

          //Determines To Constraints (Connection point) of the edge.
          toConstraint = new mxPoint(
              (endXY.getX() - absOriginTo.getX())
                  / dimentionTo.getX(),
View Full Code Here

   * @return The new edge added.
   */
  private static Object addNotConnectedEdge(mxGraph graph, Object parent,
      mxVdxShape edgeShape)
  {
    mxCell edge = null;

    //Defines the label of the edge.
    String textLabel = edgeShape.getTextLabel();

    //Get begin and end of edge.
    double height = pageHeight;
    mxCell parentCell = (mxCell) parent;

    if (parentCell != null)
    {
      mxGeometry parentGeometry = parentCell.getGeometry();

      if (parentGeometry != null)
      {
        height = parentGeometry.getHeight();
      }
    }

    mxPoint beginXY = edgeShape.getBeginXY(height);
    mxPoint endXY = edgeShape.getEndXY(height);

    //Create the source and target cell of the edge.
    mxCell target = (mxCell) graph.insertVertex(parent, null, null,
        endXY.getX(), endXY.getY(), 0, 0);

    mxCell source = (mxCell) graph.insertVertex(parent, null, null,
        beginXY.getX(), beginXY.getY(), 0, 0);

    //Define style of the edge
    String style = edgeShape.getStyleFromEdgeShape(height);

    //Determines Constraints (Connection points) of the edge.
    mxPoint fromConstraint = new mxPoint(0, 0);
    mxPoint toConstraint = new mxPoint(0, 0);

    //Insert new edge and set constraints.
    edge = (mxCell) graph.insertEdge(source.getParent(), null, textLabel,
        source, target, style);
    graph.setConnectionConstraint(edge, source, true,
        new mxConnectionConstraint(fromConstraint, false));
    graph.setConnectionConstraint(edge, target, false,
        new mxConnectionConstraint(toConstraint, false));
View Full Code Here

  public void execute(Object parent) {
    SimpleGraph sg = new SimpleGraph();   
    HashMap <mxCell, SimpleVertex> vertexes = new HashMap<mxCell, SimpleVertex>();
    for (Object obj : graph.getChildVertices(parent)) {
      if (obj instanceof mxCell) {
        mxCell cell = (mxCell) obj;
        SimpleVertex sv = new SimpleVertex();
        int width = (int) Math.round(cell.getGeometry().getWidth());
        int height = (int) Math.round(cell.getGeometry().getHeight());
        VertexExt ve = new VertexExt(cell.getGeometry().getPoint(), width, height);
        sv.setVertexext(ve);
        sv.setProperty("id", cell.getId());
        sg.addVertex(sv);
        vertexes.put(cell, sv);
      }
    }
    for (Object obj : graph.getChildEdges(parent)) {
      if (obj instanceof mxCell) {
        mxCell cell = (mxCell) obj;
        SimpleEdge se = new SimpleEdge(vertexes.get(cell.getSource()), vertexes.get(cell.getTarget()));
        se.setProperty("id", cell.getId());
        sg.addEdge(se);
      }
    }
    MultiLayerLayouter.layout(sg);
   
        mxCell someCell = ((mxCell)vertexes.keySet().toArray()[0]);
        double xscale = someCell.getGeometry().getWidth() / (vertexes.get(someCell).getVertexext().getWidth() - .5);
        double yscale = someCell.getGeometry().getHeight() / (vertexes.get(someCell).getVertexext().getHeight() - .5);
    for (Object obj : sg.getVertices()) {
      if (obj instanceof SimpleVertex) {
        SimpleVertex sv = (SimpleVertex) obj;
       
        for (mxCell vertex: vertexes.keySet()) {
          if (vertex.getId().equals(sv.getProperty("id"))) {
            VertexExt ve =  sv.getVertexext();
            mxGeometry vertexGeometry = vertex.getGeometry();
            super.setVertexLocation(vertex, ve.getLeftTop().getX()*xscale, ve.getLeftTop().getY()*yscale);
          }
        }
               
      }
    }
    for (Object obj : sg.getEdges()) {
      if (obj instanceof SimpleEdge) {
        SimpleEdge se = (SimpleEdge) obj;
        for (Object e : graph.getChildEdges(parent)) {
          if (e instanceof mxCell) {
            mxCell edge = (mxCell) e;
            if (edge.getId().equals(se.getProperty("id"))) {
              List<mxPoint> jgraphpoints = new ArrayList<mxPoint>();
              jgraphpoints.add(new mxPoint(edge.getSource().getGeometry().getCenterX(),
                  edge.getTarget().getGeometry().getCenterY()));
              super.setEdgePoints(edge, jgraphpoints);
              super.setOrthogonalEdge(edge, true);
            }
          }
        }
View Full Code Here

    for (Object vertex : vertexes)
    {
      List<mxGmlNode> Gmlnodes = gmlGraph.getNodes();

      mxCell v = (mxCell) vertex;
      String id = v.getId();

      mxGmlNode gmlNode = new mxGmlNode(id, null);
      addNodeData(gmlNode, v);
      Gmlnodes.add(gmlNode);
      gmlGraph.setNodes(Gmlnodes);
View Full Code Here

TOP

Related Classes of com.mxgraph.model.mxCell

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.