Home » Eclipse Projects » GEF » Extending FlowFigure
Extending FlowFigure [message #160111] |
Thu, 02 December 2004 11:16  |
Eclipse User |
|
|
|
Originally posted by: none.none.com
Hi,
I am trying to extend FlowFigure to simulate a flow layout similar to html,
where the text could wrap to the next line (like TextFlow does, when inside
PageFlow). I need to mix text (inline or block) with other kinds of controls
(always block).
I can't afford to have all my figures extend FlowFigure, so instead I
created a generic class FlowFigureLeaf that derives from FlowFigure and acts
as a container of any single Figure. My problem is how to implement this
FlowFigureLeaf to have its child figure render/layout properly, so far the
FlowFigure mechanisms remain cryptic and it doesn't work. Any
hint/suggestion would be welcomed. Do I need a FlowLayoutManager or not? If
yes what would it need to do, if not what should the FlowFigureLeaf.layout
function do? FlowFigureLeaf has only one child, and it's not a FlowFigure,
but any generic Figure.
Thanks,
David
|
|
|
Re: Extending FlowFigure [message #160119 is a reply to message #160111] |
Thu, 02 December 2004 11:39   |
Eclipse User |
|
|
|
Originally posted by: none.us.ibm.com
You want to create a wrapper flow figure capable of wrapping any generic
figure.
This shouldn't be hard. Create a flowwrapper which when it lays out,
constructs a box with the desired width and height for the normal inner
figure. If you want the figure to fill up the containing block, you can
request a newline, then get the amount of available space on the newline,
and use that as the box's width. Then add the box to the current line, and
endline again. On postlayout, your box will be adjusted (although probably
it won't move since it fills block width), then you just reposition the
wrapped figure to be inside the box.
"David Michonneau" <none@none.com> wrote in message
news:conf5d$rfq$1@www.eclipse.org...
> Hi,
>
> I am trying to extend FlowFigure to simulate a flow layout similar to
html,
> where the text could wrap to the next line (like TextFlow does, when
inside
> PageFlow). I need to mix text (inline or block) with other kinds of
controls
> (always block).
>
> I can't afford to have all my figures extend FlowFigure, so instead I
> created a generic class FlowFigureLeaf that derives from FlowFigure and
acts
> as a container of any single Figure. My problem is how to implement this
> FlowFigureLeaf to have its child figure render/layout properly, so far the
> FlowFigure mechanisms remain cryptic and it doesn't work. Any
> hint/suggestion would be welcomed. Do I need a FlowLayoutManager or not?
If
> yes what would it need to do, if not what should the FlowFigureLeaf.layout
> function do? FlowFigureLeaf has only one child, and it's not a FlowFigure,
> but any generic Figure.
>
> Thanks,
>
> David
>
>
|
|
|
Re: Extending FlowFigure [message #160187 is a reply to message #160119] |
Thu, 02 December 2004 15:00   |
Eclipse User |
|
|
|
Originally posted by: none.none.com
I'm doing something like this, but it only creates a small box, although
when I debug I can see the width and height in this code is correct. Am I
missing anything?
class WrapperFigure{
....
protected void layout()
{
context.endLine();
int width = context.getCurrentLine().getAvailableWidth();
int height = context.getCurrentLine().getHeight();
box.setWidth ( width);
box.setHeight ( height );
context.getCurrentLine().add(box);
context.endLine();
}
/**
* @see org.eclipse.draw2d.text.FlowFigure#postValidate()
*/
public void postValidate()
{
Rectangle r = new Rectangle(box.x, box.y, box.getWidth(),
box.getHeight()) ;
Dimension figureSize =
figure.getPreferredSize(box.getWidth(),box.getHeight());
// set bounds of child
figure.setBounds(new Rectangle(box.x, box.y, figureSize.width,
figureSize.height));
}
"Randy Hudson" <none@us.ibm.com> wrote in message
news:congfk$uo7$1@www.eclipse.org...
> You want to create a wrapper flow figure capable of wrapping any generic
> figure.
>
> This shouldn't be hard. Create a flowwrapper which when it lays out,
> constructs a box with the desired width and height for the normal inner
> figure. If you want the figure to fill up the containing block, you can
> request a newline, then get the amount of available space on the newline,
> and use that as the box's width. Then add the box to the current line,
> and
> endline again. On postlayout, your box will be adjusted (although
> probably
> it won't move since it fills block width), then you just reposition the
> wrapped figure to be inside the box.
>
> "David Michonneau" <none@none.com> wrote in message
> news:conf5d$rfq$1@www.eclipse.org...
>> Hi,
>>
>> I am trying to extend FlowFigure to simulate a flow layout similar to
> html,
>> where the text could wrap to the next line (like TextFlow does, when
> inside
>> PageFlow). I need to mix text (inline or block) with other kinds of
> controls
>> (always block).
>>
>> I can't afford to have all my figures extend FlowFigure, so instead I
>> created a generic class FlowFigureLeaf that derives from FlowFigure and
> acts
>> as a container of any single Figure. My problem is how to implement this
>> FlowFigureLeaf to have its child figure render/layout properly, so far
>> the
>> FlowFigure mechanisms remain cryptic and it doesn't work. Any
>> hint/suggestion would be welcomed. Do I need a FlowLayoutManager or not?
> If
>> yes what would it need to do, if not what should the
>> FlowFigureLeaf.layout
>> function do? FlowFigureLeaf has only one child, and it's not a
>> FlowFigure,
>> but any generic Figure.
>>
>> Thanks,
>>
>> David
>>
>>
>
>
|
|
| | |
Re: Extending FlowFigure [message #160416 is a reply to message #160368] |
Fri, 03 December 2004 15:40   |
Eclipse User |
|
|
|
Originally posted by: none.us.ibm.com
The multiple layouts are probably because of multiple width hints being
used. One is without the vertical scrollbar present, and one with. The 3rd
layout is probably to undo the 2nd (if the scrollbar isn't actually needed).
BTW, the preferred sizes of a flowpage get cached by width hint, so you
shouldn't see so many layout every time.
As far as empty lines, etc., I don't have enough info to know what is
happening.
"David Michonneau" <none@none.com> wrote in message
news:coq7p5$2jv$1@www.eclipse.org...
> Thanks, that took care of it!
>
> And now another issue... the layout function is called three times, and
for
> some unknown reason, it causes the first line to be empty, but with the
size
> of the element on the next line. I am not sure why the FlowPageLayout
> manager calls layoutChildren since the children are going to be layed out
> anyway by the validate call, but I guess there is a reason. If I don't set
a
The reason is to respond to the getPreferredSize request
> height to the box I add, all my lines are of height 0. Any idea of what
> could be wrong?
>
> Thanks,
>
> David
>
>
>
> "Randy Hudson" <none@us.ibm.com> wrote in message
> news:convbr$30s$1@www.eclipse.org...
> > Probably the wrapper figure needs to update its own bounds as well.
> >
> >
>
>
|
|
|
Re: Extending FlowFigure [message #161250 is a reply to message #160416] |
Fri, 10 December 2004 10:26   |
Eclipse User |
|
|
|
Originally posted by: none.none.com
The problem is when layout is called multiple lines, it keeps doing
context.endLine();
context.getCurrentLine.add(box);
context.endLine();
then the getCurrentLine gets the next line based on the height of the box in
the first line... The box is added to each line, creating this gap. How can
I avoid that?
Thanks,
David
"Randy Hudson" <none@us.ibm.com> wrote in message
news:coqivk$s63$1@www.eclipse.org...
> The multiple layouts are probably because of multiple width hints being
> used. One is without the vertical scrollbar present, and one with. The
> 3rd
> layout is probably to undo the 2nd (if the scrollbar isn't actually
> needed).
> BTW, the preferred sizes of a flowpage get cached by width hint, so you
> shouldn't see so many layout every time.
>
> As far as empty lines, etc., I don't have enough info to know what is
> happening.
>
> "David Michonneau" <none@none.com> wrote in message
> news:coq7p5$2jv$1@www.eclipse.org...
>> Thanks, that took care of it!
>>
>> And now another issue... the layout function is called three times, and
> for
>> some unknown reason, it causes the first line to be empty, but with the
> size
>> of the element on the next line. I am not sure why the FlowPageLayout
>> manager calls layoutChildren since the children are going to be layed out
>> anyway by the validate call, but I guess there is a reason. If I don't
>> set
> a
>
> The reason is to respond to the getPreferredSize request
>
>> height to the box I add, all my lines are of height 0. Any idea of what
>> could be wrong?
>>
>> Thanks,
>>
>> David
>>
>>
>>
>> "Randy Hudson" <none@us.ibm.com> wrote in message
>> news:convbr$30s$1@www.eclipse.org...
>> > Probably the wrapper figure needs to update its own bounds as well.
>> >
>> >
>>
>>
>
>
|
|
|
Re: Extending FlowFigure [message #161268 is a reply to message #161250] |
Fri, 10 December 2004 14:01   |
Eclipse User |
|
|
|
Originally posted by: none.none.com
Finally what I did was to change flowpage validate() method:
public void validate() {
if (isValid())
return;
setValid(true);
layout(); // instead of calling super.validate();
postValidate();
}
if it calls super.validate like in the original implementation, that calls
validate on all children, and their layout function as well, which is bad
since it won't clean-up the context after calling it. We don't really need
to call validate on children, since it's done in layout() by
layoutChildren().
What do you think about that?
Thanks,
David
"David Michonneau" <none@none.com> wrote in message
news:cpcf6a$fhc$1@www.eclipse.org...
> The problem is when layout is called multiple lines, it keeps doing
>
> context.endLine();
> context.getCurrentLine.add(box);
> context.endLine();
>
> then the getCurrentLine gets the next line based on the height of the box
> in the first line... The box is added to each line, creating this gap. How
> can I avoid that?
>
> Thanks,
>
> David
>
> "Randy Hudson" <none@us.ibm.com> wrote in message
> news:coqivk$s63$1@www.eclipse.org...
>> The multiple layouts are probably because of multiple width hints being
>> used. One is without the vertical scrollbar present, and one with. The
>> 3rd
>> layout is probably to undo the 2nd (if the scrollbar isn't actually
>> needed).
>> BTW, the preferred sizes of a flowpage get cached by width hint, so you
>> shouldn't see so many layout every time.
>>
>> As far as empty lines, etc., I don't have enough info to know what is
>> happening.
>>
>> "David Michonneau" <none@none.com> wrote in message
>> news:coq7p5$2jv$1@www.eclipse.org...
>>> Thanks, that took care of it!
>>>
>>> And now another issue... the layout function is called three times, and
>> for
>>> some unknown reason, it causes the first line to be empty, but with the
>> size
>>> of the element on the next line. I am not sure why the FlowPageLayout
>>> manager calls layoutChildren since the children are going to be layed
>>> out
>>> anyway by the validate call, but I guess there is a reason. If I don't
>>> set
>> a
>>
>> The reason is to respond to the getPreferredSize request
>>
>>> height to the box I add, all my lines are of height 0. Any idea of what
>>> could be wrong?
>>>
>>> Thanks,
>>>
>>> David
>>>
>>>
>>>
>>> "Randy Hudson" <none@us.ibm.com> wrote in message
>>> news:convbr$30s$1@www.eclipse.org...
>>> > Probably the wrapper figure needs to update its own bounds as well.
>>> >
>>> >
>>>
>>>
>>
>>
>
>
|
|
|
Re: Extending FlowFigure [message #161432 is a reply to message #161268] |
Mon, 13 December 2004 11:36   |
Eclipse User |
|
|
|
Originally posted by: none.us.ibm.com
I don't have any test cases where layouts occur twice (without invalidates()
coming between them). super.validate() should basically do nothing since
the children are valid at that point, so a workaround isn' required.
"David Michonneau" <none@none.com> wrote in message
news:cpcrq2$o7s$1@www.eclipse.org...
> Finally what I did was to change flowpage validate() method:
>
> public void validate() {
> if (isValid())
> return;
> setValid(true);
> layout(); // instead of calling super.validate();
> postValidate();
> }
>
> if it calls super.validate like in the original implementation, that calls
> validate on all children, and their layout function as well, which is bad
> since it won't clean-up the context after calling it. We don't really need
> to call validate on children, since it's done in layout() by
> layoutChildren().
>
> What do you think about that?
>
> Thanks,
>
> David
>
> "David Michonneau" <none@none.com> wrote in message
> news:cpcf6a$fhc$1@www.eclipse.org...
> > The problem is when layout is called multiple lines, it keeps doing
> >
> > context.endLine();
> > context.getCurrentLine.add(box);
> > context.endLine();
> >
> > then the getCurrentLine gets the next line based on the height of the
box
> > in the first line... The box is added to each line, creating this gap.
How
> > can I avoid that?
> >
> > Thanks,
> >
> > David
> >
> > "Randy Hudson" <none@us.ibm.com> wrote in message
> > news:coqivk$s63$1@www.eclipse.org...
> >> The multiple layouts are probably because of multiple width hints being
> >> used. One is without the vertical scrollbar present, and one with.
The
> >> 3rd
> >> layout is probably to undo the 2nd (if the scrollbar isn't actually
> >> needed).
> >> BTW, the preferred sizes of a flowpage get cached by width hint, so you
> >> shouldn't see so many layout every time.
> >>
> >> As far as empty lines, etc., I don't have enough info to know what is
> >> happening.
> >>
> >> "David Michonneau" <none@none.com> wrote in message
> >> news:coq7p5$2jv$1@www.eclipse.org...
> >>> Thanks, that took care of it!
> >>>
> >>> And now another issue... the layout function is called three times,
and
> >> for
> >>> some unknown reason, it causes the first line to be empty, but with
the
> >> size
> >>> of the element on the next line. I am not sure why the FlowPageLayout
> >>> manager calls layoutChildren since the children are going to be layed
> >>> out
> >>> anyway by the validate call, but I guess there is a reason. If I don't
> >>> set
> >> a
> >>
> >> The reason is to respond to the getPreferredSize request
> >>
> >>> height to the box I add, all my lines are of height 0. Any idea of
what
> >>> could be wrong?
> >>>
> >>> Thanks,
> >>>
> >>> David
> >>>
> >>>
> >>>
> >>> "Randy Hudson" <none@us.ibm.com> wrote in message
> >>> news:convbr$30s$1@www.eclipse.org...
> >>> > Probably the wrapper figure needs to update its own bounds as well.
> >>> >
> >>> >
> >>>
> >>>
> >>
> >>
> >
> >
>
>
|
|
|
Re: Extending FlowFigure [message #161464 is a reply to message #161432] |
Mon, 13 December 2004 12:48   |
Eclipse User |
|
|
|
Originally posted by: none.none.com
It seems the child of flowpage gets invalid in postvalidate(), causing it to
layout again.
postvalidate()
{
figure.setBounds(bounds); // figure is the child of the wrapper
flowfigure)
this.setBounds(bounds);
}
actually there is a new scenario where it happens: when I add a child to the
enclosed figure, it again calls validate too many times, am I doing
something wrong?
Thanks,
David
"Randy Hudson" <none@us.ibm.com> wrote in message
news:cpkgdr$289$1@www.eclipse.org...
>I don't have any test cases where layouts occur twice (without
>invalidates()
> coming between them). super.validate() should basically do nothing since
> the children are valid at that point, so a workaround isn' required.
>
> "David Michonneau" <none@none.com> wrote in message
> news:cpcrq2$o7s$1@www.eclipse.org...
>> Finally what I did was to change flowpage validate() method:
>>
>> public void validate() {
>> if (isValid())
>> return;
>> setValid(true);
>> layout(); // instead of calling super.validate();
>> postValidate();
>> }
>>
>> if it calls super.validate like in the original implementation, that
>> calls
>> validate on all children, and their layout function as well, which is bad
>> since it won't clean-up the context after calling it. We don't really
>> need
>> to call validate on children, since it's done in layout() by
>> layoutChildren().
>>
>> What do you think about that?
>>
>> Thanks,
>>
>> David
>>
>> "David Michonneau" <none@none.com> wrote in message
>> news:cpcf6a$fhc$1@www.eclipse.org...
>> > The problem is when layout is called multiple lines, it keeps doing
>> >
>> > context.endLine();
>> > context.getCurrentLine.add(box);
>> > context.endLine();
>> >
>> > then the getCurrentLine gets the next line based on the height of the
> box
>> > in the first line... The box is added to each line, creating this gap.
> How
>> > can I avoid that?
>> >
>> > Thanks,
>> >
>> > David
>> >
>> > "Randy Hudson" <none@us.ibm.com> wrote in message
>> > news:coqivk$s63$1@www.eclipse.org...
>> >> The multiple layouts are probably because of multiple width hints
>> >> being
>> >> used. One is without the vertical scrollbar present, and one with.
> The
>> >> 3rd
>> >> layout is probably to undo the 2nd (if the scrollbar isn't actually
>> >> needed).
>> >> BTW, the preferred sizes of a flowpage get cached by width hint, so
>> >> you
>> >> shouldn't see so many layout every time.
>> >>
>> >> As far as empty lines, etc., I don't have enough info to know what is
>> >> happening.
>> >>
>> >> "David Michonneau" <none@none.com> wrote in message
>> >> news:coq7p5$2jv$1@www.eclipse.org...
>> >>> Thanks, that took care of it!
>> >>>
>> >>> And now another issue... the layout function is called three times,
> and
>> >> for
>> >>> some unknown reason, it causes the first line to be empty, but with
> the
>> >> size
>> >>> of the element on the next line. I am not sure why the FlowPageLayout
>> >>> manager calls layoutChildren since the children are going to be layed
>> >>> out
>> >>> anyway by the validate call, but I guess there is a reason. If I
>> >>> don't
>> >>> set
>> >> a
>> >>
>> >> The reason is to respond to the getPreferredSize request
>> >>
>> >>> height to the box I add, all my lines are of height 0. Any idea of
> what
>> >>> could be wrong?
>> >>>
>> >>> Thanks,
>> >>>
>> >>> David
>> >>>
>> >>>
>> >>>
>> >>> "Randy Hudson" <none@us.ibm.com> wrote in message
>> >>> news:convbr$30s$1@www.eclipse.org...
>> >>> > Probably the wrapper figure needs to update its own bounds as well.
>> >>> >
>> >>> >
>> >>>
>> >>>
>> >>
>> >>
>> >
>> >
>>
>>
>
>
|
|
| |
Re: Extending FlowFigure [message #161566 is a reply to message #161487] |
Wed, 15 December 2004 08:47  |
Eclipse User |
|
|
|
Originally posted by: none.none.com
The code below is my own code, which is triggering the figure to become
invalid. I have a flowwrapperfigure that contains a generic IFigure, should
I do the setBounds somewhere else? I thought it has to be done in
postvalidate?
Thanks,
David
"Randy Hudson" <none@us.ibm.com> wrote in message
news:cpkrhk$6h8$1@www.eclipse.org...
> Maybe you are nesting flowpages? I don't see that code and comment in my
> FlowPage postValidate() method.
>
> Try posting a snippet of code which shows the problem.
>
> "David Michonneau" <none@none.com> wrote in message
> news:cpkkm9$gb4$1@www.eclipse.org...
>> It seems the child of flowpage gets invalid in postvalidate(), causing it
> to
>> layout again.
>>
>> postvalidate()
>> {
>> figure.setBounds(bounds); // figure is the child of the wrapper
>> flowfigure)
>> this.setBounds(bounds);
>> }
>>
>> actually there is a new scenario where it happens: when I add a child to
> the
>> enclosed figure, it again calls validate too many times, am I doing
>> something wrong?
>>
>> Thanks,
>>
>> David
>
>
|
|
|
Goto Forum:
Current Time: Wed Jul 30 17:47:31 EDT 2025
Powered by FUDForum. Page generated in 0.04836 seconds
|