configurable snap to grid

This commit is contained in:
bancika
2011-02-18 22:17:03 +00:00
parent 746aadd8a2
commit abdf02eac8
5 changed files with 45 additions and 16 deletions
@@ -36,6 +36,8 @@ public interface IPlugInPort {
public static final String HI_QUALITY_RENDER_KEY = "hiQualityRender";
public static final String EXPORT_GRID_KEY = "exportGrid";
public static final String STICKY_POINTS_KEY = "stickyPoints";
public static final String METRIC_KEY = "metric";
public static final String SNAP_TO_GRID_KEY = "snapToGrid";
/**
* Returns size of the canvas that takes project dimensions into account as
@@ -53,7 +53,6 @@ public class Presenter implements IPlugInPort {
public static final VersionNumber CURRENT_VERSION = new VersionNumber(3, 0, 7);
public static final String DEFAULTS_KEY_PREFIX = "default.";
public static final String METRIC_KEY = "metric";
public static final List<IDIYComponent<?>> EMPTY_SELECTION = Collections.emptyList();
@@ -92,8 +91,6 @@ public class Presenter implements IPlugInPort {
private Point previousDragPoint = null;
private Project preDragProject = null;
private boolean snapToGrid = true;
public Presenter(IView view) {
super();
this.view = view;
@@ -361,7 +358,8 @@ public class Presenter implements IPlugInPort {
switch (componentTypeSlot.getCreationMethod()) {
case SINGLE_CLICK:
try {
if (snapToGrid) {
if (ConfigurationManager.getInstance().readBoolean(
IPlugInPort.SNAP_TO_GRID_KEY, true)) {
CalcUtils.snapPointToGrid(scaledPoint, currentProject.getGridSpacing());
}
IDIYComponent<?> component = instantiationManager.instantiateComponent(
@@ -385,7 +383,8 @@ public class Presenter implements IPlugInPort {
case POINT_BY_POINT:
// First click is just to set the controlPointSlot and
// componentSlot.
if (snapToGrid) {
if (ConfigurationManager.getInstance().readBoolean(IPlugInPort.SNAP_TO_GRID_KEY,
true)) {
CalcUtils.snapPointToGrid(scaledPoint, currentProject.getGridSpacing());
}
if (instantiationManager.getComponentSlot() == null) {
@@ -460,7 +459,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 (snapToGrid) {
if (ConfigurationManager.getInstance().readBoolean(IPlugInPort.SNAP_TO_GRID_KEY, true)) {
CalcUtils.snapPointToGrid(scaledPoint, currentProject.getGridSpacing());
}
boolean refresh = false;
@@ -469,7 +468,8 @@ public class Presenter implements IPlugInPort {
refresh = instantiationManager.updatePointByPoint(scaledPoint);
break;
case SINGLE_CLICK:
refresh = instantiationManager.updateSingleClick(scaledPoint, snapToGrid,
refresh = instantiationManager.updateSingleClick(scaledPoint, ConfigurationManager
.getInstance().readBoolean(IPlugInPort.SNAP_TO_GRID_KEY, true),
currentProject.getGridSpacing());
break;
}
@@ -712,7 +712,8 @@ public class Presenter implements IPlugInPort {
if (isFirst) {
isFirst = false;
controlPoints[index].translate(dx, dy);
if (snapToGrid) {
if (ConfigurationManager.getInstance().readBoolean(
IPlugInPort.SNAP_TO_GRID_KEY, true)) {
CalcUtils.snapPointToGrid(controlPoints[index], currentProject
.getGridSpacing());
}
@@ -46,6 +46,8 @@ public class ConfigPlugin implements IPlugIn {
"Sticky Points", IPlugInPort.STICKY_POINTS_KEY, true), CONFIG_MENU);
swingUI.injectMenuAction(ActionFactory.getInstance().createConfigAction(plugInPort,
"Export Grid", IPlugInPort.EXPORT_GRID_KEY, false), CONFIG_MENU);
swingUI.injectMenuAction(ActionFactory.getInstance().createConfigAction(plugInPort,
"Snap to Grid", IPlugInPort.SNAP_TO_GRID_KEY, true), CONFIG_MENU);
File themeDir = new File("themes");
if (themeDir.exists()) {
XStream xStream = new XStream(new DomDriver());