mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-11 01:32:08 +10:00
This commit is contained in:
+6
@@ -0,0 +1,6 @@
|
||||
package com.diyfever.diylc.model;
|
||||
|
||||
public enum ComponentLayer {
|
||||
|
||||
BELOW_CHASSIS, CHASSIS, BELOW_BOARD, BOARD, TRACE, COMPONENT, ABOVE_COMPONENT;
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
package com.diyfever.diylc.model;
|
||||
|
||||
public enum ComponentState {
|
||||
|
||||
NORMAL, SELECTED, LOCKED
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
package com.diyfever.diylc.model;
|
||||
|
||||
import java.awt.Graphics2D;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* Interface for component instance. Implementation classes of this interface
|
||||
* will be instantiated by the application when component is added to the
|
||||
* canvas. <br>
|
||||
* <br>
|
||||
* <b>Note: </b>Implementing classes must have an empty constructor.
|
||||
*
|
||||
* @author Branislav Stojkovic
|
||||
*
|
||||
* @see IComponentType
|
||||
*/
|
||||
public interface IComponentInstance extends Serializable {
|
||||
|
||||
/**
|
||||
* Draws the component onto the {@link Graphics2D}.
|
||||
*
|
||||
* @param g2d
|
||||
* @param componentState
|
||||
*/
|
||||
void draw(Graphics2D g2d, ComponentState componentState);
|
||||
|
||||
// IComponentInstance clone() throws CloneNotSupportedException;
|
||||
}
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
package com.diyfever.diylc.model;
|
||||
|
||||
import javax.swing.Icon;
|
||||
|
||||
/**
|
||||
* Interface used to describe a component type.
|
||||
*
|
||||
* @author Branislav Stojkovic
|
||||
*
|
||||
* @see IComponentInstance
|
||||
*/
|
||||
public interface IComponentType {
|
||||
|
||||
/**
|
||||
* Returns component type name.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
String getName();
|
||||
|
||||
/**
|
||||
* Returns component category.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
String getCategory();
|
||||
|
||||
/**
|
||||
* Returns component type description that may contain HTML tags.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
String getDescription();
|
||||
|
||||
/**
|
||||
* Returns an {@link Icon} used to represent component type.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
Icon getIcon();
|
||||
|
||||
/**
|
||||
* Returns a {@link ComponentLayer} where this component belongs.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
ComponentLayer getComponentLayer();
|
||||
|
||||
/**
|
||||
* Returns class that represents component instances of this component type.
|
||||
* Application will instantiate objects of this class when components are
|
||||
* created.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
Class<? extends IComponentInstance> getComponentInstanceClass();
|
||||
}
|
||||
+157
@@ -0,0 +1,157 @@
|
||||
package com.diyfever.diylc.model;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.diyfever.diylc.model.annotations.EditableProperty;
|
||||
import com.diyfever.diylc.model.measures.Size;
|
||||
import com.diyfever.diylc.model.measures.SizeUnit;
|
||||
|
||||
public class Project implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private String title;
|
||||
private String author;
|
||||
private String description;
|
||||
private Size width;
|
||||
private Size height;
|
||||
private List<IComponentInstance> components;
|
||||
|
||||
public Project() {
|
||||
components = new ArrayList<IComponentInstance>();
|
||||
title = "New Project";
|
||||
author = System.getProperty("user.name");
|
||||
width = new Size(29d, SizeUnit.cm);
|
||||
height = new Size(21d, SizeUnit.cm);
|
||||
}
|
||||
|
||||
public Project(String title, String author, String description, Size width,
|
||||
Size height, List<IComponentInstance> components) {
|
||||
super();
|
||||
this.title = title;
|
||||
this.author = author;
|
||||
this.description = description;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this.components = components;
|
||||
}
|
||||
|
||||
@EditableProperty
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
@EditableProperty
|
||||
public String getAuthor() {
|
||||
return author;
|
||||
}
|
||||
|
||||
public void setAuthor(String author) {
|
||||
this.author = author;
|
||||
}
|
||||
|
||||
@EditableProperty
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
@EditableProperty
|
||||
public Size getWidth() {
|
||||
return width;
|
||||
}
|
||||
|
||||
public void setWidth(Size width) {
|
||||
this.width = width;
|
||||
}
|
||||
|
||||
@EditableProperty
|
||||
public Size getHeight() {
|
||||
return height;
|
||||
}
|
||||
|
||||
public void setHeight(Size height) {
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
public List<IComponentInstance> getComponents() {
|
||||
return components;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((author == null) ? 0 : author.hashCode());
|
||||
result = prime * result
|
||||
+ ((components == null) ? 0 : components.hashCode());
|
||||
result = prime * result
|
||||
+ ((description == null) ? 0 : description.hashCode());
|
||||
result = prime * result + ((height == null) ? 0 : height.hashCode());
|
||||
result = prime * result + ((title == null) ? 0 : title.hashCode());
|
||||
result = prime * result + ((width == null) ? 0 : width.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
Project other = (Project) obj;
|
||||
if (author == null) {
|
||||
if (other.author != null)
|
||||
return false;
|
||||
} else if (!author.equals(other.author))
|
||||
return false;
|
||||
if (components == null) {
|
||||
if (other.components != null)
|
||||
return false;
|
||||
} else if (!components.equals(other.components))
|
||||
return false;
|
||||
if (description == null) {
|
||||
if (other.description != null)
|
||||
return false;
|
||||
} else if (!description.equals(other.description))
|
||||
return false;
|
||||
if (height == null) {
|
||||
if (other.height != null)
|
||||
return false;
|
||||
} else if (!height.equals(other.height))
|
||||
return false;
|
||||
if (title == null) {
|
||||
if (other.title != null)
|
||||
return false;
|
||||
} else if (!title.equals(other.title))
|
||||
return false;
|
||||
if (width == null) {
|
||||
if (other.width != null)
|
||||
return false;
|
||||
} else if (!width.equals(other.width))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public Project clone() throws CloneNotSupportedException {
|
||||
// List<IComponentInstance> clonedComponents = new ArrayList<IComponentInstance>();
|
||||
// for (IComponentInstance component : components) {
|
||||
// clonedComponents.add(component.clone());
|
||||
// }
|
||||
// Project project = new Project(title, author, description,
|
||||
// width.clone(), height.clone(), clonedComponents);
|
||||
// return project;
|
||||
// }
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
package com.diyfever.diylc.model;
|
||||
|
||||
public enum VisibilityPolicy {
|
||||
|
||||
ALWAYS, WHEN_SELECTED, NEVER;
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
package com.diyfever.diylc.model.annotations;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface BomName {
|
||||
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
package com.diyfever.diylc.model.annotations;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface BomValue {
|
||||
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
package com.diyfever.diylc.model.annotations;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface ComponentName {
|
||||
|
||||
}
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
package com.diyfever.diylc.model.annotations;
|
||||
|
||||
import java.awt.Point;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
import com.diyfever.diylc.model.VisibilityPolicy;
|
||||
|
||||
/**
|
||||
* Annotation for control points. This annotation may be added to a field XYZ of
|
||||
* type {@link Point} only when both getters and setters for that property
|
||||
* exist. Annotation is added always on the getter.
|
||||
*
|
||||
* @author Branislav Stojkovic
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface ControlPoint {
|
||||
|
||||
/**
|
||||
* Determines when should the control point be rendered on the screen.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
VisibilityPolicy visibilityPolicy() default VisibilityPolicy.ALWAYS;
|
||||
|
||||
/**
|
||||
* If true, application will allow the user to edit the control point.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
boolean editable() default true;
|
||||
|
||||
/**
|
||||
* If true, the control point may be joined with other components' control
|
||||
* points.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
boolean sticky() default true;
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
package com.diyfever.diylc.model.annotations;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
/**
|
||||
* Used to annotate editable component property. Editable property XYZ must have
|
||||
* both getter and setter named <code>getXYZ</code> and <code>setXYZ</code>
|
||||
* respectively and this annotation must be placed on the getter method.
|
||||
*
|
||||
* @author Branislav Stojkovic
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface EditableProperty {
|
||||
|
||||
/**
|
||||
* Returns property name. If left blank property name will be extracted from
|
||||
* the getter name, e.g. getter <code>getXYZ</code> will induce property
|
||||
* name <code>XYZ</code>.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
String name() default "";
|
||||
|
||||
/**
|
||||
* If true, application may set default value for this property.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
boolean defaultable() default false;
|
||||
}
|
||||
+77
@@ -0,0 +1,77 @@
|
||||
package com.diyfever.diylc.model.measures;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.Format;
|
||||
|
||||
public class AbstractMeasure<T extends Enum<? extends Unit>> implements
|
||||
Serializable, Cloneable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
protected static final Format format = new DecimalFormat("0.00");
|
||||
|
||||
protected Double value;
|
||||
protected T unit;
|
||||
|
||||
public AbstractMeasure() {
|
||||
}
|
||||
|
||||
public AbstractMeasure(Double value, T unit) {
|
||||
super();
|
||||
this.value = value;
|
||||
this.unit = unit;
|
||||
}
|
||||
|
||||
public Double getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(Double value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public T getUnit() {
|
||||
return unit;
|
||||
}
|
||||
|
||||
public void setUnit(T multiplier) {
|
||||
this.unit = multiplier;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((unit == null) ? 0 : unit.hashCode());
|
||||
result = prime * result + ((value == null) ? 0 : value.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
AbstractMeasure<?> other = (AbstractMeasure<?>) obj;
|
||||
if (unit == null) {
|
||||
if (other.unit != null)
|
||||
return false;
|
||||
} else if (!unit.equals(other.unit))
|
||||
return false;
|
||||
if (value == null) {
|
||||
if (other.value != null)
|
||||
return false;
|
||||
} else if (!value.equals(other.value))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return format.format(value) + " " + unit;
|
||||
}
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
package com.diyfever.diylc.model.measures;
|
||||
|
||||
public class Capacitance extends AbstractMeasure<CapacitanceUnit> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public Capacitance() {
|
||||
super();
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
public Capacitance(Double value, CapacitanceUnit unit) {
|
||||
super(value, unit);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
@Override
|
||||
public Capacitance clone() throws CloneNotSupportedException {
|
||||
return new Capacitance(value, unit);
|
||||
}
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
package com.diyfever.diylc.model.measures;
|
||||
|
||||
public enum CapacitanceUnit implements Unit {
|
||||
|
||||
pF(1, "pF"), nF(1e3, "nF"), uF(1e6, "\u03bcF"), mF(1e9, "mF"), F(1e12, "F");
|
||||
|
||||
double factor;
|
||||
String display;
|
||||
|
||||
private CapacitanceUnit(double factor, String display) {
|
||||
this.factor = factor;
|
||||
this.display = display;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getFactor() {
|
||||
return factor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return display;
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
package com.diyfever.diylc.model.measures;
|
||||
|
||||
public class Converter {
|
||||
|
||||
public static <T extends Enum<? extends Unit>> AbstractMeasure<T> convert(
|
||||
AbstractMeasure<T> measure, T newUnit) {
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
package com.diyfever.diylc.model.measures;
|
||||
|
||||
public class Inductance extends AbstractMeasure<InductanceUnit> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public Inductance() {
|
||||
super();
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
public Inductance(Double value, InductanceUnit unit) {
|
||||
super(value, unit);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
@Override
|
||||
public Inductance clone() throws CloneNotSupportedException {
|
||||
return new Inductance(value, unit);
|
||||
}
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
package com.diyfever.diylc.model.measures;
|
||||
|
||||
public enum InductanceUnit implements Unit {
|
||||
|
||||
pH(1, "pH"), nH(1e3, "nH"), uH(1e6, "\u03bcH"), mH(1e9, "mH"), H(1e12, "H");
|
||||
|
||||
double factor;
|
||||
String display;
|
||||
|
||||
private InductanceUnit(double factor, String display) {
|
||||
this.factor = factor;
|
||||
this.display = display;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getFactor() {
|
||||
return factor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return display;
|
||||
}
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
package com.diyfever.diylc.model.measures;
|
||||
|
||||
public class Resistance extends AbstractMeasure<ResistanceUnit> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public Resistance() {
|
||||
super();
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
public Resistance(Double value, ResistanceUnit multiplier) {
|
||||
super(value, multiplier);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
@Override
|
||||
public Resistance clone() throws CloneNotSupportedException {
|
||||
return new Resistance(value, unit);
|
||||
}
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
package com.diyfever.diylc.model.measures;
|
||||
|
||||
public enum ResistanceUnit implements Unit {
|
||||
|
||||
R(1, "\u03a9"), K(1e3, "K"), M(1e6, "M");
|
||||
|
||||
double factor;
|
||||
String display;
|
||||
|
||||
private ResistanceUnit(double factor, String display) {
|
||||
this.factor = factor;
|
||||
this.display = display;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getFactor() {
|
||||
return factor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return display;
|
||||
}
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
package com.diyfever.diylc.model.measures;
|
||||
|
||||
import java.awt.Toolkit;
|
||||
|
||||
public class Size extends AbstractMeasure<SizeUnit> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public static final int PIXELS_PER_INCH = Toolkit.getDefaultToolkit()
|
||||
.getScreenResolution();
|
||||
|
||||
public Size() {
|
||||
super();
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
public Size(Double value, SizeUnit unit) {
|
||||
super(value, unit);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
public int convertToPixels() {
|
||||
double factor = getUnit().getFactor() / SizeUnit.in.getFactor();
|
||||
return (int) (factor * PIXELS_PER_INCH * getValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Size clone() throws CloneNotSupportedException {
|
||||
return new Size(value, unit);
|
||||
}
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
package com.diyfever.diylc.model.measures;
|
||||
|
||||
public enum SizeUnit implements Unit {
|
||||
|
||||
mm(1d), cm(10d), m(1e4d), in(25.4d), ft(25.4d * 12), yd(9144d);
|
||||
|
||||
double factor;
|
||||
|
||||
private SizeUnit(double factor) {
|
||||
this.factor = factor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getFactor() {
|
||||
return factor;
|
||||
}
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
package com.diyfever.diylc.model.measures;
|
||||
|
||||
public interface Unit {
|
||||
|
||||
double getFactor();
|
||||
}
|
||||
Reference in New Issue
Block a user