From 19cfca3df8e67d665698cd72b7a9a7868bb6f365 Mon Sep 17 00:00:00 2001 From: bancika Date: Wed, 8 Feb 2012 04:48:08 +0000 Subject: [PATCH] --- .../src/org/diylc/common/IPlugInPort.java | 17 +++++-- .../src/org/diylc/presenter/Presenter.java | 49 ++++++++++++------- 2 files changed, 44 insertions(+), 22 deletions(-) diff --git a/ diy-layout-creator --username bancika@gmail.com/diylc-core/src/org/diylc/common/IPlugInPort.java b/ diy-layout-creator --username bancika@gmail.com/diylc-core/src/org/diylc/common/IPlugInPort.java index cf962148..c1a75cd3 100644 --- a/ diy-layout-creator --username bancika@gmail.com/diylc-core/src/org/diylc/common/IPlugInPort.java +++ b/ diy-layout-creator --username bancika@gmail.com/diylc-core/src/org/diylc/common/IPlugInPort.java @@ -4,6 +4,7 @@ import java.awt.Cursor; import java.awt.Dimension; import java.awt.Graphics2D; import java.awt.Point; +import java.awt.dnd.DnDConstants; import java.awt.geom.Point2D; import java.util.List; import java.util.Map; @@ -44,6 +45,9 @@ public interface IPlugInPort { public static final String OUTLINE_KEY = "outline"; public static final String THEME_KEY = "theme"; public static final String RECENT_COMPONENTS_KEY = "recentComponents"; + + public static final int DND_TOGGLE_STICKY = 0x1; + public static final int DND_TOGGLE_SNAP = 0x40000000; /** * Returns size of the canvas that takes project dimensions into account as @@ -212,11 +216,9 @@ public interface IPlugInPort { * Note: point coordinates are scaled for zoom factor. * * @param point - * @param ctrlDown - * @param shiftDown - * @param altDown + * @param dragAction */ - void dragStarted(Point point, boolean ctrlDown, boolean shiftDown, boolean altDown); + void dragStarted(Point point, int dragAction); /** * Checks if it's possible to drop over the specified point. @@ -228,6 +230,13 @@ public interface IPlugInPort { */ boolean dragOver(Point point); + /** + * Changes the current drag action during the dragging. + * + * @param dragAction + */ + void dragActionChanged(int dragAction); + /** * Notification that drag has been ended in the specified point. * 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 4dfb8988..6bb48992 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 @@ -5,6 +5,7 @@ import java.awt.Dimension; import java.awt.Graphics2D; import java.awt.Point; import java.awt.Rectangle; +import java.awt.dnd.DnDConstants; import java.awt.geom.Area; import java.awt.geom.Point2D; import java.lang.reflect.Modifier; @@ -93,6 +94,7 @@ public class Presenter implements IPlugInPort { // Previous mouse location, not scaled for zoom factor. private Point previousDragPoint = null; private Project preDragProject = null; + private int dragAction; public Presenter(IView view) { super(); @@ -366,8 +368,7 @@ public class Presenter implements IPlugInPort { switch (componentTypeSlot.getCreationMethod()) { case SINGLE_CLICK: try { - if (ConfigurationManager.getInstance().readBoolean( - IPlugInPort.SNAP_TO_GRID_KEY, true)) { + if (isSnapToGrid()) { CalcUtils.snapPointToGrid(scaledPoint, currentProject.getGridSpacing()); } IDIYComponent component = instantiationManager.instantiateComponent( @@ -401,8 +402,7 @@ public class Presenter implements IPlugInPort { case POINT_BY_POINT: // First click is just to set the controlPointSlot and // componentSlot. - if (ConfigurationManager.getInstance().readBoolean( - IPlugInPort.SNAP_TO_GRID_KEY, true)) { + if (isSnapToGrid()) { CalcUtils.snapPointToGrid(scaledPoint, currentProject.getGridSpacing()); } if (instantiationManager.getComponentSlot() == null) { @@ -517,7 +517,7 @@ public class Presenter implements IPlugInPort { Map, Set> components = new HashMap, Set>(); Point scaledPoint = scalePoint(point); if (instantiationManager.getComponentTypeSlot() != null) { - if (ConfigurationManager.getInstance().readBoolean(IPlugInPort.SNAP_TO_GRID_KEY, true)) { + if (isSnapToGrid()) { CalcUtils.snapPointToGrid(scaledPoint, currentProject.getGridSpacing()); } boolean refresh = false; @@ -526,8 +526,7 @@ public class Presenter implements IPlugInPort { refresh = instantiationManager.updatePointByPoint(scaledPoint); break; case SINGLE_CLICK: - refresh = instantiationManager.updateSingleClick(scaledPoint, ConfigurationManager - .getInstance().readBoolean(IPlugInPort.SNAP_TO_GRID_KEY, true), + refresh = instantiationManager.updateSingleClick(scaledPoint, isSnapToGrid(), currentProject.getGridSpacing()); break; } @@ -601,21 +600,22 @@ public class Presenter implements IPlugInPort { } @Override - public void dragStarted(Point point, boolean ctrlDown, boolean shiftDown, boolean altDown) { - LOG.debug(String.format("dragStarted(%s)", point)); + public void dragStarted(Point point, int dragAction) { + LOG.debug(String.format("dragStarted(%s, %s)", point, dragAction)); if (instantiationManager.getComponentTypeSlot() != null) { LOG.debug("Cannot start drag because a new component is being created."); - mouseClicked(point, ctrlDown, shiftDown, altDown, 1); + mouseClicked(point, dragAction == DnDConstants.ACTION_COPY, dragAction == DnDConstants.ACTION_LINK, dragAction == DnDConstants.ACTION_MOVE, 1); return; } - dragInProgress = true; + this.dragInProgress = true; + this.dragAction = dragAction; preDragProject = cloner.deepClone(currentProject); Point scaledPoint = scalePoint(point); - previousDragPoint = scaledPoint; + this.previousDragPoint = scaledPoint; List> components = findComponentsAt(scaledPoint); - if (!controlPointMap.isEmpty()) { + if (!this.controlPointMap.isEmpty()) { // If we're dragging control points reset selection. - updateSelection(new ArrayList>(controlPointMap.keySet())); + updateSelection(new ArrayList>(this.controlPointMap.keySet())); // messageDispatcher.dispatchMessage(EventType.SELECTION_CHANGED, // selectedComponents); // messageDispatcher.dispatchMessage(EventType.SELECTION_SIZE_CHANGED, @@ -651,13 +651,13 @@ public class Presenter implements IPlugInPort { for (int i = 0; i < c.getControlPointCount(); i++) { pointIndices.add(i); } - controlPointMap.put(c, pointIndices); + this.controlPointMap.put(c, pointIndices); } } // Expand control points to include all stuck components. boolean sticky = ConfigurationManager.getInstance().readBoolean( IPlugInPort.STICKY_POINTS_KEY, true); - if (ctrlDown) { + if (this.dragAction == IPlugInPort.DND_TOGGLE_STICKY) { sticky = !sticky; } if (sticky) { @@ -665,6 +665,12 @@ public class Presenter implements IPlugInPort { } } } + + @Override + public void dragActionChanged(int dragAction) { + LOG.debug("dragActionChanged(" + dragAction + ")"); + this.dragAction = dragAction; + } /** * Finds any components that are stuck to one of the components already in @@ -740,6 +746,14 @@ public class Presenter implements IPlugInPort { LOG.trace("Component count didn't change, done with expanding."); } } + + private boolean isSnapToGrid() { + boolean snapToGrid = ConfigurationManager.getInstance().readBoolean( + IPlugInPort.SNAP_TO_GRID_KEY, true); + if (this.dragAction == IPlugInPort.DND_TOGGLE_SNAP) + snapToGrid = !snapToGrid; + return snapToGrid; + } @Override public boolean dragOver(Point point) { @@ -773,8 +787,7 @@ public class Presenter implements IPlugInPort { isFirst = false; Point testPoint = new Point(controlPoints[index]); testPoint.translate(dx, dy); - if (ConfigurationManager.getInstance().readBoolean( - IPlugInPort.SNAP_TO_GRID_KEY, true)) { + if (isSnapToGrid()) { CalcUtils.snapPointToGrid(testPoint, currentProject .getGridSpacing()); }