mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-11 01:32:08 +10:00
ability to center label
This commit is contained in:
@@ -1,15 +1,15 @@
|
|||||||
<map>
|
<map>
|
||||||
<entry>
|
<entry>
|
||||||
<string>lastPath</string>
|
<string>metric</string>
|
||||||
<string>C:\Documents and Settings\Branislav Stojkovic\Desktop\oldFiles</string>
|
<boolean>true</boolean>
|
||||||
</entry>
|
</entry>
|
||||||
<entry>
|
<entry>
|
||||||
<string>zoom</string>
|
<string>zoom</string>
|
||||||
<double>1.0</double>
|
<double>1.0</double>
|
||||||
</entry>
|
</entry>
|
||||||
<entry>
|
<entry>
|
||||||
<string>metric</string>
|
<string>lastPath</string>
|
||||||
<boolean>true</boolean>
|
<string>C:\Documents and Settings\Branislav Stojkovic\Desktop\oldFiles</string>
|
||||||
</entry>
|
</entry>
|
||||||
<entry>
|
<entry>
|
||||||
<string>default.org.diylc.components.misc.Label:Color</string>
|
<string>default.org.diylc.components.misc.Label:Color</string>
|
||||||
|
|||||||
Binary file not shown.
+7
-6
@@ -206,15 +206,16 @@ public class ProjectFileManager {
|
|||||||
IDIYComponent<?> component = null;
|
IDIYComponent<?> component = null;
|
||||||
if (nodeName.equalsIgnoreCase("text")) {
|
if (nodeName.equalsIgnoreCase("text")) {
|
||||||
LOG.debug("Recognized " + nodeName);
|
LOG.debug("Recognized " + nodeName);
|
||||||
Label pad = new Label();
|
Label label = new Label();
|
||||||
pad.setName(nameAttr);
|
label.setName(nameAttr);
|
||||||
if (color != null) {
|
if (color != null) {
|
||||||
pad.setColor(color);
|
label.setColor(color);
|
||||||
}
|
}
|
||||||
pad.setText(valueAttr);
|
label.setText(valueAttr);
|
||||||
pad.setControlPoint(convertV1CoordinatesToV3Point(referencePoint, x1Attr,
|
label.setCenter(false);
|
||||||
|
label.setControlPoint(convertV1CoordinatesToV3Point(referencePoint, x1Attr,
|
||||||
y1Attr), 0);
|
y1Attr), 0);
|
||||||
component = pad;
|
component = label;
|
||||||
} else if (nodeName.equalsIgnoreCase("pad")) {
|
} else if (nodeName.equalsIgnoreCase("pad")) {
|
||||||
LOG.debug("Recognized " + nodeName);
|
LOG.debug("Recognized " + nodeName);
|
||||||
SolderPad pad = new SolderPad();
|
SolderPad pad = new SolderPad();
|
||||||
|
|||||||
+18
-2
@@ -27,6 +27,7 @@ public class Label extends AbstractComponent<Void> {
|
|||||||
private String text = DEFAULT_TEXT;
|
private String text = DEFAULT_TEXT;
|
||||||
private Font font = LABEL_FONT;
|
private Font font = LABEL_FONT;
|
||||||
private Color color = LABEL_COLOR;
|
private Color color = LABEL_COLOR;
|
||||||
|
private boolean center = true;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void draw(Graphics2D g2d, ComponentState componentState, Project project,
|
public void draw(Graphics2D g2d, ComponentState componentState, Project project,
|
||||||
@@ -39,9 +40,16 @@ public class Label extends AbstractComponent<Void> {
|
|||||||
int textHeight = (int) rect.getHeight();
|
int textHeight = (int) rect.getHeight();
|
||||||
int textWidth = (int) rect.getWidth();
|
int textWidth = (int) rect.getWidth();
|
||||||
|
|
||||||
|
int x;
|
||||||
|
int y;
|
||||||
|
if (center) {
|
||||||
// Center text horizontally and vertically
|
// Center text horizontally and vertically
|
||||||
int x = point.x - textWidth / 2;
|
x = point.x - textWidth / 2;
|
||||||
int y = point.y - textHeight / 2 + fontMetrics.getAscent();
|
y = point.y - textHeight / 2 + fontMetrics.getAscent();
|
||||||
|
} else {
|
||||||
|
x = point.x;
|
||||||
|
y = point.y - textHeight;
|
||||||
|
}
|
||||||
|
|
||||||
g2d.drawString(text, x, y);
|
g2d.drawString(text, x, y);
|
||||||
}
|
}
|
||||||
@@ -107,6 +115,14 @@ public class Label extends AbstractComponent<Void> {
|
|||||||
this.color = color;
|
this.color = color;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean getCenter() {
|
||||||
|
return center;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCenter(boolean center) {
|
||||||
|
this.center = center;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return super.getName();
|
return super.getName();
|
||||||
|
|||||||
Reference in New Issue
Block a user