mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-07 12:24:58 +10:00
Added "Dot Spacing" property in project settings that shows dots on
every N-th grid line intersection
This commit is contained in:
@@ -34,7 +34,8 @@ import java.util.Set;
|
||||
import org.diylc.appframework.update.VersionNumber;
|
||||
import org.diylc.core.annotations.EditableProperty;
|
||||
import org.diylc.core.annotations.MultiLineText;
|
||||
import org.diylc.core.annotations.PositiveMeasureValidator;
|
||||
import org.diylc.core.annotations.PositiveMeasureValidator;
|
||||
import org.diylc.core.annotations.PositiveNonZeroMeasureValidator;
|
||||
import org.diylc.core.measures.Size;
|
||||
import org.diylc.core.measures.SizeUnit;
|
||||
|
||||
@@ -62,7 +63,8 @@ public class Project implements Serializable, Cloneable {
|
||||
private String description;
|
||||
private Size width;
|
||||
private Size height;
|
||||
private Size gridSpacing;
|
||||
private Size gridSpacing;
|
||||
private Integer dotSpacing;
|
||||
private List<IDIYComponent<?>> components;
|
||||
private Set<Set<IDIYComponent<?>>> groups;
|
||||
private Set<Integer> lockedLayers;
|
||||
@@ -134,6 +136,17 @@ public class Project implements Serializable, Cloneable {
|
||||
|
||||
public void setGridSpacing(Size gridSpacing) {
|
||||
this.gridSpacing = gridSpacing;
|
||||
}
|
||||
|
||||
@EditableProperty(name = "Dot Spacing", validatorClass = PositiveNonZeroMeasureValidator.class)
|
||||
public Integer getDotSpacing() {
|
||||
if (dotSpacing == null)
|
||||
dotSpacing = 1;
|
||||
return dotSpacing;
|
||||
}
|
||||
|
||||
public void setDotSpacing(Integer dotSpacing) {
|
||||
this.dotSpacing = dotSpacing;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -31,13 +31,15 @@ public class Theme implements Serializable {
|
||||
private String name;
|
||||
private Color bgColor;
|
||||
private Color gridColor;
|
||||
private Color outlineColor;
|
||||
private Color outlineColor;
|
||||
private Color dotColor;
|
||||
|
||||
public Theme(String name, Color bgColor, Color gridColor, Color outlineColor) {
|
||||
public Theme(String name, Color bgColor, Color gridColor, Color dotColor, Color outlineColor) {
|
||||
super();
|
||||
this.name = name;
|
||||
this.bgColor = bgColor;
|
||||
this.gridColor = gridColor;
|
||||
this.gridColor = gridColor;
|
||||
this.dotColor = dotColor;
|
||||
this.outlineColor = outlineColor;
|
||||
}
|
||||
|
||||
@@ -51,6 +53,12 @@ public class Theme implements Serializable {
|
||||
|
||||
public Color getGridColor() {
|
||||
return gridColor;
|
||||
}
|
||||
|
||||
public Color getDotColor() {
|
||||
if (dotColor == null)
|
||||
dotColor = gridColor;
|
||||
return dotColor;
|
||||
}
|
||||
|
||||
public Color getOutlineColor() {
|
||||
@@ -61,9 +69,6 @@ public class Theme implements Serializable {
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((bgColor == null) ? 0 : bgColor.hashCode());
|
||||
result = prime * result + ((gridColor == null) ? 0 : gridColor.hashCode());
|
||||
result = prime * result + ((outlineColor == null) ? 0 : outlineColor.hashCode());
|
||||
result = prime * result + ((name == null) ? 0 : name.hashCode());
|
||||
return result;
|
||||
}
|
||||
@@ -76,22 +81,7 @@ public class Theme implements Serializable {
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
Theme other = (Theme) obj;
|
||||
if (bgColor == null) {
|
||||
if (other.bgColor != null)
|
||||
return false;
|
||||
} else if (!bgColor.equals(other.bgColor))
|
||||
return false;
|
||||
if (gridColor == null) {
|
||||
if (other.gridColor != null)
|
||||
return false;
|
||||
} else if (!gridColor.equals(other.gridColor))
|
||||
return false;
|
||||
if (outlineColor == null) {
|
||||
if (other.outlineColor != null)
|
||||
return false;
|
||||
} else if (!outlineColor.equals(other.outlineColor))
|
||||
return false;
|
||||
Theme other = (Theme) obj;
|
||||
if (name == null) {
|
||||
if (other.name != null)
|
||||
return false;
|
||||
|
||||
@@ -42,8 +42,12 @@ public class PositiveMeasureValidator implements IPropertyValidator {
|
||||
if (measure.getValue() < 0) {
|
||||
throw new ValidationException("must be greater or equal to zero.");
|
||||
}
|
||||
} else if (value instanceof Integer) {
|
||||
Integer i = (Integer) value;
|
||||
if (i < 0)
|
||||
throw new ValidationException("must be greater or equal to zero.");
|
||||
} else {
|
||||
throw new ValidationException("wrong data type, measure expected.");
|
||||
throw new ValidationException("wrong data type.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+6
-2
@@ -42,8 +42,12 @@ public class PositiveNonZeroMeasureValidator implements IPropertyValidator {
|
||||
if (measure.getValue() <= 0) {
|
||||
throw new ValidationException("must be greater than zero.");
|
||||
}
|
||||
} else {
|
||||
throw new ValidationException("wrong data type, measure expected.");
|
||||
} else if (value instanceof Integer) {
|
||||
Integer i = (Integer) value;
|
||||
if (i < 0)
|
||||
throw new ValidationException("must be greater or equal to zero.");
|
||||
} else {
|
||||
throw new ValidationException("wrong data type.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,6 +60,10 @@ public class Size extends AbstractMeasure<SizeUnit> implements Comparable<Size>
|
||||
}
|
||||
}
|
||||
throw new IllegalArgumentException("Could not parse size: " + value);
|
||||
}
|
||||
|
||||
public Size scale(double factor) {
|
||||
return new Size(value * factor, unit);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -182,6 +182,10 @@ public class DrawingManager {
|
||||
g2dWrapper.setColor(theme.getBgColor());
|
||||
g2dWrapper.fillRect(0, 0, d.width, d.height);
|
||||
g2d.clip(new Rectangle(new Point(0, 0), d));
|
||||
|
||||
// calculate size to be rendered
|
||||
double extraSpace = getExtraSpace(project) * zoom;
|
||||
Dimension dInner = getCanvasDimensions(project, zoom, false);
|
||||
|
||||
GridType gridType = GridType.LINES;
|
||||
if (drawOptions.contains(DrawOption.GRID) && gridType != GridType.NONE) {
|
||||
@@ -204,15 +208,21 @@ public class DrawingManager {
|
||||
for (double j = zoomStep; j < d.height; j += zoomStep) {
|
||||
g2dWrapper.draw(new Line2D.Double(0, j, d.width - 1, j));
|
||||
}
|
||||
// draw dots if needed
|
||||
if (project.getDotSpacing() > 1 && zoomStep > 8) {
|
||||
g2d.setStroke(ObjectCache.getInstance().fetchZoomableStroke(gridThickness * 3));
|
||||
g2d.setColor(theme.getDotColor());
|
||||
for (double i = extraSpace + zoomStep * project.getDotSpacing(); i < extraSpace + dInner.width; i += zoomStep * project.getDotSpacing())
|
||||
for (double j = extraSpace + zoomStep * project.getDotSpacing(); j < extraSpace + dInner.height; j += zoomStep * project.getDotSpacing()) {
|
||||
g2d.fillOval((int)Math.round(i - 1), (int)Math.round(j - 1), 3, 3);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Rectangle2D extraSpaceRect = null;
|
||||
AffineTransform extraSpaceTx = null;
|
||||
// manage extra space
|
||||
double extraSpace = 0;
|
||||
if (drawOptions.contains(DrawOption.EXTRA_SPACE)) {
|
||||
Dimension dInner = getCanvasDimensions(project, zoom, false);
|
||||
extraSpace = getExtraSpace(project) * zoom;
|
||||
if (drawOptions.contains(DrawOption.EXTRA_SPACE)) {
|
||||
float borderThickness = (float) (3f * (zoom > 1 ? 1 : zoom));
|
||||
g2d.setStroke(ObjectCache.getInstance().fetchStroke(borderThickness, new float[] {borderThickness * 4, borderThickness * 4, }, 0, BasicStroke.CAP_BUTT));
|
||||
g2dWrapper.setColor(theme.getOutlineColor());
|
||||
@@ -458,7 +468,7 @@ public class DrawingManager {
|
||||
double width = project.getWidth().convertToPixels();
|
||||
double height = project.getHeight().convertToPixels();
|
||||
double targetExtraSpace = EXTRA_SPACE * Math.max(width, height);
|
||||
return CalcUtils.roundToGrid(targetExtraSpace, project.getGridSpacing());
|
||||
return CalcUtils.roundToGrid(targetExtraSpace, project.getGridSpacing().scale(project.getDotSpacing()));
|
||||
}
|
||||
|
||||
public Dimension getCanvasDimensions(Project project, Double zoomLevel, boolean includeExtraSpace) {
|
||||
@@ -488,7 +498,7 @@ public class DrawingManager {
|
||||
|
||||
public void setTheme(Theme theme) {
|
||||
this.theme = theme;
|
||||
ConfigurationManager.getInstance().writeValue(IPlugInPort.THEME_KEY, theme);
|
||||
ConfigurationManager.getInstance().writeValue(IPlugInPort.THEME_KEY, theme.getName());
|
||||
messageDispatcher.dispatchMessage(EventType.REPAINT);
|
||||
}
|
||||
|
||||
|
||||
@@ -2774,6 +2774,10 @@
|
||||
<releaseDate>2020-03-26 00:00:00.000 CET</releaseDate>
|
||||
<name></name>
|
||||
<changes>
|
||||
<org.diylc.appframework.update.Change>
|
||||
<changeType>NEW_FEATURE</changeType>
|
||||
<description>Added "Dot Spacing" property in project settings that shows dots on every N-th grid line intersection</description>
|
||||
</org.diylc.appframework.update.Change>
|
||||
<org.diylc.appframework.update.Change>
|
||||
<changeType>BUG_FIX</changeType>
|
||||
<description>Issues with circuit analysis introduced in version 4.0.1. Wires and jumpers are made non-conductive by mistake.</description>
|
||||
|
||||
@@ -38,7 +38,7 @@ public class Constants {
|
||||
public static final Stroke DASHED_STROKE = new BasicStroke(1.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10f,
|
||||
new float[] {2.0f, 4.0f}, 0.0f);
|
||||
|
||||
public static final Theme DEFAULT_THEME = new Theme("Light", Constants.CANVAS_COLOR, new Color(240, 240, 240),
|
||||
public static final Theme DEFAULT_THEME = new Theme("Light", Constants.CANVAS_COLOR, new Color(240, 240, 240), new Color(200, 200, 200),
|
||||
Color.black);
|
||||
|
||||
public static final Color TRANSPARENT_COLOR = new Color(0, 0, 0, 0);
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@@ -12,6 +12,12 @@
|
||||
<blue>193</blue>
|
||||
<alpha>255</alpha>
|
||||
</gridColor>
|
||||
<dotColor>
|
||||
<red>142</red>
|
||||
<green>219</green>
|
||||
<blue>255</blue>
|
||||
<alpha>255</alpha>
|
||||
</dotColor>
|
||||
<outlineColor>
|
||||
<red>255</red>
|
||||
<green>255</green>
|
||||
|
||||
@@ -12,6 +12,12 @@
|
||||
<blue>40</blue>
|
||||
<alpha>255</alpha>
|
||||
</gridColor>
|
||||
<dotColor>
|
||||
<red>60</red>
|
||||
<green>60</green>
|
||||
<blue>60</blue>
|
||||
<alpha>255</alpha>
|
||||
</dotColor>
|
||||
<outlineColor>
|
||||
<red>255</red>
|
||||
<green>255</green>
|
||||
|
||||
@@ -12,6 +12,12 @@
|
||||
<blue>240</blue>
|
||||
<alpha>240</alpha>
|
||||
</gridColor>
|
||||
<dotColor>
|
||||
<red>200</red>
|
||||
<green>200</green>
|
||||
<blue>200</blue>
|
||||
<alpha>240</alpha>
|
||||
</dotColor>
|
||||
<outlineColor>
|
||||
<red>0</red>
|
||||
<green>0</green>
|
||||
|
||||
Reference in New Issue
Block a user