add tantalum cap

This commit is contained in:
Branislav Stojkovic
2019-01-10 18:06:57 +01:00
parent 4eda278bc0
commit bfe044f3f6
6 changed files with 270 additions and 3 deletions
Binary file not shown.
@@ -172,7 +172,7 @@ public class RadialElectrolytic extends AbstractRadialComponent<Capacitance> {
finalTickColor = tickColor;
}
g2d.setColor(finalTickColor);
g2d.setStroke(ObjectCache.getInstance().fetchZoomableStroke(2));
g2d.setStroke(ObjectCache.getInstance().fetchZoomableStroke(1));
if (folded) {
int tickLength = height / 7;
for (int i = 0; i < 3; i++) {
@@ -181,8 +181,8 @@ public class RadialElectrolytic extends AbstractRadialComponent<Capacitance> {
+ tickLength);
}
} else {
g2d.drawLine((int) (totalDiameter * (invert ? 0.1 : 0.9)), totalDiameter / 2 - (int) (totalDiameter * 0.05),
(int) (totalDiameter * (invert ? 0.1 : 0.9)), totalDiameter / 2 + (int) (totalDiameter * 0.05));
g2d.drawLine((int) (totalDiameter * (invert ? 0.1 : 0.9)), totalDiameter / 2 - (int) (totalDiameter * 0.06),
(int) (totalDiameter * (invert ? 0.1 : 0.9)), totalDiameter / 2 + (int) (totalDiameter * 0.06));
}
}
// int coverDiameter = getClosestOdd(totalDiameter * 3 / 4);
@@ -0,0 +1,263 @@
/*
DIY Layout Creator (DIYLC).
Copyright (c) 2009-2018 held jointly by the individual authors.
This file is part of DIYLC.
DIYLC is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
DIYLC is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with DIYLC. If not, see <http://www.gnu.org/licenses/>.
*/
package org.diylc.components.passive;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Shape;
import java.awt.geom.Area;
import java.awt.geom.Ellipse2D;
import java.awt.geom.Rectangle2D;
import java.awt.geom.RoundRectangle2D;
import org.diylc.appframework.miscutils.ConfigurationManager;
import org.diylc.common.IPlugInPort;
import org.diylc.common.ObjectCache;
import org.diylc.common.SimpleComponentTransformer;
import org.diylc.components.AbstractRadialComponent;
import org.diylc.core.CreationMethod;
import org.diylc.core.IDIYComponent;
import org.diylc.core.Theme;
import org.diylc.core.annotations.ComponentDescriptor;
import org.diylc.core.annotations.EditableProperty;
import org.diylc.core.annotations.PositiveMeasureValidator;
import org.diylc.core.measures.Capacitance;
import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit;
import org.diylc.utils.Constants;
@ComponentDescriptor(name = "Tantalum Capacitor", author = "Branislav Stojkovic", category = "Passive",
creationMethod = CreationMethod.POINT_BY_POINT, instanceNamePrefix = "C",
description = "Vertically mounted tantalum capacitor", zOrder = IDIYComponent.COMPONENT,
transformer = SimpleComponentTransformer.class)
public class TantalumCapacitor extends AbstractRadialComponent<Capacitance> {
private static final long serialVersionUID = 1L;
public static Size DEFAULT_SIZE = new Size(1d / 4, SizeUnit.in);
public static Color BODY_COLOR = Color.decode("#CFAD28");
public static Color BORDER_COLOR = BODY_COLOR.darker();
public static Color MARKER_COLOR = BODY_COLOR.darker();
public static Color TICK_COLOR = Color.white;
public static Size HEIGHT = new Size(0.4d, SizeUnit.in);
public static Size EDGE_RADIUS = new Size(1d, SizeUnit.mm);
private Capacitance value = null;
private org.diylc.core.measures.Voltage voltageNew = null;
private Color markerColor = MARKER_COLOR;
private Color tickColor = TICK_COLOR;
private boolean folded = false;
private Size height = HEIGHT;
private boolean invert = false;
public TantalumCapacitor() {
super();
this.bodyColor = BODY_COLOR;
this.borderColor = BORDER_COLOR;
this.labelColor = TICK_COLOR;
}
@EditableProperty(validatorClass = PositiveMeasureValidator.class)
public Capacitance getValue() {
return value;
}
public void setValue(Capacitance value) {
this.value = value;
}
@Override
public String getValueForDisplay() {
return getValue().toString() + (getVoltageNew() == null ? "" : " " + getVoltageNew().toString());
}
@EditableProperty(name = "Voltage")
public org.diylc.core.measures.Voltage getVoltageNew() {
return voltageNew;
}
public void setVoltageNew(org.diylc.core.measures.Voltage voltageNew) {
this.voltageNew = voltageNew;
}
public void drawIcon(Graphics2D g2d, int width, int height) {
g2d.setColor(BODY_COLOR);
int margin = 3;
Ellipse2D body =
new Ellipse2D.Double(margin, margin, getClosestOdd(width - 2 * margin), getClosestOdd(width - 2 * margin));
g2d.fill(body);
Area marker = new Area(body);
marker.subtract(new Area(new Rectangle2D.Double(4 * margin, margin, width, getClosestOdd(width - 2
* margin))));
g2d.setColor(MARKER_COLOR);
g2d.fill(marker);
g2d.setColor(TICK_COLOR);
g2d.drawLine(2 * margin + 1, height / 2 - 2, 2 * margin + 1, height / 2 + 2);
g2d.drawLine(2 * margin - 2 + 1, height / 2, 2 * margin + 2 + 1, height / 2);
g2d.setColor(BORDER_COLOR);
g2d.draw(body);
}
@Override
protected void decorateComponentBody(Graphics2D g2d, boolean outlineMode) {
int height = (int) getHeight().convertToPixels();
int totalDiameter = getClosestOdd(getLength().convertToPixels());
if (!outlineMode) {
if (folded) {
Area area = new Area(getBodyShape());
if (!invert) {
area.subtract(new Area(new Rectangle2D.Double(totalDiameter * 0.2, -height, totalDiameter, height * 2)));
} else {
area.subtract(new Area(new Rectangle2D.Double(0, -height, totalDiameter * 0.8, height * 2)));
}
g2d.setColor(markerColor);
g2d.fill(area);
} else {
Area area = new Area(getBodyShape());
if (!invert) {
area.subtract(new Area(new Rectangle2D.Double(totalDiameter * 0.2, 0, totalDiameter, totalDiameter)));
} else {
area.subtract(new Area(new Rectangle2D.Double(0, 0, totalDiameter * 0.8, totalDiameter)));
}
g2d.setColor(markerColor);
g2d.fill(area);
}
}
Color finalTickColor;
if (outlineMode) {
Theme theme =
(Theme) ConfigurationManager.getInstance().readObject(IPlugInPort.THEME_KEY, Constants.DEFAULT_THEME);
finalTickColor = theme.getOutlineColor();
} else {
finalTickColor = tickColor;
}
g2d.setColor(finalTickColor);
g2d.setStroke(ObjectCache.getInstance().fetchZoomableStroke(1));
if (folded) {
int tickLength = height / 7;
for (int i = 0; i < 3; i++) {
g2d.drawLine((int) (totalDiameter * (!invert ? 0.08 : 0.92)), -height / 2 + tickLength + i * tickLength * 2,
(int) (totalDiameter * (!invert ? 0.08 : 0.92)), -height / 2 + tickLength + i * tickLength * 2
+ tickLength);
}
} else {
g2d.drawLine((int) (totalDiameter * (!invert ? 0.1 : 0.9)), totalDiameter / 2 - (int) (totalDiameter * 0.06),
(int) (totalDiameter * (!invert ? 0.1 : 0.9)), totalDiameter / 2 + (int) (totalDiameter * 0.06));
g2d.drawLine((int) (totalDiameter * (!invert ? 0.04 : 0.84)), totalDiameter / 2,
(int) (totalDiameter * (!invert ? 0.16 : 0.96)), totalDiameter / 2);
}
// int coverDiameter = getClosestOdd(totalDiameter * 3 / 4);
// g2d.setColor(coverColor);
// int position = (totalDiameter - coverDiameter) / 2;
// g2d.fillOval(position, position, coverDiameter, coverDiameter);
// g2d.setColor(coverColor.darker());
// g2d.drawLine(position + coverDiameter / 5, position + coverDiameter /
// 5, position + 4
// * coverDiameter / 5, position + 4 * coverDiameter / 5);
// g2d.drawLine(position + coverDiameter / 5, position + 4 *
// coverDiameter / 5, position + 4
// * coverDiameter / 5, position + coverDiameter / 5);
}
@Override
protected Size getDefaultWidth() {
return null;
}
@Override
public Size getWidth() {
return super.getWidth();
}
@Override
protected Size getDefaultLength() {
// We'll reuse width property to set the diameter.
return DEFAULT_SIZE;
}
@EditableProperty(name = "Diameter")
@Override
public Size getLength() {
return super.getLength();
}
@EditableProperty(name = "Marker")
public Color getMarkerColor() {
return markerColor;
}
public void setMarkerColor(Color coverColor) {
this.markerColor = coverColor;
}
@EditableProperty(name = "Tick")
public Color getTickColor() {
return tickColor;
}
public void setTickColor(Color tickColor) {
this.tickColor = tickColor;
}
@EditableProperty
public boolean getFolded() {
return folded;
}
public void setFolded(boolean folded) {
this.folded = folded;
}
@EditableProperty
public Size getHeight() {
if (height == null) {
height = HEIGHT;
}
return height;
}
public void setHeight(Size height) {
this.height = height;
}
@EditableProperty(name = "Invert polarity")
public boolean getInvert() {
return invert;
}
public void setInvert(boolean invert) {
this.invert = invert;
}
@Override
protected Shape getBodyShape() {
double height = (int) getHeight().convertToPixels();
double diameter = (int) getLength().convertToPixels();
if (folded) {
return new RoundRectangle2D.Double(0f, -height / 2 - LEAD_THICKNESS.convertToPixels() / 2,
getClosestOdd(diameter), getClosestOdd(height), EDGE_RADIUS.convertToPixels(), EDGE_RADIUS.convertToPixels());
}
return new Ellipse2D.Double(0f, 0f, getClosestOdd(diameter), getClosestOdd(diameter));
}
}
Binary file not shown.
Binary file not shown.
+4
View File
@@ -2146,6 +2146,10 @@
<changeType>NEW_FEATURE</changeType>
<description>"P-Bass Pickup" added</description>
</org.diylc.appframework.update.Change>
<org.diylc.appframework.update.Change>
<changeType>NEW_FEATURE</changeType>
<description>"Tantalum Capacitor" added</description>
</org.diylc.appframework.update.Change>
<org.diylc.appframework.update.Change>
<changeType>NEW_FEATURE</changeType>
<description>Ability to have "Single-coil Pickup" and "Humbucker Pickup" with no poles, similar to EMG, Lace Sensor...</description>