public ConnectionSet connections(String[] roles, DefaultEdge[] edges, Port[] objects) { // Connections that will be inserted into the Model ConnectionSet cs = new ConnectionSet(); // Create connections between objects and this n-edge. for (int i = 0; i < objects.length; i++) { cs.connect(edges[i], this.getPort(roles[i]), objects[i]); } return cs; }
/** * A shortcut method to create a connection set that represents the * connections in this model. Useful for encoding to avoid writing redundant * connection data stored in the cells. */ public ConnectionSet getConnectionSet() { return ConnectionSet .create(this, DefaultGraphModel.getAll(this), false); }
/** * Connect or disconnect <code>edge</code> from <code>source</code> and * <code>target</code> in <code>cs</code> based on * <code>disconnect</code>. */ protected static void connect(ConnectionSet cs, Object edge, Object port, boolean source, boolean disconnect) { if (disconnect) cs.disconnect(edge, source); else cs.connect(edge, port, source); }
/** * Applies <code>connectionSet</code> to the model. Returns a connection * set that may be used to undo this change. */ protected ConnectionSet handleConnectionSet(ConnectionSet cs) { if (cs != null) { ConnectionSet csundo = new ConnectionSet(); Iterator it = cs.connections(); while (it.hasNext()) { ConnectionSet.Connection c = (ConnectionSet.Connection) it .next(); Object edge = c.getEdge(); if (c.isSource()) csundo.connect(edge, getSource(edge), true); else csundo.connect(edge, getTarget(edge), false); handleConnection(c, false); } // When removing edges it is possible that an edge is // removed in a later step which has been added in a // previous connection establishment (set semantic). // Therefore, we first need to remove all old connections // and then add all new connections in two steps. it = cs.connections(); while (it.hasNext()) handleConnection((ConnectionSet.Connection) it.next(), true); return csundo; } return null; }
public void beginUpdate() { updateLevel++; if (updateLevel == 1) { transEditAttrs = new Hashtable(); transEditCS = new ConnectionSet(); transEditPM = new ParentMap(); transAddedCells = new HashSet(); transRemovedCells = new HashSet(); } }
/** * Returns a connection set that represents the connection or disconnection * of <code>cells</code> in <code>model</code> based on * <code>disconnect</code>. */ public static ConnectionSet create(GraphModel m, Object[] cells, boolean disconnect) { ConnectionSet cs = new ConnectionSet(); for (int i = 0; i < cells.length; i++) { Object cell = cells[i]; // Edge if (m.isEdge(cell)) { if (disconnect) cs.disconnect(cell); else cs.connect(cell, m.getSource(cell), m.getTarget(cell)); } // Port Iterator it = m.edges(cell); while (it.hasNext()) { // Edge At Port Object edge = it.next(); if (m.getSource(edge) == cell) connect(cs, edge, cell, true, disconnect); else if (m.getTarget(edge) == cell) connect(cs, edge, cell, false, disconnect); } } return cs; }
/** * Constructs a ConnectionSet with one Connection. */ public ConnectionSet(Object edge, Object port, boolean source) { connect(edge, port, source); }
Set connections = transEditCS.getConnections(); connections.addAll(cs.getConnections()); transEditCS.setConnections(connections); Set edges = transEditCS.getEdges(); edges.addAll(cs.getEdges()); transEditCS.setEdges(edges);
ConnectionSet cs = new ConnectionSet(); for (int i = 0; i < cells.length; i++) { if (cells[i] instanceof EdgeView) { && !contains(port.getCell())) { view.setSource(null); cs.disconnect(view.getCell(), true); && !contains(port.getCell())) { view.setTarget(null); cs.disconnect(view.getCell(), false);
protected void handleExternalDrop(JGraph graph, Object[] cells, Map nested, ConnectionSet cs, ParentMap pm, double dx, double dy) { // Removes all connections for which the port is neither // passed in the parent map nor already in the model. Iterator it = cs.connections(); while (it.hasNext()) { ConnectionSet.Connection conn = (ConnectionSet.Connection) it .next(); if (!pm.getChangedNodes().contains(conn.getPort()) && !graph.getModel().contains(conn.getPort())) { it.remove(); } } Map clones = graph.cloneCells(cells); graph.getGraphLayoutCache().insertClones(cells, clones, nested, cs, pm, dx, dy); }
tmp.addAll(attributes.keySet()); if (cs != null) tmp.addAll(cs.getChangedEdges()); if (pm != null) tmp.addAll(pm.getChangedNodes());
if (cells != null) { if (cs != null) cs = cs.clone(clones); if (pm != null) pm = pm.clone(clones);
/** * Disconnect <code>edge</code> from <code>source</code> and * <code>target</code> in the connection set. The previous connections * between <code>edge</code> and its source and target are replaced in the * set. */ public void disconnect(Object edge) { disconnect(edge, true); disconnect(edge, false); }
/** * Creates a new connection set based on this connection set, where the * edges, and ports are mapped using <code>map</code>. If a port is not * found, the old port is used. If both, the edge and the port are not in * <code>map</code>, the entry is ignored. * <p> * <strong>Note: </strong> Consequently, unselected edges are only * reconnected at the first "paste" after a "cut", because in this case the * ConnectionSet is not cloned. */ public ConnectionSet clone(Map map) { ConnectionSet cs = new ConnectionSet(); Iterator it = connections(); while (it.hasNext()) { // Shortcut Vars Connection c = (Connection) it.next(); Object edge = map.get(c.getEdge()); Object port = c.getPort(); if (port != null) port = map.get(port); // New Port if (edge != null && port != null) cs.connect(edge, port, c.isSource()); // Old Port else if (edge != null) cs.connect(edge, c.getPort(), c.isSource()); } return cs; }
/** * Helper methods that connects the source of <code>edge</code> to * <code>port</code> in <code>model</model>. */ public static void setSourcePort(GraphModel model, Object edge, Object port) { model.edit(null, new ConnectionSet(edge, port, true), null, null); }
/** * Connect <code>edge</code> to <code>source</code> and * <code>target</code> in the connection set. The previous connections * between <code>edge</code> and its source and target are replaced in the * set. */ public void connect(Object edge, Object source, Object target) { connect(edge, source, true); connect(edge, target, false); }
Iterator it = cs.connections(); while (it.hasNext()) { ConnectionSet.Connection conn = (ConnectionSet.Connection) it
tmp.addAll(connectionSet.getChangedEdges()); if (remove != null) { for (int i = 0; i < remove.length; i++)
processNestedMap(nested, true); nested = GraphConstants.replaceKeys(cellMap, nested); cs = cs.clone(cellMap); Object[] cells = cellMap.values().toArray(); graph.getGraphLayoutCache().insert(cells, nested, cs, null,
public void run() { ConnectionSet cs = new ConnectionSet(); cs.connect(newEdge, otherextreme.getFirstChild(), vertex.getFirstChild()); Hashtable edgeprops = new Hashtable(); Hashtable elements = new Hashtable(); GraphConstants.setDashPattern(edgeprops, new float[] { 3, 3 }); elements.put(newEdge, edgeprops); glc.insert(new Object[] { newEdge }, elements, cs, null); // to conenct port with port } };