added display pinout

This commit is contained in:
bancika
2020-04-12 23:57:07 +02:00
parent 30c29ab452
commit 2889d51387
14 changed files with 191 additions and 85 deletions
@@ -2942,6 +2942,10 @@
<changeType>NEW_FEATURE</changeType> <changeType>NEW_FEATURE</changeType>
<description>Added "Duo-Diode" tube symbol</description> <description>Added "Duo-Diode" tube symbol</description>
</org.diylc.appframework.update.Change> </org.diylc.appframework.update.Change>
<org.diylc.appframework.update.Change>
<changeType>NEW_FEATURE</changeType>
<description>Transistor components can display pinout instead of name or value</description>
</org.diylc.appframework.update.Change>
<org.diylc.appframework.update.Change> <org.diylc.appframework.update.Change>
<changeType>IMPROVEMENT</changeType> <changeType>IMPROVEMENT</changeType>
<description>Prevent the app from closing while running background operations, like saving and exporting files</description> <description>Prevent the app from closing while running background operations, like saving and exporting files</description>
Binary file not shown.
@@ -230,7 +230,7 @@ public class StringUtils {
int textY = 0; int textY = 0;
switch (verticalAlignment) { switch (verticalAlignment) {
case TOP: case TOP:
textY = y + stringBounds.height; textY = y;
break; break;
case CENTER: case CENTER:
textY = y - visualBounds.height / 2 - visualBounds.y; textY = y - visualBounds.height / 2 - visualBounds.y;
@@ -168,7 +168,7 @@ public abstract class AbstractBoard extends AbstractTransparentComponent<String>
drawPoint.x += xOffset; drawPoint.x += xOffset;
StringUtils.drawCenteredText(g2d, label, StringUtils.drawCenteredText(g2d, label,
drawPoint.x, firstPoint.y - 2, drawPoint.x, firstPoint.y - 2,
HorizontalAlignment.CENTER, VerticalAlignment.TOP); HorizontalAlignment.CENTER, VerticalAlignment.BOTTOM);
if (getCoordinateDisplay() == CoordinateDisplay.Both_Sides) { if (getCoordinateDisplay() == CoordinateDisplay.Both_Sides) {
StringUtils.drawCenteredText(g2d, label, StringUtils.drawCenteredText(g2d, label,
drawPoint.x, (int) (finalSecondPoint.y - COORDINATE_FONT_SIZE), drawPoint.x, (int) (finalSecondPoint.y - COORDINATE_FONT_SIZE),
@@ -161,10 +161,10 @@ public class Breadboard extends AbstractComponent<Void> {
// Draw horizontal labels // Draw horizontal labels
if (y == 0) { if (y == 0) {
g2d.setColor(COORDINATE_COLOR); g2d.setColor(COORDINATE_COLOR);
StringUtils.drawCenteredText(g2d, new String(new byte[] {(byte) (a + x + 5 * section)}), holeX, (int) (point.y), StringUtils.drawCenteredText(g2d, new String(new byte[] {(byte) (a + x + 5 * section)}), holeX, (int) (point.y + COORDINATE_FONT_SIZE),
HorizontalAlignment.CENTER, VerticalAlignment.TOP); HorizontalAlignment.CENTER, VerticalAlignment.TOP);
StringUtils.drawCenteredText(g2d, new String(new byte[] {(byte) (a + x + 5 * section)}), holeX, (int) (point.y StringUtils.drawCenteredText(g2d, new String(new byte[] {(byte) (a + x + 5 * section)}), holeX, (int) (point.y
+ spacing * 30 + COORDINATE_FONT_SIZE / 2), HorizontalAlignment.CENTER, VerticalAlignment.TOP); + spacing * 31 - COORDINATE_FONT_SIZE / 2), HorizontalAlignment.CENTER, VerticalAlignment.TOP);
} }
} }
} }
@@ -281,7 +281,7 @@ public class ProtoBoard extends AbstractComponent<Void> {
// Draw horizontal labels // Draw horizontal labels
if (y == 0) { if (y == 0) {
g2d.setColor(textColor); g2d.setColor(textColor);
StringUtils.drawCenteredText(g2d, Integer.toString(SEGMENTS_SUM[segment] + x + 1), padX, (int) (point.y + (yOffset - 1) * spacing) - 1, StringUtils.drawCenteredText(g2d, Integer.toString(SEGMENTS_SUM[segment] + x + 1), padX, (int) (point.y + (yOffset) * spacing) - padSize / 2 - 2,
HorizontalAlignment.CENTER, VerticalAlignment.TOP); HorizontalAlignment.CENTER, VerticalAlignment.TOP);
} }
} }
@@ -443,7 +443,7 @@ public class ProtoBoard extends AbstractComponent<Void> {
HorizontalAlignment.RIGHT, VerticalAlignment.CENTER); HorizontalAlignment.RIGHT, VerticalAlignment.CENTER);
// Draw top-right labels // Draw top-right labels
int labelY = (int) (point.y + 3.3 * spacing); int labelY = (int) (point.y + 3.8 * spacing) + 1;
StringUtils.drawCenteredText(g2d, "+5V", (int) (point.x + width - 6 * spacing), labelY, HorizontalAlignment.CENTER, VerticalAlignment.TOP); StringUtils.drawCenteredText(g2d, "+5V", (int) (point.x + width - 6 * spacing), labelY, HorizontalAlignment.CENTER, VerticalAlignment.TOP);
StringUtils.drawCenteredText(g2d, "+", (int) (point.x + width - 5 * spacing) - 6, labelY, HorizontalAlignment.CENTER, VerticalAlignment.TOP); StringUtils.drawCenteredText(g2d, "+", (int) (point.x + width - 5 * spacing) - 6, labelY, HorizontalAlignment.CENTER, VerticalAlignment.TOP);
StringUtils.drawCenteredText(g2d, " 12V", (int) (point.x + width - 5 * spacing) + 2, labelY, HorizontalAlignment.CENTER, VerticalAlignment.TOP); StringUtils.drawCenteredText(g2d, " 12V", (int) (point.x + width - 5 * spacing) + 2, labelY, HorizontalAlignment.CENTER, VerticalAlignment.TOP);
@@ -467,7 +467,7 @@ public class ProtoBoard extends AbstractComponent<Void> {
g2d.setColor(textColor); g2d.setColor(textColor);
g2d.setFont(LABEL_FONT.deriveFont(COORDINATE_FONT_SIZE + 2)); g2d.setFont(LABEL_FONT.deriveFont(COORDINATE_FONT_SIZE + 2));
StringUtils.drawCenteredText(g2d, "P-0+o by:\nKristian Blåsol 2019", (int) (point.x + width * 0.70d), (int) (point.y + (yOffset + ROW_COUNT + 0.4) * spacing), StringUtils.drawCenteredText(g2d, "P-0+o by:\nKristian Blåsol 2019", (int) (point.x + width * 0.70d), (int) (point.y + (yOffset + ROW_COUNT + 0.9) * spacing),
HorizontalAlignment.LEFT, VerticalAlignment.TOP); HorizontalAlignment.LEFT, VerticalAlignment.TOP);
// draw central mini pads // draw central mini pads
@@ -22,12 +22,16 @@
package org.diylc.components.semiconductors; package org.diylc.components.semiconductors;
import java.awt.Color; import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.Point; import java.awt.Point;
import java.awt.geom.Area; import java.awt.geom.Area;
import java.awt.geom.Rectangle2D; import java.awt.geom.Rectangle2D;
import org.diylc.common.Display; import org.diylc.awt.StringUtils;
import org.diylc.common.HorizontalAlignment;
import org.diylc.common.Orientation; import org.diylc.common.Orientation;
import org.diylc.common.VerticalAlignment;
import org.diylc.components.AbstractTransparentComponent; import org.diylc.components.AbstractTransparentComponent;
import org.diylc.core.VisibilityPolicy; import org.diylc.core.VisibilityPolicy;
import org.diylc.core.annotations.EditableProperty; import org.diylc.core.annotations.EditableProperty;
@@ -46,7 +50,7 @@ public abstract class AbstractTransistorPackage extends AbstractTransparentCompo
protected Color bodyColor; protected Color bodyColor;
protected Color borderColor; protected Color borderColor;
protected Color labelColor = LABEL_COLOR; protected Color labelColor = LABEL_COLOR;
protected Display display = Display.NAME; protected TransistorDisplay display = TransistorDisplay.NAME;
public AbstractTransistorPackage() { public AbstractTransistorPackage() {
} }
@@ -180,14 +184,14 @@ public abstract class AbstractTransistorPackage extends AbstractTransparentCompo
} }
@EditableProperty @EditableProperty
public Display getDisplay() { public TransistorDisplay getDisplay() {
if (display == null) { if (display == null) {
display = Display.NAME; display = TransistorDisplay.NAME;
} }
return display; return display;
} }
public void setDisplay(Display display) { public void setDisplay(TransistorDisplay display) {
this.display = display; this.display = display;
} }
@@ -218,4 +222,75 @@ public abstract class AbstractTransistorPackage extends AbstractTransparentCompo
Rectangle2D bounds = getBody()[0].getBounds2D(); Rectangle2D bounds = getBody()[0].getBounds2D();
return new Rectangle2D.Double(bounds.getX() - margin, bounds.getY() - margin, bounds.getWidth() + 2 * margin, bounds.getHeight() + 2 * margin); return new Rectangle2D.Double(bounds.getX() - margin, bounds.getY() - margin, bounds.getWidth() + 2 * margin, bounds.getHeight() + 2 * margin);
} }
protected boolean flipPinoutLabel() {
return false;
}
protected void drawPinout(Graphics2D g2d) {
TransistorPinout p = getPinout();
if (p == null)
return;
Font f = g2d.getFont();
f = f.deriveFont((float) (f.getSize() * 0.7));
g2d.setFont(f);
int d = 4; // hard-coded
String pinout = p.toPinout();
for (int i = 0; i < pinout.length(); i++) {
Point point = getControlPoint(i);
int dx = 0;
int dy = 0;
HorizontalAlignment ha = HorizontalAlignment.CENTER;
VerticalAlignment va = VerticalAlignment.CENTER;
switch (getOrientation()) {
case DEFAULT:
if (flipPinoutLabel()) {
dx = -d;
ha = HorizontalAlignment.RIGHT;
} else {
dx = d;
ha = HorizontalAlignment.LEFT;
}
break;
case _90:
if (flipPinoutLabel()) {
dy = -d;
va = VerticalAlignment.TOP;
} else {
dy = d;
va = VerticalAlignment.BOTTOM;
}
break;
case _180:
if (flipPinoutLabel()) {
dx = d;
ha = HorizontalAlignment.LEFT;
} else {
dx = -d;
ha = HorizontalAlignment.RIGHT;
}
break;
case _270:
if (flipPinoutLabel()) {
dy = d;
va = VerticalAlignment.BOTTOM;
} else {
dy = -d;
va = VerticalAlignment.TOP;
}
break;
}
StringUtils.drawCenteredText(g2d, pinout.charAt(i) + "", point.x + dx, point.y + dy, ha, va);
}
}
public enum TransistorDisplay {
NAME, VALUE, NONE, BOTH, PINOUT;
@Override
public String toString() {
return name().substring(0, 1) + name().substring(1).toLowerCase();
}
}
} }
@@ -16,4 +16,9 @@ public enum TransistorPinout {
sb.append(" ").append(parts[0]); sb.append(" ").append(parts[0]);
return sb.toString(); return sb.toString();
}; };
public String toPinout() {
String[] parts = name().split("_");
return parts[1];
}
} }
@@ -34,7 +34,6 @@ import java.awt.geom.Rectangle2D;
import java.awt.geom.RoundRectangle2D; import java.awt.geom.RoundRectangle2D;
import org.diylc.appframework.miscutils.ConfigurationManager; import org.diylc.appframework.miscutils.ConfigurationManager;
import org.diylc.common.Display;
import org.diylc.common.IPlugInPort; import org.diylc.common.IPlugInPort;
import org.diylc.common.ObjectCache; import org.diylc.common.ObjectCache;
import org.diylc.components.transform.TO1Transformer; import org.diylc.components.transform.TO1Transformer;
@@ -213,23 +212,27 @@ public class TransistorTO1 extends AbstractTransistorPackage {
: getLabelColor(); : getLabelColor();
} }
g2d.setColor(finalLabelColor); g2d.setColor(finalLabelColor);
String label = ""; if (getDisplay() == TransistorDisplay.PINOUT) {
label = (getDisplay() == Display.NAME) ? getName() : getValue(); drawPinout(g2d);
if (getDisplay() == Display.NONE) { } else {
label = ""; String label = "";
label = (getDisplay() == TransistorDisplay.NAME) ? getName() : getValue();
if (getDisplay() == TransistorDisplay.NONE) {
label = "";
}
if (getDisplay() == TransistorDisplay.BOTH) {
label = getName() + " " + (getValue() == null ? "" : getValue().toString());
}
FontMetrics fontMetrics = g2d.getFontMetrics(g2d.getFont());
Rectangle2D rect = fontMetrics.getStringBounds(label, g2d);
int textHeight = (int) (rect.getHeight());
int textWidth = (int) (rect.getWidth());
// Center text horizontally and vertically
Rectangle bounds = mainArea.getBounds();
int x = bounds.x + (bounds.width - textWidth) / 2;
int y = bounds.y + (bounds.height - textHeight) / 2 + fontMetrics.getAscent();
g2d.drawString(label, x, y);
} }
if (getDisplay() == Display.BOTH) {
label = getName() + " " + (getValue() == null ? "" : getValue().toString());
}
FontMetrics fontMetrics = g2d.getFontMetrics(g2d.getFont());
Rectangle2D rect = fontMetrics.getStringBounds(label, g2d);
int textHeight = (int) (rect.getHeight());
int textWidth = (int) (rect.getWidth());
// Center text horizontally and vertically
Rectangle bounds = mainArea.getBounds();
int x = bounds.x + (bounds.width - textWidth) / 2;
int y = bounds.y + (bounds.height - textHeight) / 2 + fontMetrics.getAscent();
g2d.drawString(label, x, y);
} }
@Override @Override
@@ -270,4 +273,9 @@ public class TransistorTO1 extends AbstractTransistorPackage {
// Reset body shape; // Reset body shape;
body = null; body = null;
} }
@Override
protected boolean flipPinoutLabel() {
return true;
}
} }
@@ -34,7 +34,6 @@ import java.awt.geom.Ellipse2D;
import java.awt.geom.Rectangle2D; import java.awt.geom.Rectangle2D;
import org.diylc.appframework.miscutils.ConfigurationManager; import org.diylc.appframework.miscutils.ConfigurationManager;
import org.diylc.common.Display;
import org.diylc.common.IPlugInPort; import org.diylc.common.IPlugInPort;
import org.diylc.common.ObjectCache; import org.diylc.common.ObjectCache;
import org.diylc.components.transform.TO220Transformer; import org.diylc.components.transform.TO220Transformer;
@@ -295,23 +294,27 @@ public class TransistorTO126 extends AbstractTransistorPackage {
: getLabelColor(); : getLabelColor();
} }
g2d.setColor(finalLabelColor); g2d.setColor(finalLabelColor);
String label = ""; if (getDisplay() == TransistorDisplay.PINOUT) {
label = (getDisplay() == Display.NAME) ? getName() : getValue(); drawPinout(g2d);
if (getDisplay() == Display.NONE) { } else {
label = ""; String label = "";
label = (getDisplay() == TransistorDisplay.NAME) ? getName() : getValue();
if (getDisplay() == TransistorDisplay.NONE) {
label = "";
}
if (getDisplay() == TransistorDisplay.BOTH) {
label = getName() + " " + (getValue() == null ? "" : getValue().toString());
}
FontMetrics fontMetrics = g2d.getFontMetrics(g2d.getFont());
Rectangle2D rect = fontMetrics.getStringBounds(label, g2d);
int textHeight = (int) (rect.getHeight());
int textWidth = (int) (rect.getWidth());
// Center text horizontally and vertically
Rectangle bounds = mainArea.getBounds();
int x = bounds.x + (bounds.width - textWidth) / 2;
int y = bounds.y + (bounds.height - textHeight) / 2 + fontMetrics.getAscent();
g2d.drawString(label, x, y);
} }
if (getDisplay() == Display.BOTH) {
label = getName() + " " + (getValue() == null ? "" : getValue().toString());
}
FontMetrics fontMetrics = g2d.getFontMetrics(g2d.getFont());
Rectangle2D rect = fontMetrics.getStringBounds(label, g2d);
int textHeight = (int) (rect.getHeight());
int textWidth = (int) (rect.getWidth());
// Center text horizontally and vertically
Rectangle bounds = mainArea.getBounds();
int x = bounds.x + (bounds.width - textWidth) / 2;
int y = bounds.y + (bounds.height - textHeight) / 2 + fontMetrics.getAscent();
g2d.drawString(label, x, y);
} }
@Override @Override
@@ -34,7 +34,6 @@ import java.awt.geom.Ellipse2D;
import java.awt.geom.Rectangle2D; import java.awt.geom.Rectangle2D;
import org.diylc.appframework.miscutils.ConfigurationManager; import org.diylc.appframework.miscutils.ConfigurationManager;
import org.diylc.common.Display;
import org.diylc.common.IPlugInPort; import org.diylc.common.IPlugInPort;
import org.diylc.common.ObjectCache; import org.diylc.common.ObjectCache;
import org.diylc.components.transform.TO220Transformer; import org.diylc.components.transform.TO220Transformer;
@@ -332,23 +331,27 @@ public class TransistorTO220 extends AbstractTransistorPackage {
: getLabelColor(); : getLabelColor();
} }
g2d.setColor(finalLabelColor); g2d.setColor(finalLabelColor);
String label = ""; if (getDisplay() == TransistorDisplay.PINOUT) {
label = (getDisplay() == Display.NAME) ? getName() : getValue(); drawPinout(g2d);
if (getDisplay() == Display.NONE) { } else {
label = ""; String label = "";
label = (getDisplay() == TransistorDisplay.NAME) ? getName() : getValue();
if (getDisplay() == TransistorDisplay.NONE) {
label = "";
}
if (getDisplay() == TransistorDisplay.BOTH) {
label = getName() + " " + (getValue() == null ? "" : getValue().toString());
}
FontMetrics fontMetrics = g2d.getFontMetrics(g2d.getFont());
Rectangle2D rect = fontMetrics.getStringBounds(label, g2d);
int textHeight = (int) (rect.getHeight());
int textWidth = (int) (rect.getWidth());
// Center text horizontally and vertically
Rectangle bounds = mainArea.getBounds();
int x = bounds.x + (bounds.width - textWidth) / 2;
int y = bounds.y + (bounds.height - textHeight) / 2 + fontMetrics.getAscent();
g2d.drawString(label, x, y);
} }
if (getDisplay() == Display.BOTH) {
label = getName() + " " + (getValue() == null ? "" : getValue().toString());
}
FontMetrics fontMetrics = g2d.getFontMetrics(g2d.getFont());
Rectangle2D rect = fontMetrics.getStringBounds(label, g2d);
int textHeight = (int) (rect.getHeight());
int textWidth = (int) (rect.getWidth());
// Center text horizontally and vertically
Rectangle bounds = mainArea.getBounds();
int x = bounds.x + (bounds.width - textWidth) / 2;
int y = bounds.y + (bounds.height - textHeight) / 2 + fontMetrics.getAscent();
g2d.drawString(label, x, y);
} }
@Override @Override
@@ -417,4 +420,9 @@ public class TransistorTO220 extends AbstractTransistorPackage {
public void setTabBorderColor(Color tabBorderColor) { public void setTabBorderColor(Color tabBorderColor) {
this.tabBorderColor = tabBorderColor; this.tabBorderColor = tabBorderColor;
} }
@Override
protected boolean flipPinoutLabel() {
return true;
}
} }
@@ -34,7 +34,6 @@ import java.awt.geom.Ellipse2D;
import java.awt.geom.Rectangle2D; import java.awt.geom.Rectangle2D;
import org.diylc.appframework.miscutils.ConfigurationManager; import org.diylc.appframework.miscutils.ConfigurationManager;
import org.diylc.common.Display;
import org.diylc.common.IPlugInPort; import org.diylc.common.IPlugInPort;
import org.diylc.common.ObjectCache; import org.diylc.common.ObjectCache;
import org.diylc.components.transform.TO92Transformer; import org.diylc.components.transform.TO92Transformer;
@@ -250,23 +249,27 @@ public class TransistorTO92 extends AbstractTransistorPackage {
: getLabelColor(); : getLabelColor();
} }
g2d.setColor(finalLabelColor); g2d.setColor(finalLabelColor);
String label = ""; if (getDisplay() == TransistorDisplay.PINOUT) {
label = (getDisplay() == Display.NAME) ? getName() : getValue(); drawPinout(g2d);
if (display == Display.NONE) { } else {
label = ""; String label = "";
label = (getDisplay() == TransistorDisplay.NAME) ? getName() : getValue();
if (display == TransistorDisplay.NONE) {
label = "";
}
if (display == TransistorDisplay.BOTH) {
label = getName() + " " + getValue();
}
FontMetrics fontMetrics = g2d.getFontMetrics(g2d.getFont());
Rectangle2D rect = fontMetrics.getStringBounds(label, g2d);
int textHeight = (int) (rect.getHeight());
int textWidth = (int) (rect.getWidth());
// Center text horizontally and vertically
Rectangle bounds = mainArea.getBounds();
int x = bounds.x + (bounds.width - textWidth) / 2;
int y = bounds.y + (bounds.height - textHeight) / 2 + fontMetrics.getAscent();
g2d.drawString(label, x, y);
} }
if (display == Display.BOTH) {
label = getName() + " " + getValue();
}
FontMetrics fontMetrics = g2d.getFontMetrics(g2d.getFont());
Rectangle2D rect = fontMetrics.getStringBounds(label, g2d);
int textHeight = (int) (rect.getHeight());
int textWidth = (int) (rect.getWidth());
// Center text horizontally and vertically
Rectangle bounds = mainArea.getBounds();
int x = bounds.x + (bounds.width - textWidth) / 2;
int y = bounds.y + (bounds.height - textHeight) / 2 + fontMetrics.getAscent();
g2d.drawString(label, x, y);
} }
@Override @Override
Binary file not shown.
Binary file not shown.