Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » HowTo "underline" WYSIWYG text in GEF
HowTo "underline" WYSIWYG text in GEF [message #223652] Wed, 04 October 2006 00:15 Go to next message
Eric Wasserman is currently offline Eric WassermanFriend
Messages: 10
Registered: July 2009
Junior Member
I have some questions regarding usage of the org.eclipse.draw2d.text
package.

1) How can one set the spacing between lines in a BlockFlow?

2) What would be a good way to "underline" just portions of text in a
multiline block of text. [Think
I put underline in quotes because the adornment would be something more
elaborate than a simple line at the baseline of the text. In fact it
would have some significant vertical extent so I need a way to leave
space for it (hence question 1). There would be several different types
of such underlinings but no span of text would have more than one kind.
Some text would not have any underline.

My current thinking is to create a separate TextFlow for each portion of
text with a different underline treatment. The TextFlow would have a
FlowBorder that drew the underline. These would all be contained within
a FlowPage.

Problems with this approach:
1) Creating separate TextFlows for each underlined segment is kind of a
pain as it doesn't correspond well to the underlying model. I could live
with this if its the "right way" to do it.

I tried to create a single text flow and have the border figure out
where to draw the underlines but I could not get the coordinate location
of where a given character in the TextFlow starts and ends. Too much in
TextFlow and the FlowBoxes was inaccessible to my TextFlow subclass.

2) I can't figure out how to leave vertical space for the underline.
Overriding AbstractFlowBorder.getBottomMargin() to have it return the
vertical extent of my underline seemed like the right thing to do but
didn't have the desired effect because it didn't change the vertical
spacing between lines. [Though getLeft/RightMargin() oddly enough did
what I expected.] I would be fine with giving all lines the extra
spacing. The line spacing doesn't need to adapt to the presence/absence
of underlining within a particular line of text in the BlockFlow.

Thanks in advance for any help.

Eric
Re: HowTo "underline" WYSIWYG text in GEF [message #223716 is a reply to message #223652] Wed, 04 October 2006 15:40 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: none.unknown.com

You do want a separate TextFlow for the parts of text that are to be
underlined. You need to override AbstractFlowBorder#getInsets(), not the
margin methods.

"Eric Wasserman" <ewasserman@voxify.com> wrote in message
news:efuufv$muu$1@utils.eclipse.org...
>I have some questions regarding usage of the org.eclipse.draw2d.text
>package.
>
> 1) How can one set the spacing between lines in a BlockFlow?
>
> 2) What would be a good way to "underline" just portions of text in a
> multiline block of text. [Think
> I put underline in quotes because the adornment would be something more
> elaborate than a simple line at the baseline of the text. In fact it would
> have some significant vertical extent so I need a way to leave space for
> it (hence question 1). There would be several different types of such
> underlinings but no span of text would have more than one kind. Some text
> would not have any underline.
>
> My current thinking is to create a separate TextFlow for each portion of
> text with a different underline treatment. The TextFlow would have a
> FlowBorder that drew the underline. These would all be contained within a
> FlowPage.
>
> Problems with this approach:
> 1) Creating separate TextFlows for each underlined segment is kind of a
> pain as it doesn't correspond well to the underlying model. I could live
> with this if its the "right way" to do it.
>
> I tried to create a single text flow and have the border figure out where
> to draw the underlines but I could not get the coordinate location of
> where a given character in the TextFlow starts and ends. Too much in
> TextFlow and the FlowBoxes was inaccessible to my TextFlow subclass.
>
> 2) I can't figure out how to leave vertical space for the underline.
> Overriding AbstractFlowBorder.getBottomMargin() to have it return the
> vertical extent of my underline seemed like the right thing to do but
> didn't have the desired effect because it didn't change the vertical
> spacing between lines. [Though getLeft/RightMargin() oddly enough did what
> I expected.] I would be fine with giving all lines the extra spacing. The
> line spacing doesn't need to adapt to the presence/absence of underlining
> within a particular line of text in the BlockFlow.
>
> Thanks in advance for any help.
>
> Eric
Re: HowTo "underline" WYSIWYG text in GEF [message #223753 is a reply to message #223716] Wed, 04 October 2006 18:39 Go to previous messageGo to next message
Eric Wasserman is currently offline Eric WassermanFriend
Messages: 10
Registered: July 2009
Junior Member
I tried overriding AbstractFlowBorder.getInsets() this added space below
the wrapped text. So if I have a single TextFlow in a FlowPage it looks
like:

---------------------------
|The quick brown fox jumped |
|over the lazy dog. |
---------------------------

adding a border to the TextFlow subclass's constructor thusly:

setBorder(new AbstractFlowBorder() {
public Insets getInsets(IFigure figure) {
return new Insets(0, 0, 10, 0);
}
});

add the extra space after all the wrapped text. So it becomes:

---------------------------
|The quick brown fox jumped |
|over the lazy dog. |
| |
---------------------------

instead of what a I want:

---------------------------
|The quick brown fox jumped |
| |
|over the lazy dog. |
| |
---------------------------




Pratik Shah wrote:
> You do want a separate TextFlow for the parts of text that are to be
> underlined. You need to override AbstractFlowBorder#getInsets(), not the
> margin methods.
>
> "Eric Wasserman" <ewasserman@voxify.com> wrote in message
> news:efuufv$muu$1@utils.eclipse.org...
>> I have some questions regarding usage of the org.eclipse.draw2d.text
>> package.
>>
>> 1) How can one set the spacing between lines in a BlockFlow?
>>
>> 2) What would be a good way to "underline" just portions of text in a
>> multiline block of text. [Think
>> I put underline in quotes because the adornment would be something more
>> elaborate than a simple line at the baseline of the text. In fact it would
>> have some significant vertical extent so I need a way to leave space for
>> it (hence question 1). There would be several different types of such
>> underlinings but no span of text would have more than one kind. Some text
>> would not have any underline.
>>
>> My current thinking is to create a separate TextFlow for each portion of
>> text with a different underline treatment. The TextFlow would have a
>> FlowBorder that drew the underline. These would all be contained within a
>> FlowPage.
>>
>> Problems with this approach:
>> 1) Creating separate TextFlows for each underlined segment is kind of a
>> pain as it doesn't correspond well to the underlying model. I could live
>> with this if its the "right way" to do it.
>>
>> I tried to create a single text flow and have the border figure out where
>> to draw the underlines but I could not get the coordinate location of
>> where a given character in the TextFlow starts and ends. Too much in
>> TextFlow and the FlowBoxes was inaccessible to my TextFlow subclass.
>>
>> 2) I can't figure out how to leave vertical space for the underline.
>> Overriding AbstractFlowBorder.getBottomMargin() to have it return the
>> vertical extent of my underline seemed like the right thing to do but
>> didn't have the desired effect because it didn't change the vertical
>> spacing between lines. [Though getLeft/RightMargin() oddly enough did what
>> I expected.] I would be fine with giving all lines the extra spacing. The
>> line spacing doesn't need to adapt to the presence/absence of underlining
>> within a particular line of text in the BlockFlow.
>>
>> Thanks in advance for any help.
>>
>> Eric
>
>
Re: HowTo "underline" WYSIWYG text in GEF [message #223761 is a reply to message #223753] Wed, 04 October 2006 19:49 Go to previous messageGo to next message
Eric Wasserman is currently offline Eric WassermanFriend
Messages: 10
Registered: July 2009
Junior Member
Here is an example that shows the issue:

public class TextTest extends AbstractExample {

public static void main(String[] args) {
new TextTest().run();
}

@Override
protected IFigure getContents() {
FlowPage fp = new FlowPage();
TextFlow tf = new TextFlow();
tf.setText("When, in the course of human events, it becomes
necessary" +
" for one people to dissolve the political bonds which have
connected" +
" them with another, and to assume among the powers of the
earth, the" +
" separate and equal station to which the laws of nature and of
nature's" +
" God entitle them, a decent respect to the opinions of mankind
requires" +
" that they should declare the causes which impel them to the
separation.");
fp.add(tf);
tf.setBorder(new AbstractFlowBorder() {

public Insets getInsets(IFigure figure) {
return new Insets(0,0,10,0);
}


});
return fp;
}

}


Eric Wasserman wrote:
> I tried overriding AbstractFlowBorder.getInsets() this added space below
> the wrapped text. So if I have a single TextFlow in a FlowPage it looks
> like:
>
> ---------------------------
> |The quick brown fox jumped |
> |over the lazy dog. |
> ---------------------------
>
> adding a border to the TextFlow subclass's constructor thusly:
>
> setBorder(new AbstractFlowBorder() {
> public Insets getInsets(IFigure figure) {
> return new Insets(0, 0, 10, 0);
> }
> });
>
> add the extra space after all the wrapped text. So it becomes:
>
> ---------------------------
> |The quick brown fox jumped |
> |over the lazy dog. |
> | |
> ---------------------------
>
> instead of what a I want:
>
> ---------------------------
> |The quick brown fox jumped |
> | |
> |over the lazy dog. |
> | |
> ---------------------------
>
>
>
>
> Pratik Shah wrote:
>> You do want a separate TextFlow for the parts of text that are to be
>> underlined. You need to override AbstractFlowBorder#getInsets(), not
>> the margin methods.
>>
>> "Eric Wasserman" <ewasserman@voxify.com> wrote in message
>> news:efuufv$muu$1@utils.eclipse.org...
>>> I have some questions regarding usage of the org.eclipse.draw2d.text
>>> package.
>>>
>>> 1) How can one set the spacing between lines in a BlockFlow?
>>>
>>> 2) What would be a good way to "underline" just portions of text in a
>>> multiline block of text. [Think
>>> I put underline in quotes because the adornment would be something
>>> more elaborate than a simple line at the baseline of the text. In
>>> fact it would have some significant vertical extent so I need a way
>>> to leave space for it (hence question 1). There would be several
>>> different types of such underlinings but no span of text would have
>>> more than one kind. Some text would not have any underline.
>>>
>>> My current thinking is to create a separate TextFlow for each portion
>>> of text with a different underline treatment. The TextFlow would have
>>> a FlowBorder that drew the underline. These would all be contained
>>> within a FlowPage.
>>>
>>> Problems with this approach:
>>> 1) Creating separate TextFlows for each underlined segment is kind of
>>> a pain as it doesn't correspond well to the underlying model. I could
>>> live with this if its the "right way" to do it.
>>>
>>> I tried to create a single text flow and have the border figure out
>>> where to draw the underlines but I could not get the coordinate
>>> location of where a given character in the TextFlow starts and ends.
>>> Too much in TextFlow and the FlowBoxes was inaccessible to my
>>> TextFlow subclass.
>>>
>>> 2) I can't figure out how to leave vertical space for the underline.
>>> Overriding AbstractFlowBorder.getBottomMargin() to have it return the
>>> vertical extent of my underline seemed like the right thing to do but
>>> didn't have the desired effect because it didn't change the vertical
>>> spacing between lines. [Though getLeft/RightMargin() oddly enough did
>>> what I expected.] I would be fine with giving all lines the extra
>>> spacing. The line spacing doesn't need to adapt to the
>>> presence/absence of underlining within a particular line of text in
>>> the BlockFlow.
>>>
>>> Thanks in advance for any help.
>>>
>>> Eric
>>
>>
Re: HowTo "underline" WYSIWYG text in GEF [message #223770 is a reply to message #223761] Wed, 04 October 2006 20:57 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: none.unknown.com

I think this is because borders bleed through lines (similar to borders in
HTML). Anyway, here's something else to try. Use custom TextFragmentBoxes
that report a taller descent than necessary: override getDescent() to do the
same as getDescentWithBorder(). To use these custom boxes, create a custom
ParagraphTextLayout that overrides fragment creation -- getFragment().
Hopefully, that'll do it for you.

"Eric Wasserman" <ewasserman@voxify.com> wrote in message
news:eg137k$8go$1@utils.eclipse.org...
> Here is an example that shows the issue:
>
> public class TextTest extends AbstractExample {
>
> public static void main(String[] args) {
> new TextTest().run();
> }
>
> @Override
> protected IFigure getContents() {
> FlowPage fp = new FlowPage();
> TextFlow tf = new TextFlow();
> tf.setText("When, in the course of human events, it becomes necessary"
> +
> " for one people to dissolve the political bonds which have
> connected" +
> " them with another, and to assume among the powers of the earth,
> the" +
> " separate and equal station to which the laws of nature and of
> nature's" +
> " God entitle them, a decent respect to the opinions of mankind
> requires" +
> " that they should declare the causes which impel them to the
> separation.");
> fp.add(tf);
> tf.setBorder(new AbstractFlowBorder() {
>
> public Insets getInsets(IFigure figure) {
> return new Insets(0,0,10,0);
> }
>
>
> });
> return fp;
> }
>
> }
>
>
> Eric Wasserman wrote:
>> I tried overriding AbstractFlowBorder.getInsets() this added space below
>> the wrapped text. So if I have a single TextFlow in a FlowPage it looks
>> like:
>>
>> ---------------------------
>> |The quick brown fox jumped |
>> |over the lazy dog. |
>> ---------------------------
>>
>> adding a border to the TextFlow subclass's constructor thusly:
>>
>> setBorder(new AbstractFlowBorder() {
>> public Insets getInsets(IFigure figure) {
>> return new Insets(0, 0, 10, 0);
>> }
>> });
>>
>> add the extra space after all the wrapped text. So it becomes:
>>
>> ---------------------------
>> |The quick brown fox jumped |
>> |over the lazy dog. |
>> | |
>> ---------------------------
>>
>> instead of what a I want:
>>
>> ---------------------------
>> |The quick brown fox jumped |
>> | |
>> |over the lazy dog. |
>> | |
>> ---------------------------
>>
>>
>>
>>
>> Pratik Shah wrote:
>>> You do want a separate TextFlow for the parts of text that are to be
>>> underlined. You need to override AbstractFlowBorder#getInsets(), not
>>> the margin methods.
>>>
>>> "Eric Wasserman" <ewasserman@voxify.com> wrote in message
>>> news:efuufv$muu$1@utils.eclipse.org...
>>>> I have some questions regarding usage of the org.eclipse.draw2d.text
>>>> package.
>>>>
>>>> 1) How can one set the spacing between lines in a BlockFlow?
>>>>
>>>> 2) What would be a good way to "underline" just portions of text in a
>>>> multiline block of text. [Think
>>>> I put underline in quotes because the adornment would be something more
>>>> elaborate than a simple line at the baseline of the text. In fact it
>>>> would have some significant vertical extent so I need a way to leave
>>>> space for it (hence question 1). There would be several different types
>>>> of such underlinings but no span of text would have more than one kind.
>>>> Some text would not have any underline.
>>>>
>>>> My current thinking is to create a separate TextFlow for each portion
>>>> of text with a different underline treatment. The TextFlow would have a
>>>> FlowBorder that drew the underline. These would all be contained within
>>>> a FlowPage.
>>>>
>>>> Problems with this approach:
>>>> 1) Creating separate TextFlows for each underlined segment is kind of a
>>>> pain as it doesn't correspond well to the underlying model. I could
>>>> live with this if its the "right way" to do it.
>>>>
>>>> I tried to create a single text flow and have the border figure out
>>>> where to draw the underlines but I could not get the coordinate
>>>> location of where a given character in the TextFlow starts and ends.
>>>> Too much in TextFlow and the FlowBoxes was inaccessible to my TextFlow
>>>> subclass.
>>>>
>>>> 2) I can't figure out how to leave vertical space for the underline.
>>>> Overriding AbstractFlowBorder.getBottomMargin() to have it return the
>>>> vertical extent of my underline seemed like the right thing to do but
>>>> didn't have the desired effect because it didn't change the vertical
>>>> spacing between lines. [Though getLeft/RightMargin() oddly enough did
>>>> what I expected.] I would be fine with giving all lines the extra
>>>> spacing. The line spacing doesn't need to adapt to the presence/absence
>>>> of underlining within a particular line of text in the BlockFlow.
>>>>
>>>> Thanks in advance for any help.
>>>>
>>>> Eric
>>>
>>>
Re: HowTo "underline" WYSIWYG text in GEF [message #223817 is a reply to message #223770] Thu, 05 October 2006 01:56 Go to previous messageGo to next message
Eric Wasserman is currently offline Eric WassermanFriend
Messages: 10
Registered: July 2009
Junior Member
This worked (though it is quite awkward). Thanks for your help Pratik.
I must admit I don't really see the utility in not having the border
insets honored by default.



To summarize (if anyone else cares), the idea is to create:

public class MarginTextFragmentBox extends TextFragmentBox {

public MarginTextFragmentBox(TextFlow textflow) {
super(textflow);
}

public int getDescent() {
return textFlow.getDescent() +
FlowUtilities.getBorderDescent(textFlow);
}
}


Then create:

public class MarginParagraphTextLayout extends ParagraphTextLayout {

public MarginParagraphTextLayout(TextFlow flow) {
super(flow);
}

protected TextFragmentBox getFragment(int i, List fragments) {
if (fragments.size() > i)
return (TextFragmentBox)fragments.get(i);
TextFragmentBox box = new
MarginTextFragmentBox((TextFlow)getFlowFigure());
fragments.add(box);
return box;
}
}

And use it by giving all the TextFlow's this layout:

TextFlow tf = new TextFlow();
tf.setLayoutManager(new MarginParagraphTextLayout(tf));


There are several difficulties with this in practice (when implementing
the TextFragmentBox subclass):

1) The class org.eclipse.draw2d.text.FlowUtilities is package protected
2) The method FlowUtilities.getBorderDescent(InlineFlow) is package
protected
3) TextFragmentBox.textflow is private (though the constructor gets the
TextFlow so you can make a copy for your subclass to use).
4) TextFlow.getDescent() is package protected



Pratik Shah wrote:
> I think this is because borders bleed through lines (similar to borders in
> HTML). Anyway, here's something else to try. Use custom TextFragmentBoxes
> that report a taller descent than necessary: override getDescent() to do the
> same as getDescentWithBorder(). To use these custom boxes, create a custom
> ParagraphTextLayout that overrides fragment creation -- getFragment().
> Hopefully, that'll do it for you.
>
> "Eric Wasserman" <ewasserman@voxify.com> wrote in message
> news:eg137k$8go$1@utils.eclipse.org...
>> Here is an example that shows the issue:
>>
>> public class TextTest extends AbstractExample {
>>
>> public static void main(String[] args) {
>> new TextTest().run();
>> }
>>
>> @Override
>> protected IFigure getContents() {
>> FlowPage fp = new FlowPage();
>> TextFlow tf = new TextFlow();
>> tf.setText("When, in the course of human events, it becomes necessary"
>> +
>> " for one people to dissolve the political bonds which have
>> connected" +
>> " them with another, and to assume among the powers of the earth,
>> the" +
>> " separate and equal station to which the laws of nature and of
>> nature's" +
>> " God entitle them, a decent respect to the opinions of mankind
>> requires" +
>> " that they should declare the causes which impel them to the
>> separation.");
>> fp.add(tf);
>> tf.setBorder(new AbstractFlowBorder() {
>>
>> public Insets getInsets(IFigure figure) {
>> return new Insets(0,0,10,0);
>> }
>>
>>
>> });
>> return fp;
>> }
>>
>> }
>>
>>
>> Eric Wasserman wrote:
>>> I tried overriding AbstractFlowBorder.getInsets() this added space below
>>> the wrapped text. So if I have a single TextFlow in a FlowPage it looks
>>> like:
>>>
>>> ---------------------------
>>> |The quick brown fox jumped |
>>> |over the lazy dog. |
>>> ---------------------------
>>>
>>> adding a border to the TextFlow subclass's constructor thusly:
>>>
>>> setBorder(new AbstractFlowBorder() {
>>> public Insets getInsets(IFigure figure) {
>>> return new Insets(0, 0, 10, 0);
>>> }
>>> });
>>>
>>> add the extra space after all the wrapped text. So it becomes:
>>>
>>> ---------------------------
>>> |The quick brown fox jumped |
>>> |over the lazy dog. |
>>> | |
>>> ---------------------------
>>>
>>> instead of what a I want:
>>>
>>> ---------------------------
>>> |The quick brown fox jumped |
>>> | |
>>> |over the lazy dog. |
>>> | |
>>> ---------------------------
>>>
>>>
>>>
>>>
>>> Pratik Shah wrote:
>>>> You do want a separate TextFlow for the parts of text that are to be
>>>> underlined. You need to override AbstractFlowBorder#getInsets(), not
>>>> the margin methods.
>>>>
>>>> "Eric Wasserman" <ewasserman@voxify.com> wrote in message
>>>> news:efuufv$muu$1@utils.eclipse.org...
>>>>> I have some questions regarding usage of the org.eclipse.draw2d.text
>>>>> package.
>>>>>
>>>>> 1) How can one set the spacing between lines in a BlockFlow?
>>>>>
>>>>> 2) What would be a good way to "underline" just portions of text in a
>>>>> multiline block of text. [Think
>>>>> I put underline in quotes because the adornment would be something more
>>>>> elaborate than a simple line at the baseline of the text. In fact it
>>>>> would have some significant vertical extent so I need a way to leave
>>>>> space for it (hence question 1). There would be several different types
>>>>> of such underlinings but no span of text would have more than one kind.
>>>>> Some text would not have any underline.
>>>>>
>>>>> My current thinking is to create a separate TextFlow for each portion
>>>>> of text with a different underline treatment. The TextFlow would have a
>>>>> FlowBorder that drew the underline. These would all be contained within
>>>>> a FlowPage.
>>>>>
>>>>> Problems with this approach:
>>>>> 1) Creating separate TextFlows for each underlined segment is kind of a
>>>>> pain as it doesn't correspond well to the underlying model. I could
>>>>> live with this if its the "right way" to do it.
>>>>>
>>>>> I tried to create a single text flow and have the border figure out
>>>>> where to draw the underlines but I could not get the coordinate
>>>>> location of where a given character in the TextFlow starts and ends.
>>>>> Too much in TextFlow and the FlowBoxes was inaccessible to my TextFlow
>>>>> subclass.
>>>>>
>>>>> 2) I can't figure out how to leave vertical space for the underline.
>>>>> Overriding AbstractFlowBorder.getBottomMargin() to have it return the
>>>>> vertical extent of my underline seemed like the right thing to do but
>>>>> didn't have the desired effect because it didn't change the vertical
>>>>> spacing between lines. [Though getLeft/RightMargin() oddly enough did
>>>>> what I expected.] I would be fine with giving all lines the extra
>>>>> spacing. The line spacing doesn't need to adapt to the presence/absence
>>>>> of underlining within a particular line of text in the BlockFlow.
>>>>>
>>>>> Thanks in advance for any help.
>>>>>
>>>>> Eric
>>>>
>
>
Re: HowTo "underline" WYSIWYG text in GEF [message #223865 is a reply to message #223817] Thu, 05 October 2006 15:05 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: none.unknown.com

"Eric Wasserman" <ewasserman@voxify.com> wrote in message
news:eg1onj$cii$1@utils.eclipse.org...
> This worked (though it is quite awkward). Thanks for your help Pratik.
> I must admit I don't really see the utility in not having the border
> insets honored by default.

It's because borders bleed into the lines surrounding it in HTML. It's not
some random behaviour we came up with. See attached image.




>
>
>
> To summarize (if anyone else cares), the idea is to create:
>
> public class MarginTextFragmentBox extends TextFragmentBox {
>
> public MarginTextFragmentBox(TextFlow textflow) {
> super(textflow);
> }
>
> public int getDescent() {
> return textFlow.getDescent() +
> FlowUtilities.getBorderDescent(textFlow);
> }
> }
>
>
> Then create:
>
> public class MarginParagraphTextLayout extends ParagraphTextLayout {
>
> public MarginParagraphTextLayout(TextFlow flow) {
> super(flow);
> }
>
> protected TextFragmentBox getFragment(int i, List fragments) {
> if (fragments.size() > i)
> return (TextFragmentBox)fragments.get(i);
> TextFragmentBox box = new
> MarginTextFragmentBox((TextFlow)getFlowFigure());
> fragments.add(box);
> return box;
> }
> }
>
> And use it by giving all the TextFlow's this layout:
>
> TextFlow tf = new TextFlow();
> tf.setLayoutManager(new MarginParagraphTextLayout(tf));
>
>
> There are several difficulties with this in practice (when implementing
> the TextFragmentBox subclass):
>
> 1) The class org.eclipse.draw2d.text.FlowUtilities is package protected
> 2) The method FlowUtilities.getBorderDescent(InlineFlow) is package
> protected
> 3) TextFragmentBox.textflow is private (though the constructor gets the
> TextFlow so you can make a copy for your subclass to use).
> 4) TextFlow.getDescent() is package protected
>
>
>
> Pratik Shah wrote:
>> I think this is because borders bleed through lines (similar to borders
>> in
>> HTML). Anyway, here's something else to try. Use custom
>> TextFragmentBoxes
>> that report a taller descent than necessary: override getDescent() to do
>> the
>> same as getDescentWithBorder(). To use these custom boxes, create a
>> custom
>> ParagraphTextLayout that overrides fragment creation -- getFragment().
>> Hopefully, that'll do it for you.
>>
>> "Eric Wasserman" <ewasserman@voxify.com> wrote in message
>> news:eg137k$8go$1@utils.eclipse.org...
>>> Here is an example that shows the issue:
>>>
>>> public class TextTest extends AbstractExample {
>>>
>>> public static void main(String[] args) {
>>> new TextTest().run();
>>> }
>>>
>>> @Override
>>> protected IFigure getContents() {
>>> FlowPage fp = new FlowPage();
>>> TextFlow tf = new TextFlow();
>>> tf.setText("When, in the course of human events, it becomes
>>> necessary"
>>> +
>>> " for one people to dissolve the political bonds which have
>>> connected" +
>>> " them with another, and to assume among the powers of the
>>> earth,
>>> the" +
>>> " separate and equal station to which the laws of nature and of
>>> nature's" +
>>> " God entitle them, a decent respect to the opinions of mankind
>>> requires" +
>>> " that they should declare the causes which impel them to the
>>> separation.");
>>> fp.add(tf);
>>> tf.setBorder(new AbstractFlowBorder() {
>>>
>>> public Insets getInsets(IFigure figure) {
>>> return new Insets(0,0,10,0);
>>> }
>>>
>>>
>>> });
>>> return fp;
>>> }
>>>
>>> }
>>>
>>>
>>> Eric Wasserman wrote:
>>>> I tried overriding AbstractFlowBorder.getInsets() this added space
>>>> below
>>>> the wrapped text. So if I have a single TextFlow in a FlowPage it looks
>>>> like:
>>>>
>>>> ---------------------------
>>>> |The quick brown fox jumped |
>>>> |over the lazy dog. |
>>>> ---------------------------
>>>>
>>>> adding a border to the TextFlow subclass's constructor thusly:
>>>>
>>>> setBorder(new AbstractFlowBorder() {
>>>> public Insets getInsets(IFigure figure) {
>>>> return new Insets(0, 0, 10, 0);
>>>> }
>>>> });
>>>>
>>>> add the extra space after all the wrapped text. So it becomes:
>>>>
>>>> ---------------------------
>>>> |The quick brown fox jumped |
>>>> |over the lazy dog. |
>>>> | |
>>>> ---------------------------
>>>>
>>>> instead of what a I want:
>>>>
>>>> ---------------------------
>>>> |The quick brown fox jumped |
>>>> | |
>>>> |over the lazy dog. |
>>>> | |
>>>> ---------------------------
>>>>
>>>>
>>>>
>>>>
>>>> Pratik Shah wrote:
>>>>> You do want a separate TextFlow for the parts of text that are to be
>>>>> underlined. You need to override AbstractFlowBorder#getInsets(), not
>>>>> the margin methods.
>>>>>
>>>>> "Eric Wasserman" <ewasserman@voxify.com> wrote in message
>>>>> news:efuufv$muu$1@utils.eclipse.org...
>>>>>> I have some questions regarding usage of the org.eclipse.draw2d.text
>>>>>> package.
>>>>>>
>>>>>> 1) How can one set the spacing between lines in a BlockFlow?
>>>>>>
>>>>>> 2) What would be a good way to "underline" just portions of text in a
>>>>>> multiline block of text. [Think
>>>>>> I put underline in quotes because the adornment would be something
>>>>>> more
>>>>>> elaborate than a simple line at the baseline of the text. In fact it
>>>>>> would have some significant vertical extent so I need a way to leave
>>>>>> space for it (hence question 1). There would be several different
>>>>>> types
>>>>>> of such underlinings but no span of text would have more than one
>>>>>> kind.
>>>>>> Some text would not have any underline.
>>>>>>
>>>>>> My current thinking is to create a separate TextFlow for each portion
>>>>>> of text with a different underline treatment. The TextFlow would have
>>>>>> a
>>>>>> FlowBorder that drew the underline. These would all be contained
>>>>>> within
>>>>>> a FlowPage.
>>>>>>
>>>>>> Problems with this approach:
>>>>>> 1) Creating separate TextFlows for each underlined segment is kind of
>>>>>> a
>>>>>> pain as it doesn't correspond well to the underlying model. I could
>>>>>> live with this if its the "right way" to do it.
>>>>>>
>>>>>> I tried to create a single text flow and have the border figure out
>>>>>> where to draw the underlines but I could not get the coordinate
>>>>>> location of where a given character in the TextFlow starts and ends.
>>>>>> Too much in TextFlow and the FlowBoxes was inaccessible to my
>>>>>> TextFlow
>>>>>> subclass.
>>>>>>
>>>>>> 2) I can't figure out how to leave vertical space for the underline.
>>>>>> Overriding AbstractFlowBorder.getBottomMargin() to have it return the
>>>>>> vertical extent of my underline seemed like the right thing to do but
>>>>>> didn't have the desired effect because it didn't change the vertical
>>>>>> spacing between lines. [Though getLeft/RightMargin() oddly enough did
>>>>>> what I expected.] I would be fine with giving all lines the extra
>>>>>> spacing. The line spacing doesn't need to adapt to the
>>>>>> presence/absence
>>>>>> of underlining within a particular line of text in the BlockFlow.
>>>>>>
>>>>>> Thanks in advance for any help.
>>>>>>
>>>>>> Eric
>>>>>
>>
>>


Re: HowTo "underline" WYSIWYG text in GEF [message #223874 is a reply to message #223865] Thu, 05 October 2006 17:16 Go to previous message
Eric Wasserman is currently offline Eric WassermanFriend
Messages: 10
Registered: July 2009
Junior Member
Ok, fair enough. But is this really "good" behavior in the sense that it
makes for a useful feature of the API? I find it quite odd and
inconsistent behavior.

Using your example as an illustration: the green border overwrites the
line of text above and yet is overwritten by the line of text below.
Further the intraline spacing is not affected by the border but
horizontal spacing is. Notice there is space inserted between the "up"
and the "." at the right side.

For my money (and I acknowledge that you've received none ;) ) I would
have preferred that the insets actually affect the spacing all around.
This would have made it more consistent with general Draw2D Figure
behavior, no?

Also having some API support for setting the line spacing (perhaps in
the layouts) seems like it would be quite useful. Should I submit this
as a Bugzilla enhancement request?


Pratik Shah wrote:
> "Eric Wasserman" <ewasserman@voxify.com> wrote in message
> news:eg1onj$cii$1@utils.eclipse.org...
>> This worked (though it is quite awkward). Thanks for your help Pratik.
>> I must admit I don't really see the utility in not having the border
>> insets honored by default.
>
> It's because borders bleed into the lines surrounding it in HTML. It's not
> some random behaviour we came up with. See attached image.
>
>
>
>
>>
>>
>> To summarize (if anyone else cares), the idea is to create:
>>
>> public class MarginTextFragmentBox extends TextFragmentBox {
>>
>> public MarginTextFragmentBox(TextFlow textflow) {
>> super(textflow);
>> }
>>
>> public int getDescent() {
>> return textFlow.getDescent() +
>> FlowUtilities.getBorderDescent(textFlow);
>> }
>> }
>>
>>
>> Then create:
>>
>> public class MarginParagraphTextLayout extends ParagraphTextLayout {
>>
>> public MarginParagraphTextLayout(TextFlow flow) {
>> super(flow);
>> }
>>
>> protected TextFragmentBox getFragment(int i, List fragments) {
>> if (fragments.size() > i)
>> return (TextFragmentBox)fragments.get(i);
>> TextFragmentBox box = new
>> MarginTextFragmentBox((TextFlow)getFlowFigure());
>> fragments.add(box);
>> return box;
>> }
>> }
>>
>> And use it by giving all the TextFlow's this layout:
>>
>> TextFlow tf = new TextFlow();
>> tf.setLayoutManager(new MarginParagraphTextLayout(tf));
>>
>>
>> There are several difficulties with this in practice (when implementing
>> the TextFragmentBox subclass):
>>
>> 1) The class org.eclipse.draw2d.text.FlowUtilities is package protected
>> 2) The method FlowUtilities.getBorderDescent(InlineFlow) is package
>> protected
>> 3) TextFragmentBox.textflow is private (though the constructor gets the
>> TextFlow so you can make a copy for your subclass to use).
>> 4) TextFlow.getDescent() is package protected
>>
>>
>>
>> Pratik Shah wrote:
>>> I think this is because borders bleed through lines (similar to borders
>>> in
>>> HTML). Anyway, here's something else to try. Use custom
>>> TextFragmentBoxes
>>> that report a taller descent than necessary: override getDescent() to do
>>> the
>>> same as getDescentWithBorder(). To use these custom boxes, create a
>>> custom
>>> ParagraphTextLayout that overrides fragment creation -- getFragment().
>>> Hopefully, that'll do it for you.
>>>
>>> "Eric Wasserman" <ewasserman@voxify.com> wrote in message
>>> news:eg137k$8go$1@utils.eclipse.org...
>>>> Here is an example that shows the issue:
>>>>
>>>> public class TextTest extends AbstractExample {
>>>>
>>>> public static void main(String[] args) {
>>>> new TextTest().run();
>>>> }
>>>>
>>>> @Override
>>>> protected IFigure getContents() {
>>>> FlowPage fp = new FlowPage();
>>>> TextFlow tf = new TextFlow();
>>>> tf.setText("When, in the course of human events, it becomes
>>>> necessary"
>>>> +
>>>> " for one people to dissolve the political bonds which have
>>>> connected" +
>>>> " them with another, and to assume among the powers of the
>>>> earth,
>>>> the" +
>>>> " separate and equal station to which the laws of nature and of
>>>> nature's" +
>>>> " God entitle them, a decent respect to the opinions of mankind
>>>> requires" +
>>>> " that they should declare the causes which impel them to the
>>>> separation.");
>>>> fp.add(tf);
>>>> tf.setBorder(new AbstractFlowBorder() {
>>>>
>>>> public Insets getInsets(IFigure figure) {
>>>> return new Insets(0,0,10,0);
>>>> }
>>>>
>>>>
>>>> });
>>>> return fp;
>>>> }
>>>>
>>>> }
>>>>
>>>>
>>>> Eric Wasserman wrote:
>>>>> I tried overriding AbstractFlowBorder.getInsets() this added space
>>>>> below
>>>>> the wrapped text. So if I have a single TextFlow in a FlowPage it looks
>>>>> like:
>>>>>
>>>>> ---------------------------
>>>>> |The quick brown fox jumped |
>>>>> |over the lazy dog. |
>>>>> ---------------------------
>>>>>
>>>>> adding a border to the TextFlow subclass's constructor thusly:
>>>>>
>>>>> setBorder(new AbstractFlowBorder() {
>>>>> public Insets getInsets(IFigure figure) {
>>>>> return new Insets(0, 0, 10, 0);
>>>>> }
>>>>> });
>>>>>
>>>>> add the extra space after all the wrapped text. So it becomes:
>>>>>
>>>>> ---------------------------
>>>>> |The quick brown fox jumped |
>>>>> |over the lazy dog. |
>>>>> | |
>>>>> ---------------------------
>>>>>
>>>>> instead of what a I want:
>>>>>
>>>>> ---------------------------
>>>>> |The quick brown fox jumped |
>>>>> | |
>>>>> |over the lazy dog. |
>>>>> | |
>>>>> ---------------------------
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> Pratik Shah wrote:
>>>>>> You do want a separate TextFlow for the parts of text that are to be
>>>>>> underlined. You need to override AbstractFlowBorder#getInsets(), not
>>>>>> the margin methods.
>>>>>>
>>>>>> "Eric Wasserman" <ewasserman@voxify.com> wrote in message
>>>>>> news:efuufv$muu$1@utils.eclipse.org...
>>>>>>> I have some questions regarding usage of the org.eclipse.draw2d.text
>>>>>>> package.
>>>>>>>
>>>>>>> 1) How can one set the spacing between lines in a BlockFlow?
>>>>>>>
>>>>>>> 2) What would be a good way to "underline" just portions of text in a
>>>>>>> multiline block of text. [Think
>>>>>>> I put underline in quotes because the adornment would be something
>>>>>>> more
>>>>>>> elaborate than a simple line at the baseline of the text. In fact it
>>>>>>> would have some significant vertical extent so I need a way to leave
>>>>>>> space for it (hence question 1). There would be several different
>>>>>>> types
>>>>>>> of such underlinings but no span of text would have more than one
>>>>>>> kind.
>>>>>>> Some text would not have any underline.
>>>>>>>
>>>>>>> My current thinking is to create a separate TextFlow for each portion
>>>>>>> of text with a different underline treatment. The TextFlow would have
>>>>>>> a
>>>>>>> FlowBorder that drew the underline. These would all be contained
>>>>>>> within
>>>>>>> a FlowPage.
>>>>>>>
>>>>>>> Problems with this approach:
>>>>>>> 1) Creating separate TextFlows for each underlined segment is kind of
>>>>>>> a
>>>>>>> pain as it doesn't correspond well to the underlying model. I could
>>>>>>> live with this if its the "right way" to do it.
>>>>>>>
>>>>>>> I tried to create a single text flow and have the border figure out
>>>>>>> where to draw the underlines but I could not get the coordinate
>>>>>>> location of where a given character in the TextFlow starts and ends.
>>>>>>> Too much in TextFlow and the FlowBoxes was inaccessible to my
>>>>>>> TextFlow
>>>>>>> subclass.
>>>>>>>
>>>>>>> 2) I can't figure out how to leave vertical space for the underline.
>>>>>>> Overriding AbstractFlowBorder.getBottomMargin() to have it return the
>>>>>>> vertical extent of my underline seemed like the right thing to do but
>>>>>>> didn't have the desired effect because it didn't change the vertical
>>>>>>> spacing between lines. [Though getLeft/RightMargin() oddly enough did
>>>>>>> what I expected.] I would be fine with giving all lines the extra
>>>>>>> spacing. The line spacing doesn't need to adapt to the
>>>>>>> presence/absence
>>>>>>> of underlining within a particular line of text in the BlockFlow.
>>>>>>>
>>>>>>> Thanks in advance for any help.
>>>>>>>
>>>>>>> Eric
>>>
>
>
Previous Topic:Drawing custom decorations in Compartment-Nodes
Next Topic:Cut Copy and paste Implementation
Goto Forum:
  


Current Time: Thu Mar 28 13:04:48 GMT 2024

Powered by FUDForum. Page generated in 0.08316 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top