added nudge

fixed ctrl/meta handling
This commit is contained in:
bancika
2017-04-24 12:59:56 +02:00
parent 217c0b1b67
commit cd5d5011c6
17 changed files with 220 additions and 51 deletions
@@ -30,14 +30,15 @@ import org.diylc.core.Theme;
* @see IMessageListener
* @see EventType
*/
public interface IPlugInPort extends ISelectionProcessor, IMouseProcessor, IKeyProcessor, ITemplateProcessor, IBlockProcessor {
public interface IPlugInPort extends ISelectionProcessor, IMouseProcessor, IKeyProcessor, ITemplateProcessor,
IBlockProcessor {
public static final String ANTI_ALIASING_KEY = "antiAliasing";
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";
public static final String SNAP_TO_GRID_KEY = "snapToGrid";
public static final String CONTINUOUS_CREATION_KEY = "continuousCreation";
public static final String AUTO_EDIT_KEY = "autoEdit";
public static final String ABNORMAL_EXIT_KEY = "abnormalExit";
@@ -58,7 +59,7 @@ public interface IPlugInPort extends ISelectionProcessor, IMouseProcessor, IKeyP
public static final int NOBUTTON = 0;
public static final int BUTTON1 = 1;
public static final int BUTTON2 = 2;
public static final int BUTTON3 = 3;
public static final int BUTTON3 = 3;
/**
* Returns size of the canvas that takes project dimensions into account as well as zoom level.
@@ -198,10 +199,11 @@ public interface IPlugInPort extends ISelectionProcessor, IMouseProcessor, IKeyP
/**
* Sets default value for the specified property name for projects.
*
* @param clazz class to set defaults to
* @param propertyName display name for property
* @param value new default value, must not be null
*/
void setProjectDefaultPropertyValue(String propertyName, Object value);
void setDefaultPropertyValue(Class<?> clazz, String propertyName, Object value);
/**
* @return a list of properties that are mutual for all the selected components. Resulting list
@@ -214,15 +216,18 @@ public interface IPlugInPort extends ISelectionProcessor, IMouseProcessor, IKeyP
/**
* @return a list of editable properties of the current project.
*
* @param obj
*/
List<PropertyWrapper> getProjectProperties();
List<PropertyWrapper> getProperties(Object obj);
/**
* Applies specified properties to the current project.
*
* @param obj
* @param properties
*/
void applyPropertiesToProject(List<PropertyWrapper> properties);
void applyProperties(Object obj, List<PropertyWrapper> properties);
/**
* Gets the current new component slot.
@@ -253,10 +258,10 @@ public interface IPlugInPort extends ISelectionProcessor, IMouseProcessor, IKeyP
* @param locked
*/
void setLayerLocked(int layerZOrder, boolean locked);
/**
* Shows or hides the specified layer. All components within +- 0.5 range will be affected by
* the change as well.
* Shows or hides the specified layer. All components within +- 0.5 range will be affected by the
* change as well.
*
* @param layerZOrder
* @param visible
@@ -7,6 +7,7 @@ import java.util.List;
import org.diylc.core.ExpansionMode;
import org.diylc.core.IDIYComponent;
import org.diylc.core.measures.Size;
public interface ISelectionProcessor {
@@ -81,4 +82,13 @@ public interface ISelectionProcessor {
* @return
*/
Rectangle2D getSelectionBounds();
/**
* Moves selection for the specified offset.
*
* @param xOffset
* @param yOffset
* @param affectStuckComponents
*/
void nudgeSelection(Size xOffset, Size yOffset, boolean affectStuckComponents);
}
@@ -0,0 +1,37 @@
package org.diylc.core.measures;
import org.diylc.core.annotations.EditableProperty;
public class Nudge {
private Size xOffset;
private Size yOffset;
private boolean affectStuckComponents;
@EditableProperty(name = "X-axis", sortOrder = 1)
public Size getxOffset() {
return xOffset;
}
public void setxOffset(Size xOffset) {
this.xOffset = xOffset;
}
@EditableProperty(name = "Y-axis", sortOrder = 2)
public Size getyOffset() {
return yOffset;
}
public void setyOffset(Size yOffset) {
this.yOffset = yOffset;
}
@EditableProperty(name = "Include stuck", sortOrder = 10)
public boolean getAffectStuckComponents() {
return affectStuckComponents;
}
public void setAffectStuckComponents(boolean affectStuckComponents) {
this.affectStuckComponents = affectStuckComponents;
}
}
@@ -51,6 +51,7 @@ import org.diylc.core.Project;
import org.diylc.core.Template;
import org.diylc.core.Theme;
import org.diylc.core.annotations.IAutoCreator;
import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit;
import org.diylc.utils.Constants;
@@ -854,6 +855,42 @@ public class Presenter implements IPlugInPort {
return totalArea.getBounds2D();
}
@Override
public void nudgeSelection(Size xOffset, Size yOffset, boolean affectStuckComponents) {
if (selectedComponents == null || selectedComponents.isEmpty())
return;
LOG.debug(String.format("nudgeSelection(%s, %s)", xOffset, yOffset));
Map<IDIYComponent<?>, Set<Integer>> controlPointMap = new HashMap<IDIYComponent<?>, Set<Integer>>();
// If there aren't any control points, try to add all the selected
// components with all their control points. That will allow the
// user to drag the whole components.
for (IDIYComponent<?> c : selectedComponents) {
Set<Integer> pointIndices = new HashSet<Integer>();
if (c.getControlPointCount() > 0) {
for (int i = 0; i < c.getControlPointCount(); i++) {
pointIndices.add(i);
}
controlPointMap.put(c, pointIndices);
}
}
if (controlPointMap.isEmpty()) {
return;
}
if (affectStuckComponents) {
includeStuckComponents(controlPointMap);
}
int dx = (int) xOffset.convertToPixels();
int dy = (int) yOffset.convertToPixels();
Project oldProject = currentProject.clone();
moveComponents(controlPointMap, dx, dy, false);
messageDispatcher.dispatchMessage(EventType.PROJECT_MODIFIED, oldProject, currentProject.clone(), "Move Selection");
messageDispatcher.dispatchMessage(EventType.REPAINT);
}
@Override
public VersionNumber getCurrentVersionNumber() {
return CURRENT_VERSION;
@@ -1403,10 +1440,10 @@ public class Presenter implements IPlugInPort {
}
@Override
public void setProjectDefaultPropertyValue(String propertyName, Object value) {
LOG.info(String.format("setProjectDefaultPropertyValue(%s, %s)", propertyName, value));
public void setDefaultPropertyValue(Class<?> clazz, String propertyName, Object value) {
LOG.info(String.format("setProjectDefaultPropertyValue(%s, %s, %s)", clazz.getName(), propertyName, value));
LOG.debug("Default property value set for " + Project.class.getName() + ":" + propertyName);
ConfigurationManager.getInstance().writeValue(DEFAULTS_KEY_PREFIX + Project.class.getName() + ":" + propertyName,
ConfigurationManager.getInstance().writeValue(DEFAULTS_KEY_PREFIX + clazz.getName() + ":" + propertyName,
value);
}
@@ -1849,14 +1886,14 @@ public class Presenter implements IPlugInPort {
}
@Override
public List<PropertyWrapper> getProjectProperties() {
List<PropertyWrapper> properties = ComponentProcessor.getInstance().extractProperties(Project.class);
public List<PropertyWrapper> getProperties(Object object) {
List<PropertyWrapper> properties = ComponentProcessor.getInstance().extractProperties(object.getClass());
try {
for (PropertyWrapper property : properties) {
property.readFrom(currentProject);
property.readFrom(object);
}
} catch (Exception e) {
LOG.error("Could not get project properties", e);
LOG.error("Could not get object properties", e);
return null;
}
Collections.sort(properties, ComparatorFactory.getInstance().getDefaultPropertyComparator());
@@ -1864,16 +1901,16 @@ public class Presenter implements IPlugInPort {
}
@Override
public void applyPropertiesToProject(List<PropertyWrapper> properties) {
LOG.debug(String.format("applyPropertiesToProject(%s)", properties));
public void applyProperties(Object obj, List<PropertyWrapper> properties) {
LOG.debug(String.format("applyProperties(%s, %s)", obj, properties));
Project oldProject = currentProject.clone();
try {
for (PropertyWrapper property : properties) {
property.writeTo(currentProject);
property.writeTo(obj);
}
} catch (Exception e) {
LOG.error("Could not apply project properties", e);
view.showMessage("Could not apply changes to the project. Check the log for details.", "Error",
LOG.error("Could not apply properties", e);
view.showMessage("Could not apply changes. Check the log for details.", "Error",
IView.ERROR_MESSAGE);
} finally {
// Notify the listeners.