mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-11 01:32:08 +10:00
better measurement
This commit is contained in:
Binary file not shown.
+11
@@ -32,4 +32,15 @@ public abstract class AbstractComponent<T> implements IDIYComponent<T> {
|
|||||||
public String toString() {
|
public String toString() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the closest odd number, i.e. x when x is odd, or x + 1 when x is
|
||||||
|
* even.
|
||||||
|
*
|
||||||
|
* @param x
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
protected int getClosestOdd(int x) {
|
||||||
|
return (x / 2) * 2 + 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-1
@@ -18,7 +18,9 @@ public class Size extends AbstractMeasure<SizeUnit> {
|
|||||||
|
|
||||||
public int convertToPixels() {
|
public int convertToPixels() {
|
||||||
double factor = getUnit().getFactor() / SizeUnit.in.getFactor();
|
double factor = getUnit().getFactor() / SizeUnit.in.getFactor();
|
||||||
return (int) Math.round(factor * Constants.PIXELS_PER_INCH * getValue());
|
int grids = (int) (factor * getValue() * Constants.GRIDS_PER_INCH);
|
||||||
|
double remainder = (factor * getValue() * Constants.GRIDS_PER_INCH) - grids;
|
||||||
|
return (int) Math.round(Constants.GRID * (grids + remainder));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ import java.util.Map;
|
|||||||
|
|
||||||
import javax.swing.Action;
|
import javax.swing.Action;
|
||||||
import javax.swing.BoxLayout;
|
import javax.swing.BoxLayout;
|
||||||
import javax.swing.Icon;
|
|
||||||
import javax.swing.JComponent;
|
import javax.swing.JComponent;
|
||||||
import javax.swing.JFrame;
|
import javax.swing.JFrame;
|
||||||
import javax.swing.JMenu;
|
import javax.swing.JMenu;
|
||||||
|
|||||||
+7
-1
@@ -3,11 +3,16 @@ package org.diylc.gui.editor;
|
|||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.awt.Component;
|
import java.awt.Component;
|
||||||
|
|
||||||
|
import javax.swing.JLabel;
|
||||||
|
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
import org.diylc.common.PropertyWrapper;
|
import org.diylc.common.PropertyWrapper;
|
||||||
import org.diylc.core.measures.AbstractMeasure;
|
import org.diylc.core.measures.AbstractMeasure;
|
||||||
|
|
||||||
public class FieldEditorFactory {
|
public class FieldEditorFactory {
|
||||||
|
|
||||||
|
private static final Logger LOG = Logger.getLogger(FieldEditorFactory.class);
|
||||||
|
|
||||||
public static Component createFieldEditor(PropertyWrapper property) {
|
public static Component createFieldEditor(PropertyWrapper property) {
|
||||||
if (property.getType().equals(String.class)) {
|
if (property.getType().equals(String.class)) {
|
||||||
StringEditor editor = new StringEditor(property);
|
StringEditor editor = new StringEditor(property);
|
||||||
@@ -30,6 +35,7 @@ public class FieldEditorFactory {
|
|||||||
ByteEditor byteEditor = new ByteEditor(property);
|
ByteEditor byteEditor = new ByteEditor(property);
|
||||||
return byteEditor;
|
return byteEditor;
|
||||||
}
|
}
|
||||||
return null;
|
LOG.error("Unrecognized parameter type: " + property.getType().getName());
|
||||||
|
return new JLabel("Unrecognized");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-2
@@ -12,8 +12,9 @@ import org.diylc.core.measures.SizeUnit;
|
|||||||
public class Constants {
|
public class Constants {
|
||||||
|
|
||||||
public static final int PIXELS_PER_INCH = Toolkit.getDefaultToolkit().getScreenResolution();
|
public static final int PIXELS_PER_INCH = Toolkit.getDefaultToolkit().getScreenResolution();
|
||||||
public static Size GRID_SIZE = new Size(0.1d, SizeUnit.in);
|
public static int GRIDS_PER_INCH = 10;
|
||||||
public static final int GRID = GRID_SIZE.convertToPixels();
|
public static Size GRID_SIZE = new Size(1d / GRIDS_PER_INCH, SizeUnit.in);
|
||||||
|
public static final int GRID = 10;
|
||||||
|
|
||||||
public static Color CANVAS_COLOR = Color.white;
|
public static Color CANVAS_COLOR = Color.white;
|
||||||
public static Color GRID_COLOR = new Color(240, 240, 240);
|
public static Color GRID_COLOR = new Color(240, 240, 240);
|
||||||
|
|||||||
Binary file not shown.
+11
-13
@@ -1,7 +1,6 @@
|
|||||||
package org.diylc.components.boards;
|
package org.diylc.components.boards;
|
||||||
|
|
||||||
import java.awt.AlphaComposite;
|
import java.awt.AlphaComposite;
|
||||||
import java.awt.BasicStroke;
|
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.awt.Composite;
|
import java.awt.Composite;
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
@@ -27,7 +26,7 @@ public class PerfBoard extends AbstractBoard {
|
|||||||
|
|
||||||
private static Size SPACING = new Size(0.1d, SizeUnit.in);
|
private static Size SPACING = new Size(0.1d, SizeUnit.in);
|
||||||
private static Size PAD_SIZE = new Size(0.08d, SizeUnit.in);
|
private static Size PAD_SIZE = new Size(0.08d, SizeUnit.in);
|
||||||
private static Size HOLE_SIZE = new Size(0.8d, SizeUnit.mm);
|
private static Size HOLE_SIZE = new Size(0.7d, SizeUnit.mm);
|
||||||
|
|
||||||
// private Area copperArea;
|
// private Area copperArea;
|
||||||
private Size spacing = SPACING;
|
private Size spacing = SPACING;
|
||||||
@@ -53,21 +52,20 @@ public class PerfBoard extends AbstractBoard {
|
|||||||
/ MAX_ALPHA));
|
/ MAX_ALPHA));
|
||||||
}
|
}
|
||||||
Point p = new Point(controlPoints[0]);
|
Point p = new Point(controlPoints[0]);
|
||||||
int radius = PAD_SIZE.convertToPixels() / 2;
|
int diameter = getClosestOdd(PAD_SIZE.convertToPixels());
|
||||||
int holeRadius = HOLE_SIZE.convertToPixels() / 2;
|
int holeDiameter = getClosestOdd(HOLE_SIZE.convertToPixels());
|
||||||
g2d.setStroke(new BasicStroke(radius));
|
int spacing = this.spacing.convertToPixels();
|
||||||
|
|
||||||
while (p.y < controlPoints[1].y - spacing.convertToPixels()) {
|
while (p.y < controlPoints[1].y - spacing) {
|
||||||
p.x = controlPoints[0].x;
|
p.x = controlPoints[0].x;
|
||||||
p.y += spacing.convertToPixels();
|
p.y += spacing;
|
||||||
while (p.x < controlPoints[1].x - spacing.convertToPixels()) {
|
while (p.x < controlPoints[1].x - spacing) {
|
||||||
p.x += spacing.convertToPixels();
|
p.x += spacing;
|
||||||
g2d.setColor(COPPER_COLOR);
|
g2d.setColor(COPPER_COLOR);
|
||||||
g2d.fillOval(p.x - radius, p.y - radius, radius * 2, radius * 2);
|
g2d.fillOval(p.x - diameter / 2, p.y - diameter / 2, diameter, diameter);
|
||||||
g2d.setColor(Constants.CANVAS_COLOR);
|
g2d.setColor(Constants.CANVAS_COLOR);
|
||||||
g2d
|
g2d.fillOval(p.x - holeDiameter / 2, p.y - holeDiameter / 2, holeDiameter,
|
||||||
.fillOval(p.x - holeRadius, p.y - holeRadius, holeRadius * 2,
|
holeDiameter);
|
||||||
holeRadius * 2);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
g2d.setComposite(oldComposite);
|
g2d.setComposite(oldComposite);
|
||||||
|
|||||||
+11
-10
@@ -26,7 +26,7 @@ public class VeroBoard extends AbstractBoard {
|
|||||||
|
|
||||||
private static Size SPACING = new Size(0.1d, SizeUnit.in);
|
private static Size SPACING = new Size(0.1d, SizeUnit.in);
|
||||||
private static Size STRIP_SIZE = new Size(0.085d, SizeUnit.in);
|
private static Size STRIP_SIZE = new Size(0.085d, SizeUnit.in);
|
||||||
private static Size HOLE_SIZE = new Size(0.8d, SizeUnit.mm);
|
private static Size HOLE_SIZE = new Size(0.7d, SizeUnit.mm);
|
||||||
|
|
||||||
// private Area copperArea;
|
// private Area copperArea;
|
||||||
private Size spacing = SPACING;
|
private Size spacing = SPACING;
|
||||||
@@ -52,17 +52,18 @@ public class VeroBoard extends AbstractBoard {
|
|||||||
/ MAX_ALPHA));
|
/ MAX_ALPHA));
|
||||||
}
|
}
|
||||||
Point p = new Point(controlPoints[0]);
|
Point p = new Point(controlPoints[0]);
|
||||||
int stripSize = STRIP_SIZE.convertToPixels() / 2 * 2;
|
int stripSize = getClosestOdd(STRIP_SIZE.convertToPixels());
|
||||||
int holeRadius = HOLE_SIZE.convertToPixels() / 2;
|
int holeRadius = getClosestOdd(HOLE_SIZE.convertToPixels() / 2);
|
||||||
|
int spacing = this.spacing.convertToPixels();
|
||||||
|
|
||||||
while (p.y < controlPoints[1].y - spacing.convertToPixels()) {
|
while (p.y < controlPoints[1].y - spacing) {
|
||||||
p.x = controlPoints[0].x;
|
p.x = controlPoints[0].x;
|
||||||
p.y += spacing.convertToPixels();
|
p.y += spacing;
|
||||||
g2d.setColor(COPPER_COLOR);
|
g2d.setColor(COPPER_COLOR);
|
||||||
g2d.fillRect(p.x + SPACING.convertToPixels() / 2, p.y - stripSize / 2,
|
g2d.fillRect(p.x + SPACING.convertToPixels() / 2, p.y - stripSize / 2,
|
||||||
controlPoints[1].x - spacing.convertToPixels() - p.x, stripSize);
|
controlPoints[1].x - spacing - p.x, stripSize);
|
||||||
while (p.x < controlPoints[1].x - spacing.convertToPixels()) {
|
while (p.x < controlPoints[1].x - spacing) {
|
||||||
p.x += spacing.convertToPixels();
|
p.x += spacing;
|
||||||
g2d.setColor(Constants.CANVAS_COLOR);
|
g2d.setColor(Constants.CANVAS_COLOR);
|
||||||
g2d
|
g2d
|
||||||
.fillOval(p.x - holeRadius, p.y - holeRadius, holeRadius * 2,
|
.fillOval(p.x - holeRadius, p.y - holeRadius, holeRadius * 2,
|
||||||
@@ -153,7 +154,7 @@ public class VeroBoard extends AbstractBoard {
|
|||||||
g2d.setColor(COPPER_COLOR);
|
g2d.setColor(COPPER_COLOR);
|
||||||
g2d.fillRect(4, width / 4, width - 8, width / 2);
|
g2d.fillRect(4, width / 4, width - 8, width / 2);
|
||||||
g2d.setColor(Constants.CANVAS_COLOR);
|
g2d.setColor(Constants.CANVAS_COLOR);
|
||||||
g2d.fillOval(width / 3 - 1, width / 2 - 1, 2, 2);
|
g2d.fillOval(width / 3 - 1, width / 2 - 1, 3, 3);
|
||||||
g2d.fillOval(2 * width / 3 - 1, width / 2 - 1, 2, 2);
|
g2d.fillOval(2 * width / 3 - 1, width / 2 - 1, 3, 3);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+35
-10
@@ -2,8 +2,9 @@ package org.diylc.components.connectivity;
|
|||||||
|
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
|
import java.awt.Point;
|
||||||
|
|
||||||
import org.diylc.components.AbstractSinglePointComponent;
|
import org.diylc.components.AbstractComponent;
|
||||||
import org.diylc.core.ComponentState;
|
import org.diylc.core.ComponentState;
|
||||||
import org.diylc.core.IDIYComponent;
|
import org.diylc.core.IDIYComponent;
|
||||||
import org.diylc.core.Project;
|
import org.diylc.core.Project;
|
||||||
@@ -14,7 +15,7 @@ import org.diylc.core.measures.SizeUnit;
|
|||||||
import org.diylc.utils.Constants;
|
import org.diylc.utils.Constants;
|
||||||
|
|
||||||
@ComponentDescriptor(name = "Solder Pad", category = "Connectivity", author = "Branislav Stojkovic", description = "test", instanceNamePrefix = "", stretchable = false, zOrder = IDIYComponent.ABOVE_BOARD + 0.1)
|
@ComponentDescriptor(name = "Solder Pad", category = "Connectivity", author = "Branislav Stojkovic", description = "test", instanceNamePrefix = "", stretchable = false, zOrder = IDIYComponent.ABOVE_BOARD + 0.1)
|
||||||
public class SolderPad extends AbstractSinglePointComponent {
|
public class SolderPad extends AbstractComponent<Color> {
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
@@ -24,11 +25,12 @@ public class SolderPad extends AbstractSinglePointComponent {
|
|||||||
|
|
||||||
private Size size = SIZE;
|
private Size size = SIZE;
|
||||||
private Color color = COLOR;
|
private Color color = COLOR;
|
||||||
|
private Point point = new Point(0, 0);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void draw(Graphics2D g2d, ComponentState componentState, Project project) {
|
public void draw(Graphics2D g2d, ComponentState componentState, Project project) {
|
||||||
int diameter = size.convertToPixels();
|
int diameter = getClosestOdd(size.convertToPixels());
|
||||||
int holeDiameter = HOLE_SIZE.convertToPixels();
|
int holeDiameter = getClosestOdd(HOLE_SIZE.convertToPixels());
|
||||||
g2d.setColor(color);
|
g2d.setColor(color);
|
||||||
g2d.fillOval(point.x - diameter / 2, point.y - diameter / 2, diameter, diameter);
|
g2d.fillOval(point.x - diameter / 2, point.y - diameter / 2, diameter, diameter);
|
||||||
g2d.setColor(Constants.CANVAS_COLOR);
|
g2d.setColor(Constants.CANVAS_COLOR);
|
||||||
@@ -38,8 +40,8 @@ public class SolderPad extends AbstractSinglePointComponent {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void drawIcon(Graphics2D g2d, int width, int height) {
|
public void drawIcon(Graphics2D g2d, int width, int height) {
|
||||||
int diameter = width / 2;
|
int diameter = getClosestOdd(width / 2);
|
||||||
int holeDiameter = 4;
|
int holeDiameter = 5;
|
||||||
g2d.setColor(COLOR);
|
g2d.setColor(COLOR);
|
||||||
g2d.fillOval((width - diameter) / 2, (height - diameter) / 2, diameter, diameter);
|
g2d.fillOval((width - diameter) / 2, (height - diameter) / 2, diameter, diameter);
|
||||||
g2d.setColor(Constants.CANVAS_COLOR);
|
g2d.setColor(Constants.CANVAS_COLOR);
|
||||||
@@ -56,12 +58,35 @@ public class SolderPad extends AbstractSinglePointComponent {
|
|||||||
this.size = size;
|
this.size = size;
|
||||||
}
|
}
|
||||||
|
|
||||||
@EditableProperty
|
@Deprecated
|
||||||
public Color getColor() {
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return super.getName();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getControlPointCount() {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Point getControlPoint(int index) {
|
||||||
|
return point;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setControlPoint(Point point, int index) {
|
||||||
|
this.point.setLocation(point);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EditableProperty(name = "Color")
|
||||||
|
@Override
|
||||||
|
public Color getValue() {
|
||||||
return color;
|
return color;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setColor(Color color) {
|
@Override
|
||||||
this.color = color;
|
public void setValue(Color value) {
|
||||||
|
this.color = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+6
@@ -79,4 +79,10 @@ public class TraceCut extends AbstractSinglePointComponent {
|
|||||||
public void setBorderColor(Color borderColor) {
|
public void setBorderColor(Color borderColor) {
|
||||||
this.borderColor = borderColor;
|
this.borderColor = borderColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return super.getName();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-5
@@ -179,13 +179,13 @@ public class MiniToggleSwitch extends AbstractTransparentComponent<ToggleSwitchT
|
|||||||
g2d.draw(body);
|
g2d.draw(body);
|
||||||
}
|
}
|
||||||
if (componentState != ComponentState.DRAGGING) {
|
if (componentState != ComponentState.DRAGGING) {
|
||||||
int circleRadius = CIRCLE_SIZE.convertToPixels() / 2;
|
int circleDiameter = getClosestOdd(CIRCLE_SIZE.convertToPixels());
|
||||||
int lugWidth = LUG_WIDTH.convertToPixels();
|
int lugWidth = getClosestOdd(LUG_WIDTH.convertToPixels());
|
||||||
int lugHeight = LUG_HEIGHT.convertToPixels();
|
int lugHeight = getClosestOdd(LUG_HEIGHT.convertToPixels());
|
||||||
for (Point p : controlPoints) {
|
for (Point p : controlPoints) {
|
||||||
g2d.setColor(CIRCLE_COLOR);
|
g2d.setColor(CIRCLE_COLOR);
|
||||||
g2d.fillOval(p.x - circleRadius, p.y - circleRadius, 2 * circleRadius,
|
g2d.fillOval(p.x - circleDiameter / 2, p.y - circleDiameter / 2,
|
||||||
2 * circleRadius);
|
circleDiameter, circleDiameter);
|
||||||
g2d.setColor(LUG_COLOR);
|
g2d.setColor(LUG_COLOR);
|
||||||
g2d.fillRect(p.x - lugWidth / 2, p.y - lugHeight / 2, lugWidth, lugHeight);
|
g2d.fillRect(p.x - lugWidth / 2, p.y - lugHeight / 2, lugWidth, lugHeight);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user