mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-10 17:22:09 +10:00
added display pinout
This commit is contained in:
Binary file not shown.
@@ -230,7 +230,7 @@ public class StringUtils {
|
||||
int textY = 0;
|
||||
switch (verticalAlignment) {
|
||||
case TOP:
|
||||
textY = y + stringBounds.height;
|
||||
textY = y;
|
||||
break;
|
||||
case CENTER:
|
||||
textY = y - visualBounds.height / 2 - visualBounds.y;
|
||||
|
||||
@@ -168,7 +168,7 @@ public abstract class AbstractBoard extends AbstractTransparentComponent<String>
|
||||
drawPoint.x += xOffset;
|
||||
StringUtils.drawCenteredText(g2d, label,
|
||||
drawPoint.x, firstPoint.y - 2,
|
||||
HorizontalAlignment.CENTER, VerticalAlignment.TOP);
|
||||
HorizontalAlignment.CENTER, VerticalAlignment.BOTTOM);
|
||||
if (getCoordinateDisplay() == CoordinateDisplay.Both_Sides) {
|
||||
StringUtils.drawCenteredText(g2d, label,
|
||||
drawPoint.x, (int) (finalSecondPoint.y - COORDINATE_FONT_SIZE),
|
||||
|
||||
@@ -161,10 +161,10 @@ public class Breadboard extends AbstractComponent<Void> {
|
||||
// Draw horizontal labels
|
||||
if (y == 0) {
|
||||
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);
|
||||
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
|
||||
if (y == 0) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -443,7 +443,7 @@ public class ProtoBoard extends AbstractComponent<Void> {
|
||||
HorizontalAlignment.RIGHT, VerticalAlignment.CENTER);
|
||||
|
||||
// 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, "+", (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);
|
||||
@@ -467,7 +467,7 @@ public class ProtoBoard extends AbstractComponent<Void> {
|
||||
g2d.setColor(textColor);
|
||||
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);
|
||||
|
||||
// draw central mini pads
|
||||
|
||||
+80
-5
@@ -22,12 +22,16 @@
|
||||
package org.diylc.components.semiconductors;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Font;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Point;
|
||||
import java.awt.geom.Area;
|
||||
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.VerticalAlignment;
|
||||
import org.diylc.components.AbstractTransparentComponent;
|
||||
import org.diylc.core.VisibilityPolicy;
|
||||
import org.diylc.core.annotations.EditableProperty;
|
||||
@@ -46,7 +50,7 @@ public abstract class AbstractTransistorPackage extends AbstractTransparentCompo
|
||||
protected Color bodyColor;
|
||||
protected Color borderColor;
|
||||
protected Color labelColor = LABEL_COLOR;
|
||||
protected Display display = Display.NAME;
|
||||
protected TransistorDisplay display = TransistorDisplay.NAME;
|
||||
|
||||
public AbstractTransistorPackage() {
|
||||
}
|
||||
@@ -180,14 +184,14 @@ public abstract class AbstractTransistorPackage extends AbstractTransparentCompo
|
||||
}
|
||||
|
||||
@EditableProperty
|
||||
public Display getDisplay() {
|
||||
public TransistorDisplay getDisplay() {
|
||||
if (display == null) {
|
||||
display = Display.NAME;
|
||||
display = TransistorDisplay.NAME;
|
||||
}
|
||||
return display;
|
||||
}
|
||||
|
||||
public void setDisplay(Display display) {
|
||||
public void setDisplay(TransistorDisplay display) {
|
||||
this.display = display;
|
||||
}
|
||||
|
||||
@@ -218,4 +222,75 @@ public abstract class AbstractTransistorPackage extends AbstractTransparentCompo
|
||||
Rectangle2D bounds = getBody()[0].getBounds2D();
|
||||
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]);
|
||||
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 org.diylc.appframework.miscutils.ConfigurationManager;
|
||||
import org.diylc.common.Display;
|
||||
import org.diylc.common.IPlugInPort;
|
||||
import org.diylc.common.ObjectCache;
|
||||
import org.diylc.components.transform.TO1Transformer;
|
||||
@@ -212,24 +211,28 @@ public class TransistorTO1 extends AbstractTransistorPackage {
|
||||
componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? LABEL_COLOR_SELECTED
|
||||
: getLabelColor();
|
||||
}
|
||||
g2d.setColor(finalLabelColor);
|
||||
String label = "";
|
||||
label = (getDisplay() == Display.NAME) ? getName() : getValue();
|
||||
if (getDisplay() == Display.NONE) {
|
||||
label = "";
|
||||
g2d.setColor(finalLabelColor);
|
||||
if (getDisplay() == TransistorDisplay.PINOUT) {
|
||||
drawPinout(g2d);
|
||||
} else {
|
||||
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
|
||||
@@ -269,5 +272,10 @@ public class TransistorTO1 extends AbstractTransistorPackage {
|
||||
updateControlPoints();
|
||||
// Reset body shape;
|
||||
body = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean flipPinoutLabel() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,7 +34,6 @@ import java.awt.geom.Ellipse2D;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
|
||||
import org.diylc.appframework.miscutils.ConfigurationManager;
|
||||
import org.diylc.common.Display;
|
||||
import org.diylc.common.IPlugInPort;
|
||||
import org.diylc.common.ObjectCache;
|
||||
import org.diylc.components.transform.TO220Transformer;
|
||||
@@ -294,24 +293,28 @@ public class TransistorTO126 extends AbstractTransistorPackage {
|
||||
componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? LABEL_COLOR_SELECTED
|
||||
: getLabelColor();
|
||||
}
|
||||
g2d.setColor(finalLabelColor);
|
||||
String label = "";
|
||||
label = (getDisplay() == Display.NAME) ? getName() : getValue();
|
||||
if (getDisplay() == Display.NONE) {
|
||||
label = "";
|
||||
g2d.setColor(finalLabelColor);
|
||||
if (getDisplay() == TransistorDisplay.PINOUT) {
|
||||
drawPinout(g2d);
|
||||
} else {
|
||||
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
|
||||
|
||||
@@ -34,7 +34,6 @@ import java.awt.geom.Ellipse2D;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
|
||||
import org.diylc.appframework.miscutils.ConfigurationManager;
|
||||
import org.diylc.common.Display;
|
||||
import org.diylc.common.IPlugInPort;
|
||||
import org.diylc.common.ObjectCache;
|
||||
import org.diylc.components.transform.TO220Transformer;
|
||||
@@ -331,24 +330,28 @@ public class TransistorTO220 extends AbstractTransistorPackage {
|
||||
componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? LABEL_COLOR_SELECTED
|
||||
: getLabelColor();
|
||||
}
|
||||
g2d.setColor(finalLabelColor);
|
||||
String label = "";
|
||||
label = (getDisplay() == Display.NAME) ? getName() : getValue();
|
||||
if (getDisplay() == Display.NONE) {
|
||||
label = "";
|
||||
g2d.setColor(finalLabelColor);
|
||||
if (getDisplay() == TransistorDisplay.PINOUT) {
|
||||
drawPinout(g2d);
|
||||
} else {
|
||||
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
|
||||
@@ -416,5 +419,10 @@ public class TransistorTO220 extends AbstractTransistorPackage {
|
||||
|
||||
public void setTabBorderColor(Color 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 org.diylc.appframework.miscutils.ConfigurationManager;
|
||||
import org.diylc.common.Display;
|
||||
import org.diylc.common.IPlugInPort;
|
||||
import org.diylc.common.ObjectCache;
|
||||
import org.diylc.components.transform.TO92Transformer;
|
||||
@@ -249,24 +248,28 @@ public class TransistorTO92 extends AbstractTransistorPackage {
|
||||
componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? LABEL_COLOR_SELECTED
|
||||
: getLabelColor();
|
||||
}
|
||||
g2d.setColor(finalLabelColor);
|
||||
String label = "";
|
||||
label = (getDisplay() == Display.NAME) ? getName() : getValue();
|
||||
if (display == Display.NONE) {
|
||||
label = "";
|
||||
g2d.setColor(finalLabelColor);
|
||||
if (getDisplay() == TransistorDisplay.PINOUT) {
|
||||
drawPinout(g2d);
|
||||
} else {
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user