mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-10 17:22:09 +10:00
added capacitor
This commit is contained in:
+8
-3
@@ -31,6 +31,7 @@ public abstract class AbstractLeadedDIYComponent implements IDIYComponent {
|
||||
|
||||
public static Color LEAD_COLOR = Color.black;
|
||||
public static Color LABEL_COLOR = Color.black;
|
||||
public static Color LABEL_COLOR_SELECTED = Color.red;
|
||||
public static Font LABEL_FONT = new Font("Tahoma", Font.BOLD, 11);
|
||||
|
||||
protected Size width;
|
||||
@@ -98,13 +99,17 @@ public abstract class AbstractLeadedDIYComponent implements IDIYComponent {
|
||||
(point1.y + point2.y - shapeRect.height) / 2);
|
||||
g2d.rotate(theta, shapeRect.width / 2, shapeRect.height / 2);
|
||||
// Draw body.
|
||||
g2d.setColor(getBodyColor());
|
||||
g2d.fill(shape);
|
||||
if (componentState != ComponentState.DRAGGING) {
|
||||
g2d.setColor(getBodyColor());
|
||||
g2d.fill(shape);
|
||||
}
|
||||
g2d.setColor(getBorderColor());
|
||||
g2d.draw(shape);
|
||||
// Draw label.
|
||||
g2d.setFont(LABEL_FONT);
|
||||
g2d.setColor(LABEL_COLOR);
|
||||
g2d
|
||||
.setColor(componentState == ComponentState.SELECTED ? LABEL_COLOR_SELECTED
|
||||
: LABEL_COLOR);
|
||||
FontMetrics fontMetrics = g2d.getFontMetrics(g2d.getFont());
|
||||
java.awt.geom.Rectangle2D textRect = fontMetrics.getStringBounds(getComponentName(), g2d);
|
||||
g2d.drawString(getComponentName(), (int) (shapeRect.width - textRect.getWidth()) / 2,
|
||||
|
||||
+71
@@ -0,0 +1,71 @@
|
||||
package org.diylc.components;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Shape;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
|
||||
import org.diylc.core.annotations.ComponentDescriptor;
|
||||
import org.diylc.core.annotations.ComponentValue;
|
||||
import org.diylc.core.annotations.EditableProperty;
|
||||
import org.diylc.core.measures.Capacitance;
|
||||
import org.diylc.core.measures.CapacitanceUnit;
|
||||
import org.diylc.core.measures.Size;
|
||||
import org.diylc.core.measures.SizeUnit;
|
||||
|
||||
@ComponentDescriptor(name = "Axial Film Capacitor", author = "bancika", category = "Passive", instanceNamePrefix = "C", desciption = "test")
|
||||
public class Capacitor extends AbstractLeadedDIYComponent {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public static Size DEFAULT_WIDTH = new Size(1d / 2, SizeUnit.in);
|
||||
public static Size DEFAULT_HEIGHT = new Size(1d / 8, SizeUnit.in);
|
||||
public static Color BODY_COLOR = Color.decode("#FFE303");
|
||||
public static Color BORDER_COLOR = Color.decode("#B8860B");
|
||||
|
||||
private Capacitance value = new Capacitance(123d, CapacitanceUnit.nF);
|
||||
|
||||
public Capacitor() {
|
||||
super();
|
||||
}
|
||||
|
||||
@ComponentValue
|
||||
@EditableProperty
|
||||
public Capacitance getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(Capacitance value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public void drawIcon(Graphics2D g2d, int width, int height) {
|
||||
g2d.drawString("C", 10, 10);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Size getDefaultHeight() {
|
||||
return DEFAULT_HEIGHT;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Size getDefaultWidth() {
|
||||
return DEFAULT_WIDTH;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Color getBodyColor() {
|
||||
return BODY_COLOR;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Color getBorderColor() {
|
||||
return BORDER_COLOR;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Shape getComponentShape() {
|
||||
return new Rectangle2D.Double(0f, 0f, getWidth().convertToPixels(), getHeight()
|
||||
.convertToPixels());
|
||||
}
|
||||
}
|
||||
+9
-3
@@ -6,6 +6,7 @@ import java.awt.Shape;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
|
||||
import org.diylc.core.annotations.ComponentDescriptor;
|
||||
import org.diylc.core.annotations.ComponentValue;
|
||||
import org.diylc.core.annotations.EditableProperty;
|
||||
import org.diylc.core.measures.Resistance;
|
||||
import org.diylc.core.measures.ResistanceUnit;
|
||||
@@ -22,15 +23,20 @@ public class Resistor extends AbstractLeadedDIYComponent {
|
||||
public static Color BODY_COLOR = Color.decode("#82CFFD");
|
||||
public static Color BORDER_COLOR = Color.decode("#5D92B1");
|
||||
|
||||
private Resistance r = new Resistance(123d, ResistanceUnit.K);
|
||||
private Resistance value = new Resistance(123d, ResistanceUnit.K);
|
||||
|
||||
public Resistor() {
|
||||
super();
|
||||
}
|
||||
|
||||
@ComponentValue
|
||||
@EditableProperty
|
||||
public Resistance getR() {
|
||||
return r;
|
||||
public Resistance getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(Resistance value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public void drawIcon(Graphics2D g2d, int width, int height) {
|
||||
|
||||
Reference in New Issue
Block a user