Expand selection feature, useful for debugging

Limit length of text in the status bar using "and X more" suffix
This commit is contained in:
bancika
2012-02-26 03:54:12 +00:00
parent 4ee7381959
commit dd9e9f054c
11 changed files with 234 additions and 7 deletions
@@ -3,6 +3,7 @@ package org.diylc.common;
import java.awt.Point;
import java.util.List;
import org.diylc.core.ExpansionMode;
import org.diylc.core.IDIYComponent;
public interface ISelectionProcessor {
@@ -32,6 +33,14 @@ public interface ISelectionProcessor {
*/
List<IDIYComponent<?>> findComponentsAt(Point point);
/**
* Expands the current selection to include surrounding components.
* Options are controlled with <code>expansionMode</code> flag.
*
* @param expansionMode
*/
void expandSelection(ExpansionMode expansionMode);
/**
* Selects all components in the project.
*/
@@ -0,0 +1,8 @@
package org.diylc.core;
public enum ExpansionMode {
ALL,
SAME_TYPE,
IMMEDIATE,
}
@@ -37,6 +37,7 @@ import org.diylc.common.IPlugIn;
import org.diylc.common.IPlugInPort;
import org.diylc.common.PropertyWrapper;
import org.diylc.components.connectivity.SolderPad;
import org.diylc.core.ExpansionMode;
import org.diylc.core.IDIYComponent;
import org.diylc.core.IView;
import org.diylc.core.Project;
@@ -55,7 +56,7 @@ public class Presenter implements IPlugInPort {
private static final Logger LOG = Logger.getLogger(Presenter.class);
public static final VersionNumber CURRENT_VERSION = new VersionNumber(3, 2, 0);
public static final VersionNumber CURRENT_VERSION = new VersionNumber(3, 3, 0);
public static final String DEFAULTS_KEY_PREFIX = "default.";
public static final List<IDIYComponent<?>> EMPTY_SELECTION = Collections.emptyList();
@@ -1078,6 +1079,7 @@ public class Presenter implements IPlugInPort {
@Override
public void refresh() {
LOG.info("refresh()");
messageDispatcher.dispatchMessage(EventType.REPAINT);
}
@@ -1093,6 +1095,7 @@ public class Presenter implements IPlugInPort {
@Override
public void renumberSelectedComponents(final boolean xAxisFirst) {
LOG.info("renumberSelectedComponents(" + xAxisFirst + ")");
if (getSelectedComponents().isEmpty()) {
return;
}
@@ -1183,6 +1186,66 @@ public class Presenter implements IPlugInPort {
controlPointMap.keySet());
}
@Override
public void expandSelection(ExpansionMode expansionMode) {
List<IDIYComponent<?>> newSelection = new ArrayList<IDIYComponent<?>>(
this.selectedComponents);
// Find control points of all selected components and all types
Set<String> selectedNamePrefixes = new HashSet<String>();
if (expansionMode == ExpansionMode.SAME_TYPE) {
for (IDIYComponent<?> component : getSelectedComponents()) {
selectedNamePrefixes.add(ComponentProcessor.getInstance().extractComponentTypeFrom(
(Class<? extends IDIYComponent<?>>) component.getClass()).getNamePrefix());
}
}
// Now try to find components that intersect with at least one component
// in the pool.
for (IDIYComponent<?> component : getCurrentProject().getComponents()) {
// Skip already selected components or ones that cannot be stuck to
// other components.
Area area = drawingManager.getComponentArea(component);
if (newSelection.contains(component) || !component.isControlPointSticky(0) || area == null)
continue;
boolean matches = false;
for (IDIYComponent<?> selectedComponent : this.selectedComponents) {
Area selectedArea = drawingManager.getComponentArea(selectedComponent);
if (selectedArea == null)
continue;
Area intersection = new Area(area);
intersection.intersect(selectedArea);
if (!intersection.isEmpty()) {
matches = true;
break;
}
}
if (matches) {
switch (expansionMode) {
case ALL:
case IMMEDIATE:
newSelection.add(component);
break;
case SAME_TYPE:
if (selectedNamePrefixes.contains(ComponentProcessor.getInstance()
.extractComponentTypeFrom(
(Class<? extends IDIYComponent<?>>) component.getClass())
.getNamePrefix())) {
newSelection.add(component);
}
break;
}
}
}
int oldSize = this.getSelectedComponents().size();
updateSelection(newSelection);
// Go deeper if possible.
if (newSelection.size() > oldSize && expansionMode != ExpansionMode.IMMEDIATE) {
expandSelection(expansionMode);
}
messageDispatcher.dispatchMessage(EventType.REPAINT);
}
/**
* Removes all the groups that contain at least one of the specified
* components.