mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-12 02:02:16 +10:00
Smarter resistor labels; try not to overlap label with bands
This commit is contained in:
@@ -62,6 +62,12 @@
|
|||||||
<attribute name="Class-Path" value="${manifest.class.path}" />
|
<attribute name="Class-Path" value="${manifest.class.path}" />
|
||||||
</manifest>
|
</manifest>
|
||||||
</jar>
|
</jar>
|
||||||
|
<copy todir="../diylc-swing/lib" overwrite="true">
|
||||||
|
<fileset dir="${jar.dir}" includes="${ant.project.name}.jar" />
|
||||||
|
</copy>
|
||||||
|
<copy todir="../library/lib" overwrite="true">
|
||||||
|
<fileset dir="${jar.dir}" includes="${ant.project.name}.jar" />
|
||||||
|
</copy>
|
||||||
</target>
|
</target>
|
||||||
|
|
||||||
<target name="javadoc">
|
<target name="javadoc">
|
||||||
|
|||||||
+1
-1
@@ -31,7 +31,7 @@ public abstract class AbstractComponent<T> implements IDIYComponent<T> {
|
|||||||
public static Color SELECTION_COLOR = Color.red;
|
public static Color SELECTION_COLOR = Color.red;
|
||||||
public static Color LABEL_COLOR = Color.black;
|
public static Color LABEL_COLOR = Color.black;
|
||||||
public static Color LABEL_COLOR_SELECTED = Color.red;
|
public static Color LABEL_COLOR_SELECTED = Color.red;
|
||||||
public static Font LABEL_FONT = new Font("Tahoma", Font.PLAIN, 13);
|
public static Font LABEL_FONT = new Font("Tahoma", Font.PLAIN, 14);
|
||||||
|
|
||||||
@EditableProperty(defaultable = false)
|
@EditableProperty(defaultable = false)
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
+9
-2
@@ -195,13 +195,16 @@ public abstract class AbstractLeadedComponent<T> extends AbstractTransparentComp
|
|||||||
g2d.setColor(finalLabelColor);
|
g2d.setColor(finalLabelColor);
|
||||||
FontMetrics fontMetrics = g2d.getFontMetrics();
|
FontMetrics fontMetrics = g2d.getFontMetrics();
|
||||||
String label = display == Display.NAME ? getName() : getValue().toString();
|
String label = display == Display.NAME ? getName() : getValue().toString();
|
||||||
|
Rectangle2D textRect = fontMetrics.getStringBounds(label, g2d);
|
||||||
|
// Don't offset in outline mode.
|
||||||
|
int offset = outlineMode ? 0 : getLabelOffset((int) shapeRect.getWidth(), (int) textRect.getWidth());
|
||||||
// Adjust label angle if needed to make sure that it's readable.
|
// Adjust label angle if needed to make sure that it's readable.
|
||||||
if ((theta >= Math.PI / 2 && theta <= Math.PI)
|
if ((theta >= Math.PI / 2 && theta <= Math.PI)
|
||||||
|| (theta < -Math.PI / 2 && theta > -Math.PI)) {
|
|| (theta < -Math.PI / 2 && theta > -Math.PI)) {
|
||||||
g2d.rotate(Math.PI, shapeRect.width / 2, shapeRect.height / 2);
|
g2d.rotate(Math.PI, shapeRect.width / 2, shapeRect.height / 2);
|
||||||
|
offset = -offset;
|
||||||
}
|
}
|
||||||
Rectangle2D textRect = fontMetrics.getStringBounds(label, g2d);
|
g2d.drawString(label, (int) (shapeRect.width - textRect.getWidth()) / 2 + offset,
|
||||||
g2d.drawString(label, (int) (shapeRect.width - textRect.getWidth()) / 2,
|
|
||||||
calculateLabelYCoordinate(shapeRect, textRect, fontMetrics));
|
calculateLabelYCoordinate(shapeRect, textRect, fontMetrics));
|
||||||
g2d.setTransform(oldTransform);
|
g2d.setTransform(oldTransform);
|
||||||
}
|
}
|
||||||
@@ -238,6 +241,10 @@ public abstract class AbstractLeadedComponent<T> extends AbstractTransparentComp
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected int getLabelOffset(int bodyWidth, int labelWidth) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return default component length.
|
* @return default component length.
|
||||||
*/
|
*/
|
||||||
|
|||||||
+1
-1
@@ -55,7 +55,7 @@ public class Presenter implements IPlugInPort {
|
|||||||
|
|
||||||
private static final Logger LOG = Logger.getLogger(Presenter.class);
|
private static final Logger LOG = Logger.getLogger(Presenter.class);
|
||||||
|
|
||||||
public static final VersionNumber CURRENT_VERSION = new VersionNumber(3, 1, 0);
|
public static final VersionNumber CURRENT_VERSION = new VersionNumber(3, 2, 0);
|
||||||
public static final String DEFAULTS_KEY_PREFIX = "default.";
|
public static final String DEFAULTS_KEY_PREFIX = "default.";
|
||||||
|
|
||||||
public static final List<IDIYComponent<?>> EMPTY_SELECTION = Collections.emptyList();
|
public static final List<IDIYComponent<?>> EMPTY_SELECTION = Collections.emptyList();
|
||||||
|
|||||||
Binary file not shown.
+14
-2
@@ -27,6 +27,8 @@ public class Resistor extends AbstractLeadedComponent<Resistance> {
|
|||||||
public static Size DEFAULT_HEIGHT = new Size(1d / 8, SizeUnit.in);
|
public static Size DEFAULT_HEIGHT = new Size(1d / 8, SizeUnit.in);
|
||||||
public static Color BODY_COLOR = Color.decode("#82CFFD");
|
public static Color BODY_COLOR = Color.decode("#82CFFD");
|
||||||
public static Color BORDER_COLOR = BODY_COLOR.darker();
|
public static Color BORDER_COLOR = BODY_COLOR.darker();
|
||||||
|
public static int BAND_SPACING = 5;
|
||||||
|
public static int FIRST_BAND = 4;
|
||||||
|
|
||||||
private Resistance value = new Resistance(123d, ResistanceUnit.K);
|
private Resistance value = new Resistance(123d, ResistanceUnit.K);
|
||||||
private Power power = Power.HALF;
|
private Power power = Power.HALF;
|
||||||
@@ -110,12 +112,22 @@ public class Resistor extends AbstractLeadedComponent<Resistance> {
|
|||||||
}
|
}
|
||||||
int height = getClosestOdd(getWidth().convertToPixels());
|
int height = getClosestOdd(getWidth().convertToPixels());
|
||||||
Color[] bands = value.getColorCode(colorCode);
|
Color[] bands = value.getColorCode(colorCode);
|
||||||
int x = 4;
|
int x = FIRST_BAND;
|
||||||
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(2));
|
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(2));
|
||||||
for (int i = 0; i < bands.length; i++) {
|
for (int i = 0; i < bands.length; i++) {
|
||||||
g2d.setColor(bands[i]);
|
g2d.setColor(bands[i]);
|
||||||
g2d.drawLine(x, 1, x, height - 1);
|
g2d.drawLine(x, 1, x, height - 1);
|
||||||
x += 5;
|
x += BAND_SPACING;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected int getLabelOffset(int bodyWidth, int labelWidth) {
|
||||||
|
Color[] bands = value.getColorCode(colorCode);
|
||||||
|
int bandArea = FIRST_BAND + BAND_SPACING * (bands.length - 1);
|
||||||
|
// Only offset the label if overlaping with the band area.
|
||||||
|
if (labelWidth > bodyWidth - 2 * bandArea)
|
||||||
|
return bandArea / 2;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
@@ -426,6 +426,10 @@
|
|||||||
<changeType>NEW_FEATURE</changeType>
|
<changeType>NEW_FEATURE</changeType>
|
||||||
<description>Perfboards can show hole coordinates</description>
|
<description>Perfboards can show hole coordinates</description>
|
||||||
</com.diyfever.gui.update.Change>
|
</com.diyfever.gui.update.Change>
|
||||||
|
<com.diyfever.gui.update.Change>
|
||||||
|
<changeType>IMPROVEMENT</changeType>
|
||||||
|
<description>Smarter resistor labels; try not to overlap label with bands</description>
|
||||||
|
</com.diyfever.gui.update.Change>
|
||||||
</changes>
|
</changes>
|
||||||
<url>http://code.google.com/p/diy-layout-creator/downloads/list</url>
|
<url>http://code.google.com/p/diy-layout-creator/downloads/list</url>
|
||||||
</com.diyfever.gui.update.Version>
|
</com.diyfever.gui.update.Version>
|
||||||
|
|||||||
Reference in New Issue
Block a user