/** * Returns the source or target of the specified edge in this connection set * or null if the connection set contains no corresponding entry for the * edge. */ public Object getPort(Object edge, boolean source) { if (edges.contains(edge)) { Iterator it = connections.iterator(); while (it.hasNext()) { Connection c = (Connection) it.next(); if (c.getEdge() == edge && c.isSource() == source) return c.getPort(); } } return null; }
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); }
/** * 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; }
/** * Inserts the specified connection into the model. */ protected void handleConnection(ConnectionSet.Connection c, boolean establish) { Object edge = c.getEdge(); Object port = (establish) ? c.getPort() : (c.isSource()) ? getSource(edge) : getTarget(edge); connect(edge, port, c.isSource(), establish); }