1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
| import javax.swing.JFrame;
import org.jdom2.JDOMException;
import com.mxgraph.model.mxCell;
import com.mxgraph.swing.mxGraphComponent;
import com.mxgraph.view.mxGraph;
import com.mxgraph.util.mxConstants;
import java.io.IOException;
public class JGraphExemple1 extends JFrame {
/** Pour éviter un warning venant du JFrame */
private static final long serialVersionUID = -8123406571694511514L;
public JGraphExemple1() throws IOException, JDOMException {
super("JGrapghX tutoriel: Exemple 1");
mxGraph graph = new mxGraph();
Object parent = graph.getDefaultParent();
Etat E= new Etat();
graph.getModel().beginUpdate();
try {
String etatFinalStyle = mxConstants.STYLE_SHAPE + "="+mxConstants.SHAPE_DOUBLE_ELLIPSE;
String etatStyle = mxConstants.STYLE_SHAPE + "="+mxConstants.SHAPE_ELLIPSE;
Object v1 = graph.insertVertex(parent, null, E, 20, 30, 100, 80,etatStyle);
Object v2 = graph.insertVertex(parent, null, E, 250, 28, 100, 80,etatFinalStyle);
graph.insertEdge(parent, null, "Transitions invoqués", v1, v2);
} finally {
graph.getModel().endUpdate();
displayModel((mxCell) parent,"");
}
mxGraphComponent graphComponent = new mxGraphComponent(graph);
getContentPane().add(graphComponent);
/*
graph.getModel().beginUpdate();
try {
Object level1 = graph.insertVertex(parent, null, "Bloc1", 10, 10, 350, 120);
Object level2 = graph.insertVertex(parent, null, "Bloc2", 10, 150, 350, 120);
Object level1_1 = graph.insertVertex(level1, null, "SubBloc11", 10, 50, 100, 40);
Object level1_2 = graph.insertVertex(level1, null, "SubBloc12", 240, 50, 100, 40);
Object level2_1 = graph.insertVertex(level2, null, "SubBloc21", 10, 50, 100, 40);
Object level2_2 = graph.insertVertex(level2, null, "SubBloc22", 240, 50, 100, 40);
graph.insertEdge(level1, null, "lien11_12", level1_1, level1_2);
graph.insertEdge(level2, null, "lien21_22", level2_1, level2_2);
graph.insertEdge(parent, null, "lien1_2", level1, level2);
}
finally {
graph.getModel().endUpdate();
displayModel((mxCell) parent,"");
}
mxGraphComponent graphComponent = new mxGraphComponent(graph);
getContentPane().add(graphComponent);
*/
}
private void displayModel(mxCell cell, String indent) {
System.out.println(indent+cell.getValue()+"("+cell.getClass().getName()+")");
int nbChilds = cell.getChildCount();
indent = indent + " ";
for (int i=0; i<nbChilds ; i++) {
displayModel((mxCell) cell.getChildAt(i), indent);
}
}
/**
* @param args
* @throws IOException
* @throws JDOMException
*/
public static void main(String[] args) throws IOException, JDOMException {
JGraphExemple1 frame = new JGraphExemple1();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(400, 320);
frame.setVisible(true);
}
} |
Partager