Created
November 7, 2014 22:58
-
-
Save satyagraha/c7ef214d4396c2644b65 to your computer and use it in GitHub Desktop.
HelloWorld4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.mydemo.jgraphx; | |
import java.awt.BorderLayout; | |
import javax.swing.JFrame; | |
import javax.swing.SwingConstants; | |
import com.mxgraph.layout.mxIGraphLayout; | |
import com.mxgraph.layout.hierarchical.mxHierarchicalLayout; | |
import com.mxgraph.swing.mxGraphComponent; | |
import com.mxgraph.util.mxConstants; | |
import com.mxgraph.view.mxGraph; | |
public class HelloWorld4 extends JFrame { | |
/** | |
* | |
*/ | |
private static final long serialVersionUID = -2707712944901661771L; | |
public HelloWorld4(int choice) { | |
mxGraph graph = new mxGraph(); | |
Object parent = graph.getDefaultParent(); | |
graph.getModel().beginUpdate(); | |
try { | |
Object v1 = graph.insertVertex(parent, null, "node1", 0, 0, 80, 30); | |
Object v2 = graph.insertVertex(parent, null, "node2", 0, 0, 80, 30); | |
Object v3 = graph.insertVertex(parent, null, "node3", 0, 0, 80, 30); | |
Object v4 = graph.insertVertex(parent, null, "node4", 0, 0, 80, 30); | |
Object v5 = graph.insertVertex(parent, null, "node5", 0, 0, 80, 30); | |
graph.insertEdge(parent, null, null, v2, v1); | |
graph.insertEdge(parent, null, null, v3, v1); | |
graph.insertEdge(parent, null, null, v4, v2); | |
graph.insertEdge(parent, null, null, v5, v3); | |
graph.insertEdge(parent, null, null, v4, v3, mxConstants.STYLE_STROKECOLOR + "=red"); | |
graph.insertEdge(parent, null, null, v5, v2, mxConstants.STYLE_STROKECOLOR + "=blue"); | |
} finally { | |
graph.getModel().endUpdate(); | |
} | |
// define layout | |
graph.setAllowNegativeCoordinates(false); | |
final mxIGraphLayout layout; | |
switch (choice) { | |
case 0: | |
layout = new mxHierarchicalLayout(graph, SwingConstants.WEST); // works ok | |
break; | |
case 1: | |
layout = new mxHierarchicalLayout(graph, SwingConstants.EAST); // broken | |
break; | |
case 2: | |
layout = new AllDirectionsHierarchicalLayout(graph, SwingConstants.EAST); // partially broken | |
break; | |
case 3: | |
layout = new mxHierarchicalLayout(graph, SwingConstants.NORTH); // works ok | |
break; | |
case 4: | |
layout = new mxHierarchicalLayout(graph, SwingConstants.SOUTH); // broken | |
break; | |
case 5: | |
layout = new AllDirectionsHierarchicalLayout(graph, SwingConstants.SOUTH); // partially broken | |
break; | |
default: | |
layout = null; | |
} | |
layout.execute(graph.getDefaultParent()); | |
JFrame f = new JFrame(); | |
f.setSize(800, 800); | |
f.setLocation(30, 20); | |
mxGraphComponent graphComponent = new mxGraphComponent(graph); | |
f.getContentPane().add(BorderLayout.CENTER, graphComponent); | |
f.setVisible(true); | |
} | |
public static void main(String[] args) { | |
new HelloWorld4(Integer.parseInt(args[0])); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment