public JGraphXGraphPanel(NAR n) {
    super(new BorderLayout());

    NARGraph g = new NARGraph();
    g.add(n, IncludeEverything, new NARGraph.DefaultGraphizer(true, true, true, true, true));

    // create a visualization using JGraph, via an adapter
    jgxAdapter = new JGraphXAdapter(g) {};

    mxGraphComponent mxc = new mxGraphComponent(jgxAdapter) {};

    mxc.setAntiAlias(true);
    mxc.setConnectable(false);
    mxc.setExportEnabled(false);
    mxc.setFoldingEnabled(false);
    mxc.setPanning(true);
    mxc.setTextAntiAlias(true);

    add(new JScrollPane(mxc), BorderLayout.CENTER);

    mxFastOrganicLayout layout =
        // new mxCompactTreeLayout(jgxAdapter);
        new mxFastOrganicLayout(jgxAdapter);
    // new mxCircleLayout(jgxAdapter);
    layout.setForceConstant(150);
    layout.execute(jgxAdapter.getDefaultParent());

    /*
    mxOrganicLayout layout =
            //new mxCompactTreeLayout(jgxAdapter);
            new mxOrganicLayout(jgxAdapter);
            //new mxCircleLayout(jgxAdapter);
    layout.setEdgeLengthCostFactor(0.001);*/

    /*
    mxCompactTreeLayout layout =
            new mxCompactTreeLayout(jgxAdapter);

    layout.setLevelDistance(40);
    layout.setNodeDistance(50);
    layout.execute(jgxAdapter.getDefaultParent());*/

    jgxAdapter.setConnectableEdges(false);
    jgxAdapter.setCellsDisconnectable(false);
    jgxAdapter.setEdgeLabelsMovable(false);
    // jgxAdapter.setCellsLocked(true);
  }
示例#2
0
 // graphs the currentLayout
 public void graph() {
   if (currentLayout == FASTORGANIC) {
     layout = new mxStackLayout(panGraph, false, 10, 20, 20, 2);
     morphLayout();
     setMxLayout(currentLayout);
     morphLayout();
     layout = new mxParallelEdgeLayout(panGraph, 20);
     morphLayout();
     setMxLayout(currentLayout);
   } else if (currentLayout == CIRCLE) {
     morphLayout();
     layout = new mxParallelEdgeLayout(panGraph, 20);
     morphLayout();
     setMxLayout(currentLayout);
   } else {
     morphLayout();
   }
   graphComponent.setConnectable(false);
 }
示例#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);
  }