diff --git a/diylc/diylc-core/src/org/diylc/presenter/update.xml b/diylc/diylc-core/src/org/diylc/presenter/update.xml
index 74d5bdaf..3a40c7ba 100644
--- a/diylc/diylc-core/src/org/diylc/presenter/update.xml
+++ b/diylc/diylc-core/src/org/diylc/presenter/update.xml
@@ -2942,6 +2942,10 @@
NEW_FEATURE
Added "Duo-Diode" tube symbol
+
+ NEW_FEATURE
+ Transistor components can display pinout instead of name or value
+
IMPROVEMENT
Prevent the app from closing while running background operations, like saving and exporting files
diff --git a/diylc/diylc-library/lib/diylc-core.jar b/diylc/diylc-library/lib/diylc-core.jar
index 5ee6e9a9..75506838 100644
Binary files a/diylc/diylc-library/lib/diylc-core.jar and b/diylc/diylc-library/lib/diylc-core.jar differ
diff --git a/diylc/diylc-library/src/org/diylc/awt/StringUtils.java b/diylc/diylc-library/src/org/diylc/awt/StringUtils.java
index 996266ae..c3822b6c 100644
--- a/diylc/diylc-library/src/org/diylc/awt/StringUtils.java
+++ b/diylc/diylc-library/src/org/diylc/awt/StringUtils.java
@@ -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;
diff --git a/diylc/diylc-library/src/org/diylc/components/boards/AbstractBoard.java b/diylc/diylc-library/src/org/diylc/components/boards/AbstractBoard.java
index 248808b4..6dca6f02 100644
--- a/diylc/diylc-library/src/org/diylc/components/boards/AbstractBoard.java
+++ b/diylc/diylc-library/src/org/diylc/components/boards/AbstractBoard.java
@@ -168,7 +168,7 @@ public abstract class AbstractBoard extends AbstractTransparentComponent
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),
diff --git a/diylc/diylc-library/src/org/diylc/components/boards/Breadboard.java b/diylc/diylc-library/src/org/diylc/components/boards/Breadboard.java
index 6d296179..c9ee19ab 100644
--- a/diylc/diylc-library/src/org/diylc/components/boards/Breadboard.java
+++ b/diylc/diylc-library/src/org/diylc/components/boards/Breadboard.java
@@ -161,10 +161,10 @@ public class Breadboard extends AbstractComponent {
// 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);
}
}
}
diff --git a/diylc/diylc-library/src/org/diylc/components/boards/ProtoBoard.java b/diylc/diylc-library/src/org/diylc/components/boards/ProtoBoard.java
index 66a9e37d..fe747dec 100644
--- a/diylc/diylc-library/src/org/diylc/components/boards/ProtoBoard.java
+++ b/diylc/diylc-library/src/org/diylc/components/boards/ProtoBoard.java
@@ -281,7 +281,7 @@ public class ProtoBoard extends AbstractComponent {
// 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 {
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 {
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
diff --git a/diylc/diylc-library/src/org/diylc/components/semiconductors/AbstractTransistorPackage.java b/diylc/diylc-library/src/org/diylc/components/semiconductors/AbstractTransistorPackage.java
index 4446b92b..86dc453c 100644
--- a/diylc/diylc-library/src/org/diylc/components/semiconductors/AbstractTransistorPackage.java
+++ b/diylc/diylc-library/src/org/diylc/components/semiconductors/AbstractTransistorPackage.java
@@ -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();
+ }
+ }
}
diff --git a/diylc/diylc-library/src/org/diylc/components/semiconductors/TransistorPinout.java b/diylc/diylc-library/src/org/diylc/components/semiconductors/TransistorPinout.java
index b652263f..9abc125e 100644
--- a/diylc/diylc-library/src/org/diylc/components/semiconductors/TransistorPinout.java
+++ b/diylc/diylc-library/src/org/diylc/components/semiconductors/TransistorPinout.java
@@ -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];
+ }
}
diff --git a/diylc/diylc-library/src/org/diylc/components/semiconductors/TransistorTO1.java b/diylc/diylc-library/src/org/diylc/components/semiconductors/TransistorTO1.java
index 1996e81b..d3842785 100644
--- a/diylc/diylc-library/src/org/diylc/components/semiconductors/TransistorTO1.java
+++ b/diylc/diylc-library/src/org/diylc/components/semiconductors/TransistorTO1.java
@@ -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;
}
}
diff --git a/diylc/diylc-library/src/org/diylc/components/semiconductors/TransistorTO126.java b/diylc/diylc-library/src/org/diylc/components/semiconductors/TransistorTO126.java
index 360bf1a4..cd321498 100644
--- a/diylc/diylc-library/src/org/diylc/components/semiconductors/TransistorTO126.java
+++ b/diylc/diylc-library/src/org/diylc/components/semiconductors/TransistorTO126.java
@@ -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
diff --git a/diylc/diylc-library/src/org/diylc/components/semiconductors/TransistorTO220.java b/diylc/diylc-library/src/org/diylc/components/semiconductors/TransistorTO220.java
index e6f16562..685a2e5a 100644
--- a/diylc/diylc-library/src/org/diylc/components/semiconductors/TransistorTO220.java
+++ b/diylc/diylc-library/src/org/diylc/components/semiconductors/TransistorTO220.java
@@ -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;
+ }
}
diff --git a/diylc/diylc-library/src/org/diylc/components/semiconductors/TransistorTO92.java b/diylc/diylc-library/src/org/diylc/components/semiconductors/TransistorTO92.java
index 03a16b65..ea89a455 100644
--- a/diylc/diylc-library/src/org/diylc/components/semiconductors/TransistorTO92.java
+++ b/diylc/diylc-library/src/org/diylc/components/semiconductors/TransistorTO92.java
@@ -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
diff --git a/diylc/diylc-swing/lib/diylc-core.jar b/diylc/diylc-swing/lib/diylc-core.jar
index 5ee6e9a9..855a12dc 100644
Binary files a/diylc/diylc-swing/lib/diylc-core.jar and b/diylc/diylc-swing/lib/diylc-core.jar differ
diff --git a/diylc/diylc-swing/library/main.jar b/diylc/diylc-swing/library/main.jar
index 8e6cccfb..cb1c1592 100644
Binary files a/diylc/diylc-swing/library/main.jar and b/diylc/diylc-swing/library/main.jar differ