/** * 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; }
/** * Disconnect <code>edge</code> from <code>port</code>. * <code>source</code> indicates if <code>port</code> is the source of * <code>edge</code>. The previous connections between <code>edge</code> * and its source or target in the set is replaced. */ public void disconnect(Object edge, boolean source) { connections.add(new Connection(edge, null, source)); edges.add(edge); }
/** * 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; }
/** * 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; }
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); }
/** * Two connections are equal if they represent the source or target of * the same edge. That is, if * <p> * c1.edge == c2.edge && c1.isSource == c2.isSource. */ public boolean equals(Object obj) { if (obj instanceof Connection) { Connection other = (Connection) obj; return (other.getEdge().equals(edge) && other.isSource() == isSource); } return false; }
/** * Constructs a connection set containing the specified connections and * updates the set of changed edges. */ public ConnectionSet(Set connections) { setConnections(connections); Iterator it = connections.iterator(); while (it.hasNext()) { Connection conn = (Connection) it.next(); edges.add(conn.getEdge()); } }
/** * 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); }
/** * Connect <code>edge</code> to <code>port</code> passed in. The * <code>source</code> indicates if <code>port</code> is the source of * <code>edge</code> object. The previous connections between * <code>edge</code> and its source or target in the set is replaced. */ public void connect(Object edge, Object port, boolean source) { Connection c = new Connection(edge, port, source); connections.remove(c); connections.add(c); edges.add(edge); }