It is only one cell, uses B as the designation, and it defaults to 9v.
Here is the code and I commented it this time. Remembered my professor's talking to me about commenting when I came back to finish this after a week.
package org.diylc.components.passive;
import java.awt.Graphics2D;
import java.awt.Shape;
import java.awt.geom.GeneralPath;
import org.diylc.components.AbstractSchematicLeadedSymbol;
import org.diylc.core.CreationMethod;
import org.diylc.core.IDIYComponent;
import org.diylc.core.annotations.ComponentDescriptor;
import org.diylc.core.annotations.EditableProperty;
import org.diylc.core.annotations.PositiveMeasureValidator;
import org.diylc.core.measures.VoltageUnit;
import org.diylc.core.measures.Voltage;
import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit;
@ComponentDescriptor(name = "Battery (schematic symbol)", author = "N9XYP", category = "Schematics", creationMethod = CreationMethod.POINT_BY_POINT, instanceNamePrefix = "B", description = "Battery schematic symbol", zOrder = IDIYComponent.COMPONENT)
public class BatterySymbol extends AbstractSchematicLeadedSymbol<String> {
private static final long serialVersionUID = 1L;
private String value = "Battery";
public static Size DEFAULT_LENGTH = new Size(0.05, SizeUnit.in); // plate spacing
public static Size DEFAULT_WIDTH = new Size(0.15, SizeUnit.in); // plate size
private org.diylc.core.measures.Voltage voltageNew = new org.diylc.core.measures.Voltage(9d, VoltageUnit.V);
// sets battery voltage to 9V
@Override
public String getValueForDisplay() {
return getValue().toString() + (getVoltageNew() == null ? "" : " " + getVoltageNew().toString());
}
@EditableProperty
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
@EditableProperty(name = "Voltage")
public org.diylc.core.measures.Voltage getVoltageNew() {
return voltageNew;
}
public void setVoltageNew(org.diylc.core.measures.Voltage voltageNew) {
this.voltageNew = voltageNew;
}
@Override
protected Size getDefaultWidth() {
return DEFAULT_WIDTH;
}
@Override
protected Size getDefaultLength() {
return DEFAULT_LENGTH;
}
@Override
protected Shape getBodyShape() {
GeneralPath polyline = new GeneralPath();
double length = getLength().convertToPixels(); // plate spacing
double width = getWidth().convertToPixels(); // plate size
polyline.moveTo(0, 0); // start point
polyline.lineTo(0, width); // draw first plate (positive)
// 2nd plate width = w/4 + w/2 + w/4
// w - w/4 = w/2 pixels
polyline.moveTo(length, width / 4); // start 2nd plate
polyline.lineTo(length, width - width / 4); // draw second plate w/2 pixels (negative)
return polyline;
}
@Override
protected void decorateComponentBody(Graphics2D g2d, boolean outlineMode) {
// Draw + sign.
g2d.setColor(getBorderColor());
int plusSize = getClosestOdd(getWidth().convertToPixels() / 4); // 1/4 length of plus sign
int x = -plusSize; // center point
int y = plusSize; // end point
g2d.drawLine(x - plusSize / 2, y, x + plusSize / 2, y); // line from X-center point +- 1/2 length about y-center
g2d.drawLine(x, y - plusSize / 2, x, y + plusSize / 2); // line from y-center point +- 1/2 length about x-center
}
public void drawIcon(Graphics2D g2d, int width, int height) {
g2d.rotate(-Math.PI / 4, width / 2, height / 2);
g2d.setColor(COLOR);
g2d.drawLine(0, height / 2, 13, height / 2); // draw leads
g2d.drawLine(width - 13, height / 2, width, height / 2);
g2d.setColor(COLOR);
g2d.drawLine(14, height / 2 - 6, 14, height / 2 + 6); // pos plate
g2d.drawLine(width - 14, height / 2 - 3, width - 14, height / 2 + 3); // neg plate
}
}