mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-12 02:02:16 +10:00
Transistors can show name or value
This commit is contained in:
Binary file not shown.
+17
-2
@@ -11,6 +11,7 @@ import java.awt.Shape;
|
|||||||
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.common.Orientation;
|
import org.diylc.common.Orientation;
|
||||||
@@ -53,6 +54,7 @@ public class TransistorTO220 extends AbstractTransparentComponent<String> {
|
|||||||
private Color borderColor = BORDER_COLOR;
|
private Color borderColor = BORDER_COLOR;
|
||||||
private Color tabColor = TAB_COLOR;
|
private Color tabColor = TAB_COLOR;
|
||||||
private Color tabBorderColor = TAB_BORDER_COLOR;
|
private Color tabBorderColor = TAB_BORDER_COLOR;
|
||||||
|
private Display display = Display.NAME;
|
||||||
|
|
||||||
public TransistorTO220() {
|
public TransistorTO220() {
|
||||||
super();
|
super();
|
||||||
@@ -246,15 +248,16 @@ public class TransistorTO220 extends AbstractTransparentComponent<String> {
|
|||||||
: LABEL_COLOR;
|
: LABEL_COLOR;
|
||||||
}
|
}
|
||||||
g2d.setColor(finalLabelColor);
|
g2d.setColor(finalLabelColor);
|
||||||
|
String label = (getDisplay() == Display.NAME) ? getName() : getValue();
|
||||||
FontMetrics fontMetrics = g2d.getFontMetrics(g2d.getFont());
|
FontMetrics fontMetrics = g2d.getFontMetrics(g2d.getFont());
|
||||||
Rectangle2D rect = fontMetrics.getStringBounds(getName(), g2d);
|
Rectangle2D rect = fontMetrics.getStringBounds(label, g2d);
|
||||||
int textHeight = (int) (rect.getHeight());
|
int textHeight = (int) (rect.getHeight());
|
||||||
int textWidth = (int) (rect.getWidth());
|
int textWidth = (int) (rect.getWidth());
|
||||||
// Center text horizontally and vertically
|
// Center text horizontally and vertically
|
||||||
Rectangle bounds = mainArea.getBounds();
|
Rectangle bounds = mainArea.getBounds();
|
||||||
int x = bounds.x + (bounds.width - textWidth) / 2;
|
int x = bounds.x + (bounds.width - textWidth) / 2;
|
||||||
int y = bounds.y + (bounds.height - textHeight) / 2 + fontMetrics.getAscent();
|
int y = bounds.y + (bounds.height - textHeight) / 2 + fontMetrics.getAscent();
|
||||||
g2d.drawString(getName(), x, y);
|
g2d.drawString(label, x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -304,4 +307,16 @@ public class TransistorTO220 extends AbstractTransparentComponent<String> {
|
|||||||
public void setTabBorderColor(Color tabBorderColor) {
|
public void setTabBorderColor(Color tabBorderColor) {
|
||||||
this.tabBorderColor = tabBorderColor;
|
this.tabBorderColor = tabBorderColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@EditableProperty
|
||||||
|
public Display getDisplay() {
|
||||||
|
if (display == null) {
|
||||||
|
display = Display.NAME;
|
||||||
|
}
|
||||||
|
return display;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDisplay(Display display) {
|
||||||
|
this.display = display;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+17
-2
@@ -12,6 +12,7 @@ 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.common.Orientation;
|
import org.diylc.common.Orientation;
|
||||||
@@ -48,6 +49,7 @@ public class TransistorTO92 extends AbstractTransparentComponent<String> {
|
|||||||
transient private Area body;
|
transient private Area body;
|
||||||
private Color bodyColor = BODY_COLOR;
|
private Color bodyColor = BODY_COLOR;
|
||||||
private Color borderColor = BORDER_COLOR;
|
private Color borderColor = BORDER_COLOR;
|
||||||
|
protected Display display = Display.NAME;
|
||||||
|
|
||||||
public TransistorTO92() {
|
public TransistorTO92() {
|
||||||
super();
|
super();
|
||||||
@@ -222,15 +224,16 @@ public class TransistorTO92 extends AbstractTransparentComponent<String> {
|
|||||||
: LABEL_COLOR;
|
: LABEL_COLOR;
|
||||||
}
|
}
|
||||||
g2d.setColor(finalLabelColor);
|
g2d.setColor(finalLabelColor);
|
||||||
|
String label = (getDisplay() == Display.NAME) ? getName() : getValue();
|
||||||
FontMetrics fontMetrics = g2d.getFontMetrics(g2d.getFont());
|
FontMetrics fontMetrics = g2d.getFontMetrics(g2d.getFont());
|
||||||
Rectangle2D rect = fontMetrics.getStringBounds(getName(), g2d);
|
Rectangle2D rect = fontMetrics.getStringBounds(label, g2d);
|
||||||
int textHeight = (int) (rect.getHeight());
|
int textHeight = (int) (rect.getHeight());
|
||||||
int textWidth = (int) (rect.getWidth());
|
int textWidth = (int) (rect.getWidth());
|
||||||
// Center text horizontally and vertically
|
// Center text horizontally and vertically
|
||||||
Rectangle bounds = mainArea.getBounds();
|
Rectangle bounds = mainArea.getBounds();
|
||||||
int x = bounds.x + (bounds.width - textWidth) / 2;
|
int x = bounds.x + (bounds.width - textWidth) / 2;
|
||||||
int y = bounds.y + (bounds.height - textHeight) / 2 + fontMetrics.getAscent();
|
int y = bounds.y + (bounds.height - textHeight) / 2 + fontMetrics.getAscent();
|
||||||
g2d.drawString(getName(), x, y);
|
g2d.drawString(label, x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -264,4 +267,16 @@ public class TransistorTO92 extends AbstractTransparentComponent<String> {
|
|||||||
public void setBorderColor(Color borderColor) {
|
public void setBorderColor(Color borderColor) {
|
||||||
this.borderColor = borderColor;
|
this.borderColor = borderColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@EditableProperty
|
||||||
|
public Display getDisplay() {
|
||||||
|
if (display == null) {
|
||||||
|
display = Display.NAME;
|
||||||
|
}
|
||||||
|
return display;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDisplay(Display display) {
|
||||||
|
this.display = display;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user