Battery - one cell

29 views
Skip to first unread message

Michael Turcotte

unread,
Nov 25, 2016, 5:34:00 PM11/25/16
to diy-layout-creator
Finally got a battery component to work. 

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
}

}



Clipboard01.jpg

Branislav Stojkovic

unread,
Nov 25, 2016, 6:01:03 PM11/25/16
to diy-layou...@googlegroups.com
cool, thanks, I will review it and include in the next release.

Cheers,
Bane

--
You received this message because you are subscribed to the Google Groups "diy-layout-creator" group.
To unsubscribe from this group and stop receiving emails from it, send an email to diy-layout-creator+unsub...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Branislav Stojkovic
www.diy-fever.com

Branislav Stojkovic

unread,
Dec 23, 2016, 9:37:15 AM12/23/16
to diy-layou...@googlegroups.com
this was released to v33

To unsubscribe from this group and stop receiving emails from it, send an email to diy-layout-creator+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Branislav Stojkovic
www.diy-fever.com



--
Branislav Stojkovic
www.diy-fever.com
Reply all
Reply to author
Forward
0 new messages