mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-10 17:22:09 +10:00
This commit is contained in:
+13
-4
@@ -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;
|
||||
@@ -45,6 +46,9 @@ public interface IPlugInPort {
|
||||
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
|
||||
* well as zoom level. Each dimension is calculated as the product of the
|
||||
@@ -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.
|
||||
*
|
||||
|
||||
+31
-18
@@ -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<IDIYComponent<?>, Set<Integer>> components = new HashMap<IDIYComponent<?>, Set<Integer>>();
|
||||
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<IDIYComponent<?>> components = findComponentsAt(scaledPoint);
|
||||
if (!controlPointMap.isEmpty()) {
|
||||
if (!this.controlPointMap.isEmpty()) {
|
||||
// If we're dragging control points reset selection.
|
||||
updateSelection(new ArrayList<IDIYComponent<?>>(controlPointMap.keySet()));
|
||||
updateSelection(new ArrayList<IDIYComponent<?>>(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) {
|
||||
@@ -666,6 +666,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
|
||||
* the map.
|
||||
@@ -741,6 +747,14 @@ public class Presenter implements IPlugInPort {
|
||||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
if (point == null) {
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user