don't group pasted components

fix: click twice on a building block makes components jump to top-left
various minor updates
This commit is contained in:
Branislav Stojkovic
2018-12-25 16:49:18 +01:00
parent 48a6857738
commit e9615d4d64
25 changed files with 2963 additions and 2331 deletions
@@ -202,9 +202,10 @@ public interface IPlugInPort extends ISelectionProcessor, IMouseProcessor, IKeyP
/**
* Adds a list of components to the project.
*
* @param components
* @param components
* @param autoGroup
*/
void pasteComponents(Collection<IDIYComponent<?>> components);
void pasteComponents(Collection<IDIYComponent<?>> components, boolean autoGroup);
/**
* Duplicates selected components and places them nearby.
@@ -117,21 +117,7 @@ public class ComponentProcessor {
keywordTag = annotation.keywordTag();
continuity = annotation.continuity();
} else { // default
name = clazz.getSimpleName();
description = "";
creationMethod = CreationMethod.SINGLE_CLICK;
category = "Uncategorized";
namePrefix = "Unknown";
author = "Unknown";
zOrder = IDIYComponent.COMPONENT;
flexibleZOrder = false;
stretchable = true;
bomPolicy = BomPolicy.SHOW_ALL_NAMES;
autoEdit = true;
transformer = null;
keywordPolicy = KeywordPolicy.NEVER_SHOW;
keywordTag = null;
continuity = false;
return null;
}
icon = null;
// Draw component icon.
@@ -29,7 +29,7 @@ import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.log4j.Logger;
import org.diylc.appframework.miscutils.ConfigurationManager;
import org.diylc.common.ComponentType;
@@ -61,9 +61,12 @@ public class InstantiationManager {
private Point firstControlPoint;
private Point potentialControlPoint;
private static final ComponentType clipboardType = new ComponentType("Clipboard contents",
public static final ComponentType clipboardType = new ComponentType("Clipboard contents",
"Components from the clipboard", CreationMethod.SINGLE_CLICK, "Multi", "", "", null, null, 0, false, false, null,
false, null, KeywordPolicy.NEVER_SHOW, null, false);
false, null, KeywordPolicy.NEVER_SHOW, null, false);
public static final ComponentType blockType = new ComponentType("Building block",
"Components from the building block", CreationMethod.SINGLE_CLICK, "Multi", "", "", null, null, 0, false, false, null,
false, null, KeywordPolicy.NEVER_SHOW, null, false);
public InstantiationManager() {}
@@ -85,7 +88,11 @@ public class InstantiationManager {
public Point getPotentialControlPoint() {
return potentialControlPoint;
}
}
public void setPotentialControlPoint(Point potentialControlPoint) {
this.potentialControlPoint = potentialControlPoint;
}
public void setComponentTypeSlot(ComponentType componentTypeSlot, Template template, Project currentProject)
throws Exception {
@@ -133,7 +140,7 @@ public class InstantiationManager {
}
public void pasteComponents(Collection<IDIYComponent<?>> components, Point scaledPoint, boolean snapToGrid,
Size gridSpacing) {
Size gridSpacing, boolean autoGroup) {
// Adjust location of components so they are centered under the mouse
// cursor
int minX = Integer.MAX_VALUE;
@@ -176,7 +183,7 @@ public class InstantiationManager {
// Update the component type slot so the app knows that something's
// being instantiated.
this.componentTypeSlot = clipboardType;
this.componentTypeSlot = autoGroup ? blockType : clipboardType;
if (snapToGrid) {
scaledPoint = new Point(scaledPoint);
@@ -356,6 +356,8 @@ public class Presenter implements IPlugInPort {
if (!Modifier.isAbstract(clazz.getModifiers()) && IDIYComponent.class.isAssignableFrom(clazz)) {
ComponentType componentType =
ComponentProcessor.getInstance().extractComponentTypeFrom((Class<? extends IDIYComponent<?>>) clazz);
if (componentType == null)
continue;
List<ComponentType> nestedList;
if (componentTypes.containsKey(componentType.getCategory())) {
nestedList = componentTypes.get(componentType.getCategory());
@@ -517,8 +519,8 @@ public class Presenter implements IPlugInPort {
addComponent(component, true);
newSelection.add(component);
}
// group components if there's more than one, e.g. building blocks
if (componentSlot.size() > 1) {
// group components if there's more than one, e.g. building blocks, but not clipboard contents
if (componentSlot.size() > 1 && !componentTypeSlot.getName().toLowerCase().contains("clipboard")) {
this.currentProject.getGroups().add(new HashSet<IDIYComponent<?>>(componentSlot));
}
// Select the new component
@@ -1452,10 +1454,10 @@ public class Presenter implements IPlugInPort {
}
@Override
public void pasteComponents(Collection<IDIYComponent<?>> components) {
LOG.info(String.format("pasteComponents(%s)", components));
public void pasteComponents(Collection<IDIYComponent<?>> components, boolean autoGroup) {
LOG.info(String.format("pasteComponents(%s, %s)", components, autoGroup));
instantiationManager.pasteComponents(components, this.previousScaledPoint, isSnapToGrid(),
currentProject.getGridSpacing());
currentProject.getGridSpacing(), autoGroup);
messageDispatcher.dispatchMessage(EventType.REPAINT);
messageDispatcher.dispatchMessage(EventType.SLOT_CHANGED, instantiationManager.getComponentTypeSlot(),
instantiationManager.getFirstControlPoint());
@@ -2327,6 +2329,8 @@ public class Presenter implements IPlugInPort {
Collection<IDIYComponent<?>> components = blocks.get(blockName);
if (components == null)
throw new InvalidBlockException();
// clear potential control point every time!
instantiationManager.setPotentialControlPoint(null);
// clone components
List<IDIYComponent<?>> clones = new ArrayList<IDIYComponent<?>>();
List<IDIYComponent<?>> testComponents = new ArrayList<IDIYComponent<?>>(currentProject.getComponents());
@@ -2341,7 +2345,7 @@ public class Presenter implements IPlugInPort {
LOG.error("Could not clone component: " + c);
}
// paste them to the project
pasteComponents(clones);
pasteComponents(clones, true);
} else
throw new InvalidBlockException();
}