From 10663fe7cfd6c4d0ae76b560b0e32fb14628bfdb Mon Sep 17 00:00:00 2001 From: lempinen Date: Thu, 29 Mar 2012 07:18:25 +0000 Subject: [PATCH] Support line breaks in multiline comments (refs #2940) git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@24562 ac1ea38d-2e2b-0410-8846-a27921b304fc --- .../sysdyn/ui/elements/MultilineTextNode.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/MultilineTextNode.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/MultilineTextNode.java index c756baa4..d390f13d 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/MultilineTextNode.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/MultilineTextNode.java @@ -150,12 +150,20 @@ public class MultilineTextNode extends TextNode { lineMeasurer.setPosition(paragraphStart); // Get lines until the entire paragraph has been displayed. - // boolean noAscent = true; - while (lineMeasurer.getPosition() < paragraphEnd) { + int next, limit, charat, position = 0; + while ((position = lineMeasurer.getPosition()) < paragraphEnd) { + + // Find possible line break and set it as a limit to the next layout + next = lineMeasurer.nextOffset(breakWidth); + limit = next; + charat = text.indexOf(System.getProperty("line.separator"),position+1); + if(charat < next && charat != -1){ + limit = charat; + } // Retrieve next layout. A cleverer program would also cache // these layouts until the component is re-sized. - TextLayout layout = lineMeasurer.nextLayout(breakWidth); + TextLayout layout = lineMeasurer.nextLayout(breakWidth, limit, false); // Compute pen x position. If the paragraph is right-to-left we // will align the TextLayouts to the right edge of the panel. -- 2.47.1