diff --git a/ diy-layout-creator --username bancika@gmail.com/diylc-core/library/main.jar b/ diy-layout-creator --username bancika@gmail.com/diylc-core/library/main.jar index 973ca445..e1301278 100644 Binary files a/ diy-layout-creator --username bancika@gmail.com/diylc-core/library/main.jar and b/ diy-layout-creator --username bancika@gmail.com/diylc-core/library/main.jar differ diff --git a/ diy-layout-creator --username bancika@gmail.com/diylc-core/src/org/diylc/presenter/DrawingManager.java b/ diy-layout-creator --username bancika@gmail.com/diylc-core/src/org/diylc/presenter/DrawingManager.java index f39ff0f2..b0050e30 100644 --- a/ diy-layout-creator --username bancika@gmail.com/diylc-core/src/org/diylc/presenter/DrawingManager.java +++ b/ diy-layout-creator --username bancika@gmail.com/diylc-core/src/org/diylc/presenter/DrawingManager.java @@ -51,8 +51,8 @@ public class DrawingManager { public static Color CONTROL_POINT_COLOR = Color.blue; public static Color SELECTED_CONTROL_POINT_COLOR = Color.green; - private Theme theme = (Theme) ConfigurationManager.getInstance().readObject( - IPlugInPort.THEME_KEY, Constants.DEFAULT_THEME); + private Theme theme = (Theme) ConfigurationManager.getInstance() + .readObject(IPlugInPort.THEME_KEY, Constants.DEFAULT_THEME); // Keeps Area object of each drawn component. private Map, Area> componentAreaMap; @@ -60,8 +60,10 @@ public class DrawingManager { // determine which components are invalidated when they are not in the map. private Map, ComponentState> lastDrawnStateMap; - private Composite slotComposite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.3f); - private Composite lockedComposite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.3f); + private Composite slotComposite = AlphaComposite.getInstance( + AlphaComposite.SRC_OVER, 0.3f); + private Composite lockedComposite = AlphaComposite.getInstance( + AlphaComposite.SRC_OVER, 0.3f); private List> failedComponents = new ArrayList>(); private double zoomLevel = 1d;// ConfigurationManager.getInstance().readDouble(ZOOM_KEY, @@ -76,7 +78,8 @@ public class DrawingManager { this.messageDispatcher = messageDispatcher; componentAreaMap = new HashMap, Area>(); lastDrawnStateMap = new HashMap, ComponentState>(); - String debugComponentAreasStr = System.getProperty(DEBUG_COMPONENT_AREAS); + String debugComponentAreasStr = System + .getProperty(DEBUG_COMPONENT_AREAS); debugComponentAreas = debugComponentAreasStr != null && debugComponentAreasStr.equalsIgnoreCase("true"); } @@ -99,10 +102,12 @@ public class DrawingManager { * @return */ public List> drawProject(Graphics2D g2d, Project project, - Set drawOptions, IComponentFiler filter, Rectangle selectionRect, - List> selectedComponents, Set> lockedComponents, - Set> groupedComponents, List controlPointSlot, - IDIYComponent componentSlot, boolean dragInProgress) { + Set drawOptions, IComponentFiler filter, + Rectangle selectionRect, List> selectedComponents, + Set> lockedComponents, + Set> groupedComponents, + List controlPointSlot, List> componentSlot, + boolean dragInProgress) { failedComponents.clear(); if (project == null) { return failedComponents; @@ -110,9 +115,8 @@ public class DrawingManager { G2DWrapper g2dWrapper = new G2DWrapper(g2d); if (drawOptions.contains(DrawOption.ANTIALIASING)) { - g2d - .setRenderingHint(RenderingHints.KEY_ANTIALIASING, - RenderingHints.VALUE_ANTIALIAS_ON); + g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, + RenderingHints.VALUE_ANTIALIAS_ON); g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); } else { @@ -121,25 +125,29 @@ public class DrawingManager { g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF); } - if (ConfigurationManager.getInstance() - .readBoolean(IPlugInPort.HI_QUALITY_RENDER_KEY, false)) { + if (ConfigurationManager.getInstance().readBoolean( + IPlugInPort.HI_QUALITY_RENDER_KEY, false)) { g2d.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY); g2d.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY); - g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); - g2d.setRenderingHint(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_ENABLE); + g2d.setRenderingHint(RenderingHints.KEY_RENDERING, + RenderingHints.VALUE_RENDER_QUALITY); + g2d.setRenderingHint(RenderingHints.KEY_DITHERING, + RenderingHints.VALUE_DITHER_ENABLE); g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); -// g2d.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, -// RenderingHints.VALUE_STROKE_PURE); + // g2d.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, + // RenderingHints.VALUE_STROKE_PURE); } else { g2d.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_SPEED); g2d.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_SPEED); - g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_SPEED); - g2d.setRenderingHint(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_DISABLE); + g2d.setRenderingHint(RenderingHints.KEY_RENDERING, + RenderingHints.VALUE_RENDER_SPEED); + g2d.setRenderingHint(RenderingHints.KEY_DITHERING, + RenderingHints.VALUE_DITHER_DISABLE); g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR); } @@ -162,12 +170,14 @@ public class DrawingManager { if (drawOptions.contains(DrawOption.GRID) && gridType != GridType.NONE) { double zoomStep = project.getGridSpacing().convertToPixels() * zoom; if (gridType == GridType.CROSSHAIR) { - g2d.setStroke(new BasicStroke(1f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, - 10f, new float[] { (float) zoomStep / 2, (float) zoomStep / 2 }, + g2d.setStroke(new BasicStroke(1f, BasicStroke.CAP_BUTT, + BasicStroke.JOIN_MITER, 10f, new float[] { + (float) zoomStep / 2, (float) zoomStep / 2 }, (float) zoomStep / 4)); } else if (gridType == GridType.DOT) { - g2d.setStroke(new BasicStroke(1f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, - 10f, new float[] { 1f, (float) zoomStep - 1 }, 0f)); + g2d.setStroke(new BasicStroke(1f, BasicStroke.CAP_BUTT, + BasicStroke.JOIN_MITER, 10f, new float[] { 1f, + (float) zoomStep - 1 }, 0f)); } g2dWrapper.setColor(theme.getGridColor()); @@ -207,7 +217,7 @@ public class DrawingManager { // Do not track the area if component is not invalidated and was // drawn in the same state. boolean trackArea = lastDrawnStateMap.get(component) != state; - + synchronized (g2d) { g2dWrapper.startedDrawingComponent(); if (!trackArea) { @@ -219,8 +229,9 @@ public class DrawingManager { } // Draw the component through the g2dWrapper. try { - component.draw(g2dWrapper, state, - drawOptions.contains(DrawOption.OUTLINE_MODE), project, g2dWrapper); + component.draw(g2dWrapper, state, drawOptions + .contains(DrawOption.OUTLINE_MODE), project, + g2dWrapper); } catch (Exception e) { LOG.error("Error drawing " + component.getName(), e); failedComponents.add(component); @@ -250,8 +261,9 @@ public class DrawingManager { g2dWrapper.setColor(CONTROL_POINT_COLOR); Point controlPoint = component.getControlPoint(i); int pointSize = CONTROL_POINT_SIZE - 2; - g2dWrapper.fillOval(controlPoint.x - pointSize / 2, controlPoint.y - - pointSize / 2, pointSize, pointSize); + g2dWrapper.fillOval(controlPoint.x - pointSize / 2, + controlPoint.y - pointSize / 2, pointSize, + pointSize); } } } @@ -266,13 +278,16 @@ public class DrawingManager { Point controlPoint = component.getControlPoint(i); int pointSize = CONTROL_POINT_SIZE; - g2dWrapper.setColor(SELECTED_CONTROL_POINT_COLOR.darker()); - g2dWrapper.fillOval(controlPoint.x - pointSize / 2, controlPoint.y - - pointSize / 2, pointSize, pointSize); + g2dWrapper.setColor(SELECTED_CONTROL_POINT_COLOR + .darker()); + g2dWrapper.fillOval(controlPoint.x - pointSize / 2, + controlPoint.y - pointSize / 2, pointSize, + pointSize); g2dWrapper.setColor(SELECTED_CONTROL_POINT_COLOR); - g2dWrapper.fillOval(controlPoint.x - CONTROL_POINT_SIZE / 2 + 1, - controlPoint.y - CONTROL_POINT_SIZE / 2 + 1, - CONTROL_POINT_SIZE - 2, CONTROL_POINT_SIZE - 2); + g2dWrapper.fillOval(controlPoint.x - CONTROL_POINT_SIZE + / 2 + 1, controlPoint.y - CONTROL_POINT_SIZE + / 2 + 1, CONTROL_POINT_SIZE - 2, + CONTROL_POINT_SIZE - 2); } } } @@ -282,12 +297,17 @@ public class DrawingManager { if (componentSlot != null) { g2dWrapper.startedDrawingComponent(); g2dWrapper.setComposite(slotComposite); - try { - componentSlot.draw(g2dWrapper, ComponentState.NORMAL, drawOptions - .contains(DrawOption.OUTLINE_MODE), project, g2dWrapper); - } catch (Exception e) { - LOG.error("Error drawing " + componentSlot.getName(), e); - failedComponents.add(componentSlot); + for (IDIYComponent component : componentSlot) { + try { + + component.draw(g2dWrapper, ComponentState.NORMAL, + drawOptions.contains(DrawOption.OUTLINE_MODE), + project, g2dWrapper); + + } catch (Exception e) { + LOG.error("Error drawing " + component.getName(), e); + failedComponents.add(component); + } } g2dWrapper.finishedDrawingComponent(); } @@ -297,12 +317,13 @@ public class DrawingManager { for (Point point : controlPointSlot) { if (point != null) { g2dWrapper.setColor(SELECTED_CONTROL_POINT_COLOR.darker()); - g2dWrapper.fillOval(point.x - CONTROL_POINT_SIZE / 2, point.y - - CONTROL_POINT_SIZE / 2, CONTROL_POINT_SIZE, CONTROL_POINT_SIZE); + g2dWrapper.fillOval(point.x - CONTROL_POINT_SIZE / 2, + point.y - CONTROL_POINT_SIZE / 2, + CONTROL_POINT_SIZE, CONTROL_POINT_SIZE); g2dWrapper.setColor(SELECTED_CONTROL_POINT_COLOR); - g2dWrapper.fillOval(point.x - CONTROL_POINT_SIZE / 2 + 1, point.y - - CONTROL_POINT_SIZE / 2 + 1, CONTROL_POINT_SIZE - 2, - CONTROL_POINT_SIZE - 2); + g2dWrapper.fillOval(point.x - CONTROL_POINT_SIZE / 2 + 1, + point.y - CONTROL_POINT_SIZE / 2 + 1, + CONTROL_POINT_SIZE - 2, CONTROL_POINT_SIZE - 2); } } } @@ -316,7 +337,8 @@ public class DrawingManager { // } // At the end draw selection rectangle if needed. - if (drawOptions.contains(DrawOption.SELECTION) && (selectionRect != null)) { + if (drawOptions.contains(DrawOption.SELECTION) + && (selectionRect != null)) { g2d.setColor(Color.white); g2d.draw(selectionRect); g2d.setColor(Color.black); @@ -371,7 +393,8 @@ public class DrawingManager { return components; } - public Dimension getCanvasDimensions(Project project, Double zoomLevel, boolean useZoom) { + public Dimension getCanvasDimensions(Project project, Double zoomLevel, + boolean useZoom) { double width = project.getWidth().convertToPixels(); double height = project.getHeight().convertToPixels(); if (useZoom) { @@ -395,7 +418,8 @@ public class DrawingManager { public void setTheme(Theme theme) { this.theme = theme; - ConfigurationManager.getInstance().writeValue(IPlugInPort.THEME_KEY, theme); + ConfigurationManager.getInstance().writeValue(IPlugInPort.THEME_KEY, + theme); messageDispatcher.dispatchMessage(EventType.REPAINT); } } diff --git a/ diy-layout-creator --username bancika@gmail.com/diylc-core/src/org/diylc/presenter/InstantiationManager.java b/ diy-layout-creator --username bancika@gmail.com/diylc-core/src/org/diylc/presenter/InstantiationManager.java index c55eb0f7..b92e11ab 100644 --- a/ diy-layout-creator --username bancika@gmail.com/diylc-core/src/org/diylc/presenter/InstantiationManager.java +++ b/ diy-layout-creator --username bancika@gmail.com/diylc-core/src/org/diylc/presenter/InstantiationManager.java @@ -15,6 +15,7 @@ import org.diylc.common.IPlugInPort; import org.diylc.common.Orientation; import org.diylc.common.OrientationHV; import org.diylc.common.PropertyWrapper; +import org.diylc.core.CreationMethod; import org.diylc.core.IDIYComponent; import org.diylc.core.Project; import org.diylc.core.Template; @@ -34,10 +35,15 @@ public class InstantiationManager { private ComponentType componentTypeSlot; private Template template; - private IDIYComponent componentSlot; + private List> componentSlot; private Point firstControlPoint; private Point potentialControlPoint; + private static final ComponentType clipboardType = new ComponentType( + "Clipboard contents", "Components from the clipboard", + CreationMethod.SINGLE_CLICK, "Multi", "", "", null, null, 0, false, + false, null, false); + public InstantiationManager() { } @@ -49,7 +55,7 @@ public class InstantiationManager { return template; } - public IDIYComponent getComponentSlot() { + public List> getComponentSlot() { return componentSlot; } @@ -90,8 +96,8 @@ public class InstantiationManager { // Set the other control point to the same location, we'll // move it later when mouse moves. - componentSlot.setControlPoint(firstControlPoint, 0); - componentSlot.setControlPoint(firstControlPoint, 1); + componentSlot.get(0).setControlPoint(firstControlPoint, 0); + componentSlot.get(0).setControlPoint(firstControlPoint, 1); } /** @@ -103,17 +109,82 @@ public class InstantiationManager { public boolean updatePointByPoint(Point scaledPoint) { boolean changeMade = !scaledPoint.equals(potentialControlPoint); potentialControlPoint = scaledPoint; - if (componentSlot != null) { - componentSlot.setControlPoint(scaledPoint, 1); + if (componentSlot != null && !componentSlot.isEmpty()) { + componentSlot.get(0).setControlPoint(scaledPoint, 1); } return changeMade; } + public void pasteComponents(List> components, + Point scaledPoint, boolean snapToGrid, Size gridSpacing) { + // Adjust location of components so they are centered under the mouse + // cursor + int minX = Integer.MAX_VALUE; + int maxX = Integer.MIN_VALUE; + int minY = Integer.MAX_VALUE; + int maxY = Integer.MIN_VALUE; + for (IDIYComponent component : components) { + for (int i = 0; i < component.getControlPointCount(); i++) { + Point p = component.getControlPoint(i); + if (p.x > maxX) { + maxX = p.x; + } + if (p.x < minX) { + minX = p.x; + } + if (p.y > maxY) { + maxY = p.y; + } + if (p.y < minY) { + minY = p.y; + } + } + } + int x = (minX + maxX) / 2; + int y = (minY + maxY) / 2; + if (snapToGrid) { + x = CalcUtils.roundToGrid(x, gridSpacing); + x = CalcUtils.roundToGrid(x, gridSpacing); + } + for (IDIYComponent component : components) { + for (int i = 0; i < component.getControlPointCount(); i++) { + Point p = component.getControlPoint(i); + p.translate(-x, -y); + component.setControlPoint(p, i); + } + } + + // Update component slot + this.componentSlot = new ArrayList>(components); + + // Update the component type slot so the app knows that something's + // being instantiated. + this.componentTypeSlot = clipboardType; + + if (snapToGrid) { + scaledPoint = new Point(scaledPoint); + CalcUtils.snapPointToGrid(scaledPoint, gridSpacing); + } + // Update the location according to mouse location + updateSingleClick(scaledPoint, snapToGrid, gridSpacing); + } + + /** + * Updates location of component slot based on the new mouse location. + * + * @param scaledPoint + * @param snapToGrid + * @param gridSpacing + * @return true if we need to refresh the canvas + */ public boolean updateSingleClick(Point scaledPoint, boolean snapToGrid, Size gridSpacing) { if (potentialControlPoint == null) { potentialControlPoint = new Point(0, 0); } + if (scaledPoint == null) { + scaledPoint = new Point(0, 0); + } int dx = scaledPoint.x - potentialControlPoint.x; int dy = scaledPoint.y - potentialControlPoint.y; if (snapToGrid) { @@ -129,19 +200,21 @@ public class InstantiationManager { LOG.error("Component slot should not be null!"); } else { Point p = new Point(); - for (int i = 0; i < componentSlot.getControlPointCount(); i++) { - p.setLocation(componentSlot.getControlPoint(i)); - p.translate(dx, dy); - componentSlot.setControlPoint(p, i); + for (IDIYComponent component : componentSlot) { + for (int i = 0; i < component.getControlPointCount(); i++) { + p.setLocation(component.getControlPoint(i)); + p.translate(dx, dy); + component.setControlPoint(p, i); + } } } return true; } @SuppressWarnings("unchecked") - public IDIYComponent instantiateComponent(ComponentType componentType, - Template template, Point point, Project currentProject) - throws Exception { + public List> instantiateComponent( + ComponentType componentType, Template template, Point point, + Project currentProject) throws Exception { LOG.info("Instatiating component of type: " + componentType.getInstanceClass().getName()); @@ -182,7 +255,9 @@ public class InstantiationManager { IPlugInPort.RECENT_COMPONENTS_KEY, recentComponentTypes); } - return component; + List> list = new ArrayList>(); + list.add(component); + return list; } public String createUniqueName(ComponentType componentType, diff --git a/ diy-layout-creator --username bancika@gmail.com/diylc-core/src/org/diylc/presenter/Presenter.java b/ diy-layout-creator --username bancika@gmail.com/diylc-core/src/org/diylc/presenter/Presenter.java index 7b7e745d..8bf68d0c 100644 --- a/ diy-layout-creator --username bancika@gmail.com/diylc-core/src/org/diylc/presenter/Presenter.java +++ b/ diy-layout-creator --username bancika@gmail.com/diylc-core/src/org/diylc/presenter/Presenter.java @@ -57,7 +57,7 @@ public class Presenter implements IPlugInPort { private static final Logger LOG = Logger.getLogger(Presenter.class); public static final VersionNumber CURRENT_VERSION = new VersionNumber(3, - 21, 0); + 22, 0); public static final String DEFAULTS_KEY_PREFIX = "default."; public static final List> EMPTY_SELECTION = Collections @@ -98,6 +98,7 @@ public class Presenter implements IPlugInPort { private Point previousDragPoint = null; private Project preDragProject = null; private int dragAction; + private Point previousScaledPoint; public Presenter(IView view) { super(); @@ -361,7 +362,7 @@ public class Presenter implements IPlugInPort { } // Don't draw the component in the slot if both control points // match. - IDIYComponent componentSlotToDraw; + List> componentSlotToDraw; if (instantiationManager.getFirstControlPoint() != null && instantiationManager.getPotentialControlPoint() != null && instantiationManager.getFirstControlPoint().equals( @@ -446,17 +447,19 @@ public class Presenter implements IPlugInPort { CalcUtils.snapPointToGrid(scaledPoint, currentProject.getGridSpacing()); } - IDIYComponent component = instantiationManager + List> componentSlot = instantiationManager .getComponentSlot(); - addComponent(component, componentTypeSlot, true); + List> newSelection = new ArrayList>(); + for (IDIYComponent component : componentSlot) { + addComponent(component, componentTypeSlot, true); + newSelection.add(component); + } // Select the new component // messageDispatcher.dispatchMessage(EventType.SELECTION_CHANGED, // selectedComponents); // messageDispatcher.dispatchMessage(EventType.SELECTION_SIZE_CHANGED, // calculateSelectionDimension()); messageDispatcher.dispatchMessage(EventType.REPAINT); - List> newSelection = new ArrayList>(); - newSelection.add(component); updateSelection(newSelection); } catch (Exception e) { LOG.error("Error instatiating component of type: " @@ -501,15 +504,18 @@ public class Presenter implements IPlugInPort { } else { // On the second click, add the component to the // project. - IDIYComponent componentSlot = instantiationManager + List> componentSlot = instantiationManager .getComponentSlot(); - componentSlot.setControlPoint(scaledPoint, 1); - addComponent(componentSlot, componentTypeSlot, true); - // Select the new component if it's not locked. + componentSlot.get(0).setControlPoint(scaledPoint, 1); List> newSelection = new ArrayList>(); - if (!isComponentLocked(componentSlot)) { - newSelection.add(componentSlot); + for (IDIYComponent component : componentSlot) { + addComponent(component, componentTypeSlot, true); + // Select the new component if it's not locked. + if (!isComponentLocked(component)) { + newSelection.add(component); + } } + updateSelection(newSelection); messageDispatcher.dispatchMessage(EventType.REPAINT); @@ -681,21 +687,23 @@ public class Presenter implements IPlugInPort { public void mouseMoved(Point point, boolean ctrlDown, boolean shiftDown, boolean altDown) { Map, Set> components = new HashMap, Set>(); - Point scaledPoint = scalePoint(point); + this.previousScaledPoint = scalePoint(point); if (instantiationManager.getComponentTypeSlot() != null) { if (isSnapToGrid()) { - CalcUtils.snapPointToGrid(scaledPoint, currentProject + CalcUtils.snapPointToGrid(previousScaledPoint, currentProject .getGridSpacing()); } boolean refresh = false; switch (instantiationManager.getComponentTypeSlot() .getCreationMethod()) { case POINT_BY_POINT: - refresh = instantiationManager.updatePointByPoint(scaledPoint); + refresh = instantiationManager + .updatePointByPoint(previousScaledPoint); break; case SINGLE_CLICK: - refresh = instantiationManager.updateSingleClick(scaledPoint, - isSnapToGrid(), currentProject.getGridSpacing()); + refresh = instantiationManager.updateSingleClick( + previousScaledPoint, isSnapToGrid(), currentProject + .getGridSpacing()); break; } if (refresh) { @@ -718,7 +726,7 @@ public class Presenter implements IPlugInPort { && componentType.isStretchable() && findAllGroupedComponents(component).size() == 1) { try { - if (scaledPoint.distance(controlPoint) < DrawingManager.CONTROL_POINT_SIZE) { + if (previousScaledPoint.distance(controlPoint) < DrawingManager.CONTROL_POINT_SIZE) { Set indices = new HashSet(); if (componentType.isStretchable()) { indices.add(pointIndex); @@ -741,7 +749,8 @@ public class Presenter implements IPlugInPort { } } - messageDispatcher.dispatchMessage(EventType.MOUSE_MOVED, scaledPoint); + messageDispatcher.dispatchMessage(EventType.MOUSE_MOVED, + previousScaledPoint); if (!components.equals(controlPointMap)) { controlPointMap = components; @@ -1105,30 +1114,14 @@ public class Presenter implements IPlugInPort { @Override public void pasteComponents(List> components) { - LOG.info(String.format("addComponents(%s)", components)); - Project oldProject = currentProject.clone(); - for (IDIYComponent component : components) { - for (int i = 0; i < component.getControlPointCount(); i++) { - Point point = new Point(component.getControlPoint(i)); - point.translate((int) currentProject.getGridSpacing() - .convertToPixels(), (int) currentProject - .getGridSpacing().convertToPixels()); - component.setControlPoint(point, i); - } - component.setName(instantiationManager.createUniqueName( - ComponentProcessor.getInstance().extractComponentTypeFrom( - (Class>) component - .getClass()), currentProject)); - addComponent(component, ComponentProcessor.getInstance() - .extractComponentTypeFrom( - (Class>) component - .getClass()), false); - } - messageDispatcher.dispatchMessage(EventType.PROJECT_MODIFIED, - oldProject, currentProject.clone(), "Add"); - projectFileManager.notifyFileChange(); - updateSelection(new ArrayList>(components)); + LOG.info(String.format("pasteComponents(%s)", components)); + instantiationManager.pasteComponents(components, + this.previousScaledPoint, isSnapToGrid(), currentProject + .getGridSpacing()); messageDispatcher.dispatchMessage(EventType.REPAINT); + messageDispatcher.dispatchMessage(EventType.SLOT_CHANGED, + instantiationManager.getComponentTypeSlot(), + instantiationManager.getFirstControlPoint()); } @Override @@ -1609,8 +1602,9 @@ public class Presenter implements IPlugInPort { if (component.isControlPointSticky(i)) { try { IDIYComponent pad = instantiationManager - .instantiateComponent(padType, null, component - .getControlPoint(i), currentProject); + .instantiateComponent(padType, null, + component.getControlPoint(i), + currentProject).get(0); pad.setControlPoint(component.getControlPoint(i), 0); addComponent(pad, padType, false); } catch (Exception e) {