mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-10 17:22:09 +10:00
Keep explicit dimensions in sync with control point location
This commit is contained in:
@@ -62,6 +62,10 @@ public class Size extends AbstractMeasure<SizeUnit> implements Comparable<Size>
|
|||||||
throw new IllegalArgumentException("Could not parse size: " + value);
|
throw new IllegalArgumentException("Could not parse size: " + value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Size fromPixels(double pixels, SizeUnit unit) {
|
||||||
|
return new Size(pixels / unit.getFactor() * SizeUnit.in.getFactor() / Constants.PIXELS_PER_INCH, unit);
|
||||||
|
}
|
||||||
|
|
||||||
public Size scale(double factor) {
|
public Size scale(double factor) {
|
||||||
return new Size(value * factor, unit);
|
return new Size(value * factor, unit);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3170,6 +3170,14 @@
|
|||||||
<changeType>IMPROVEMENT</changeType>
|
<changeType>IMPROVEMENT</changeType>
|
||||||
<description>Improved rendering precision, especially when using metric units</description>
|
<description>Improved rendering precision, especially when using metric units</description>
|
||||||
</org.diylc.appframework.update.Change>
|
</org.diylc.appframework.update.Change>
|
||||||
|
<org.diylc.appframework.update.Change>
|
||||||
|
<changeType>IMPROVEMENT</changeType>
|
||||||
|
<description>Improve snap to grid when moving a node that connects several components</description>
|
||||||
|
</org.diylc.appframework.update.Change>
|
||||||
|
<org.diylc.appframework.update.Change>
|
||||||
|
<changeType>IMPROVEMENT</changeType>
|
||||||
|
<description>Improved board sizing, keep explicit dimensions in sync with control point location</description>
|
||||||
|
</org.diylc.appframework.update.Change>
|
||||||
<org.diylc.appframework.update.Change>
|
<org.diylc.appframework.update.Change>
|
||||||
<changeType>IMPROVEMENT</changeType>
|
<changeType>IMPROVEMENT</changeType>
|
||||||
<description>Shorten donation label when the window is smaller</description>
|
<description>Shorten donation label when the window is smaller</description>
|
||||||
|
|||||||
Binary file not shown.
@@ -28,8 +28,10 @@ import java.awt.Graphics2D;
|
|||||||
import java.awt.geom.Point2D;
|
import java.awt.geom.Point2D;
|
||||||
import java.awt.geom.Rectangle2D;
|
import java.awt.geom.Rectangle2D;
|
||||||
|
|
||||||
|
import org.diylc.appframework.miscutils.ConfigurationManager;
|
||||||
import org.diylc.awt.StringUtils;
|
import org.diylc.awt.StringUtils;
|
||||||
import org.diylc.common.HorizontalAlignment;
|
import org.diylc.common.HorizontalAlignment;
|
||||||
|
import org.diylc.common.IPlugInPort;
|
||||||
import org.diylc.common.ObjectCache;
|
import org.diylc.common.ObjectCache;
|
||||||
import org.diylc.common.VerticalAlignment;
|
import org.diylc.common.VerticalAlignment;
|
||||||
import org.diylc.components.AbstractTransparentComponent;
|
import org.diylc.components.AbstractTransparentComponent;
|
||||||
@@ -53,8 +55,10 @@ public abstract class AbstractBoard extends AbstractTransparentComponent<String>
|
|||||||
public static Size DEFAULT_HEIGHT = new Size(1.2d, SizeUnit.in);
|
public static Size DEFAULT_HEIGHT = new Size(1.2d, SizeUnit.in);
|
||||||
|
|
||||||
protected String value = "";
|
protected String value = "";
|
||||||
|
// two control points used for controlling the position
|
||||||
protected Point2D[] controlPoints = new Point2D[] {new Point2D.Double(0, 0),
|
protected Point2D[] controlPoints = new Point2D[] {new Point2D.Double(0, 0),
|
||||||
new Point2D.Double(DEFAULT_WIDTH.convertToPixels(), DEFAULT_HEIGHT.convertToPixels())};
|
new Point2D.Double(DEFAULT_WIDTH.convertToPixels(), DEFAULT_HEIGHT.convertToPixels())};
|
||||||
|
// top-left and bottom-right points
|
||||||
protected Point2D firstPoint = new Point2D.Double();
|
protected Point2D firstPoint = new Point2D.Double();
|
||||||
protected Point2D secondPoint = new Point2D.Double();
|
protected Point2D secondPoint = new Point2D.Double();
|
||||||
|
|
||||||
@@ -307,25 +311,49 @@ public abstract class AbstractBoard extends AbstractTransparentComponent<String>
|
|||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private SizeUnit getDefaultUnit() {
|
||||||
|
if (ConfigurationManager.getInstance().readBoolean(IPlugInPort.METRIC_KEY, true))
|
||||||
|
return SizeUnit.mm;
|
||||||
|
return SizeUnit.in;
|
||||||
|
}
|
||||||
|
|
||||||
@EditableProperty(name = "Explicit Length", validatorClass = BoardModeValidator.class)
|
@EditableProperty(name = "Explicit Length", validatorClass = BoardModeValidator.class)
|
||||||
public Size getLength() {
|
public Size getLength() {
|
||||||
return length;
|
if (getMode() == BoardSizingMode.TwoPoints) {
|
||||||
|
double lengthPx = Math.abs(this.firstPoint.getX() - this.secondPoint.getX());
|
||||||
|
this.length = Size.fromPixels(lengthPx, length == null ? getDefaultUnit() : length.getUnit());
|
||||||
|
}
|
||||||
|
return this.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLength(Size length) {
|
public void setLength(Size length) {
|
||||||
|
if (getMode() == BoardSizingMode.Explicit) {
|
||||||
|
setControlPoint(firstPoint, 0);
|
||||||
|
Point2D second = new Point2D.Double(firstPoint.getX() + length.convertToPixels(), firstPoint.getY() + width.convertToPixels());
|
||||||
|
setControlPoint(second, 1);
|
||||||
|
}
|
||||||
this.length = length;
|
this.length = length;
|
||||||
}
|
}
|
||||||
|
|
||||||
@EditableProperty(name = "Explicit Width", validatorClass = BoardModeValidator.class)
|
@EditableProperty(name = "Explicit Width", validatorClass = BoardModeValidator.class)
|
||||||
public Size getWidth() {
|
public Size getWidth() {
|
||||||
return width;
|
if (getMode() == BoardSizingMode.TwoPoints) {
|
||||||
|
double widthPx = Math.abs(this.firstPoint.getY() - this.secondPoint.getY());
|
||||||
|
this.width = Size.fromPixels(widthPx, width == null ? getDefaultUnit() : width.getUnit());
|
||||||
|
}
|
||||||
|
return this.width;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setWidth(Size width) {
|
public void setWidth(Size width) {
|
||||||
|
if (getMode() == BoardSizingMode.Explicit) {
|
||||||
|
setControlPoint(firstPoint, 0);
|
||||||
|
Point2D second = new Point2D.Double(firstPoint.getX() + length.convertToPixels(), firstPoint.getY() + width.convertToPixels());
|
||||||
|
setControlPoint(second, 1);
|
||||||
|
}
|
||||||
this.width = width;
|
this.width = width;
|
||||||
}
|
}
|
||||||
|
|
||||||
@EditableProperty(name = "Sizing Mode")
|
@EditableProperty(name = "Dimension Mode")
|
||||||
public BoardSizingMode getMode() {
|
public BoardSizingMode getMode() {
|
||||||
if (mode == null)
|
if (mode == null)
|
||||||
mode = BoardSizingMode.TwoPoints;
|
mode = BoardSizingMode.TwoPoints;
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user