mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-10 17:22:09 +10:00
Big update - replace Point with Point2D in most places to increase
accuracy
This commit is contained in:
@@ -21,8 +21,8 @@
|
||||
*/
|
||||
package org.diylc.common;
|
||||
|
||||
import java.awt.Point;
|
||||
|
||||
import java.awt.geom.Point2D;
|
||||
|
||||
import org.diylc.core.IDIYComponent;
|
||||
|
||||
public class DefaultTransformer implements IComponentTransformer {
|
||||
@@ -43,11 +43,11 @@ public class DefaultTransformer implements IComponentTransformer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void rotate(IDIYComponent<?> component, Point center, int direction) {
|
||||
public void rotate(IDIYComponent<?> component, Point2D center, int direction) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mirror(IDIYComponent<?> component, Point center, int direction) {
|
||||
public void mirror(IDIYComponent<?> component, Point2D center, int direction) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -21,8 +21,8 @@
|
||||
*/
|
||||
package org.diylc.common;
|
||||
|
||||
import java.awt.Point;
|
||||
|
||||
import java.awt.geom.Point2D;
|
||||
|
||||
import org.diylc.core.IDIYComponent;
|
||||
|
||||
public interface IComponentTransformer {
|
||||
@@ -39,7 +39,7 @@ public interface IComponentTransformer {
|
||||
|
||||
boolean mirroringChangesCircuit();
|
||||
|
||||
void rotate(IDIYComponent<?> component, Point center, int direction);
|
||||
void rotate(IDIYComponent<?> component, Point2D center, int direction);
|
||||
|
||||
void mirror(IDIYComponent<?> component, Point center, int direction);
|
||||
void mirror(IDIYComponent<?> component, Point2D center, int direction);
|
||||
}
|
||||
|
||||
@@ -21,13 +21,13 @@
|
||||
*/
|
||||
package org.diylc.common;
|
||||
|
||||
import java.awt.Point;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import org.diylc.core.ExpansionMode;
|
||||
import org.diylc.core.IDIYComponent;
|
||||
import java.awt.geom.Point2D;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import org.diylc.core.ExpansionMode;
|
||||
import org.diylc.core.IDIYComponent;
|
||||
import org.diylc.core.measures.Size;
|
||||
|
||||
public interface ISelectionProcessor {
|
||||
@@ -55,7 +55,7 @@ public interface ISelectionProcessor {
|
||||
* @param includeLocked
|
||||
* @return
|
||||
*/
|
||||
List<IDIYComponent<?>> findComponentsAt(Point point, boolean includeLocked);
|
||||
List<IDIYComponent<?>> findComponentsAt(Point2D point, boolean includeLocked);
|
||||
|
||||
/**
|
||||
* Expands the current selection to include surrounding components. Options are controlled with
|
||||
|
||||
@@ -21,9 +21,10 @@
|
||||
*/
|
||||
package org.diylc.common;
|
||||
|
||||
import java.awt.Point;
|
||||
import java.awt.geom.AffineTransform;
|
||||
|
||||
import java.awt.Point;
|
||||
import java.awt.geom.AffineTransform;
|
||||
import java.awt.geom.Point2D;
|
||||
|
||||
import org.diylc.core.IDIYComponent;
|
||||
|
||||
public class SimpleComponentTransformer implements IComponentTransformer {
|
||||
@@ -44,23 +45,23 @@ public class SimpleComponentTransformer implements IComponentTransformer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void rotate(IDIYComponent<?> component, Point center, int direction) {
|
||||
AffineTransform rotate = AffineTransform.getRotateInstance(Math.PI / 2 * direction, center.x, center.y);
|
||||
public void rotate(IDIYComponent<?> component, Point2D center, int direction) {
|
||||
AffineTransform rotate = AffineTransform.getRotateInstance(Math.PI / 2 * direction, center.getX(), center.getY());
|
||||
for (int index = 0; index < component.getControlPointCount(); index++) {
|
||||
Point p = new Point(component.getControlPoint(index));
|
||||
rotate.transform(p, p);
|
||||
Point2D p = new Point2D.Double();
|
||||
rotate.transform(component.getControlPoint(index), p);
|
||||
component.setControlPoint(p, index);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mirror(IDIYComponent<?> component, Point center, int direction) {
|
||||
public void mirror(IDIYComponent<?> component, Point2D center, int direction) {
|
||||
for (int i = 0; i < component.getControlPointCount(); i++) {
|
||||
Point p = component.getControlPoint(i);
|
||||
Point2D p = component.getControlPoint(i);
|
||||
if (direction == IComponentTransformer.HORIZONTAL) {
|
||||
component.setControlPoint(new Point(p.x - 2 * (p.x - center.x), p.y), i);
|
||||
component.setControlPoint(new Point2D.Double(p.getX() - 2 * (p.getX() - center.getX()), p.getY()), i);
|
||||
} else {
|
||||
component.setControlPoint(new Point(p.x, p.y - 2 * (p.y - center.y)), i);
|
||||
component.setControlPoint(new Point.Double(p.getX(), p.getY() - 2 * (p.getY() - center.getY())), i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,8 +23,8 @@ package org.diylc.components;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Font;
|
||||
import java.awt.Point;
|
||||
import java.awt.Shape;
|
||||
import java.awt.geom.Point2D;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import java.lang.reflect.Array;
|
||||
import java.lang.reflect.Field;
|
||||
@@ -117,23 +117,23 @@ public abstract class AbstractComponent<T> implements IDIYComponent<T> {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
int minX = Integer.MAX_VALUE;
|
||||
int minY = Integer.MAX_VALUE;
|
||||
int maxX = Integer.MIN_VALUE;
|
||||
int maxY = Integer.MIN_VALUE;
|
||||
double minX = Integer.MAX_VALUE;
|
||||
double minY = Integer.MAX_VALUE;
|
||||
double maxX = Integer.MIN_VALUE;
|
||||
double maxY = Integer.MIN_VALUE;
|
||||
for (int i = 0; i < getControlPointCount(); i++) {
|
||||
Point p = getControlPoint(i);
|
||||
if (minX > p.x) {
|
||||
minX = p.x;
|
||||
Point2D p = getControlPoint(i);
|
||||
if (minX > p.getX()) {
|
||||
minX = p.getX();
|
||||
}
|
||||
if (maxX < p.x) {
|
||||
maxX = p.x;
|
||||
if (maxX < p.getX()) {
|
||||
maxX = p.getX();
|
||||
}
|
||||
if (minY > p.y) {
|
||||
minY = p.y;
|
||||
if (minY > p.getY()) {
|
||||
minY = p.getY();
|
||||
}
|
||||
if (maxY < p.y) {
|
||||
maxY = p.y;
|
||||
if (maxY < p.getY()) {
|
||||
maxY = p.getY();
|
||||
}
|
||||
}
|
||||
Rectangle2D rect = new Rectangle2D.Double(minX, minY, maxX - minX, maxY - minY);
|
||||
@@ -160,18 +160,19 @@ public abstract class AbstractComponent<T> implements IDIYComponent<T> {
|
||||
// Deep copy point arrays.
|
||||
// TODO: something nicer
|
||||
if (value != null && value.getClass().isArray()
|
||||
&& value.getClass().getComponentType().isAssignableFrom(Point.class)) {
|
||||
&& value.getClass().getComponentType().isAssignableFrom(Point2D.class)) {
|
||||
Object newArray = Array.newInstance(value.getClass().getComponentType(), Array.getLength(value));
|
||||
for (int i = 0; i < Array.getLength(value); i++) {
|
||||
Point p = (Point) Array.get(value, i);
|
||||
Array.set(newArray, i, new Point(p));
|
||||
Point2D p = (Point2D) Array.get(value, i);
|
||||
Array.set(newArray, i, new Point2D.Double(p.getX(), p.getY()));
|
||||
}
|
||||
value = newArray;
|
||||
}
|
||||
// Deep copy points.
|
||||
// TODO: something nicer
|
||||
if (value != null && value instanceof Point) {
|
||||
value = new Point((Point) value);
|
||||
if (value != null && value instanceof Point2D) {
|
||||
Point2D p = (Point2D) value;
|
||||
value = new Point2D.Double(p.getX(), p.getY());
|
||||
}
|
||||
|
||||
field.set(newInstance, value);
|
||||
|
||||
@@ -21,7 +21,6 @@ import java.awt.AlphaComposite;
|
||||
import java.awt.Color;
|
||||
import java.awt.Composite;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Point;
|
||||
import java.awt.geom.CubicCurve2D;
|
||||
import java.awt.geom.Path2D;
|
||||
import java.awt.geom.Point2D;
|
||||
@@ -53,12 +52,12 @@ public abstract class AbstractCurvedComponent<T> extends AbstractTransparentComp
|
||||
public static Size DEFAULT_SIZE = new Size(1d, SizeUnit.in);
|
||||
|
||||
// for backward compatibility
|
||||
protected Point[] controlPoints = null;
|
||||
protected Point2D[] controlPoints = null;
|
||||
|
||||
protected Point[] controlPoints2 = new Point[] {new Point(0, 0),
|
||||
new Point((int) (DEFAULT_SIZE.convertToPixels() / 2), 0),
|
||||
new Point((int) (DEFAULT_SIZE.convertToPixels() / 2), (int) (DEFAULT_SIZE.convertToPixels())),
|
||||
new Point((int) DEFAULT_SIZE.convertToPixels(), (int) DEFAULT_SIZE.convertToPixels())};
|
||||
protected Point2D[] controlPoints2 = new Point2D[] {new Point2D.Double(0, 0),
|
||||
new Point2D.Double(DEFAULT_SIZE.convertToPixels() / 2, 0),
|
||||
new Point2D.Double(DEFAULT_SIZE.convertToPixels() / 2, DEFAULT_SIZE.convertToPixels()),
|
||||
new Point2D.Double(DEFAULT_SIZE.convertToPixels(), DEFAULT_SIZE.convertToPixels())};
|
||||
|
||||
protected Color color = getDefaultColor();
|
||||
protected PointCount pointCount = PointCount.FOUR;
|
||||
@@ -102,7 +101,7 @@ public abstract class AbstractCurvedComponent<T> extends AbstractTransparentComp
|
||||
return;
|
||||
}
|
||||
|
||||
Point[] p = getControlPoints();
|
||||
Point2D[] p = getControlPoints();
|
||||
|
||||
// smoothen the curve if needed
|
||||
if (getSmooth() && lastUpdatePointIndex >= 0) {
|
||||
@@ -127,25 +126,25 @@ public abstract class AbstractCurvedComponent<T> extends AbstractTransparentComp
|
||||
g2d.setStroke(Constants.DASHED_STROKE);
|
||||
g2d.setColor(GUIDELINE_COLOR);
|
||||
for (int i = 0; i < p.length - 1; i++) {
|
||||
g2d.drawLine(p[i].x, p[i].y, p[i + 1].x, p[i + 1].y);
|
||||
g2d.drawLine((int)p[i].getX(), (int)p[i].getY(), (int)p[i + 1].getX(), (int)p[i + 1].getY());
|
||||
}
|
||||
drawingObserver.startTracking();
|
||||
}
|
||||
|
||||
Path2D path = new Path2D.Double();
|
||||
path.moveTo(p[0].x, p[0].y);
|
||||
path.moveTo(p[0].getX(), p[0].getY());
|
||||
if (getPointCount() == PointCount.TWO) {
|
||||
path.lineTo(p[1].x, p[1].y);
|
||||
path.lineTo(p[1].getX(), p[1].getY());
|
||||
} else if (getPointCount() == PointCount.THREE) {
|
||||
path.curveTo(p[1].x, p[1].y, p[1].x, p[1].y, p[2].x, p[2].y);
|
||||
path.curveTo(p[1].getX(), p[1].getY(), p[1].getX(), p[1].getY(), p[2].getX(), p[2].getY());
|
||||
} else if (getPointCount() == PointCount.FOUR) {
|
||||
path.curveTo(p[1].x, p[1].y, p[2].x, p[2].y, p[3].x, p[3].y);
|
||||
path.curveTo(p[1].getX(), p[1].getY(), p[2].getX(), p[2].getY(), p[3].getX(), p[3].getY());
|
||||
} else if (getPointCount() == PointCount.FIVE) {
|
||||
path.quadTo(p[1].x, p[1].y, p[2].x, p[2].y);
|
||||
path.quadTo(p[3].x, p[3].y, p[4].x, p[4].y);
|
||||
path.quadTo(p[1].getX(), p[1].getY(), p[2].getX(), p[2].getY());
|
||||
path.quadTo(p[3].getX(), p[3].getY(), p[4].getX(), p[4].getY());
|
||||
} else if (getPointCount() == PointCount.SEVEN) {
|
||||
path.curveTo(p[1].x, p[1].y, p[2].x, p[2].y, p[3].x, p[3].y);
|
||||
path.curveTo(p[4].x, p[4].y, p[5].x, p[5].y, p[6].x, p[6].y);
|
||||
path.curveTo(p[1].getX(), p[1].getY(), p[2].getX(), p[2].getY(), p[3].getX(), p[3].getY());
|
||||
path.curveTo(p[4].getX(), p[4].getY(), p[5].getX(), p[5].getY(), p[6].getX(), p[6].getY());
|
||||
}
|
||||
|
||||
Composite oldComposite = g2d.getComposite();
|
||||
@@ -166,23 +165,23 @@ public abstract class AbstractCurvedComponent<T> extends AbstractTransparentComp
|
||||
return pointCount;
|
||||
}
|
||||
|
||||
protected Point[] getControlPoints() {
|
||||
protected Point2D[] getControlPoints() {
|
||||
if (this.controlPoints != null) {
|
||||
// ensure backward compatibility by copying points from the old structure to the new one
|
||||
switch (getPointCount()) {
|
||||
case TWO:
|
||||
this.controlPoints2 = new Point[2];
|
||||
this.controlPoints2 = new Point2D[2];
|
||||
this.controlPoints2[0] = this.controlPoints[0];
|
||||
this.controlPoints2[1] = this.controlPoints[3];
|
||||
break;
|
||||
case THREE:
|
||||
this.controlPoints2 = new Point[3];
|
||||
this.controlPoints2 = new Point2D[3];
|
||||
this.controlPoints2[0] = this.controlPoints[0];
|
||||
this.controlPoints2[1] = this.controlPoints[1];
|
||||
this.controlPoints2[2] = this.controlPoints[3];
|
||||
break;
|
||||
case FOUR:
|
||||
this.controlPoints2 = new Point[4];
|
||||
this.controlPoints2 = new Point2D[4];
|
||||
this.controlPoints2[0] = this.controlPoints[0];
|
||||
this.controlPoints2[1] = this.controlPoints[1];
|
||||
this.controlPoints2[2] = this.controlPoints[2];
|
||||
@@ -198,42 +197,42 @@ public abstract class AbstractCurvedComponent<T> extends AbstractTransparentComp
|
||||
}
|
||||
|
||||
public void setPointCount(PointCount pointCount) {
|
||||
Point[] p = getControlPoints();
|
||||
Point[] newPoints = new Point[pointCount.count];
|
||||
Point2D[] p = getControlPoints();
|
||||
Point2D[] newPoints = new Point2D[pointCount.count];
|
||||
newPoints[0] = p[0];
|
||||
newPoints[pointCount.count - 1] = p[p.length - 1];
|
||||
|
||||
if (pointCount == PointCount.THREE) {
|
||||
newPoints[1] =
|
||||
new Point((newPoints[pointCount.count - 1].x + newPoints[0].x) / 2,
|
||||
(newPoints[pointCount.count - 1].y + newPoints[0].y) / 2);
|
||||
new Point2D.Double((newPoints[pointCount.count - 1].getX() + newPoints[0].getX()) / 2,
|
||||
(newPoints[pointCount.count - 1].getY() + newPoints[0].getY()) / 2);
|
||||
} else if (pointCount == PointCount.FOUR) {
|
||||
newPoints[1] =
|
||||
new Point((newPoints[pointCount.count - 1].x + newPoints[0].x) / 2,
|
||||
(newPoints[pointCount.count - 1].y + newPoints[0].y) / 2);
|
||||
new Point2D.Double((newPoints[pointCount.count - 1].getX() + newPoints[0].getX()) / 2,
|
||||
(newPoints[pointCount.count - 1].getY() + newPoints[0].getY()) / 2);
|
||||
newPoints[2] =
|
||||
new Point((newPoints[pointCount.count - 1].x + newPoints[0].x) / 2,
|
||||
(newPoints[pointCount.count - 1].y + newPoints[0].y) / 2);
|
||||
new Point2D.Double((newPoints[pointCount.count - 1].getX() + newPoints[0].getX()) / 2,
|
||||
(newPoints[pointCount.count - 1].getY() + newPoints[0].getY()) / 2);
|
||||
} else if (pointCount == PointCount.FIVE) {
|
||||
newPoints[2] =
|
||||
new Point((newPoints[pointCount.count - 1].x + newPoints[0].x) / 2,
|
||||
(newPoints[pointCount.count - 1].y + newPoints[0].y) / 2);
|
||||
newPoints[1] = new Point((newPoints[2].x + newPoints[0].x) / 2, (newPoints[2].y + newPoints[0].y) / 2);
|
||||
new Point2D.Double((newPoints[pointCount.count - 1].getX() + newPoints[0].getX()) / 2,
|
||||
(newPoints[pointCount.count - 1].getY() + newPoints[0].getY()) / 2);
|
||||
newPoints[1] = new Point2D.Double((newPoints[2].getX() + newPoints[0].getX()) / 2, (newPoints[2].getY() + newPoints[0].getY()) / 2);
|
||||
newPoints[3] =
|
||||
new Point((newPoints[pointCount.count - 1].x + newPoints[2].x) / 2,
|
||||
(newPoints[pointCount.count - 1].y + newPoints[2].y) / 2);
|
||||
new Point2D.Double((newPoints[pointCount.count - 1].getX() + newPoints[2].getX()) / 2,
|
||||
(newPoints[pointCount.count - 1].getY() + newPoints[2].getY()) / 2);
|
||||
} else if (pointCount == PointCount.SEVEN) {
|
||||
newPoints[3] =
|
||||
new Point((newPoints[pointCount.count - 1].x + newPoints[0].x) / 2,
|
||||
(newPoints[pointCount.count - 1].y + newPoints[0].y) / 2);
|
||||
newPoints[2] = new Point((newPoints[3].x + newPoints[0].x) / 2, (newPoints[3].y + newPoints[0].y) / 2);
|
||||
newPoints[1] = new Point((newPoints[3].x + newPoints[0].x) / 2, (newPoints[3].y + newPoints[0].y) / 2);
|
||||
new Point2D.Double((newPoints[pointCount.count - 1].getX() + newPoints[0].getX()) / 2,
|
||||
(newPoints[pointCount.count - 1].getY() + newPoints[0].getY()) / 2);
|
||||
newPoints[2] = new Point2D.Double((newPoints[3].getX() + newPoints[0].getX()) / 2, (newPoints[3].getY() + newPoints[0].getY()) / 2);
|
||||
newPoints[1] = new Point2D.Double((newPoints[3].getX() + newPoints[0].getX()) / 2, (newPoints[3].getY() + newPoints[0].getY()) / 2);
|
||||
newPoints[4] =
|
||||
new Point((newPoints[pointCount.count - 1].x + newPoints[3].x) / 2,
|
||||
(newPoints[pointCount.count - 1].y + newPoints[3].y) / 2);
|
||||
new Point2D.Double((newPoints[pointCount.count - 1].getX() + newPoints[3].getX()) / 2,
|
||||
(newPoints[pointCount.count - 1].getY() + newPoints[3].getY()) / 2);
|
||||
newPoints[5] =
|
||||
new Point((newPoints[pointCount.count - 1].x + newPoints[3].x) / 2,
|
||||
(newPoints[pointCount.count - 1].y + newPoints[3].y) / 2);
|
||||
new Point2D.Double((newPoints[pointCount.count - 1].getX() + newPoints[3].getX()) / 2,
|
||||
(newPoints[pointCount.count - 1].getY() + newPoints[3].getY()) / 2);
|
||||
}
|
||||
|
||||
this.controlPoints2 = newPoints;
|
||||
@@ -261,13 +260,13 @@ public abstract class AbstractCurvedComponent<T> extends AbstractTransparentComp
|
||||
}
|
||||
|
||||
@Override
|
||||
public Point getControlPoint(int index) {
|
||||
public Point2D getControlPoint(int index) {
|
||||
return getControlPoints()[index];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setControlPoint(Point point, int index) {
|
||||
Point[] p = getControlPoints();
|
||||
public void setControlPoint(Point2D point, int index) {
|
||||
Point2D[] p = getControlPoints();
|
||||
p[index].setLocation(point);
|
||||
this.lastUpdatePointIndex = index;
|
||||
// if (getSmooth()) {
|
||||
@@ -286,8 +285,8 @@ public abstract class AbstractCurvedComponent<T> extends AbstractTransparentComp
|
||||
// }
|
||||
}
|
||||
|
||||
private Point findThirdPoint(Point p0, Point p) {
|
||||
return new Point(2 * p0.x - p.x, 2 * p0.y - p.y);
|
||||
private Point2D findThirdPoint(Point2D p0, Point2D p) {
|
||||
return new Point2D.Double(2 * p0.getX() - p.getX(), 2 * p0.getY() - p.getY());
|
||||
}
|
||||
|
||||
@EditableProperty(name = "Color")
|
||||
@@ -335,7 +334,7 @@ public abstract class AbstractCurvedComponent<T> extends AbstractTransparentComp
|
||||
public Size getLength() {
|
||||
double d = 0;
|
||||
try {
|
||||
Point[] p = getControlPoints();
|
||||
Point2D[] p = getControlPoints();
|
||||
if (getPointCount() == PointCount.TWO) {
|
||||
d = p[0].distance(p[1]);
|
||||
} else if (getPointCount() == PointCount.THREE) {
|
||||
@@ -364,21 +363,21 @@ public abstract class AbstractCurvedComponent<T> extends AbstractTransparentComp
|
||||
|
||||
@Override
|
||||
public Rectangle2D getCachingBounds() {
|
||||
int minX = Integer.MAX_VALUE;
|
||||
int maxX = Integer.MIN_VALUE;
|
||||
int minY = Integer.MAX_VALUE;
|
||||
int maxY = Integer.MIN_VALUE;
|
||||
int margin = 50; // hard coded, replace with something meaningful
|
||||
double minX = Integer.MAX_VALUE;
|
||||
double maxX = Integer.MIN_VALUE;
|
||||
double minY = Integer.MAX_VALUE;
|
||||
double maxY = Integer.MIN_VALUE;
|
||||
double margin = 50; // hard coded, replace with something meaningful
|
||||
for (int i = 0; i < getControlPointCount(); i++) {
|
||||
Point p = getControlPoint(i);
|
||||
if (p.x < minX)
|
||||
minX = p.x;
|
||||
if (p.x > maxX)
|
||||
maxX = p.x;
|
||||
if (p.y < minY)
|
||||
minY = p.y;
|
||||
if (p.y > maxY)
|
||||
maxY = p.y;
|
||||
Point2D p = getControlPoint(i);
|
||||
if (p.getX() < minX)
|
||||
minX = p.getX();
|
||||
if (p.getX() > maxX)
|
||||
maxX = p.getX();
|
||||
if (p.getY() < minY)
|
||||
minY = p.getY();
|
||||
if (p.getY() > maxY)
|
||||
maxY = p.getY();
|
||||
}
|
||||
|
||||
return new Rectangle2D.Double(minX - margin, minY - margin, maxX - minX + 2 * margin, maxY - minY + 2 * margin);
|
||||
|
||||
@@ -21,9 +21,9 @@
|
||||
*/
|
||||
package org.diylc.components.transform;
|
||||
|
||||
import java.awt.Point;
|
||||
|
||||
import org.diylc.common.IComponentTransformer;
|
||||
import java.awt.geom.Point2D;
|
||||
|
||||
import org.diylc.common.IComponentTransformer;
|
||||
import org.diylc.core.IDIYComponent;
|
||||
|
||||
public class DefaultTransformer implements IComponentTransformer {
|
||||
@@ -44,11 +44,11 @@ public class DefaultTransformer implements IComponentTransformer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void rotate(IDIYComponent<?> component, Point center, int direction) {
|
||||
public void rotate(IDIYComponent<?> component, Point2D center, int direction) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mirror(IDIYComponent<?> component, Point center, int direction) {
|
||||
public void mirror(IDIYComponent<?> component, Point2D center, int direction) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+13
-13
@@ -21,10 +21,10 @@
|
||||
*/
|
||||
package org.diylc.components.transform;
|
||||
|
||||
import java.awt.Point;
|
||||
import java.awt.geom.AffineTransform;
|
||||
|
||||
import org.diylc.common.IComponentTransformer;
|
||||
import java.awt.geom.AffineTransform;
|
||||
import java.awt.geom.Point2D;
|
||||
|
||||
import org.diylc.common.IComponentTransformer;
|
||||
import org.diylc.core.IDIYComponent;
|
||||
|
||||
public class LeadedComponentTransformer implements IComponentTransformer {
|
||||
@@ -45,23 +45,23 @@ public class LeadedComponentTransformer implements IComponentTransformer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void rotate(IDIYComponent<?> component, Point center, int direction) {
|
||||
AffineTransform rotate = AffineTransform.getRotateInstance(Math.PI / 2 * direction, center.x, center.y);
|
||||
for (int index = 0; index < component.getControlPointCount(); index++) {
|
||||
Point p = new Point(component.getControlPoint(index));
|
||||
rotate.transform(p, p);
|
||||
public void rotate(IDIYComponent<?> component, Point2D center, int direction) {
|
||||
AffineTransform rotate = AffineTransform.getRotateInstance(Math.PI / 2 * direction, center.getX(), center.getY());
|
||||
for (int index = 0; index < component.getControlPointCount(); index++) {
|
||||
Point2D p = new Point2D.Double();
|
||||
rotate.transform(component.getControlPoint(index), p);
|
||||
component.setControlPoint(p, index);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mirror(IDIYComponent<?> component, Point center, int direction) {
|
||||
public void mirror(IDIYComponent<?> component, Point2D center, int direction) {
|
||||
for (int i = 0; i < component.getControlPointCount(); i++) {
|
||||
Point p = component.getControlPoint(i);
|
||||
Point2D p = component.getControlPoint(i);
|
||||
if (direction == IComponentTransformer.HORIZONTAL) {
|
||||
component.setControlPoint(new Point(p.x - 2 * (p.x - center.x), p.y), i);
|
||||
component.setControlPoint(new Point2D.Double(p.getX() - 2 * (p.getX() - center.getX()), p.getY()), i);
|
||||
} else {
|
||||
component.setControlPoint(new Point(p.x, p.y - 2 * (p.y - center.y)), i);
|
||||
component.setControlPoint(new Point2D.Double(p.getX(), p.getY() - 2 * (p.getY() - center.getY())), i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,12 +21,12 @@
|
||||
*/
|
||||
package org.diylc.core;
|
||||
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Point;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.geom.Point2D;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import java.io.Serializable;
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.diylc.core.annotations.ComponentDescriptor;
|
||||
import org.diylc.core.annotations.ComponentDescriptor;
|
||||
import org.diylc.core.annotations.EditableProperty;
|
||||
|
||||
/**
|
||||
@@ -89,7 +89,7 @@ public interface IDIYComponent<T> extends Serializable, Cloneable {
|
||||
* @param index
|
||||
* @return control point at the specified index.
|
||||
*/
|
||||
Point getControlPoint(int index);
|
||||
Point2D getControlPoint(int index);
|
||||
|
||||
/**
|
||||
* Updates the control point at the specified index.
|
||||
@@ -97,7 +97,7 @@ public interface IDIYComponent<T> extends Serializable, Cloneable {
|
||||
* @param point
|
||||
* @param index
|
||||
*/
|
||||
void setControlPoint(Point point, int index);
|
||||
void setControlPoint(Point2D point, int index);
|
||||
|
||||
/**
|
||||
* @param index
|
||||
|
||||
@@ -20,16 +20,16 @@
|
||||
|
||||
*/
|
||||
package org.diylc.core;
|
||||
|
||||
import java.awt.Point;
|
||||
import java.util.List;
|
||||
|
||||
import java.awt.geom.Point2D;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class Template {
|
||||
|
||||
private String name;
|
||||
private Map<String, Object> values;
|
||||
private List<Point> points;
|
||||
private List<Point2D> points;
|
||||
@SuppressWarnings("unused")
|
||||
@Deprecated
|
||||
private boolean defaultFlag;
|
||||
@@ -37,7 +37,7 @@ public class Template {
|
||||
public Template() {
|
||||
}
|
||||
|
||||
public Template(String name, Map<String, Object> values, List<Point> points) {
|
||||
public Template(String name, Map<String, Object> values, List<Point2D> points) {
|
||||
this.name = name;
|
||||
this.values = values;
|
||||
this.points = points;
|
||||
@@ -59,11 +59,11 @@ public class Template {
|
||||
this.values = values;
|
||||
}
|
||||
|
||||
public List<Point> getPoints() {
|
||||
public List<Point2D> getPoints() {
|
||||
return points;
|
||||
}
|
||||
|
||||
public void setPoints(List<Point> points) {
|
||||
public void setPoints(List<Point2D> points) {
|
||||
this.points = points;
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
*/
|
||||
package org.diylc.presenter;
|
||||
|
||||
import java.awt.Point;
|
||||
import java.awt.geom.Point2D;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
@@ -37,18 +37,18 @@ public class CalcUtils {
|
||||
* @param x
|
||||
* @return
|
||||
*/
|
||||
public static int roundToGrid(double x, Size gridSpacing) {
|
||||
public static double roundToGrid(double x, Size gridSpacing) {
|
||||
double grid = gridSpacing.convertToPixels();
|
||||
return (int) Math.round((Math.round(1f * x / grid) * grid));
|
||||
return (Math.round(1f * x / grid) * grid);
|
||||
}
|
||||
|
||||
public static void snapPointToGrid(Point point, Size gridSpacing) {
|
||||
int x = roundToGrid(point.x, gridSpacing);
|
||||
int y = roundToGrid(point.y, gridSpacing);
|
||||
public static void snapPointToGrid(Point2D point, Size gridSpacing) {
|
||||
double x = roundToGrid(point.getX(), gridSpacing);
|
||||
double y = roundToGrid(point.getY(), gridSpacing);
|
||||
point.setLocation(x, y);
|
||||
}
|
||||
|
||||
public static void snapPointToObjects(Point point, Size gridSpacing, IDIYComponent<?> component, List<IDIYComponent<?>> components) {
|
||||
public static void snapPointToObjects(Point2D point, Size gridSpacing, IDIYComponent<?> component, List<IDIYComponent<?>> components) {
|
||||
for (IDIYComponent<?> c : components) {
|
||||
if (c == component)
|
||||
continue;
|
||||
|
||||
@@ -18,8 +18,8 @@
|
||||
package org.diylc.presenter;
|
||||
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Point;
|
||||
import java.awt.geom.Area;
|
||||
import java.awt.geom.Point2D;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.HashMap;
|
||||
@@ -93,7 +93,7 @@ public class DrawingCache {
|
||||
|
||||
if (type != null && type.getEnableCache()) {
|
||||
// if we need to apply caching
|
||||
Point firstPoint = component.getControlPoint(0);
|
||||
Point2D firstPoint = component.getControlPoint(0);
|
||||
|
||||
CacheValue value = renderAndCache(component, g2d, componentState, outlineMode, project, zoom);
|
||||
|
||||
@@ -107,8 +107,8 @@ public class DrawingCache {
|
||||
}
|
||||
try {
|
||||
// draw cached image
|
||||
g2d.getCanvasGraphics().drawImage(value.getImage(), (int) ((firstPoint.x - value.getDx()) * zoom),
|
||||
(int) ((firstPoint.y - value.getDy())* zoom), null);
|
||||
g2d.getCanvasGraphics().drawImage(value.getImage(), (int) ((firstPoint.getX() - value.getDx()) * zoom),
|
||||
(int) ((firstPoint.getY() - value.getDy())* zoom), null);
|
||||
} finally {
|
||||
if (Math.abs(1.0 - zoom) > 1e-4) {
|
||||
g2d.getCanvasGraphics().scale(zoom, zoom);
|
||||
@@ -157,7 +157,7 @@ public class DrawingCache {
|
||||
private CacheValue renderAndCache(IDIYComponent<?> component, G2DWrapper g2d, ComponentState componentState,
|
||||
boolean outlineMode, Project project, double zoom) {
|
||||
// if we need to apply caching
|
||||
Point firstPoint = component.getControlPoint(0);
|
||||
Point2D firstPoint = component.getControlPoint(0);
|
||||
|
||||
// cache hit!
|
||||
CacheValue value = null;
|
||||
@@ -172,8 +172,8 @@ public class DrawingCache {
|
||||
int width = (int)Math.round(rect.getWidth() * zoom);
|
||||
int height = (int)Math.round(rect.getHeight() * zoom);
|
||||
// calculate the position of the first point relative to the caching bounds
|
||||
int dx = (int) (firstPoint.x - rect.getX());
|
||||
int dy = (int) (firstPoint.y - rect.getY());
|
||||
int dx = (int) (firstPoint.getX() - rect.getX());
|
||||
int dy = (int) (firstPoint.getY() - rect.getY());
|
||||
|
||||
// create image
|
||||
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
|
||||
@@ -191,7 +191,7 @@ public class DrawingCache {
|
||||
cg2d.scale(zoom, zoom);
|
||||
}
|
||||
// translate to make the top-left corner of the component match (0, 0)
|
||||
cg2d.translate(-firstPoint.x + dx, -firstPoint.y + dy);
|
||||
cg2d.translate(-firstPoint.getX() + dx, -firstPoint.getY() + dy);
|
||||
|
||||
// wrap the graphics so we can track
|
||||
G2DWrapper wrapper = new G2DWrapper(cg2d, zoom);
|
||||
|
||||
@@ -29,6 +29,7 @@ import java.awt.RenderingHints;
|
||||
import java.awt.geom.AffineTransform;
|
||||
import java.awt.geom.Area;
|
||||
import java.awt.geom.Line2D;
|
||||
import java.awt.geom.Point2D;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
@@ -155,7 +156,7 @@ public class DrawingManager {
|
||||
*/
|
||||
public List<IDIYComponent<?>> drawProject(Graphics2D g2d, Project project, Set<DrawOption> drawOptions,
|
||||
IComponentFilter filter, Rectangle selectionRect, Collection<IDIYComponent<?>> selectedComponents,
|
||||
Set<IDIYComponent<?>> lockedComponents, Set<IDIYComponent<?>> groupedComponents, List<Point> controlPointSlot,
|
||||
Set<IDIYComponent<?>> lockedComponents, Set<IDIYComponent<?>> groupedComponents, List<Point2D> controlPointSlot,
|
||||
List<IDIYComponent<?>> componentSlot, boolean dragInProgress, Double externalZoom, Rectangle2D visibleRect) {
|
||||
long totalStartTime = System.nanoTime();
|
||||
failedComponents.clear();
|
||||
@@ -370,9 +371,9 @@ public class DrawingManager {
|
||||
.contains(component) && !selectedComponents.contains(component) && component
|
||||
.getControlPointVisibilityPolicy(i) == VisibilityPolicy.ALWAYS))) {
|
||||
g2dWrapper.setColor(CONTROL_POINT_COLOR);
|
||||
Point controlPoint = component.getControlPoint(i);
|
||||
Point2D controlPoint = component.getControlPoint(i);
|
||||
int pointSize = CONTROL_POINT_SIZE - 2;
|
||||
g2dWrapper.fillOval(controlPoint.x - pointSize / 2, controlPoint.y - pointSize / 2, pointSize, pointSize);
|
||||
g2dWrapper.fillOval((int)(controlPoint.getX() - pointSize / 2), (int)(controlPoint.getY() - pointSize / 2), pointSize, pointSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -384,14 +385,14 @@ public class DrawingManager {
|
||||
&& (component.getControlPointVisibilityPolicy(i) == VisibilityPolicy.WHEN_SELECTED || component
|
||||
.getControlPointVisibilityPolicy(i) == VisibilityPolicy.ALWAYS)) {
|
||||
|
||||
Point controlPoint = component.getControlPoint(i);
|
||||
Point2D controlPoint = component.getControlPoint(i);
|
||||
int pointSize = CONTROL_POINT_SIZE;
|
||||
|
||||
g2dWrapper.setColor(SELECTED_CONTROL_POINT_COLOR.darker());
|
||||
g2dWrapper.fillOval(controlPoint.x - pointSize / 2, controlPoint.y - pointSize / 2, pointSize, pointSize);
|
||||
g2dWrapper.fillOval((int)(controlPoint.getX() - pointSize / 2), (int)(controlPoint.getY() - pointSize / 2), pointSize, pointSize);
|
||||
g2dWrapper.setColor(SELECTED_CONTROL_POINT_COLOR);
|
||||
g2dWrapper.fillOval(controlPoint.x - CONTROL_POINT_SIZE / 2 + 1, controlPoint.y - CONTROL_POINT_SIZE / 2
|
||||
+ 1, CONTROL_POINT_SIZE - 2, CONTROL_POINT_SIZE - 2);
|
||||
g2dWrapper.fillOval((int)(controlPoint.getX() - CONTROL_POINT_SIZE / 2 + 1), (int)(controlPoint.getY() - CONTROL_POINT_SIZE / 2
|
||||
+ 1), CONTROL_POINT_SIZE - 2, CONTROL_POINT_SIZE - 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -417,13 +418,13 @@ public class DrawingManager {
|
||||
|
||||
// Draw control points of the component in the slot.
|
||||
if (controlPointSlot != null) {
|
||||
for (Point point : controlPointSlot) {
|
||||
for (Point2D point : controlPointSlot) {
|
||||
if (point != null) {
|
||||
g2dWrapper.setColor(SELECTED_CONTROL_POINT_COLOR.darker());
|
||||
g2dWrapper.fillOval(point.x - CONTROL_POINT_SIZE / 2, point.y - CONTROL_POINT_SIZE / 2, CONTROL_POINT_SIZE,
|
||||
g2dWrapper.fillOval((int)(point.getX() - CONTROL_POINT_SIZE / 2), (int)(point.getY() - CONTROL_POINT_SIZE / 2), CONTROL_POINT_SIZE,
|
||||
CONTROL_POINT_SIZE);
|
||||
g2dWrapper.setColor(SELECTED_CONTROL_POINT_COLOR);
|
||||
g2dWrapper.fillOval(point.x - CONTROL_POINT_SIZE / 2 + 1, point.y - CONTROL_POINT_SIZE / 2 + 1,
|
||||
g2dWrapper.fillOval((int)(point.getX() - CONTROL_POINT_SIZE / 2 + 1), (int)(point.getY() - CONTROL_POINT_SIZE / 2 + 1),
|
||||
CONTROL_POINT_SIZE - 2, CONTROL_POINT_SIZE - 2);
|
||||
}
|
||||
}
|
||||
@@ -539,7 +540,7 @@ public class DrawingManager {
|
||||
continuityAreaCache = null;
|
||||
}
|
||||
|
||||
public List<IDIYComponent<?>> findComponentsAt(Point point, Project project) {
|
||||
public List<IDIYComponent<?>> findComponentsAt(Point2D point, Project project) {
|
||||
List<IDIYComponent<?>> components = new ArrayList<IDIYComponent<?>>();
|
||||
for (int i = 0; i < project.getComponents().size(); i++) {
|
||||
ComponentArea area = componentAreaMap.get(project.getComponents().get(i));
|
||||
@@ -588,7 +589,7 @@ public class DrawingManager {
|
||||
messageDispatcher.dispatchMessage(EventType.REPAINT);
|
||||
}
|
||||
|
||||
public void findContinuityAreaAtPoint(Project project, Point p) {
|
||||
public void findContinuityAreaAtPoint(Project project, Point2D p) {
|
||||
if (continuityAreaCache == null)
|
||||
continuityAreaCache = getContinuityAreas(project);
|
||||
|
||||
|
||||
@@ -21,29 +21,29 @@
|
||||
*/
|
||||
package org.diylc.presenter;
|
||||
|
||||
import java.awt.Point;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.awt.geom.Point2D;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.diylc.appframework.miscutils.ConfigurationManager;
|
||||
import org.diylc.common.ComponentType;
|
||||
import org.diylc.common.IPlugInPort;
|
||||
import org.diylc.common.Orientation;
|
||||
import org.diylc.common.OrientationHV;
|
||||
import org.diylc.common.PropertyWrapper;
|
||||
import org.diylc.core.CreationMethod;
|
||||
import org.diylc.core.IDIYComponent;
|
||||
import org.diylc.core.Project;
|
||||
import org.diylc.core.Template;
|
||||
import org.diylc.core.annotations.KeywordPolicy;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.diylc.appframework.miscutils.ConfigurationManager;
|
||||
import org.diylc.common.ComponentType;
|
||||
import org.diylc.common.IPlugInPort;
|
||||
import org.diylc.common.Orientation;
|
||||
import org.diylc.common.OrientationHV;
|
||||
import org.diylc.common.PropertyWrapper;
|
||||
import org.diylc.core.CreationMethod;
|
||||
import org.diylc.core.IDIYComponent;
|
||||
import org.diylc.core.Project;
|
||||
import org.diylc.core.Template;
|
||||
import org.diylc.core.annotations.KeywordPolicy;
|
||||
import org.diylc.core.measures.Size;
|
||||
|
||||
/**
|
||||
@@ -60,8 +60,8 @@ public class InstantiationManager {
|
||||
private ComponentType componentTypeSlot;
|
||||
private Template template;
|
||||
private List<IDIYComponent<?>> componentSlot;
|
||||
private Point firstControlPoint;
|
||||
private Point potentialControlPoint;
|
||||
private Point2D firstControlPoint;
|
||||
private Point2D potentialControlPoint;
|
||||
|
||||
public static final ComponentType clipboardType = new ComponentType("Clipboard contents",
|
||||
"Components from the clipboard", CreationMethod.SINGLE_CLICK, "Multi", "", "", null, null, 0, false, null,
|
||||
@@ -84,15 +84,15 @@ public class InstantiationManager {
|
||||
return componentSlot;
|
||||
}
|
||||
|
||||
public Point getFirstControlPoint() {
|
||||
public Point2D getFirstControlPoint() {
|
||||
return firstControlPoint;
|
||||
}
|
||||
|
||||
public Point getPotentialControlPoint() {
|
||||
public Point2D getPotentialControlPoint() {
|
||||
return potentialControlPoint;
|
||||
}
|
||||
|
||||
public void setPotentialControlPoint(Point potentialControlPoint) {
|
||||
public void setPotentialControlPoint(Point2D potentialControlPoint) {
|
||||
this.potentialControlPoint = potentialControlPoint;
|
||||
}
|
||||
|
||||
@@ -105,10 +105,10 @@ public class InstantiationManager {
|
||||
} else {
|
||||
switch (componentTypeSlot.getCreationMethod()) {
|
||||
case POINT_BY_POINT:
|
||||
this.componentSlot = forceInstatiate ? instantiateComponent(componentTypeSlot, template, new Point(0, 0), currentProject) : null;
|
||||
this.componentSlot = forceInstatiate ? instantiateComponent(componentTypeSlot, template, new Point2D.Double(0, 0), currentProject) : null;
|
||||
break;
|
||||
case SINGLE_CLICK:
|
||||
this.componentSlot = instantiateComponent(componentTypeSlot, template, new Point(0, 0), currentProject);
|
||||
this.componentSlot = instantiateComponent(componentTypeSlot, template, new Point2D.Double(0, 0), currentProject);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -116,7 +116,7 @@ public class InstantiationManager {
|
||||
this.potentialControlPoint = null;
|
||||
}
|
||||
|
||||
public void instatiatePointByPoint(Point scaledPoint, Project currentProject) throws Exception {
|
||||
public void instatiatePointByPoint(Point2D scaledPoint, Project currentProject) throws Exception {
|
||||
firstControlPoint = scaledPoint;
|
||||
componentSlot = instantiateComponent(componentTypeSlot, template, firstControlPoint, currentProject);
|
||||
|
||||
@@ -132,7 +132,7 @@ public class InstantiationManager {
|
||||
* @param scaledPoint
|
||||
* @return true, if any change is made
|
||||
*/
|
||||
public boolean updatePointByPoint(Point scaledPoint) {
|
||||
public boolean updatePointByPoint(Point2D scaledPoint) {
|
||||
boolean changeMade = !scaledPoint.equals(potentialControlPoint);
|
||||
potentialControlPoint = scaledPoint;
|
||||
if (componentSlot != null && !componentSlot.isEmpty()) {
|
||||
@@ -142,14 +142,14 @@ public class InstantiationManager {
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void pasteComponents(Collection<IDIYComponent<?>> components, Point scaledPoint, boolean snapToGrid,
|
||||
public void pasteComponents(Collection<IDIYComponent<?>> components, Point2D scaledPoint, boolean snapToGrid,
|
||||
Size gridSpacing, boolean autoGroup, Project currentProject, boolean assignNewNames) {
|
||||
// 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;
|
||||
double minX = Integer.MAX_VALUE;
|
||||
double maxX = Integer.MIN_VALUE;
|
||||
double minY = Integer.MAX_VALUE;
|
||||
double maxY = Integer.MIN_VALUE;
|
||||
|
||||
Set<String> existingNames = new HashSet<String>();
|
||||
for (IDIYComponent<?> c : currentProject.getComponents())
|
||||
@@ -169,32 +169,32 @@ public class InstantiationManager {
|
||||
}
|
||||
|
||||
for (int i = 0; i < component.getControlPointCount(); i++) {
|
||||
Point p = component.getControlPoint(i);
|
||||
if (p.x > maxX) {
|
||||
maxX = p.x;
|
||||
Point2D p = component.getControlPoint(i);
|
||||
if (p.getX() > maxX) {
|
||||
maxX = p.getX();
|
||||
}
|
||||
if (p.x < minX) {
|
||||
minX = p.x;
|
||||
if (p.getX() < minX) {
|
||||
minX = p.getX();
|
||||
}
|
||||
if (p.y > maxY) {
|
||||
maxY = p.y;
|
||||
if (p.getY() > maxY) {
|
||||
maxY = p.getY();
|
||||
}
|
||||
if (p.y < minY) {
|
||||
minY = p.y;
|
||||
if (p.getY() < minY) {
|
||||
minY = p.getY();
|
||||
}
|
||||
}
|
||||
}
|
||||
int x = minX;
|
||||
int y = minY;
|
||||
double x = minX;
|
||||
double y = minY;
|
||||
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);
|
||||
Point2D p = component.getControlPoint(i);
|
||||
Point2D newP = new Point2D.Double(p.getX() - x, p.getY() - y);
|
||||
component.setControlPoint(newP, i);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -206,7 +206,7 @@ public class InstantiationManager {
|
||||
this.componentTypeSlot = autoGroup ? blockType : clipboardType;
|
||||
|
||||
if (snapToGrid) {
|
||||
scaledPoint = new Point(scaledPoint);
|
||||
scaledPoint = new Point2D.Double(scaledPoint.getX(), scaledPoint.getY());
|
||||
CalcUtils.snapPointToGrid(scaledPoint, gridSpacing);
|
||||
}
|
||||
// Update the location according to mouse location
|
||||
@@ -221,15 +221,15 @@ public class InstantiationManager {
|
||||
* @param gridSpacing
|
||||
* @return true if we need to refresh the canvas
|
||||
*/
|
||||
public boolean updateSingleClick(Point scaledPoint, boolean snapToGrid, Size gridSpacing) {
|
||||
public boolean updateSingleClick(Point2D scaledPoint, boolean snapToGrid, Size gridSpacing) {
|
||||
if (potentialControlPoint == null) {
|
||||
potentialControlPoint = new Point(0, 0);
|
||||
potentialControlPoint = new Point2D.Double(0, 0);
|
||||
}
|
||||
if (scaledPoint == null) {
|
||||
scaledPoint = new Point(0, 0);
|
||||
scaledPoint = new Point2D.Double(0, 0);
|
||||
}
|
||||
int dx = scaledPoint.x - potentialControlPoint.x;
|
||||
int dy = scaledPoint.y - potentialControlPoint.y;
|
||||
double dx = scaledPoint.getX() - potentialControlPoint.getX();
|
||||
double dy = scaledPoint.getY() - potentialControlPoint.getY();
|
||||
if (snapToGrid) {
|
||||
dx = CalcUtils.roundToGrid(dx, gridSpacing);
|
||||
dy = CalcUtils.roundToGrid(dy, gridSpacing);
|
||||
@@ -238,15 +238,15 @@ public class InstantiationManager {
|
||||
if (dx == 0 && dy == 0) {
|
||||
return false;
|
||||
}
|
||||
potentialControlPoint.translate(dx, dy);
|
||||
potentialControlPoint.setLocation(potentialControlPoint.getX() + dx, potentialControlPoint.getY() + dy);
|
||||
if (componentSlot == null) {
|
||||
LOG.error("Component slot should not be null!");
|
||||
} else {
|
||||
Point p = new Point();
|
||||
Point2D p = new Point2D.Double();
|
||||
for (IDIYComponent<?> component : componentSlot) {
|
||||
for (int i = 0; i < component.getControlPointCount(); i++) {
|
||||
p.setLocation(component.getControlPoint(i));
|
||||
p.translate(dx, dy);
|
||||
for (int i = 0; i < component.getControlPointCount(); i++) {
|
||||
Point2D oldP = component.getControlPoint(i);
|
||||
p.setLocation(oldP.getX() + dx, oldP.getY() + dy);
|
||||
component.setControlPoint(p, i);
|
||||
}
|
||||
}
|
||||
@@ -255,7 +255,7 @@ public class InstantiationManager {
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public List<IDIYComponent<?>> instantiateComponent(ComponentType componentType, Template template, Point point,
|
||||
public List<IDIYComponent<?>> instantiateComponent(ComponentType componentType, Template template, Point2D point,
|
||||
Project currentProject) throws InstantiationException, IllegalAccessException {
|
||||
LOG.info("Instatiating component of type: " + componentType.getInstanceClass().getName());
|
||||
|
||||
@@ -266,9 +266,9 @@ public class InstantiationManager {
|
||||
|
||||
// Translate them to the desired location.
|
||||
if (point != null) {
|
||||
for (int j = 0; j < component.getControlPointCount(); j++) {
|
||||
Point controlPoint = new Point(component.getControlPoint(j));
|
||||
controlPoint.translate(point.x, point.y);
|
||||
for (int j = 0; j < component.getControlPointCount(); j++) {
|
||||
Point2D p = component.getControlPoint(j);
|
||||
Point2D controlPoint = new Point2D.Double(p.getX() + point.getX(), p.getY() + point.getY());
|
||||
// snapPointToGrid(controlPoint);
|
||||
component.setControlPoint(controlPoint, j);
|
||||
}
|
||||
@@ -387,9 +387,9 @@ public class InstantiationManager {
|
||||
public void loadComponentShapeFromTemplate(IDIYComponent<?> component, Template template) {
|
||||
if (template != null && template.getPoints() != null
|
||||
&& template.getPoints().size() >= component.getControlPointCount()) {
|
||||
for (int i = 0; i < component.getControlPointCount(); i++) {
|
||||
Point p = new Point(component.getControlPoint(0));
|
||||
p.translate(template.getPoints().get(i).x, template.getPoints().get(i).y);
|
||||
for (int i = 0; i < component.getControlPointCount(); i++) {
|
||||
Point2D oldP = component.getControlPoint(0);
|
||||
Point2D p = new Point2D.Double(oldP.getX() + template.getPoints().get(i).getX(), oldP.getY() + template.getPoints().get(i).getY());
|
||||
component.setControlPoint(p, i);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -202,10 +202,10 @@ public class Presenter implements IPlugInPort {
|
||||
// D&D
|
||||
private boolean dragInProgress = false;
|
||||
// Previous mouse location, not scaled for zoom factor.
|
||||
private Point previousDragPoint = null;
|
||||
private Point2D previousDragPoint = null;
|
||||
private Project preDragProject = null;
|
||||
private int dragAction;
|
||||
private Point previousScaledPoint;
|
||||
private Point2D previousScaledPoint;
|
||||
|
||||
private DIYTest test = null;
|
||||
|
||||
@@ -246,8 +246,8 @@ public class Presenter implements IPlugInPort {
|
||||
// IPlugInPort
|
||||
|
||||
@Override
|
||||
public Double[] getAvailableZoomLevels() {
|
||||
return new Double[] {0.25d, 0.3333d, 0.5d, 0.6667d, 0.75d, 1d, 1.25d, 1.5d, 2d, 2.5d, 3d};
|
||||
public java.lang.Double[] getAvailableZoomLevels() {
|
||||
return new java.lang.Double[] {0.25d, 0.3333d, 0.5d, 0.6667d, 0.75d, 1d, 1.25d, 1.5d, 2d, 2.5d, 3d};
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -502,7 +502,7 @@ public class Presenter implements IPlugInPort {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Graphics2D g2d, Set<DrawOption> drawOptions, final IComponentFilter filter, Double externalZoom, Rectangle2D visibleRect) {
|
||||
public void draw(Graphics2D g2d, Set<DrawOption> drawOptions, final IComponentFilter filter, java.lang.Double externalZoom, Rectangle2D visibleRect) {
|
||||
if (currentProject == null) {
|
||||
return;
|
||||
}
|
||||
@@ -566,7 +566,7 @@ public class Presenter implements IPlugInPort {
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public List<IDIYComponent<?>> findComponentsAtScaled(Point point, boolean includeLocked) {
|
||||
public List<IDIYComponent<?>> findComponentsAtScaled(Point2D point, boolean includeLocked) {
|
||||
List<IDIYComponent<?>> components = drawingManager.findComponentsAt(point, currentProject);
|
||||
Iterator<IDIYComponent<?>> iterator = components.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
@@ -579,8 +579,8 @@ public class Presenter implements IPlugInPort {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IDIYComponent<?>> findComponentsAt(Point point, boolean includeLocked) {
|
||||
Point scaledPoint = scalePoint(point);
|
||||
public List<IDIYComponent<?>> findComponentsAt(Point2D point, boolean includeLocked) {
|
||||
Point2D scaledPoint = scalePoint(point);
|
||||
List<IDIYComponent<?>> components = findComponentsAtScaled(scaledPoint, includeLocked);
|
||||
return components;
|
||||
}
|
||||
@@ -601,7 +601,7 @@ public class Presenter implements IPlugInPort {
|
||||
test.addStep(DIYTest.MOUSE_CLICKED, params);
|
||||
}
|
||||
|
||||
Point scaledPoint = scalePoint(point);
|
||||
Point2D scaledPoint = scalePoint(point);
|
||||
if (clickCount >= 2) {
|
||||
editSelection();
|
||||
} else {
|
||||
@@ -728,9 +728,9 @@ public class Presenter implements IPlugInPort {
|
||||
}
|
||||
}
|
||||
|
||||
private void addPendingComponentsToProject(Point scaledPoint, ComponentType componentTypeSlot, Template template) {
|
||||
private void addPendingComponentsToProject(Point2D scaledPoint, ComponentType componentTypeSlot, Template template) {
|
||||
List<IDIYComponent<?>> componentSlot = instantiationManager.getComponentSlot();
|
||||
Point firstPoint = componentSlot.get(0).getControlPoint(0);
|
||||
Point2D firstPoint = componentSlot.get(0).getControlPoint(0);
|
||||
// don't allow to create component with the same points
|
||||
if (scaledPoint == null || scaledPoint.equals(firstPoint))
|
||||
return;
|
||||
@@ -924,7 +924,7 @@ public class Presenter implements IPlugInPort {
|
||||
for (int i = currentProject.getComponents().size() - 1; i >= 0; i--) {
|
||||
IDIYComponent<?> component = currentProject.getComponents().get(i);
|
||||
for (int pointIndex = 0; pointIndex < component.getControlPointCount(); pointIndex++) {
|
||||
Point controlPoint = component.getControlPoint(pointIndex);
|
||||
Point2D controlPoint = component.getControlPoint(pointIndex);
|
||||
// Only consider selected components that are not grouped.
|
||||
if (selectedComponents.contains(component) && component.canPointMoveFreely(pointIndex)
|
||||
&& findAllGroupedComponents(component).size() == 1) {
|
||||
@@ -945,7 +945,7 @@ public class Presenter implements IPlugInPort {
|
||||
}
|
||||
|
||||
Point2D inPoint =
|
||||
new Point2D.Double(1.0d * previousScaledPoint.x / Constants.PIXELS_PER_INCH, 1.0d * previousScaledPoint.y
|
||||
new Point2D.Double(1.0d * previousScaledPoint.getX() / Constants.PIXELS_PER_INCH, 1.0d * previousScaledPoint.getY()
|
||||
/ Constants.PIXELS_PER_INCH);
|
||||
Point2D mmPoint =
|
||||
new Point2D.Double(inPoint.getX() * SizeUnit.in.getFactor() / SizeUnit.cm.getFactor() * 10d, inPoint.getY()
|
||||
@@ -1123,7 +1123,7 @@ public class Presenter implements IPlugInPort {
|
||||
this.dragInProgress = true;
|
||||
this.dragAction = dragAction;
|
||||
this.preDragProject = currentProject.clone();
|
||||
Point scaledPoint = scalePoint(point);
|
||||
Point2D scaledPoint = scalePoint(point);
|
||||
this.previousDragPoint = scaledPoint;
|
||||
List<IDIYComponent<?>> components = forceSelectionRect ? null : findComponentsAtScaled(scaledPoint, false);
|
||||
if (controlPointMap != null && !this.controlPointMap.isEmpty()) {
|
||||
@@ -1207,9 +1207,9 @@ public class Presenter implements IPlugInPort {
|
||||
break;
|
||||
}
|
||||
for (Integer j : entry.getValue()) {
|
||||
Point firstPoint = component.getControlPoint(i);
|
||||
Point2D firstPoint = component.getControlPoint(i);
|
||||
if (entry.getKey().isControlPointSticky(j)) {
|
||||
Point secondPoint = entry.getKey().getControlPoint(j);
|
||||
Point2D secondPoint = entry.getKey().getControlPoint(j);
|
||||
// If they are close enough we can consider
|
||||
// them matched.
|
||||
if (firstPoint.distance(secondPoint) < DrawingManager.CONTROL_POINT_SIZE) {
|
||||
@@ -1278,23 +1278,24 @@ public class Presenter implements IPlugInPort {
|
||||
if (point == null || configManager.readBoolean(HIGHLIGHT_CONTINUITY_AREA, false)) {
|
||||
return false;
|
||||
}
|
||||
Point scaledPoint = scalePoint(point);
|
||||
Point2D scaledPoint = scalePoint(point);
|
||||
if (controlPointMap != null && !controlPointMap.isEmpty()) {
|
||||
// We're dragging control point(s).
|
||||
int dx = (scaledPoint.x - previousDragPoint.x);
|
||||
int dy = (scaledPoint.y - previousDragPoint.y);
|
||||
int dx = (int) (scaledPoint.getX() - previousDragPoint.getX());
|
||||
int dy = (int) (scaledPoint.getY() - previousDragPoint.getY());
|
||||
|
||||
Point actualD = moveComponents(this.controlPointMap, dx, dy, isSnapToGrid(), isSnapToObjects());
|
||||
Point2D actualD = moveComponents(this.controlPointMap, dx, dy, isSnapToGrid(), isSnapToObjects());
|
||||
if (actualD == null)
|
||||
return true;
|
||||
|
||||
previousDragPoint.translate(actualD.x, actualD.y);
|
||||
previousDragPoint.setLocation(previousDragPoint.getX() + actualD.getX(), previousDragPoint.getY() + actualD.getY());
|
||||
} else if (selectedComponents.isEmpty() && instantiationManager.getComponentTypeSlot() == null
|
||||
&& previousDragPoint != null) {
|
||||
// If there's no selection, the only thing to do is update the
|
||||
// selection rectangle and refresh.
|
||||
Rectangle oldSelectionRect = selectionRect == null ? null : new Rectangle(selectionRect);
|
||||
this.selectionRect = Utils.createRectangle(scaledPoint, previousDragPoint);
|
||||
this.selectionRect = Utils.createRectangle(new Point((int)scaledPoint.getX(), (int)scaledPoint.getY()),
|
||||
new Point((int)previousDragPoint.getX(), (int)previousDragPoint.getY()));
|
||||
if (selectionRect.equals(oldSelectionRect)) {
|
||||
return true;
|
||||
}
|
||||
@@ -1308,11 +1309,11 @@ public class Presenter implements IPlugInPort {
|
||||
return true;
|
||||
}
|
||||
|
||||
private Point moveComponents(Map<IDIYComponent<?>, Set<Integer>> controlPointMap, int dx, int dy, boolean snapToGrid, boolean snapToObjects) {
|
||||
private Point2D moveComponents(Map<IDIYComponent<?>, Set<Integer>> controlPointMap, int dx, int dy, boolean snapToGrid, boolean snapToObjects) {
|
||||
// After we make the transfer and snap to grid, calculate actual dx
|
||||
// and dy. We'll use them to translate the previous drag point.
|
||||
int actualDx = 0;
|
||||
int actualDy = 0;
|
||||
double actualDx = 0;
|
||||
double actualDy = 0;
|
||||
// For each component, do a simulation of the move to see if any of
|
||||
// them will overlap or go out of bounds.
|
||||
|
||||
@@ -1323,17 +1324,16 @@ public class Presenter implements IPlugInPort {
|
||||
if (controlPointMap.size() == 1) {
|
||||
Map.Entry<IDIYComponent<?>, Set<Integer>> entry = controlPointMap.entrySet().iterator().next();
|
||||
|
||||
Point firstPoint = entry.getKey().getControlPoint(entry.getValue().toArray(new Integer[] {})[0]);
|
||||
Point testPoint = new Point(firstPoint);
|
||||
testPoint.translate(dx, dy);
|
||||
Point2D firstPoint = entry.getKey().getControlPoint(entry.getValue().toArray(new Integer[] {})[0]);
|
||||
Point2D testPoint = new Point2D.Double(firstPoint.getX() + dx, firstPoint.getY() + dy);
|
||||
if (snapToGrid) {
|
||||
CalcUtils.snapPointToGrid(testPoint, currentProject.getGridSpacing());
|
||||
} else if (snapToObjects) {
|
||||
CalcUtils.snapPointToObjects(testPoint, currentProject.getGridSpacing(), entry.getKey(), currentProject.getComponents());
|
||||
}
|
||||
|
||||
actualDx = testPoint.x - firstPoint.x;
|
||||
actualDy = testPoint.y - firstPoint.y;
|
||||
actualDx = testPoint.getX() - firstPoint.getX();
|
||||
actualDy = testPoint.getY() - firstPoint.getY();
|
||||
} else if (snapToGrid) {
|
||||
actualDx = CalcUtils.roundToGrid(dx, currentProject.getGridSpacing());
|
||||
actualDy = CalcUtils.roundToGrid(dy, currentProject.getGridSpacing());
|
||||
@@ -1350,16 +1350,16 @@ public class Presenter implements IPlugInPort {
|
||||
// Validate if moving can be done.
|
||||
for (Map.Entry<IDIYComponent<?>, Set<Integer>> entry : controlPointMap.entrySet()) {
|
||||
IDIYComponent<?> component = entry.getKey();
|
||||
Point[] controlPoints = new Point[component.getControlPointCount()];
|
||||
Point2D[] controlPoints = new Point2D[component.getControlPointCount()];
|
||||
for (int index = 0; index < component.getControlPointCount(); index++) {
|
||||
controlPoints[index] = new Point(component.getControlPoint(index));
|
||||
Point2D p = component.getControlPoint(index);
|
||||
controlPoints[index] = new Point2D.Double(p.getX(), p.getY());
|
||||
// When the first point is moved, calculate how much it
|
||||
// actually moved after snapping.
|
||||
if (entry.getValue().contains(index)) {
|
||||
controlPoints[index].translate(actualDx, actualDy);
|
||||
controlPoints[index].translate((int) extraSpace, (int) extraSpace);
|
||||
if (controlPoints[index].x < 0 || controlPoints[index].y < 0 || controlPoints[index].x > d.width
|
||||
|| controlPoints[index].y > d.height) {
|
||||
controlPoints[index].setLocation(controlPoints[index].getX() + actualDx + extraSpace, controlPoints[index].getY() + actualDy + extraSpace);
|
||||
if (controlPoints[index].getX() < 0 || controlPoints[index].getY() < 0 || controlPoints[index].getX() > d.width
|
||||
|| controlPoints[index].getY() > d.height) {
|
||||
// At least one control point went out of bounds.
|
||||
return null;
|
||||
}
|
||||
@@ -1386,8 +1386,8 @@ public class Presenter implements IPlugInPort {
|
||||
for (Map.Entry<IDIYComponent<?>, Set<Integer>> entry : controlPointMap.entrySet()) {
|
||||
IDIYComponent<?> c = entry.getKey();
|
||||
for (Integer index : entry.getValue()) {
|
||||
Point p = new Point(c.getControlPoint(index));
|
||||
p.translate(actualDx, actualDy);
|
||||
Point2D oldP = c.getControlPoint(index);
|
||||
Point2D p = new Point2D.Double(oldP.getX() + actualDx, oldP.getY() + actualDy);
|
||||
c.setControlPoint(p, index);
|
||||
}
|
||||
}
|
||||
@@ -1396,7 +1396,7 @@ public class Presenter implements IPlugInPort {
|
||||
drawingManager.clearComponentAreaMap();
|
||||
drawingManager.clearContinuityArea();
|
||||
|
||||
return new Point(actualDx, actualDy);
|
||||
return new Point2D.Double(actualDx, actualDy);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1418,7 +1418,7 @@ public class Presenter implements IPlugInPort {
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
private void rotateComponents(Collection<IDIYComponent<?>> components, int direction, boolean snapToGrid) {
|
||||
Point center = getCenterOf(components, snapToGrid);
|
||||
Point2D center = getCenterOf(components, snapToGrid);
|
||||
|
||||
boolean canRotate = true;
|
||||
for (IDIYComponent<?> component : selectedComponents) {
|
||||
@@ -1527,7 +1527,7 @@ public class Presenter implements IPlugInPort {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private void mirrorComponents(Collection<IDIYComponent<?>> components, int direction, boolean snapToGrid) {
|
||||
Point center = getCenterOf(components, snapToGrid);
|
||||
Point2D center = getCenterOf(components, snapToGrid);
|
||||
|
||||
boolean canMirror = true;
|
||||
boolean changesCircuit = false;
|
||||
@@ -1567,38 +1567,38 @@ public class Presenter implements IPlugInPort {
|
||||
drawingManager.clearContinuityArea();
|
||||
}
|
||||
|
||||
private Point getCenterOf(Collection<IDIYComponent<?>> components, boolean snapToGrid) {
|
||||
private Point2D getCenterOf(Collection<IDIYComponent<?>> components, boolean snapToGrid) {
|
||||
// Determine center of rotation
|
||||
int minX = Integer.MAX_VALUE;
|
||||
int minY = Integer.MAX_VALUE;
|
||||
int maxX = Integer.MIN_VALUE;
|
||||
int maxY = Integer.MIN_VALUE;
|
||||
double minX = Integer.MAX_VALUE;
|
||||
double minY = Integer.MAX_VALUE;
|
||||
double maxX = Integer.MIN_VALUE;
|
||||
double maxY = Integer.MIN_VALUE;
|
||||
for (IDIYComponent<?> component : components) {
|
||||
for (int i = 0; i < component.getControlPointCount(); i++) {
|
||||
Point p = component.getControlPoint(i);
|
||||
if (minX > p.x) {
|
||||
minX = p.x;
|
||||
Point2D p = component.getControlPoint(i);
|
||||
if (minX > p.getX()) {
|
||||
minX = p.getX();
|
||||
}
|
||||
if (maxX < p.x) {
|
||||
maxX = p.x;
|
||||
if (maxX < p.getX()) {
|
||||
maxX = p.getX();
|
||||
}
|
||||
if (minY > p.y) {
|
||||
minY = p.y;
|
||||
if (minY > p.getY()) {
|
||||
minY = p.getY();
|
||||
}
|
||||
if (maxY < p.y) {
|
||||
maxY = p.y;
|
||||
if (maxY < p.getY()) {
|
||||
maxY = p.getY();
|
||||
}
|
||||
}
|
||||
}
|
||||
int centerX = (maxX + minX) / 2;
|
||||
int centerY = (maxY + minY) / 2;
|
||||
double centerX = (maxX + minX) / 2;
|
||||
double centerY = (maxY + minY) / 2;
|
||||
|
||||
if (snapToGrid) {
|
||||
CalcUtils.roundToGrid(centerX, this.currentProject.getGridSpacing());
|
||||
CalcUtils.roundToGrid(centerY, this.currentProject.getGridSpacing());
|
||||
}
|
||||
|
||||
return new Point(centerX, centerY);
|
||||
return new Point2D.Double(centerX, centerY);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1613,7 +1613,7 @@ public class Presenter implements IPlugInPort {
|
||||
test.addStep(DIYTest.DRAG_END, params);
|
||||
}
|
||||
|
||||
Point scaledPoint = scalePoint(point);
|
||||
Point2D scaledPoint = scalePoint(point);
|
||||
|
||||
if (!dragInProgress && instantiationManager.getComponentSlot() == null) {
|
||||
return;
|
||||
@@ -1623,7 +1623,8 @@ public class Presenter implements IPlugInPort {
|
||||
// If there's no selection finalize selectionRect and see which
|
||||
// components intersect with it.
|
||||
if (scaledPoint != null) {
|
||||
this.selectionRect = Utils.createRectangle(scaledPoint, previousDragPoint);
|
||||
this.selectionRect = Utils.createRectangle(new Point((int)scaledPoint.getX(), (int)scaledPoint.getY()),
|
||||
new Point((int)previousDragPoint.getX(), (int)previousDragPoint.getY()));;
|
||||
}
|
||||
List<IDIYComponent<?>> newSelection = new ArrayList<IDIYComponent<?>>();
|
||||
if (!configManager.readBoolean(HIGHLIGHT_CONTINUITY_AREA, false))
|
||||
@@ -1691,8 +1692,8 @@ public class Presenter implements IPlugInPort {
|
||||
cloned.setName(instantiationManager.createUniqueName(componentType, currentProject.getComponents()));
|
||||
newSelection.add(cloned);
|
||||
for (int i = 0; i < component.getControlPointCount(); i++) {
|
||||
Point p = component.getControlPoint(i);
|
||||
Point newPoint = new Point(p.x + grid, p.y + grid);
|
||||
Point2D p = component.getControlPoint(i);
|
||||
Point2D newPoint = new Point2D.Double(p.getX() + grid, p.getY() + grid);
|
||||
cloned.setControlPoint(newPoint, i);
|
||||
}
|
||||
currentProject.getComponents().add(cloned);
|
||||
@@ -2500,16 +2501,17 @@ public class Presenter implements IPlugInPort {
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
List<Point> points = new ArrayList<Point>();
|
||||
List<Point2D> points = new ArrayList<Point2D>();
|
||||
|
||||
for (int i = 0; i < component.getControlPointCount(); i++) {
|
||||
Point p = new Point(component.getControlPoint(i));
|
||||
Point2D oldP = component.getControlPoint(i);
|
||||
Point2D p = new Point2D.Double(oldP.getX(), oldP.getY());
|
||||
points.add(p);
|
||||
}
|
||||
int x = points.iterator().next().x;
|
||||
int y = points.iterator().next().y;
|
||||
for (Point point : points) {
|
||||
point.translate(-x, -y);
|
||||
double x = points.iterator().next().getX();
|
||||
double y = points.iterator().next().getY();
|
||||
for (Point2D point : points) {
|
||||
point.setLocation(point.getX() + x, point.getY() + y);
|
||||
}
|
||||
|
||||
Template template = new Template(variantName, values, points);
|
||||
@@ -2853,14 +2855,14 @@ public class Presenter implements IPlugInPort {
|
||||
* @param point
|
||||
* @return
|
||||
*/
|
||||
private Point scalePoint(Point point) {
|
||||
Point p =
|
||||
point == null ? null : new Point((int) (point.x / drawingManager.getZoomLevel()),
|
||||
(int) (point.y / drawingManager.getZoomLevel()));
|
||||
private Point2D scalePoint(Point2D point) {
|
||||
Point2D p =
|
||||
point == null ? null : new Point2D.Double(point.getX() / drawingManager.getZoomLevel(),
|
||||
point.getY() / drawingManager.getZoomLevel());
|
||||
|
||||
if (p != null && configManager.readBoolean(EXTRA_SPACE_KEY, true)) {
|
||||
double extraSpace = drawingManager.getExtraSpace(currentProject);
|
||||
p.translate((int) (-extraSpace), (int) (-extraSpace));
|
||||
p.setLocation(p.getX() - extraSpace, p.getY() - extraSpace);
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
@@ -3165,7 +3165,11 @@
|
||||
</versionNumber>
|
||||
<releaseDate>2020-09-04 00:00:00.000 CET</releaseDate>
|
||||
<name></name>
|
||||
<changes>
|
||||
<changes>
|
||||
<org.diylc.appframework.update.Change>
|
||||
<changeType>IMPROVEMENT</changeType>
|
||||
<description>Improved rendering precision, especially when using metric units</description>
|
||||
</org.diylc.appframework.update.Change>
|
||||
<org.diylc.appframework.update.Change>
|
||||
<changeType>NEW_FEATURE</changeType>
|
||||
<description>On MacOS the app registers to open .DIY files</description>
|
||||
|
||||
@@ -21,7 +21,6 @@
|
||||
*/
|
||||
package org.diylc.serialization;
|
||||
|
||||
import java.awt.Point;
|
||||
import java.awt.geom.Area;
|
||||
import java.awt.geom.Path2D;
|
||||
import java.awt.geom.PathIterator;
|
||||
@@ -35,7 +34,7 @@ import com.thoughtworks.xstream.io.HierarchicalStreamReader;
|
||||
import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
|
||||
|
||||
/**
|
||||
* Serializes {@link Point} objects by converting coordinates from pixels to inches, thus avoiding
|
||||
* Serializes {@link Area} objects by converting coordinates from pixels to inches, thus avoiding
|
||||
* the resolution to affect point placement.
|
||||
*
|
||||
* @author Branislav Stojkovic
|
||||
|
||||
@@ -20,19 +20,19 @@
|
||||
|
||||
*/
|
||||
package org.diylc.serialization;
|
||||
|
||||
import java.awt.Point;
|
||||
|
||||
import org.diylc.utils.Constants;
|
||||
|
||||
import com.thoughtworks.xstream.converters.Converter;
|
||||
import com.thoughtworks.xstream.converters.MarshallingContext;
|
||||
import com.thoughtworks.xstream.converters.UnmarshallingContext;
|
||||
import com.thoughtworks.xstream.io.HierarchicalStreamReader;
|
||||
|
||||
import java.awt.geom.Point2D;
|
||||
|
||||
import org.diylc.utils.Constants;
|
||||
|
||||
import com.thoughtworks.xstream.converters.Converter;
|
||||
import com.thoughtworks.xstream.converters.MarshallingContext;
|
||||
import com.thoughtworks.xstream.converters.UnmarshallingContext;
|
||||
import com.thoughtworks.xstream.io.HierarchicalStreamReader;
|
||||
import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
|
||||
|
||||
/**
|
||||
* Serializes {@link Point} objects by converting coordinates from pixels to inches, thus avoiding
|
||||
* Serializes {@link Point2D} objects by converting coordinates from pixels to inches, thus avoiding
|
||||
* the resolution to affect point placement.
|
||||
*
|
||||
* @author Branislav Stojkovic
|
||||
@@ -41,21 +41,21 @@ public class PointConverter implements Converter {
|
||||
|
||||
@Override
|
||||
public void marshal(Object object, HierarchicalStreamWriter writer, MarshallingContext context) {
|
||||
Point point = (Point) object;
|
||||
writer.addAttribute("x", Double.toString(1d * point.x / Constants.PIXELS_PER_INCH));
|
||||
writer.addAttribute("y", Double.toString(1d * point.y / Constants.PIXELS_PER_INCH));
|
||||
Point2D point = (Point2D) object;
|
||||
writer.addAttribute("x", Double.toString(1d * point.getX() / Constants.PIXELS_PER_INCH));
|
||||
writer.addAttribute("y", Double.toString(1d * point.getY() / Constants.PIXELS_PER_INCH));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
|
||||
double x = Double.parseDouble(reader.getAttribute("x"));
|
||||
double y = Double.parseDouble(reader.getAttribute("y"));
|
||||
return new Point((int) Math.round(x * Constants.PIXELS_PER_INCH), (int) Math.round(y * Constants.PIXELS_PER_INCH));
|
||||
return new Point2D.Double(x * Constants.PIXELS_PER_INCH, y * Constants.PIXELS_PER_INCH);
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
@Override
|
||||
public boolean canConvert(Class clazz) {
|
||||
return Point.class.isAssignableFrom(clazz);
|
||||
return Point2D.class.isAssignableFrom(clazz);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,7 +97,7 @@ public class ProjectFileManager {
|
||||
}
|
||||
};
|
||||
xStream.autodetectAnnotations(true);
|
||||
xStream.alias("point", java.awt.Point.class);
|
||||
xStream.alias("point", java.awt.geom.Point2D.class);
|
||||
xStream.alias("font", java.awt.Font.class);
|
||||
xStream.alias("project", Project.class);
|
||||
xStream.aliasPackage("diylc", "org.diylc.components");
|
||||
@@ -107,7 +107,7 @@ public class ProjectFileManager {
|
||||
xStream.registerConverter(new MeasureConverter());
|
||||
xStream.registerConverter(new AreaConverter());
|
||||
xStream.addImmutableType(Color.class);
|
||||
xStream.addImmutableType(java.awt.Point.class);
|
||||
xStream.addImmutableType(java.awt.geom.Point2D.class);
|
||||
xStream.addImmutableType(org.diylc.core.measures.Voltage.class);
|
||||
xStream.addImmutableType(org.diylc.core.measures.Resistance.class);
|
||||
xStream.addImmutableType(org.diylc.core.measures.Capacitance.class);
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
package org.diylc.presenter;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.diylc.core.measures.Size;
|
||||
import org.diylc.core.measures.SizeUnit;
|
||||
import org.junit.Test;
|
||||
|
||||
public class CalcUtilsTest {
|
||||
|
||||
@Test
|
||||
public void TestRoundToGrid() {
|
||||
Size spacing = new Size(1d, SizeUnit.mm);
|
||||
int value = 5;
|
||||
double s = spacing.convertToPixels();
|
||||
double targetPrev = (value - 1) * s;
|
||||
double target = value * s;
|
||||
double targetNext = (value + 1) * s;
|
||||
for (int i = -100; i <= 100; i++) {
|
||||
double rounded = CalcUtils.roundToGrid(target + i / 100.0 * s, spacing);
|
||||
double expected = i < -50 ? targetPrev : (i >= 50 ? targetNext : target);
|
||||
assertTrue("Failed at " + i + " rounded = " + rounded + "; expected = " + expected, Math.abs(rounded - expected) < 1e-10);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -21,23 +21,24 @@
|
||||
*/
|
||||
package org.diylc.testcomponents;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Point;
|
||||
|
||||
import org.diylc.components.AbstractComponent;
|
||||
import org.diylc.core.ComponentState;
|
||||
import org.diylc.core.IDIYComponent;
|
||||
import org.diylc.core.IDrawingObserver;
|
||||
import org.diylc.core.Project;
|
||||
import org.diylc.core.VisibilityPolicy;
|
||||
import org.diylc.core.annotations.ComponentDescriptor;
|
||||
import org.diylc.core.annotations.EditableProperty;
|
||||
import org.diylc.core.measures.Capacitance;
|
||||
import org.diylc.core.measures.CapacitanceUnit;
|
||||
import org.diylc.core.measures.Resistance;
|
||||
import org.diylc.core.measures.ResistanceUnit;
|
||||
import org.diylc.core.measures.Size;
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Point;
|
||||
import java.awt.geom.Point2D;
|
||||
|
||||
import org.diylc.components.AbstractComponent;
|
||||
import org.diylc.core.ComponentState;
|
||||
import org.diylc.core.IDIYComponent;
|
||||
import org.diylc.core.IDrawingObserver;
|
||||
import org.diylc.core.Project;
|
||||
import org.diylc.core.VisibilityPolicy;
|
||||
import org.diylc.core.annotations.ComponentDescriptor;
|
||||
import org.diylc.core.annotations.EditableProperty;
|
||||
import org.diylc.core.measures.Capacitance;
|
||||
import org.diylc.core.measures.CapacitanceUnit;
|
||||
import org.diylc.core.measures.Resistance;
|
||||
import org.diylc.core.measures.ResistanceUnit;
|
||||
import org.diylc.core.measures.Size;
|
||||
import org.diylc.core.measures.SizeUnit;
|
||||
|
||||
@ComponentDescriptor(name = "Mock", author = "bancika", category = "Sample", instanceNamePrefix = "M",
|
||||
@@ -51,7 +52,7 @@ public class MockDIYComponent extends AbstractComponent<Capacitance> {
|
||||
private Resistance r = new Resistance(123d, ResistanceUnit.K);
|
||||
private Size s = new Size(1d, SizeUnit.cm);
|
||||
private Color color = Color.green;
|
||||
private Point leftTopCorner = new Point(0, 0);
|
||||
private Point2D leftTopCorner = new Point(0, 0);
|
||||
private String name = "something";
|
||||
|
||||
public MockDIYComponent(String testField, Capacitance c, Resistance r, Size s, Color color, Point leftTopCorner) {
|
||||
@@ -98,12 +99,12 @@ public class MockDIYComponent extends AbstractComponent<Capacitance> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Point getControlPoint(int index) {
|
||||
public Point2D getControlPoint(int index) {
|
||||
return leftTopCorner;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setControlPoint(Point point, int index) {
|
||||
public void setControlPoint(Point2D point, int index) {
|
||||
leftTopCorner.setLocation(point);
|
||||
}
|
||||
|
||||
@@ -157,7 +158,7 @@ public class MockDIYComponent extends AbstractComponent<Capacitance> {
|
||||
public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode, Project project,
|
||||
IDrawingObserver drawingObserver) {
|
||||
g2d.setColor(componentState.equals(ComponentState.SELECTED) ? color : color.darker());
|
||||
g2d.fillRect(leftTopCorner.x, leftTopCorner.y, 200, 50);
|
||||
g2d.fillRect((int)leftTopCorner.getX(), (int)leftTopCorner.getY(), 200, 50);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user