better default label position on schematic symbols

This commit is contained in:
Branislav Stojkovic
2019-03-19 19:03:21 +01:00
parent 9925d58347
commit a0601cc83d
5 changed files with 18 additions and 6 deletions
Binary file not shown.
@@ -98,6 +98,8 @@ public abstract class AbstractLeadedComponent<T> extends AbstractTransparentComp
} catch (NullPointerException e) { } catch (NullPointerException e) {
// This will happen if components do not have any shape. // This will happen if components do not have any shape.
} }
if (newPoints != null)
newPoints[2] = calculateLabelPosition(newPoints[0], newPoints[1]);
} }
protected boolean IsCopperArea() { protected boolean IsCopperArea() {
@@ -21,13 +21,14 @@
*/ */
package org.diylc.components; package org.diylc.components;
import java.awt.Color; import java.awt.Color;
import java.awt.FontMetrics; import java.awt.FontMetrics;
import java.awt.geom.Rectangle2D; import java.awt.Point;
import java.awt.geom.Rectangle2D;
import org.diylc.common.LabelPosition; import org.diylc.common.LabelPosition;
import org.diylc.core.ComponentState; import org.diylc.core.ComponentState;
import org.diylc.core.annotations.EditableProperty; import org.diylc.core.annotations.EditableProperty;
public abstract class AbstractSchematicLeadedSymbol<T> extends AbstractLeadedComponent<T> { public abstract class AbstractSchematicLeadedSymbol<T> extends AbstractLeadedComponent<T> {
@@ -68,6 +69,15 @@ public abstract class AbstractSchematicLeadedSymbol<T> extends AbstractLeadedCom
} else { } else {
return (int) (shapeRect.getHeight() + textRect.getHeight()); return (int) (shapeRect.getHeight() + textRect.getHeight());
} }
}
@Override
protected Point calculateLabelPosition(Point point1, Point point2) {
double x = (point1.x + point2.x) / 2.0;
double y = (point1.y + point2.y) / 2.0;
double theta = Math.atan2(point2.y - point1.y, point2.x - point2.x) - Math.PI / 2;
double r = width.convertToPixels() / 2 + LABEL_FONT.getSize() / 2;
return new Point((int) (x + Math.cos(theta) * r), (int) (y + Math.sin(theta) * r));
} }
@EditableProperty(name = "Label Position") @EditableProperty(name = "Label Position")
Binary file not shown.
Binary file not shown.