copy-paste improvement

This commit is contained in:
bancika
2012-10-04 11:14:49 +00:00
parent 7bf8ff9347
commit 954bf200d2
4 changed files with 200 additions and 107 deletions
@@ -51,8 +51,8 @@ public class DrawingManager {
public static Color CONTROL_POINT_COLOR = Color.blue; public static Color CONTROL_POINT_COLOR = Color.blue;
public static Color SELECTED_CONTROL_POINT_COLOR = Color.green; public static Color SELECTED_CONTROL_POINT_COLOR = Color.green;
private Theme theme = (Theme) ConfigurationManager.getInstance().readObject( private Theme theme = (Theme) ConfigurationManager.getInstance()
IPlugInPort.THEME_KEY, Constants.DEFAULT_THEME); .readObject(IPlugInPort.THEME_KEY, Constants.DEFAULT_THEME);
// Keeps Area object of each drawn component. // Keeps Area object of each drawn component.
private Map<IDIYComponent<?>, Area> componentAreaMap; private Map<IDIYComponent<?>, Area> componentAreaMap;
@@ -60,8 +60,10 @@ public class DrawingManager {
// determine which components are invalidated when they are not in the map. // determine which components are invalidated when they are not in the map.
private Map<IDIYComponent<?>, ComponentState> lastDrawnStateMap; private Map<IDIYComponent<?>, ComponentState> lastDrawnStateMap;
private Composite slotComposite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.3f); private Composite slotComposite = AlphaComposite.getInstance(
private Composite lockedComposite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.3f); AlphaComposite.SRC_OVER, 0.3f);
private Composite lockedComposite = AlphaComposite.getInstance(
AlphaComposite.SRC_OVER, 0.3f);
private List<IDIYComponent<?>> failedComponents = new ArrayList<IDIYComponent<?>>(); private List<IDIYComponent<?>> failedComponents = new ArrayList<IDIYComponent<?>>();
private double zoomLevel = 1d;// ConfigurationManager.getInstance().readDouble(ZOOM_KEY, private double zoomLevel = 1d;// ConfigurationManager.getInstance().readDouble(ZOOM_KEY,
@@ -76,7 +78,8 @@ public class DrawingManager {
this.messageDispatcher = messageDispatcher; this.messageDispatcher = messageDispatcher;
componentAreaMap = new HashMap<IDIYComponent<?>, Area>(); componentAreaMap = new HashMap<IDIYComponent<?>, Area>();
lastDrawnStateMap = new HashMap<IDIYComponent<?>, ComponentState>(); lastDrawnStateMap = new HashMap<IDIYComponent<?>, ComponentState>();
String debugComponentAreasStr = System.getProperty(DEBUG_COMPONENT_AREAS); String debugComponentAreasStr = System
.getProperty(DEBUG_COMPONENT_AREAS);
debugComponentAreas = debugComponentAreasStr != null debugComponentAreas = debugComponentAreasStr != null
&& debugComponentAreasStr.equalsIgnoreCase("true"); && debugComponentAreasStr.equalsIgnoreCase("true");
} }
@@ -99,10 +102,12 @@ public class DrawingManager {
* @return * @return
*/ */
public List<IDIYComponent<?>> drawProject(Graphics2D g2d, Project project, public List<IDIYComponent<?>> drawProject(Graphics2D g2d, Project project,
Set<DrawOption> drawOptions, IComponentFiler filter, Rectangle selectionRect, Set<DrawOption> drawOptions, IComponentFiler filter,
List<IDIYComponent<?>> selectedComponents, Set<IDIYComponent<?>> lockedComponents, Rectangle selectionRect, List<IDIYComponent<?>> selectedComponents,
Set<IDIYComponent<?>> groupedComponents, List<Point> controlPointSlot, Set<IDIYComponent<?>> lockedComponents,
IDIYComponent<?> componentSlot, boolean dragInProgress) { Set<IDIYComponent<?>> groupedComponents,
List<Point> controlPointSlot, List<IDIYComponent<?>> componentSlot,
boolean dragInProgress) {
failedComponents.clear(); failedComponents.clear();
if (project == null) { if (project == null) {
return failedComponents; return failedComponents;
@@ -110,8 +115,7 @@ public class DrawingManager {
G2DWrapper g2dWrapper = new G2DWrapper(g2d); G2DWrapper g2dWrapper = new G2DWrapper(g2d);
if (drawOptions.contains(DrawOption.ANTIALIASING)) { if (drawOptions.contains(DrawOption.ANTIALIASING)) {
g2d g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON); RenderingHints.VALUE_ANTIALIAS_ON);
g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
RenderingHints.VALUE_TEXT_ANTIALIAS_ON); RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
@@ -121,25 +125,29 @@ public class DrawingManager {
g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
RenderingHints.VALUE_TEXT_ANTIALIAS_OFF); RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
} }
if (ConfigurationManager.getInstance() if (ConfigurationManager.getInstance().readBoolean(
.readBoolean(IPlugInPort.HI_QUALITY_RENDER_KEY, false)) { IPlugInPort.HI_QUALITY_RENDER_KEY, false)) {
g2d.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, g2d.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION,
RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY); RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
g2d.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, g2d.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING,
RenderingHints.VALUE_COLOR_RENDER_QUALITY); RenderingHints.VALUE_COLOR_RENDER_QUALITY);
g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); g2d.setRenderingHint(RenderingHints.KEY_RENDERING,
g2d.setRenderingHint(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_ENABLE); RenderingHints.VALUE_RENDER_QUALITY);
g2d.setRenderingHint(RenderingHints.KEY_DITHERING,
RenderingHints.VALUE_DITHER_ENABLE);
g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
RenderingHints.VALUE_INTERPOLATION_BILINEAR); RenderingHints.VALUE_INTERPOLATION_BILINEAR);
// g2d.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, // g2d.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL,
// RenderingHints.VALUE_STROKE_PURE); // RenderingHints.VALUE_STROKE_PURE);
} else { } else {
g2d.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, g2d.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION,
RenderingHints.VALUE_ALPHA_INTERPOLATION_SPEED); RenderingHints.VALUE_ALPHA_INTERPOLATION_SPEED);
g2d.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, g2d.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING,
RenderingHints.VALUE_COLOR_RENDER_SPEED); RenderingHints.VALUE_COLOR_RENDER_SPEED);
g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_SPEED); g2d.setRenderingHint(RenderingHints.KEY_RENDERING,
g2d.setRenderingHint(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_DISABLE); RenderingHints.VALUE_RENDER_SPEED);
g2d.setRenderingHint(RenderingHints.KEY_DITHERING,
RenderingHints.VALUE_DITHER_DISABLE);
g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR); RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);
} }
@@ -162,12 +170,14 @@ public class DrawingManager {
if (drawOptions.contains(DrawOption.GRID) && gridType != GridType.NONE) { if (drawOptions.contains(DrawOption.GRID) && gridType != GridType.NONE) {
double zoomStep = project.getGridSpacing().convertToPixels() * zoom; double zoomStep = project.getGridSpacing().convertToPixels() * zoom;
if (gridType == GridType.CROSSHAIR) { if (gridType == GridType.CROSSHAIR) {
g2d.setStroke(new BasicStroke(1f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, g2d.setStroke(new BasicStroke(1f, BasicStroke.CAP_BUTT,
10f, new float[] { (float) zoomStep / 2, (float) zoomStep / 2 }, BasicStroke.JOIN_MITER, 10f, new float[] {
(float) zoomStep / 2, (float) zoomStep / 2 },
(float) zoomStep / 4)); (float) zoomStep / 4));
} else if (gridType == GridType.DOT) { } else if (gridType == GridType.DOT) {
g2d.setStroke(new BasicStroke(1f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, g2d.setStroke(new BasicStroke(1f, BasicStroke.CAP_BUTT,
10f, new float[] { 1f, (float) zoomStep - 1 }, 0f)); BasicStroke.JOIN_MITER, 10f, new float[] { 1f,
(float) zoomStep - 1 }, 0f));
} }
g2dWrapper.setColor(theme.getGridColor()); g2dWrapper.setColor(theme.getGridColor());
@@ -219,8 +229,9 @@ public class DrawingManager {
} }
// Draw the component through the g2dWrapper. // Draw the component through the g2dWrapper.
try { try {
component.draw(g2dWrapper, state, component.draw(g2dWrapper, state, drawOptions
drawOptions.contains(DrawOption.OUTLINE_MODE), project, g2dWrapper); .contains(DrawOption.OUTLINE_MODE), project,
g2dWrapper);
} catch (Exception e) { } catch (Exception e) {
LOG.error("Error drawing " + component.getName(), e); LOG.error("Error drawing " + component.getName(), e);
failedComponents.add(component); failedComponents.add(component);
@@ -250,8 +261,9 @@ public class DrawingManager {
g2dWrapper.setColor(CONTROL_POINT_COLOR); g2dWrapper.setColor(CONTROL_POINT_COLOR);
Point controlPoint = component.getControlPoint(i); Point controlPoint = component.getControlPoint(i);
int pointSize = CONTROL_POINT_SIZE - 2; int pointSize = CONTROL_POINT_SIZE - 2;
g2dWrapper.fillOval(controlPoint.x - pointSize / 2, controlPoint.y g2dWrapper.fillOval(controlPoint.x - pointSize / 2,
- pointSize / 2, pointSize, pointSize); controlPoint.y - pointSize / 2, pointSize,
pointSize);
} }
} }
} }
@@ -266,13 +278,16 @@ public class DrawingManager {
Point controlPoint = component.getControlPoint(i); Point controlPoint = component.getControlPoint(i);
int pointSize = CONTROL_POINT_SIZE; int pointSize = CONTROL_POINT_SIZE;
g2dWrapper.setColor(SELECTED_CONTROL_POINT_COLOR.darker()); g2dWrapper.setColor(SELECTED_CONTROL_POINT_COLOR
g2dWrapper.fillOval(controlPoint.x - pointSize / 2, controlPoint.y .darker());
- pointSize / 2, pointSize, pointSize); g2dWrapper.fillOval(controlPoint.x - pointSize / 2,
controlPoint.y - pointSize / 2, pointSize,
pointSize);
g2dWrapper.setColor(SELECTED_CONTROL_POINT_COLOR); g2dWrapper.setColor(SELECTED_CONTROL_POINT_COLOR);
g2dWrapper.fillOval(controlPoint.x - CONTROL_POINT_SIZE / 2 + 1, g2dWrapper.fillOval(controlPoint.x - CONTROL_POINT_SIZE
controlPoint.y - CONTROL_POINT_SIZE / 2 + 1, / 2 + 1, controlPoint.y - CONTROL_POINT_SIZE
CONTROL_POINT_SIZE - 2, CONTROL_POINT_SIZE - 2); / 2 + 1, CONTROL_POINT_SIZE - 2,
CONTROL_POINT_SIZE - 2);
} }
} }
} }
@@ -282,12 +297,17 @@ public class DrawingManager {
if (componentSlot != null) { if (componentSlot != null) {
g2dWrapper.startedDrawingComponent(); g2dWrapper.startedDrawingComponent();
g2dWrapper.setComposite(slotComposite); g2dWrapper.setComposite(slotComposite);
for (IDIYComponent<?> component : componentSlot) {
try { try {
componentSlot.draw(g2dWrapper, ComponentState.NORMAL, drawOptions
.contains(DrawOption.OUTLINE_MODE), project, g2dWrapper); component.draw(g2dWrapper, ComponentState.NORMAL,
drawOptions.contains(DrawOption.OUTLINE_MODE),
project, g2dWrapper);
} catch (Exception e) { } catch (Exception e) {
LOG.error("Error drawing " + componentSlot.getName(), e); LOG.error("Error drawing " + component.getName(), e);
failedComponents.add(componentSlot); failedComponents.add(component);
}
} }
g2dWrapper.finishedDrawingComponent(); g2dWrapper.finishedDrawingComponent();
} }
@@ -297,12 +317,13 @@ public class DrawingManager {
for (Point point : controlPointSlot) { for (Point point : controlPointSlot) {
if (point != null) { if (point != null) {
g2dWrapper.setColor(SELECTED_CONTROL_POINT_COLOR.darker()); g2dWrapper.setColor(SELECTED_CONTROL_POINT_COLOR.darker());
g2dWrapper.fillOval(point.x - CONTROL_POINT_SIZE / 2, point.y g2dWrapper.fillOval(point.x - CONTROL_POINT_SIZE / 2,
- CONTROL_POINT_SIZE / 2, CONTROL_POINT_SIZE, CONTROL_POINT_SIZE); point.y - CONTROL_POINT_SIZE / 2,
CONTROL_POINT_SIZE, CONTROL_POINT_SIZE);
g2dWrapper.setColor(SELECTED_CONTROL_POINT_COLOR); g2dWrapper.setColor(SELECTED_CONTROL_POINT_COLOR);
g2dWrapper.fillOval(point.x - CONTROL_POINT_SIZE / 2 + 1, point.y g2dWrapper.fillOval(point.x - CONTROL_POINT_SIZE / 2 + 1,
- CONTROL_POINT_SIZE / 2 + 1, CONTROL_POINT_SIZE - 2, point.y - CONTROL_POINT_SIZE / 2 + 1,
CONTROL_POINT_SIZE - 2); CONTROL_POINT_SIZE - 2, CONTROL_POINT_SIZE - 2);
} }
} }
} }
@@ -316,7 +337,8 @@ public class DrawingManager {
// } // }
// At the end draw selection rectangle if needed. // 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.setColor(Color.white);
g2d.draw(selectionRect); g2d.draw(selectionRect);
g2d.setColor(Color.black); g2d.setColor(Color.black);
@@ -371,7 +393,8 @@ public class DrawingManager {
return components; 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 width = project.getWidth().convertToPixels();
double height = project.getHeight().convertToPixels(); double height = project.getHeight().convertToPixels();
if (useZoom) { if (useZoom) {
@@ -395,7 +418,8 @@ public class DrawingManager {
public void setTheme(Theme theme) { public void setTheme(Theme theme) {
this.theme = theme; this.theme = theme;
ConfigurationManager.getInstance().writeValue(IPlugInPort.THEME_KEY, theme); ConfigurationManager.getInstance().writeValue(IPlugInPort.THEME_KEY,
theme);
messageDispatcher.dispatchMessage(EventType.REPAINT); messageDispatcher.dispatchMessage(EventType.REPAINT);
} }
} }
@@ -15,6 +15,7 @@ import org.diylc.common.IPlugInPort;
import org.diylc.common.Orientation; import org.diylc.common.Orientation;
import org.diylc.common.OrientationHV; import org.diylc.common.OrientationHV;
import org.diylc.common.PropertyWrapper; import org.diylc.common.PropertyWrapper;
import org.diylc.core.CreationMethod;
import org.diylc.core.IDIYComponent; import org.diylc.core.IDIYComponent;
import org.diylc.core.Project; import org.diylc.core.Project;
import org.diylc.core.Template; import org.diylc.core.Template;
@@ -34,10 +35,15 @@ public class InstantiationManager {
private ComponentType componentTypeSlot; private ComponentType componentTypeSlot;
private Template template; private Template template;
private IDIYComponent<?> componentSlot; private List<IDIYComponent<?>> componentSlot;
private Point firstControlPoint; private Point firstControlPoint;
private Point potentialControlPoint; 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() { public InstantiationManager() {
} }
@@ -49,7 +55,7 @@ public class InstantiationManager {
return template; return template;
} }
public IDIYComponent<?> getComponentSlot() { public List<IDIYComponent<?>> getComponentSlot() {
return componentSlot; return componentSlot;
} }
@@ -90,8 +96,8 @@ public class InstantiationManager {
// Set the other control point to the same location, we'll // Set the other control point to the same location, we'll
// move it later when mouse moves. // move it later when mouse moves.
componentSlot.setControlPoint(firstControlPoint, 0); componentSlot.get(0).setControlPoint(firstControlPoint, 0);
componentSlot.setControlPoint(firstControlPoint, 1); componentSlot.get(0).setControlPoint(firstControlPoint, 1);
} }
/** /**
@@ -103,17 +109,82 @@ public class InstantiationManager {
public boolean updatePointByPoint(Point scaledPoint) { public boolean updatePointByPoint(Point scaledPoint) {
boolean changeMade = !scaledPoint.equals(potentialControlPoint); boolean changeMade = !scaledPoint.equals(potentialControlPoint);
potentialControlPoint = scaledPoint; potentialControlPoint = scaledPoint;
if (componentSlot != null) { if (componentSlot != null && !componentSlot.isEmpty()) {
componentSlot.setControlPoint(scaledPoint, 1); componentSlot.get(0).setControlPoint(scaledPoint, 1);
} }
return changeMade; return changeMade;
} }
public void pasteComponents(List<IDIYComponent<?>> 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<IDIYComponent<?>>(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, public boolean updateSingleClick(Point scaledPoint, boolean snapToGrid,
Size gridSpacing) { Size gridSpacing) {
if (potentialControlPoint == null) { if (potentialControlPoint == null) {
potentialControlPoint = new Point(0, 0); potentialControlPoint = new Point(0, 0);
} }
if (scaledPoint == null) {
scaledPoint = new Point(0, 0);
}
int dx = scaledPoint.x - potentialControlPoint.x; int dx = scaledPoint.x - potentialControlPoint.x;
int dy = scaledPoint.y - potentialControlPoint.y; int dy = scaledPoint.y - potentialControlPoint.y;
if (snapToGrid) { if (snapToGrid) {
@@ -129,19 +200,21 @@ public class InstantiationManager {
LOG.error("Component slot should not be null!"); LOG.error("Component slot should not be null!");
} else { } else {
Point p = new Point(); Point p = new Point();
for (int i = 0; i < componentSlot.getControlPointCount(); i++) { for (IDIYComponent<?> component : componentSlot) {
p.setLocation(componentSlot.getControlPoint(i)); for (int i = 0; i < component.getControlPointCount(); i++) {
p.setLocation(component.getControlPoint(i));
p.translate(dx, dy); p.translate(dx, dy);
componentSlot.setControlPoint(p, i); component.setControlPoint(p, i);
}
} }
} }
return true; return true;
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public IDIYComponent<?> instantiateComponent(ComponentType componentType, public List<IDIYComponent<?>> instantiateComponent(
Template template, Point point, Project currentProject) ComponentType componentType, Template template, Point point,
throws Exception { Project currentProject) throws Exception {
LOG.info("Instatiating component of type: " LOG.info("Instatiating component of type: "
+ componentType.getInstanceClass().getName()); + componentType.getInstanceClass().getName());
@@ -182,7 +255,9 @@ public class InstantiationManager {
IPlugInPort.RECENT_COMPONENTS_KEY, recentComponentTypes); IPlugInPort.RECENT_COMPONENTS_KEY, recentComponentTypes);
} }
return component; List<IDIYComponent<?>> list = new ArrayList<IDIYComponent<?>>();
list.add(component);
return list;
} }
public String createUniqueName(ComponentType componentType, public String createUniqueName(ComponentType componentType,
@@ -57,7 +57,7 @@ public class Presenter implements IPlugInPort {
private static final Logger LOG = Logger.getLogger(Presenter.class); private static final Logger LOG = Logger.getLogger(Presenter.class);
public static final VersionNumber CURRENT_VERSION = new VersionNumber(3, public static final VersionNumber CURRENT_VERSION = new VersionNumber(3,
21, 0); 22, 0);
public static final String DEFAULTS_KEY_PREFIX = "default."; public static final String DEFAULTS_KEY_PREFIX = "default.";
public static final List<IDIYComponent<?>> EMPTY_SELECTION = Collections public static final List<IDIYComponent<?>> EMPTY_SELECTION = Collections
@@ -98,6 +98,7 @@ public class Presenter implements IPlugInPort {
private Point previousDragPoint = null; private Point previousDragPoint = null;
private Project preDragProject = null; private Project preDragProject = null;
private int dragAction; private int dragAction;
private Point previousScaledPoint;
public Presenter(IView view) { public Presenter(IView view) {
super(); super();
@@ -361,7 +362,7 @@ public class Presenter implements IPlugInPort {
} }
// Don't draw the component in the slot if both control points // Don't draw the component in the slot if both control points
// match. // match.
IDIYComponent<?> componentSlotToDraw; List<IDIYComponent<?>> componentSlotToDraw;
if (instantiationManager.getFirstControlPoint() != null if (instantiationManager.getFirstControlPoint() != null
&& instantiationManager.getPotentialControlPoint() != null && instantiationManager.getPotentialControlPoint() != null
&& instantiationManager.getFirstControlPoint().equals( && instantiationManager.getFirstControlPoint().equals(
@@ -446,17 +447,19 @@ public class Presenter implements IPlugInPort {
CalcUtils.snapPointToGrid(scaledPoint, CalcUtils.snapPointToGrid(scaledPoint,
currentProject.getGridSpacing()); currentProject.getGridSpacing());
} }
IDIYComponent<?> component = instantiationManager List<IDIYComponent<?>> componentSlot = instantiationManager
.getComponentSlot(); .getComponentSlot();
List<IDIYComponent<?>> newSelection = new ArrayList<IDIYComponent<?>>();
for (IDIYComponent<?> component : componentSlot) {
addComponent(component, componentTypeSlot, true); addComponent(component, componentTypeSlot, true);
newSelection.add(component);
}
// Select the new component // Select the new component
// messageDispatcher.dispatchMessage(EventType.SELECTION_CHANGED, // messageDispatcher.dispatchMessage(EventType.SELECTION_CHANGED,
// selectedComponents); // selectedComponents);
// messageDispatcher.dispatchMessage(EventType.SELECTION_SIZE_CHANGED, // messageDispatcher.dispatchMessage(EventType.SELECTION_SIZE_CHANGED,
// calculateSelectionDimension()); // calculateSelectionDimension());
messageDispatcher.dispatchMessage(EventType.REPAINT); messageDispatcher.dispatchMessage(EventType.REPAINT);
List<IDIYComponent<?>> newSelection = new ArrayList<IDIYComponent<?>>();
newSelection.add(component);
updateSelection(newSelection); updateSelection(newSelection);
} catch (Exception e) { } catch (Exception e) {
LOG.error("Error instatiating component of type: " LOG.error("Error instatiating component of type: "
@@ -501,15 +504,18 @@ public class Presenter implements IPlugInPort {
} else { } else {
// On the second click, add the component to the // On the second click, add the component to the
// project. // project.
IDIYComponent<?> componentSlot = instantiationManager List<IDIYComponent<?>> componentSlot = instantiationManager
.getComponentSlot(); .getComponentSlot();
componentSlot.setControlPoint(scaledPoint, 1); componentSlot.get(0).setControlPoint(scaledPoint, 1);
addComponent(componentSlot, componentTypeSlot, true);
// Select the new component if it's not locked.
List<IDIYComponent<?>> newSelection = new ArrayList<IDIYComponent<?>>(); List<IDIYComponent<?>> newSelection = new ArrayList<IDIYComponent<?>>();
if (!isComponentLocked(componentSlot)) { for (IDIYComponent<?> component : componentSlot) {
newSelection.add(componentSlot); addComponent(component, componentTypeSlot, true);
// Select the new component if it's not locked.
if (!isComponentLocked(component)) {
newSelection.add(component);
} }
}
updateSelection(newSelection); updateSelection(newSelection);
messageDispatcher.dispatchMessage(EventType.REPAINT); messageDispatcher.dispatchMessage(EventType.REPAINT);
@@ -681,21 +687,23 @@ public class Presenter implements IPlugInPort {
public void mouseMoved(Point point, boolean ctrlDown, boolean shiftDown, public void mouseMoved(Point point, boolean ctrlDown, boolean shiftDown,
boolean altDown) { boolean altDown) {
Map<IDIYComponent<?>, Set<Integer>> components = new HashMap<IDIYComponent<?>, Set<Integer>>(); Map<IDIYComponent<?>, Set<Integer>> components = new HashMap<IDIYComponent<?>, Set<Integer>>();
Point scaledPoint = scalePoint(point); this.previousScaledPoint = scalePoint(point);
if (instantiationManager.getComponentTypeSlot() != null) { if (instantiationManager.getComponentTypeSlot() != null) {
if (isSnapToGrid()) { if (isSnapToGrid()) {
CalcUtils.snapPointToGrid(scaledPoint, currentProject CalcUtils.snapPointToGrid(previousScaledPoint, currentProject
.getGridSpacing()); .getGridSpacing());
} }
boolean refresh = false; boolean refresh = false;
switch (instantiationManager.getComponentTypeSlot() switch (instantiationManager.getComponentTypeSlot()
.getCreationMethod()) { .getCreationMethod()) {
case POINT_BY_POINT: case POINT_BY_POINT:
refresh = instantiationManager.updatePointByPoint(scaledPoint); refresh = instantiationManager
.updatePointByPoint(previousScaledPoint);
break; break;
case SINGLE_CLICK: case SINGLE_CLICK:
refresh = instantiationManager.updateSingleClick(scaledPoint, refresh = instantiationManager.updateSingleClick(
isSnapToGrid(), currentProject.getGridSpacing()); previousScaledPoint, isSnapToGrid(), currentProject
.getGridSpacing());
break; break;
} }
if (refresh) { if (refresh) {
@@ -718,7 +726,7 @@ public class Presenter implements IPlugInPort {
&& componentType.isStretchable() && componentType.isStretchable()
&& findAllGroupedComponents(component).size() == 1) { && findAllGroupedComponents(component).size() == 1) {
try { try {
if (scaledPoint.distance(controlPoint) < DrawingManager.CONTROL_POINT_SIZE) { if (previousScaledPoint.distance(controlPoint) < DrawingManager.CONTROL_POINT_SIZE) {
Set<Integer> indices = new HashSet<Integer>(); Set<Integer> indices = new HashSet<Integer>();
if (componentType.isStretchable()) { if (componentType.isStretchable()) {
indices.add(pointIndex); 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)) { if (!components.equals(controlPointMap)) {
controlPointMap = components; controlPointMap = components;
@@ -1105,30 +1114,14 @@ public class Presenter implements IPlugInPort {
@Override @Override
public void pasteComponents(List<IDIYComponent<?>> components) { public void pasteComponents(List<IDIYComponent<?>> components) {
LOG.info(String.format("addComponents(%s)", components)); LOG.info(String.format("pasteComponents(%s)", components));
Project oldProject = currentProject.clone(); instantiationManager.pasteComponents(components,
for (IDIYComponent<?> component : components) { this.previousScaledPoint, isSnapToGrid(), currentProject
for (int i = 0; i < component.getControlPointCount(); i++) { .getGridSpacing());
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<? extends IDIYComponent<?>>) component
.getClass()), currentProject));
addComponent(component, ComponentProcessor.getInstance()
.extractComponentTypeFrom(
(Class<? extends IDIYComponent<?>>) component
.getClass()), false);
}
messageDispatcher.dispatchMessage(EventType.PROJECT_MODIFIED,
oldProject, currentProject.clone(), "Add");
projectFileManager.notifyFileChange();
updateSelection(new ArrayList<IDIYComponent<?>>(components));
messageDispatcher.dispatchMessage(EventType.REPAINT); messageDispatcher.dispatchMessage(EventType.REPAINT);
messageDispatcher.dispatchMessage(EventType.SLOT_CHANGED,
instantiationManager.getComponentTypeSlot(),
instantiationManager.getFirstControlPoint());
} }
@Override @Override
@@ -1609,8 +1602,9 @@ public class Presenter implements IPlugInPort {
if (component.isControlPointSticky(i)) { if (component.isControlPointSticky(i)) {
try { try {
IDIYComponent<?> pad = instantiationManager IDIYComponent<?> pad = instantiationManager
.instantiateComponent(padType, null, component .instantiateComponent(padType, null,
.getControlPoint(i), currentProject); component.getControlPoint(i),
currentProject).get(0);
pad.setControlPoint(component.getControlPoint(i), 0); pad.setControlPoint(component.getControlPoint(i), 0);
addComponent(pad, padType, false); addComponent(pad, padType, false);
} catch (Exception e) { } catch (Exception e) {