Added "Label Orientation" property to leaded components that can be used

to force labels to be rendered horizontally instead of following
component placement direction
This commit is contained in:
Branislav Stojkovic
2019-01-10 18:44:23 +01:00
parent 0f3f2a350b
commit 7caadec1ec
6 changed files with 34 additions and 6 deletions
@@ -71,6 +71,7 @@ public abstract class AbstractLeadedComponent<T> extends AbstractTransparentComp
protected Color leadColor = LEAD_COLOR; protected Color leadColor = LEAD_COLOR;
protected Display display = Display.NAME; protected Display display = Display.NAME;
private boolean flipStanding = false; private boolean flipStanding = false;
private LabelOriantation labelOriantation = LabelOriantation.Directional;
protected AbstractLeadedComponent() { protected AbstractLeadedComponent() {
super(); super();
@@ -235,9 +236,17 @@ public abstract class AbstractLeadedComponent<T> extends AbstractTransparentComp
g2d.rotate(Math.PI, length / 2, width / 2); g2d.rotate(Math.PI, length / 2, width / 2);
offset = -offset; offset = -offset;
} }
g2d.drawString(label, (int) (length - textRect.getWidth()) / 2 + offset, if (getLabelOriantation() == LabelOriantation.Horizontal) {
calculateLabelYCoordinate(shapeRect, textRect, fontMetrics)); g2d.setTransform(oldTransform);
g2d.setTransform(oldTransform); double x = (points[0].x + points[1].x - length) / 2.0;
double y = (points[0].y + points[1].y - width) / 2.0;
g2d.drawString(label, (int) (x + (length - textRect.getWidth()) / 2 + offset),
(int)(y + calculateLabelYCoordinate(shapeRect, textRect, fontMetrics)));
} else {
g2d.drawString(label, (int) (length - textRect.getWidth()) / 2 + offset,
calculateLabelYCoordinate(shapeRect, textRect, fontMetrics));
g2d.setTransform(oldTransform);
}
} }
} }
@@ -367,7 +376,7 @@ public abstract class AbstractLeadedComponent<T> extends AbstractTransparentComp
: getLeadColor(); : getLeadColor();
} }
@EditableProperty(name = "Lead color") @EditableProperty(name = "Lead Color")
public Color getLeadColor() { public Color getLeadColor() {
if (leadColor == null) { if (leadColor == null) {
leadColor = LEAD_COLOR_ICON; leadColor = LEAD_COLOR_ICON;
@@ -457,7 +466,7 @@ public abstract class AbstractLeadedComponent<T> extends AbstractTransparentComp
this.display = display; this.display = display;
} }
@EditableProperty(name = "Label color") @EditableProperty(name = "Label Color")
public Color getLabelColor() { public Color getLabelColor() {
return labelColor; return labelColor;
} }
@@ -465,6 +474,17 @@ public abstract class AbstractLeadedComponent<T> extends AbstractTransparentComp
public void setLabelColor(Color labelColor) { public void setLabelColor(Color labelColor) {
this.labelColor = labelColor; this.labelColor = labelColor;
} }
@EditableProperty(name = "Label Orientation")
public LabelOriantation getLabelOriantation() {
if (labelOriantation == null)
labelOriantation = LabelOriantation.Directional;
return labelOriantation;
}
public void setLabelOriantation(LabelOriantation labelOriantation) {
this.labelOriantation = labelOriantation;
}
/** /**
* Override this method with @EditableProperty annotation in child classes where standing mode is * Override this method with @EditableProperty annotation in child classes where standing mode is
@@ -479,4 +499,8 @@ public abstract class AbstractLeadedComponent<T> extends AbstractTransparentComp
public void setFlipStanding(boolean flipStanding) { public void setFlipStanding(boolean flipStanding) {
this.flipStanding = flipStanding; this.flipStanding = flipStanding;
} }
public enum LabelOriantation {
Directional, Horizontal
}
} }
Binary file not shown.
@@ -200,7 +200,7 @@ public class Resistor extends AbstractLeadedComponent<Resistance> {
@Override @Override
protected int getLabelOffset(int bodyWidth, int labelWidth) { protected int getLabelOffset(int bodyWidth, int labelWidth) {
if (value == null || getColorCode() == ResistorColorCode.NONE) if (value == null || getColorCode() == ResistorColorCode.NONE || getLabelOriantation() != AbstractLeadedComponent.LabelOriantation.Directional)
return 0; return 0;
int width = getClosestOdd(getWidth().convertToPixels()); int width = getClosestOdd(getWidth().convertToPixels());
Color[] bands = value.getColorCode(colorCode); Color[] bands = value.getColorCode(colorCode);
Binary file not shown.
Binary file not shown.
+4
View File
@@ -2138,6 +2138,10 @@
<releaseDate>2019-01-09 00:00:00.000 CET</releaseDate> <releaseDate>2019-01-09 00:00:00.000 CET</releaseDate>
<name></name> <name></name>
<changes> <changes>
<org.diylc.appframework.update.Change>
<changeType>NEW_FEATURE</changeType>
<description>Added "Label Orientation" property to leaded components that can be used to force labels to be rendered horizontally instead of following component placement direction</description>
</org.diylc.appframework.update.Change>
<org.diylc.appframework.update.Change> <org.diylc.appframework.update.Change>
<changeType>NEW_FEATURE</changeType> <changeType>NEW_FEATURE</changeType>
<description>"Jazz Bass Pickup" added</description> <description>"Jazz Bass Pickup" added</description>