DIL IC label improvements

This commit is contained in:
bancika
2017-04-27 13:56:24 +02:00
parent ccf6e7bb7e
commit 0fcd523d6b
5 changed files with 58 additions and 18 deletions
Binary file not shown.
@@ -7,6 +7,7 @@ import java.awt.FontMetrics;
import java.awt.Graphics2D; import java.awt.Graphics2D;
import java.awt.Point; import java.awt.Point;
import java.awt.Rectangle; import java.awt.Rectangle;
import java.awt.geom.AffineTransform;
import java.awt.geom.Area; import java.awt.geom.Area;
import java.awt.geom.Ellipse2D; import java.awt.geom.Ellipse2D;
import java.awt.geom.Rectangle2D; import java.awt.geom.Rectangle2D;
@@ -56,7 +57,7 @@ public class DIL_IC extends AbstractTransparentComponent<String> {
private Size pinSpacing = new Size(0.1d, SizeUnit.in); private Size pinSpacing = new Size(0.1d, SizeUnit.in);
private Size rowSpacing = new Size(0.3d, SizeUnit.in); private Size rowSpacing = new Size(0.3d, SizeUnit.in);
private Point[] controlPoints = new Point[] {new Point(0, 0)}; private Point[] controlPoints = new Point[] {new Point(0, 0)};
protected Display display = Display.NAME; protected Display display = Display.BOTH;
private Color bodyColor = BODY_COLOR; private Color bodyColor = BODY_COLOR;
private Color borderColor = BORDER_COLOR; private Color borderColor = BORDER_COLOR;
private Color labelColor = LABEL_COLOR; private Color labelColor = LABEL_COLOR;
@@ -329,6 +330,9 @@ public class DIL_IC extends AbstractTransparentComponent<String> {
g2d.fill(getBody()[1]); g2d.fill(getBody()[1]);
} }
} }
drawingObserver.stopTracking();
// Draw label. // Draw label.
g2d.setFont(project.getFont()); g2d.setFont(project.getFont());
Color finalLabelColor; Color finalLabelColor;
@@ -345,22 +349,48 @@ public class DIL_IC extends AbstractTransparentComponent<String> {
} }
g2d.setColor(finalLabelColor); g2d.setColor(finalLabelColor);
FontMetrics fontMetrics = g2d.getFontMetrics(g2d.getFont()); FontMetrics fontMetrics = g2d.getFontMetrics(g2d.getFont());
String label = ""; String[] label = null;
label = (getDisplay() == Display.NAME) ? getName() : getValue();
if (getDisplay() == Display.NONE) { if (getDisplay() == Display.NAME) {
label = ""; label = new String[] {getName()};
} else if (getDisplay() == Display.VALUE) {
label = new String[] {getValue().toString()};
} else if (getDisplay() == Display.BOTH) {
String value = getValue().toString();
label = value.isEmpty() ? new String[] {getName()} : new String[] {getName(), value};
} }
if (getDisplay() == Display.BOTH) {
label = getName() + " " + (getValue() == null ? "" : getValue().toString()); if (label != null) {
} for (int i = 0; i < label.length; i++) {
Rectangle2D rect = fontMetrics.getStringBounds(label, g2d); String l = label[i];
Rectangle2D rect = fontMetrics.getStringBounds(l, 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(label, x, y);
AffineTransform oldTransform = g2d.getTransform();
if (getOrientation() == Orientation.DEFAULT || getOrientation() == Orientation._180) {
int centerX = bounds.x + bounds.width / 2;
int centerY = bounds.y + bounds.height / 2;
g2d.rotate(-Math.PI / 2, centerX, centerY);
}
if (label.length == 2) {
if (i == 0)
g2d.translate(0, -textHeight / 2);
else if (i == 1)
g2d.translate(0, textHeight / 2);
}
g2d.drawString(l, x, y);
g2d.setTransform(oldTransform);
}
}
// draw pin numbers // draw pin numbers
int pinNo = 0; int pinNo = 0;
@@ -501,11 +531,17 @@ public class DIL_IC extends AbstractTransparentComponent<String> {
public enum DisplayNumbers { public enum DisplayNumbers {
NO, DIP, CONNECTOR; NO("No"), DIP("DIP"), CONNECTOR("Connector");
private String label;
private DisplayNumbers(String label) {
this.label = label;
}
@Override @Override
public String toString() { public String toString() {
return name(); return label;
} }
} }
} }
Binary file not shown.
Binary file not shown.
+4
View File
@@ -1774,6 +1774,10 @@
<changeType>IMPROVEMENT</changeType> <changeType>IMPROVEMENT</changeType>
<description>Do not block the UI while checking for new version at startup (can be problematic when there's connectivity issues)</description> <description>Do not block the UI while checking for new version at startup (can be problematic when there's connectivity issues)</description>
</org.diylc.appframework.update.Change> </org.diylc.appframework.update.Change>
<org.diylc.appframework.update.Change>
<changeType>IMPROVEMENT</changeType>
<description>DIL IC label rotates to fit the longer side of the component. Name and value are displayed in separate lines</description>
</org.diylc.appframework.update.Change>
</changes> </changes>
<url>https://github.com/bancika/diy-layout-creator/releases</url> <url>https://github.com/bancika/diy-layout-creator/releases</url>
</org.diylc.appframework.update.Version> </org.diylc.appframework.update.Version>