mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-26 22:41:59 -04:00
allow multi line text
This commit is contained in:
parent
89c2c4679d
commit
4ca0f4cd72
@ -2,6 +2,7 @@ package de.neemann.digital.draw.shapes;
|
|||||||
|
|
||||||
import de.neemann.digital.core.Observer;
|
import de.neemann.digital.core.Observer;
|
||||||
import de.neemann.digital.core.element.ElementAttributes;
|
import de.neemann.digital.core.element.ElementAttributes;
|
||||||
|
import de.neemann.digital.core.element.Keys;
|
||||||
import de.neemann.digital.core.element.PinDescriptions;
|
import de.neemann.digital.core.element.PinDescriptions;
|
||||||
import de.neemann.digital.draw.elements.IOState;
|
import de.neemann.digital.draw.elements.IOState;
|
||||||
import de.neemann.digital.draw.elements.Pins;
|
import de.neemann.digital.draw.elements.Pins;
|
||||||
@ -11,26 +12,28 @@ import de.neemann.digital.draw.graphics.Style;
|
|||||||
import de.neemann.digital.draw.graphics.Vector;
|
import de.neemann.digital.draw.graphics.Vector;
|
||||||
import de.neemann.digital.lang.Lang;
|
import de.neemann.digital.lang.Lang;
|
||||||
|
|
||||||
|
import java.util.StringTokenizer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Simple text
|
* Simple text
|
||||||
*
|
*
|
||||||
* @author hneemann
|
* @author hneemann
|
||||||
*/
|
*/
|
||||||
public class TextShape implements Shape {
|
public class TextShape implements Shape {
|
||||||
private final String label;
|
private final String text;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new instance
|
* Create a new instance
|
||||||
*
|
*
|
||||||
* @param attr attributes
|
* @param attr attributes
|
||||||
* @param inputs the inputs
|
* @param inputs the inputs
|
||||||
* @param outputs the outputs
|
* @param outputs the outputs
|
||||||
*/
|
*/
|
||||||
public TextShape(ElementAttributes attr, PinDescriptions inputs, PinDescriptions outputs) {
|
public TextShape(ElementAttributes attr, PinDescriptions inputs, PinDescriptions outputs) {
|
||||||
String text = attr.getLabel();
|
String text = attr.get(Keys.DESCRIPTION);
|
||||||
if (text.length() == 0)
|
if (text.length() == 0)
|
||||||
text = Lang.get("elem_Text");
|
text = Lang.get("elem_Text");
|
||||||
this.label = text;
|
this.text = text;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -46,6 +49,12 @@ public class TextShape implements Shape {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void drawTo(Graphic graphic, Style highLight) {
|
public void drawTo(Graphic graphic, Style highLight) {
|
||||||
graphic.drawText(new Vector(0, 0), new Vector(1, 0), label, Orientation.LEFTTOP, Style.NORMAL_TEXT);
|
StringTokenizer st = new StringTokenizer(text, "\n");
|
||||||
|
Vector pos = new Vector(0, 0);
|
||||||
|
while (st.hasMoreTokens()) {
|
||||||
|
String text = st.nextToken();
|
||||||
|
graphic.drawText(pos, pos.add(1, 0), text, Orientation.LEFTTOP, Style.NORMAL_TEXT);
|
||||||
|
pos = pos.add(0, Style.NORMAL_TEXT.getFontSize());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,7 @@ public class DummyElement implements Element {
|
|||||||
* The TextElement description
|
* The TextElement description
|
||||||
*/
|
*/
|
||||||
public static final ElementTypeDescription TEXTDESCRIPTION = new ElementTypeDescription("Text", DummyElement.class)
|
public static final ElementTypeDescription TEXTDESCRIPTION = new ElementTypeDescription("Text", DummyElement.class)
|
||||||
.addAttribute(Keys.LABEL);
|
.addAttribute(Keys.DESCRIPTION);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new dummy element
|
* Creates a new dummy element
|
||||||
|
Loading…
x
Reference in New Issue
Block a user