improved piece of code

This commit is contained in:
bancika
2011-01-21 21:17:30 +00:00
parent 91509c2bce
commit 2c00a7a973
@@ -585,16 +585,14 @@ public class Presenter implements IPlugInPort {
int oldSize = controlPointMap.size(); int oldSize = controlPointMap.size();
LOG.debug("Expanding selected component map"); LOG.debug("Expanding selected component map");
for (IDIYComponent<?> component : currentProject.getComponents()) { for (IDIYComponent<?> component : currentProject.getComponents()) {
// Do not process a component if it's already in the map.
ComponentType componentType = componentTypeMap.get(component.getClass().getName()); ComponentType componentType = componentTypeMap.get(component.getClass().getName());
// Do not process a component if it's already in the map.
if (!controlPointMap.containsKey(component)) {
// Check if there's a control point in the current selection // Check if there's a control point in the current selection
// that matches with one of its control points. // that matches with one of its control points.
for (int i = 0; i < component.getControlPointCount(); i++) { for (int i = 0; i < component.getControlPointCount(); i++) {
if (controlPointMap.containsKey(component)) { if (component.isControlPointSticky(i)) {
break;
}
if (!controlPointMap.containsKey(component) && component.isControlPointSticky(i)) {
boolean componentMatches = false; boolean componentMatches = false;
for (Map.Entry<IDIYComponent<?>, Set<Integer>> entry : controlPointMap for (Map.Entry<IDIYComponent<?>, Set<Integer>> entry : controlPointMap
.entrySet()) { .entrySet()) {
@@ -605,8 +603,8 @@ public class Presenter implements IPlugInPort {
Point firstPoint = component.getControlPoint(i); Point firstPoint = component.getControlPoint(i);
if (entry.getKey().isControlPointSticky(j)) { if (entry.getKey().isControlPointSticky(j)) {
Point secondPoint = entry.getKey().getControlPoint(j); Point secondPoint = entry.getKey().getControlPoint(j);
// If they are close enough we can consider them // If they are close enough we can consider
// matched. // them matched.
if (firstPoint.distance(secondPoint) < DrawingManager.CONTROL_POINT_SIZE) { if (firstPoint.distance(secondPoint) < DrawingManager.CONTROL_POINT_SIZE) {
componentMatches = true; componentMatches = true;
break; break;
@@ -632,6 +630,7 @@ public class Presenter implements IPlugInPort {
} }
} }
} }
}
int newSize = controlPointMap.size(); int newSize = controlPointMap.size();
// As long as we're adding new components, do another iteration. // As long as we're adding new components, do another iteration.
if (newSize > oldSize) { if (newSize > oldSize) {