Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Grafica;
- import com.mxgraph.layout.hierarchical.mxHierarchicalLayout;
- import com.mxgraph.layout.mxCircleLayout;
- import com.mxgraph.layout.mxCompactTreeLayout;
- import com.mxgraph.layout.mxFastOrganicLayout;
- import com.mxgraph.layout.mxIGraphLayout;
- import com.mxgraph.layout.mxParallelEdgeLayout;
- import com.mxgraph.layout.mxPartitionLayout;
- import com.mxgraph.layout.mxStackLayout;
- import com.mxgraph.model.mxGeometry;
- import javax.swing.JFrame;
- import com.mxgraph.swing.mxGraphComponent;
- import com.mxgraph.util.mxConstants;
- import com.mxgraph.util.mxPoint;
- import com.mxgraph.view.mxCellState;
- import com.mxgraph.view.mxEdgeStyle;
- import com.mxgraph.view.mxGraph;
- import com.mxgraph.view.mxGraphView;
- import com.mxgraph.view.mxStylesheet;
- import java.util.HashMap;
- import java.util.Hashtable;
- import java.util.Map;
- import javax.swing.JPanel;
- import javax.swing.SwingConstants;
- public class ejemplo extends JPanel {
- /**
- *
- */
- private static final long serialVersionUID = -2707712944901661771L;
- public mxGraph graph;
- public ejemplo() {
- super();
- mxGraph graph = new mxGraph();
- //{
- // protected mxGraphView createGraphView()
- // {
- // return new mxGraphView(this)
- // {
- // public mxPoint getPoint(mxCellState state,
- // mxGeometry geometry)
- // {
- // double x = state.getCenterX()+10;
- // double y = state.getCenterY();
- // if (state.getAbsolutePointCount() == 3)
- // {
- // mxPoint mid = state.getAbsolutePoint(1);
- // x = mid.getX();
- // y = mid.getY();
- // }
- //
- // return new mxPoint(x, y);
- // }
- // };
- // }
- //};
- Object parent = graph.getDefaultParent();
- mxStylesheet stylesheet = graph.getStylesheet();
- Hashtable<String, Object> estiloEstado = new Hashtable<String, Object>();
- estiloEstado.put(mxConstants.STYLE_SHAPE, mxConstants.SHAPE_ELLIPSE);
- estiloEstado.put(mxConstants.STYLE_FONTSIZE, 20);
- Hashtable<String, Object> estiloEFinal = new Hashtable<String, Object>();
- estiloEFinal.put(mxConstants.STYLE_SHAPE, mxConstants.SHAPE_DOUBLE_ELLIPSE);
- estiloEFinal.put(mxConstants.STYLE_FONTSIZE, 20);
- Map<String, Object> edgeStyle = new HashMap<String, Object>();
- edgeStyle.put(mxConstants.STYLE_SHAPE, mxConstants.SHAPE_CONNECTOR);
- edgeStyle.put(mxConstants.STYLE_ENDARROW, mxConstants.ARROW_CLASSIC);
- edgeStyle.put(mxConstants.STYLE_STROKECOLOR, "#000000");
- edgeStyle.put(mxConstants.STYLE_FONTCOLOR, "#000000");
- stylesheet.setDefaultEdgeStyle(edgeStyle);
- // Map<String, Object> EdgeStyle = graph.getStylesheet().getDefaultEdgeStyle();
- //EdgeStyle.put(mxConstants.STYLE_EDGE, mxEdgeStyle.OrthConnector);
- //EdgeStyle.put(mxConstants.STYLE_STROKECOLOR, "red");
- //EdgeStyle.put(mxConstants.STYLE_STROKEWIDTH, 2);
- stylesheet.putCellStyle("ESTADOFINAL", estiloEFinal);
- stylesheet.putCellStyle("ESTADO", estiloEstado);
- graph.setStylesheet(stylesheet);
- graph.getModel().beginUpdate();
- graph.setCellsLocked(true);
- graph.setVertexLabelsMovable(false);
- graph.setEdgeLabelsMovable(false);
- try {
- Object q0 = graph.insertVertex(parent, null, "", 100, 100, 50, 50, "opacity=0");
- Object qA = graph.insertVertex(parent, null, "A", 100, 100, 50, 50, "ESTADOFINAL");
- Object qB = graph.insertVertex(parent, null, "B", 100, 200, 50, 50, "ESTADO");
- Object qC = graph.insertVertex(parent, null, "C", 300, 300, 50, 50, "ESTADO");
- Object qD = graph.insertVertex(parent, null, "D", 400, 400, 50, 50, "ESTADO");
- //Object v3 = graph.insertVertex(parent, null, "q2", 250, 200,50,50, "ESTADO");
- graph.insertEdge(parent, null, "", q0, qA); //flechita inicial
- graph.insertEdge(parent, null, "0", qA, qA,"rounded=1");
- graph.insertEdge(parent, null, "1", qA, qB,"rounded=1");
- graph.insertEdge(parent, null, "0", qB, qB,"rounded=1");
- graph.insertEdge(parent, null, "1", qB, qA);
- graph.insertEdge(parent, null, "1", qB, qC);
- graph.insertEdge(parent, null, "1", qC, qD);
- //mxParallelEdgeLayout layout = new mxParallelEdgeLayout(graph);
- // mxIGraphLayout layout = new mxFastOrganicLayout(graph);
- // mxCircleLayout layout = new mxCircleLayout(graph);
- //mxCompactTreeLayout layout = new mxCompactTreeLayout(graph);
- //mxPartitionLayout layout = new mxPartitionLayout(graph, true, 50, 50);
- //mxParallelEdgeLayout layout2 = new mxParallelEdgeLayout(graph);
- mxHierarchicalLayout layout = new mxHierarchicalLayout(graph);
- layout.setInterRankCellSpacing(50.0);
- layout.setIntraCellSpacing(50.0);
- // layout.setParallelEdgeSpacing(200.0);
- //
- //
- layout.setDisableEdgeStyle(false);
- layout.execute(graph.getDefaultParent());
- } finally {
- graph.getModel().endUpdate();
- }
- this.add(new mxGraphComponent(graph));
- }
- public static void main(String[] args) {
- JFrame frame = new JFrame();
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- frame.setSize(600, 600);
- ejemplo ej = new ejemplo();
- mxGraphComponent graphComponent = new mxGraphComponent(ej.graph);
- frame.add(graphComponent);
- frame.setVisible(true);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement