protected void handleAssociations() { Hashtable<String, Object> edgeStyle = new Hashtable<String, Object>(); edgeStyle.put(mxConstants.STYLE_ORTHOGONAL, true); edgeStyle.put(mxConstants.STYLE_EDGE, mxEdgeStyle.ElbowConnector); edgeStyle.put(mxConstants.STYLE_ENTRY_X, 0.0); edgeStyle.put(mxConstants.STYLE_ENTRY_Y, 0.5); graph.getStylesheet().putCellStyle(STYLE_SEQUENCEFLOW, edgeStyle); Hashtable<String, Object> boundaryEdgeStyle = new Hashtable<String, Object>(); boundaryEdgeStyle.put(mxConstants.STYLE_EXIT_X, 0.5); boundaryEdgeStyle.put(mxConstants.STYLE_EXIT_Y, 1.0); boundaryEdgeStyle.put(mxConstants.STYLE_ENTRY_X, 0.5); boundaryEdgeStyle.put(mxConstants.STYLE_ENTRY_Y, 1.0); boundaryEdgeStyle.put(mxConstants.STYLE_EDGE, mxEdgeStyle.OrthConnector); graph.getStylesheet().putCellStyle(STYLE_BOUNDARY_SEQUENCEFLOW, boundaryEdgeStyle); for (Association association : associations.values()) { Object sourceVertex = generatedVertices.get(association.getSourceRef()); Object targetVertex = generatedVertices.get(association.getTargetRef()); String style = null; if (handledFlowElements.get(association.getSourceRef()) instanceof BoundaryEvent) { // Sequence flow out of boundary events are handled in a different way, // to make them visually appealing for the eye of the dear end user. style = STYLE_BOUNDARY_SEQUENCEFLOW; } else { style = STYLE_SEQUENCEFLOW; } Object associationEdge = graph.insertEdge(cellParent, association.getId(), "", sourceVertex, targetVertex, style); generatedAssociationEdges.put(association.getId(), associationEdge); } }
Object sequenceFlowEdge = graph.insertEdge(cellParent, sequenceFlow.getId(), "", sourceVertex, targetVertex, style); generatedSequenceFlowEdges.put(sequenceFlow.getId(), sequenceFlowEdge);
/** * Creates and adds a new edge with an empty style. */ public Object insertEdge(Object parent, String id, Object value, Object source, Object target) { return insertEdge(parent, id, value, source, target, null); }
/** * Creates and adds a new edge with an empty style. */ public Object insertEdge(Object parent, String id, Object value, Object source, Object target) { return insertEdge(parent, id, value, source, target, null); }
/** * @param aGraph * @param numVertices * Returns a path graph */ public void getPathGraph(mxAnalysisGraph aGraph, int numVertices) { if (numVertices < 0) { throw new IllegalArgumentException(); } mxGraph graph = aGraph.getGraph(); Object parent = graph.getDefaultParent(); Object[] vertices = new Object[numVertices]; for (int i = 0; i < numVertices; i++) { vertices[i] = graph.insertVertex(parent, null, new Integer(i).toString(), 0, 0, 25, 25); } for (int i = 0; i < numVertices - 1; i++) { graph.insertEdge(parent, null, getNewEdgeValue(aGraph), vertices[i], vertices[i + 1]); } };
/** * @param aGraph * @param numVertices * Returns a path graph */ public void getPathGraph(mxAnalysisGraph aGraph, int numVertices) { if (numVertices < 0) { throw new IllegalArgumentException(); } mxGraph graph = aGraph.getGraph(); Object parent = graph.getDefaultParent(); Object[] vertices = new Object[numVertices]; for (int i = 0; i < numVertices; i++) { vertices[i] = graph.insertVertex(parent, null, new Integer(i).toString(), 0, 0, 25, 25); } for (int i = 0; i < numVertices - 1; i++) { graph.insertEdge(parent, null, getNewEdgeValue(aGraph), vertices[i], vertices[i + 1]); } };
/** * @param aGraph * @param numVertices * Returns a star graph * Note that minimum vertex number is 4 */ public void getStarGraph(mxAnalysisGraph aGraph, int numVertices) { if (numVertices < 4) { throw new IllegalArgumentException(); } mxGraph graph = aGraph.getGraph(); Object parent = graph.getDefaultParent(); Object[] vertices = new Object[numVertices]; for (int i = 0; i < numVertices; i++) { vertices[i] = graph.insertVertex(parent, null, new Integer(i).toString(), 0, 0, 25, 25); } int numVertexesInPerimeter = numVertices - 1; for (int i = 0; i < numVertexesInPerimeter; i++) { graph.insertEdge(parent, null, getNewEdgeValue(aGraph), vertices[numVertexesInPerimeter], vertices[i]); } };
private static void addStartTransition(mxGraph graph, MTask<?> taskInicial, Map<String, Object> mapaVertice) { final Object v = graph.insertVertex(graph.getDefaultParent(), null, null, 20, 20, 20, 20); setStyle(v, "START"); final Object destino = mapaVertice.get(taskInicial.getAbbreviation()); graph.insertEdge(graph.getDefaultParent(), null, null, v, destino); }
private static void addStartTransition(mxGraph graph, STask<?> taskInicial, Map<String, Object> mapaVertice) { final Object v = graph.insertVertex(graph.getDefaultParent(), null, null, 20, 20, 20, 20); setStyle(v, "START"); final Object destiny = mapaVertice.get(taskInicial.getAbbreviation()); graph.insertEdge(graph.getDefaultParent(), null, null, v, destiny); }
private static void addStartTransition(mxGraph graph, STask<?> taskInicial, Map<String, Object> mapaVertice) { final Object v = graph.insertVertex(graph.getDefaultParent(), null, null, 20, 20, 20, 20); setStyle(v, "START"); final Object destiny = mapaVertice.get(taskInicial.getAbbreviation()); graph.insertEdge(graph.getDefaultParent(), null, null, v, destiny); }
private static void addStartTransition(mxGraph graph, STask<?> taskInicial, Map<String, Object> mapaVertice) { final Object v = graph.insertVertex(graph.getDefaultParent(), null, null, 20, 20, 20, 20); setStyle(v, "START"); final Object destiny = mapaVertice.get(taskInicial.getAbbreviation()); graph.insertEdge(graph.getDefaultParent(), null, null, v, destiny); }
private void createDirectLinks(mxGraph graph, Object parent, Map<String, Object> insertedVertex, CubeContainer cubeContainer, Object currentContainer) { // create relation to all direct links if (cubeContainer.getLinks() != null) { for (Link link : cubeContainer.getLinks()) { final String linkId = link.getName(); Object linkContainer = null; if (insertedVertex.containsKey(linkId)) { linkContainer = insertedVertex.get(linkId); } else { linkContainer = graph.insertVertex(parent, null, linkId, 0, 0, 80, 30); } graph.updateCellSize(currentContainer); graph.insertEdge(parent, null, link.getAlias(), currentContainer, linkContainer); insertedVertex.put(linkId, linkContainer); } } }
private static void createTransition(mxGraph graph, STransition transition, String transitionName, Map<String, Object> mapNodes) { Object origin = mapNodes.get(transition.getOrigin().getAbbreviation()); Object destiny = mapNodes.get(transition.getDestination().getAbbreviation()); String name = transitionName; if (transition.getDestination().getName().equals(transitionName)) { name = null; } graph.insertEdge(graph.getDefaultParent(), null, formatName(name), origin, destiny); }
private static void createTransition(mxGraph graph, STransition transition, Map<String, Object> mapNodes) { final Object origin = mapNodes.get(transition.getOrigin().getAbbreviation()); final Object destiny = mapNodes.get(transition.getDestination().getAbbreviation()); String name = transition.getName(); if (transition.getDestination().getName().equals(name)) { name = null; } else { name = formatName(name); } graph.insertEdge(graph.getDefaultParent(), null, name, origin, destiny); }
@Override public void insertGraphEdge(GraphEdge graphEdge) throws GraphRenderingException { Object nodeA = getGraphNodeObjectMap().get(graphEdge.getGraphNodeA()); if (nodeA == null) { throw new GraphRenderingException("First node from edge has not been inserted yet."); } Object nodeB = getGraphNodeObjectMap().get(graphEdge.getGraphNodeB()); if (nodeB == null) { throw new GraphRenderingException("Second node from edge has not been inserted yet."); } StringBuilder styleSB = new StringBuilder(); if (graphEdge.getColor() != null) { styleSB.append(mxConstants.STYLE_STROKECOLOR).append("=").append(graphEdge.getColor()).append(";"); } if (GraphEdge.Style.DASHED.equals(graphEdge.getStyle())) { styleSB.append(mxConstants.STYLE_DASHED).append("=true;"); } styleSB.append(mxConstants.STYLE_ROUNDED).append("=true;"); styleSB.append(mxConstants.STYLE_EDGE).append("=").append(mxConstants.EDGESTYLE_ENTITY_RELATION); String label = graphEdge.getLabel(); Object edge = getGraph().insertEdge(getGraph().getDefaultParent(), null, label, nodeA, nodeB); getGraph().getModel().setStyle(edge, styleSB.toString()); }
private static void createTransition(mxGraph graph, STransition transition, Map<String, Object> mapNodes) { final Object origin = mapNodes.get(transition.getOrigin().getAbbreviation()); final Object destiny = mapNodes.get(transition.getDestination().getAbbreviation()); String name = transition.getName(); if (transition.getDestination().getName().equals(name)) { name = null; } else { name = formatName(name); } graph.insertEdge(graph.getDefaultParent(), null, name, origin, destiny); }
public class TelaPrincipalController { @FXML private SwingNode swingComponentWrapper ; public void initialize() { SwingUtilities.invokeLater(this::createMxGraph); } private void createMxGraph() { mxGraph grafo = new mxGraph(); Object parent = grafo.getDefaultParent(); Object v1 = grafo.insertVertex(parent, null, "Brazil", 100, 100, 50, 40); Object v2 = grafo.insertVertex(parent, null, "Soccer", 240, 150, 50, 40); Object a1 = grafo.insertEdge(parent, null, "loves", v1, v2); mxGraphComponent graphComponent = new mxGraphComponent(grafo); swingComponentWrapper.setContent(graphComponent); } @FXML private void selecionarNo() { // ... } // etc etc... }
private static void createTransition(mxGraph graph, MTransition transicao, Map<String, Object> mapaVertice) { final Object origem = mapaVertice.get(transicao.getOrigin().getAbbreviation()); final Object destino = mapaVertice.get(transicao.getDestination().getAbbreviation()); String nome = transicao.getName(); if (transicao.getDestination().getName().equals(nome)) { nome = null; } else { nome = formatarNome(nome); } graph.insertEdge(graph.getDefaultParent(), null, nome, origem, destino); }
public static mxGraph makeHelloWorldGraph() { mxGraph graph = new mxGraph(); Object parent = graph.getDefaultParent(); graph.getModel().beginUpdate(); try { Object v1 = graph.insertVertex(parent, null, "", 20, 20, 80, 30,"opacity=0"); Object v2 = graph.insertVertex(parent, null, "World!", 240, 150, 80, 30); graph.insertEdge(parent, null, "Edge", v1, v2); } finally { graph.getModel().endUpdate(); } return graph; }
import javax.swing.JFrame; import com.mxgraph.swing.mxGraphComponent; import com.mxgraph.view.mxGraph; public class GraphFrame extends JFrame { public static void main(String[] args) { mxGraph graph = new mxGraph(); Object parent = graph.getDefaultParent(); graph.getModel().beginUpdate(); try { Object v1 = graph.insertVertex(parent, null, "Hello", 20, 20, 80, 30); Object v2 = graph.insertVertex(parent, null, "World!", 240, 150, 80, 30); graph.insertEdge(parent, null, "Edge", v1, v2); } finally { graph.getModel().endUpdate(); } mxGraphComponent graphComponent = new mxGraphComponent(graph); GraphFrame frame = new GraphFrame(); frame.add(graphComponent); frame.pack(); frame.setVisible(true); } }