mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-10 09:12:09 +10:00
improved piece of code
This commit is contained in:
+35
-36
@@ -585,49 +585,48 @@ 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());
|
||||||
|
|
||||||
// Check if there's a control point in the current selection
|
// Do not process a component if it's already in the map.
|
||||||
// that matches with one of its control points.
|
if (!controlPointMap.containsKey(component)) {
|
||||||
for (int i = 0; i < component.getControlPointCount(); i++) {
|
// Check if there's a control point in the current selection
|
||||||
if (controlPointMap.containsKey(component)) {
|
// that matches with one of its control points.
|
||||||
break;
|
for (int i = 0; i < component.getControlPointCount(); i++) {
|
||||||
}
|
if (component.isControlPointSticky(i)) {
|
||||||
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()) {
|
if (componentMatches) {
|
||||||
if (componentMatches) {
|
break;
|
||||||
break;
|
}
|
||||||
}
|
for (Integer j : entry.getValue()) {
|
||||||
for (Integer j : entry.getValue()) {
|
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
|
||||||
// If they are close enough we can consider them
|
// them matched.
|
||||||
// matched.
|
if (firstPoint.distance(secondPoint) < DrawingManager.CONTROL_POINT_SIZE) {
|
||||||
if (firstPoint.distance(secondPoint) < DrawingManager.CONTROL_POINT_SIZE) {
|
componentMatches = true;
|
||||||
componentMatches = true;
|
break;
|
||||||
break;
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
if (componentMatches) {
|
||||||
if (componentMatches) {
|
LOG.debug("Including component: " + component);
|
||||||
LOG.debug("Including component: " + component);
|
Set<Integer> indices = new HashSet<Integer>();
|
||||||
Set<Integer> indices = new HashSet<Integer>();
|
// For stretchable components just add the
|
||||||
// For stretchable components just add the
|
// matching component.
|
||||||
// matching component.
|
// Otherwise, add all control points.
|
||||||
// Otherwise, add all control points.
|
if (componentType.isStretchable()) {
|
||||||
if (componentType.isStretchable()) {
|
indices.add(i);
|
||||||
indices.add(i);
|
} else {
|
||||||
} else {
|
for (int k = 0; k < component.getControlPointCount(); k++) {
|
||||||
for (int k = 0; k < component.getControlPointCount(); k++) {
|
indices.add(k);
|
||||||
indices.add(k);
|
}
|
||||||
}
|
}
|
||||||
|
controlPointMap.put(component, indices);
|
||||||
}
|
}
|
||||||
controlPointMap.put(component, indices);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user