Exemplo n.º 1
0
  public mxGraphComponent gerar() {
    graph.getModel().beginUpdate();

    if (!gerado) {
      Object fim =
          graph.insertVertex(
              parent,
              null,
              "Fim",
              10
                  + (colunaatual * DISTANCIAX)
                  + (LARGURA * colunaatual)
                  + Math.round((LARGURA - 70) / 2),
              10 + ((nlinhas) * DISTANCIAY) + (ALTURA * nlinhas++),
              70,
              ALTURA,
              "terminador");
      graph.insertEdge(parent, null, getProximaLigacao(), ultimo, fim, "linhaquadrada");
      gerado = true;
    }
    graph.setAllowDanglingEdges(false);
    graph.setAutoSizeCells(true);
    graph.setConnectableEdges(false);
    graph.getModel().endUpdate();

    final mxGraphComponent graphComponent = new mxGraphComponent(graph);
    graphComponent.setToolTips(true);
    graphComponent.getViewport().setOpaque(true);
    graphComponent.getViewport().setBackground(new Color(250, 250, 250));
    graphComponent.setGridVisible(true);
    getContentPane().add(graphComponent);

    // Handle only mouse click events
    graphComponent
        .getGraphControl()
        .addMouseListener(
            new MouseAdapter() {

              @Override
              public void mousePressed(MouseEvent e) {
                Object cell = graphComponent.getCellAt(e.getX(), e.getY());
                if (cell != null) {
                  JanelaPrincipal.alertarClique((String) ((mxCell) cell).getValue());
                }
              }
            });

    return graphComponent;
  }
Exemplo n.º 2
0
  public Port() {
    super("Hello, World!");

    mxGraph graph =
        new mxGraph() {

          // Ports are not used as terminals for edges, they are
          // only used to compute the graphical connection point
          public boolean isPort(Object cell) {
            mxGeometry geo = getCellGeometry(cell);

            return (geo != null) ? geo.isRelative() : false;
          }

          // Implements a tooltip that shows the actual
          // source and target of an edge
          public String getToolTipForCell(Object cell) {
            if (model.isEdge(cell)) {
              return convertValueToString(model.getTerminal(cell, true))
                  + " -> "
                  + convertValueToString(model.getTerminal(cell, false));
            }

            return super.getToolTipForCell(cell);
          }

          // Removes the folding icon and disables any folding
          public boolean isCellFoldable(Object cell, boolean collapse) {
            return false;
          }
        };

    // Sets the default edge style
    Map<String, Object> style = graph.getStylesheet().getDefaultEdgeStyle();
    style.put(mxConstants.STYLE_EDGE, mxEdgeStyle.ElbowConnector);

    Object parent = graph.getDefaultParent();

    graph.getModel().beginUpdate();
    try {
      mxCell v1 = (mxCell) graph.insertVertex(parent, null, "Hello", 20, 20, 100, 100, "");
      v1.setConnectable(false);
      mxGeometry geo = graph.getModel().getGeometry(v1);
      // The size of the rectangle when the minus sign is clicked
      geo.setAlternateBounds(new mxRectangle(20, 20, 100, 50));

      mxGeometry geo1 = new mxGeometry(0, 0.5, PORT_DIAMETER, PORT_DIAMETER);
      // Because the origin is at upper left corner, need to translate to
      // position the center of port correctly
      geo1.setOffset(new mxPoint(-PORT_RADIUS, -PORT_RADIUS));
      geo1.setRelative(true);

      mxCell port1 = new mxCell(null, geo1, "shape=ellipse;perimter=ellipsePerimeter");
      port1.setVertex(true);

      mxGeometry geo2 = new mxGeometry(1.0, 0.5, PORT_DIAMETER, PORT_DIAMETER);
      geo2.setOffset(new mxPoint(-PORT_RADIUS, -PORT_RADIUS));
      geo2.setRelative(true);

      mxCell port2 = new mxCell(null, geo2, "shape=ellipse;perimter=ellipsePerimeter");
      port2.setVertex(true);

      graph.addCell(port1, v1);
      graph.addCell(port2, v1);

      Object v2 = graph.insertVertex(parent, null, "World!", 240, 150, 80, 30);

      graph.insertEdge(parent, null, "Edge", port2, v2);
    } finally {
      graph.getModel().endUpdate();
    }

    mxGraphComponent graphComponent = new mxGraphComponent(graph);
    getContentPane().add(graphComponent);
    graphComponent.setToolTips(true);
  }
Exemplo n.º 3
0
  public Validation() {
    super("Hello, World!");

    Document xmlDocument = mxDomUtils.createDocument();
    Element sourceNode = xmlDocument.createElement("Source");
    Element targetNode = xmlDocument.createElement("Target");
    Element subtargetNode = xmlDocument.createElement("Subtarget");

    mxGraph graph = new mxGraph();
    Object parent = graph.getDefaultParent();

    graph.getModel().beginUpdate();
    try {
      Object v1 = graph.insertVertex(parent, null, sourceNode, 20, 20, 80, 30);
      Object v2 = graph.insertVertex(parent, null, targetNode, 200, 20, 80, 30);
      Object v3 = graph.insertVertex(parent, null, targetNode.cloneNode(true), 200, 80, 80, 30);
      Object v4 = graph.insertVertex(parent, null, targetNode.cloneNode(true), 200, 140, 80, 30);
      graph.insertVertex(parent, null, subtargetNode, 200, 200, 80, 30);
      Object v6 = graph.insertVertex(parent, null, sourceNode.cloneNode(true), 20, 140, 80, 30);
      graph.insertEdge(parent, null, "", v1, v2);
      graph.insertEdge(parent, null, "", v1, v3);
      graph.insertEdge(parent, null, "", v6, v4);
      // Object e4 = graph.insertEdge(parent, null, "", v1, v4);
    } finally {
      graph.getModel().endUpdate();
    }

    mxMultiplicity[] multiplicities = new mxMultiplicity[3];

    // Source nodes needs 1..2 connected Targets
    multiplicities[0] =
        new mxMultiplicity(
            true,
            "Source",
            null,
            null,
            1,
            "2",
            Arrays.asList(new String[] {"Target"}),
            "Source Must Have 1 or 2 Targets",
            "Source Must Connect to Target",
            true);

    // Source node does not want any incoming connections
    multiplicities[1] =
        new mxMultiplicity(
            false,
            "Source",
            null,
            null,
            0,
            "0",
            null,
            "Source Must Have No Incoming Edge",
            null,
            true); // Type does not matter

    // Target needs exactly one incoming connection from Source
    multiplicities[2] =
        new mxMultiplicity(
            false,
            "Target",
            null,
            null,
            1,
            "1",
            Arrays.asList(new String[] {"Source"}),
            "Target Must Have 1 Source",
            "Target Must Connect From Source",
            true);

    graph.setMultiplicities(multiplicities);

    final mxGraphComponent graphComponent = new mxGraphComponent(graph);
    graph.setMultigraph(false);
    graph.setAllowDanglingEdges(false);
    graphComponent.setConnectable(true);
    graphComponent.setToolTips(true);

    // Enables rubberband selection
    new mxRubberband(graphComponent);
    new mxKeyboardHandler(graphComponent);

    // Installs automatic validation (use editor.validation = true
    // if you are using an mxEditor instance)
    graph
        .getModel()
        .addListener(
            mxEvent.CHANGE,
            new mxIEventListener() {
              public void invoke(Object sender, mxEventObject evt) {
                graphComponent.validateGraph();
              }
            });

    // Initial validation
    graphComponent.validateGraph();

    getContentPane().add(graphComponent);
  }