mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-11 09:42:08 +10:00
This commit is contained in:
+14
@@ -0,0 +1,14 @@
|
||||
package com.diyfever.diylc;
|
||||
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Suite;
|
||||
import org.junit.runners.Suite.SuiteClasses;
|
||||
|
||||
import com.diyfever.diylc.plugins.file.BomMakerTest;
|
||||
import com.diyfever.diylc.presenter.ClassProcessorTest;
|
||||
|
||||
@RunWith(Suite.class)
|
||||
@SuiteClasses( { BomMakerTest.class, ClassProcessorTest.class })
|
||||
public class AllTests {
|
||||
|
||||
}
|
||||
+63
@@ -0,0 +1,63 @@
|
||||
package com.diyfever.diylc;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.Icon;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JScrollPane;
|
||||
|
||||
import org.apache.log4j.BasicConfigurator;
|
||||
|
||||
import com.diyfever.diylc.plugins.online.model.ProjectEntity;
|
||||
import com.diyfever.gui.objecttable.IActionProcessor;
|
||||
import com.diyfever.gui.objecttable.ObjectListTable;
|
||||
|
||||
public class TableTest {
|
||||
|
||||
/**
|
||||
* @param args
|
||||
* @throws Exception
|
||||
*/
|
||||
public static void main(String[] args) throws Exception {
|
||||
BasicConfigurator.configure();
|
||||
|
||||
List<ProjectEntity> projects = new ArrayList<ProjectEntity>();
|
||||
projects
|
||||
.add(new ProjectEntity(1, "first", "some text", "bane", "none"));
|
||||
projects.add(new ProjectEntity(2, "second", "anoter text", "bisera",
|
||||
"none"));
|
||||
|
||||
ObjectListTable<ProjectEntity> t = new ObjectListTable<ProjectEntity>(
|
||||
ProjectEntity.class, new String[] { "getName",
|
||||
"getDescription", "getCategory", "getOwner",
|
||||
"action:Download" },
|
||||
new IActionProcessor<ProjectEntity>() {
|
||||
|
||||
@Override
|
||||
public void actionExecuted(ProjectEntity value,
|
||||
String actionColumnName) {
|
||||
System.out.println("row clicked: " + actionColumnName
|
||||
+ " - " + value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Icon getActionIcon(String actionColumnName) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getActionLabel(String actionColumnName) {
|
||||
return "get me";
|
||||
}
|
||||
});
|
||||
t.setData(projects);
|
||||
JFrame f = new JFrame();
|
||||
f.add(new JScrollPane(t));
|
||||
f.pack();
|
||||
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
f.setVisible(true);
|
||||
}
|
||||
|
||||
}
|
||||
+128
@@ -0,0 +1,128 @@
|
||||
package com.diyfever.diylc.components;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Point;
|
||||
|
||||
import com.diyfever.diylc.model.ComponentState;
|
||||
import com.diyfever.diylc.model.IComponentInstance;
|
||||
import com.diyfever.diylc.model.VisibilityPolicy;
|
||||
import com.diyfever.diylc.model.annotations.BomName;
|
||||
import com.diyfever.diylc.model.annotations.BomValue;
|
||||
import com.diyfever.diylc.model.annotations.ControlPoint;
|
||||
import com.diyfever.diylc.model.annotations.EditableProperty;
|
||||
import com.diyfever.diylc.model.measures.Capacitance;
|
||||
import com.diyfever.diylc.model.measures.CapacitanceUnit;
|
||||
import com.diyfever.diylc.model.measures.Resistance;
|
||||
import com.diyfever.diylc.model.measures.ResistanceUnit;
|
||||
import com.diyfever.diylc.model.measures.Size;
|
||||
import com.diyfever.diylc.model.measures.SizeUnit;
|
||||
|
||||
public class MockComponentInstance implements IComponentInstance {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private String testField = "Hello World";
|
||||
private Capacitance c = new Capacitance(100d, CapacitanceUnit.uF);
|
||||
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 String name = "something";
|
||||
|
||||
public MockComponentInstance(String testField, Capacitance c, Resistance r,
|
||||
Size s, Color color, Point leftTopCorner) {
|
||||
super();
|
||||
this.testField = testField;
|
||||
this.c = c;
|
||||
this.r = r;
|
||||
this.s = s;
|
||||
this.color = color;
|
||||
this.leftTopCorner = leftTopCorner;
|
||||
}
|
||||
|
||||
public MockComponentInstance() {
|
||||
super();
|
||||
}
|
||||
|
||||
@BomName
|
||||
@EditableProperty
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@ControlPoint(visibilityPolicy = VisibilityPolicy.WHEN_SELECTED)
|
||||
public Point getLeftTopCorner() {
|
||||
return leftTopCorner;
|
||||
}
|
||||
|
||||
public void setLeftTopCorner(Point leftTopCorner) {
|
||||
this.leftTopCorner = leftTopCorner;
|
||||
}
|
||||
|
||||
@EditableProperty(name = "Test Field")
|
||||
public String getTestField() {
|
||||
return testField;
|
||||
}
|
||||
|
||||
public void setTestField(String testField) {
|
||||
this.testField = testField;
|
||||
}
|
||||
|
||||
@BomValue
|
||||
@EditableProperty(defaultable = true)
|
||||
public Capacitance getC() {
|
||||
return c;
|
||||
}
|
||||
|
||||
public void setC(Capacitance c) {
|
||||
this.c = c;
|
||||
}
|
||||
|
||||
@EditableProperty(defaultable = true)
|
||||
public Color getColor() {
|
||||
return color;
|
||||
}
|
||||
|
||||
public void setColor(Color color) {
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
@EditableProperty
|
||||
public Resistance getR() {
|
||||
return r;
|
||||
}
|
||||
|
||||
// Setter is commented out, ClassProcessor should ignore this property.
|
||||
// public void setR(Resistance r) {
|
||||
// this.r = r;
|
||||
// }
|
||||
|
||||
// No annotation, so this property should be ignored.
|
||||
public Size getS() {
|
||||
return s;
|
||||
}
|
||||
|
||||
public void setS(Size s) {
|
||||
this.s = s;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Graphics2D g2d, ComponentState componentState) {
|
||||
g2d.setColor(componentState.equals(ComponentState.SELECTED) ? color
|
||||
: color.darker());
|
||||
g2d.fillRect(leftTopCorner.x, leftTopCorner.y, 200, 50);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MockComponentInstance clone() throws CloneNotSupportedException {
|
||||
MockComponentInstance newInstance = new MockComponentInstance(
|
||||
testField, c.clone(), r.clone(), s.clone(), color,
|
||||
(Point) leftTopCorner.clone());
|
||||
return newInstance;
|
||||
}
|
||||
}
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
package com.diyfever.diylc.components;
|
||||
|
||||
import javax.swing.Icon;
|
||||
|
||||
import com.diyfever.diylc.images.IconLoader;
|
||||
import com.diyfever.diylc.model.ComponentLayer;
|
||||
import com.diyfever.diylc.model.IComponentInstance;
|
||||
import com.diyfever.diylc.model.IComponentType;
|
||||
|
||||
public class MockComponentType implements IComponentType {
|
||||
|
||||
@Override
|
||||
public Class<? extends IComponentInstance> getComponentInstanceClass() {
|
||||
return MockComponentInstance.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ComponentLayer getComponentLayer() {
|
||||
return ComponentLayer.BOARD;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Some description";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Icon getIcon() {
|
||||
return IconLoader.Gears.getIcon();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Mock Component";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCategory() {
|
||||
return "Samples";
|
||||
}
|
||||
|
||||
}
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
package com.diyfever.diylc.plugins.file;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.diyfever.diylc.components.MockComponentInstance;
|
||||
import com.diyfever.diylc.model.IComponentInstance;
|
||||
import com.diyfever.diylc.model.measures.Capacitance;
|
||||
import com.diyfever.diylc.model.measures.CapacitanceUnit;
|
||||
|
||||
public class BomMakerTest {
|
||||
|
||||
@Test
|
||||
public void testCreateBom() {
|
||||
List<IComponentInstance> components = new ArrayList<IComponentInstance>();
|
||||
MockComponentInstance c1 = new MockComponentInstance();
|
||||
c1.setC(new Capacitance(3d, CapacitanceUnit.pF));
|
||||
components.add(c1);
|
||||
components.add(new MockComponentInstance());
|
||||
components.add(new MockComponentInstance());
|
||||
List<BomEntry> bom = BomMaker.getInstance().createBom(components);
|
||||
assertNotNull(bom);
|
||||
assertEquals(2, bom.size());
|
||||
BomEntry entry1 = bom.get(0);
|
||||
assertEquals("something", entry1.getName());
|
||||
assertEquals(2, (int) entry1.getQuantity());
|
||||
BomEntry entry2 = bom.get(1);
|
||||
assertEquals("something", entry2.getName());
|
||||
assertEquals(1, (int) entry2.getQuantity());
|
||||
}
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
package com.diyfever.diylc.presenter;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.diyfever.diylc.common.ControlPointWrapper;
|
||||
import com.diyfever.diylc.common.PropertyWrapper;
|
||||
import com.diyfever.diylc.components.MockComponentInstance;
|
||||
|
||||
public class ClassProcessorTest {
|
||||
|
||||
@Test
|
||||
public void testExtractProperties() {
|
||||
List<PropertyWrapper> properties = ComponentProcessor.getInstance()
|
||||
.extractProperties(MockComponentInstance.class);
|
||||
assertNotNull(properties);
|
||||
assertEquals(4, properties.size());
|
||||
};
|
||||
|
||||
@Test
|
||||
public void testExtractControlPoints() {
|
||||
List<ControlPointWrapper> controlPoints = ComponentProcessor
|
||||
.getInstance()
|
||||
.extractControlPoints(MockComponentInstance.class);
|
||||
assertNotNull(controlPoints);
|
||||
assertEquals(1, controlPoints.size());
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user