From 954bf200d20f647cc5c6133c30c0ce9f1e9ef56f Mon Sep 17 00:00:00 2001 From: bancika Date: Thu, 4 Oct 2012 11:14:49 +0000 Subject: [PATCH] copy-paste improvement --- .../diylc-core/library/main.jar | Bin 258232 -> 258232 bytes .../org/diylc/presenter/DrawingManager.java | 122 +++++++++++------- .../diylc/presenter/InstantiationManager.java | 103 +++++++++++++-- .../src/org/diylc/presenter/Presenter.java | 82 ++++++------ 4 files changed, 200 insertions(+), 107 deletions(-) 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 973ca445652556fcf081d87c8fb4a7aca30bc6de..e1301278e49284de08cf23399bbd827a955e3f2f 100644 GIT binary patch delta 2495 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 VJf6@_2HBl_YcD&wb(E} 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) {