allow multi line text

This commit is contained in:
hneemann 2017-07-04 18:22:40 +02:00
parent 89c2c4679d
commit 4ca0f4cd72
2 changed files with 15 additions and 6 deletions

View File

@ -2,6 +2,7 @@ package de.neemann.digital.draw.shapes;
import de.neemann.digital.core.Observer;
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.draw.elements.IOState;
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.lang.Lang;
import java.util.StringTokenizer;
/**
* Simple text
*
* @author hneemann
*/
public class TextShape implements Shape {
private final String label;
private final String text;
/**
* Create a new instance
*
* @param attr attributes
* @param attr attributes
* @param inputs the inputs
* @param outputs the outputs
*/
public TextShape(ElementAttributes attr, PinDescriptions inputs, PinDescriptions outputs) {
String text = attr.getLabel();
String text = attr.get(Keys.DESCRIPTION);
if (text.length() == 0)
text = Lang.get("elem_Text");
this.label = text;
this.text = text;
}
@ -46,6 +49,12 @@ public class TextShape implements Shape {
@Override
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());
}
}
}

View File

@ -27,7 +27,7 @@ public class DummyElement implements Element {
* The TextElement description
*/
public static final ElementTypeDescription TEXTDESCRIPTION = new ElementTypeDescription("Text", DummyElement.class)
.addAttribute(Keys.LABEL);
.addAttribute(Keys.DESCRIPTION);
/**
* Creates a new dummy element