mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-11 01:32:08 +10:00
Ability to rotate text
This commit is contained in:
Binary file not shown.
+26
-1
@@ -8,6 +8,7 @@ import java.awt.Point;
|
|||||||
import java.awt.geom.Rectangle2D;
|
import java.awt.geom.Rectangle2D;
|
||||||
|
|
||||||
import org.diylc.common.HorizontalAlignment;
|
import org.diylc.common.HorizontalAlignment;
|
||||||
|
import org.diylc.common.Orientation;
|
||||||
import org.diylc.common.VerticalAlignment;
|
import org.diylc.common.VerticalAlignment;
|
||||||
import org.diylc.components.AbstractComponent;
|
import org.diylc.components.AbstractComponent;
|
||||||
import org.diylc.core.ComponentState;
|
import org.diylc.core.ComponentState;
|
||||||
@@ -34,6 +35,7 @@ public class Label extends AbstractComponent<Void> {
|
|||||||
private boolean center;
|
private boolean center;
|
||||||
private HorizontalAlignment horizontalAlignment = HorizontalAlignment.CENTER;
|
private HorizontalAlignment horizontalAlignment = HorizontalAlignment.CENTER;
|
||||||
private VerticalAlignment verticalAlignment = VerticalAlignment.CENTER;
|
private VerticalAlignment verticalAlignment = VerticalAlignment.CENTER;
|
||||||
|
private Orientation orientation = Orientation.DEFAULT;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void draw(Graphics2D g2d, ComponentState componentState,
|
public void draw(Graphics2D g2d, ComponentState componentState,
|
||||||
@@ -56,7 +58,7 @@ public class Label extends AbstractComponent<Void> {
|
|||||||
y = point.y - textHeight / 2 + fontMetrics.getAscent();
|
y = point.y - textHeight / 2 + fontMetrics.getAscent();
|
||||||
break;
|
break;
|
||||||
case TOP:
|
case TOP:
|
||||||
y = point.y - textHeight + fontMetrics.getAscent();
|
y = point.y - textHeight + fontMetrics.getAscent();
|
||||||
break;
|
break;
|
||||||
case BOTTOM:
|
case BOTTOM:
|
||||||
y = point.y + fontMetrics.getAscent();
|
y = point.y + fontMetrics.getAscent();
|
||||||
@@ -80,6 +82,17 @@ public class Label extends AbstractComponent<Void> {
|
|||||||
+ getHorizontalAlignment());
|
+ getHorizontalAlignment());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
switch (getOrientation()) {
|
||||||
|
case _90:
|
||||||
|
g2d.rotate(Math.PI / 2, point.x, point.y);
|
||||||
|
break;
|
||||||
|
case _180:
|
||||||
|
g2d.rotate(Math.PI, point.x, point.y);
|
||||||
|
break;
|
||||||
|
case _270:
|
||||||
|
g2d.rotate(Math.PI * 3 / 2, point.x, point.y);
|
||||||
|
break;
|
||||||
|
}
|
||||||
g2d.drawString(text, x, y);
|
g2d.drawString(text, x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -156,6 +169,18 @@ public class Label extends AbstractComponent<Void> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@EditableProperty
|
||||||
|
public Orientation getOrientation() {
|
||||||
|
if (orientation == null) {
|
||||||
|
orientation = Orientation.DEFAULT;
|
||||||
|
}
|
||||||
|
return orientation;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOrientation(Orientation orientation) {
|
||||||
|
this.orientation = orientation;
|
||||||
|
}
|
||||||
|
|
||||||
@EditableProperty(name = "Font Size")
|
@EditableProperty(name = "Font Size")
|
||||||
public int getFontSize() {
|
public int getFontSize() {
|
||||||
return font.getSize();
|
return font.getSize();
|
||||||
|
|||||||
Reference in New Issue
Block a user