// look up for gate at selected end
if (_translatingPoint && ss instanceof ConnectionPathSelection && ((ConnectionPathSelection)ss).isOneEndSelected()){
ConnectionPathSelection cps = ((ConnectionPathSelection)ss);
Connection connection = cps.getConnection();
boolean isFirstEndSelected = ((ConnectionPathSelection)ss).isFirstEndSelected();
Point p = isFirstEndSelected? connection.getPath().getNode(0) : connection.getPath().getNode(connection.getPath().getNodeNumber()-1);
// Component
GatedComponent gc = getGateComponentAt(p);
if (gc != null){
_currentTrackedComponent.add(gc);
}
// Gate
Gate gate = getGateAt(p);
if (gate != null){
_currentTrackedGates.add(new TrackedGate(connection, isFirstEndSelected, gate));
}
} else if (_translatingShapes){
Shape s = ss.element;
// For each connection ends, look up for a gate
if (ss instanceof ConnectionPathSelection){
Connection connection = ((ConnectionPathSelection)ss).getConnection();
Path connectionPath = connection.getPath();
Point firstEnd = connectionPath.getNode(0); // first end
GatedComponent gc = getGateComponentAt(firstEnd);
if (gc != null){
_currentTrackedComponent.add(gc);
}
Gate gate = getGateAt(firstEnd);
if (gate != null){
_currentTrackedGates.add(new TrackedGate(connection, true, gate));
}
Point lastEnd = connectionPath.getNode(connectionPath.getNodeNumber()-1); // first end
gc = getGateComponentAt(lastEnd);
if (gc != null){
_currentTrackedComponent.add(gc);
}
gate = getGateAt(lastEnd);
if (gate != null){
_currentTrackedGates.add(new TrackedGate(connection, false, gate));
}
// For each gates, look up for a connection ends
} else if (s instanceof GatedComponent){
GatedComponent gc = ((GatedComponent)s);
List gates = gc.getGates();
for(int i =0;i<gates.size();i++){
Gate gate = (Gate)gates.get(i);
Point gateAnchor = gate.getAnchor();
Connection connection = _elementContainer.getSelection().getConnectionAt(gateAnchor.x, gateAnchor.y);
if (connection != null && !connection.isConnected(gate)){
// first connection bound is free
if ( gate.canBeHanged(connection.getPath().getNode(0)) && connection.getFirstEndGate()==null){
_currentTrackedGates.add(new TrackedGate(connection, true, gate));
// last connection bound is free
} else if ( gate.canBeHanged(connection.getPath().getNode(connection.getPath().getNodeNumber()-1))
&& connection.getLastEndGate()==null){
_currentTrackedGates.add(new TrackedGate(connection, false, gate));
}
}
}
}