Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » Wrap Text
Wrap Text [message #176309] Fri, 08 April 2005 23:16 Go to next message
Eclipse UserFriend
Originally posted by: jsk_lam.hotmail.com

Hi,

I have a org.eclipse.draw2d.Label and would like to have the text wrapped
around to next line if the box is not wide enough to fit the string.

Would someone please help and show me what do I need to do?

Thanks
sl
Re: Wrap Text [message #176328 is a reply to message #176309] Sat, 09 April 2005 07:58 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: lorenz.m.gmx.at

Hi,
see my posting above.
Place the text into TextFlow and it gets wrapped.


SL wrote:
> Hi,
>
> I have a org.eclipse.draw2d.Label and would like to have the text
> wrapped around to next line if the box is not wide enough to fit the
> string.
>
> Would someone please help and show me what do I need to do?
>
> Thanks
> sl
>
Re: Wrap Text [message #176347 is a reply to message #176328] Sat, 09 April 2005 14:45 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: jsk_lam.hotmail.com

Hi Larenz,

> see my posting above.

Which one is that? I couldn't find it.

> Place the text into TextFlow and it gets wrapped.

This is what I did:
Label label = new Label();
TextFlow textFlow = new TextFlow(node.getLabel());
label.add(textFlow);
Panel panel = new Panel(); // My panel contains multiple figures.
panel.add(_label);
....
This is the errors I got:
Unhandled event loop exception
Reason: Failed to execute runnable (java.lang.NullPointerException)
*** SWT nested exception
Reason: java.lang.NullPointerException

Best Regards,
SL.

"Lorenz Maierhofer" <lorenz.m@gmx.at> wrote in message
news:d381u0$8uk$1@news.eclipse.org...
> Hi,
> see my posting above.
> Place the text into TextFlow and it gets wrapped.
>
>
> SL wrote:
> > Hi,
> >
> > I have a org.eclipse.draw2d.Label and would like to have the text
> > wrapped around to next line if the box is not wide enough to fit the
> > string.
> >
> > Would someone please help and show me what do I need to do?
> >
> > Thanks
> > sl
> >
Re: Wrap Text [message #176354 is a reply to message #176347] Sat, 09 April 2005 16:03 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: lorenz.m.gmx.at

Hi,

Just don't use Label, but something like:

TextFlow content = new TextFlow("TExt to wrap");
FlowPage fp = new FlowPage();
fp.add(content);
Panel panel = new Panel(); // My panel contains multiple figures.
panel.add(fp);
add(panel);



> This is what I did:
> Label label = new Label();
> TextFlow textFlow = new TextFlow(node.getLabel());
> label.add(textFlow);
> Panel panel = new Panel(); // My panel contains multiple figures.
> panel.add(_label);
> ....
> This is the errors I got:
> Unhandled event loop exception
> Reason: Failed to execute runnable (java.lang.NullPointerException)
> *** SWT nested exception
> Reason: java.lang.NullPointerException
>
> Best Regards,
> SL.
>
> "Lorenz Maierhofer" <lorenz.m@gmx.at> wrote in message
> news:d381u0$8uk$1@news.eclipse.org...
>
>>Hi,
>>see my posting above.
>>Place the text into TextFlow and it gets wrapped.
>>
>>
>>SL wrote:
>>
>>>Hi,
>>>
>>>I have a org.eclipse.draw2d.Label and would like to have the text
>>>wrapped around to next line if the box is not wide enough to fit the
>>>string.
>>>
>>>Would someone please help and show me what do I need to do?
>>>
>>>Thanks
>>>sl
>>>
>
>
>
Re: Wrap Text [message #176390 is a reply to message #176354] Sun, 10 April 2005 14:48 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: jsk_lam.hotmail.com

Well, the text does not even show up in the panel with FlowPage.

"Lorenz Maierhofer" <lorenz.m@gmx.at> wrote in message
news:d38uc3$8jt$1@news.eclipse.org...
> Hi,
>
> Just don't use Label, but something like:
>
> TextFlow content = new TextFlow("TExt to wrap");
> FlowPage fp = new FlowPage();
> fp.add(content);
> Panel panel = new Panel(); // My panel contains multiple figures.
> panel.add(fp);
> add(panel);
>
>
>
> > This is what I did:
> > Label label = new Label();
> > TextFlow textFlow = new TextFlow(node.getLabel());
> > label.add(textFlow);
> > Panel panel = new Panel(); // My panel contains multiple figures.
> > panel.add(_label);
> > ....
> > This is the errors I got:
> > Unhandled event loop exception
> > Reason: Failed to execute runnable (java.lang.NullPointerException)
> > *** SWT nested exception
> > Reason: java.lang.NullPointerException
> >
> > Best Regards,
> > SL.
> >
> > "Lorenz Maierhofer" <lorenz.m@gmx.at> wrote in message
> > news:d381u0$8uk$1@news.eclipse.org...
> >
> >>Hi,
> >>see my posting above.
> >>Place the text into TextFlow and it gets wrapped.
> >>
> >>
> >>SL wrote:
> >>
> >>>Hi,
> >>>
> >>>I have a org.eclipse.draw2d.Label and would like to have the text
> >>>wrapped around to next line if the box is not wide enough to fit the
> >>>string.
> >>>
> >>>Would someone please help and show me what do I need to do?
> >>>
> >>>Thanks
> >>>sl
> >>>
> >
> >
> >
Re: Wrap Text [message #176397 is a reply to message #176390] Sun, 10 April 2005 16:05 Go to previous messageGo to next message
Pratik Shah is currently offline Pratik ShahFriend
Messages: 1077
Registered: July 2009
Senior Member
That would depend on the layout of the panel. But if you just want to
display that text, you don't need the panel.

"slam" <jsk_lam@hotmail.com> wrote in message
news:d3bel5$rm6$1@news.eclipse.org...
> Well, the text does not even show up in the panel with FlowPage.
>
> "Lorenz Maierhofer" <lorenz.m@gmx.at> wrote in message
> news:d38uc3$8jt$1@news.eclipse.org...
> > Hi,
> >
> > Just don't use Label, but something like:
> >
> > TextFlow content = new TextFlow("TExt to wrap");
> > FlowPage fp = new FlowPage();
> > fp.add(content);
> > Panel panel = new Panel(); // My panel contains multiple figures.
> > panel.add(fp);
> > add(panel);
> >
> >
> >
> > > This is what I did:
> > > Label label = new Label();
> > > TextFlow textFlow = new TextFlow(node.getLabel());
> > > label.add(textFlow);
> > > Panel panel = new Panel(); // My panel contains multiple figures.
> > > panel.add(_label);
> > > ....
> > > This is the errors I got:
> > > Unhandled event loop exception
> > > Reason: Failed to execute runnable (java.lang.NullPointerException)
> > > *** SWT nested exception
> > > Reason: java.lang.NullPointerException
> > >
> > > Best Regards,
> > > SL.
> > >
> > > "Lorenz Maierhofer" <lorenz.m@gmx.at> wrote in message
> > > news:d381u0$8uk$1@news.eclipse.org...
> > >
> > >>Hi,
> > >>see my posting above.
> > >>Place the text into TextFlow and it gets wrapped.
> > >>
> > >>
> > >>SL wrote:
> > >>
> > >>>Hi,
> > >>>
> > >>>I have a org.eclipse.draw2d.Label and would like to have the text
> > >>>wrapped around to next line if the box is not wide enough to fit the
> > >>>string.
> > >>>
> > >>>Would someone please help and show me what do I need to do?
> > >>>
> > >>>Thanks
> > >>>sl
> > >>>
> > >
> > >
> > >
>
>
Re: Wrap Text [message #176431 is a reply to message #176397] Sun, 10 April 2005 21:36 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: jsk_lam.hotmail.com

I do need the panel, it is the container of 3 figures:

+------+
| Icon |
| Text |
| Icon |
+------+

"Pratik Shah" <ppshah@us.ibm.com> wrote in message
news:d3bj64$rg$1@news.eclipse.org...
> That would depend on the layout of the panel. But if you just want to
> display that text, you don't need the panel.
>
> "slam" <jsk_lam@hotmail.com> wrote in message
> news:d3bel5$rm6$1@news.eclipse.org...
> > Well, the text does not even show up in the panel with FlowPage.
> >
> > "Lorenz Maierhofer" <lorenz.m@gmx.at> wrote in message
> > news:d38uc3$8jt$1@news.eclipse.org...
> > > Hi,
> > >
> > > Just don't use Label, but something like:
> > >
> > > TextFlow content = new TextFlow("TExt to wrap");
> > > FlowPage fp = new FlowPage();
> > > fp.add(content);
> > > Panel panel = new Panel(); // My panel contains multiple figures.
> > > panel.add(fp);
> > > add(panel);
> > >
> > >
> > >
> > > > This is what I did:
> > > > Label label = new Label();
> > > > TextFlow textFlow = new TextFlow(node.getLabel());
> > > > label.add(textFlow);
> > > > Panel panel = new Panel(); // My panel contains multiple figures.
> > > > panel.add(_label);
> > > > ....
> > > > This is the errors I got:
> > > > Unhandled event loop exception
> > > > Reason: Failed to execute runnable (java.lang.NullPointerException)
> > > > *** SWT nested exception
> > > > Reason: java.lang.NullPointerException
> > > >
> > > > Best Regards,
> > > > SL.
> > > >
> > > > "Lorenz Maierhofer" <lorenz.m@gmx.at> wrote in message
> > > > news:d381u0$8uk$1@news.eclipse.org...
> > > >
> > > >>Hi,
> > > >>see my posting above.
> > > >>Place the text into TextFlow and it gets wrapped.
> > > >>
> > > >>
> > > >>SL wrote:
> > > >>
> > > >>>Hi,
> > > >>>
> > > >>>I have a org.eclipse.draw2d.Label and would like to have the text
> > > >>>wrapped around to next line if the box is not wide enough to fit
the
> > > >>>string.
> > > >>>
> > > >>>Would someone please help and show me what do I need to do?
> > > >>>
> > > >>>Thanks
> > > >>>sl
> > > >>>
> > > >
> > > >
> > > >
> >
> >
>
>
Re: Wrap Text [message #176437 is a reply to message #176431] Sun, 10 April 2005 22:06 Go to previous messageGo to next message
Pratik Shah is currently offline Pratik ShahFriend
Messages: 1077
Registered: July 2009
Senior Member
And you're saying no text appears now that you're using a FlowPage? Are you
using a ToolbarLayout for your panel?

This should be simple to debug yourself. You're doing something basic
wrong.

"slam" <jsk_lam@hotmail.com> wrote in message
news:d3c6hs$mm4$1@news.eclipse.org...
> I do need the panel, it is the container of 3 figures:
>
> +------+
> | Icon |
> | Text |
> | Icon |
> +------+
>
> "Pratik Shah" <ppshah@us.ibm.com> wrote in message
> news:d3bj64$rg$1@news.eclipse.org...
> > That would depend on the layout of the panel. But if you just want to
> > display that text, you don't need the panel.
> >
> > "slam" <jsk_lam@hotmail.com> wrote in message
> > news:d3bel5$rm6$1@news.eclipse.org...
> > > Well, the text does not even show up in the panel with FlowPage.
> > >
> > > "Lorenz Maierhofer" <lorenz.m@gmx.at> wrote in message
> > > news:d38uc3$8jt$1@news.eclipse.org...
> > > > Hi,
> > > >
> > > > Just don't use Label, but something like:
> > > >
> > > > TextFlow content = new TextFlow("TExt to wrap");
> > > > FlowPage fp = new FlowPage();
> > > > fp.add(content);
> > > > Panel panel = new Panel(); // My panel contains multiple figures.
> > > > panel.add(fp);
> > > > add(panel);
> > > >
> > > >
> > > >
> > > > > This is what I did:
> > > > > Label label = new Label();
> > > > > TextFlow textFlow = new TextFlow(node.getLabel());
> > > > > label.add(textFlow);
> > > > > Panel panel = new Panel(); // My panel contains multiple
figures.
> > > > > panel.add(_label);
> > > > > ....
> > > > > This is the errors I got:
> > > > > Unhandled event loop exception
> > > > > Reason: Failed to execute runnable
(java.lang.NullPointerException)
> > > > > *** SWT nested exception
> > > > > Reason: java.lang.NullPointerException
> > > > >
> > > > > Best Regards,
> > > > > SL.
> > > > >
> > > > > "Lorenz Maierhofer" <lorenz.m@gmx.at> wrote in message
> > > > > news:d381u0$8uk$1@news.eclipse.org...
> > > > >
> > > > >>Hi,
> > > > >>see my posting above.
> > > > >>Place the text into TextFlow and it gets wrapped.
> > > > >>
> > > > >>
> > > > >>SL wrote:
> > > > >>
> > > > >>>Hi,
> > > > >>>
> > > > >>>I have a org.eclipse.draw2d.Label and would like to have the text
> > > > >>>wrapped around to next line if the box is not wide enough to fit
> the
> > > > >>>string.
> > > > >>>
> > > > >>>Would someone please help and show me what do I need to do?
> > > > >>>
> > > > >>>Thanks
> > > > >>>sl
> > > > >>>
> > > > >
> > > > >
> > > > >
> > >
> > >
> >
> >
>
>
Re: Wrap Text [message #176574 is a reply to message #176437] Mon, 11 April 2005 00:18 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: jsk_lam.hotmail.com

Yes, no text appears and no error or exception until all figures are
created,
then the exceptions occured. I am using the ToolbarLayout.
I tried to use FlowLayout, but the layout becomes

+----------------+
| Icon Text Icon |
+----------------+

This is not the way I want.

"Pratik Shah" <ppshah@us.ibm.com> wrote in message
news:d3c8af$oan$1@news.eclipse.org...
> And you're saying no text appears now that you're using a FlowPage? Are
you
> using a ToolbarLayout for your panel?
>
> This should be simple to debug yourself. You're doing something basic
> wrong.
>
> "slam" <jsk_lam@hotmail.com> wrote in message
> news:d3c6hs$mm4$1@news.eclipse.org...
> > I do need the panel, it is the container of 3 figures:
> >
> > +------+
> > | Icon |
> > | Text |
> > | Icon |
> > +------+
> >
> > "Pratik Shah" <ppshah@us.ibm.com> wrote in message
> > news:d3bj64$rg$1@news.eclipse.org...
> > > That would depend on the layout of the panel. But if you just want to
> > > display that text, you don't need the panel.
> > >
> > > "slam" <jsk_lam@hotmail.com> wrote in message
> > > news:d3bel5$rm6$1@news.eclipse.org...
> > > > Well, the text does not even show up in the panel with FlowPage.
> > > >
> > > > "Lorenz Maierhofer" <lorenz.m@gmx.at> wrote in message
> > > > news:d38uc3$8jt$1@news.eclipse.org...
> > > > > Hi,
> > > > >
> > > > > Just don't use Label, but something like:
> > > > >
> > > > > TextFlow content = new TextFlow("TExt to wrap");
> > > > > FlowPage fp = new FlowPage();
> > > > > fp.add(content);
> > > > > Panel panel = new Panel(); // My panel contains multiple
figures.
> > > > > panel.add(fp);
> > > > > add(panel);
> > > > >
> > > > >
> > > > >
> > > > > > This is what I did:
> > > > > > Label label = new Label();
> > > > > > TextFlow textFlow = new TextFlow(node.getLabel());
> > > > > > label.add(textFlow);
> > > > > > Panel panel = new Panel(); // My panel contains multiple
> figures.
> > > > > > panel.add(_label);
> > > > > > ....
> > > > > > This is the errors I got:
> > > > > > Unhandled event loop exception
> > > > > > Reason: Failed to execute runnable
> (java.lang.NullPointerException)
> > > > > > *** SWT nested exception
> > > > > > Reason: java.lang.NullPointerException
> > > > > >
> > > > > > Best Regards,
> > > > > > SL.
> > > > > >
> > > > > > "Lorenz Maierhofer" <lorenz.m@gmx.at> wrote in message
> > > > > > news:d381u0$8uk$1@news.eclipse.org...
> > > > > >
> > > > > >>Hi,
> > > > > >>see my posting above.
> > > > > >>Place the text into TextFlow and it gets wrapped.
> > > > > >>
> > > > > >>
> > > > > >>SL wrote:
> > > > > >>
> > > > > >>>Hi,
> > > > > >>>
> > > > > >>>I have a org.eclipse.draw2d.Label and would like to have the
text
> > > > > >>>wrapped around to next line if the box is not wide enough to
fit
> > the
> > > > > >>>string.
> > > > > >>>
> > > > > >>>Would someone please help and show me what do I need to do?
> > > > > >>>
> > > > > >>>Thanks
> > > > > >>>sl
> > > > > >>>
> > > > > >
> > > > > >
> > > > > >
> > > >
> > > >
> > >
> > >
> >
> >
>
>
Re: Wrap Text [message #176636 is a reply to message #176354] Mon, 11 April 2005 15:11 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: none.us.ibm.com

It works for me:

public static void main(String[] args) {
Display d = new Display();
Shell shell = new Shell(d);
shell.setLayout(new FillLayout());

FigureCanvas canvas = new FigureCanvas(shell);
canvas.getViewport().setContentsTracksWidth(true);
Figure panel = new Figure();
panel.setLayoutManager(new ToolbarLayout());
TextFlow content = new TextFlow(System.getProperties().toString());
FlowPage fp = new FlowPage();
fp.add(content);
panel.add(fp);
panel.add(new Label("A label"));
canvas.setContents(panel);


shell.setText("draw2d");
shell.open();
while (!shell.isDisposed())
while (!d.readAndDispatch())
d.sleep();

}
Re: Wrap Text [message #176717 is a reply to message #176636] Mon, 11 April 2005 21:04 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: jsk_lam.hotmail.com

It works only if the long string contains spaces in between, then the string
will wrap
at the space boundary. If I have a long continuous string without space in
between,
then it will not wrap.

"Randy Hudson" <none@us.ibm.com> wrote in message
news:d3e4cl$3rq$1@news.eclipse.org...
> It works for me:
>
> public static void main(String[] args) {
> Display d = new Display();
> Shell shell = new Shell(d);
> shell.setLayout(new FillLayout());
>
> FigureCanvas canvas = new FigureCanvas(shell);
> canvas.getViewport().setContentsTracksWidth(true);
> Figure panel = new Figure();
> panel.setLayoutManager(new ToolbarLayout());
> TextFlow content = new TextFlow(System.getProperties().toString());
> FlowPage fp = new FlowPage();
> fp.add(content);
> panel.add(fp);
> panel.add(new Label("A label"));
> canvas.setContents(panel);
>
>
> shell.setText("draw2d");
> shell.open();
> while (!shell.isDisposed())
> while (!d.readAndDispatch())
> d.sleep();
>
> }
>
>
Re: Wrap Text [message #176731 is a reply to message #176717] Mon, 11 April 2005 21:09 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: jsk_lam.hotmail.com

Looks like it is a bug.

"slam" <jsk_lam@hotmail.com> wrote in message
news:d3ep30$3nb$1@news.eclipse.org...
> It works only if the long string contains spaces in between, then the
string
> will wrap
> at the space boundary. If I have a long continuous string without space
in
> between,
> then it will not wrap.
>
> "Randy Hudson" <none@us.ibm.com> wrote in message
> news:d3e4cl$3rq$1@news.eclipse.org...
> > It works for me:
> >
> > public static void main(String[] args) {
> > Display d = new Display();
> > Shell shell = new Shell(d);
> > shell.setLayout(new FillLayout());
> >
> > FigureCanvas canvas = new FigureCanvas(shell);
> > canvas.getViewport().setContentsTracksWidth(true);
> > Figure panel = new Figure();
> > panel.setLayoutManager(new ToolbarLayout());
> > TextFlow content = new TextFlow(System.getProperties().toString());
> > FlowPage fp = new FlowPage();
> > fp.add(content);
> > panel.add(fp);
> > panel.add(new Label("A label"));
> > canvas.setContents(panel);
> >
> >
> > shell.setText("draw2d");
> > shell.open();
> > while (!shell.isDisposed())
> > while (!d.readAndDispatch())
> > d.sleep();
> >
> > }
> >
> >
>
>
Re: Wrap Text [message #176754 is a reply to message #176717] Mon, 11 April 2005 21:14 Go to previous messageGo to next message
Pratik Shah is currently offline Pratik ShahFriend
Messages: 1077
Registered: July 2009
Senior Member
Aah, that was an important piece of information you didn't mention earlier.

Add these lines to your code:
ParagraphTextLayout layout = new ParagraphTextLayout(textFlow,
ParagraphTextLayout.WORD_WRAP_SOFT);
textFlow.setLayoutManager(layout);

By default, TextFlow uses WORD_WRAP_HARD.

"slam" <jsk_lam@hotmail.com> wrote in message
news:d3ep30$3nb$1@news.eclipse.org...
> It works only if the long string contains spaces in between, then the
string
> will wrap
> at the space boundary. If I have a long continuous string without space
in
> between,
> then it will not wrap.
>
> "Randy Hudson" <none@us.ibm.com> wrote in message
> news:d3e4cl$3rq$1@news.eclipse.org...
> > It works for me:
> >
> > public static void main(String[] args) {
> > Display d = new Display();
> > Shell shell = new Shell(d);
> > shell.setLayout(new FillLayout());
> >
> > FigureCanvas canvas = new FigureCanvas(shell);
> > canvas.getViewport().setContentsTracksWidth(true);
> > Figure panel = new Figure();
> > panel.setLayoutManager(new ToolbarLayout());
> > TextFlow content = new TextFlow(System.getProperties().toString());
> > FlowPage fp = new FlowPage();
> > fp.add(content);
> > panel.add(fp);
> > panel.add(new Label("A label"));
> > canvas.setContents(panel);
> >
> >
> > shell.setText("draw2d");
> > shell.open();
> > while (!shell.isDisposed())
> > while (!d.readAndDispatch())
> > d.sleep();
> >
> > }
> >
> >
>
>
Re: Wrap Text [message #177135 is a reply to message #176754] Tue, 12 April 2005 20:38 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: jsk_lam.hotmail.com

Is there a way to get the size of the displayed text?
Dimension flowPageSize_ = _flowPage.getSize(); // Always return
(w=64, h=36) regardless of how many lines.

This causes exception:
Dimension flowPagePrefSize = _flowPage.getPreferredSize();

I need to know the height of the _flowPage to size the container Panel that
contains the _flowPage.


"Pratik Shah" <ppshah@us.ibm.com> wrote in message
news:d3epln$4iu$1@news.eclipse.org...
> Aah, that was an important piece of information you didn't mention
earlier.
>
> Add these lines to your code:
> ParagraphTextLayout layout = new ParagraphTextLayout(textFlow,
> ParagraphTextLayout.WORD_WRAP_SOFT);
> textFlow.setLayoutManager(layout);
>
> By default, TextFlow uses WORD_WRAP_HARD.
>
> "slam" <jsk_lam@hotmail.com> wrote in message
> news:d3ep30$3nb$1@news.eclipse.org...
> > It works only if the long string contains spaces in between, then the
> string
> > will wrap
> > at the space boundary. If I have a long continuous string without space
> in
> > between,
> > then it will not wrap.
> >
> > "Randy Hudson" <none@us.ibm.com> wrote in message
> > news:d3e4cl$3rq$1@news.eclipse.org...
> > > It works for me:
> > >
> > > public static void main(String[] args) {
> > > Display d = new Display();
> > > Shell shell = new Shell(d);
> > > shell.setLayout(new FillLayout());
> > >
> > > FigureCanvas canvas = new FigureCanvas(shell);
> > > canvas.getViewport().setContentsTracksWidth(true);
> > > Figure panel = new Figure();
> > > panel.setLayoutManager(new ToolbarLayout());
> > > TextFlow content = new TextFlow(System.getProperties().toString());
> > > FlowPage fp = new FlowPage();
> > > fp.add(content);
> > > panel.add(fp);
> > > panel.add(new Label("A label"));
> > > canvas.setContents(panel);
> > >
> > >
> > > shell.setText("draw2d");
> > > shell.open();
> > > while (!shell.isDisposed())
> > > while (!d.readAndDispatch())
> > > d.sleep();
> > >
> > > }
> > >
> > >
> >
> >
>
>
Re: Wrap Text [message #177165 is a reply to message #177135] Tue, 12 April 2005 20:55 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: none.us.ibm.com

Call getPreferredSize. If you get an exception, it's because you haven't
parented the figure and it doesn't know what font to use.
Re: Wrap Text [message #178317 is a reply to message #177135] Tue, 19 April 2005 18:25 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: jsk_lam.hotmail.com

Hi Pratik,

I have the following code snippet:
_textFlow = new TextFlow(node.getLabel());
ParagraphTextLayout layout = new ParagraphTextLayout(
_textFlow, ParagraphTextLayout.WORD_WRAP_SOFT);
_textFlow.setLayoutManager(layout);
_flowPage = new FlowPage();
_flowPage.add(_textFlow);
_flowPage.setHorizontalAligment(PositionConstants.CENTER );

// TODO: which one to set?
_textFlow.setFont(_fontLabel);
_flowPage.setFont(_fontLabel);

// Must set the font to use before calling getPreferredSize() or
exception will occur.
displayedTextPrefSize = _flowPage.getPreferredSize(); // width=???,
height=13
_nodePanel.add(_flowPage);

_flowPage.getPreferredSize() does not know how to return the number of lines
wrapped.
I really need to know how many lines wrapped to size the _nodePanel
accordingly.

The question I have is: How can I find the number of lines wrapped?

Also, I notice thta the WORD_WRAP_SOFT also break on the space if needed.

Best Regards
slam

"slam" <jsk_lam@hotmail.com> wrote in message
news:d3hbvr$j76$1@news.eclipse.org...
> Is there a way to get the size of the displayed text?
> Dimension flowPageSize_ = _flowPage.getSize(); // Always return
> (w=64, h=36) regardless of how many lines.
>
> This causes exception:
> Dimension flowPagePrefSize = _flowPage.getPreferredSize();
>
> I need to know the height of the _flowPage to size the container Panel
that
> contains the _flowPage.
>
>
> "Pratik Shah" <ppshah@us.ibm.com> wrote in message
> news:d3epln$4iu$1@news.eclipse.org...
> > Aah, that was an important piece of information you didn't mention
> earlier.
> >
> > Add these lines to your code:
> > ParagraphTextLayout layout = new ParagraphTextLayout(textFlow,
> > ParagraphTextLayout.WORD_WRAP_SOFT);
> > textFlow.setLayoutManager(layout);
> >
> > By default, TextFlow uses WORD_WRAP_HARD.
> >
> > "slam" <jsk_lam@hotmail.com> wrote in message
> > news:d3ep30$3nb$1@news.eclipse.org...
> > > It works only if the long string contains spaces in between, then the
> > string
> > > will wrap
> > > at the space boundary. If I have a long continuous string without
space
> > in
> > > between,
> > > then it will not wrap.
> > >
> > > "Randy Hudson" <none@us.ibm.com> wrote in message
> > > news:d3e4cl$3rq$1@news.eclipse.org...
> > > > It works for me:
> > > >
> > > > public static void main(String[] args) {
> > > > Display d = new Display();
> > > > Shell shell = new Shell(d);
> > > > shell.setLayout(new FillLayout());
> > > >
> > > > FigureCanvas canvas = new FigureCanvas(shell);
> > > > canvas.getViewport().setContentsTracksWidth(true);
> > > > Figure panel = new Figure();
> > > > panel.setLayoutManager(new ToolbarLayout());
> > > > TextFlow content = new TextFlow(System.getProperties().toString());
> > > > FlowPage fp = new FlowPage();
> > > > fp.add(content);
> > > > panel.add(fp);
> > > > panel.add(new Label("A label"));
> > > > canvas.setContents(panel);
> > > >
> > > >
> > > > shell.setText("draw2d");
> > > > shell.open();
> > > > while (!shell.isDisposed())
> > > > while (!d.readAndDispatch())
> > > > d.sleep();
> > > >
> > > > }
> > > >
> > > >
> > >
> > >
> >
> >
>
>
Re: Wrap Text [message #178355 is a reply to message #178317] Tue, 19 April 2005 21:38 Go to previous messageGo to next message
Pratik Shah is currently offline Pratik ShahFriend
Messages: 1077
Registered: July 2009
Senior Member
"sl" <jsk_lam@hotmail.com> wrote in message
news:d43iul$rf5$1@news.eclipse.org...
> Hi Pratik,
>
> I have the following code snippet:
> _textFlow = new TextFlow(node.getLabel());
> ParagraphTextLayout layout = new ParagraphTextLayout(
> _textFlow, ParagraphTextLayout.WORD_WRAP_SOFT);
> _textFlow.setLayoutManager(layout);
> _flowPage = new FlowPage();
> _flowPage.add(_textFlow);
> _flowPage.setHorizontalAligment(PositionConstants.CENTER );
>
> // TODO: which one to set?
> _textFlow.setFont(_fontLabel);
> _flowPage.setFont(_fontLabel);

####
You should be able to figure this out by looking at Figure#getFont().

>
> // Must set the font to use before calling getPreferredSize() or
> exception will occur.
> displayedTextPrefSize = _flowPage.getPreferredSize(); //
width=???,
> height=13

####
If you debug this, you'll realize that invoking flowPage.getPreferredSize()
means invoking flowPage.getPreferredSize(-1, -1). What that means is that
you're asking the flowpage how big does it want to be if it had infinite
width and infinite height available. Since it has infinite width, it
doesn't need to wrap and hence it will return a size such that all text fits
on one line. If, however, you tell it how much width is available (height
would still be -1), it will return the appropriate size.

Your next question is going to be....how do you know how much width is
available? Use LayoutManagers and don't set the bounds of the figure
yourself. If you don't see why or how that'll fix your problem, set a
breakpoint in getPreferredSize(wHint, hHint) and walk through what's
happening and try to understand.

> _nodePanel.add(_flowPage);
>
> _flowPage.getPreferredSize() does not know how to return the number of
lines
> wrapped.
> I really need to know how many lines wrapped to size the _nodePanel
> accordingly.
>
> The question I have is: How can I find the number of lines wrapped?
>
> Also, I notice thta the WORD_WRAP_SOFT also break on the space if needed.

####
Yes, it wraps in a readable format if it can. This is the intended
behaviour.

>
> Best Regards
> slam
>
> "slam" <jsk_lam@hotmail.com> wrote in message
> news:d3hbvr$j76$1@news.eclipse.org...
> > Is there a way to get the size of the displayed text?
> > Dimension flowPageSize_ = _flowPage.getSize(); // Always return
> > (w=64, h=36) regardless of how many lines.
> >
> > This causes exception:
> > Dimension flowPagePrefSize = _flowPage.getPreferredSize();
> >
> > I need to know the height of the _flowPage to size the container Panel
> that
> > contains the _flowPage.
> >
> >
> > "Pratik Shah" <ppshah@us.ibm.com> wrote in message
> > news:d3epln$4iu$1@news.eclipse.org...
> > > Aah, that was an important piece of information you didn't mention
> > earlier.
> > >
> > > Add these lines to your code:
> > > ParagraphTextLayout layout = new ParagraphTextLayout(textFlow,
> > > ParagraphTextLayout.WORD_WRAP_SOFT);
> > > textFlow.setLayoutManager(layout);
> > >
> > > By default, TextFlow uses WORD_WRAP_HARD.
> > >
> > > "slam" <jsk_lam@hotmail.com> wrote in message
> > > news:d3ep30$3nb$1@news.eclipse.org...
> > > > It works only if the long string contains spaces in between, then
the
> > > string
> > > > will wrap
> > > > at the space boundary. If I have a long continuous string without
> space
> > > in
> > > > between,
> > > > then it will not wrap.
> > > >
> > > > "Randy Hudson" <none@us.ibm.com> wrote in message
> > > > news:d3e4cl$3rq$1@news.eclipse.org...
> > > > > It works for me:
> > > > >
> > > > > public static void main(String[] args) {
> > > > > Display d = new Display();
> > > > > Shell shell = new Shell(d);
> > > > > shell.setLayout(new FillLayout());
> > > > >
> > > > > FigureCanvas canvas = new FigureCanvas(shell);
> > > > > canvas.getViewport().setContentsTracksWidth(true);
> > > > > Figure panel = new Figure();
> > > > > panel.setLayoutManager(new ToolbarLayout());
> > > > > TextFlow content = new
TextFlow(System.getProperties().toString());
> > > > > FlowPage fp = new FlowPage();
> > > > > fp.add(content);
> > > > > panel.add(fp);
> > > > > panel.add(new Label("A label"));
> > > > > canvas.setContents(panel);
> > > > >
> > > > >
> > > > > shell.setText("draw2d");
> > > > > shell.open();
> > > > > while (!shell.isDisposed())
> > > > > while (!d.readAndDispatch())
> > > > > d.sleep();
> > > > >
> > > > > }
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >
> >
> >
>
>
Re: Wrap Text [message #179028 is a reply to message #178317] Mon, 25 April 2005 14:04 Go to previous message
Eclipse UserFriend
Originally posted by: none.us.ibm.com

It's best to avoid calling setFont() unless you are changing from the
inherited one. Instead, you should add the figure to the lightweightsystem
it is going to showup in.

Can you back up a bit and tell us what you are trying to do. there is
probably a much easier way.
Previous Topic:remove fields on "ContextMenuProvider"
Next Topic:How to refresh/redraw the whole of the container edit part
Goto Forum:
  


Current Time: Mon Jan 30 11:33:03 GMT 2023

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

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

Back to the top